Skip to content

Commit 4047f2e

Browse files
authored
GLSLNodeBuilder: Fix texelFetch*() code generation with depth textures. (#31760)
* Add a swizzle when sampling a depth texture * Texture parameter can be null * Rollback to using vec4 for depth texture UV
1 parent 105a994 commit 4047f2e

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ ${ flowData.code }
380380
/**
381381
* Generates the GLSL snippet that reads a single texel from a texture without sampling or filtering.
382382
*
383-
* @param {Texture} texture - The texture.
383+
* @param {?Texture} texture - The texture.
384384
* @param {string} textureProperty - The name of the texture uniform in the shader.
385385
* @param {string} uvIndexSnippet - A GLSL snippet that represents texture coordinates used for sampling.
386386
* @param {?string} depthSnippet - A GLSL snippet that represents the 0-based texture array index to sample.
@@ -390,28 +390,42 @@ ${ flowData.code }
390390
*/
391391
generateTextureLoad( texture, textureProperty, uvIndexSnippet, depthSnippet, offsetSnippet, levelSnippet = '0' ) {
392392

393+
let snippet;
394+
393395
if ( depthSnippet ) {
394396

395397
if ( offsetSnippet ) {
396398

397-
return `texelFetchOffset( ${ textureProperty }, ivec3( ${ uvIndexSnippet }, ${ depthSnippet } ), ${ levelSnippet }, ${ offsetSnippet } )`;
399+
snippet = `texelFetchOffset( ${ textureProperty }, ivec3( ${ uvIndexSnippet }, ${ depthSnippet } ), ${ levelSnippet }, ${ offsetSnippet } )`;
398400

399-
}
401+
} else {
400402

401-
return `texelFetch( ${ textureProperty }, ivec3( ${ uvIndexSnippet }, ${ depthSnippet } ), ${ levelSnippet } )`;
403+
snippet = `texelFetch( ${ textureProperty }, ivec3( ${ uvIndexSnippet }, ${ depthSnippet } ), ${ levelSnippet } )`;
404+
405+
}
402406

403407
} else {
404408

405409
if ( offsetSnippet ) {
406410

407-
return `texelFetchOffset( ${ textureProperty }, ${ uvIndexSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
411+
snippet = `texelFetchOffset( ${ textureProperty }, ${ uvIndexSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
412+
413+
} else {
414+
415+
snippet = `texelFetch( ${ textureProperty }, ${ uvIndexSnippet }, ${ levelSnippet } )`;
408416

409417
}
410418

411-
return `texelFetch( ${ textureProperty }, ${ uvIndexSnippet }, ${ levelSnippet } )`;
419+
}
420+
421+
if ( texture !== null && texture.isDepthTexture ) {
422+
423+
snippet += '.x';
412424

413425
}
414426

427+
return snippet;
428+
415429
}
416430

417431
/**

0 commit comments

Comments
 (0)