-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
BitcountNode - Add bitCount functions #31990
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.
|
Related:
There is a custom bitCount() TSL function that I needed for the SSGI. The original Unity code used a built-in function but because of GLSL the code uses an implementation from https://graphics.stanford.edu/%7Eseander/bithacks.html.
three.js/examples/jsm/tsl/display/SSGINode.js
Lines 448 to 462 in 2a02884
It's great to see WGSL support! How about providing a built-in bitCount() TSL function that fallbacks to the above code for the WebGL backend?
It's great to see WGSL support! How about providing a built-in
bitCount()TSL function that fallbacks to the above code for the WebGL backend?
In hindsight, I think it's possible to add polyfills for the other functions as well, so I will get on doing that. The link you provided should be useful in generating the necessary functions.
I'm going to fix the extant issues like documentation, but I'm also going to draft this PR so I can implement a polyfill approach. Basically, I'd be adding GLSL polyfills similar to how the WGSLNodeBuilder has polyfills for certain functions. Would this approach be desired, or would a different approach be preferred ( for instance, generating different nodes depending on the renderer's backend ). Personally, I'd prefer polyfilling in the GLSLNodeBuilder to keep the node code simpler for a simple mathematical operation.
Personally, I'd prefer polyfilling in the GLSLNodeBuilder to keep the node code simpler for a simple mathematical operation.
Then I suggest you start with that approach so we can see how it ends up in code.
(削除) I see that the bid twiddling hacks for counting bits mainly concern Uints, but the WGSL countOneBits function (GLSL bitCount equivalent), can also take in a signed integer or vectors. The vectors are trivial to implement, but are there any references for a signed integer equivalent of bitCount? (削除ここまで)
Nevermind, we can just case the i32 to a u32 using the GLSL bitcast functionality.
Test Examples
- Validate functionality under WebGL backend
https://raw.githack.com/cmhhelgeson/three.js/bit_count_example/examples/webgpu_bitcount.html
- Validate SSGI functionality (the visuals seem off here but they match the existing representation of SSGI under the WebGL backend)
Existing SSGI Example with forceWebGL set to true as example. Note how the existing SSGI implementation is significantly more noisy than the WebGPU example.
https://raw.githack.com/cmhhelgeson/three.js/ssgi_test/examples/webgpu_postprocessing_ssgi.html
the visuals seem off here
What deviations are you seeing on your system?
a3fe872 to
6650be0
Compare
4eabc26 to
a238659
Compare
Is it possible that #32091 is affecting the ability of displacementmap to pass its test? I'm not sure if the screenshots were updated before or after the light scattering PR, as that's the only reason I could think as to why materials_displacement is failing despite not activating the SSGINode.
...Count helper function names
...component wise bitCounts rather than accumulative bitCounts
a238659 to
07c1c38
Compare
Uh oh!
There was an error while loading. Please reload this page.
Description
Add countTrailingZeros, countLeadingZeros, and countOneBits to TSL. Ideally, this functionality would also be accessible through the WebGLBackend, but I'm not sure what the status or likelihood is of the GLSL 3.1 functionality getting added to WebGL anytime in the future ( see KhronosGroup/WebGL#3714 ).
The impetus for implementing these functions is that they're notionally more concise and/or performant than equivalent operations ( log2, directly bit shifting, etc ).
I've also implemented each of these functions GLSL equivalents (findLSB, findMSB, bitCount) as aliases for the GLSL to TSL transpiration process. If it's preferred by the maintainers, we can get rid of the aliases and/or use the NodeBuilders to specify how the bitCount functions get constructed instead.