OpengGL Es (亮度+ 對(duì)比度 + 飽和度 )

變量聲明 (GLES 語法)

precision mediump float;
varying highp vec2 textureCoordinate;
uniform sampler2D inputTexture;

//亮度
uniform lowp float brightness;
//對(duì)比度
uniform lowp float contrast;

//飽和度
uniform lowp float saturation;
// Values from \\\"Graphics Shaders: Theory and Practice\\\" by Bailey and Cunningham
const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);

1.亮度調(diào)整

lowp vec4 textureColor = texture2D(inputTexture, textureCoordinate);
gl_FragColor = vec4((textureColor.rgb + vec3(brightness)), textureColor.w);
獲取handle
 mBrightnessHandle = GLES20.glGetUniformLocation(mProgramId, "brightness");
賦值 (-1.0 to 1.0, 默認(rèn)為0.0f)
GLES20.glUniform1f(mBrightnessHandle, 0.0f);

2.對(duì)比度

lowp vec4 textureColor = texture2D(inputTexture, textureCoordinate);
 gl_FragColor = vec4((textureColor.rgb - vec3(0.5)) *  contrast + vec3(0.5), textureColor.w);
獲取handle
  mContrastHandle = GLES20.glGetUniformLocation(mProgramId, "contrast");
賦值 ( 0.0 ~ 4.0, 默認(rèn)1.0f)
  GLES20.glUniform1f(mContrastHandle, 1.0f);

3.飽和度

 lowp vec4 textureColor = texture2D(inputTexture, textureCoordinate);
 lowp vec3 greyScaleColor = vec3(dot(contrastColor.rgb, luminanceWeighting));
 gl_FragColor = vec4(mix(greyScaleColor, contrastColor.rgb, saturation), textureColor.w);
獲取handle
  mSaturationHandle = GLES30.glGetUniformLocation(mProgramId, "saturation");
賦值(0.0 ~ 2.0之間 默認(rèn)1.0f)
  GLES20.glUniform1f(mSaturationHandle, mSaturationValue);

如果想一起合并使用同一個(gè)fragment_shader,可以這樣弄

void main()
{
    //亮度
    lowp vec3 brightnessColor  = textureColor.rgb + vec3(brightness);

    //對(duì)比度
    lowp vec3 contrastColor = (brightnessColor.rgb - vec3(0.5)) * contrast + vec3(0.5);

    //飽和度
    lowp vec3 greyScaleColor = vec3(dot(contrastColor.rgb, luminanceWeighting));
    gl_FragColor = vec4(mix(greyScaleColor, contrastColor.rgb, saturation), textureColor.w);
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容