Extra2D/shader/default.vert

49 lines
1.2 KiB
GLSL
Raw Normal View History

#version 320 es
precision highp float;
// 全局 UBO (binding = 0) - 每帧更新一次
layout(std140, binding = 0) uniform GlobalUBO {
mat4 uViewProjection;
vec4 uCameraPosition;
float uTime;
float uDeltaTime;
vec2 uScreenSize;
};
// 材质 UBO (binding = 1) - 每物体更新
layout(std140, binding = 1) uniform MaterialUBO {
vec4 uColor;
vec4 uTintColor;
float uOpacity;
float uPadding[3]; // std140 对齐填充
};
// 模型矩阵作为单独的统一变量(每个物体设置)
uniform mat4 uModelMatrix;
// 顶点属性
layout(location = 0) in vec2 aPosition;
layout(location = 1) in vec2 aTexCoord;
layout(location = 2) in vec4 aColor;
// 输出到片段着色器
out vec2 vTexCoord;
out vec4 vColor;
out vec4 vTintColor;
out float vOpacity;
/**
* @brief
*
*
*
*/
void main() {
gl_Position = uViewProjection * uModelMatrix * vec4(aPosition, 0.0, 1.0);
vTexCoord = aTexCoord;
// 混合顶点颜色和材质 UBO 中的颜色
vColor = aColor * uColor;
vTintColor = uTintColor;
vOpacity = uOpacity;
}