123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- // 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 <cc-global>
- #include <cc-local>
- 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 <cc-global>
- #include <alpha-test>
- #include <texture>
- in vec4 v_color;
- #if USE_TEXTURE
- in vec2 v_uv0;
- uniform sampler2D texture;
- #endif
-
- vec2 getSt(){
- vec4 o = vec4(1, 1, 1, 1);
- #if USE_TEXTURE
- CCTexture(texture, v_uv0, o);
- #endif
- o *= v_color;
- ALPHA_TEST(o);
- return v_uv0;
- }
- float Hash( vec2 p, in float s)
- {
- vec3 p2 = vec3(p.xy,27.0 * abs(sin(s)));
- return fract(sin(dot(p2,vec3(27.1,61.7, 12.4)))*273758.5453123);
- }
- float noise(in vec2 p, in float s)
- {
- vec2 i = floor(p);
- vec2 f = fract(p);
- f *= f * (3.0-2.0*f);
-
- return mix(mix(Hash(i + vec2(0.,0.), s), Hash(i + vec2(1.,0.), s),f.x),
- mix(Hash(i + vec2(0.,1.), s), Hash(i + vec2(1.,1.), s),f.x),f.y) * s;
- }
- float fbm(vec2 p)
- {
- float v = 0.0;
- v += noise(p*2., 0.25);
- v += noise(p*8., 0.0625);
- return v;
- }
- const float thickness = 100.0;// 闪电粗细值,值越小,闪电越粗
- const float offset = 0.4; // 闪电的偏移值
- const vec3 color = vec3(0.68, 0.85, 1.0);//此处可以修改 闪电的颜色
- const float rang = 0.45; // 闪电范围参数,一定范围内(小于1.0),值越大闪电边缘光越小
-
- void main () {
- vec2 st = getSt();
- vec2 position = vec2(offset) - st;
- float t = abs(0.5/ ((position.x + fbm(position + cc_time.x)) * thickness));
- vec3 finalColor = t / color;
- float absv = abs(finalColor.x) + abs(finalColor.y) + abs(finalColor.z);
- gl_FragColor = vec4( finalColor,smoothstep(rang,1.0,absv));
- }
- }%
|