Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

For my android application, I want to apply brightness and contrast shader on same image.

At present I am using gpuimage plugin. In that I found two separate program for brightness and contrast as per the following.

Contrast shader:

    varying highp vec2 textureCoordinate;

    uniform sampler2D inputImageTexture;
    uniform lowp float contrast;

    void main()
    {
         lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);

         gl_FragColor = vec4(((textureColor.rgb - vec3(0.5)) * contrast + vec3(0.5)), textureColor.w);
    }

Brightness shader:

    varying highp vec2 textureCoordinate;

    uniform sampler2D inputImageTexture;
    uniform lowp float brightness;

    void main()
    {
        lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);

        gl_FragColor = vec4((textureColor.rgb + vec3(brightness)), textureColor.w);
    }

Now applying both of the effects I write following code

    varying highp vec2 textureCoordinate;
    uniform sampler2D inputImageTexture;
    varying highp vec2 textureCoordinate2;
    uniform sampler2D inputImageTexture2;
    uniform lowp float contrast;
    uniform lowp float brightness;

    void main()
    {
        lowp vec4 textureColorForContrast = texture2D(inputImageTexture, textureCoordinate);

        lowp vec4 contastVec4 = vec4(((textureColorForContrast.rgb - vec3(0.5)) * contrast + vec3(0.5)), textureColorForContrast.w);
        lowp vec4 textureColorForBrightness = texture2D(inputImageTexture2, textureCoordinate2);

        lowp vec4 brightnessVec4 = vec4((textureColorForBrightness.rgb + vec3(brightness)), textureColorForBrightness.w);
        gl_FragColor = contastVec4 + brightnessVec4;
    }

Doesn't able to get desire result. I can't able to figure out what I have to do next? So please friends help me in this. What program I have to write?

share|improve this question

closed as off-topic by Josh Petrie Jun 16 at 16:40

  • This question does not appear to be about game development within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

    
This question is a intra-network cross-post. Please don't cross-post between StackExchange sites. –  Josh Petrie Jun 16 at 16:40
add comment

1 Answer 1

up vote 1 down vote accepted

Try:

varying highp vec2 textureCoordinate;

uniform sampler2D inputImageTexture;
uniform lowp float brightness;
uniform lowp float contrast;

void main()
{
    lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
    textureColor.rgb = ((textureColor.rgb - vec3(0.5)) * contrast + vec3(0.5));
    gl_FragColor = vec4((textureColor.rgb + vec3(brightness)), textureColor.w);
}

EDIT: The reason why your shader was not working, is because you were doubling the input too. If you think of it, the first shaders apply ONE effect to ONE image. When merging both, you'd expect TWO effects on ONE image. But what you tried to do was applying TWO effects on TWO images. You just had to get rid of the second texture and UV parameters, then apply both effects on the single texture remaining.

share|improve this answer
    
Downvoter, care to comment? –  Gustavo Maciel Jun 12 at 16:33
    
Thanks for your reply. I will reply you shortly. –  Siddharth Jun 12 at 16:35
    
Sorry at present I can't give you reply because my eclipse not working properly because adt update and it frustrating me. –  Siddharth Jun 12 at 16:56
    
your answer is correct and worked as expected. thanks for help –  Siddharth Jun 18 at 15:52
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.