1

I try to create simple computer tomography viewer with OpenGL, data is 1D float array that represents single slice.

glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE,  width, height, 0, GL_LUMINANCE, GL_FLOAT, data);

Question

How to modify the colors/float values in fragment shader for the windowing purposes So displaying all values above some treshold as white and all below as black and the rest as greys between

my fragment shader

out vec4 FragColor;
  
in vec3 ourColor;
in vec2 TexCoord;

uniform sampler2D ourTexture;

void main()
{
    FragColor = texture(ourTexture, TexCoord);
}

All works well yet I have some problems

Image I get now just for reference

1

1 Answer 1

3

well simply by combining thresholding with linear interpolation something like this:

out vec4 FragColor;
  
in vec3 ourColor;
in vec2 TexCoord;

uniform sampler2D ourTexture;

void main()
    {
    vec4 col=texture(ourTexture, TexCoord);   // input color
    float t0=0.25,t1=0.75;                    // thresholds
    float t=length(col.rgb)/1.73205081;       // /sqrt(3) ... parameter is intensity of color
    t=(t-t0)/(t1-t0);                         // dynamic range <t0,t1> -> <0,1>
    t=max(t,0.0);                             // cut off unused range
    t=min(t,1.0);
    FragColor = vec4(t,t,t,col.a);
    }

Beware I did not test it as I wrote this directly in answer editor so there might be some hidden typos and too lazy to create MCVE from scratch...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.