question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uint8Array to Texture conversion seems to be off by one.

See original GitHub issue

I’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:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

4reactions
ivanpopelyshevcommented, Mar 29, 2020

I’m happy to share that experience with you. Its not often people stumble across it, and yes it should be confusing.

1reaction
ivanpopelyshevcommented, Mar 29, 2020

255 is 1.0

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found