Text archives Help
- From: boulos@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [Manta] r1980 - in trunk: Core/Math Engine/Renderers Interface Model/Cameras Model/Lights Model/Materials
- Date: Wed, 9 Jan 2008 13:40:27 -0700 (MST)
Author: boulos
Date: Wed Jan 9 13:40:24 2008
New Revision: 1980
Modified:
trunk/Core/Math/SSEDefs.h
trunk/Engine/Renderers/KajiyaPathtracer.cc
trunk/Interface/RayPacket.h
trunk/Model/Cameras/PinholeCamera.cc
trunk/Model/Lights/AreaLight.cc
trunk/Model/Materials/Dielectric.cc
trunk/Model/Materials/MetalMaterial.cc
trunk/Model/Materials/Phong.cc
trunk/Model/Materials/ThinDielectric.cc
trunk/Model/Materials/Transparent.cc
Log:
Core/Math/SSEDefs.h
Removing tabs.
Interface/RayPacket.h
Engine/Renderers/KajiyaPathtracer.cc
Model/Cameras/PinholeCamera.cc
Model/Lights/AreaLight.cc
Model/Materials/Dielectric.cc
Model/Materials/MetalMaterial.cc
Model/Materials/Phong.cc
Model/Materials/ThinDielectric.cc
Model/Materials/Transparent.cc
Adding ignoreEmittedLight flag to rays to avoid double counting area
lights. In theory, this works for the path tracer now and doesn't
bother the standard ray tracer, but it's hard to tell.
Modified: trunk/Core/Math/SSEDefs.h
==============================================================================
--- trunk/Core/Math/SSEDefs.h (original)
+++ trunk/Core/Math/SSEDefs.h Wed Jan 9 13:40:24 2008
@@ -75,12 +75,12 @@
sse_t sse;
float f[4];
};
-
+
union sse_int_union
{
__m128i ssei;
int i[4];
- };
+ };
#ifndef MANTA_SSE_GCC
// Stores 1 64 bit int twice in 4 32 bit ints
@@ -96,7 +96,7 @@
const int low = ( 0xFFFFFFFFL & val);
return _mm_set_epi32(high, low, high, low);
}
-
+
#endif
#ifndef MANTA_SSE_CAST
@@ -106,7 +106,7 @@
static inline __m128d _mm_castps_pd (__m128 val) { union { __m128 f;
__m128d d;} c; c.f = val; return c.d; }
static inline __m128 _mm_castpd_ps (__m128d val) { union { __m128 f;
__m128d d;} c; c.d = val; return c.f; }
#endif
-
+
static const MANTA_ALIGN(16) sse_t _mm_eps = _mm_set_ps1(1e-5);
static const MANTA_ALIGN(16) sse_t _mm_minus_eps = _mm_set_ps1(-1e-5);
static const MANTA_ALIGN(16) sse_t _mm_epsilon = _mm_set_ps1(1e-5);
@@ -339,15 +339,15 @@
}
inline float simd_component(sse_t t, int offset)
- {
+ {
MANTA_ALIGN(16)
float f[4];
_mm_store_ps(f,t);
return f[offset];
}
-
+
inline void simd_cerr(sse_t t)
- {
+ {
std::cerr << t << std::endl;
}
@@ -358,7 +358,7 @@
_mm_store_ps(f,t);
return Vec3f(f[2], f[1], f[0]);
}
-
+
inline Vector as_Vector(sse_t t)
{
MANTA_ALIGN(16)
@@ -366,7 +366,7 @@
_mm_store_ps(f,t);
return Vector(f[2], f[1], f[0]);
}
-
+
inline int count_nonzeros(sse_t t)
{
int mask = _mm_movemask_ps(t);
@@ -378,7 +378,7 @@
((mask & (1 << 3)) >> 3));
return nonzeros;
}
-
+
inline int count_zeros(sse_t t)
{
// You could use this if your compiler isn't stupid.
@@ -456,7 +456,7 @@
return product;
#endif
- }
+ }
// For trig functions like sin and cos, see TrigSSE.h
Modified: trunk/Engine/Renderers/KajiyaPathtracer.cc
==============================================================================
--- trunk/Engine/Renderers/KajiyaPathtracer.cc (original)
+++ trunk/Engine/Renderers/KajiyaPathtracer.cc Wed Jan 9 13:40:24 2008
@@ -74,7 +74,7 @@
}
/*
-
+
Basic algorithm:
while there are active rays and depth < maxdepth
@@ -175,7 +175,7 @@
}
if(rays.begin() == rays.end())
break;
-
+
// 4. compute new rays and reflectance
// For MatlSortSweep, this was already done simultaneous with sorting
if(msm != MatlSortSweep){
@@ -222,6 +222,7 @@
// Not in shadow, so compute the direct lighting contributions.
Vector normal = rays.getFFNormal(i);
Vector light_dir = shadowRays.getDirection(i);
+ // TODO(boulos): Replace this with BSDFEval
double weight=Dot(normal, light_dir);
Color light_color = shadowRays.getColor(i);
result.set(i, result.get(i) + total_attenuation.get(i) *
light_color * weight);
@@ -229,6 +230,11 @@
}
} while(!shadowState.done());
+ // (5.b) Mark rays as having had direct light computed already.
+ for(int i=rays.begin();i<rays.end();i++){
+ rays.data->ignoreEmittedLight[i] = 1;
+ }
+
// 6. Russian roulete to kill rays
RussianRouletteMode rrm = depth >=
static_cast<int>(russian_roulette_mode.size())?russian_roulette_mode[russian_roulette_mode.size()-1]:russian_roulette_mode[depth];
switch(rrm){
@@ -268,14 +274,14 @@
i=end;
}
const_cast<RenderContext&>(context).shadowAlgorithm = save_sa;
-
+
for(int i = rays.begin(); i < rays.end(); i++){
for(int j=0;j<3;j++)
result.colordata[j][i] += data->color[j][i] *
total_attenuation.colordata[j][i];
}
}
- // Add contribution from background rays, which will be at the beginning.
+ // Add contribution from background rays, which will be at the beginning.
if(rays.begin() != originalBegin){
RayPacket subPacket(rays, originalBegin, rays.begin());
context.scene->getBackground()->shade(context, subPacket);
@@ -311,10 +317,11 @@
for(int i=rays.begin();i<rays.end()-1;i++){
for(int j=i+1;j<rays.end();j++){
if(sort_needs_swap(data, i, j)){
- // Move hitPrim, hitMatl, hitTex, origin, direction, minT, time
+ // Move hitPrim, hitMatl, hitTex, emitted light flag, origin,
direction, minT, time
swap(data->hitPrim, i, j);
swap(data->hitMatl, i, j);
swap(data->hitTex, i, j);
+ swap(data->ignoreEmittedLight, i, j);
for(int k=0;k<3;k++)
swap(data->origin[k], i, j);
for(int k=0;k<3;k++)
@@ -342,7 +349,7 @@
swap(data->dPdu[k], i, j);
for(int k=0;k<3;k++)
swap(data->dPdv[k], i, j);
-
+
// Move sample_id, region_id
swap(data->sample_id, i, j);
swap(data->region_id, i, j);
@@ -380,7 +387,7 @@
int newEnd = rays.end()-1;
while(newEnd >= rays.begin() && rr.get(newEnd) >=
reflectance.get(newEnd).maxComponent())
newEnd--;
-
+
for(int i=rays.begin();i<=newEnd;i++){
double max = reflectance.get(i).maxComponent();
if(rr.get(i) > max){
@@ -392,7 +399,7 @@
swap(data->origin[j], i, newEnd);
for(int j=0;j<3;j++)
swap(data->direction[j], i, newEnd);
-
+
// Move ffnormal
for(int j=0;j<3;j++)
swap(data->ffnormal[j], i, newEnd);
@@ -404,26 +411,26 @@
// Move time
// Look at one-way move optimization
swap(data->time, i, newEnd);
-
+
// Move sample_id, region_id
// Look at one-way move optimization
swap(data->sample_id, i, newEnd);
swap(data->region_id, i, newEnd);
-
+
// Move result
for(int j=0;j<3;j++)
swap(result.colordata[j], i, newEnd);
-
+
// Move reflectance
// Look at one-way move optimization
for(int j=0;j<3;j++)
swap(reflectance.colordata[j], i, newEnd);
-
+
// Move total attenuation
// Look at one-way move optimization
for(int j=0;j<3;j++)
swap(total_attenuation.colordata[j], i, newEnd);
-
+
// Move rr
// Look at one-way move optimization
swap(rr.data, i, newEnd);
@@ -513,7 +520,7 @@
swap(data->dPdu[k], i, j);
for(int k=0;k<3;k++)
swap(data->dPdv[k], i, j);
-
+
// Move sample_id, region_id
swap(data->sample_id, i, j);
swap(data->region_id, i, j);
@@ -595,7 +602,7 @@
swap(data->dPdu[k], i, newBegin);
for(int k=0;k<3;k++)
swap(data->dPdv[k], i, newBegin);
-
+
// Move sample_id, region_id
swap(data->sample_id, i, newBegin);
swap(data->region_id, i, newBegin);
Modified: trunk/Interface/RayPacket.h
==============================================================================
--- trunk/Interface/RayPacket.h (original)
+++ trunk/Interface/RayPacket.h Wed Jan 9 13:40:24 2008
@@ -111,6 +111,11 @@
MANTA_ALIGN(16) unsigned int sample_depth[MaxSize];
MANTA_ALIGN(16) unsigned int sample_id[MaxSize];
MANTA_ALIGN(16) unsigned int region_id[MaxSize];
+ // NOTE(boulos): SSE has no good way to do bools. This also allows
+ // us to do per-ray flags in the future. I'm also making this
+ // ignoreEmittedLight since this will be the default for almost
+ // everything, and it can be filled in using setzero
+ MANTA_ALIGN(16) unsigned int ignoreEmittedLight[MaxSize];
MANTA_ALIGN(16) int signs[3][MaxSize]; // 1=negative, 0=zero, positive
// Scratchpad
@@ -247,7 +252,6 @@
{
rayBegin = rayBegin_in; rayEnd = rayEnd_in;
}
-
// Image space
void setPixel(int which, int whichEye, Real imageX, Real imageY)
Modified: trunk/Model/Cameras/PinholeCamera.cc
==============================================================================
--- trunk/Model/Cameras/PinholeCamera.cc (original)
+++ trunk/Model/Cameras/PinholeCamera.cc Wed Jan 9 13:40:24 2008
@@ -247,6 +247,7 @@
if (NORMALIZE_RAYS)
raydir.normalize();
rays.setRay(i, eye, raydir);
+ rays.data->ignoreEmittedLight[i] = 0;
if (CREATE_CORNER_RAYS) {
//find max ray extents.
@@ -265,6 +266,7 @@
if (NORMALIZE_RAYS)
raydir.normalize();
rays.setRay(i, eye, raydir);
+ rays.data->ignoreEmittedLight[i] = 0;
if (CREATE_CORNER_RAYS) {
//find max ray extents
@@ -279,6 +281,7 @@
if (NORMALIZE_RAYS)
raydir.normalize();
rays.setRay(i, eye, raydir);
+ rays.data->ignoreEmittedLight[i] = 0;
if (CREATE_CORNER_RAYS) {
//find max ray extents
@@ -288,7 +291,6 @@
max_u = Max(max_u, rays.getImageCoordinates(i, 1));
}
}
-
sse_t min_vs = set4(min_v);
sse_t max_vs = set4(max_v);
sse_t min_us = set4(min_u);
@@ -333,6 +335,8 @@
store44(&data->origin[1][i], eyey);
store44(&data->origin[2][i], eyez);
+ _mm_store_si128((__m128i*)&(data->ignoreEmittedLight[i]),
_mm_setzero_si128());
+
if (CREATE_CORNER_RAYS) {
min_vs = min4(min_vs, imagev);
max_vs = max4(max_vs, imagev);
@@ -374,6 +378,8 @@
if (NORMALIZE_RAYS)
raydir.normalize();
rays.setRay(i, eye, raydir);
+ rays.data->ignoreEmittedLight[i] = 0;
+
if (CREATE_CORNER_RAYS) {
min_v = Min(min_v, v_imageCoord);
max_v = Max(max_v, v_imageCoord);
Modified: trunk/Model/Lights/AreaLight.cc
==============================================================================
--- trunk/Model/Lights/AreaLight.cc (original)
+++ trunk/Model/Lights/AreaLight.cc Wed Jan 9 13:40:24 2008
@@ -42,8 +42,9 @@
Real cosine = -Dot(dir, normals.get(i));
destRays.setDirection(i, dir);
destRays.overrideMinT(i, len - T_EPSILON);
- if (cosine <= Real(0)) {
- // Wrong side of the light
+ if (cosine <= Real(0) ||
+ sourceRays.data->ignoreEmittedLight[i]) {
+ // Wrong side of the light or we shouldn't count anyway
destRays.setColor(i, Color::black());
} else {
// pdf = (dist^2 / cosine) * inv_area, which we assume is in
@@ -61,7 +62,8 @@
Real cosine = -Dot(dir, normals.get(i));
destRays.setDirection(i, dir);
destRays.overrideMinT(i, len - T_EPSILON);
- if (cosine <= Real(0)) {
+ if (cosine <= Real(0) ||
+ sourceRays.data->ignoreEmittedLight[i]) {
// Wrong side of the light
destRays.setColor(i, Color::black());
} else {
@@ -95,10 +97,7 @@
_mm_load_ps(&normals.vectordata[1][i]),
_mm_load_ps(&normals.vectordata[2][i]));
cosine = xor4(cosine, _mm_signbit);
- cosine = _mm_max_ps(cosine, _mm_setzero_ps());
- __m128 solid_pdf = _mm_div_ps(_mm_mul_ps(_mm_load_ps(&pdfs.data[i]),
- len2),
- cosine);
+
_mm_store_ps(&destData->direction[0][i],
dir_x);
_mm_store_ps(&destData->direction[1][i],
@@ -106,14 +105,27 @@
_mm_store_ps(&destData->direction[2][i],
dir_z);
- _mm_store_ps(&destData->color[0][i],
- _mm_div_ps(_mm_set1_ps(color[0]), solid_pdf));
- _mm_store_ps(&destData->color[1][i],
- _mm_div_ps(_mm_set1_ps(color[1]), solid_pdf));
- _mm_store_ps(&destData->color[2][i],
- _mm_div_ps(_mm_set1_ps(color[2]), solid_pdf));
-
_mm_store_ps(&destData->minT[i], _mm_sub_ps(len,
_mm_set1_ps(T_EPSILON)));
+
+ // If the cosine < 0 || ignoreEmittedLight != 0
+ __m128 black_light = _mm_or_ps(_mm_cmple_ps(cosine, _mm_setzero_ps()),
+
_mm_cmpneq_ps(_mm_load_ps((float*)&(sourceData->ignoreEmittedLight[i])),
+ _mm_setzero_ps()));
+ if (_mm_movemask_ps(black_light) == 0xf) {
+ // All black
+ _mm_store_ps(&destData->color[0][i], _mm_setzero_ps());
+ _mm_store_ps(&destData->color[1][i], _mm_setzero_ps());
+ _mm_store_ps(&destData->color[2][i], _mm_setzero_ps());
+ } else {
+ __m128 solid_pdf = _mm_div_ps(_mm_mul_ps(_mm_load_ps(&pdfs.data[i]),
+ len2),
+ cosine);
+ for (unsigned int c = 0; c < 3; c++) {
+ _mm_store_ps(&destData->color[c][i],
+ _mm_or_ps(_mm_and_ps(black_light, _mm_setzero_ps()),
+ _mm_andnot_ps(black_light,
_mm_div_ps(_mm_set1_ps(color[c]), solid_pdf))));
+ }
+ }
}
for(;i<sourceRays.rayEnd;i++){
// Generate a point on the light
@@ -122,7 +134,8 @@
Real cosine = -Dot(dir, normals.get(i));
destRays.setDirection(i, dir);
destRays.overrideMinT(i, len - T_EPSILON);
- if (cosine <= Real(0)) {
+ if (cosine <= Real(0) ||
+ sourceRays.data->ignoreEmittedLight[i]) {
// Wrong side of the light
destRays.setColor(i, Color::black());
} else {
@@ -141,7 +154,8 @@
Real cosine = -Dot(dir, normals.get(i));
destRays.setDirection(i, dir);
destRays.overrideMinT(i, len - T_EPSILON);
- if (cosine <= Real(0)) {
+ if (cosine <= Real(0) ||
+ sourceRays.data->ignoreEmittedLight[i]) {
// Wrong side of the light
destRays.setColor(i, Color::black());
} else {
Modified: trunk/Model/Materials/Dielectric.cc
==============================================================================
--- trunk/Model/Materials/Dielectric.cc (original)
+++ trunk/Model/Materials/Dielectric.cc Wed Jan 9 13:40:24 2008
@@ -140,6 +140,7 @@
reflected_rays.setImportance(num_refl, refl_importance);
reflected_rays.setTime(num_refl, rays.getTime(i));
reflected_rays.setRay(num_refl, hitpos, refl_dir);
+ reflected_rays.data->ignoreEmittedLight[num_refl] = 0;
context.sample_generator->setupChildRay(context, rays,
reflected_rays, i, num_refl);
refl_source[num_refl] = i;
refl_attenuation[num_refl] = beers_color;
@@ -179,6 +180,7 @@
reflected_rays.setImportance(num_refl, refl_importance);
reflected_rays.setTime(num_refl, rays.getTime(i));
reflected_rays.setRay(num_refl, hitpos, refl_dir);
+ reflected_rays.data->ignoreEmittedLight[num_refl] = 0;
context.sample_generator->setupChildRay(context, rays,
reflected_rays, i, num_refl);
refl_source[num_refl] = i;
num_refl++;
@@ -195,6 +197,7 @@
(eta_inverse * costheta - costheta2) * normal);
context.sample_generator->setupChildRay(context, rays,
refracted_rays, i, num_refr);
refracted_rays.setRay(num_refr, hitpos, refr_dir);
+ refracted_rays.data->ignoreEmittedLight[num_refr] = 0;
if (debugFlag) { cerr << "refr_dir.length() =
"<<refr_dir.length()<<"\n"; }
refr_source[num_refr] = i;
num_refr++;
Modified: trunk/Model/Materials/MetalMaterial.cc
==============================================================================
--- trunk/Model/Materials/MetalMaterial.cc (original)
+++ trunk/Model/Materials/MetalMaterial.cc Wed Jan 9 13:40:24 2008
@@ -55,6 +55,7 @@
Vector normal = rays.getFFNormal(i);
Vector refl_dir = rayD - normal*(2*Dot(normal, rayD));
refl_rays.setRay(i, rays.getHitPosition(i), refl_dir);
+ refl_rays.data->ignoreEmittedLight[i] = 0;
refl_rays.setImportance(i, rays.getImportance(i));
refl_rays.setTime(i, rays.getTime(i));
}
Modified: trunk/Model/Materials/Phong.cc
==============================================================================
--- trunk/Model/Materials/Phong.cc (original)
+++ trunk/Model/Materials/Phong.cc Wed Jan 9 13:40:24 2008
@@ -441,6 +441,7 @@
Vector refl_dir = (rays.getDirection(i) -
rays.getFFNormal(i)*(2*Dot(rays.getFFNormal(i),
rays.getDirection(i) )));
refl_rays.setRay(i, rays.getHitPosition(i), refl_dir);
+ refl_rays.data->ignoreEmittedLight[i] = 0;
refl_rays.setImportance(i, rays.getImportance(i) * refl.data[i]);
refl_rays.setTime(i, rays.getTime(i));
}
@@ -450,6 +451,7 @@
Vector refl_dir = (rays.getDirection(i) -
rays.getFFNormal(i)*(2*Dot(rays.getFFNormal(i),
rays.getDirection(i) )));
refl_rays.setRay(i, rays.getHitPosition(i), refl_dir);
+ refl_rays.data->ignoreEmittedLight[i] = 0;
refl_rays.setImportance(i, rays.getImportance(i) * refl.data[i]);
refl_rays.setTime(i, rays.getTime(i));
}
@@ -474,6 +476,9 @@
_mm_store_ps(&refldata->origin[0][i],
_mm_load_ps(&data->hitPosition[0][i]));
_mm_store_ps(&refldata->origin[1][i],
_mm_load_ps(&data->hitPosition[1][i]));
_mm_store_ps(&refldata->origin[2][i],
_mm_load_ps(&data->hitPosition[2][i]));
+
+ _mm_store_si128((__m128i*)&(refl_rays.data->ignoreEmittedLight[i]),
+ _mm_setzero_si128());
__m128 r = _mm_load_ps(&refl.data[i]);
_mm_store_ps(&refldata->importance[0][i],
_mm_mul_ps(_mm_load_ps(&data->importance[0][i]), r));
_mm_store_ps(&refldata->importance[1][i],
_mm_mul_ps(_mm_load_ps(&data->importance[1][i]), r));
@@ -485,6 +490,7 @@
Vector refl_dir = (rays.getDirection(i) -
rays.getFFNormal(i)*(2*Dot(rays.getFFNormal(i),
rays.getDirection(i) )));
refl_rays.setRay(i, rays.getHitPosition(i), refl_dir);
+ refl_rays.data->ignoreEmittedLight[i] = 0;
refl_rays.setImportance(i, rays.getImportance(i) * refl.data[i]);
refl_rays.setTime(i, rays.getTime(i));
}
@@ -494,6 +500,7 @@
Vector refl_dir = (rays.getDirection(i) -
rays.getFFNormal(i)*(2*Dot(rays.getFFNormal(i),
rays.getDirection(i) )));
refl_rays.setRay(i, rays.getHitPosition(i), refl_dir);
+ refl_rays.data->ignoreEmittedLight[i] = 0;
refl_rays.setImportance(i, rays.getImportance(i) * refl.data[i]);
refl_rays.setTime(i, rays.getTime(i));
}
Modified: trunk/Model/Materials/ThinDielectric.cc
==============================================================================
--- trunk/Model/Materials/ThinDielectric.cc (original)
+++ trunk/Model/Materials/ThinDielectric.cc Wed Jan 9 13:40:24 2008
@@ -166,6 +166,7 @@
reflected_rays.setImportance(num_refl, refl_importance);
context.sample_generator->setupChildRay(context, rays,
reflected_rays, i, num_refl);
reflected_rays.setRay(num_refl, hitpos, refl_dir);
+ reflected_rays.data->ignoreEmittedLight[num_refl] = 0;
refl_source[num_refl] = i;
num_refl++;
}
@@ -184,6 +185,7 @@
Vector refr_orig = hitpos + refr_dir * refraction_ray_length;
context.sample_generator->setupChildRay(context, rays,
refracted_rays, i, num_refr);
refracted_rays.setRay(num_refr, refr_orig, rayD);
+ refracted_rays.data->ignoreEmittedLight[num_refr] = 0;
if (debugFlag) { cerr << "refr_dir.length() =
"<<refr_dir.length()<<"\n"; }
refr_source[num_refr] = i;
num_refr++;
@@ -201,6 +203,7 @@
reflected_rays.setTime(num_refl, rays.getTime(i));
context.sample_generator->setupChildRay(context, rays,
reflected_rays, i, num_refl);
reflected_rays.setRay(num_refl, hitpos, refl_dir);
+ reflected_rays.data->ignoreEmittedLight[num_refl] = 0;
refl_source[num_refl] = i;
refl_attenuation[num_refl] = Color::white();
num_refl++;
Modified: trunk/Model/Materials/Transparent.cc
==============================================================================
--- trunk/Model/Materials/Transparent.cc (original)
+++ trunk/Model/Materials/Transparent.cc Wed Jan 9 13:40:24 2008
@@ -137,6 +137,7 @@
secondaryRays.setOrigin ( size, rays.getHitPosition( i ) );
secondaryRays.setDirection( size, rays.getDirection ( i ) );
secondaryRays.setTime ( size, rays.getTime ( i ) );
+ secondaryRays.data->ignoreEmittedLight[size] =
rays.data->ignoreEmittedLight[i];
map[size] = i;
++size;
}
- [Manta] r1980 - in trunk: Core/Math Engine/Renderers Interface Model/Cameras Model/Lights Model/Materials, boulos, 01/09/2008
Archive powered by MHonArc 2.6.16.