-
Notifications
You must be signed in to change notification settings - Fork 0
/
lavaglow_lighting.shader
252 lines (200 loc) · 10.4 KB
/
lavaglow_lighting.shader
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#version 130
uniform mat2x4 color_xform;
uniform sampler2D palettetex;
uniform sampler2D framebuf;
uniform float palette;
uniform vec2 screensize;
uniform float timer;
uniform float waterheight;
uniform float playerglow_strength;
uniform vec2 playerPos;
uniform float level_param;
uniform vec4 light0;
uniform vec4 light1;
uniform vec4 light2;
uniform vec4 light3;
uniform vec4 light4;
uniform vec4 light5;
uniform vec4 light6;
uniform vec4 light7;
varying vec2 worldPos;
varying vec2 blurcoords[25];
varying vec2 screencoords;
varying vec2 ratio;
const vec4 light_color = vec4(1.0, 0.33, 0.0, 0.8); // r, g, b, a. the gradient light that is above (and on top) of the water
const float light_distance = 1.5; // less = farther distance
const vec4 glow_color = vec4(1.0, 0.80, 0.0, 0.0); // alpha is unused here. the color that white parts glow when near water
const float glow_strength = 24; // how strong the glow effect is
const float glow_threshold = 0.00; // how bright the green channel needs to be to trigger a glow
const float glow_distance = .0015; // size of the glow
const float overexpose = 0.25; // colors more than full bright bleed into other channels to make stuff whiter
#if COMPILING_VERTEX_PROGRAM
void vert()
{
vec4 outcolor = gl_Color * color_xform[0] + color_xform[1];
vec2 palette_size = vec2(textureSize(palettetex, 0).xy);
gl_FrontColor = vec4(texture(palettetex, vec2((outcolor.r * 15.0 + 0.5) / palette_size.x, (palette + 0.5) / palette_size.y)).rgb, outcolor.a);
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
worldPos = (gl_ModelViewMatrix * gl_Vertex).xy;
screencoords = (gl_Position.xy+vec2(1, 1)) * 0.5;
float scale_x = screensize.x / 1280.0;
float scale_y = screensize.y / 720.0;
float scale_min = min(scale_x, scale_y);
ratio = vec2(scale_min / scale_x, scale_min / scale_y);
ratio.y *= (1280.0 / 720.0);
blurcoords[0] = screencoords.xy + vec2(-2,-2) * ratio * glow_distance;
blurcoords[1] = screencoords.xy + vec2(-1,-2) * ratio * glow_distance;
blurcoords[2] = screencoords.xy + vec2( 0,-2) * ratio * glow_distance;
blurcoords[3] = screencoords.xy + vec2( 1,-2) * ratio * glow_distance;
blurcoords[4] = screencoords.xy + vec2( 2,-2) * ratio * glow_distance;
blurcoords[5] = screencoords.xy + vec2(-2,-1) * ratio * glow_distance;
blurcoords[6] = screencoords.xy + vec2(-1,-1) * ratio * glow_distance;
blurcoords[7] = screencoords.xy + vec2( 0,-1) * ratio * glow_distance;
blurcoords[8] = screencoords.xy + vec2( 1,-1) * ratio * glow_distance;
blurcoords[9] = screencoords.xy + vec2( 2,-1) * ratio * glow_distance;
blurcoords[10] = screencoords.xy + vec2(-2, 0) * ratio * glow_distance;
blurcoords[11] = screencoords.xy + vec2(-1, 0) * ratio * glow_distance;
blurcoords[12] = screencoords.xy + vec2( 0, 0) * ratio * glow_distance;
blurcoords[13] = screencoords.xy + vec2( 1, 0) * ratio * glow_distance;
blurcoords[14] = screencoords.xy + vec2( 2, 0) * ratio * glow_distance;
blurcoords[15] = screencoords.xy + vec2(-2, 1) * ratio * glow_distance;
blurcoords[16] = screencoords.xy + vec2(-1, 1) * ratio * glow_distance;
blurcoords[17] = screencoords.xy + vec2( 0, 1) * ratio * glow_distance;
blurcoords[18] = screencoords.xy + vec2( 1, 1) * ratio * glow_distance;
blurcoords[19] = screencoords.xy + vec2( 2, 1) * ratio * glow_distance;
blurcoords[20] = screencoords.xy + vec2(-2, 2) * ratio * glow_distance;
blurcoords[21] = screencoords.xy + vec2(-1, 2) * ratio * glow_distance;
blurcoords[22] = screencoords.xy + vec2( 0, 2) * ratio * glow_distance;
blurcoords[23] = screencoords.xy + vec2( 1, 2) * ratio * glow_distance;
blurcoords[24] = screencoords.xy + vec2( 2, 2) * ratio * glow_distance;
}
#elif COMPILING_FRAGMENT_PROGRAM
float hash(float x)
{
return fract(sin(x) * 43758.5453);
}
float noise(float u)
{
vec3 x = vec3(u, 0, 0);
vec3 p = floor(x);
vec3 f = fract(x);
f = f * f * (3.0 - 2.0 * f);
float n = p.x + p.y * 57.0 + 113.0 * p.z;
return mix(mix(mix(hash(n + 0.0), hash(n + 1.0), f.x),
mix(hash(n + 57.0), hash(n + 58.0), f.x), f.y),
mix(mix(hash(n + 113.0), hash(n + 114.0), f.x),
mix(hash(n + 170.0), hash(n + 171.0), f.x), f.y),
f.z);
}
vec4 gblend(vec4 a, vec4 b)
{
return 1.0 - (1.0 - a) * (1.0 - b);
}
float overscreen(float a, float b)
{
return 1.0 - (1.0 - clamp(a, 0.0, 1.0)) * (1.0 - clamp(b, 0.0, 1.0)) + max(0.0, a - 1.0) + max(0.0, b - 1.0);
}
void frag()
{
// SLUDGEGLOW2 STUFF ////////////////////////////////////////////////////////////////
float blurcolor = 0;
blurcolor += max(0, texture(framebuf, blurcoords[1 ]).g-glow_threshold) * 4.0 / 252.0;
blurcolor += max(0, texture(framebuf, blurcoords[2 ]).g-glow_threshold) * 6.0 / 252.0;
blurcolor += max(0, texture(framebuf, blurcoords[3 ]).g-glow_threshold) * 4.0 / 252.0;
blurcolor += max(0, texture(framebuf, blurcoords[5 ]).g-glow_threshold) * 4.0 / 252.0;
blurcolor += max(0, texture(framebuf, blurcoords[6 ]).g-glow_threshold) * 16.0 / 252.0;
blurcolor += max(0, texture(framebuf, blurcoords[7 ]).g-glow_threshold) * 24.0 / 252.0;
blurcolor += max(0, texture(framebuf, blurcoords[8 ]).g-glow_threshold) * 16.0 / 252.0;
blurcolor += max(0, texture(framebuf, blurcoords[9 ]).g-glow_threshold) * 4.0 / 252.0;
blurcolor += max(0, texture(framebuf, blurcoords[10]).g-glow_threshold) * 6.0 / 252.0;
blurcolor += max(0, texture(framebuf, blurcoords[11]).g-glow_threshold) * 24.0 / 252.0;
blurcolor += max(0, texture(framebuf, blurcoords[12]).g-glow_threshold) * 36.0 / 252.0;
blurcolor += max(0, texture(framebuf, blurcoords[13]).g-glow_threshold) * 24.0 / 252.0;
blurcolor += max(0, texture(framebuf, blurcoords[14]).g-glow_threshold) * 6.0 / 252.0;
blurcolor += max(0, texture(framebuf, blurcoords[15]).g-glow_threshold) * 4.0 / 252.0;
blurcolor += max(0, texture(framebuf, blurcoords[16]).g-glow_threshold) * 16.0 / 252.0;
blurcolor += max(0, texture(framebuf, blurcoords[17]).g-glow_threshold) * 24.0 / 252.0;
blurcolor += max(0, texture(framebuf, blurcoords[18]).g-glow_threshold) * 16.0 / 252.0;
blurcolor += max(0, texture(framebuf, blurcoords[19]).g-glow_threshold) * 4.0 / 252.0;
blurcolor += max(0, texture(framebuf, blurcoords[21]).g-glow_threshold) * 4.0 / 252.0;
blurcolor += max(0, texture(framebuf, blurcoords[22]).g-glow_threshold) * 6.0 / 252.0;
blurcolor += max(0, texture(framebuf, blurcoords[23]).g-glow_threshold) * 4.0 / 252.0;
vec4 basecolor = texture(framebuf, screencoords.xy);
float dy = waterheight - worldPos.y;
dy += noise(worldPos.x / 32.0 + timer * 2 ) * 6;
dy += noise(worldPos.x / 16.0 + timer * -4.35) * 3;
dy += noise(worldPos.x / 8.0 + timer * 1 ) * 1.5;
float glowval = -(dy / 360.0);
glowval = glowval * light_distance;
glowval += 1;
glowval = clamp(glowval, 0.0, 1.0);
glowval = glowval * glowval;
vec2 playervec = playerPos - worldPos;
float dp = length(playervec);
float angle = dot(vec2(0, -1), playervec) / (dp) * 100;
float angle2 = dp;
dp += noise(dp / 32.0 + timer * 2 ) * 6;
dp += noise(dp / 16.0 + timer * -4.35) * 3;
dp += noise(dp / 8.0 + timer * 1 ) * 1.5;
dp += noise(angle / 32.0 + timer * 2 ) * 6;
dp += noise(angle / 16.0 + timer * -4.35) * 3;
dp += noise(angle / 8.0 + timer * 1 ) * 1.5;
dp = -(dp / 360.0);
float glowval2 = dp * light_distance / playerglow_strength;
glowval2 += 1;
glowval2 = clamp(glowval2, 0.0, 1.0);
glowval2 = glowval2 * glowval2 * playerglow_strength;
float dx = worldPos.x;
dx += noise(worldPos.y / 32.0 + timer * 2 ) * 6;
dx += noise(worldPos.y / 16.0 + timer * -4.35) * 3;
dx += noise(worldPos.y / 8.0 + timer * 1 ) * 1.5;
float glowval3 = -(dx / 360.0);
glowval3 = glowval3 * light_distance / (playerglow_strength * 4);
glowval3 += 1;
glowval3 = clamp(glowval3, 0.0, 1.0);
glowval3 = glowval3 * glowval3 * playerglow_strength * 1.5;
glowval = overscreen(glowval, glowval3);
glowval = overscreen(glowval, glowval2);
vec4 outcolor = basecolor;
outcolor = gblend(outcolor, mix(vec4(0.0), light_color * light_color.a, glowval));
vec4 glowcolor = (glow_color * glowval * glow_strength) * blurcolor;
outcolor = outcolor + glowcolor;
float extra_green = max(outcolor.g - 1.0, 0.0);
outcolor.r += extra_green * overexpose;
outcolor.b += extra_green * overexpose;
float extra_red = max(outcolor.r - 1.0, 0.0);
outcolor.g += extra_red * overexpose;
outcolor.b += extra_red * overexpose;
float extra_blue = max(outcolor.b - 1.0, 0.0);
outcolor.r += extra_blue * overexpose;
outcolor.g += extra_blue * overexpose;
/////////////////////////////////////////////////////////////////////////////////////
// LIGHTING STUFF ///////////////////////////////////////////////////////////////////
float d = length(playerPos - worldPos);
float ambient_light = level_param * level_param;
float l_p = min(1.0, 60.0 / (d + 50.0));
float l_0 = min(1.0, light0.z / (length(light0.xy - worldPos) + light0.z * 0.75));
float l_1 = min(1.0, light1.z / (length(light1.xy - worldPos) + light1.z * 0.75));
float l_2 = min(1.0, light2.z / (length(light2.xy - worldPos) + light2.z * 0.75));
float l_3 = min(1.0, light3.z / (length(light3.xy - worldPos) + light3.z * 0.75));
float l_4 = min(1.0, light4.z / (length(light4.xy - worldPos) + light4.z * 0.75));
float l_5 = min(1.0, light5.z / (length(light5.xy - worldPos) + light5.z * 0.75));
float l_6 = min(1.0, light6.z / (length(light6.xy - worldPos) + light6.z * 0.75));
float l_7 = min(1.0, light7.z / (length(light7.xy - worldPos) + light7.z * 0.75));
l_p = l_p * l_p;
l_0 = l_0 * l_0 * 2;
l_1 = l_1 * l_1 * 2;
l_2 = l_2 * l_2 * 2;
l_3 = l_3 * l_3 * 2;
l_4 = l_4 * l_4 * 2;
l_5 = l_5 * l_5 * 2;
l_6 = l_6 * l_6 * 2;
l_7 = l_7 * l_7 * 2;
float lightval = l_p + l_0 + l_1 + l_2 + l_3 + l_4 + l_5 + l_6 + l_7 + glowval;
lightval = 1.0 - (1.0 - lightval) * (1.0 - ambient_light);
outcolor *= min(1.5, lightval);
/////////////////////////////////////////////////////////////////////////////////////
outcolor.a = gl_Color.a;
gl_FragColor = outcolor;
}
#endif