Raytracing speed again, this time with gdc.

downs default_357-line at yahoo.de
Thu Nov 8 18:57:56 PST 2007


Bill Baxter wrote:
> 
> Could the difference be in part due to default initialization in D?
> Maybe all your rays and vecs are getting initialized first to NaN and
> then overwritten with the value you want, and that is slowing it down.
> 
> You could try sticking some =void's in your structs, like so:
> 
> struct Vec {
>   double x=void, y=void, z=void;
>   Vec opAdd(ref Vec other) { return Vec(x+other.x, y+other.y, z+other.z); }
>   Vec opSub(ref Vec other) { return Vec(x-other.x, y-other.y, z-other.z); }
>   Vec opMul(double a) { return Vec(x*a, y*a, z*a); }
>   double dot(ref Vec other) { return x*other.x+y*other.y+z*other.z; }
>   Vec unitise() { return opMul(1.0/dsqrt(dot(*this))); }
> }
> 
> struct Pair(T, U) { T first=void; U second=void; }
> typedef Pair!(double, Vec) Hit;
> 
> struct Ray { Vec orig=void, dir=void; }
> 
> 
> --bb

If you check the source, you'll see that practically all my structs are either
manually initialized with proper values or the result of a calculation. Also,
I tried that and it's not it.
Sorry.

Still, thanks for the idea!
 --downs


More information about the Digitalmars-d-learn mailing list