Skip to content

Commit eeda2cc

Browse files
authored
Fix shadow catcher (#330)
1 parent 3ddbae1 commit eeda2cc

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/shadow-catcher.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
BLEND_MULTIPLICATIVE,
2+
BLEND_PREMULTIPLIED,
33
SHADOW_VSM_16F,
44
SHADOWUPDATE_REALTIME as SHADOWUPDATE,
55
AppBase,
@@ -12,6 +12,14 @@ import {
1212
StandardMaterial
1313
} from 'playcanvas';
1414

15+
const litUserMainEndGLSL = `
16+
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0 - gl_FragColor.r);
17+
`;
18+
19+
const litUserMainEndWGSL = `
20+
output.color = vec4f(0.0, 0.0, 0.0, 1.0 - output.color.r);
21+
`;
22+
1523
class ShadowCatcher {
1624
layer: Layer;
1725

@@ -38,12 +46,16 @@ class ShadowCatcher {
3846

3947
// create shadow catcher material
4048
this.material = new StandardMaterial();
49+
this.material.blendType = BLEND_PREMULTIPLIED;
4150
this.material.shadowCatcher = true;
4251
this.material.useSkybox = false;
43-
this.material.blendType = BLEND_MULTIPLICATIVE;
4452
this.material.depthWrite = false;
4553
this.material.diffuse.set(0, 0, 0);
4654
this.material.specular.set(0, 0, 0);
55+
56+
this.material.shaderChunks.glsl.set('litUserMainEndPS', litUserMainEndGLSL);
57+
this.material.shaderChunks.wgsl.set('litUserMainEndPS', litUserMainEndWGSL);
58+
4759
this.material.update();
4860

4961
// create shadow catcher geometry

src/viewer.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,11 @@ class Viewer {
725725
texture.type = TEXTURETYPE_RGBM;
726726
}
727727
this.initSkybox(texture);
728+
729+
// if we don't unload the texture asset and user selects it a second time, the
730+
// brightness is completely wrong.
731+
textureAsset.unload();
732+
app.assets.remove(textureAsset);
728733
});
729734
app.assets.add(textureAsset);
730735
app.assets.load(textureAsset);

0 commit comments

Comments
 (0)