-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.h
54 lines (40 loc) · 1.21 KB
/
utils.h
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
54
// From http://www.reddit.com/r/gamedev/comments/2j17wk/a_slightly_faster_bufferless_vertex_shader_trick/
// NOTE: this is in direct3d texture coord space (origin upper left)
// remember to flip y coordinate
//By CeeJay.dk
//License : CC0 - http://creativecommons.org/publicdomain/zero/1.0/
//Basic Buffer/Layout-less fullscreen triangle vertex shader
vec2 triangleVertex(in int vertID, out vec2 texcoord)
{
/*
//See: https://web.archive.org/web/20140719063725/http://www.altdev.co/2011/08/08/interesting-vertex-shader-trick/
1
( 0, 2)
[-1, 3] [ 3, 3]
.
|`.
| `.
| `.
'------`
0 2
( 0, 0) ( 2, 0)
[-1,-1] [ 3,-1]
ID=0 -> Pos=[-1,-1], Tex=(0,0)
ID=1 -> Pos=[-1, 3], Tex=(0,2)
ID=2 -> Pos=[ 3,-1], Tex=(2,0)
*/
texcoord.x = (vertID == 2) ? 2.0 : 0.0;
texcoord.y = (vertID == 1) ? 2.0 : 0.0;
return texcoord * vec2(2.0, -2.0) + vec2(-1.0, 1.0);
}
vec2 flipTexCoord(in vec2 tc) {
return tc * vec2(1.0, -1.0) + vec2(0.0, 1.0);
}
vec4 flipTexCoord(in vec4 tc) {
return tc * vec4(1.0, -1.0, 1.0, -1.0) + vec4(0.0, 1.0, 0.0, 1.0);
}
struct OITData {
uint color;
float depth;
uint prev;
};