-1
\$\begingroup\$

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?

\$\endgroup\$

closed as off-topic by Josh Jun 16 '14 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.

  • \$\begingroup\$ This question is a intra-network cross-post. Please don't cross-post between StackExchange sites. \$\endgroup\$ – Josh Jun 16 '14 at 16:40
2
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Downvoter, care to comment? \$\endgroup\$ – Gustavo Maciel Jun 12 '14 at 16:33
  • \$\begingroup\$ Sorry at present I can't give you reply because my eclipse not working properly because adt update and it frustrating me. \$\endgroup\$ – Siddharth Jun 12 '14 at 16:56
  • \$\begingroup\$ your answer is correct and worked as expected. thanks for help \$\endgroup\$ – Siddharth Jun 18 '14 at 15:52

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