glsl着色器-混色,正常模式(如在Photoshop中) [英] glsl shader - color blend, normal mode (like in Photoshop)
本文介绍了glsl着色器-混色,正常模式(如在Photoshop中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建混合2种颜色(实际上是图像和颜色作为叠加在图像上的颜色)的效果,就像在Photoshop中使用常规混合"模式的颜色叠加"
Im trying to create effect of blending 2 colors (actually image and color as overlay over image), like in photoshop "Color Overlay" with "Normal Blending" mode
我正在使用libgdx
Im using libgdx
这是我到目前为止所拥有的
This is what i have so far
attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord0;
uniform mat4 u_projTrans;
varying vec4 v_color;
varying vec2 v_texCoords;
void main()
{
v_color = a_color;
v_texCoords = a_texCoord0;
gl_Position = u_projTrans * a_position;
}
还有片段
#ifdef GL_ES
#define LOWP lowp
precision mediump float;
#else
#define LOWP
#endif
varying LOWP vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
void main()
{
vec4 curColor = texture2D(u_texture, v_texCoords);
vec3 cA = curColor.rgb;//color A, background
vec3 cB = v_color.rgb;//color B, overlay
float aA = curColor.a;
float aB = v_color.a;
vec3 color = (cA * aA + cB * aB * (1 - aA)) / aA + aB * (1 - aA);
float alpha = aA + aB * (1 - aA);
gl_FragColor = vec4(color, alpha);
}
我使用了维基百科
当我使用此着色器时,什么也没有发生,使用此着色器绘制的对象是透明的,不可见的
When i use this shader, nothing happens, object which is drawn with this shader is transparent, invisible
推荐答案
gl_FragColor = texture2D(u_texture, v_texCoords);
gl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(1.0), v_color.a);
这是解决方案,这要感谢@ Tenfour04
This is the solution, thanks to @Tenfour04
这篇关于glsl着色器-混色,正常模式(如在Photoshop中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文