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));
}效果图
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);
}效果图
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);
}效果图
本文出自 “不会飞的纸飞机” 博客,请务必保留此出处http://douzhq.blog.51cto.com/12552184/1931090
基于Qt的OpenGL可编程管线学习(17)- 差值、反差值、排除
原文地址:http://douzhq.blog.51cto.com/12552184/1931090