Question

Im trying to create a fragment shader that will do the same job as the photoshop levels output slider. I would like to do this on a specific channel (in this case blue).

I have the code as below:

varying highp vec2 textureCoordinate;

uniform sampler2D inputImageTexture;

#define GammaCorrection(color, gamma)       pow(color, vec3(1.0/gamma))

#define LevelsControlOutputRange(color, minOutput, maxOutput) mix(vec3(minOutput/255), vec3(maxOutput/255), color)


void main()
{

     lowp vec4 texel = texture2D(inputImageTexture, textureCoordinate);

     lowp vec3 outputColor;
     outputColor.rgb = texel.rgb;

     lowp vec3 pass3 = LevelsControlOutputRange(outputColor,200,255); 

     lowp vec4 pass4;
     pass4.r = outputColor.r;
     pass4.g = outputColor.g;
     pass4.b = pass3.b;

 gl_FragColor = pass4;


}

This has no effect on the resulting image so i think that i may have to do more with the line:

pass4.b = pass3.b;

Could anyone help point me in the right direction?

Thanks

Was it helpful?

Solution

mix takes a value between 0…1 as the mixing parameter. Your 255 will be clamped to 1 and therefore you'll always get the max output value. In a similar fashion texture values are in the range 0…1 to you must not divide by 255 to get into some range! BTW: Simply dividing by 255 is not correct – details here http://kaba.hilvi.org/programming/range/index.htm

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top