Manta Interactive Ray Tracer Development Mailing List

Text archives Help


Re: [MANTA] some coding advice requested


Chronological Thread 
  • From: "Steven G. Parker" <sparker@cs.utah.edu>
  • To: Peter Shirley <shirley@cs.utah.edu>
  • Cc: manta@sci.utah.edu
  • Subject: Re: [MANTA] some coding advice requested
  • Date: Fri, 13 May 2005 10:13:10 -0600

Peter Shirley wrote:
I'm doing some restructuring of the innards of the materials
(especially to get rid of shadow rays for specular surfaces) and
while I'm at it I am trying to clean some things up.  There are
a few trade-offs I'd like some feedback on.

1. Often we can either go stack or heap, e.g.

    float *co = new float[4];   // 4 rays in this particular packet

    vs

    float co[32];  // 32 is max packet size

   I am inclined to change the former to the latter in the current code
   but perhaps my insincts are wrong?

Absolutely. The latter is the right way to do it. Look at Lambertian.cc for the best example. Use float co[RayPacket::MaxSize];

2.  A lot of the direct lighting code is:

    if shadow directions are normalized
        for each shadow ray
             20-30 lines of code
    else
        for each shadow ray
             normalize
             20-30 lines of code

   I am inclined to bite the bullet and change this to

    if shadow directions are not normalized
        for each shadow ray
             normalize
    for each shadow ray
         20-30 lines of code

    My guess is that extra loop is just not that expensive, and the code
    is cleaner/smaller.

Opinions on either appreciated.  I know profiling is a good answer,
but we don't yet have a full working system with complex models so
I am leery of that now.

I profiled this case and normalizing as you go was slightly faster. The reason is that square roots and divides required by normalization have long latencies, so you can get a lot of other useful work done while you are waiting for those operations to complete. If in doubt, I recommend the simpler version. More specifically, I recommend the simpler version until you have profiled the difference.

This loop:
     if shadow directions are not normalized
         for each shadow ray
              normalize
Can be achieved by doing:
    raypacket.normalizeRayDirections();
(or similar).  It does the check automatically.

Steve





Archive powered by MHonArc 2.6.16.

Top of page