|
|
@@ -582,7 +582,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Generates the WGSL snippet that reads a single texel from a texture without sampling or filtering.
|
|
|
+ * Generates the WGSL snippet that reads a single texel from a storage texture.
|
|
|
*
|
|
|
* @param {Texture} texture - The texture.
|
|
|
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
|
@@ -592,11 +592,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
* @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
|
|
|
* @return {string} The WGSL snippet.
|
|
|
*/
|
|
|
- generateTextureLoad( texture, textureProperty, uvIndexSnippet, levelSnippet, depthSnippet, offsetSnippet ) {
|
|
|
-
|
|
|
- const isStorageTexture = texture.isStorageTexture === true;
|
|
|
-
|
|
|
- if ( levelSnippet === null && ! isStorageTexture ) levelSnippet = '0u';
|
|
|
+ generateStorageTextureLoad( texture, textureProperty, uvIndexSnippet, levelSnippet, depthSnippet, offsetSnippet ) {
|
|
|
|
|
|
if ( offsetSnippet ) {
|
|
|
|
|
|
@@ -608,33 +604,52 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
|
|
|
if ( depthSnippet ) {
|
|
|
|
|
|
- // Storage textures don't take a level parameter in WGSL
|
|
|
- if ( isStorageTexture ) {
|
|
|
+ snippet = `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ depthSnippet } )`;
|
|
|
|
|
|
- snippet = `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ depthSnippet } )`;
|
|
|
+ } else {
|
|
|
|
|
|
- } else {
|
|
|
+ snippet = `textureLoad( ${ textureProperty }, ${ uvIndexSnippet } )`;
|
|
|
|
|
|
- snippet = `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ depthSnippet }, u32( ${ levelSnippet } ) )`;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ return snippet;
|
|
|
|
|
|
- } else {
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Generates the WGSL snippet that reads a single texel from a texture without sampling or filtering.
|
|
|
+ *
|
|
|
+ * @param {Texture} texture - The texture.
|
|
|
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
|
+ * @param {string} uvIndexSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
|
+ * @param {?string} levelSnippet - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
|
|
|
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
|
+ * @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
|
|
|
+ * @return {string} The WGSL snippet.
|
|
|
+ */
|
|
|
+ generateTextureLoad( texture, textureProperty, uvIndexSnippet, levelSnippet, depthSnippet, offsetSnippet ) {
|
|
|
|
|
|
- // Storage textures don't take a level parameter in WGSL
|
|
|
- if ( isStorageTexture ) {
|
|
|
+ if ( levelSnippet === null ) levelSnippet = '0u';
|
|
|
|
|
|
- snippet = `textureLoad( ${ textureProperty }, ${ uvIndexSnippet } )`;
|
|
|
+ if ( offsetSnippet ) {
|
|
|
|
|
|
- } else {
|
|
|
+ uvIndexSnippet = `${ uvIndexSnippet } + ${ offsetSnippet }`;
|
|
|
|
|
|
- snippet = `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, u32( ${ levelSnippet } ) )`;
|
|
|
+ }
|
|
|
|
|
|
- if ( this.renderer.backend.compatibilityMode && texture.isDepthTexture ) {
|
|
|
+ let snippet;
|
|
|
|
|
|
- snippet += '.x';
|
|
|
+ if ( depthSnippet ) {
|
|
|
|
|
|
- }
|
|
|
+ snippet = `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ depthSnippet }, u32( ${ levelSnippet } ) )`;
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ snippet = `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, u32( ${ levelSnippet } ) )`;
|
|
|
+
|
|
|
+ if ( this.renderer.backend.compatibilityMode && texture.isDepthTexture ) {
|
|
|
+
|
|
|
+ snippet += '.x';
|
|
|
|
|
|
}
|
|
|
|