Text archives Help
- From: sparker@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r760 - in trunk: Engine/Renderers Interface Model/Instances Model/Materials Model/MiscObjects scenes
- Date: Fri, 9 Dec 2005 15:50:03 -0700 (MST)
Author: sparker
Date: Fri Dec 9 15:50:03 2005
New Revision: 760
Modified:
trunk/Engine/Renderers/Raytracer.cc
trunk/Interface/RayPacket.h
trunk/Interface/RenderParameters.h
trunk/Model/Instances/Instance.cc
trunk/Model/Materials/CMakeLists.txt
trunk/Model/Materials/Dielectric.cc
trunk/Model/Materials/Dielectric.h
trunk/Model/Materials/Phong.cc
trunk/Model/MiscObjects/CuttingPlane.cc
trunk/Model/MiscObjects/Difference.cc
trunk/scenes/BARTReader.cc
trunk/scenes/primtest.cc
Log:
re-implemented Dielectric (doesn't quite work yet, but it looks nice)
Restored ray importance for ray tree pruning
Added dielectric material option to primtest
Minor fix to BART reader to get it to compile
Modified: trunk/Engine/Renderers/Raytracer.cc
==============================================================================
--- trunk/Engine/Renderers/Raytracer.cc (original)
+++ trunk/Engine/Renderers/Raytracer.cc Fri Dec 9 15:50:03 2005
@@ -40,6 +40,7 @@
{
ASSERT(rays.getFlag(RayPacket::HaveImageCoordinates));
context.camera->makeRays(rays);
+ rays.initializeImportance();
traceRays(context, rays);
}
Modified: trunk/Interface/RayPacket.h
==============================================================================
--- trunk/Interface/RayPacket.h (original)
+++ trunk/Interface/RayPacket.h Fri Dec 9 15:50:03 2005
@@ -35,7 +35,6 @@
ConstantSigns = 0x1000
};
-
inline RayPacket(RayPacketData& data, int size, int depth, int flags);
// Create a subset of another raypacket
@@ -95,9 +94,10 @@
Point hitPosition;
Point texCoords;
Vector inverseDirection;
- int sign[3]; // Mask describing ray direction, 1==negative
0==positive,zero
+ int sign[3]; // Mask describing ray direction, 1==negative
0==positive,zero
Color ambientLight;
Color light;
+ Color importance; // 1-attenuation, where eye rays have importance
== 1
int shadowBegin, shadowEnd;
int whichEye;
@@ -117,6 +117,7 @@
data[which].imageY = imageY;
data[which].whichEye = whichEye;
}
+
void useLocalColors() {
for(int i=0;i<size;i++)
data[i].color = &data[i].localColor;
@@ -237,9 +238,24 @@
flags |= HaveNormals;
}
+ void normalizeNormals()
+ {
+ ASSERT(flags & HaveNormals);
+ if(flags & HaveUnitNormals)
+ return;
+ for(int i=0;i<size;i++)
+ data[i].normal.normalize();
+ flags |= HaveUnitNormals;
+ }
int getDepth() const {
return depth;
+ }
+
+ void initializeImportance()
+ {
+ for(int i=0;i<size;i++)
+ data[i].importance = Color::white();
}
private:
RayPacket(const RayPacket&);
Modified: trunk/Interface/RenderParameters.h
==============================================================================
--- trunk/Interface/RenderParameters.h (original)
+++ trunk/Interface/RenderParameters.h Fri Dec 9 15:50:03 2005
@@ -7,8 +7,10 @@
public:
RenderParameters() {
maxDepth = 15;
+ importanceCutoff = 0.01;
}
int maxDepth;
+ Real importanceCutoff;
private:
};
}
Modified: trunk/Model/Instances/Instance.cc
==============================================================================
--- trunk/Model/Instances/Instance.cc (original)
+++ trunk/Model/Instances/Instance.cc Fri Dec 9 15:50:03 2005
@@ -89,12 +89,12 @@
// Instance was hit
Real s = scales[i];
if(e.hitInfo.hit(te.hitInfo.minT()*s, material, this, tex)){
- // Instance is now the closest
- Real is = inv_scales[i];
- e.hitInfo.scratchpad<MPTscale>() =
MPTscale(te.hitInfo.hitMaterial(),
-
te.hitInfo.hitPrimitive(),
-
te.hitInfo.hitTexCoordMapper(),
-
s, is);
+ // Instance is now the closest
+ Real is = inv_scales[i];
+ e.hitInfo.scratchpad<MPTscale>() = MPTscale(te.hitInfo.hitMaterial(),
+
te.hitInfo.hitPrimitive(),
+
te.hitInfo.hitTexCoordMapper(),
+ s, is);
}
}
}
Modified: trunk/Model/Materials/CMakeLists.txt
==============================================================================
--- trunk/Model/Materials/CMakeLists.txt (original)
+++ trunk/Model/Materials/CMakeLists.txt Fri Dec 9 15:50:03 2005
@@ -4,8 +4,8 @@
Materials/AmbientOcclusion.cc
Materials/Checker.h
Materials/Checker.cc
-# Materials/Dielectric.h
-# Materials/Dielectric.cc
+ Materials/Dielectric.h
+ Materials/Dielectric.cc
Materials/Flat.h
Materials/Flat.cc
Materials/Lambertian.h
Modified: trunk/Model/Materials/Dielectric.cc
==============================================================================
--- trunk/Model/Materials/Dielectric.cc (original)
+++ trunk/Model/Materials/Dielectric.cc Fri Dec 9 15:50:03 2005
@@ -42,7 +42,8 @@
using namespace Manta;
Dielectric::Dielectric(const Texture<Real>* n, const Texture<Real>* nt,
- const Texture<Color>* sigma_a)
+ const Texture<Color>* sigma_a,
+ Real cutoff)
: n(n), nt(nt), sigma_a(sigma_a)
{
@@ -56,26 +57,18 @@
{
if(rays.getDepth() >= context.scene->getRenderParameters().maxDepth)
{
- 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;
+ for(int i=0;i<rays.getSize();i++)
+ {
+ RayPacket::Element& e = rays.get(i);
+ rays.setResult(i, Color::black());
+ }
+ return;
}
-
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);
- }
+ rays.normalizeNormals();
Real n_values[RayPacket::MaxSize];
Real nt_values[RayPacket::MaxSize];
@@ -85,169 +78,114 @@
nt->mapValues(context, rays, nt_values);
sigma_a->mapValues(context, rays, sigma_a_values);
- Vector refl_dirs[RayPacket::MaxSize];
- Vector refr_dirs[RayPacket::MaxSize];
- Real fresnel_coeffs[RayPacket::MaxSize]; // might be better to compute
- Color beers_colors[RayPacket::MaxSize];
- Real beers_coeffs[RayPacket::MaxSize];
- bool internally_reflected[RayPacket::MaxSize];
- bool apply_beers[RayPacket::MaxSize];
- bool kill_ray[RayPacket::MaxSize];
-
- int num_internal = 0;
- int num_branch = 0;
-
- for(int i=0;i<rays.getSize();i++)
- {
- RayPacket::Element& e = rays.get(i);
-
- if ( e.importance < (Real)0.05 )
- {
- kill_ray[i] = true;
- continue;
- }
- else
- {
- kill_ray[i] = false;
- }
-
- Vector N = e.normal;
- Real n_dot_v = Dot(N, e.ray.direction());
- Real eta_tmp;
- Real eta_tmp_inv;
- bool was_incoming = ( n_dot_v < 0 );
- if ( was_incoming )
- {
- eta_tmp = n_values[i]/nt_values[i];
- eta_tmp_inv = 1 / eta_tmp;
- n_dot_v = -n_dot_v;
- apply_beers[i] = false;
- beers_coeffs[i] = 1;// allows blind multiplication
- }
- else
- {
- N = -N;
- eta_tmp = nt_values[i]/n_values[i];
- eta_tmp_inv = 1 / eta_tmp;
- apply_beers[i] = true;
- beers_colors[i] = sigma_a_values[i].Pow(e.hitInfo.minT());
- beers_coeffs[i] = beers_colors[i].Mean();
- }
-
- Real cosine = 1 + (n_dot_v*n_dot_v - 1) * (eta_tmp_inv*eta_tmp_inv);
- if ( cosine <= 0 )
- {
- // total internal reflection
- Vector refl_dir = e.ray.direction() + 2*n_dot_v*N;
- internally_reflected[i] = true;
- refl_dirs[i] = refl_dir;
- num_internal++;
- }
- else
- {
- cosine = (cosine > 0) ? Sqrt(cosine) : 0;
- // Real cos_min = ( cosine > n_dot_v ) ? n_dot_v : cosine;
- Real k = 1 - cosine;
- k*=k*k*k*k;
-
- Real r0 = (n_values[i] - nt_values[i]) / (n_values[i] +
nt_values[i]);
- r0 *= r0;
- Real R = r0*(1-k) + k;
-
- Vector refr_dir = (e.ray.direction()*eta_tmp_inv +
- (n_dot_v*eta_tmp_inv - cosine) * N);
- Vector refl_dir = e.ray.direction() + 2*n_dot_v*N;
-
- 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);
+ RayPacket reflected_rays(reflected_data, 0, rays.getDepth()+1,
RayPacket::NormalizedDirections);
+ RayPacket refracted_rays(refracted_data, 0, 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++)
+
+ Color refl_attenuation[RayPacket::MaxSize];
+ Color refr_attenuation[RayPacket::MaxSize];
+
+ int refl_source[RayPacket::MaxSize];
+ int num_refl = 0;
+ int refr_source[RayPacket::MaxSize];
+ int num_refr = 0;
+
+ Real cutoff = localCutoffScale *
context.scene->getRenderParameters().importanceCutoff;
+
+ // Compute coefficients and set up raypackets
+ for(int i=0;i<rays.getSize();i++)
{
- RayPacket::Element& e = rays.get(i);
- if (kill_ray[i])
- continue;
+ RayPacket::Element& e = rays.get(i);
+ *e.color = Color::black();
- if (internally_reflected[i])
- {
- RayPacket::Element& r = internal_rays.get(internal_counter);
- r.ray.set(e.hitPosition, refl_dirs[i]);
- r.importance = e.importance * beers_coeffs[i];
- internal_counter++;
- }
- else
- {
- RayPacket::Element& refl = reflected_rays.get(branch_counter);
- refl.ray.set(e.hitPosition, refl_dirs[i]);
- refl.importance = e.importance * fresnel_coeffs[i] *
beers_coeffs[i];
- RayPacket::Element& refr = refracted_rays.get(branch_counter);
- refr.ray.set(e.hitPosition, refr_dirs[i]);
- refr.importance = e.importance * (1 - fresnel_coeffs[i]) *
beers_coeffs[i];
- branch_counter++;
+ Real n_dot_v = Dot(e.normal, e.ray.direction());
+ Real eta_tmp_inv;
+ bool was_incoming = ( n_dot_v < 0 );
+ Color beers_color;
+ if ( was_incoming )
+ {
+ eta_tmp_inv = nt_values[i]/n_values[i];
+ n_dot_v = -n_dot_v;
+ beers_color = Color::white();
+ }
+ else
+ {
+ e.normal = -e.normal;
+ eta_tmp_inv = n_values[i]/nt_values[i];
+ beers_color = sigma_a_values[i].Pow(e.hitInfo.minT());
+ }
+
+ Real cosine_sq = 1 + (n_dot_v*n_dot_v - 1) * (eta_tmp_inv*eta_tmp_inv);
+ if ( cosine_sq <= 0 )
+ {
+ // total internal reflection - no attenuation
+ RayPacket::Element& r = reflected_rays.get(num_refl);
+ r.importance = e.importance * beers_color;
+ if(r.importance.luminance() > cutoff){
+ Vector refl_dir = e.ray.direction() + 2*n_dot_v*e.normal;
+ r.ray.set(e.hitPosition, refl_dir);
+ refl_source[num_refl] = i;
+ num_refl++;
+ }
+ }
+ else
+ {
+ Real cosine = Sqrt(cosine);
+ Real k = 1 - cosine;
+ k*=(k*k)*(k*k);
+
+ Real r0 = (n_values[i] - nt_values[i]) / (n_values[i] + nt_values[i]);
+ r0 *= r0;
+ Real R = r0*(1-k) + k;
+
+ // Possibly create refraction ray
+ refr_attenuation[num_refr] = beers_color * (1-R);
+ RayPacket::Element& refr = refracted_rays.get(num_refr);
+ refr.importance = e.importance * refr_attenuation[num_refr];
+ if(refr.importance.luminance() > cutoff){
+ Vector refr_dir = (e.ray.direction()*eta_tmp_inv +
+ (n_dot_v*eta_tmp_inv - cosine) * e.normal);
+ refr.ray.set(e.hitPosition, refr_dir);
+ refr_source[num_refr] = i;
+ num_refr++;
+ }
+
+ // Possibly create reflection ray
+ refl_attenuation[num_refl] = beers_color * R;
+ RayPacket::Element& refl = reflected_rays.get(num_refl);
+ refl.importance = e.importance * refl_attenuation[num_refl];
+ if(refl.importance.luminance() > cutoff){
+ Vector refl_dir = e.ray.direction() + (2*n_dot_v)*e.normal;
+ refl.ray.set(e.hitPosition, refl_dir);
+ refl_source[num_refl] = i;
+ num_refl++;
}
+ }
}
// fire them off
+ reflected_rays.resize(num_refl);
+ refracted_rays.resize(num_refr);
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++)
+ for (int i = 0; i < num_refl; i++)
{
- RayPacket::Element& e = rays.get(i);
- if (kill_ray[i])
- {
- rays.setResult(i, Color::black());
- continue;
- }
-
- if (internally_reflected[i])
- {
- RayPacket::Element& r = internal_rays.get(internal_counter);
-
- rays.setResult(i, *r.color);
- internal_counter++;
- }
- else
- {
- RayPacket::Element& refl = reflected_rays.get(branch_counter);
- RayPacket::Element& refr = refracted_rays.get(branch_counter);
-
- rays.setResult(i, (Color::white()*fresnel_coeffs[i])*(*refl.color)
+
- (Color::white()*(1-fresnel_coeffs[i]))*(*refr.color)
);
-
- branch_counter++;
- }
-
- if (apply_beers[i])
- {
- *e.color *= beers_colors[i];
- }
+ RayPacket::Element& r = reflected_rays.get(i);
+ RayPacket::Element& e = rays.get(refl_source[i]);
+ *e.color += refl_attenuation[i] * r.localColor;
+ }
+ for (int i = 0; i < num_refr; i++)
+ {
+ RayPacket::Element& r = refracted_rays.get(i);
+ RayPacket::Element& e = rays.get(refr_source[i]);
+ *e.color += refr_attenuation[i] * r.localColor;
}
}
-
Modified: trunk/Model/Materials/Dielectric.h
==============================================================================
--- trunk/Model/Materials/Dielectric.h (original)
+++ trunk/Model/Materials/Dielectric.h Fri Dec 9 15:50:03 2005
@@ -42,22 +42,26 @@
class Dielectric : public LitMaterial
{
public:
- Dielectric(const Real n, const Real nt, const Color
&sigma_a)
- : n(new Constant<Real>(n)),
- nt(new Constant<Real>(nt)),
- sigma_a(new Constant<Color>(sigma_a))
- { }
+ Dielectric(const Real n, const Real nt, const Color &sigma_a,
+ Real localCutoffScale = 1)
+ : n(new Constant<Real>(n)),
+ nt(new Constant<Real>(nt)),
+ sigma_a(new Constant<Color>(sigma_a)),
+ localCutoffScale(localCutoffScale)
+ { }
- Dielectric(const Texture<Real>* n, const Texture<Real>* nt,
- const Texture<Color>* sigma_a);
- ~Dielectric();
+ Dielectric(const Texture<Real>* n, const Texture<Real>* nt,
+ const Texture<Color>* sigma_a,
+ Real localCutoffScale = 1);
+ ~Dielectric();
- void shade(const RenderContext& context, RayPacket& rays) const;
+ void shade(const RenderContext& context, RayPacket& rays) const;
private:
- const Texture<Real>* n;
- const Texture<Real>* nt;
- const Texture<Color>* sigma_a;
+ const Texture<Real>* n;
+ const Texture<Real>* nt;
+ const Texture<Color>* sigma_a;
+ Real localCutoffScale;
};
}
Modified: trunk/Model/Materials/Phong.cc
==============================================================================
--- trunk/Model/Materials/Phong.cc (original)
+++ trunk/Model/Materials/Phong.cc Fri Dec 9 15:50:03 2005
@@ -118,6 +118,7 @@
e.normal*(2*Dot(e.normal, e.ray.direction() )));
RayPacket::Element& r = refl_rays.get(i);
r.ray.set(e.hitPosition, refl_dir);
+ r.importance = e.importance * refl[i];
}
refl_rays.resetHit();
context.renderer->traceRays(context, refl_rays);
Modified: trunk/Model/MiscObjects/CuttingPlane.cc
==============================================================================
--- trunk/Model/MiscObjects/CuttingPlane.cc (original)
+++ trunk/Model/MiscObjects/CuttingPlane.cc Fri Dec 9 15:50:03 2005
@@ -30,7 +30,7 @@
// Send a new ray packet with new ray origins.
RayPacketData new_data;
- RayPacket new_rays( new_data, rays.getSize(), rays.getDepth(),
rays.getAllFlags() );
+ RayPacket new_rays( new_data, rays.getSize(), rays.getDepth(),
rays.getAllFlags());
rays.normalizeDirections();
rays.computeInverseDirections();
Modified: trunk/Model/MiscObjects/Difference.cc
==============================================================================
--- trunk/Model/MiscObjects/Difference.cc (original)
+++ trunk/Model/MiscObjects/Difference.cc Fri Dec 9 15:50:03 2005
@@ -31,7 +31,7 @@
{
RayPacketData raydata1;
RayPacket object1_rays(raydata1, rays.getSize(), rays.getDepth(),
- rays.getAllFlags());
+ rays.getAllFlags());
RayPacketData raydata2;
RayPacket object2_rays(raydata2, rays.getSize(), rays.getDepth(),
rays.getAllFlags());
Modified: trunk/scenes/BARTReader.cc
==============================================================================
--- trunk/scenes/BARTReader.cc (original)
+++ trunk/scenes/BARTReader.cc Fri Dec 9 15:50:03 2005
@@ -2,7 +2,7 @@
#include <Core/Exceptions/IllegalArgument.h>
#include <Core/Util/Args.h>
#include <Interface/Scene.h>
-#include <Readers/BART/parse.h>
+#include <Model/Readers/BART/parse.h>
#include <Core/Util/NotFinished.h>
#include <sgi_stl_warnings_off.h>
Modified: trunk/scenes/primtest.cc
==============================================================================
--- trunk/scenes/primtest.cc (original)
+++ trunk/scenes/primtest.cc Fri Dec 9 15:50:03 2005
@@ -12,6 +12,7 @@
#include <Model/Groups/Group.h>
#include <Model/Lights/PointLight.h>
#include <Model/Materials/Checker.h>
+#include <Model/Materials/Dielectric.h>
#include <Model/Materials/Lambertian.h>
#include <Model/Materials/MetalMaterial.h>
#include <Model/Materials/Phong.h>
@@ -167,6 +168,10 @@
Image *img = readTGA( imageName );
matl = new Lambertian( new ImageTexture<Color>( img ) );
mapr = new UniformMapper();
+ }
+ else if(material == "dielectric")
+ {
+ matl = new Dielectric(1.6, 1.0, Color(RGB(.9, .8, .8)));
}
else
throw IllegalArgument("Unknown material type for primtest: "+material,
0, args);
- [MANTA] r760 - in trunk: Engine/Renderers Interface Model/Instances Model/Materials Model/MiscObjects scenes, sparker, 12/09/2005
Archive powered by MHonArc 2.6.16.