Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/materials/PhysicalPathTracingMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,10 @@ export class PhysicalPathTracingMaterial extends MaterialBase {

if ( ! hit ) {

if ( i == 0 || transmissiveRay ) {
if ( i == 0 || transmissiveRay || i == 1 && ! isShadowRay ) {

gl_FragColor.rgb += sampleBackground( environmentRotation * rayDirection ) * throughputColor;
gl_FragColor.a = backgroundAlpha;
gl_FragColor.a = i == 1 && ! isShadowRay ? 1.0 : backgroundAlpha;

} else {

Expand Down Expand Up @@ -857,7 +857,8 @@ export class PhysicalPathTracingMaterial extends MaterialBase {

// get the material pdf
vec3 sampleColor;
float lightMaterialPdf = bsdfResult( outgoing, clearcoatOutgoing, normalize( invBasis * lightSampleRec.direction ), normalize( clearcoatInvBasis * lightSampleRec.direction ), surfaceRec, sampleColor );
float specularPdf;
float lightMaterialPdf = bsdfResult( outgoing, clearcoatOutgoing, normalize( invBasis * lightSampleRec.direction ), normalize( clearcoatInvBasis * lightSampleRec.direction ), surfaceRec, specularPdf, sampleColor );
bool isValidSampleColor = all( greaterThanEqual( sampleColor, vec3( 0.0 ) ) );
if ( lightMaterialPdf > 0.0 && isValidSampleColor ) {

Expand Down Expand Up @@ -887,6 +888,8 @@ export class PhysicalPathTracingMaterial extends MaterialBase {

}

// TODO: we pass a shadow ray boolean in here but this needs to be handled per the new ray or even within the
// "attenuateHit" function
// check if a ray could even reach the surface
vec3 attenuatedColor;
if (
Expand All @@ -897,10 +900,19 @@ export class PhysicalPathTracingMaterial extends MaterialBase {

// get the material pdf
vec3 sampleColor;
float envMaterialPdf = bsdfResult( outgoing, clearcoatOutgoing, normalize( invBasis * envDirection ), normalize( clearcoatInvBasis * envDirection ), surfaceRec, sampleColor );
float specularPdf;
float envMaterialPdf = bsdfResult( outgoing, clearcoatOutgoing, normalize( invBasis * envDirection ), normalize( clearcoatInvBasis * envDirection ), surfaceRec, specularPdf, sampleColor );
bool isValidSampleColor = all( greaterThanEqual( sampleColor, vec3( 0.0 ) ) );
if ( envMaterialPdf > 0.0 && isValidSampleColor ) {

// determine whether the ray is a shadow ray so we can use this for specular reflection determination
bool isShadowRay = specularPdf < rand();
if ( i <= 1 && ! isShadowRay ) {

envColor = sampleBackground( envDirection );

}

// weight the direct light contribution
envPdf /= float( lights.count + 1u );
float misWeight = misHeuristic( envPdf, envMaterialPdf );
Expand Down
4 changes: 1 addition & 3 deletions src/shader/shaderMaterialSampling.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,10 @@ float bsdfEval( vec3 wo, vec3 clearcoatWo, vec3 wi, vec3 clearcoatWi, SurfaceRec

}

float bsdfResult( vec3 wo, vec3 clearcoatWo, vec3 wi, vec3 clearcoatWi, SurfaceRec surf, out vec3 color ) {
float bsdfResult( vec3 wo, vec3 clearcoatWo, vec3 wi, vec3 clearcoatWi, SurfaceRec surf, out float specularPdf, out vec3 color ) {

float[ 4 ] pdf;
getLobeWeights( wo, clearcoatWo, surf, pdf );

float specularPdf;
return bsdfEval( wo, clearcoatWo, wi, clearcoatWi, surf, pdf, specularPdf, color );

}
Expand Down