Skip to content
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

TSL Support for data packing / unpacking functions #30663

Open
brutestack opened this issue Mar 6, 2025 · 0 comments
Open

TSL Support for data packing / unpacking functions #30663

brutestack opened this issue Mar 6, 2025 · 0 comments
Labels
Enhancement TSL Three.js Shading Language

Comments

@brutestack
Copy link

brutestack commented Mar 6, 2025

Description

Currently there is no way to rewrite GLSL shader that uses packing functions such as UnpackHalf2x16 to TSL. However, both GLSL and WGSL provide equivalent functions for packing/unpacking vectors to/from integers

GLSL:

PackSnorm4x8
PackUnorm4x8
PackSnorm2x16
PackUnorm2x16
PackHalf2x16
PackDouble2x32

UnpackSnorm4x8
UnpackUnorm4x8
UnpackSnorm2x16
UnpackUnorm2x16
UnpackHalf2x16
UnpackDouble2x32

WGSL:

pack4x8snorm
pack4x8unorm
pack4xI8
pack4xU8
pack4xI8Clamp
pack4xU8Clamp
pack2x16snorm
pack2x16unorm
pack2x16float

unpack4x8snorm
unpack4x8unorm
unpack4xI8
unpack4xU8
unpack2x16snorm
unpack2x16unorm
unpack2x16float

https://www.w3.org/TR/WGSL/#pack-builtin-functions
https://www.w3.org/TR/WGSL/#unpack-builtin-functions

Solution

Please add packing and unpacking functions to TSL like it is done for bitcast function in MathNode

Alternatives

Otherwise is there any simple way of adding new math functions to TSL by providing GLSL and WGSL code equivalents?

Additional context

GLSL example code:

uint packedValue = 0x3C001A00; // Example 32-bit unsigned integer
vec2 unpackedValue = unpackHalf2x16(packedValue);

After rewritten to TSL should look like this:

const packedValue = uint(0x3C001A00); // Example 32-bit unsigned integer
const unpackedValue = packedValue.unpack2x16float(); // vec2 result of unpacking
@sunag sunag added Enhancement TSL Three.js Shading Language labels Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement TSL Three.js Shading Language
Projects
None yet
Development

No branches or pull requests

2 participants