基于Qt的OpenGL可编程管线学习(16)-柔光、强光、叠加
1、柔光
成都创新互联是专业的错那网站建设公司,错那接单;提供成都做网站、网站制作,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行错那网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
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 = 2.0 * blendColor * baseColor + baseColor * baseColor - 2.0 * baseColor * baseColor * blendColor; }
效果图
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); vec3 lumCoeff = vec3(0.2125, 0.7154, 0.0721); float luminance = dot(blendColor.rgb, lumCoeff); if (luminance < 0.45) { gl_FragColor = 2.0 * blendColor * baseColor; } else if (luminance > 0.55) { gl_FragColor = vec4(1.0) - 2.0 * (vec4(1.0) - baseColor) * (vec4(1.0) - blendColor); } else { vec4 color1 = 2.0 * blendColor * baseColor;; vec4 color2 = vec4(1.0) - 2.0 * (vec4(1.0) - baseColor) * (vec4(1.0) - blendColor); gl_FragColor = mix(color1, color2, (luminance -0.45) * 10.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); vec3 lumCoeff = vec3(0.2125, 0.7154, 0.0721); float luminance = dot(baseColor.rgb, lumCoeff); if (luminance < 0.45) { gl_FragColor = 2.0 * blendColor * baseColor; } else if (luminance > 0.55) { gl_FragColor = vec4(1.0) - 2.0 * (vec4(1.0) - baseColor) * (vec4(1.0) - blendColor); } else { vec4 color1 = 2.0 * blendColor * baseColor;; vec4 color2 = vec4(1.0) - 2.0 * (vec4(1.0) - baseColor) * (vec4(1.0) - blendColor); gl_FragColor = mix(color1, color2, (luminance -0.45) * 10.0); } }
效果图
当前名称:基于Qt的OpenGL可编程管线学习(16)-柔光、强光、叠加
文章来源:http://scyanting.com/article/jcgcjs.html