将无符号整数纹理转换为标准化浮点数并再返回的正确方法是什么?
作为一个测试,我目前正在尝试将无符号的int纹理渲染到标准的RGB上下文,以下是有效的,但感觉不对
相关抽奖代码:
ShaderPropertySetter.SetUniform(gl, "uTexture_us2", 0);
ShaderPropertySetter.SetUniform(gl, "maxIntensity_u", MaxIntensity);
ShaderPropertySetter.SetUniform(gl, "minIntensity_u", MinIntensity);
ShaderPropertySetter.SetUniformMat4(gl, "uModelMatrix_m4", modelMatrix);
canvas.Bind(gl);// this binds the vertex buffer
gl.BindTexture(OpenGL.GL_TEXTURE_2D, texture);
gl.DrawArrays(OpenGL.GL_QUADS, 0, 4);
纹理创建
public static void FillTextureDataWithUintBuffer(OpenGL gl, uint[] buffer, int width, int height)
{
unsafe
{
fixed (uint* dataprt = buffer)
{
IntPtr pixels = new IntPtr(dataprt);
const int GL_R32UI = 0x8236; //GL_R32UI is not currently defined in SharpGL
gl.TexImage2D(OpenGL.GL_TEXTURE_2D,
0,
GL_R32UI,
width,
height,
0,
OpenGL.GL_RED_INTEGER,
OpenGL.GL_UNSIGNED_INT,
pixels);
}
}
OpenGLTesting.CheckForFailure(gl);
}
目前的GLSL代码
--- ----修订 (修正了评论者指出的愚蠢错误) #version 150核心
in vec2 pass_texCord;
uniform usampler2D uTexture_us2;
uniform uint maxIntensity_u;
uniform uint minIntensity_u;
float linearNormalize(float value, in float max, in float min)
{
//normalized = (x-min(x))/(max(x)-min(x))
return (value - min) / (max - min);
}
void main(void)
{
uvec4 value = texture(uTexture_us2, pass_texCord);
float valuef = float(value.r);
float max = float(maxIntensity_u);
float min = float(minIntensity_u);
float normalized = linearNormalize(valuef,max,min) ;
gl_FragColor = vec4(normalized,normalized,normalized,1);
}
所以我对GLSL代码的当前状态不满意(特别是因为它没有工作:p)因为我正在执行浮动转换,这似乎打败了这一点。
原因:
我正在研究一个合成器,其中一些纹理存储为单通道unsigned int,而其他纹理存储在三通道浮点数中,当一个与另一个混合时,我想转换" blendee"
注意:我正在使用SharpGL