ddnet/data/shader/quad.vert

43 lines
1.1 KiB
GLSL
Raw Normal View History

layout (location = 0) in vec4 inVertex;
layout (location = 1) in vec4 inColor;
2020-08-19 05:05:51 +00:00
#ifdef TW_QUAD_TEXTURED
layout (location = 2) in vec2 inVertexTexCoord;
#endif
2020-08-19 05:05:51 +00:00
uniform mat4x2 gPos;
2020-08-19 05:05:51 +00:00
uniform vec2 gOffsets[TW_MAX_QUADS];
uniform float gRotations[TW_MAX_QUADS];
2020-08-19 05:05:51 +00:00
noperspective out vec4 QuadColor;
flat out int QuadIndex;
#ifdef TW_QUAD_TEXTURED
noperspective out vec2 TexCoord;
#endif
void main()
{
vec2 FinalPos = vec2(inVertex.xy);
2020-08-19 05:05:51 +00:00
int TmpQuadIndex = int(gl_VertexID / 4);
2020-08-19 05:05:51 +00:00
if(gRotations[TmpQuadIndex] != 0.0)
{
float X = FinalPos.x - inVertex.z;
float Y = FinalPos.y - inVertex.w;
2020-08-19 05:05:51 +00:00
FinalPos.x = X * cos(gRotations[TmpQuadIndex]) - Y * sin(gRotations[TmpQuadIndex]) + inVertex.z;
FinalPos.y = X * sin(gRotations[TmpQuadIndex]) + Y * cos(gRotations[TmpQuadIndex]) + inVertex.w;
}
2020-08-19 05:05:51 +00:00
FinalPos.x = FinalPos.x / 1024.0 + gOffsets[TmpQuadIndex].x;
FinalPos.y = FinalPos.y / 1024.0 + gOffsets[TmpQuadIndex].y;
2020-08-19 05:05:51 +00:00
gl_Position = vec4(gPos * vec4(FinalPos, 0.0, 1.0), 0.0, 1.0);
QuadColor = inColor;
QuadIndex = TmpQuadIndex;
#ifdef TW_QUAD_TEXTURED
TexCoord = inVertexTexCoord;
#endif
}