Skip to main content
Post Closed as "Not suitable for this site" by CommunityBot
We are interested in the shaders, not the stringized version of it
Source Link
Gustavo Maciel
  • 5.2k
  • 3
  • 27
  • 43

public static final String CONTRAST_FRAGMENT_SHADER = "" + "varying highp vec2 textureCoordinate;\n" + " \n" + " uniform sampler2D inputImageTexture;\n" + " uniform lowp float contrast;\n" + " \n" + " void main()\n" + " {\n" + " lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" + " \n" + " gl_FragColor = vec4(((textureColor.rgb - vec3(0.5)) * contrast + vec3(0.5)), textureColor.w);\n" + " }"; Contrast shader:

public static final String BRIGHTNESS_FRAGMENT_SHADERvarying =highp ""vec2 textureCoordinate;
    + 
 "varying highp vec2 textureCoordinate;\n"uniform sampler2D inputImageTexture;
    +uniform "lowp \n"float contrast;
    + 
 " uniform sampler2D inputImageTexture;\n"void main()
    +{
 " uniform       lowp floatvec4 brightness;\n"textureColor = texture2D(inputImageTexture, textureCoordinate);
    
         gl_FragColor = vec4(((textureColor.rgb - vec3(0.5)) * contrast + "vec3(0.5)), \n"textureColor.w);
    +}

Brightness shader:

 "   varying highp vec2 textureCoordinate;
    
    uniform sampler2D inputImageTexture;
    uniform lowp float brightness;
    
    void main()\n"
    + " {\n"
    + "     lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n";
    + "     \n"
    + "     gl_FragColor = vec4((textureColor.rgb + vec3(brightness)), textureColor.w);\n";
    + " }";
public static final String CONTRAST_BRIGHTNESS_FRAGMENT_SHADER = ""
    + "varyingvarying highp vec2 textureCoordinate;\n"textureCoordinate;
    + " uniform sampler2D inputImageTexture;\n"inputImageTexture;
    + "varyingvarying highp vec2 textureCoordinate2;\n"textureCoordinate2;
    + " uniform sampler2D inputImageTexture2;\n"inputImageTexture2;
    + " uniform lowp float contrast;\n"contrast;
    + " uniform lowp float brightness;\n"brightness;
    + " \n"
    + " void main()\n"
    + " {\n"
    + "     lowp vec4 textureColorForContrast = texture2D(inputImageTexture, textureCoordinate);\n";
    + "     \n"
    + "     lowp vec4 contastVec4 = vec4(((textureColorForContrast.rgb - vec3(0.5)) * contrast + vec3(0.5)), textureColorForContrast.w);\n";
    + "     lowp vec4 textureColorForBrightness = texture2D(inputImageTexture2, textureCoordinate2);\n";
    + "     \n"
    + "     lowp vec4 brightnessVec4 = vec4((textureColorForBrightness.rgb + vec3(brightness)), textureColorForBrightness.w);\n";
    + "     gl_FragColor = contastVec4 + brightnessVec4;\n"brightnessVec4;
 + "  }";

public static final String CONTRAST_FRAGMENT_SHADER = "" + "varying highp vec2 textureCoordinate;\n" + " \n" + " uniform sampler2D inputImageTexture;\n" + " uniform lowp float contrast;\n" + " \n" + " void main()\n" + " {\n" + " lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" + " \n" + " gl_FragColor = vec4(((textureColor.rgb - vec3(0.5)) * contrast + vec3(0.5)), textureColor.w);\n" + " }";

public static final String BRIGHTNESS_FRAGMENT_SHADER = ""
    + "varying highp vec2 textureCoordinate;\n"
    + " \n"
    + " uniform sampler2D inputImageTexture;\n"
    + " uniform lowp float brightness;\n"
    + " \n"
    + " void main()\n"
    + " {\n"
    + "     lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n"
    + "     \n"
    + "     gl_FragColor = vec4((textureColor.rgb + vec3(brightness)), textureColor.w);\n"
    + " }";
public static final String CONTRAST_BRIGHTNESS_FRAGMENT_SHADER = ""
    + "varying highp vec2 textureCoordinate;\n"
    + " uniform sampler2D inputImageTexture;\n"
    + "varying highp vec2 textureCoordinate2;\n"
    + " uniform sampler2D inputImageTexture2;\n"
    + " uniform lowp float contrast;\n"
    + " uniform lowp float brightness;\n"
    + " \n"
    + " void main()\n"
    + " {\n"
    + "     lowp vec4 textureColorForContrast = texture2D(inputImageTexture, textureCoordinate);\n"
    + "     \n"
    + "     lowp vec4 contastVec4 = vec4(((textureColorForContrast.rgb - vec3(0.5)) * contrast + vec3(0.5)), textureColorForContrast.w);\n"
    + "     lowp vec4 textureColorForBrightness = texture2D(inputImageTexture2, textureCoordinate2);\n"
    + "     \n"
    + "     lowp vec4 brightnessVec4 = vec4((textureColorForBrightness.rgb + vec3(brightness)), textureColorForBrightness.w);\n"
    + "     gl_FragColor = contastVec4 + brightnessVec4;\n" + " }";

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);
    }
    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;
    }
Source Link
Siddharth
  • 2k
  • 5
  • 27
  • 55

Combine Two Shader Program

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.

public static final String CONTRAST_FRAGMENT_SHADER = "" + "varying highp vec2 textureCoordinate;\n" + " \n" + " uniform sampler2D inputImageTexture;\n" + " uniform lowp float contrast;\n" + " \n" + " void main()\n" + " {\n" + " lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" + " \n" + " gl_FragColor = vec4(((textureColor.rgb - vec3(0.5)) * contrast + vec3(0.5)), textureColor.w);\n" + " }";

public static final String BRIGHTNESS_FRAGMENT_SHADER = ""
    + "varying highp vec2 textureCoordinate;\n"
    + " \n"
    + " uniform sampler2D inputImageTexture;\n"
    + " uniform lowp float brightness;\n"
    + " \n"
    + " void main()\n"
    + " {\n"
    + "     lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n"
    + "     \n"
    + "     gl_FragColor = vec4((textureColor.rgb + vec3(brightness)), textureColor.w);\n"
    + " }";

Now applying both of the effects I write following code

public static final String CONTRAST_BRIGHTNESS_FRAGMENT_SHADER = ""
    + "varying highp vec2 textureCoordinate;\n"
    + " uniform sampler2D inputImageTexture;\n"
    + "varying highp vec2 textureCoordinate2;\n"
    + " uniform sampler2D inputImageTexture2;\n"
    + " uniform lowp float contrast;\n"
    + " uniform lowp float brightness;\n"
    + " \n"
    + " void main()\n"
    + " {\n"
    + "     lowp vec4 textureColorForContrast = texture2D(inputImageTexture, textureCoordinate);\n"
    + "     \n"
    + "     lowp vec4 contastVec4 = vec4(((textureColorForContrast.rgb - vec3(0.5)) * contrast + vec3(0.5)), textureColorForContrast.w);\n"
    + "     lowp vec4 textureColorForBrightness = texture2D(inputImageTexture2, textureCoordinate2);\n"
    + "     \n"
    + "     lowp vec4 brightnessVec4 = vec4((textureColorForBrightness.rgb + vec3(brightness)), textureColorForBrightness.w);\n"
    + "     gl_FragColor = contastVec4 + brightnessVec4;\n" + " }";

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?