Skip to content

Commit eab0267

Browse files
committed
Fix orientations
1 parent fd0d17c commit eab0267

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

App/CL/integrator_pt.cl

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -339,21 +339,8 @@ __kernel void ShadeSurface(
339339
DifferentialGeometry_Fill(&scene, &isect, &diffgeo);
340340

341341
// Check if we are hitting from the inside
342-
343-
float backfacing = dot(diffgeo.ng, wi) < 0.f;
344-
int twosided = diffgeo.mat.twosided;
345-
if (twosided && backfacing)
346-
{
347-
// Reverse normal and tangents in this case
348-
// but not for BTDFs, since BTDFs rely
349-
// on normal direction in order to arrange
350-
// indices of refraction
351-
diffgeo.n = -diffgeo.n;
352-
diffgeo.dpdu = -diffgeo.dpdu;
353-
diffgeo.dpdv = -diffgeo.dpdv;
354-
}
355-
356-
float ndotwi = dot(diffgeo.n, wi);
342+
float ngdotwi = dot(diffgeo.ng, wi);
343+
bool backfacing = ngdotwi < 0.f;
357344

358345
// Select BxDF
359346
Material_Select(&scene, wi, &sampler, TEXTURE_ARGS, SAMPLER_ARGS, &diffgeo);
@@ -388,11 +375,11 @@ __kernel void ShadeSurface(
388375

389376
lightsamples[globalid] = 0.f;
390377
return;
391-
}
378+
}
392379

393380

394-
float s = Bxdf_IsBtdf(&diffgeo) ? (-sign(ndotwi)) : 1.f;
395-
if (!twosided && backfacing && !Bxdf_IsBtdf(&diffgeo))
381+
float s = Bxdf_IsBtdf(&diffgeo) ? (-sign(ngdotwi)) : 1.f;
382+
if (backfacing && !Bxdf_IsBtdf(&diffgeo))
396383
{
397384
//Reverse normal and tangents in this case
398385
//but not for BTDFs, since BTDFs rely
@@ -401,8 +388,10 @@ __kernel void ShadeSurface(
401388
diffgeo.n = -diffgeo.n;
402389
diffgeo.dpdu = -diffgeo.dpdu;
403390
diffgeo.dpdv = -diffgeo.dpdv;
391+
s = -s;
404392
}
405393

394+
406395
// TODO: this is test code, need to
407396
// maintain proper volume stack here
408397
//if (Bxdf_IsBtdf(&diffgeo))
@@ -413,10 +402,13 @@ __kernel void ShadeSurface(
413402

414403
// Check if we need to apply normal map
415404
//ApplyNormalMap(&diffgeo, TEXTURE_ARGS);
416-
DifferentialGeometry_ApplyBumpMap(&diffgeo, TEXTURE_ARGS);
405+
DifferentialGeometry_ApplyBumpMap(&diffgeo, TEXTURE_ARGS);
406+
417407
//DifferentialGeometry_ApplyNormalMap(&diffgeo, TEXTURE_ARGS);
418408
DifferentialGeometry_CalculateTangentTransforms(&diffgeo);
419409

410+
float ndotwi = fabs(dot(diffgeo.n, wi));
411+
420412
float lightpdf = 0.f;
421413
float bxdflightpdf = 0.f;
422414
float bxdfpdf = 0.f;

0 commit comments

Comments
 (0)