Skip to content

Commit 7315607

Browse files
Merge pull request #760 from Emik03/mobile-compatible-shaders
Avoid use of any integer to float coercion in shaders to support mobile
2 parents c481790 + 40867a6 commit 7315607

File tree

11 files changed

+47
-47
lines changed

11 files changed

+47
-47
lines changed

assets/shaders/astral.fs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ vec4 HSVtoRGB(vec4 hsv) {
164164

165165
float bitxor(float val1, float val2)
166166
{
167-
float outp = 0;
168-
for(int i = 1; i < 9; i++) outp += floor(mod(mod(floor(val1*pow(2,-i)),pow(2,i))+mod(floor(val2*pow(2,-i)),pow(2,i)),2))*pow(2,i);
169-
return outp/256;
167+
float outp = 0.;
168+
for(float i = 1.; i < 9.; i++) outp += floor(mod(mod(floor(val1*pow(2.,-i)),pow(2.,i))+mod(floor(val2*pow(2.,-i)),pow(2.,i)),2.))*pow(2.,i);
169+
return outp/256.;
170170
}
171171

172172
float mod2(float val1, float mod1)
@@ -183,7 +183,7 @@ float rand(vec2 c){
183183
}
184184

185185
float noise(vec2 p, float freq ){
186-
float unit = 1/freq;
186+
float unit = 1./freq;
187187
vec2 ij = floor(p/unit);
188188
vec2 xy = mod(p,unit)/unit;
189189
//xy = 3.*xy*xy-2.*xy*xy*xy;
@@ -249,8 +249,8 @@ vec4 effect( vec4 colour, Image texture, vec2 texture_coords, vec2 screen_coords
249249

250250
vec4 pixel = Texel(texture, texture_coords);
251251

252-
float cx = uv_scaled_centered.x * 1;
253-
float cy = uv_scaled_centered.y * 1;
252+
float cx = uv_scaled_centered.x * 1.;
253+
float cy = uv_scaled_centered.y * 1.;
254254

255255

256256

@@ -263,8 +263,8 @@ vec4 effect( vec4 colour, Image texture, vec2 texture_coords, vec2 screen_coords
263263

264264
vec2 mouse_offset = (screen_coords.xy - mouse_screen_pos.xy)/screen_scale;
265265

266-
float scaled_uvy = (uv.y +mouse_offset.y -0.5)*5*1.338;
267-
float scaled_uvx = (uv.x +mouse_offset.x -0.5)*5;
266+
float scaled_uvy = (uv.y +mouse_offset.y -0.5)*5.*1.338;
267+
float scaled_uvx = (uv.x +mouse_offset.x -0.5)*5.;
268268
float norm_uv = sqrt(scaled_uvx*scaled_uvx + scaled_uvy*scaled_uvy);
269269

270270
pixel = vec4(pixel.rgb * 0.0 + tex.rgb * tex.a, pixel.a);
@@ -273,17 +273,17 @@ vec4 effect( vec4 colour, Image texture, vec2 texture_coords, vec2 screen_coords
273273
vec4 textp = RGB(hsl);
274274
tex.rgb = textp.rgb;
275275

276-
float stars = ((pNoise(uv*10 + t/15.0, 10)*pNoise(uv*10 + t/15.0, 10)+1.5)/1+0.15 + ((pNoise(uv*12 + t/15.0, 10)+1.2)/1+0.3))/2.2+0.05 + 0.007*norm_uv * 1.1;
276+
float stars = ((pNoise(uv*10. + t/15.0, 10)*pNoise(uv*10. + t/15.0, 10)+1.5)/1.+0.15 + ((pNoise(uv*12. + t/15.0, 10)+1.2)/1.+0.3))/2.2+0.05 + 0.007*norm_uv * 1.1;
277277

278278
float clusters = (pNoise(uv*10.0-t/15.0, 10)+1.5)/1.5-0.25 + 0.007*norm_uv;
279279

280-
float super_clusters = (pNoise(uv/15.0, 10)+0.1)/2+0.3 - 0.008*norm_uv;
280+
float super_clusters = (pNoise(uv/15.0, 10)+0.1)/2.+0.3 - 0.008*norm_uv;
281281

282282
clusters *= clusters * clusters * clusters * 0.4;
283283
stars *= stars * stars;
284284
super_clusters *= super_clusters * super_clusters;
285285

286-
colour.rgb = vec3(0.6, 0.45, 1) * (((clusters + stars + super_clusters)+0.1)) * 0.285;
286+
colour.rgb = vec3(0.6, 0.45, 1.) * (((clusters + stars + super_clusters)+0.1)) * 0.285;
287287

288288
return dissolve_mask(tex*colour, texture_coords, uv);
289289
}
@@ -299,6 +299,6 @@ vec4 position( mat4 transform_projection, vec4 vertex_position )
299299
float scale = 0.2*(-0.03 - 0.3*max(0., 0.3-mid_dist))
300300
*hovering*(length(mouse_offset)*length(mouse_offset))/(2. -mid_dist);
301301

302-
return transform_projection * vertex_position + vec4(0,0,0,scale);
302+
return transform_projection * vertex_position + vec4(0.,0.,0.,scale);
303303
}
304304
#endif

assets/shaders/blur.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,6 @@ vec4 position( mat4 transform_projection, vec4 vertex_position )
179179
float scale = 0.2*(-0.03 - 0.3*max(0., 0.3-mid_dist))
180180
*hovering*(length(mouse_offset)*length(mouse_offset))/(2. -mid_dist);
181181

182-
return transform_projection * vertex_position + vec4(0,0,0,scale);
182+
return transform_projection * vertex_position + vec4(0.,0.,0.,scale);
183183
}
184184
#endif

assets/shaders/glass.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,6 @@ vec4 position( mat4 transform_projection, vec4 vertex_position )
104104
float scale = 0.2*(-0.03 - 0.3*max(0., 0.3-mid_dist))
105105
*hovering*(length(mouse_offset)*length(mouse_offset))/(2. -mid_dist);
106106

107-
return transform_projection * vertex_position + vec4(0,0,0,scale);
107+
return transform_projection * vertex_position + vec4(0.,0.,0.,scale);
108108
}
109109
#endif

assets/shaders/glitched.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,6 @@ vec4 position( mat4 transform_projection, vec4 vertex_position )
139139
float scale = 0.2*(-0.03 - 0.3*max(0., 0.3-mid_dist))
140140
*hovering*(length(mouse_offset)*length(mouse_offset))/(2. -mid_dist);
141141

142-
return transform_projection * vertex_position + vec4(0,0,0,scale);
142+
return transform_projection * vertex_position + vec4(0.,0.,0.,scale);
143143
}
144144
#endif

assets/shaders/glitched_b.fs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ vec4 HSVtoRGB(vec4 hsv) {
161161

162162
float bitxor(float val1, float val2)
163163
{
164-
float outp = 0;
165-
for(int i = 1; i < 9; i++) outp += floor(mod(mod(floor(val1*pow(2,-i)),pow(2,i))+mod(floor(val2*pow(2,-i)),pow(2,i)),2))*pow(2,i);
166-
return outp/256;
164+
float outp = 0.;
165+
for(float i = 1.; i < 9.; i++) outp += floor(mod(mod(floor(val1*pow(2.,-i)),pow(2.,i))+mod(floor(val2*pow(2.,-i)),pow(2.,i)),2.))*pow(2.,i);
166+
return outp/256.;
167167
}
168168

169169
float mod2(float val1, float mod1)
@@ -207,48 +207,48 @@ vec4 effect( vec4 colour, Image texture, vec2 texture_coords, vec2 screen_coords
207207

208208
vec4 pixel = Texel(texture, texture_coords);
209209

210-
float cx = uv_scaled_centered.x * 1;
211-
float cy = uv_scaled_centered.y * 1;
210+
float cx = uv_scaled_centered.x * 1.;
211+
float cy = uv_scaled_centered.y * 1.;
212212

213-
float randnum = mod2(floor(4*t), 256)*mod2(floor(4*t), 27);
214-
randnum = mod2(bitxor(pow(randnum, 3) - randnum + 3, 7 + floor(randnum/11)), 256);
215-
randnum = mod2(randnum*123.54,0.1)*10;
213+
float randnum = mod2(floor(4.*t), 256.)*mod2(floor(4.*t), 27.);
214+
randnum = mod2(bitxor(pow(randnum, 3.) - randnum + 3., 7. + floor(randnum/11.)), 256.);
215+
randnum = mod2(randnum*123.54,0.1)*10.;
216216

217217

218218

219219
vec4 hsl = HSL(vec4(tex.r, tex.g, tex.b, tex.a));
220220

221-
float xorscale = 10;
221+
float xorscale = 10.;
222222

223223
// |y| = 50, |x| = 50
224224

225225
float mbx;
226226
float mby;
227227
float offx;
228228
float offy;
229-
float rmasksum = -1;
230-
float rectmask = 1;
231-
t = floor(t/4);
229+
float rmasksum = -1.;
230+
float rectmask = 1.;
231+
t = floor(t/4.);
232232

233-
for(int i = 0; i < 5; i++)
233+
for(float i = 0.; i < 5.; i++)
234234
{
235-
randnum = bitxor(255*randnum + mod2(t,81), pow(randnum*(16-i), 2));
236-
mbx = (cx - 25*sin(100/randnum)) * (1 + 2*(floor(cos(177/randnum + 1))));
237-
mby = (cy - 25*cos(113/randnum + 1)) * (1 + 2*(floor(sin(221/randnum))));
238-
offx = bitxor(255*randnum, pow(255*randnum,5) - 255*randnum);
239-
offy = bitxor(255*randnum, pow(255*randnum,5) + 255*randnum);
240-
offx /= 10;
241-
offy /= 10;
235+
randnum = bitxor(255.*randnum + mod2(t,81.), pow(randnum*(16.-i), 2.));
236+
mbx = (cx - 25.*sin(100./randnum)) * (1. + 2.*(floor(cos(177./randnum + 1.))));
237+
mby = (cy - 25.*cos(113./randnum + 1.)) * (1. + 2.*(floor(sin(221./randnum))));
238+
offx = bitxor(255.*randnum, pow(255.*randnum,5.) - 255.*randnum);
239+
offy = bitxor(255.*randnum, pow(255.*randnum,5.) + 255.*randnum);
240+
offx /= 10.;
241+
offy /= 10.;
242242
rectmask = (-mbx + abs(abs(mbx) + offx) - offx) - (mby - abs(abs(mby) - offy) + offy);
243-
rmasksum *= -1 * min(0, max(-1, 5 - pow(rectmask, 2)));
243+
rmasksum *= -1. * min(0., max(-1., 5. - pow(rectmask, 2.)));
244244
}
245245

246-
float laddermask = pow(sin((23-20*randnum*randnum)*pow(sin(sin(cy*randnum) + pow(sin(cy*randnum),2)),2)),2) * rmasksum;
246+
float laddermask = pow(sin((23.-20.*randnum*randnum)*pow(sin(sin(cy*randnum) + pow(sin(cy*randnum),2.)),2.)),2.) * rmasksum;
247247

248248

249-
hsl.x += floor(randnum + 0.1) * rmasksum * 4 * randnum * (1 - laddermask);// * bitxor(cx * xorscale, cy * xorscale)/4;
250-
hsl.y += laddermask * (1 + 2 * rmasksum);
251-
hsl.z += floor(randnum + 0.2) * (1 + rmasksum) * (1 - 1.5*hsl.z) * 0.1;
249+
hsl.x += floor(randnum + 0.1) * rmasksum * 4. * randnum * (1. - laddermask);// * bitxor(cx * xorscale, cy * xorscale)/4;
250+
hsl.y += laddermask * (1. + 2. * rmasksum);
251+
hsl.z += floor(randnum + 0.2) * (1. + rmasksum) * (1. - 1.5*hsl.z) * 0.1;
252252

253253
tex.rgb = RGB(hsl).rgb;
254254

@@ -277,6 +277,6 @@ vec4 position( mat4 transform_projection, vec4 vertex_position )
277277
float scale = 0.2*(-0.03 - 0.3*max(0., 0.3-mid_dist))
278278
*hovering*(length(mouse_offset)*length(mouse_offset))/(2. -mid_dist);
279279

280-
return transform_projection * vertex_position + vec4(0,0,0,scale);
280+
return transform_projection * vertex_position + vec4(0.,0.,0.,scale);
281281
}
282282
#endif

assets/shaders/gold.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,6 @@ vec4 position( mat4 transform_projection, vec4 vertex_position )
109109
float scale = 0.2*(-0.03 - 0.3*max(0., 0.3-mid_dist))
110110
*hovering*(length(mouse_offset)*length(mouse_offset))/(2. -mid_dist);
111111

112-
return transform_projection * vertex_position + vec4(0,0,0,scale);
112+
return transform_projection * vertex_position + vec4(0.,0.,0.,scale);
113113
}
114114
#endif

assets/shaders/m.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,6 @@ vec4 position( mat4 transform_projection, vec4 vertex_position )
130130
float scale = 0.2*(-0.03 - 0.3*max(0., 0.3-mid_dist))
131131
*hovering*(length(mouse_offset)*length(mouse_offset))/(2. -mid_dist);
132132

133-
return transform_projection * vertex_position + vec4(0,0,0,scale);
133+
return transform_projection * vertex_position + vec4(0.,0.,0.,scale);
134134
}
135135
#endif

assets/shaders/mosaic.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,6 @@ vec4 position( mat4 transform_projection, vec4 vertex_position )
145145
float scale = 0.2*(-0.03 - 0.3*max(0., 0.3-mid_dist))
146146
*hovering*(length(mouse_offset)*length(mouse_offset))/(2. -mid_dist);
147147

148-
return transform_projection * vertex_position + vec4(0,0,0,scale);
148+
return transform_projection * vertex_position + vec4(0.,0.,0.,scale);
149149
}
150150
#endif

assets/shaders/noisy.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@ vec4 position( mat4 transform_projection, vec4 vertex_position )
8888
float scale = 0.2*(-0.03 - 0.3*max(0., 0.3-mid_dist))
8989
*hovering*(length(mouse_offset)*length(mouse_offset))/(2. -mid_dist);
9090

91-
return transform_projection * vertex_position + vec4(0,0,0,scale);
91+
return transform_projection * vertex_position + vec4(0.,0.,0.,scale);
9292
}
9393
#endif

assets/shaders/oversat.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,6 @@ vec4 position( mat4 transform_projection, vec4 vertex_position )
222222
float scale = 0.2*(-0.03 - 0.3*max(0., 0.3-mid_dist))
223223
*hovering*(length(mouse_offset)*length(mouse_offset))/(2. -mid_dist);
224224

225-
return transform_projection * vertex_position + vec4(0,0,0,scale);
225+
return transform_projection * vertex_position + vec4(0.,0.,0.,scale);
226226
}
227227
#endif

0 commit comments

Comments
 (0)