Uint8Array to Texture conversion seems to be off by one.
See original GitHub issueI’m working on a custom shader that takes some state as a texture, with one item per pixel. The state is stored in a Uint8Array
which is converted to a one dimensional texture like this:
const state = new Uint8Array(items * 4);
const texture = new PIXI.Texture.fromBuffer(state, items, 1);
When the texture was passed to the shader (as a uniform), the values all seemed slightly off. I tried multiplying each value by 255.0
the dividing the result by 256.0
, and everything worked correctly.
It appears that PIXI is dividing the unsigned 8-bit integers in the Uint8Array by 255
to convert them to floating point fractions of one, when it should be dividing by 256
.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top Results From Across the Web
Uint8Array to Texture conversion seems to be off by one. #6507
I'm working on a custom shader that takes some state as a texture, with one item per pixel. The state is stored in...
Read more >Float32Array not updating ArrayBuffer to reflect assigned ...
1 Answer 1 · Beautifully answered, thank you so much! After refactoring into a few isolated tests it appears to not be the...
Read more >Problem with constructing a DataTexture with ArrayBuffer
The document says DataTexture can receive an ArrayBuffer as argument to construct a new DataTexture. In fact, three.js will not transfer the ArrayBuffer...
Read more >Image Textures
So, working with texture images in WebGL involves working with texture objects, texture units, and sampler variables. The relationship among the three is ......
Read more >WebGL2 Textures
We use the texture coordinates passed from the vertex shader and we call texture to look up a color from that texture. #version...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m happy to share that experience with you. Its not often people stumble across it, and yes it should be confusing.
255 is 1.0