3 |
4 |
5 |
6 |
9 | Shaderboy Test
10 |
29 |
30 |
31 | Shaderboy Test
32 |
33 | Simply place an <img> tag somewhere, write a GLSL shader for it and poof:
34 |
35 |
42 |
43 |
44 |
45 |
48 |
49 |
--------------------------------------------------------------------------------
/test/shader.glsl:
--------------------------------------------------------------------------------
1 | precision highp float;
2 |
3 | uniform sampler2D image;
4 | uniform sampler2D texture0;
5 | uniform sampler2D texture1;
6 | uniform float time;
7 | varying vec2 pixelCoords;
8 |
9 | mat4 rotationMatrix(vec3 axis, float angle)
10 | {
11 | axis = normalize(axis);
12 | float s = sin(angle);
13 | float c = cos(angle);
14 | float oc = 1.0 - c;
15 |
16 | return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0,
17 | oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0,
18 | oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0,
19 | 0.0, 0.0, 0.0, 1.0);
20 | }
21 |
22 |
23 | void main() {
24 | mat4 rot = rotationMatrix(vec3(1.0,1.0,1.0), 1.0472);
25 | vec4 uv = vec4(pixelCoords.xy, 1.0, 1.0);
26 | vec4 uvRot = uv * rot;
27 |
28 | vec4 map = texture2D(texture0, pixelCoords);
29 | float distortion = (sin(uvRot.x*50.0+time)*0.005);
30 | float distortion2 = (sin(uvRot.y*42.0+time)*0.005);
31 |
32 | vec4 dist = vec4(distortion, distortion2, 1.0, 1.0);
33 |
34 | float xPos = (uv.x+dist.y);
35 | float yPos = (uv.y+dist.x);
36 |
37 | gl_FragColor = texture2D( texture1, vec2(xPos,yPos));
38 | if(map.r < 0.2){
39 | gl_FragColor = texture2D(image, pixelCoords);
40 | }
41 | }
--------------------------------------------------------------------------------