// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. CCEffect %{ techniques: - passes: - vert: vs frag: fs blendState: targets: - blend: true rasterizerState: cullMode: none properties: texture: { value: white } alphaThreshold: { value: 0.5 } }% CCProgram vs %{ precision highp float; #include #include in vec3 a_position; in vec4 a_color; out vec4 v_color; #if USE_TEXTURE in vec2 a_uv0; out vec2 v_uv0; #endif void main () { vec4 pos = vec4(a_position, 1); #if CC_USE_MODEL pos = cc_matViewProj * cc_matWorld * pos; #else pos = cc_matViewProj * pos; #endif #if USE_TEXTURE v_uv0 = a_uv0; #endif v_color = a_color; gl_Position = pos; } }% CCProgram fs %{ precision highp float; #include #include #include in vec4 v_color; #if USE_TEXTURE in vec2 v_uv0; uniform sampler2D texture; #endif const vec2 iResolution = vec2(0.5, 0.5); float hash21(vec2 x) { return fract(cos(mod(dot(x, vec2(13.9898, 8.141)), 3.14)) * 43758.5453); } vec2 hash22(vec2 uv) { uv = vec2(dot(uv, vec2(127.1,311.7)), dot(uv, vec2(269.5,183.3))); return 2.0 * fract(sin(uv) * 43758.5453123) - 1.0; } float perlinNoise(vec2 uv) { vec2 iuv = floor(uv); vec2 fuv = fract(uv); vec2 blur = smoothstep(.0, 1., fuv); vec2 bl = vec2(.0, .0); vec2 br = vec2(1., .0); vec2 tl = vec2(.0, 1.); vec2 tr = vec2(1., 1.); vec2 bln = hash22(iuv + bl); vec2 brn = hash22(iuv + br); vec2 tln = hash22(iuv + tl); vec2 trn = hash22(iuv + tr); float b = mix(dot(bln, fuv - bl), dot(brn, fuv - br), blur.x); float t = mix(dot(tln, fuv - tl), dot(trn, fuv - tr), blur.x); float c = mix(b, t, blur.y); float rs = 2.0 * texture2D(texture, vec2(uv.x,0.75)).r; return (c * rs); } float fbm(vec2 uv, int octaves) { float value = .0; float amplitude = .5; float freq = 2.0; for(int i = 0; i < 30; i++) { value += perlinNoise(uv) * amplitude; uv *= freq; amplitude *= .5; } return value; } mat2 R(float q) { return mat2(cos(q), sin(q), -sin(q), cos(q)); } void main () { vec2 uvv = (v_uv0 - 0.5) / iResolution.y; vec3 col1, col2; uvv.xy += fbm(uvv.yx + cc_time.x * 0.5, 30); float dist1 = abs(uvv.y); col1 = vec3(1.0) * mix(0.0, 0.05, hash21(vec2(sin(cc_time.x)))) / dist1; vec4 o = vec4(0.0); vec2 uv = v_uv0; float t = cc_time.x, e, s, g, k = 0.01; for(float i = 0.0; i < 100.0; i++) { g += max(k, e * 0.2); vec3 p = vec3((uv - 0.6) / iResolution.y * g + iResolution / iResolution.y * R(t + g * 0.5) * 0.5, g + t / 0.3); e = 0.3 - dot(p.xy, p.xy); for (float s = 2.0; s < 100.0; s ++) { p.yz *= R(s); e += abs(dot(sin(p * s + t * s * 0.2) / s, p - p + 1.0)); } o += o.w * min(e * o + (sin(vec4(1.0, 2.0, 3.0, 1.0) - p.z * 0.3) * 0.6 - 0.4), k) * k; } vec3 finalColor = mix(o.rgb, col1, 0.3); finalColor *= min(1.0, 1.0 + cos(0.15 * t)) + min(1.0, max(0.0, -2.0 - 4.0 * cos(0.15 * t))) * smoothstep(0.85, 1.0, fract(sin(t) * 43758.5453)); gl_FragColor = vec4(finalColor, 1.0); } }%