更改 gl 颜色的 alpha 属性
Changing the alpha property of gl color
我使用下面的代码来降低或增加 gl_FragColor
的亮度。
void main()
{
#ifdef SHADER_API_GLES3
vec2 uvTop = mix(_UvTopLeftRight.xy, _UvTopLeftRight.zw, gl_MultiTexCoord0.x);
vec2 uvBottom = mix(_UvBottomLeftRight.xy, _UvBottomLeftRight.zw, gl_MultiTexCoord0.x);
textureCoord = mix(uvTop, uvBottom, gl_MultiTexCoord0.y);
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
#endif
}
但是,如何更改 gl_color 的 alpha 属性?
我尝试通过 gl_FragColor.a = 100
更改它,但出于某种原因,它只是创建了奇怪的线条。
我是不是漏了什么?
颜色通道和 Alpha 通道的值是 [0.0, 1.0] 范围内的归一化浮点值。
可以通过设置 gl_FragColor.a
来更改 Alpha 通道。例如:
(另见 Swizzling)
gl_FragColor.a = 0.6;
或
gl_FragColor = vec4(pow(texture(_MainTex, textureCoord).rgb, vec3(2.2)), 0.6);
进一步查看The OpenGL Shading Language specification:
5.5 Vector and Scalar Components and Length
The names of the components of a vector or scalar are denoted by a single letter. As a notational convenience, several letters are associated with each component based on common usage of position, color or texture coordinate vectors. The individual components can be selected by following the variable name with period ( . ) and then the component name.
The component names supported are:
{x, y, z, w}
Useful when accessing vectors that represent points or normals
{r, g, b, a}
Useful when accessing vectors that represent colors
{s, t, p, q}
Useful when accessing vectors that represent texture coordinates/>
我使用下面的代码来降低或增加 gl_FragColor
的亮度。
void main()
{
#ifdef SHADER_API_GLES3
vec2 uvTop = mix(_UvTopLeftRight.xy, _UvTopLeftRight.zw, gl_MultiTexCoord0.x);
vec2 uvBottom = mix(_UvBottomLeftRight.xy, _UvBottomLeftRight.zw, gl_MultiTexCoord0.x);
textureCoord = mix(uvTop, uvBottom, gl_MultiTexCoord0.y);
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
#endif
}
但是,如何更改 gl_color 的 alpha 属性?
我尝试通过 gl_FragColor.a = 100
更改它,但出于某种原因,它只是创建了奇怪的线条。
我是不是漏了什么?
颜色通道和 Alpha 通道的值是 [0.0, 1.0] 范围内的归一化浮点值。
可以通过设置 gl_FragColor.a
来更改 Alpha 通道。例如:
(另见 Swizzling)
gl_FragColor.a = 0.6;
或
gl_FragColor = vec4(pow(texture(_MainTex, textureCoord).rgb, vec3(2.2)), 0.6);
进一步查看The OpenGL Shading Language specification:
5.5 Vector and Scalar Components and Length
The names of the components of a vector or scalar are denoted by a single letter. As a notational convenience, several letters are associated with each component based on common usage of position, color or texture coordinate vectors. The individual components can be selected by following the variable name with period ( . ) and then the component name.
The component names supported are:
{x, y, z, w}
Useful when accessing vectors that represent points or normals
{r, g, b, a}
Useful when accessing vectors that represent colors
{s, t, p, q}
Useful when accessing vectors that represent texture coordinates/>