スライドショー3

attribute vec3 position; attribute vec2 texcoord; uniform mat4 modelViewMatrix; uniform mat4 modelViewMatrixInverse; uniform mat4 modelViewProjectionMatrix; varying vec2 fragTexCoord; void main() { fragTexCoord = vec2(texcoord.x, 1.0 - texcoord.y); gl_Position = modelViewProjectionMatrix * vec4(position, 1.0); } #ifdef GL_FRAGMENT_PRECISION_HIGH precision highp float; #else precision mediump float; #endif uniform sampler2D tex; uniform float time; uniform float calcSw; varying vec2 fragTexCoord; const int oct = 8; const float per = 0.5; const float PI = 3.1415926; const float SQ = 1.4142136; const float EX = 2.7182818; const float SQ10 = 3.1622777; const float eps = 0.000001; // 補間関数 float interpolate(float a, float b, float x){ float f = (1.0 - cos(x * PI)) * 0.5; return a * (1.0 - f) + b * f; } // 乱数生成 float rnd(vec2 p){ return fract(sin(dot(p ,vec2(12.9898,78.233))) * 43758.5453); } // 補間乱数 float irnd(vec2 p){ vec2 i = floor(p); vec2 f = fract(p); vec4 v = vec4(rnd(vec2(i.x, i.y )), rnd(vec2(i.x + 1.0, i.y )), rnd(vec2(i.x, i.y + 1.0)), rnd(vec2(i.x + 1.0, i.y + 1.0))); return interpolate(interpolate(v.x, v.y, f.x), interpolate(v.z, v.w, f.x), f.y); } // ノイズ生成 float noise(vec2 p){ float t = 0.0; for(int i = 0; i < oct; i++){ float freq = pow(2.0, float(i)); float amp = pow(per, float(oct - i)); t += irnd(vec2(p.x / freq, p.y / freq)) * amp; } return t; } // シームレスノイズ生成 float snoise(vec2 p, vec2 q, vec2 r){ return noise(vec2(p.x, p.y )) * q.x * q.y + noise(vec2(p.x, p.y + r.y)) * q.x * (1.0 - q.y) + noise(vec2(p.x + r.x, p.y )) * (1.0 - q.x) * q.y + noise(vec2(p.x + r.x, p.y + r.y)) * (1.0 - q.x) * (1.0 - q.y); } //星 void star(void){ vec2 q = vec2(fragTexCoord.x, 1.0 - fragTexCoord.y); vec2 p = (q - 0.5) * 2.0; float l = length(p); float th = atan(p.y, p.x); float f0 = cos((acos(sin(5.0 * th)) - 2.0 * PI) / 5.0); if(abs(f0) < eps) { discard; } float t = mod(time, 4.0) / 4.0; float r = 1.0 / f0 / SQ10 * t * 3.0; r = mix(r, SQ, t); float inner = 0.0; if(l <= r) { inner = 1.0; } vec4 texCol = texture2D(tex, fragTexCoord); texCol.a = inner; gl_FragColor = texCol; } //円 void circle(void){ vec4 texCol = texture2D(tex, fragTexCoord); float t = 1.0 - length((fragTexCoord - 0.5) * 2.0) / SQ; //float t = length((fragTexCoord - 0.5) * 2.0) / SQ; float spn = 32.0; float rt = 4.0; float pw = 32.0; float m = pow(min(t * mod(time * rt, spn), 1.0), pw); //float m = min(t * mod(time * rt, spn), 1.0); texCol.a = texCol.a * m; gl_FragColor = texCol; } //ランダムモザイク void mosaic(void){ vec4 texCol = texture2D(tex, fragTexCoord); // noise //vec2 t = floor(gl_FragCoord.xy / 16.0); vec2 t = floor(gl_FragCoord.xy / 16.0) + vec2(time * 10.0, time * 3.0); //vec2 t = gl_FragCoord.xy + vec2(time * 10.0); //float n = noise(t); float n = rnd(t); // seamless noise //const float map = 256.0; //vec2 t = mod(gl_FragCoord.xy + vec2(time * 10.0), map); //float n = snoise(t, t / map, vec2(map)); //texCol.a = texCol.a * n; float spn = 32.0; float rt = 4.0; float pw = 32.0; //float m = min(floor(n * mod(time * rt, spn)), 1.0); float m = pow(min(n * mod(time * rt, spn), 1.0), pw); //float m = floor(n * 2.0); texCol.a = texCol.a * m; gl_FragColor = texCol; //gl_FragColor = vec4(vec3(n), 1.0); } void main(void) { //mosaic(); //circle(); //star(); if(0.0 <= calcSw && calcSw < 1.0) { mosaic(); } else if(calcSw < 2.0) { circle(); } else if(calcSw < 3.0) { star(); } else { mosaic(); } }


mosaic circle star 





 






戻る