OpenRCT2/data/shaders/drawrect.vert

57 lines
1.5 KiB
GLSL
Raw Normal View History

2017-10-19 22:46:49 +02:00
#version 150
// Allows for about 8 million draws per frame
const float DEPTH_INCREMENT = 1.0 / float(1u << 22u);
2017-10-19 22:46:49 +02:00
uniform ivec2 uScreenSize;
2023-12-08 13:02:43 +01:00
// clang-format off
2017-10-19 22:46:49 +02:00
in ivec4 vClip;
in int vTexColourAtlas;
in vec4 vTexColourBounds;
in int vTexMaskAtlas;
in vec4 vTexMaskBounds;
in ivec3 vPalettes;
in int vFlags;
in uint vColour;
in ivec4 vBounds;
in int vDepth;
2017-10-19 22:46:49 +02:00
in mat4x2 vVertMat;
in vec2 vVertVec;
out vec2 fPosition;
2017-10-22 04:04:24 +02:00
out vec3 fPeelPos;
2017-10-19 22:46:49 +02:00
flat out int fFlags;
flat out uint fColour;
out vec3 fTexColour;
out vec3 fTexMask;
flat out vec3 fPalettes;
2023-12-08 13:02:43 +01:00
// clang-format on
2017-10-19 22:46:49 +02:00
void main()
{
// Clamp position by vClip, correcting interpolated values for the clipping
2023-12-08 13:02:43 +01:00
vec2 m = clamp(
((vVertMat * vec4(vClip)) - (vVertMat * vec4(vBounds))) / vec2(vBounds.zw - vBounds.xy) + vVertVec, 0.0, 1.0);
vec2 pos = mix(vec2(vBounds.xy), vec2(vBounds.zw), m);
2017-10-19 22:46:49 +02:00
fTexColour = vec3(mix(vTexColourBounds.xy, vTexColourBounds.zw, m), vTexColourAtlas);
fTexMask = vec3(mix(vTexMaskBounds.xy, vTexMaskBounds.zw, m), vTexMaskAtlas);
fPosition = pos;
2017-10-22 04:04:24 +02:00
// Transform screen coordinates to texture coordinates
float depth = 1.0 - (float(vDepth) + 1.0) * DEPTH_INCREMENT;
pos = pos / vec2(uScreenSize);
2017-10-22 04:04:24 +02:00
pos.y = pos.y * -1.0 + 1.0;
fPeelPos = vec3(pos, depth * 0.5 + 0.5);
2017-10-19 22:46:49 +02:00
fFlags = vFlags;
fColour = vColour;
fPalettes = vec3(vPalettes);
2017-10-22 04:04:24 +02:00
// Transform texture coordinates to viewport coordinates
pos = pos * 2.0 - 1.0;
gl_Position = vec4(pos, depth, 1.0);
2017-10-19 22:46:49 +02:00
}