将FP16值存储在RGBA8纹理中

时间:2014-04-20 14:08:59

标签: opengl

是否可以将FP16值存储在RGBA8纹理中,存储在RG和BA中,就像在此图像中一样?如何在具有渲染纹理和FBO的OpenGL 3.3+中实现?

enter image description here

1 个答案:

答案 0 :(得分:4)

这只是我的头脑,但你不能乘以255并取整数部分和小数部分?像这样:

vec2 normal = vec2(normalizedX, normalizedY);
normal = normal / 2.0 + 0.5; // <- This gets all values to be between 0 and 1
vec4 intNormal;
intNormal.r = (int)(normal.x * 255.0);
intNormal.g = (int)(fract(normal.x * 255.0) * 255.0);
intNormal.b = (int)(normal.y * 255.0);
intNormal.a = (int)(fract(normal.y * 255.0) * 255.0);

然后你可以像这样重建它们,我想:

vec4 intNormal = texture2D (gBuffer, coord); // Or wherever you get it from
vec2 normal;
normal.x = (float)intNormal.r / 255.0 + ((float)intNormal.g / 255.0) / 255.0;
normal.y = (float)intNormal.b / 255.0 + ((float)intNormal.a / 255.0) / 255.0;
normal = normal * 2.0 - 1.0; // <- this gets us back to -1.0 to 1.0 for the normal