Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] Vertical branch is now in the trunk


Chronological Thread 
  • From: James Bigler <bigler@cs.utah.edu>
  • To: manta@sci.utah.edu
  • Subject: [MANTA] Vertical branch is now in the trunk
  • Date: Tue, 24 Jan 2006 16:21:14 -0700

This is what I've been composing for the list.  Can you take a look at this 
please?

Thanks,
James

Some things to take note of.

There is no more HitInfo or RayPacket::Element class. All the functionality of the HitInfo and RayPacket::Element classes has been moved into the RayPacket class. Also, ray packet indexing doesn't always start at zero, so you should iterate from RayPacket::begin() to RayPacket::end().

Before:

for(int i = 0; i < rays.getSize(); i++) {
  RayPacket::Element& e = rays.get(i);

  if(e.hitInfo().wasHit()) {
   Real n_dot_d = Dot (e.normal, e.ray.direction());
  }
}

After:

for(int i = rays.begin(); i < rays.end(); i++ ) {
  if(rays.wasHit(i)) {
    Real n_dot_d = Dot(rays.getNormal(i), rays.getDirection(i));
  }
}

You must use the accessor functions to get data in to and out of the RayPacket (i.e. getNormal() and setNormal()). This provides opportunity to unpack and pack the data from vertical to horizontal representation. If you plan to something several times like the normal or ray direction, you should make a local copy rather than accessing it from the ray packet each time. This will help prevent unnecessary packing.

----------------------------------------------------------------------
The shadow algorithm interface has also changed.

There's now an int map[] that defines the which ray is the parent of the shadow ray. If you can generate more than one shadow ray for each ray packet element, this will help you.

You tell when you are done with the shadow rays by checking the boolean return statement. There is also a class that holds state from one iteration of the shadow generator to the next. It is filled if the the firstTime parameter is true. After calling computeShadows once, you should pass false in for this.

Here's an example from Lambertian.cc.

Before:

activeLights->getAmbientLight()->computeAmbient(context, rays);

int start = 0;

do {
  RayPacket shadowRays(data, 0, rays.getDepth(), 0);
  int end = context.shadowAlgorithm->computeShadows(context, activeLights,
                                                    rays, start, shadowRays);

  for(int i=start;i<end;i++){
    RayPacket::Element& e = rays.get(i);
    Color totalLight(e.ambientLight);
    for(int j=e.shadowBegin;j<e.shadowEnd;j++){
      RayPacket::Element& s = shadowRays.get(j);
      if(!s.hitInfo.wasHit()){
        ColorComponent cos_theta = Dot(s.ray.direction(), e.normal);
        totalLight += s.light*cos_theta;
      }
    }
    rays.setResult(i, colors[i]*totalLight);
  }
  start = end;
} while (start < rays.getSize());

After:---------------------------------------------------------------

ColorArray totalLight;
activeLights->getAmbientLight()->computeAmbient(context, rays, totalLight);

ShadowAlgorithm::StateBuffer stateBuffer;
bool firstTime = true;
bool done;

do {
  int map[RayPacket::MaxSize];
  RayPacket shadowRays(shadowData, 0, 0, rays.getDepth(), 0);

  done = context.shadowAlgorithm->computeShadows(context, activeLights,
                                                 rays, map, shadowRays,
                                                 firstTime, stateBuffer);

  for(int j=shadowRays.begin(); j < shadowRays.end(); j++){
    if(!shadowRays.wasHit(j)){
      // Not in shadow, so compute the direct and specular contributions.
      int to = map[j];
      Vector normal = rays.getNormal(to);
      Vector shadowdir = shadowRays.getDirection(j);
      ColorComponent cos_theta = Dot(shadowdir, normal);
      Color light = shadowRays.getColor(j);
      for(int k = 0; k < Color::NumComponents;k++)
        totalLight[k][to] += light[k]*cos_theta;
    }
  }
  firstTime = false;
} while(!done);


// Sum up diffuse/specular contributions
for(int i = rays.begin(); i < rays.end(); i++){
  Color result;
  for(int j=0;j<Color::NumComponents;j++)
    result[j] = totalLight[j][i] * diffuse[i][j];
  rays.setColor(i, result);
}


James





  • [MANTA] Vertical branch is now in the trunk, James Bigler, 01/24/2006

Archive powered by MHonArc 2.6.16.

Top of page