From 5bab962c5b76d3af530845d308bf5ec98a1a0cbf Mon Sep 17 00:00:00 2001 From: aardgoose Date: Fri, 22 Sep 2023 17:38:55 +0100 Subject: [PATCH] WebGPURenderer: Support textureCompare() operations in WebGL backend (#26823) Co-authored-by: aardgoose --- .../renderers/webgl/nodes/GLSLNodeBuilder.js | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js b/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js index 0de36c2ad24a4a..e800caa02166ba 100644 --- a/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +++ b/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js @@ -62,6 +62,20 @@ class GLSLNodeBuilder extends NodeBuilder { } + getTextureCompare( texture, textureProperty, uvSnippet, compareSnippet, shaderStage = this.shaderStage ) { + + if ( shaderStage === 'fragment' ) { + + return `texture( ${textureProperty}, vec3( ${uvSnippet}, ${compareSnippet} ) )`; + + } else { + + console.error( `WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${ shaderStage } shader.` ); + + } + + } + getVars( shaderStage ) { const snippets = []; @@ -94,7 +108,15 @@ class GLSLNodeBuilder extends NodeBuilder { if ( uniform.type === 'texture' ) { - snippet = `sampler2D ${uniform.name};`; + if ( uniform.node.value.compareFunction ) { + + snippet = `sampler2DShadow ${uniform.name};`; + + } else { + + snippet = `sampler2D ${uniform.name};`; + + } } else if ( uniform.type === 'cubeTexture' ) { @@ -324,6 +346,7 @@ ${ this.getSignature() } // precision precision highp float; precision highp int; +precision lowp sampler2DShadow; // uniforms ${shaderData.uniforms}