Text archives Help
- From: boulos@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r449 - in branches/itanium2: Core/Color Model/Materials
- Date: Thu, 28 Jul 2005 02:25:16 -0600 (MDT)
Author: boulos
Date: Thu Jul 28 02:25:15 2005
New Revision: 449
Modified:
branches/itanium2/Core/Color/ColorSpace.h
branches/itanium2/Model/Materials/Dielectric.cc
Log:
Added Pow and Log functions to ColorSpace for
the calculation of Beer's Law.
Dielectric added Beer's law and now returns
the ambient color when max depth has been
reached.
Modified: branches/itanium2/Core/Color/ColorSpace.h
==============================================================================
--- branches/itanium2/Core/Color/ColorSpace.h (original)
+++ branches/itanium2/Core/Color/ColorSpace.h Thu Jul 28 02:25:15 2005
@@ -20,7 +20,7 @@
ColorSpace(const ColorSpace<Traits>& copy)
{
for(int i=0;i<3;i++)
- data[i]=copy.data[i];
+ data[i]=copy.data[i];
}
ColorSpace& operator=(const ColorSpace<Traits> ©) {
for(int i=0;i<NumComponents;i++)
@@ -44,12 +44,12 @@
// Conversions to concrete color classes
- //
+ //
// This is what I originally did, but I thought that the error
// messages were confusing when you tried to pass the wrong thing
// into the ctor
//
- //template<class C>
+ //template<class C>
// explicit ColorSpace(const C& color) {
// Traits::convertFrom(data, color);
//}
@@ -156,8 +156,26 @@
returnValue.data[i] = Exp(scale*data[i]);
return returnValue;
}
-
- ColorSpace<Traits> attenuate(const ColorSpace<Traits> &scale)
const {
+
+ template<typename Scalar>
+ ColorSpace<Traits> Pow(Scalar exponent) const
+ {
+ using SCIRun::Pow;
+ ColorSpace<Traits> returnValue;
+ for (int i=0; i < NumComponents; i++)
+ returnValue.data[i] = SCIRun::Pow(data[i], exponent);
+ return returnValue;
+ }
+
+ ColorSpace<Traits> Log() const
+ {
+ ColorSpace<Traits> returnValue;
+ for (int i=0; i < NumComponents; i++)
+ returnValue.data[i] = log(data[i]);
+ return returnValue;
+ }
+
+ ColorSpace<Traits> attenuate(const ColorSpace<Traits>
&scale) const {
using SCIRun::Exp;
ColorSpace<Traits> returnValue;
for(int i=0;i<NumComponents;i++)
@@ -172,7 +190,7 @@
data[i] = fillValue;
}
};
-
+
}
#endif
Modified: branches/itanium2/Model/Materials/Dielectric.cc
==============================================================================
--- branches/itanium2/Model/Materials/Dielectric.cc (original)
+++ branches/itanium2/Model/Materials/Dielectric.cc Thu Jul 28 02:25:15
2005
@@ -95,160 +95,170 @@
{
if(rays.getDepth() >= context.scene->getRenderParameters().maxDepth)
{
- for(int i=0;i<rays.getSize();i++)
- rays.setResult(i, Color::white()); // average scene color might be
better
+ activeLights->getAmbientLight()->computeAmbient(context, rays);
+ for(int i=0;i<rays.getSize();i++)
+ {
+ RayPacket::Element& e = rays.get(i);
+ rays.setResult(i, e.ambientLight);
+ }
+ return;
}
- else
+
+
+ rays.computeHitPositions();
+ rays.normalizeDirections();
+ rays.computeNormals(context);
+ if (!(rays.getFlags() & rays.HaveUnitNormals))
{
- rays.computeHitPositions();
- rays.normalizeDirections();
- rays.computeNormals(context);
- if (!(rays.getFlags() & rays.HaveUnitNormals))
- {
- // I would like to replace this with a call to
- // rays.normalizeNormals() but need to add it.
- fprintf(stderr, "Dielectric assumes unit normals\n");
- exit(-1);
- }
-
- double n_values[RayPacket::MaxSize];
- double nt_values[RayPacket::MaxSize];
- Color sigma_a_values[RayPacket::MaxSize];
-
- n->mapValues(context, rays, n_values);
- nt->mapValues(context, rays, nt_values);
- sigma_a->mapValues(context, rays, sigma_a_values);
-
- bool internally_reflected[RayPacket::MaxSize];
- Vector refl_dirs[RayPacket::MaxSize];
- Vector refr_dirs[RayPacket::MaxSize];
- float fresnel_coeffs[RayPacket::MaxSize]; // might be better to compute
- int num_internal = 0;
- int num_branch = 0;
+ // I would like to replace this with a call to
+ // rays.normalizeNormals() but need to add it.
+ fprintf(stderr, "Dielectric assumes unit normals\n");
+ exit(-1);
+ }
- for(int i=0;i<rays.getSize();i++)
+ double n_values[RayPacket::MaxSize];
+ double nt_values[RayPacket::MaxSize];
+ Color sigma_a_values[RayPacket::MaxSize];
+
+ n->mapValues(context, rays, n_values);
+ nt->mapValues(context, rays, nt_values);
+ sigma_a->mapValues(context, rays, sigma_a_values);
+
+ bool internally_reflected[RayPacket::MaxSize];
+ Vector refl_dirs[RayPacket::MaxSize];
+ Vector refr_dirs[RayPacket::MaxSize];
+ float fresnel_coeffs[RayPacket::MaxSize]; // might be better to compute
+ int num_internal = 0;
+ int num_branch = 0;
+
+ for(int i=0;i<rays.getSize();i++)
+ {
+ RayPacket::Element& e = rays.get(i);
+ double cosine = -Dot(e.normal, e.ray.direction());
+ Vector refl_dir, refr_dir;
+ bool from_outside = (cosine > 0);
+ bool total_internal_reflection;
+ refr_dir = e.ray.direction();
+ refl_dir = e.ray.direction() + 2 * cosine * e.normal;
+
+ if (from_outside)
{
- RayPacket::Element& e = rays.get(i);
- double cosine = -Dot(e.normal, e.ray.direction());
- Vector refl_dir, refr_dir;
- bool from_outside = (cosine > 0);
- bool total_internal_reflection;
- refr_dir = e.ray.direction();
- refl_dir = e.ray.direction() + 2 * cosine * e.normal;
-
- if (from_outside)
- {
- // refract changes the refr_dir
- total_internal_reflection = !Refract(e.normal,
- n_values[i],
- nt_values[i],
- refr_dir);
- }
- else
- {
- total_internal_reflection = !Refract(-e.normal,
- nt_values[i],
- n_values[i],
- refr_dir);
- cosine = -cosine;
- }
+ // refract changes the refr_dir
+ total_internal_reflection = !Refract(e.normal,
+ n_values[i],
+ nt_values[i],
+ refr_dir);
+ }
+ else
+ {
+ total_internal_reflection = !Refract(-e.normal,
+ nt_values[i],
+ n_values[i],
+ refr_dir);
+ cosine = -cosine;
+ }
- if (total_internal_reflection)
- {
- internally_reflected[i] = true;
- num_internal++;
- refl_dirs[i] = refl_dir;
- }
- else // reflection and refraction
- {
- float cosine2;
- if (from_outside) {
- cosine2 = -Dot(e.normal, refr_dir);
- }
- else {
- cosine2 = Dot(e.normal, refr_dir);
- }
-
- if (cosine2 < cosine) cosine = cosine2; // for Schlick
- float k = 1 - cosine;
- k*=k*k*k*k;
-
- double r0 = (n_values[i] - nt_values[i]) / (n_values[i] +
nt_values[i]);
- r0 *= r0;
- float R = r0*(1-k) + k;
-
- internally_reflected[i] = false;
- num_branch++;
- refl_dirs[i] = refl_dir;
- refr_dirs[i] = refr_dir;
- fresnel_coeffs[i] = R;
- }
- }
-
- // okay we've got everything ready now
-
- RayPacketData total_internal_data;
- RayPacketData reflected_data;
- RayPacketData refracted_data;
-
- RayPacket internal_rays(total_internal_data, num_internal,
rays.getDepth()+1, RayPacket::NormalizedDirections);
- RayPacket reflected_rays(reflected_data, num_branch,
rays.getDepth()+1, RayPacket::NormalizedDirections);
- RayPacket refracted_rays(refracted_data, num_branch,
rays.getDepth()+1, RayPacket::NormalizedDirections);
-
- internal_rays.useLocalColors();
- reflected_rays.useLocalColors();
- refracted_rays.useLocalColors();
-
- // for accessing ray packet elements between the 3 sets (or 2 pairs
really)
- int internal_counter = 0;
- int branch_counter = 0;
- // fill in the raypackets
- for (int i = 0; i < rays.getSize(); i++)
+ if (total_internal_reflection)
{
- RayPacket::Element& e = rays.get(i);
+ internally_reflected[i] = true;
+ num_internal++;
+ refl_dirs[i] = refl_dir;
+ }
+ else // reflection and refraction
+ {
+ float cosine2;
+ if (from_outside) {
+ cosine2 = -Dot(e.normal, refr_dir);
+ }
+ else {
+ cosine2 = Dot(e.normal, refr_dir);
+ }
+
+ if (cosine2 < cosine) cosine = cosine2; // for Schlick
+ float k = 1 - cosine;
+ k*=k*k*k*k;
+
+ double r0 = (n_values[i] - nt_values[i]) / (n_values[i] +
nt_values[i]);
+ r0 *= r0;
+ float R = r0*(1-k) + k;
+
+ internally_reflected[i] = false;
+ num_branch++;
+ refl_dirs[i] = refl_dir;
+ refr_dirs[i] = refr_dir;
+ fresnel_coeffs[i] = R;
+ }
+ }
- if (internally_reflected[i])
- {
- RayPacket::Element& r = internal_rays.get(internal_counter);
- r.ray.set(e.hitPosition, refl_dirs[i]);
- internal_counter++;
- }
- else
- {
- RayPacket::Element& refl = reflected_rays.get(branch_counter);
- refl.ray.set(e.hitPosition, refl_dirs[i]);
- RayPacket::Element& refr = refracted_rays.get(branch_counter);
- refr.ray.set(e.hitPosition, refr_dirs[i]);
- branch_counter++;
- }
+ // okay we've got everything ready now
+
+ RayPacketData total_internal_data;
+ RayPacketData reflected_data;
+ RayPacketData refracted_data;
+
+ RayPacket internal_rays(total_internal_data, num_internal,
rays.getDepth()+1, RayPacket::NormalizedDirections);
+ RayPacket reflected_rays(reflected_data, num_branch, rays.getDepth()+1,
RayPacket::NormalizedDirections);
+ RayPacket refracted_rays(refracted_data, num_branch, rays.getDepth()+1,
RayPacket::NormalizedDirections);
+
+ internal_rays.useLocalColors();
+ reflected_rays.useLocalColors();
+ refracted_rays.useLocalColors();
+
+ // for accessing ray packet elements between the 3 sets (or 2 pairs really)
+ int internal_counter = 0;
+ int branch_counter = 0;
+ // fill in the raypackets
+ for (int i = 0; i < rays.getSize(); i++)
+ {
+ RayPacket::Element& e = rays.get(i);
+
+ if (internally_reflected[i])
+ {
+ RayPacket::Element& r = internal_rays.get(internal_counter);
+ r.ray.set(e.hitPosition, refl_dirs[i]);
+ internal_counter++;
}
+ else
+ {
+ RayPacket::Element& refl = reflected_rays.get(branch_counter);
+ refl.ray.set(e.hitPosition, refl_dirs[i]);
+ RayPacket::Element& refr = refracted_rays.get(branch_counter);
+ refr.ray.set(e.hitPosition, refr_dirs[i]);
+ branch_counter++;
+ }
+ }
- // fire them off
- context.renderer->traceRays(context, reflected_rays);
- context.renderer->traceRays(context, refracted_rays);
- context.renderer->traceRays(context, internal_rays);
-
- internal_counter = 0;
- branch_counter = 0;
- // compute their results
- for (int i = 0; i < rays.getSize(); i++)
- {
- if (internally_reflected[i])
- {
- RayPacket::Element& r = internal_rays.get(internal_counter);
- // TODO: Apply beer's law attenuation to total internal
reflection ray.
- rays.setResult(i, *r.color);
- internal_counter++;
- }
- else
- {
- RayPacket::Element& refl = reflected_rays.get(branch_counter);
- RayPacket::Element& refr = refracted_rays.get(branch_counter);
- // TODO: Apply beer's law attenuation to refracted ray
- rays.setResult(i,
(Color::white()*fresnel_coeffs[i])*(*refl.color) +
-
(Color::white()*(1.-fresnel_coeffs[i]))*(*refr.color) );
- branch_counter++;
- }
+ // fire them off
+ context.renderer->traceRays(context, reflected_rays);
+ context.renderer->traceRays(context, refracted_rays);
+ context.renderer->traceRays(context, internal_rays);
+
+ internal_counter = 0;
+ branch_counter = 0;
+ // compute their results
+ for (int i = 0; i < rays.getSize(); i++)
+ {
+ if (internally_reflected[i])
+ {
+ RayPacket::Element& r = internal_rays.get(internal_counter);
+ // These two Beer's law calculations are equivalent, but
+ // one may be faster than the other
+ //(*r.color) *=
sigma_a_values[i].Log().attenuate(r.hitInfo.minT());
+ (*r.color) *= sigma_a_values[i].Pow(r.hitInfo.minT());
+ rays.setResult(i, *r.color);
+ internal_counter++;
+ }
+ else
+ {
+ RayPacket::Element& refl = reflected_rays.get(branch_counter);
+ RayPacket::Element& refr = refracted_rays.get(branch_counter);
+ // These two Beer's law calculations are equivalent, but
+ // one may be faster than the other
+ //(*refr.color) *=
sigma_a_values[i].Log().attenuate(refr.hitInfo.minT());
+ (*refr.color) *= sigma_a_values[i].Pow(refr.hitInfo.minT());
+ rays.setResult(i, (Color::white()*fresnel_coeffs[i])*(*refl.color)
+
+
(Color::white()*(1.-fresnel_coeffs[i]))*(*refr.color) );
+ branch_counter++;
}
}
}
- [MANTA] r449 - in branches/itanium2: Core/Color Model/Materials, boulos, 07/28/2005
Archive powered by MHonArc 2.6.16.