开发者

Reading 32-bit RGBA float values in GLSL

开发者 https://www.devze.com 2022-12-14 10:18 出处:网络
I\'m trying send some 32 bit float data to a shader, but the results are erratic. If I test with full white (1,1,1,1) the values are all zero. This is my code for creating the texture:

I'm trying send some 32 bit float data to a shader, but the results are erratic. If I test with full white (1,1,1,1) the values are all zero. This is my code for creating the texture:

gl.glTexIm开发者_如何学JAVAage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA32F_ARB, 512, 512, 0, GL.GL_RGBA, GL.GL_FLOAT, data);

and reading from it in GLSL:

uniform sampler2D u_tex1;

varying vec2 v_uv;

void main()
{
    gl_FragColor = texture2D(u_tex1, v_uv);
}

If i set the texture to random values something shows up, but it's not correct. Is this the correct way to read from an RGBA32F texture or am I missing something?


You're not giving much info on the things you did< The code you show is correct though.

Some things I can think of that may be wrong:

  • your data does not have the right data in (are there floats in there?)
  • your texture is not filtered properly (since you only provide 1 mip level, you need to disable mipmapping)
  • your texture is not bound to the texture unit for the sampler u_tex1 (so you may not be fetching from it).
  • your texture coordinates are not what you think they are (and, depending on your clamping/wrapping mode, this can lead to a texel that is not white. Use GL_CLAMP_TO_EDGE or GL_REPEAT to not interact with the texture border)

There are lots of ways to not have texturing working, I hope I hit the correct one in this list!

0

精彩评论

暂无评论...
验证码 换一张
取 消