Text archives Help
- From: sparker@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1047 - in trunk: Engine/Shadows Interface Model/Materials Model/Textures
- Date: Mon, 8 May 2006 16:42:13 -0600 (MDT)
Author: sparker
Date: Mon May 8 16:42:03 2006
New Revision: 1047
Modified:
trunk/Engine/Shadows/BeamShadows.cc
trunk/Engine/Shadows/BeamShadows.h
trunk/Engine/Shadows/HardShadows.cc
trunk/Engine/Shadows/HardShadows.h
trunk/Engine/Shadows/NoShadows.cc
trunk/Engine/Shadows/NoShadows.h
trunk/Interface/RayPacket.h
trunk/Interface/ShadowAlgorithm.h
trunk/Model/Materials/AmbientOcclusion.cc
trunk/Model/Materials/Lambertian.cc
trunk/Model/Materials/Phong.cc
trunk/Model/Materials/Transparent.cc
trunk/Model/Textures/CheckerTexture.h
Log:
Redo shadowAlgorithm interface to use masking instead of mapping
Will facilitate vectorization of shading code
Modified: trunk/Engine/Shadows/BeamShadows.cc
==============================================================================
--- trunk/Engine/Shadows/BeamShadows.cc (original)
+++ trunk/Engine/Shadows/BeamShadows.cc Mon May 8 16:42:03 2006
@@ -60,7 +60,6 @@
bool BeamShadows::computeShadows(const RenderContext& context,
const LightSet* lights,
RayPacket& rays, // Input rays.
- int map[], // map from
shadow rays to input rays
RayPacket& shadowRays, // Output
shadow rays, already intersected.
bool firstTime,
StateBuffer& stateBuffer)
Modified: trunk/Engine/Shadows/BeamShadows.h
==============================================================================
--- trunk/Engine/Shadows/BeamShadows.h (original)
+++ trunk/Engine/Shadows/BeamShadows.h Mon May 8 16:42:03 2006
@@ -16,7 +16,7 @@
virtual ~BeamShadows();
virtual bool computeShadows(const RenderContext& context, const
LightSet* lights,
- RayPacket& source, int map[], RayPacket&
shadowRays,
+ RayPacket& source, RayPacket& shadowRays,
bool firstTime, StateBuffer& stateBuffer);
static ShadowAlgorithm* create(const vector<string>& args);
Modified: trunk/Engine/Shadows/HardShadows.cc
==============================================================================
--- trunk/Engine/Shadows/HardShadows.cc (original)
+++ trunk/Engine/Shadows/HardShadows.cc Mon May 8 16:42:03 2006
@@ -25,7 +25,6 @@
bool HardShadows::computeShadows(const RenderContext& context,
const LightSet* lights,
RayPacket& sourceRays, // Input rays.
- int map[], // map from
shadow rays to input rays
RayPacket& shadowRays, // Output
shadow rays, already intersected.
bool firstTime,
StateBuffer& stateBuffer)
@@ -36,67 +35,47 @@
sourceRays.computeHitPositions();
sourceRays.computeNormals( context );
- int sidx = 0;
- int starti, j;
+ int j;
if(firstTime){
- starti = sourceRays.begin();
j = 0;
} else {
- starti = stateBuffer.i1;
- j = stateBuffer.i2;
+ j = stateBuffer.i1;
}
- bool done = true;
- for(; j < nlights; j++){
- // Compute the contribution for this light.
+
+ // Compute the contribution for this light.
+ int last = -1;
+ do {
Color lightColors[RayPacket::MaxSize];
Vector lightDirections[RayPacket::MaxSize];
lights->getLight(j)->computeLight( lightColors, lightDirections,
context, sourceRays);
- for(int i = starti; i < sourceRays.end(); i++){
+ for(int i = sourceRays.begin(); i < sourceRays.end(); i++){
// Check to see if the light is on the front face.
Vector dir = lightDirections[i];
if(Dot(dir, sourceRays.getNormal(i)) > 0) {
-
+
// If so normalize and compute length.
Real length = dir.normalize();
// Populate the shadow ray.
- shadowRays.setRay(sidx, sourceRays.getHitPosition(i), dir );
- shadowRays.setColor(sidx, lightColors[i]);
- shadowRays.resetHit( sidx, length );
- map[sidx] = i;
- if(++sidx >= RayPacket::MaxSize){
- if(i+1 == sourceRays.end()){
- if(j+1 == nlights){
- // Do nothing - we are done
- } else {
- // Save our position but start on the next light
- stateBuffer.i1 = sourceRays.begin();
- stateBuffer.i2 = j+1;
- done = false;
- }
- } else {
- stateBuffer.i1 = i+1;
- stateBuffer.i2 = j;
- done = false;
- }
- // Okay, a goto is nasty, but C++ doesn't have "break 2" and we
need to get
- // out of this loop without too much extra work
- goto break2;
- }
+ shadowRays.setRay(i, sourceRays.getHitPosition(i), dir );
+ shadowRays.setColor(i, lightColors[i]);
+ shadowRays.resetHit(i, length );
+ last = i;
+ } else {
+ shadowRays.maskRay(i);
}
}
-
- starti = sourceRays.begin();
- }
- break2:
+ j++;
+ } while(last == -1 && j < nlights);
// Send the shadow rays.
shadowRays.setFlag(
RayPacket::NormalizedDirections|RayPacket::HaveHitRecords );
- shadowRays.resize ( sidx );
-
+ shadowRays.resize ( last + 1);
context.scene->getObject()->intersect(context, shadowRays);
- return done;
+
+ stateBuffer.i1 = j;
+ return j == nlights;
}
string HardShadows::getName() const {
Modified: trunk/Engine/Shadows/HardShadows.h
==============================================================================
--- trunk/Engine/Shadows/HardShadows.h (original)
+++ trunk/Engine/Shadows/HardShadows.h Mon May 8 16:42:03 2006
@@ -16,7 +16,7 @@
virtual ~HardShadows();
virtual bool computeShadows(const RenderContext& context, const
LightSet* lights,
- RayPacket& source, int map[], RayPacket&
shadowRays,
+ RayPacket& source, RayPacket& shadowRays,
bool firstTime, StateBuffer& stateBuffer);
static ShadowAlgorithm* create(const vector<string>& args);
Modified: trunk/Engine/Shadows/NoShadows.cc
==============================================================================
--- trunk/Engine/Shadows/NoShadows.cc (original)
+++ trunk/Engine/Shadows/NoShadows.cc Mon May 8 16:42:03 2006
@@ -20,7 +20,7 @@
}
bool NoShadows::computeShadows(const RenderContext& context, const LightSet*
lights,
- RayPacket& sourceRays, int map[], RayPacket&
shadowRays,
+ RayPacket& sourceRays, RayPacket& shadowRays,
bool firstTime, StateBuffer& stateBuffer)
{
int nlights = lights->numLights();
@@ -29,63 +29,40 @@
sourceRays.computeHitPositions();
sourceRays.computeNormals( context );
- int sidx = 0;
- int starti, j;
+ int j;
if(firstTime){
- starti = sourceRays.begin();
j = 0;
} else {
- starti = stateBuffer.i1;
- j = stateBuffer.i2;
+ j = stateBuffer.i1;
}
- bool done = true;
- for(; j < nlights; j++){
- // Compute the contribution for this light.
+ // Compute the contribution for this light.
+ int last = -1;
+ do {
Color lightColors[RayPacket::MaxSize];
Vector lightDirections[RayPacket::MaxSize];
lights->getLight(j)->computeLight( lightColors, lightDirections,
context, sourceRays);
- for(int i = starti; i < sourceRays.end(); i++){
+ for(int i = sourceRays.begin(); i < sourceRays.end(); i++){
// Check to see if the light is on the front face.
Vector dir = lightDirections[i];
if(Dot(dir, sourceRays.getNormal(i)) > 0) {
-
+
// If so normalize and compute length.
Real length = dir.normalize();
// Populate the direction and color only
- shadowRays.setDirection(sidx, dir );
- shadowRays.setColor(sidx, lightColors[i]);
- map[sidx] = i;
- if(++sidx >= RayPacket::MaxSize){
- if(i+1 == sourceRays.end()){
- if(j+1 == nlights){
- // Do nothing - we are done
- } else {
- // Save our position but start on the next light
- stateBuffer.i1 = sourceRays.begin();
- stateBuffer.i2 = j+1;
- done = false;
- }
- } else {
- stateBuffer.i1 = i+1;
- stateBuffer.i2 = j;
- done = false;
- }
- // Okay, a goto is nasty, but C++ doesn't have "break 2" and we
need to get
- // out of this loop without too much extra work
- goto break2;
- }
+ shadowRays.setDirection(i, dir );
+ shadowRays.setColor(i, lightColors[i]);
+ shadowRays.resetHit(i);
+ last = i;
+ } else {
+ shadowRays.maskRay(i);
}
}
-
- starti = sourceRays.begin();
- }
- break2:
-
- shadowRays.resize ( sidx );
- shadowRays.resetHits();
- return done;
+ shadowRays.resize (last);
+ } while(last == -1 && j < nlights);
+ stateBuffer.i1 = j;
+ return j == nlights;
}
string NoShadows::getName() const {
Modified: trunk/Engine/Shadows/NoShadows.h
==============================================================================
--- trunk/Engine/Shadows/NoShadows.h (original)
+++ trunk/Engine/Shadows/NoShadows.h Mon May 8 16:42:03 2006
@@ -16,7 +16,7 @@
virtual ~NoShadows();
virtual bool computeShadows(const RenderContext& context, const
LightSet* lights,
- RayPacket& source, int map[], RayPacket&
shadowRays,
+ RayPacket& source, RayPacket& shadowRays,
bool firstTime, StateBuffer& stateBuffer);
static ShadowAlgorithm* create(const vector<string>& args);
Modified: trunk/Interface/RayPacket.h
==============================================================================
--- trunk/Interface/RayPacket.h (original)
+++ trunk/Interface/RayPacket.h Mon May 8 16:42:03 2006
@@ -324,9 +324,17 @@
}
flags |= HaveHitRecords;
}
+ void resetHit(int which) {
+ data->hitMatl[which] = 0;
+ data->minT[which] = MAXT;
+ }
void resetHit(int which, Real maxt) {
data->hitMatl[which] = 0;
data->minT[which] = maxt;
+ }
+ void maskRay(int which) {
+ data->hitMatl[which] = (Material*)0xffffffff;
+ data->minT[which] = -MAXT;
}
Real &getMinT(int which) const
{
Modified: trunk/Interface/ShadowAlgorithm.h
==============================================================================
--- trunk/Interface/ShadowAlgorithm.h (original)
+++ trunk/Interface/ShadowAlgorithm.h Mon May 8 16:42:03 2006
@@ -46,7 +46,7 @@
};
virtual bool computeShadows(const RenderContext& context, const
LightSet* lights,
- RayPacket& source, int map[], RayPacket&
shadowRays,
+ RayPacket& source, RayPacket& shadowRays,
bool firstTime, StateBuffer& stateBuffer) =
0;
virtual std::string getName() const = 0;
Modified: trunk/Model/Materials/AmbientOcclusion.cc
==============================================================================
--- trunk/Model/Materials/AmbientOcclusion.cc (original)
+++ trunk/Model/Materials/AmbientOcclusion.cc Mon May 8 16:42:03 2006
@@ -124,19 +124,18 @@
int map[RayPacket::MaxSize];
RayPacket shadowRays(data, RayPacket::UnknownShape, 0, 0,
rays.getDepth(), 0);
done = context.shadowAlgorithm->computeShadows(context, activeLights,
- rays, map, shadowRays,
+ rays, shadowRays,
firstTime, stateBuffer);
shadowRays.normalizeDirections();
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 normal = rays.getNormal(j);
Vector shadowdir = shadowRays.getDirection(j);
ColorComponent cos_theta = Dot(shadowdir, normal);
Color light = shadowRays.getColor(j);
for(int k = 0; k < Color::NumComponents;k++)
- total[k][to] += light[k]*cos_theta*(ColorComponent)0.6;
+ total[k][j] += light[k]*cos_theta*(ColorComponent)0.6;
}
}
Modified: trunk/Model/Materials/Lambertian.cc
==============================================================================
--- trunk/Model/Materials/Lambertian.cc (original)
+++ trunk/Model/Materials/Lambertian.cc Mon May 8 16:42:03 2006
@@ -59,7 +59,7 @@
// in the state rather than using anything in the state buffer. Most
// sas will only need to store an int or two in the statebuffer.
done = context.shadowAlgorithm->computeShadows(context, activeLights,
- rays, map, shadowRays,
+ rays, shadowRays,
firstTime, stateBuffer);
// We need normalized directions for proper dot product computation.
Modified: trunk/Model/Materials/Phong.cc
==============================================================================
--- trunk/Model/Materials/Phong.cc (original)
+++ trunk/Model/Materials/Phong.cc Mon May 8 16:42:03 2006
@@ -110,7 +110,6 @@
bool done;
int count = 0;
do {
- int map[RayPacket::MaxSize];
RayPacketData shadowData;
RayPacket shadowRays(shadowData, RayPacket::UnknownShape, 0, 0,
rays.getDepth(), 0);
@@ -120,30 +119,29 @@
// in the state rather than using anything in the state buffer. Most
// sas will only need to store an int or two in the statebuffer.
done = context.shadowAlgorithm->computeShadows(context, activeLights,
- rays, map, shadowRays,
+ rays, shadowRays,
firstTime, stateBuffer);
// We need normalized directions for proper dot product computation.
shadowRays.normalizeDirections();
- for(int j=shadowRays.begin(); j < shadowRays.end(); j++){
- if(!shadowRays.wasHit(j)){
+ for(int i=shadowRays.begin(); i < shadowRays.end(); i++){
+ if(!shadowRays.wasHit(i)){
// Not in shadow, so compute the direct and specular contributions.
- int to = map[j];
- Vector normal = rays.getNormal(to);
- Vector shadowdir = shadowRays.getDirection(j);
+ Vector normal = rays.getNormal(i);
+ Vector shadowdir = shadowRays.getDirection(i);
ColorComponent cos_theta = Dot(shadowdir, normal);
- Color light = shadowRays.getColor(j);
+ Color light = shadowRays.getColor(i);
for(int k = 0; k < Color::NumComponents;k++)
- ambientAndDiffuseLight[k][to] += light[k]*cos_theta;
- Vector dir = rays.getDirection(to);
+ ambientAndDiffuseLight[k][i] += light[k]*cos_theta;
+ Vector dir = rays.getDirection(i);
Vector H = shadowdir-dir;
ColorComponent cos_alpha = Dot(H, normal);
if(cos_alpha > 0){
Color::ComponentType length = H.length2();
Color::ComponentType scale = ipow(cos_alpha*cos_alpha/length,
specpow);
for(int k=0;k<Color::NumComponents;k++)
- specularLight[k][to] += light[k] * scale;
+ specularLight[k][i] += light[k] * scale;
}
}
}
Modified: trunk/Model/Materials/Transparent.cc
==============================================================================
--- trunk/Model/Materials/Transparent.cc (original)
+++ trunk/Model/Materials/Transparent.cc Mon May 8 16:42:03 2006
@@ -90,7 +90,7 @@
// in the state rather than using anything in the state buffer. Most
// sas will only need to store an int or two in the statebuffer.
done = context.shadowAlgorithm->computeShadows(context, activeLights,
- rays, map, shadowRays,
+ rays, shadowRays,
firstTime, stateBuffer);
// We need normalized directions for proper dot product computation.
@@ -99,13 +99,12 @@
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 normal = rays.getNormal(j);
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;
+ totalLight[k][j] += light[k]*cos_theta;
}
}
firstTime = false;
Modified: trunk/Model/Textures/CheckerTexture.h
==============================================================================
--- trunk/Model/Textures/CheckerTexture.h (original)
+++ trunk/Model/Textures/CheckerTexture.h Mon May 8 16:42:03 2006
@@ -65,7 +65,7 @@
vv2=-vv2+1;
int i1 = (int)vv1;
int i2 = (int)vv2;
- int which = (i1+i2)%2;
+ int which = (i1+i2)&1;
results.set(i, values[which]);
}
}
- [MANTA] r1047 - in trunk: Engine/Shadows Interface Model/Materials Model/Textures, sparker, 05/08/2006
Archive powered by MHonArc 2.6.16.