From 66f50ec16258e3af01a81f57504487e81c6dc012 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Fri, 25 Nov 2022 22:49:52 +0900 Subject: [PATCH] Add a functional background reflect --- src/materials/PhysicalPathTracingMaterial.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/materials/PhysicalPathTracingMaterial.js b/src/materials/PhysicalPathTracingMaterial.js index 50e4d0338..f59e42486 100644 --- a/src/materials/PhysicalPathTracingMaterial.js +++ b/src/materials/PhysicalPathTracingMaterial.js @@ -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 { @@ -877,6 +877,14 @@ export class PhysicalPathTracingMaterial extends MaterialBase { float envPdf = randomEnvMapSample( envMapInfo, envColor, envDirection ); envDirection = invEnvironmentRotation * envDirection; + // TODO: This shadow ray needs to be determined by whether the _new_ evn-sampled direction is a shadow ray + // not the last randomly sampled ray direction + if ( i <= 1 && ! isShadowRay ) { + + envColor = sampleBackground( envDirection ); + + } + // this env sampling is not set up for transmissive sampling and yields overly bright // results so we ignore the sample in this case. // TODO: this should be improved but how? The env samples could traverse a few layers?