TSL: Add texture offset feature#31715
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
|
|
||
| if ( offsetSnippet ) { | ||
|
|
||
| uvSnippet = `${ uvSnippet } + ${ vecType }<f32>(${ offsetSnippet }) / ${ vecType }<f32>( ${ textureDimension } )`; | ||
|
|
||
| } | ||
|
|
There was a problem hiding this comment.
This part and another similar one in generateFilteredTexture are a bit odd, but they are implemented this way because the wrap function expects normalized texture coordinates.
This reverts commit bdf37a2.
|
There is already the possibility to define offset for textures: three.js/src/textures/Texture.js Lines 191 to 198 in f78867d Is What would happen if you use |
|
If I'm correct, that offset is for repeating, but the offset node on TextureNode is for sampling offset (i.e. sampling a UV with an offset of the unnormalized texture coordinate, just as we do with |
|
Answering your question, both offsets are applied. One is in the UV space with a wrap function, and the other is applied at sampling time after wrapping. A typical use case of the sampling offset is convolution or neighbor texel lookup, and Texture's offset is not appropriate for it. |
|
For the sake of completeness, But I understand there is a distinction between offsetting texture coordinates and use cases where So the unit of |
|
I should have said Yes, offsetNode is in signed integers, as written in the JSDoc. Both GLSL and WGSL have well-defined dedicated functions or overloads. |
Related issue: None
Description
This PR adds
offsetNodetoTextureNodeandTexture3DNodefor the texel offset applied to the unnormalized texture coordinate before sampling the texture.In the WebGLBackend, a texture sample with an offset should be transpiled to the corresponding built-in functions, but in the WebGPUBackend, the built-in functions corresponding to the following do not have an offset parameter, thus they behave differently than built-in functions (i.e. works without upper/lower limits on the offset).
load()sample(),level()on unfilterable textures