@@ -339,21 +339,8 @@ __kernel void ShadeSurface(
339
339
DifferentialGeometry_Fill (& scene , & isect , & diffgeo );
340
340
341
341
// 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 ;
357
344
358
345
// Select BxDF
359
346
Material_Select (& scene , wi , & sampler , TEXTURE_ARGS , SAMPLER_ARGS , & diffgeo );
@@ -388,11 +375,11 @@ __kernel void ShadeSurface(
388
375
389
376
lightsamples [globalid ] = 0.f ;
390
377
return ;
391
- }
378
+ }
392
379
393
380
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 ))
396
383
{
397
384
//Reverse normal and tangents in this case
398
385
//but not for BTDFs, since BTDFs rely
@@ -401,8 +388,10 @@ __kernel void ShadeSurface(
401
388
diffgeo .n = - diffgeo .n ;
402
389
diffgeo .dpdu = - diffgeo .dpdu ;
403
390
diffgeo .dpdv = - diffgeo .dpdv ;
391
+ s = - s ;
404
392
}
405
393
394
+
406
395
// TODO: this is test code, need to
407
396
// maintain proper volume stack here
408
397
//if (Bxdf_IsBtdf(&diffgeo))
@@ -413,10 +402,13 @@ __kernel void ShadeSurface(
413
402
414
403
// Check if we need to apply normal map
415
404
//ApplyNormalMap(&diffgeo, TEXTURE_ARGS);
416
- DifferentialGeometry_ApplyBumpMap (& diffgeo , TEXTURE_ARGS );
405
+ DifferentialGeometry_ApplyBumpMap (& diffgeo , TEXTURE_ARGS );
406
+
417
407
//DifferentialGeometry_ApplyNormalMap(&diffgeo, TEXTURE_ARGS);
418
408
DifferentialGeometry_CalculateTangentTransforms (& diffgeo );
419
409
410
+ float ndotwi = fabs (dot (diffgeo .n , wi ));
411
+
420
412
float lightpdf = 0.f ;
421
413
float bxdflightpdf = 0.f ;
422
414
float bxdfpdf = 0.f ;
0 commit comments