-
Notifications
You must be signed in to change notification settings - Fork 5
/
shader_src.h
218 lines (204 loc) · 14.3 KB
/
shader_src.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
Copyright (c) 2012, Peter de Rivaz
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* WebGL version at http://penguinspuzzle.appspot.com
*
* This file contains the source code for the different shaders used in the game.
* _vs are the vertex shaders.
* _fs are the fragment shaders.
*/
const GLchar *shader_vs =
" attribute vec2 tex; \n"
" attribute vec3 vertex; \n"
" attribute vec3 normal; \n"
" varying vec2 tcoord; \n"
" uniform mat4 view; \n"
" uniform mat4 world; \n"
" uniform vec4 blend; \n"
" varying float light; \n"
" void main(void) { \n"
" vec4 normal2 = world * vec4(normal,0.0); \n"
" light = 0.5+max(0.0,0.5*dot(normal2.xyz,vec3(0.7,0,0.7))); \n"
" tcoord = tex+blend.xy; \n"
" vec4 vertex2 = world * vec4(vertex,1.0); \n"
" gl_Position = view * vertex2; \n"
" } \n";
const GLchar *shader_fs =
" precision mediump float; \n"
" uniform vec4 color; \n"
" uniform sampler2D texture; \n"
" varying vec2 tcoord; \n"
" varying float light; \n"
" void main(void) { \n"
" mediump vec4 col = texture2D(texture,tcoord); \n"
" if (col.x>0.9 && col.y>0.6 && col.y<0.61 && col.z<0.1) \n"
" discard; \n"
" gl_FragColor = col*light; \n"
" gl_FragColor.a = 1.0; \n"
" } \n";
const GLchar *explshader_vs =
" attribute vec2 tex; \n"
" attribute vec3 vertex; \n"
" attribute vec3 normal; \n"
" varying vec2 tcoord; \n"
" uniform mat4 view; \n"
" uniform mat4 world; \n"
" uniform vec4 blend; \n"
" varying float light; \n"
" void main(void) { \n"
" // blend.x gives time to simulate \n"
" light = 0.5+max(0.0,0.5*dot(vertex.xyz,vec3(0.7,0,0.7))); \n"
" tcoord = tex*0.23+vec2(0.51,0.26); \n"
" // Update the position \n"
" vec3 vt = vertex + vertex*blend.x*0.06; \n"
" vt[2] -= blend.x*blend.x*0.05; \n"
" vec4 vertex2 = world * vec4(vt,1.0); \n"
" vec4 pos = view * vertex2; \n"
" // Now we want to translate the x,y depending on tex.xy \n"
" pos.xy += 0.05*pos.z*tex.xy; \n"
" gl_Position = pos; \n"
" } \n";
const GLchar *explshader_fs =
" precision mediump float; \n"
" uniform vec4 color; \n"
" uniform sampler2D texture; \n"
" varying vec2 tcoord; \n"
" varying float light; \n"
" void main(void) { \n"
" mediump vec4 col = texture2D(texture,tcoord); \n"
" gl_FragColor = col; \n"
" gl_FragColor.a = col.b*0.8; \n"
" } \n";
const GLchar *shadowshader_vs =
" attribute vec2 tex; \n"
" attribute vec3 vertex; \n"
" attribute vec3 normal; \n"
" varying vec2 tcoord; \n"
" uniform mat4 view; \n"
" uniform mat4 view_reflect; \n"
" uniform mat4 world; \n"
" uniform vec4 blend; \n"
" varying float light; \n"
" varying float light_dist; \n"
" varying vec4 reflect_pos; \n"
" void main(void) { \n"
" vec4 pos = world * vec4(vertex,1.0); \n"
" vec4 normal2 = world * vec4(normal,0.0); \n"
" light = 0.5+max(0.0,0.5*dot(normal2.xyz,vec3(0.7,0,0.7))); \n"
" tcoord = tex+blend.xy; \n"
" light_dist = (pos.z+20.0)*0.004; // Should really be after world transform \n"
" reflect_pos = view_reflect * pos; \n"
" gl_Position = view * pos; \n"
" } \n";
const GLchar *shadowshader_fs =
" precision mediump float; \n"
" uniform vec4 color; \n"
" uniform sampler2D texture; \n"
" varying vec2 tcoord; \n"
" varying float light; \n"
" varying float light_dist; \n"
" varying vec4 reflect_pos; \n"
" uniform sampler2D texture_reflect; \n"
" void main(void) { \n"
" mediump vec4 col = texture2D(texture,tcoord); \n"
" if (col.x>0.9 && col.y>0.6 && col.y<0.61 && col.z<0.1) \n"
" discard; \n"
" mediump vec4 col2; \n"
" vec2 reflect_sample; \n"
" reflect_sample = (vec2(reflect_pos.x,reflect_pos.y)*0.5)/reflect_pos.w+0.5; \n"
" col2 = texture2D(texture_reflect,reflect_sample); \n"
" col = col*light; \n"
" if (light_dist+0.01 < col2.r) \n"
" col = col * 0.5; \n"
" gl_FragColor = col; \n"
" gl_FragColor.a = 1.0; \n"
" } \n";
const GLchar *sunshader_vs =
" attribute vec2 tex; \n"
" attribute vec3 vertex; \n"
" attribute vec3 normal; \n"
" uniform mat4 world; \n"
" uniform mat4 view; \n"
" varying float light; \n"
" varying vec2 tcoord; \n"
" void main(void) { \n"
" vec4 pos = world * vec4(vertex,1.0); \n"
" light = (pos.z+20.0)*0.004; \n"
" tcoord = tex; \n"
" gl_Position = view * pos; \n"
" } \n";
const GLchar *sunshader_fs =
" precision mediump float; \n"
" uniform sampler2D texture; \n"
" varying vec2 tcoord; \n"
" varying float light; \n"
" void main(void) { \n"
" mediump vec4 col = texture2D(texture,tcoord); \n"
" if (col.x>0.9 && col.y>0.6 && col.y<0.61 && col.z<0.1) \n"
" discard; \n"
" gl_FragColor = vec4(light,light,light,1.0); \n"
" } \n";
const GLchar *watershader_vs =
" attribute vec2 tex; \n"
" attribute vec3 vertex; \n"
" varying vec2 tcoord; \n"
" varying vec2 tcoord2; \n"
" uniform mat4 view; \n"
" uniform mat4 view_reflect; \n"
" uniform vec4 blend; \n"
" varying vec4 reflect_pos; \n"
" void main(void) { \n"
" vec4 pos = vec4(vertex,1.0); \n"
" tcoord = tex+blend.xy; \n"
" tcoord2 = tex.ts+blend.zw; \n"
" reflect_pos = view_reflect * pos; \n"
" gl_Position = view * pos; \n"
" } \n";
const GLchar *watershader_fs =
" precision mediump float; \n"
" uniform sampler2D texture; \n"
" uniform sampler2D texture_reflect; \n"
" varying vec2 tcoord; \n"
" varying vec2 tcoord2; \n"
" varying vec4 reflect_pos; \n"
" void main(void) { \n"
" mediump vec3 eye; \n"
" float light2; \n"
" mediump vec4 col; \n"
" mediump vec4 col2; \n"
" vec2 reflect_sample; \n"
" col = texture2D(texture,tcoord); \n"
" col2 = texture2D(texture,tcoord2); \n"
" col=col*0.4+col2*0.6-0.5; \n"
" reflect_sample = (vec2(reflect_pos.x,reflect_pos.y)*0.5)/reflect_pos.w+0.5; \n"
" reflect_sample = vec2(reflect_sample.s+col.s*0.1,reflect_sample.t+col.t*0.1+0.005); \n"
" col2 = texture2D(texture_reflect,reflect_sample); \n"
" eye = vec3(gl_FragCoord.x-320.0+(col.r)*1000.0,gl_FragCoord.y+(col.g)*1000.0-540.0,600.0); \n"
" eye=normalize(eye); \n"
" light2=dot(eye,vec3(0.1,0.3,0.8)); \n"
" light2=2.0*pow(light2,4.0); \n"
" gl_FragColor = col2*0.7+vec4(1.0,0.8,0.6,1.0)*light2; \n"
" gl_FragColor.a = 1.0; \n"
" } \n";