What happens to float values written to UNSIGNED_BYTE texture? This is more a theoretical question. I'm wondering what happens when I write float values into an empty RGBA texture of type gl.UNSIGNED_BYTE in WebGL 1.0. Obviously, every channel then has 8 bits. But that wouldn't be enough to represent floating point values, would it? Nevertheless it somehow works, more or less. See part of a fragment shader code here:

precision highp float;

uniform vec2 u_Resolution;

void main(void){
   gl_FragColor = vec4(gl_FragCoord.xy / u_Resolution, 0.0, 1.0);
}


When I specify the texture to be of type gl.FLOAT (using the OES_texture_float extension), the results of course look better. But I want to know exactly why they do.

In addition: does the specified precision have an effect on the texture (to be written)?
Unsigned byte textures in a graphics API are usually "normalized"—the byte values are interpreted as ranging from 0.0 to 1.0, with a byte of 255 mapping to 1.0. So no, they aren't truly floating-point values, but the hardware will automatically convert them to/from float when you read/write the texture. If you try to write a value outside the [0, 1] range, it will be clamped.

As for the precision highp part, it doesn't directly affect the texture, but it can certainly affect any calculations of values you write to the texture. For example, to calculate an 8-bit texture you certainly want a minimum of 8 bits of mantissa precision (i.e. lowp)—and you probably want more than that, depending on what calculations you're doing. I'd advise you to check what the actual precision levels are on your device, since they vary widely depending on what GPU you have. See this question for more.