Skip to content

Commit

Permalink
Removed WebGL1 related shadow rendering code (#6311)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
  • Loading branch information
mvaligursky and Martin Valigursky authored Apr 29, 2024
1 parent aa51d5c commit 3b97f7e
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 23 deletions.
1 change: 0 additions & 1 deletion src/platform/graphics/null/null-graphics-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class NullGraphicsDevice extends GraphicsDevice {
this.supportsBoneTextures = true;
this.supportsMorphTargetTexturesCore = true;
this.supportsAreaLights = true;
this.supportsDepthShadow = true;
this.supportsGpuParticles = false;
this.supportsMrt = true;
this.extUintElement = true;
Expand Down
1 change: 0 additions & 1 deletion src/platform/graphics/webgl/webgl-graphics-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,6 @@ class WebglGraphicsDevice extends GraphicsDevice {
}

this.supportsMorphTargetTexturesCore = (this.maxPrecision === "highp" && this.maxVertexTextures >= 2);
this.supportsDepthShadow = this.isWebGL2;

this._textureFloatHighPrecision = undefined;

Expand Down
1 change: 0 additions & 1 deletion src/platform/graphics/webgpu/webgpu-graphics-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
this.supportsBoneTextures = true;
this.supportsMorphTargetTexturesCore = true;
this.supportsAreaLights = true;
this.supportsDepthShadow = true;
this.supportsGpuParticles = true;
this.supportsMrt = true;
this.supportsCompute = true;
Expand Down
7 changes: 1 addition & 6 deletions src/scene/light.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class LightRenderData {
return rt.colorBuffer;
}

return light._isPcf && light.device.supportsDepthShadow ? rt.depthBuffer : rt.colorBuffer;
return light._isPcf ? rt.depthBuffer : rt.colorBuffer;
}

return null;
Expand Down Expand Up @@ -388,11 +388,6 @@ class Light {
if (this._type === LIGHTTYPE_OMNI && value !== SHADOW_PCF3 && value !== SHADOW_PCSS)
value = SHADOW_PCF3; // VSM or HW PCF for omni lights is not supported yet

const supportsDepthShadow = device.supportsDepthShadow;
if (value === SHADOW_PCF5 && !supportsDepthShadow) {
value = SHADOW_PCF3; // fallback from HW PCF to old PCF
}

// fallback from vsm32 to vsm16
if (value === SHADOW_VSM32 && (!device.textureFloatRenderable || !device.textureFloatFilterable))
value = SHADOW_VSM16;
Expand Down
4 changes: 1 addition & 3 deletions src/scene/lighting/light-texture-atlas.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,8 @@ class LightTextureAtlas {
updateUniforms() {

// shadow atlas texture
const isShadowFilterPcf = true;
const rt = this.shadowAtlas.renderTargets[0];
const isDepthShadow = !this.device.isWebGL1 && isShadowFilterPcf;
const shadowBuffer = isDepthShadow ? rt.depthBuffer : rt.colorBuffer;
const shadowBuffer = rt.depthBuffer;
this._shadowAtlasTextureId.setValue(shadowBuffer);

// shadow atlas params
Expand Down
10 changes: 4 additions & 6 deletions src/scene/renderer/shadow-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,17 @@ class ShadowMap {
return PIXELFORMAT_RGBA16F;
} else if (shadowType === SHADOW_PCF5) {
return PIXELFORMAT_DEPTH;
} else if ((shadowType === SHADOW_PCF1 || shadowType === SHADOW_PCF3) && device.supportsDepthShadow) {
} else if (shadowType === SHADOW_PCF1 || shadowType === SHADOW_PCF3) {
return PIXELFORMAT_DEPTH;
} else if ((shadowType === SHADOW_PCSS) && !device.isWebGL1) {
} else if (shadowType === SHADOW_PCSS) {
return PIXELFORMAT_R32F;
}

return PIXELFORMAT_RGBA8;
}

static getShadowFiltering(device, shadowType) {
if ((shadowType === SHADOW_PCF1 || shadowType === SHADOW_PCF3 || shadowType === SHADOW_PCSS) && !device.supportsDepthShadow) {
return FILTER_NEAREST;
} else if (shadowType === SHADOW_VSM32) {
if (shadowType === SHADOW_VSM32) {
return device.extTextureFloatLinear ? FILTER_LINEAR : FILTER_NEAREST;
} else if (shadowType === SHADOW_VSM16) {
return device.extTextureHalfFloatLinear ? FILTER_LINEAR : FILTER_NEAREST;
Expand Down Expand Up @@ -119,7 +117,7 @@ class ShadowMap {
});

let target = null;
if (shadowType === SHADOW_PCF5 || ((shadowType === SHADOW_PCF1 || shadowType === SHADOW_PCF3) && device.supportsDepthShadow)) {
if (shadowType === SHADOW_PCF5 || shadowType === SHADOW_PCF1 || shadowType === SHADOW_PCF3) {

// enable hardware PCF when sampling the depth texture
texture.compareOnRead = true;
Expand Down
2 changes: 1 addition & 1 deletion src/scene/renderer/shadow-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class ShadowRenderer {

// normal omni shadows on webgl2 encode depth in RGBA8 and do manual PCF sampling
// clustered omni shadows on webgl2 use depth format and hardware PCF sampling
let hwPcf = shadowType === SHADOW_PCF5 || ((shadowType === SHADOW_PCF1 || shadowType === SHADOW_PCF3) && device.supportsDepthShadow);
let hwPcf = shadowType === SHADOW_PCF5 || shadowType === SHADOW_PCF1 || shadowType === SHADOW_PCF3;
if (type === LIGHTTYPE_OMNI && !isClustered) {
hwPcf = false;
}
Expand Down
6 changes: 2 additions & 4 deletions src/scene/shader-lib/programs/lit-shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,7 @@ class LitShader {
code += this.frontendDecl;
code += this.frontendCode;

const mayPackDepth = shadowType === SHADOW_PCF1 || shadowType === SHADOW_PCF3 || shadowType === SHADOW_PCF5 || shadowType === SHADOW_PCSS;
const mustPackDepth = (lightType === LIGHTTYPE_OMNI && shadowType !== SHADOW_PCSS && !options.clusteredLightingEnabled);
const usePackedDepth = mayPackDepth && !device.supportsDepthShadow || mustPackDepth;
const usePackedDepth = (lightType === LIGHTTYPE_OMNI && shadowType !== SHADOW_PCSS && !options.clusteredLightingEnabled);
if (usePackedDepth) {
code += chunks.packDepthPS;
} else if (shadowType === SHADOW_VSM8) {
Expand Down Expand Up @@ -687,7 +685,7 @@ class LitShader {
if (lightType === LIGHTTYPE_OMNI) {
decl.append("uniform samplerCube light" + i + "_shadowMap;");
} else {
if (light._isPcf && device.supportsDepthShadow) {
if (light._isPcf) {
decl.append("uniform sampler2DShadow light" + i + "_shadowMap;");
} else {
decl.append("uniform sampler2D light" + i + "_shadowMap;");
Expand Down

0 comments on commit 3b97f7e

Please sign in to comment.