| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- // Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
- CCEffect %{
- techniques:
- - passes:
- - vert: sprite-vs:vert
- frag: sprite-fs:frag
- depthStencilState:
- depthTest: false
- depthWrite: false
- blendState:
- targets:
- - blend: true
- blendSrc: src_alpha
- blendDst: one_minus_src_alpha
- blendDstAlpha: one_minus_src_alpha
- rasterizerState:
- cullMode: none
- properties:
- scanColor: { value: [0.5, 0.5, 0.5, 0.2] }
- scanWidth: { value: 0.05 }
- scanSpeed: { value: 1.0 }
- scanIntensity: { value: 2.0 }
- alphaThreshold: { value: 0.5 }
- }%
- CCProgram sprite-vs %{
- precision highp float;
- #include <builtin/uniforms/cc-global>
- #if USE_LOCAL
- #include <builtin/uniforms/cc-local>
- #endif
- #if SAMPLE_FROM_RT
- #include <common/common-define>
- #endif
- in vec3 a_position;
- in vec2 a_texCoord;
- in vec4 a_color;
- out vec4 color;
- out vec2 uv0;
- vec4 vert () {
- vec4 pos = vec4(a_position, 1);
- #if USE_LOCAL
- pos = cc_matWorld * pos;
- #endif
- #if USE_PIXEL_ALIGNMENT
- pos = cc_matView * pos;
- pos.xyz = floor(pos.xyz);
- pos = cc_matProj * pos;
- #else
- pos = cc_matViewProj * pos;
- #endif
- uv0 = a_texCoord;
- #if SAMPLE_FROM_RT
- CC_HANDLE_RT_SAMPLE_FLIP(uv0);
- #endif
- color = a_color;
- return pos;
- }
- }%
- CCProgram sprite-fs %{
- precision highp float;
- #include <builtin/internal/embedded-alpha>
- #include <builtin/internal/alpha-test>
- #include <builtin/uniforms/cc-global>
-
- in vec4 color;
- #if USE_TEXTURE
- in vec2 uv0;
- #pragma builtin(local)
- layout(set = 2, binding = 12) uniform sampler2D cc_spriteTexture;
- #endif
- uniform ScanUniforms {
- vec4 scanColor;
- float scanWidth;
- float scanSpeed;
- float scanIntensity;
- };
- vec4 frag () {
- vec4 o = vec4(1, 1, 1, 1);
- #if USE_TEXTURE
- o *= CCSampleWithAlphaSeparated(cc_spriteTexture, uv0);
-
- // 计算扫描线位置 (从右下到左上)
- float scanPosition = mod(cc_time.x * scanSpeed, 2.0 + scanWidth);
-
- // 计算当前像素到扫描线的距离 (对角线扫描)
- float diagonalPos = (1.0-(uv0.x + uv0.y) * 0.5); // 从右下到左上的对角线位置
- float distanceToScan = abs(diagonalPos - scanPosition);
-
- // 创建扫描线效果
- float scanEffect = 0.0;
- if (distanceToScan < scanWidth) {
- // 在扫描线范围内,计算强度
- float normalizedDistance = distanceToScan / scanWidth;
- scanEffect = (1.0 - normalizedDistance) * scanIntensity;
-
- // 使用平滑过渡
- scanEffect = smoothstep(0.0, 1.0, scanEffect);
- }
-
- // 应用扫描效果
- if (scanEffect > 0.0) {
- // 混合原始颜色和扫描颜色
- o.rgb = mix(o.rgb, scanColor.rgb, scanEffect * scanColor.a);
- // 增加亮度
- o.rgb += scanColor.rgb * scanEffect * 0.5;
- }
-
- #endif
- o *= color;
- ALPHA_TEST(o);
- return o;
- }
- }%
|