|
@@ -219,19 +219,32 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
|
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
|
* @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
* @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.
|
|
|
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
|
* @return {string} The WGSL snippet.
|
|
* @return {string} The WGSL snippet.
|
|
|
*/
|
|
*/
|
|
|
- _generateTextureSample( texture, textureProperty, uvSnippet, depthSnippet, shaderStage = this.shaderStage ) {
|
|
|
|
|
|
|
+ _generateTextureSample( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet, shaderStage = this.shaderStage ) {
|
|
|
|
|
|
|
|
if ( shaderStage === 'fragment' ) {
|
|
if ( shaderStage === 'fragment' ) {
|
|
|
|
|
|
|
|
if ( depthSnippet ) {
|
|
if ( depthSnippet ) {
|
|
|
|
|
|
|
|
|
|
+ if ( offsetSnippet ) {
|
|
|
|
|
+
|
|
|
|
|
+ return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ offsetSnippet } )`;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet } )`;
|
|
return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet } )`;
|
|
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
|
|
|
|
+ if ( offsetSnippet ) {
|
|
|
|
|
+
|
|
|
|
|
+ return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ offsetSnippet } )`;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet } )`;
|
|
return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet } )`;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -253,21 +266,28 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
* @param {string} uvSnippet - 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} 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} 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.
|
|
* @return {string} The WGSL snippet.
|
|
|
*/
|
|
*/
|
|
|
- generateTextureSampleLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet ) {
|
|
|
|
|
|
|
+ generateTextureSampleLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, offsetSnippet ) {
|
|
|
|
|
|
|
|
if ( this.isUnfilterable( texture ) === false ) {
|
|
if ( this.isUnfilterable( texture ) === false ) {
|
|
|
|
|
|
|
|
|
|
+ if ( offsetSnippet ) {
|
|
|
|
|
+
|
|
|
|
|
+ return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet } )`;
|
|
return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet } )`;
|
|
|
|
|
|
|
|
} else if ( this.isFilteredTexture( texture ) ) {
|
|
} else if ( this.isFilteredTexture( texture ) ) {
|
|
|
|
|
|
|
|
- return this.generateFilteredTexture( texture, textureProperty, uvSnippet, levelSnippet );
|
|
|
|
|
|
|
+ return this.generateFilteredTexture( texture, textureProperty, uvSnippet, offsetSnippet, levelSnippet );
|
|
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
|
|
- return this.generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, levelSnippet );
|
|
|
|
|
|
|
+ return this.generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet, levelSnippet );
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -445,16 +465,23 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
* @param {Texture} texture - The texture.
|
|
* @param {Texture} texture - The texture.
|
|
|
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
|
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
* @param {string} uvSnippet - 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} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
|
|
|
|
|
+ * @param {string} [levelSnippet='0u'] - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
|
|
|
* @return {string} The WGSL snippet.
|
|
* @return {string} The WGSL snippet.
|
|
|
*/
|
|
*/
|
|
|
- generateFilteredTexture( texture, textureProperty, uvSnippet, levelSnippet = '0u' ) {
|
|
|
|
|
|
|
+ generateFilteredTexture( texture, textureProperty, uvSnippet, offsetSnippet, levelSnippet = '0u' ) {
|
|
|
|
|
|
|
|
this._include( 'biquadraticTexture' );
|
|
this._include( 'biquadraticTexture' );
|
|
|
|
|
|
|
|
const wrapFunction = this.generateWrapFunction( texture );
|
|
const wrapFunction = this.generateWrapFunction( texture );
|
|
|
const textureDimension = this.generateTextureDimension( texture, textureProperty, levelSnippet );
|
|
const textureDimension = this.generateTextureDimension( texture, textureProperty, levelSnippet );
|
|
|
|
|
|
|
|
|
|
+ if ( offsetSnippet ) {
|
|
|
|
|
+
|
|
|
|
|
+ uvSnippet = `${ uvSnippet } + vec2<f32>(${ offsetSnippet }) / ${ textureDimension }`;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return `tsl_biquadraticTexture( ${ textureProperty }, ${ wrapFunction }( ${ uvSnippet } ), ${ textureDimension }, u32( ${ levelSnippet } ) )`;
|
|
return `tsl_biquadraticTexture( ${ textureProperty }, ${ wrapFunction }( ${ uvSnippet } ), ${ textureDimension }, u32( ${ levelSnippet } ) )`;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -467,18 +494,26 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
|
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
|
* @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
* @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.
|
|
|
* @param {string} [levelSnippet='0u'] - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
|
|
* @param {string} [levelSnippet='0u'] - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
|
|
|
* @return {string} The WGSL snippet.
|
|
* @return {string} The WGSL snippet.
|
|
|
*/
|
|
*/
|
|
|
- generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, levelSnippet = '0u' ) {
|
|
|
|
|
|
|
+ generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet, levelSnippet = '0u' ) {
|
|
|
|
|
|
|
|
const wrapFunction = this.generateWrapFunction( texture );
|
|
const wrapFunction = this.generateWrapFunction( texture );
|
|
|
const textureDimension = this.generateTextureDimension( texture, textureProperty, levelSnippet );
|
|
const textureDimension = this.generateTextureDimension( texture, textureProperty, levelSnippet );
|
|
|
|
|
|
|
|
const vecType = texture.isData3DTexture ? 'vec3' : 'vec2';
|
|
const vecType = texture.isData3DTexture ? 'vec3' : 'vec2';
|
|
|
|
|
+
|
|
|
|
|
+ if ( offsetSnippet ) {
|
|
|
|
|
+
|
|
|
|
|
+ uvSnippet = `${ uvSnippet } + ${ vecType }<f32>(${ offsetSnippet }) / ${ vecType }<f32>( ${ textureDimension } )`;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const coordSnippet = `${ vecType }<u32>( ${ wrapFunction }( ${ uvSnippet } ) * ${ vecType }<f32>( ${ textureDimension } ) )`;
|
|
const coordSnippet = `${ vecType }<u32>( ${ wrapFunction }( ${ uvSnippet } ) * ${ vecType }<f32>( ${ textureDimension } ) )`;
|
|
|
|
|
|
|
|
- return this.generateTextureLoad( texture, textureProperty, coordSnippet, depthSnippet, levelSnippet );
|
|
|
|
|
|
|
+ return this.generateTextureLoad( texture, textureProperty, coordSnippet, depthSnippet, null, levelSnippet );
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -489,13 +524,20 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
* @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} uvIndexSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
|
* @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
* @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.
|
|
|
* @param {string} [levelSnippet='0u'] - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
|
|
* @param {string} [levelSnippet='0u'] - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
|
|
|
* @return {string} The WGSL snippet.
|
|
* @return {string} The WGSL snippet.
|
|
|
*/
|
|
*/
|
|
|
- generateTextureLoad( texture, textureProperty, uvIndexSnippet, depthSnippet, levelSnippet = '0u' ) {
|
|
|
|
|
|
|
+ generateTextureLoad( texture, textureProperty, uvIndexSnippet, depthSnippet, offsetSnippet, levelSnippet = '0u' ) {
|
|
|
|
|
|
|
|
let snippet;
|
|
let snippet;
|
|
|
|
|
|
|
|
|
|
+ if ( offsetSnippet ) {
|
|
|
|
|
+
|
|
|
|
|
+ uvIndexSnippet = `${ uvIndexSnippet } + ${ offsetSnippet }`;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if ( depthSnippet ) {
|
|
if ( depthSnippet ) {
|
|
|
|
|
|
|
|
snippet = `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ depthSnippet }, u32( ${ levelSnippet } ) )`;
|
|
snippet = `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ depthSnippet }, u32( ${ levelSnippet } ) )`;
|
|
@@ -578,20 +620,21 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
|
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
|
* @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
* @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.
|
|
|
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
|
* @return {string} The WGSL snippet.
|
|
* @return {string} The WGSL snippet.
|
|
|
*/
|
|
*/
|
|
|
- generateTexture( texture, textureProperty, uvSnippet, depthSnippet, shaderStage = this.shaderStage ) {
|
|
|
|
|
|
|
+ generateTexture( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet, shaderStage = this.shaderStage ) {
|
|
|
|
|
|
|
|
let snippet = null;
|
|
let snippet = null;
|
|
|
|
|
|
|
|
if ( this.isUnfilterable( texture ) ) {
|
|
if ( this.isUnfilterable( texture ) ) {
|
|
|
|
|
|
|
|
- snippet = this.generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, '0', shaderStage );
|
|
|
|
|
|
|
+ snippet = this.generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet, '0', shaderStage );
|
|
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
|
|
- snippet = this._generateTextureSample( texture, textureProperty, uvSnippet, depthSnippet, shaderStage );
|
|
|
|
|
|
|
+ snippet = this._generateTextureSample( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet, shaderStage );
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -607,14 +650,21 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
|
* @param {Array<string>} gradSnippet - An array holding both gradient WGSL snippets.
|
|
* @param {Array<string>} gradSnippet - An array holding both gradient WGSL snippets.
|
|
|
* @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
* @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.
|
|
|
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
|
* @return {string} The WGSL snippet.
|
|
* @return {string} The WGSL snippet.
|
|
|
*/
|
|
*/
|
|
|
- generateTextureGrad( texture, textureProperty, uvSnippet, gradSnippet, depthSnippet, shaderStage = this.shaderStage ) {
|
|
|
|
|
|
|
+ generateTextureGrad( texture, textureProperty, uvSnippet, gradSnippet, depthSnippet, offsetSnippet, shaderStage = this.shaderStage ) {
|
|
|
|
|
|
|
|
if ( shaderStage === 'fragment' ) {
|
|
if ( shaderStage === 'fragment' ) {
|
|
|
|
|
|
|
|
// TODO handle i32 or u32 --> uvSnippet, array_index: A, ddx, ddy
|
|
// TODO handle i32 or u32 --> uvSnippet, array_index: A, ddx, ddy
|
|
|
|
|
+ if ( offsetSnippet ) {
|
|
|
|
|
+
|
|
|
|
|
+ return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] }, ${ offsetSnippet } )`;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
|
|
return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
|
|
|
|
|
|
|
|
} else {
|
|
} else {
|
|
@@ -634,19 +684,32 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
|
* @param {string} compareSnippet - A WGSL snippet that represents the reference value.
|
|
* @param {string} compareSnippet - A WGSL snippet that represents the reference value.
|
|
|
* @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
* @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.
|
|
|
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
|
* @return {string} The WGSL snippet.
|
|
* @return {string} The WGSL snippet.
|
|
|
*/
|
|
*/
|
|
|
- generateTextureCompare( texture, textureProperty, uvSnippet, compareSnippet, depthSnippet, shaderStage = this.shaderStage ) {
|
|
|
|
|
|
|
+ generateTextureCompare( texture, textureProperty, uvSnippet, compareSnippet, depthSnippet, offsetSnippet, shaderStage = this.shaderStage ) {
|
|
|
|
|
|
|
|
if ( shaderStage === 'fragment' ) {
|
|
if ( shaderStage === 'fragment' ) {
|
|
|
|
|
|
|
|
if ( texture.isDepthTexture === true && texture.isArrayTexture === true ) {
|
|
if ( texture.isDepthTexture === true && texture.isArrayTexture === true ) {
|
|
|
|
|
|
|
|
|
|
+ if ( offsetSnippet ) {
|
|
|
|
|
+
|
|
|
|
|
+ return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet } )`;
|
|
return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet } )`;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if ( offsetSnippet ) {
|
|
|
|
|
+
|
|
|
|
|
+ return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet } )`;
|
|
return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet } )`;
|
|
|
|
|
|
|
|
} else {
|
|
} else {
|
|
@@ -665,22 +728,29 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
* @param {string} uvSnippet - 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} 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} 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.
|
|
|
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
|
* @return {string} The WGSL snippet.
|
|
* @return {string} The WGSL snippet.
|
|
|
*/
|
|
*/
|
|
|
- generateTextureLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet ) {
|
|
|
|
|
|
|
+ generateTextureLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, offsetSnippet ) {
|
|
|
|
|
|
|
|
if ( this.isUnfilterable( texture ) === false ) {
|
|
if ( this.isUnfilterable( texture ) === false ) {
|
|
|
|
|
|
|
|
|
|
+ if ( offsetSnippet ) {
|
|
|
|
|
+
|
|
|
|
|
+ return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet } )`;
|
|
return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet } )`;
|
|
|
|
|
|
|
|
} else if ( this.isFilteredTexture( texture ) ) {
|
|
} else if ( this.isFilteredTexture( texture ) ) {
|
|
|
|
|
|
|
|
- return this.generateFilteredTexture( texture, textureProperty, uvSnippet, levelSnippet );
|
|
|
|
|
|
|
+ return this.generateFilteredTexture( texture, textureProperty, uvSnippet, offsetSnippet, levelSnippet );
|
|
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
|
|
- return this.generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, levelSnippet );
|
|
|
|
|
|
|
+ return this.generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet, levelSnippet );
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -694,13 +764,20 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
|
* @param {string} biasSnippet - A WGSL snippet that represents the bias to apply to the mip level before sampling.
|
|
* @param {string} biasSnippet - A WGSL snippet that represents the bias to apply to the mip level before sampling.
|
|
|
* @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
* @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.
|
|
|
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
|
* @return {string} The WGSL snippet.
|
|
* @return {string} The WGSL snippet.
|
|
|
*/
|
|
*/
|
|
|
- generateTextureBias( texture, textureProperty, uvSnippet, biasSnippet, depthSnippet, shaderStage = this.shaderStage ) {
|
|
|
|
|
|
|
+ generateTextureBias( texture, textureProperty, uvSnippet, biasSnippet, depthSnippet, offsetSnippet, shaderStage = this.shaderStage ) {
|
|
|
|
|
|
|
|
if ( shaderStage === 'fragment' ) {
|
|
if ( shaderStage === 'fragment' ) {
|
|
|
|
|
|
|
|
|
|
+ if ( offsetSnippet ) {
|
|
|
|
|
+
|
|
|
|
|
+ return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ biasSnippet }, ${ offsetSnippet } )`;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ biasSnippet } )`;
|
|
return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ biasSnippet } )`;
|
|
|
|
|
|
|
|
} else {
|
|
} else {
|