| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- // 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 }
- sys_time: { value: 0.1, editor: { tooltip: '频率' } }
-
- }%
-
-
- 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 <texture>
- #include <alpha-test>
- in vec4 v_color;
-
- in vec2 v_uv0;
- uniform sampler2D texture;
-
- // 自定义属性
- uniform Properties {
- float sys_time; // 频率
- };
-
- float inFlash(float angle, vec2 uv, float xLength, float interval, float beginTime, float offX, float loopTime){
-
- //亮度值
- float brightness = 0.0;
- //倾斜角
- float angleInRed = 0.0174444 * angle;
-
- //当前时间
- float currentTime = sys_time/interval;
-
- //获取本次光照的起始时间
- //float currentTimeInt = floor(currentTime/interval) -1.0;
- //currentTimeInt *= interval;
-
- //获取本次光照的流逝时间 = 当前时间 - 起始时间
- //float currentTimePassed = currentTime - currentTimeInt;
-
- if(currentTime > beginTime)
- {
- //底部左边界和右边界
- float xBottomLeftBound;
- float xBottomRightBound;
-
- //此点边界
- float xPointLeftBound;
- float xPointRightBound;
-
- float x0 = currentTime - beginTime;
- x0 /= loopTime;
-
- //设置右边界
- xBottomRightBound = x0;
- //设置左边界
- xBottomLeftBound = x0 - xLength;
-
- //投影至x的长度 = y/tan(angle)
- float xProjL = (uv.y)/tan(angleInRed);
-
- //此点的左边界 = 底部左边界 - 投影至x的长度
- xPointLeftBound = xBottomLeftBound - xProjL;
- //此点的右边界 = 底部右边界 - 投影至x的长度
- xPointRightBound = xBottomRightBound - xProjL;
- //边界加上一个偏移
- xPointLeftBound += offX;
- xPointRightBound += offX;
-
- //如果该点在区域内
- if(uv.x > xPointLeftBound && uv.x < xPointRightBound)
- {
- //得到发光区域的中心点
- float midness = (xPointLeftBound + xPointRightBound)/2.0;
- //趋近中心点的程度,0表示位于边缘, 1 表示位于中心点
- float rate = (xLength - 2.0 * abs(uv.x - midness)) / (xLength);
- brightness = rate;
- }
- }
-
- brightness = max(brightness, 0.0);
- //返回颜色 = 纯白色 * 亮度
- //vec4 col = vec4 (1,1,1,1) * brightness;
- return brightness;
-
-
- }
-
- void main () {
- // 保存顶点颜色
- vec4 color = v_color;
-
- // 叠加纹理颜色
- color *= texture(texture, v_uv0);
-
- vec4 outp;
- //传进i.uv等参数,得到亮度值
- float tmpBrightness;
- tmpBrightness = inFlash(60.0, v_uv0, 4.0, 0.25, 1.0, 0.15, 0.5);
- //图像区域,判定设置为颜色的A >0.5, 输出为材质颜色 + 光亮值
- if(color.w >0.5)
- {
- outp = color + vec4(1,1,1,1) * tmpBrightness/1.5;
- }
- else
- {
- outp = vec4(0,0,0,0);
- }
-
- gl_FragColor = outp;
- }
- }%
|