Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since you didn't deign to give us the exact code you used to create and upload your texture, I can only guess at what you're doing.</p> <p>You seem to be creating a JavaScript array of floating-point numbers. You then create a Uint8Array, passing that array to the constructor. </p> <p>According to the WebGL spec (or rather, the spec that the WebGL spec refers to when ostensibly specifying this behavior), the conversion from floats to unsigned bytes happens in one of two ways, based on the destination. If the destination is considered "clamped", then it clamps the number to the destination range, namely [0, 255] for your case. If the destination is not considered "clamped", then it is taken modulo 2<sup>8</sup>. The WebGL "specification" is sufficiently poor that it is not entirely clear whether the construction of Uint8Array is considered clamped or not. Whether clamped or taken modulo 2<sup>8</sup>, the decimal point is chopped off and the integer value stored.</p> <p>However, when you give this data to <strike>Open</strike>WebGL, you told WebGL to interpret the bytes as normalized unsigned integer values. This means that the input values on the range [0, 255] will be accessed by users of the texture as [0, 1] floating point values.</p> <p>So if your input array had the value 183.45, the value in the Uint8Array would be 183. The value in the texture would be 183/255, or 0.718. If your input value was 0.45, the Uint8Array would hold 0, and the texture result would be 0.0.</p> <p>Now, because you passed the data as GL_RGBA, that means that every 4 unsigned bytes will be taken as a single texel. So every call to <code>texture</code> will fetch those particular four values (at the given texture coordinate, using the given filtering parameters), thus returning a <code>vec4</code>.</p> <p>It is not clear what you intend to do with this floating-point data, so it is hard to make suggestions as to how best to pass float data to a shader. However, a general solution would be to use the OES_texture_float extension and actually create a texture that stores floating-point data. Of course, if it isn't available, you'll still have to find a way to do what you want.</p> <p>BTW, Khronos really should be ashamed of themselves for even calling WebGL a specification. It barely specifies anything; it's just a bunch of references to <em>other</em> specifications, which makes finding the effects of anything exceedingly difficult.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload