mattdesl / glsl-lut

lookup table color transforms for glslify
http://mattdesl.github.io/glsl-lut/example/demo.html
MIT License
175 stars 12 forks source link

confusing calculation of texture position #4

Closed jiseopX closed 5 months ago

jiseopX commented 4 years ago

in your fragment shader glsl code, it calculates texture position as texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);

but i can't understand the meaning of the formula what is '0.5/512.0' for? why isn't it texPos1.x = (quad1.x * 0.125) + 63.0/512.0 * textureColor.r; ?

mattdesl commented 4 years ago

Your suggestion leads to a different computation.

r = 0.5 // => 0.5
x = 0.5/512.0 + ((0.125 - 1.0/512.0) * r) // => 0.0625
y = 63.0/512.0 * r; // => 0.0615234375
Dimezis commented 4 years ago

what is '0.5/512.0' for? Assuming 512 is the size of the LUT, 0.5/512 is the size of half-texel.

It is used to shift the position by half-texel from the top left corner of the texel, so the color is not being interpolated