Skip to content

Commit

Permalink
WebGPURenderer: Support textureCompare() operations in WebGL backend (#…
Browse files Browse the repository at this point in the history
…26823)

Co-authored-by: aardgoose <angus.sawyer@email.com>
  • Loading branch information
aardgoose and aardgoose committed Sep 22, 2023
1 parent ac901f1 commit 5bab962
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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' ) {

Expand Down Expand Up @@ -324,6 +346,7 @@ ${ this.getSignature() }
// precision
precision highp float;
precision highp int;
precision lowp sampler2DShadow;
// uniforms
${shaderData.uniforms}
Expand Down

0 comments on commit 5bab962

Please sign in to comment.