File: drawrect.vert

package info (click to toggle)
openrct2 0.4.3%2Bds-1
  • links: PTS, VCS
  • area: contrib
  • in suites: bookworm
  • size: 67,880 kB
  • sloc: cpp: 549,527; ansic: 1,322; sh: 441; python: 269; xml: 180; php: 34; makefile: 19
file content (53 lines) | stat: -rw-r--r-- 1,492 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#version 150

// Allows for about 8 million draws per frame
const float DEPTH_INCREMENT = 1.0 / float(1u << 22u);

uniform ivec2 uScreenSize;

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;

in mat4x2 vVertMat;
in vec2   vVertVec;

out vec2       fPosition;
out vec3       fPeelPos;
flat out int   fFlags;
flat out uint  fColour;
out vec3       fTexColour;
out vec3       fTexMask;
flat out vec3  fPalettes;

void main()
{
    // Clamp position by vClip, correcting interpolated values for the clipping
    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);
    fTexColour = vec3(mix(vTexColourBounds.xy, vTexColourBounds.zw, m), vTexColourAtlas);
    fTexMask = vec3(mix(vTexMaskBounds.xy, vTexMaskBounds.zw, m), vTexMaskAtlas);

    fPosition = pos;

    // Transform screen coordinates to texture coordinates
    float depth = 1.0 - (float(vDepth) + 1.0) * DEPTH_INCREMENT;
    pos = pos / vec2(uScreenSize);
    pos.y = pos.y * -1.0 + 1.0;
    fPeelPos = vec3(pos, depth * 0.5 + 0.5);

    fFlags = vFlags;
    fColour = vColour;
    fPalettes = vec3(vPalettes);

    // Transform texture coordinates to viewport coordinates
    pos = pos * 2.0 - 1.0;
    gl_Position = vec4(pos, depth, 1.0);
}