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

Commit 16d1312

Browse files
author
Lucas
authored
Fix dark shadow catcher reflections (#6)
1 parent d64ac4c commit 16d1312

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/renderer/glsl/rayTrace.frag

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,42 +112,41 @@ ${sampleShadowCatcher(params)}
112112

113113
struct Path {
114114
Ray ray;
115+
vec3 li;
115116
float alpha;
116117
vec3 beta;
117118
bool specularBounce;
118119
bool abort;
119120
};
120121

121-
vec3 bounce(inout Path path, int i) {
122-
vec3 li;
123-
122+
void bounce(inout Path path, int i) {
124123
if (path.abort) {
125-
return li;
124+
return;
126125
}
127126

128127
SurfaceInteraction si = intersectScene(path.ray);
129128

130129
if (!si.hit) {
131130
if (path.specularBounce) {
132-
li += path.beta * sampleEnvmapFromDirection(path.ray.d);
131+
path.li += path.beta * sampleEnvmapFromDirection(path.ray.d);
133132
}
134133

135134
path.abort = true;
136135
} else {
137136
#ifdef USE_GLASS
138137
if (si.materialType == THIN_GLASS || si.materialType == THICK_GLASS) {
139-
li += sampleGlassSpecular(si, i, path.ray, path.beta);
138+
path.li += sampleGlassSpecular(si, i, path.ray, path.beta);
140139
path.specularBounce = true;
141140
}
142141
#endif
143142
#ifdef USE_SHADOW_CATCHER
144143
if (si.materialType == SHADOW_CATCHER) {
145-
li += sampleShadowCatcher(si, i, path.ray, path.beta, path.alpha, li, path.abort);
144+
path.li += sampleShadowCatcher(si, i, path.ray, path.beta, path.alpha, path.li, path.abort);
146145
path.specularBounce = false;
147146
}
148147
#endif
149148
if (si.materialType == STANDARD) {
150-
li += sampleMaterial(si, i, path.ray, path.beta, path.abort);
149+
path.li += sampleMaterial(si, i, path.ray, path.beta, path.abort);
151150
path.specularBounce = false;
152151
}
153152

@@ -160,17 +159,14 @@ vec3 bounce(inout Path path, int i) {
160159
path.beta /= 1.0 - q;
161160
}
162161
}
163-
164-
return li;
165162
}
166163

167164
// Path tracing integrator as described in
168165
// http://www.pbr-book.org/3ed-2018/Light_Transport_I_Surface_Reflection/Path_Tracing.html#
169166
vec4 integrator(inout Ray ray) {
170-
vec3 li;
171-
172167
Path path;
173168
path.ray = ray;
169+
path.li = vec3(0);
174170
path.alpha = 1.0;
175171
path.beta = vec3(1.0);
176172
path.specularBounce = true;
@@ -182,10 +178,10 @@ vec4 integrator(inout Ray ray) {
182178
// for (int i = 1; i < params.bounces + 1, i += 1)
183179
// equivelant to
184180
${unrollLoop('i', 1, params.BOUNCES + 1, 1, `
185-
li += bounce(path, i);
181+
bounce(path, i);
186182
`)}
187183

188-
return vec4(li, path.alpha);
184+
return vec4(path.li, path.alpha);
189185
}
190186

191187
void main() {

0 commit comments

Comments
 (0)