shaderwebglfragment-shader

Accessing unclamped values from floating point textures in WebGL fragment shader


I'm trying to render a matrix of luminance values on a canvas as an image, when the luminance values are between 0 and 4000. I'm using a 2D floating point texture to do so, because I had heard that they offer ranges between [-inf, inf].

gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, ct.columns, ct.rows, 0, gl.LUMINANCE, gl.FLOAT, new Float32Array(ct.grid[i]));

However, when I go and retrieve the texture values in my fragment shader, they are always clamped between [0, 1.0]. Specifically,

vec4 texcolour = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));

texcolour.rgb will always be between 0 and 1.0. How can I access unclamped values inside my fragment shader, so that I may do the normalizing myself?

Thank you


Solution

  • How are you testing this? Can you try something like

    vec4 texcolour = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
    gl_FragColor = texcolour.x > 3000.0 ? vec4(0,1,0,1) : vec4(1,0,0,1);
    

    Update: The issue for OP turned out to be a bug in Chromium in handling LUMINANCE and depth textures (it's been fixed since).