Skip to content

Commit

Permalink
Improved handling of VSM32 on WebGPU (#5684)
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 Sep 27, 2023
1 parent 93fa36f commit 97857fa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/platform/graphics/graphics-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ class GraphicsDevice extends EventHandler {
*/
textureHalfFloatRenderable;

/**
* True if filtering can be applied when sampling float textures.
*
* @type {boolean}
* @readonly
*/
textureFloatFilterable = true;

/**
* A vertex buffer representing a quad.
*
Expand Down
4 changes: 2 additions & 2 deletions src/platform/graphics/webgpu/webgpu-graphics-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
this.supportsImageBitmap = true;
this.extStandardDerivatives = true;
this.extBlendMinmax = true;
this.areaLightLutFormat = this.floatFilterable ? PIXELFORMAT_RGBA32F : PIXELFORMAT_RGBA8;
this.areaLightLutFormat = this.textureFloatFilterable ? PIXELFORMAT_RGBA32F : PIXELFORMAT_RGBA8;
this.supportsTextureFetch = true;

// WebGPU currently only supports 1 and 4 samples
Expand Down Expand Up @@ -215,7 +215,7 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
}
return supported;
};
this.floatFilterable = requireFeature('float32-filterable');
this.textureFloatFilterable = requireFeature('float32-filterable');
this.extCompressedTextureS3TC = requireFeature('texture-compression-bc');
this.extCompressedTextureETC = requireFeature('texture-compression-etc2');
this.extCompressedTextureASTC = requireFeature('texture-compression-astc');
Expand Down
6 changes: 4 additions & 2 deletions src/scene/light.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,12 @@ class Light {
value = SHADOW_PCF3; // fallback from HW PCF to old PCF
}

if (value === SHADOW_VSM32 && !device.textureFloatRenderable) // fallback from vsm32 to vsm16
// fallback from vsm32 to vsm16
if (value === SHADOW_VSM32 && (!device.textureFloatRenderable || !device.textureFloatFilterable))
value = SHADOW_VSM16;

if (value === SHADOW_VSM16 && !device.textureHalfFloatRenderable) // fallback from vsm16 to vsm8
// fallback from vsm16 to vsm8
if (value === SHADOW_VSM16 && !device.textureHalfFloatRenderable)
value = SHADOW_VSM8;

this._isVsm = value >= SHADOW_VSM8 && value <= SHADOW_VSM32;
Expand Down

0 comments on commit 97857fa

Please sign in to comment.