Files
Destrum/destrum/assets_src/shaders/shape2d.vert
T

34 lines
1.0 KiB
GLSL

#version 460
#extension GL_GOOGLE_include_directive : require
#include "shape2d.glsl"
layout (location = 0) out vec2 outLocalPos;
layout (location = 1) out vec2 outQuadPos;
layout (location = 2) flat out uint outShapeIndex;
// Room for the antialiased edge outside the shape's bounds
const float EDGE_MARGIN = 1.0;
const vec2 CORNERS[6] = vec2[](
vec2(-1.0, -1.0), vec2(1.0, -1.0), vec2(1.0, 1.0),
vec2(-1.0, -1.0), vec2(1.0, 1.0), vec2(-1.0, 1.0)
);
void main()
{
Shape2D shape = pcs.shapeBuffer.shapes[gl_InstanceIndex];
vec2 corner = CORNERS[gl_VertexIndex];
vec2 localPos = corner * (shape.halfSize + EDGE_MARGIN);
float c = cos(shape.rotation);
float s = sin(shape.rotation);
vec2 rotated = vec2(localPos.x * c - localPos.y * s, localPos.x * s + localPos.y * c);
gl_Position = pcs.projection * vec4(shape.center + rotated, 0.0, 1.0);
outLocalPos = localPos;
outQuadPos = localPos / max(shape.halfSize, vec2(1e-6)) * 0.5 + 0.5;
outShapeIndex = gl_InstanceIndex;
}