Skip to content

Commit 224ef16

Browse files
committed
refactor(soba): simplify contact shadows; multiply frames to workaround race cond
1 parent ce1d543 commit 224ef16

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

libs/soba/staging/src/lib/contact-shadows.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,13 @@ export class NgtsContactShadows {
184184
blurPlane.visible = true;
185185
blurPlane.material = horizontalBlurMaterial;
186186
horizontalBlurMaterial.uniforms['tDiffuse'].value = renderTarget.texture;
187-
horizontalBlurMaterial.uniforms['h'].value = (blur * 1) / 256;
187+
horizontalBlurMaterial.uniforms['h'].value = blur / 256;
188188
this.gl().setRenderTarget(renderTargetBlur);
189189
this.gl().render(blurPlane, shadowsCamera);
190190

191191
blurPlane.material = verticalBlurMaterial;
192192
verticalBlurMaterial.uniforms['tDiffuse'].value = renderTargetBlur.texture;
193-
verticalBlurMaterial.uniforms['v'].value = (blur * 1) / 256;
193+
verticalBlurMaterial.uniforms['v'].value = blur / 256;
194194
this.gl().setRenderTarget(renderTarget);
195195
this.gl().render(blurPlane, shadowsCamera);
196196
blurPlane.visible = false;
@@ -205,26 +205,27 @@ export class NgtsContactShadows {
205205

206206
injectBeforeRender(() => {
207207
const shadowsCamera = this.shadowsCameraRef()?.nativeElement;
208+
if (!shadowsCamera) return;
208209
const [{ frames, blur, smooth }, gl, scene, contactShadows, { depthMaterial, renderTarget }] = [
209210
this.options(),
210211
this.gl(),
211212
this.scene(),
212-
this.contactShadowsRef(),
213+
this.contactShadowsRef().nativeElement,
213214
this.shadowsOptions(),
214215
];
215-
if (shadowsCamera && (frames === Infinity || count < frames)) {
216+
if (frames === Infinity || count < frames * frames) {
216217
count++;
217218
initialBackground = scene.background;
218219
initialOverrideMaterial = scene.overrideMaterial;
219-
contactShadows.nativeElement.visible = false;
220+
contactShadows.visible = false;
220221
scene.background = null;
221222
scene.overrideMaterial = depthMaterial;
222223
gl.setRenderTarget(renderTarget);
223224
gl.render(scene, shadowsCamera);
224225
this.blurShadows(blur);
225226
if (smooth) this.blurShadows(blur * 0.4);
226227
gl.setRenderTarget(null);
227-
contactShadows.nativeElement.visible = true;
228+
contactShadows.visible = true;
228229
scene.overrideMaterial = initialOverrideMaterial;
229230
scene.background = initialBackground;
230231
}

0 commit comments

Comments
 (0)