33 lines
640 B
GLSL
33 lines
640 B
GLSL
#version 320 es
|
|
precision mediump float;
|
|
|
|
// 材质 UBO
|
|
layout(std140, binding = 1) uniform MaterialUBO {
|
|
vec4 tintColor;
|
|
float opacity;
|
|
} uMaterial;
|
|
|
|
// 输入从顶点着色器
|
|
in vec2 vTexCoord;
|
|
in vec4 vColor;
|
|
|
|
// 纹理采样器
|
|
uniform sampler2D uTexture;
|
|
|
|
// 输出颜色
|
|
out vec4 fragColor;
|
|
|
|
void main() {
|
|
// 采样纹理
|
|
vec4 texColor = texture(uTexture, vTexCoord);
|
|
|
|
// 应用顶点颜色、材质颜色和透明度
|
|
fragColor = texColor * vColor * uMaterial.tintColor;
|
|
fragColor.a *= uMaterial.opacity;
|
|
|
|
// 丢弃完全透明的像素
|
|
if (fragColor.a < 0.01) {
|
|
discard;
|
|
}
|
|
}
|