Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
Fix dark shadow catcher reflections (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas committed Aug 28, 2019
1 parent d64ac4c commit 16d1312
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/renderer/glsl/rayTrace.frag
Original file line number Diff line number Diff line change
Expand Up @@ -112,42 +112,41 @@ ${sampleShadowCatcher(params)}

struct Path {
Ray ray;
vec3 li;
float alpha;
vec3 beta;
bool specularBounce;
bool abort;
};

vec3 bounce(inout Path path, int i) {
vec3 li;

void bounce(inout Path path, int i) {
if (path.abort) {
return li;
return;
}

SurfaceInteraction si = intersectScene(path.ray);

if (!si.hit) {
if (path.specularBounce) {
li += path.beta * sampleEnvmapFromDirection(path.ray.d);
path.li += path.beta * sampleEnvmapFromDirection(path.ray.d);
}

path.abort = true;
} else {
#ifdef USE_GLASS
if (si.materialType == THIN_GLASS || si.materialType == THICK_GLASS) {
li += sampleGlassSpecular(si, i, path.ray, path.beta);
path.li += sampleGlassSpecular(si, i, path.ray, path.beta);
path.specularBounce = true;
}
#endif
#ifdef USE_SHADOW_CATCHER
if (si.materialType == SHADOW_CATCHER) {
li += sampleShadowCatcher(si, i, path.ray, path.beta, path.alpha, li, path.abort);
path.li += sampleShadowCatcher(si, i, path.ray, path.beta, path.alpha, path.li, path.abort);
path.specularBounce = false;
}
#endif
if (si.materialType == STANDARD) {
li += sampleMaterial(si, i, path.ray, path.beta, path.abort);
path.li += sampleMaterial(si, i, path.ray, path.beta, path.abort);
path.specularBounce = false;
}

Expand All @@ -160,17 +159,14 @@ vec3 bounce(inout Path path, int i) {
path.beta /= 1.0 - q;
}
}

return li;
}

// Path tracing integrator as described in
// http://www.pbr-book.org/3ed-2018/Light_Transport_I_Surface_Reflection/Path_Tracing.html#
vec4 integrator(inout Ray ray) {
vec3 li;

Path path;
path.ray = ray;
path.li = vec3(0);
path.alpha = 1.0;
path.beta = vec3(1.0);
path.specularBounce = true;
Expand All @@ -182,10 +178,10 @@ vec4 integrator(inout Ray ray) {
// for (int i = 1; i < params.bounces + 1, i += 1)
// equivelant to
${unrollLoop('i', 1, params.BOUNCES + 1, 1, `
li += bounce(path, i);
bounce(path, i);
`)}

return vec4(li, path.alpha);
return vec4(path.li, path.alpha);
}

void main() {
Expand Down

0 comments on commit 16d1312

Please sign in to comment.