You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
123 lines
3.4 KiB
123 lines
3.4 KiB
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:
|
|
alphaThreshold: { value: 0.5 }
|
|
_LineColor:
|
|
{
|
|
value: [1, 1, 1, 1],
|
|
editor: { type: color, displayName: "颜色" },
|
|
}
|
|
_LineWidth:
|
|
{ value: 0.1, editor: { range: [0.0, 10.0], displayName: "宽度" } }
|
|
_TexelSize:
|
|
{ value: [0.001, 0.001], editor: { displayName: "Texel Size" } }
|
|
_GlowIntensity:
|
|
{ value: 1.0, editor: { range: [0.0, 10.0], displayName: "发光强度" } }
|
|
}%
|
|
|
|
CCProgram shared-ubos %{
|
|
#pragma define-mate USE_HIGH_SAMPLER
|
|
|
|
uniform Constants {
|
|
vec4 _LineColor;
|
|
vec2 _TexelSize;
|
|
float _LineWidth;
|
|
float _GlowIntensity;
|
|
};
|
|
}%
|
|
|
|
CCProgram sprite-vs %{
|
|
precision highp float;
|
|
#include <builtin/uniforms/cc-global>
|
|
#include <shared-ubos>
|
|
|
|
in vec3 a_position;
|
|
in vec2 a_texCoord;
|
|
in vec4 a_color;
|
|
|
|
out vec4 v_vertexColor;
|
|
out vec2 v_uv0;
|
|
out vec4 v_uv1;
|
|
out vec4 v_uv2;
|
|
#if USE_HIGH_SAMPLER
|
|
out vec4 v_uv3;
|
|
out vec4 v_uv4;
|
|
#endif
|
|
|
|
vec4 vert() {
|
|
vec4 pos = vec4(a_position, 1);
|
|
pos = cc_matViewProj * pos;
|
|
v_vertexColor = a_color;
|
|
|
|
vec2 width = _LineWidth * _TexelSize.xy;
|
|
v_uv0 = a_texCoord;
|
|
v_uv1.xy = v_uv0 + vec2(0.0, 1.0) * width;
|
|
v_uv1.zw = v_uv0 + vec2(0.0, - 1.0) * width;
|
|
v_uv2.xy = v_uv0 + vec2(-1.0, 0.0) * width;
|
|
v_uv2.zw = v_uv0 + vec2(1.0, 0.0) * width;
|
|
#if USE_HIGH_SAMPLER
|
|
v_uv3.xy = v_uv0 + vec2(-1.0, - 1.0) * width;
|
|
v_uv3.zw = v_uv0 + vec2(1.0, 1.0) * width;
|
|
v_uv4.xy = v_uv0 + vec2(-1.0, 1.0) * width;
|
|
v_uv4.zw = v_uv0 + vec2(1.0, - 1.0) * width;
|
|
#endif
|
|
return pos;
|
|
}
|
|
}%
|
|
|
|
CCProgram sprite-fs %{
|
|
precision highp float;
|
|
#include <builtin/internal/embedded-alpha>
|
|
#include <builtin/internal/alpha-test>
|
|
#include <Lib/color.chunk>
|
|
#include <shared-ubos>
|
|
|
|
in vec4 v_vertexColor;
|
|
in vec2 v_uv0;
|
|
in vec4 v_uv1;
|
|
in vec4 v_uv2;
|
|
#if USE_HIGH_SAMPLER
|
|
in vec4 v_uv3;
|
|
in vec4 v_uv4;
|
|
#endif
|
|
#pragma builtin(local)
|
|
layout(set = 2, binding = 12) uniform sampler2D cc_spriteTexture;
|
|
|
|
vec4 frag() {
|
|
vec4 color0 = texture(cc_spriteTexture, v_uv1.xy);
|
|
vec4 color1 = texture(cc_spriteTexture, v_uv1.zw);
|
|
vec4 color2 = texture(cc_spriteTexture, v_uv2.xy);
|
|
vec4 color3 = texture(cc_spriteTexture, v_uv2.zw);
|
|
float w = color0.a * color1.a * color2.a * color3.a;
|
|
|
|
#if USE_HIGH_SAMPLER
|
|
vec4 color4 = texture(cc_spriteTexture, v_uv3.xy);
|
|
vec4 color5 = texture(cc_spriteTexture, v_uv3.zw);
|
|
vec4 color6 = texture(cc_spriteTexture, v_uv4.xy);
|
|
vec4 color7 = texture(cc_spriteTexture, v_uv4.zw);
|
|
w *= color4.a * color5.a * color6.a * color7.a;
|
|
#endif
|
|
|
|
vec4 color = texture(cc_spriteTexture, v_uv0);
|
|
vec4 glowColor = _LineColor * _GlowIntensity;
|
|
color.xyz = mix(glowColor.rgb, color.rgb, w);
|
|
|
|
color *= v_vertexColor;
|
|
ALPHA_TEST(color);
|
|
return color;
|
|
}
|
|
}% |