Debian Codegraph @

ruby/video/opengl/shaders.hpp

raw
1 static string OpenGLOutputVertexShader = R"(
2 #version 150
3
4 uniform vec4 targetSize;
5 uniform vec4 outputSize;
6
7 in vec2 texCoord;
8
9 out Vertex {
10 vec2 texCoord;
11 } vertexOut;
12
13 void main() {
14 //center image within output window
15 if(gl_VertexID == 0 || gl_VertexID == 2) {
16 gl_Position.x = -(targetSize.x / outputSize.x);
17 } else {
18 gl_Position.x = +(targetSize.x / outputSize.x);
19 }
20
21 //center and flip vertically (buffer[0, 0] = top-left; OpenGL[0, 0] = bottom-left)
22 if(gl_VertexID == 0 || gl_VertexID == 1) {
23 gl_Position.y = +(targetSize.y / outputSize.y);
24 } else {
25 gl_Position.y = -(targetSize.y / outputSize.y);
26 }
27
28 //align image to even pixel boundary to prevent aliasing
29 vec2 align = fract((outputSize.xy + targetSize.xy) / 2.0) * 2.0;
30 gl_Position.xy -= align / outputSize.xy;
31 gl_Position.zw = vec2(0.0, 1.0);
32
33 vertexOut.texCoord = texCoord;
34 }
35 )";
36
37 static string OpenGLVertexShader = R"(
38 #version 150
39
40 in vec4 position;
41 in vec2 texCoord;
42
43 out Vertex {
44 vec2 texCoord;
45 } vertexOut;
46
47 void main() {
48 gl_Position = position;
49 vertexOut.texCoord = texCoord;
50 }
51 )";
52
53 static string OpenGLGeometryShader = R"(
54 #version 150
55
56 layout(triangles) in;
57 layout(triangle_strip, max_vertices = 3) out;
58
59 in Vertex {
60 vec2 texCoord;
61 } vertexIn[];
62
63 out Vertex {
64 vec2 texCoord;
65 };
66
67 void main() {
68 for(int i = 0; i < gl_in.length(); i++) {
69 gl_Position = gl_in[i].gl_Position;
70 texCoord = vertexIn[i].texCoord;
71 EmitVertex();
72 }
73 EndPrimitive();
74 }
75 )";
76
77 static string OpenGLFragmentShader = R"(
78 #version 150
79
80 uniform sampler2D source[];
81
82 in Vertex {
83 vec2 texCoord;
84 };
85
86 out vec4 fragColor;
87
88 void main() {
89 fragColor = texture(source[0], texCoord);
90 }
91 )";