Comments (12)
Live example with changes proposed in this post: (panning is enabled in this example)
https://raw.githack.com/westlangley/three.js/dev-pack_depth/examples/webgl_materials_channels.html
Master branch: (panning disabled)
https://threejs.org/examples/webgl_materials_channels.html
from three.js.
I did a few round-trip tests with the new routines and everything seems to work as expected.
@WestLangley Since you have already updated the channels example, would you file these changes as a PR? The new constants THREE.RGDepthPacking
and THREE.RGADepthPacking
sound good to me.
from three.js.
My fix:
- force the value when v=1.0
- correct the last element of UNPACK_FACTORS
- change the order RGBA -> R is the most significant
- make similar (but slightly) different functions for 3 "resolutions" : RGBA (4 bytes), RGB (3 bytes) RG (2 bytes)
Here I made a fiddle , which tests in javascript the packing/unpacking for all cases, with alternative float-uint8 conversions (the common one, fquant255_a , and the alternative fquant255_b)
It seems it works ok, the relative error (error/ 256^components) does not exceed the expected values. It works slightly better for the common quantization)
If asked, i can provide the GLSL versions
https://jsfiddle.net/hjgonzalez984/2z39qw8d/41/
from three.js.
Here is an implementation of mine, with a sandbox to test it
https://codesandbox.io/p/sandbox/threejs-depth-packing3-5wklnl
I think the RGB and RG variants should be added as alternatives to the MeshDepthMaterial.depthPacking constant
https://threejs.org/docs/#api/en/materials/MeshDepthMaterial.depthPacking
And I think that the RGB should be preferred over RGBA. With 24 bits (and even 16 bits) of precision we already cover the vast majority of practical uses. Also, considering that the float simple precision is 24 bits, in real life, when using RGBA the least significant channel (be it R or A) will be just noise (or zero).
from three.js.
I have updated the live examples posted above to include the latest changes proposed by @leonbloy.
from three.js.
The PR affects the velocity shader in https://threejs.org/examples/webgl_materials_channels
This is also the only module where the mentioned packing/unpacking routines are used.
@bhouston Since these functions were added in #23784, do you mind having a look at this issue?
from three.js.
@Rabbid76 I've seen at stackoverflow that you have quite some experience in this area. In your post about depth packing you essentially implement the point differently that is raised by the OP. The order of the pack factors is reversed. Should we update our RGBA packing routines?
from three.js.
If I'm not mistaken, packDepthToRGBA has a more fundamental problem:
packDepthToRGBA(1.0) = packDepthToRGBA(0.0) = vec4(0, 0, 0, 0)
from three.js.
This is good stuff. These encoders/decoders have always been problematic.
BTW I implemented a glsl unit test system in Threeify. Would be amazing to get something similar to that in Three.js at some point:
https://github.com/bhouston/threeify/blob/main/packages/core/src/shaders/math/unitIntervalPacking.test.glsl
https://github.com/bhouston/threeify/blob/main/packages/core/src/shaders/microgeometry/normalPacking.test.glsl
Basically It would run these shaders and the asset would write 0 or 1 into a texture which I would then read back and check:
https://github.com/bhouston/threeify/blob/main/examples/src/units/glsl/index.ts
Formally proposed as a new feature here: #28708
from three.js.
I'm not sure if it's possible to do something safe, because the packing/unpacking needs to know exactly how the mapping float-uint8 is done internally, round( v * 255.0)
or floor(v * 255.999...)
or whatever. And, if I'm not mistaken, this is not mandated
from three.js.
I'm not sure if it's possible to do something safe, because the packing/unpacking needs to know exactly how the mapping float-uint8 is done internally, round( v * 255.0) or floor(v * 255.999...) or whatever. And, if I'm not mistaken, this is not mandated
You could use a similar idea to the unit tests, but it would be a quick test that is run initially on load to profile the GPU / drivers, to determine the packing details and then use that information in order to pick which packing method to use in the full shaders.
from three.js.
I think it would be good to have a PR for this. In this way, we can easier evaluate the suggested changes.
All four points of your suggested fix sound good to me.
make similar (but slightly) different functions for 3 "resolutions" : RGBA (4 bytes), RGB (3 bytes) RG (2 bytes)
Even if we don't need the RGB routines, it can't hurt to have working versions in the repository.
from three.js.
Related Issues (20)
- NodeCache breaking change with offscreenCanvas in WebGPURenderer and Point Light HOT 2
- Reflector: Add support for `OrthographicCamera`. HOT 12
- Documentation: State of `WebGPURenderer` and Nodes HOT 5
- Mesh: allow caller to specify which geometry to raycast and ignore material visibility HOT 1
- VRMLLexer: Improve support for `Script`, `PROTO` and sensor nodes. HOT 6
- Examples: webgpu_materials.html is rendering material as black
- WebXR not supported on WebGPURenderer HOT 3
- WebGPU example "Fat line" broken when dash enabled HOT 1
- Mesh Bash Flickering on iOS ( webgpu enabled ) HOT 2
- Better performance support for passing `VideoFrame`'s to a `CanvasTexture` or `VideoTexture`
- OutputPass inpostprocessing. render error HOT 1
- TSL Editor Example: Does not work because of 404 of three JS files HOT 5
- MaterialXLoader: "time" and "frame" MaterialX nodes not loaded
- MaterialXLoader: Can't load `standard_surface_brick_procedural.mtlx` sample file
- Can't load #standard_surface_brick_procedural.mtlx sample file HOT 1
- URL `https://experience.soletanche-bachy.com/` is not available on projects page HOT 1
- Using the games_fps example, there is an exception in my model
- GLTFExport + KTX textures issue
- Many demos on the internet are no more working since r161 HOT 6
- Vite import fails on v0.167.0 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from three.js.