1、差值

shader

//差值
uniform sampler2D U_MainTexture;
uniform sampler2D U_SubTexture;

varying vec2 M_coord;

void main()
{
        vec4 blendColor = texture2D(U_SubTexture, M_coord);
        vec4 baseColor = texture2D(U_MainTexture, M_coord);

        gl_FragColor = abs(vec4(blendColor.rgb - baseColor.rgb, 1.0));
}

效果图

基于Qt的OpenGL可编程管线学习(17)- 差值、反差值、排除_OpenGL


2、反差值

shader

//反差值
uniform sampler2D U_MainTexture;
uniform sampler2D U_SubTexture;

varying vec2 M_coord;

void main()
{
        vec4 blendColor = texture2D(U_SubTexture, M_coord);
        vec4 baseColor = texture2D(U_MainTexture, M_coord);

        gl_FragColor = vec4(vec3(1.0) - abs(vec3(blendColor.rgb - baseColor.rgb)), 1.0);
}

效果图

基于Qt的OpenGL可编程管线学习(17)- 差值、反差值、排除_Qt_02


3、排除

shader

//排除
uniform sampler2D U_MainTexture;
uniform sampler2D U_SubTexture;

varying vec2 M_coord;

void main()
{
        vec4 blendColor = texture2D(U_SubTexture, M_coord);
        vec4 baseColor = texture2D(U_MainTexture, M_coord);
        gl_FragColor = vec4(blendColor.rgb + baseColor.rgb - 2.0 * blendColor.rgb * baseColor.rgb, 1.0);
}

效果图

基于Qt的OpenGL可编程管线学习(17)- 差值、反差值、排除_Shader_03