Packing float into vec4 - how does this code work?

前端 未结 3 1874
离开以前
离开以前 2020-12-05 11:01

I am trying to study shadow mapping in WebGL. I see same piece of shader code copied in various libraries and examples that achieve this. However nowhere did I find the expl

3条回答
  •  情深已故
    2020-12-05 11:10

    It's not storing a GLSL float in a GLSL vec4. What it's doing is storing a value in a vec4 which, when written to an RGBA8 framebuffer (32-bit value) can be read as a vec4 and then reconstituted into the same float that was given previously.

    If you did what you suggest, just writing the floating-point value to the red channel of the framebuffer, you'd only get 8 bits of accuracy. With this method, you get all 32-bits working for you.

提交回复
热议问题