! Factor port of the raytracer benchmark from
! http://www.ffconsultancy.com/languages/ray_tracer/index.html
-USING: arrays accessors generalizations io io.files io.files.temp
+USING: arrays accessors generalizations io.files io.files.temp
io.encodings.binary kernel math math.constants math.functions
-math.vectors math.vectors.simd math.vectors.simd.cords
-math.parser make sequences words combinators ;
+math.vectors math.vectors.simd.cords math.parser make sequences
+words combinators ;
IN: benchmark.raytracer-simd
<< SYNTAX: no-compile last-word t "no-compile" set-word-prop ; >>
: sphere-v ( sphere ray -- v ) [ center>> ] [ orig>> ] bi* v- ; inline no-compile
-: sphere-b ( v ray -- b ) dir>> v. ; inline no-compile
+: sphere-b ( v ray -- b ) dir>> vdot ; inline no-compile
: sphere-d ( sphere b v -- d ) [ radius>> sq ] [ sq ] [ norm-sq ] tri* - + ; inline no-compile
: sray-intersect ( ray scene hit -- ray )
swap [ ray-o light vneg <ray> ] dip initial-intersect ; inline no-compile
-: ray-g ( hit -- g ) normal>> light v. ; inline no-compile
+: ray-g ( hit -- g ) normal>> light vdot ; inline no-compile
: cast-ray ( ray scene -- g )
2dup initial-intersect dup lambda>> 1/0. = [
: ray-pixel ( scene point -- ray-grid )
[ 0.0 ] 2dip
- oversampling iota [
- oversampling iota [
+ oversampling <iota> [
+ oversampling <iota> [
ss-point v+ normalize
double-4{ 0.0 0.0 -4.0 0.0 } swap <ray>
swap cast-ray +
] 2with each ; inline no-compile
: ray-trace ( scene -- grid )
- size iota <reversed> [
- size iota [
+ size <iota> <reversed> [
+ size <iota> [
[ size 0.5 * - ] bi@ swap size
0.0 double-4-boa ray-pixel
] 2with map