Debian Codegraph @

src/game/shaders.h

raw symbols SCIP
1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2013 Jussi Lind <[email protected]>
3 //
4 // Dust Racing 2D is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 // Dust Racing 2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>.
15
16 #ifndef SHADERS_H
17 #define SHADERS_H
18
19 static const char * carVsh =
20 "#version 120\n"
21 ""
22 "attribute vec3 inVertex;\n"
23 "attribute vec3 inNormal;\n"
24 "attribute vec2 inTexCoord;\n"
25 "attribute vec4 inColor;\n"
26 "uniform vec4 scale = vec4(1, 1, 1, 1);\n"
27 "uniform mat4 vp;\n"
28 "uniform mat4 v;\n"
29 "uniform mat4 model;\n"
30 "uniform vec4 dd = vec4(1, 1, 1, 1);\n"
31 "uniform vec4 dc = vec4(1, 1, 1, 1);\n"
32 "uniform vec4 sd = vec4(1, 1, 1, 1);\n"
33 "uniform vec4 sc = vec4(1, 1, 1, 1);\n"
34 "uniform vec4 ac = vec4(1, 1, 1, 1);\n"
35 "uniform float sCoeff = 1;\n"
36 "varying vec4 ddRotated;\n"
37 "varying vec2 texCoord0;\n"
38 "varying vec2 texCoord1;\n"
39 "varying vec4 vColor;\n"
40 "varying mat4 normalRot;\n"
41 ""
42 "void main()\n"
43 "{\n"
44 " gl_Position = vp * model * (vec4(inVertex, 1) * scale);\n"
45 ""
46 " // We need this for normal mapping in the fragment shader.\n"
47 " normalRot = mat4(mat3(model));\n"
48 " ddRotated = vec4(dd.xyz, 0) * normalRot;\n"
49 ""
50 " texCoord0 = inTexCoord;\n"
51 " texCoord1 = (normalRot * vec4(inTexCoord, 0.0, 0.0)).xy;\n"
52 ""
53 " vec3 vNormalEye = (v * model * vec4(inNormal, 1)).xyz;\n"
54 " vec3 vVertexEye = (v * model * vec4(inVertex, 1) * scale).xyz;\n"
55 ""
56 " vec3 eye = vec3(0, 0, 1);\n"
57 " vec3 pos = vVertexEye;\n"
58 " vec3 V = normalize(eye - pos);\n"
59 " vec3 L = normalize(-eye);\n"
60 " vec3 N = normalize(-vNormalEye);\n"
61 ""
62 " float si = max(0.0, pow(dot(reflect(L, N), V), sCoeff));\n"
63 ""
64 " vColor = inColor * vec4(ac.rgb, 1.0) * ac.a + vec4(sc.xyz, 1.0) * si;\n"
65 "}\n";
66
67 static const char * carFsh =
68 "#version 120\n"
69 ""
70 "uniform sampler2D tex0;\n"
71 "uniform sampler2D tex1;\n"
72 "uniform sampler2D tex2;\n"
73 "uniform vec4 dd = vec4(1, 1, 1, 1);\n"
74 "uniform vec4 dc = vec4(1, 1, 1, 1);\n"
75 "uniform float dCoeff = 1;\n"
76 "varying vec4 ddRotated;\n"
77 "varying vec2 texCoord0;\n"
78 "varying vec2 texCoord1;\n"
79 "varying vec4 vColor;\n"
80 ""
81 "void main(void)\n"
82 "{\n"
83 " vec4 texColor = texture2D(tex0, texCoord0);\n"
84 " vec4 sky = texture2D(tex1, texCoord1);\n"
85 " vec4 normal = texture2D(tex2, texCoord0);\n"
86 ""
87 " if (texColor.a < 0.1)\n"
88 " {\n"
89 " discard;\n"
90 " }\n"
91 " else\n"
92 " {\n"
93 " vec3 N = normalize((normal.xyz - vec3(0.5, 0.5, 0.5)) * 2.0);\n"
94 " float di = dot(-ddRotated.xyz, N) * dc.a;\n"
95 " float refl = 0.33 * ((1.0 - texColor.r) + texColor.g + (1.0 - texColor.b));\n"
96 " refl *= refl * refl;\n"
97 " gl_FragColor = 0.80 * (sky * refl + texColor * (1.0 - refl)) + 0.20 * (vec4(dc.rgb, 1.0) * di * dCoeff + vColor);\n"
98 " }\n"
99 "}\n";
100
101 static const char * menuVsh =
102 "#version 120\n"
103 ""
104 "attribute vec3 inVertex;\n"
105 "attribute vec2 inTexCoord;\n"
106 "attribute vec4 inColor;\n"
107 "uniform vec4 color = vec4(1, 1, 1, 1);\n"
108 "uniform vec4 scale = vec4(1, 1, 1, 1);\n"
109 "uniform mat4 vp;\n"
110 "uniform mat4 model;\n"
111 "varying vec4 vColor;\n"
112 "varying vec2 texCoord0;\n"
113 ""
114 "void main()\n"
115 "{\n"
116 " gl_Position = vp * model * (vec4(inVertex, 1) * scale);\n"
117 " texCoord0 = inTexCoord;\n"
118 " vColor = inColor * color;\n"
119 "}\n";
120
121 static const char * menuFsh =
122 "#version 120\n"
123 ""
124 "varying vec2 texCoord0;\n"
125 "varying vec4 vColor;\n"
126 "uniform sampler2D tex0;\n"
127 "uniform float fade = 1;\n"
128 ""
129 "void main(void)\n"
130 "{\n"
131 " vec4 texColor = texture2D(tex0, texCoord0);\n"
132 " if (texColor.a < 0.1)\n"
133 " {\n"
134 " discard;\n"
135 " }\n"
136 " else\n"
137 " {\n"
138 " gl_FragColor = vColor * texColor * fade;\n"
139 " }\n"
140 "}\n";
141
142 static const char * fboVsh =
143 "#version 120\n"
144 ""
145 "attribute vec3 inVertex;\n"
146 "attribute vec2 inTexCoord;\n"
147 "varying vec2 texCoord0;\n"
148 ""
149 "void main()\n"
150 "{\n"
151 " gl_Position = vec4(inVertex, 1);\n"
152 " texCoord0 = inTexCoord;\n"
153 "}\n";
154
155 static const char * fboFsh =
156 "#version 120\n"
157 ""
158 "uniform sampler2D tex0;\n"
159 "uniform float fade = 1;\n"
160 "varying vec2 texCoord0;\n"
161 ""
162 "void main(void)\n"
163 "{\n"
164 " gl_FragColor = texture2D(tex0, texCoord0) * fade;\n"
165 "}\n";
166
167 static const char * tileVsh =
168 "#version 120\n"
169 ""
170 "attribute vec3 inVertex;\n"
171 "attribute vec3 inNormal;\n"
172 "attribute vec2 inTexCoord;\n"
173 "attribute vec4 inColor;\n"
174 "uniform vec4 scale = vec4(1, 1, 1, 1);\n"
175 "uniform mat4 vp;\n"
176 "uniform mat4 model;\n"
177 "uniform vec4 dd = vec4(1, 1, 1, 1);\n"
178 "uniform vec4 dc = vec4(1, 1, 1, 1);\n"
179 "uniform vec4 ac = vec4(1, 1, 1, 1);\n"
180 "uniform float dCoeff = 1;\n"
181 "varying vec2 texCoord0;\n"
182 "varying vec2 texCoord1;\n"
183 "varying vec4 vColor;\n"
184 ""
185 "void main()\n"
186 "{\n"
187 " gl_Position = vp * model * (vec4(inVertex, 1) * scale);\n"
188 " float di = dot(dd.xyz, -inNormal) * dc.a;\n"
189 " vColor = inColor * (\n"
190 " vec4(ac.rgb, 1.0) * ac.a +\n"
191 " vec4(dc.rgb, 1.0) * di * dCoeff);\n"
192 ""
193 " texCoord0 = inTexCoord;\n"
194 " texCoord1 = inTexCoord;\n"
195 "}\n";
196
197 static const char * tile3dFsh =
198 "#version 120\n"
199 ""
200 "uniform sampler2D tex0;\n"
201 "uniform sampler2D tex1;\n"
202 "uniform sampler2D tex2;\n"
203 "varying vec2 texCoord0;\n"
204 "varying vec4 vColor;\n"
205 ""
206 "void main(void)\n"
207 "{\n"
208 " vec4 color0 = texture2D(tex0, texCoord0);\n"
209 " vec4 color1 = texture2D(tex1, texCoord0);\n"
210 " vec4 color2 = texture2D(tex2, texCoord0);\n"
211 ""
212 " if (color0.a < 0.01)\n"
213 " {\n"
214 " discard;\n"
215 " }\n"
216 " else\n"
217 " {\n"
218 " if ((color0.r + color0.b) <= color0.g)\n"
219 " {\n"
220 " color0 = mix(color1, color2, color0.g);\n"
221 " }\n"
222 ""
223 " gl_FragColor = color0 * vColor;\n"
224 " }\n"
225 "}\n";
226
227 #endif // SHADERS_H