mirror of
https://gitee.com/ruanwujing/green-pack-cocos
synced 2024-12-25 19:28:43 +00:00
128 lines
2.9 KiB
Plaintext
128 lines
2.9 KiB
Plaintext
// 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:
|
|
b_matrix: { value:[
|
|
1, 0, 0, 0,
|
|
0, 1, 0, 0,
|
|
0, 0, 1, 0,
|
|
0, 0, 0, 0]}
|
|
light_pos: {value: [0.5, -0.5, 1, 1]}
|
|
}%
|
|
|
|
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>
|
|
in vec4 color;
|
|
in vec2 uv0;
|
|
|
|
uniform Constant {
|
|
mat4x4 b_matrix;
|
|
vec4 light_pos;
|
|
};
|
|
#pragma builtin(local)
|
|
layout(set = 2, binding = 12) uniform sampler2D cc_spriteTexture;
|
|
|
|
|
|
vec4 frag () {
|
|
vec2 uv = fract(uv0 * 4.0);
|
|
vec2 id = floor(uv0 * 4.0);
|
|
|
|
vec2 xy = uv * 2.0 - 1.0;
|
|
|
|
float z = sqrt(1.0 - length(xy));
|
|
|
|
vec3 _p3d = vec3(xy, z);
|
|
|
|
vec4 p = b_matrix * vec4(_p3d, 1.0);
|
|
vec3 p3d = p.xyz;
|
|
|
|
vec4 background = vec4(0.0, 0.0, 0.0, 0.0);
|
|
vec4 ballColor = color;
|
|
#if USE_BELT
|
|
// 上下两个白圈的中心店
|
|
vec3 white1 = vec3(0.0, 1.0, 0.0);
|
|
vec3 white2 = vec3(0.0, -1.0, 0.0);
|
|
float whiteLen = 0.7;
|
|
|
|
vec3 dw1 = white1 - p3d;
|
|
vec3 dw2 = white2 - p3d;
|
|
float dw = min(dot(dw1, dw1), dot(dw2, dw2));
|
|
ballColor = mix(ballColor, vec4(1.0, 1.0, 1.0, 1.0), smoothstep(0.0, -0.1, dw - whiteLen));
|
|
#endif
|
|
vec2 _xy = p3d.xy * 0.8 + 0.5;
|
|
vec2 _uv = _xy * 0.25 + id * 0.25;
|
|
vec4 numColor = CCSampleWithAlphaSeparated(cc_spriteTexture, _uv);
|
|
|
|
vec4 o = mix(ballColor, numColor, smoothstep(0., -0.1, length(_xy - 0.5) - 0.48) * step(0.0, p3d.z));
|
|
o = mix(background, o, smoothstep(0.0, -0.1, length(xy) - 1.0));
|
|
|
|
#if USE_LIGHT
|
|
vec3 lightDir = normalize(light_pos.xyz - _p3d.xyz);
|
|
float d = dot(normalize(_p3d.xyz), lightDir);
|
|
d = clamp(d, 0.0, 1.0);
|
|
d = sqrt(d);
|
|
float nol = 0.5 + 0.5 * d;
|
|
o *= vec4(nol, nol, nol, 1.0);
|
|
#endif
|
|
|
|
return o;
|
|
}
|
|
}%
|