-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
TSL: Add texture offset feature #31715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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