基于Qt的OpenGL可编程管线学习(14)- 正片叠底、逆正片叠底

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 = blendColor * baseColor;
}

效果图

基于Qt的OpenGL可编程管线学习(14)- 正片叠底、逆正片叠底


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(1.0) - (vec4(1.0) - blendColor) * (vec4(1.0) - baseColor);
}

效果图

基于Qt的OpenGL可编程管线学习(14)- 正片叠底、逆正片叠底