mirror of
https://gitee.com/ruanwujing/green-pack-cocos
synced 2025-10-09 16:46:17 +00:00
添加新的sdf裁切形状示例;添加形状调节参数
This commit is contained in:
@@ -17,6 +17,8 @@ CCEffect %{
|
||||
cullMode: none
|
||||
properties:
|
||||
alphaThreshold: { value: 0.5 }
|
||||
circleParams: { value:[0.5, 0.01, -0.01, 0.0]}
|
||||
|
||||
}%
|
||||
|
||||
CCProgram sprite-vs %{
|
||||
@@ -67,6 +69,10 @@ CCProgram sprite-fs %{
|
||||
#include "../chunks/sdf2d"
|
||||
in vec4 color;
|
||||
|
||||
uniform Constant {
|
||||
vec4 circleParams;
|
||||
};
|
||||
|
||||
#if USE_TEXTURE
|
||||
in vec2 uv0;
|
||||
#pragma builtin(local)
|
||||
@@ -85,8 +91,8 @@ CCProgram sprite-fs %{
|
||||
#endif
|
||||
|
||||
vec2 uv = (uv0 - color.xy) / color.zw;
|
||||
float d = sdCircle(uv - 0.5, 0.5);
|
||||
float c = smoothstep(0.01, -0.01, d);
|
||||
float d = sdCircle(uv - 0.5, circleParams.x);
|
||||
float c = smoothstep(circleParams.y, circleParams.z, d);
|
||||
o.a *= c;
|
||||
ALPHA_TEST(o);
|
||||
return o;
|
||||
|
93
assets/resources/effects/color_sdf2d_heart.effect
Normal file
93
assets/resources/effects/color_sdf2d_heart.effect
Normal file
@@ -0,0 +1,93 @@
|
||||
// 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:
|
||||
params: { value:[0.5, 0.5, 0.01, -0.01]}
|
||||
|
||||
}%
|
||||
|
||||
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 "../chunks/sdf2d"
|
||||
in vec4 color;
|
||||
|
||||
uniform Constant {
|
||||
vec4 params;
|
||||
};
|
||||
|
||||
|
||||
in vec2 uv0;
|
||||
#pragma builtin(local)
|
||||
layout(set = 2, binding = 12) uniform sampler2D cc_spriteTexture;
|
||||
|
||||
vec4 frag () {
|
||||
vec4 o = vec4(1, 1, 1, 1);
|
||||
|
||||
o *= CCSampleWithAlphaSeparated(cc_spriteTexture, uv0);
|
||||
|
||||
vec2 uv = (uv0 - color.xy) / color.zw;
|
||||
#if UP_SIDE_DOWN
|
||||
uv.y = 1.0 - uv.y;
|
||||
#endif
|
||||
float d = sdHeart((uv + vec2(-0.5, params.y)) / params.x);
|
||||
float c = smoothstep(params.z, params.w, d);
|
||||
o.a *= c;
|
||||
return o;
|
||||
}
|
||||
}%
|
11
assets/resources/effects/color_sdf2d_heart.effect.meta
Normal file
11
assets/resources/effects/color_sdf2d_heart.effect.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "1.7.1",
|
||||
"importer": "effect",
|
||||
"imported": true,
|
||||
"uuid": "fef16f75-0140-40d5-97b8-99185849b0e8",
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
100
assets/resources/effects/color_sdf2d_star5.effect
Normal file
100
assets/resources/effects/color_sdf2d_star5.effect
Normal file
@@ -0,0 +1,100 @@
|
||||
// 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:
|
||||
alphaThreshold: { value: 0.5 }
|
||||
star5Params: { value:[0.5, 0.5, 0.01, -0.01]}
|
||||
|
||||
}%
|
||||
|
||||
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 "../chunks/sdf2d"
|
||||
in vec4 color;
|
||||
|
||||
uniform Constant {
|
||||
vec4 star5Params;
|
||||
};
|
||||
|
||||
#if USE_TEXTURE
|
||||
in vec2 uv0;
|
||||
#pragma builtin(local)
|
||||
layout(set = 2, binding = 12) uniform sampler2D cc_spriteTexture;
|
||||
#endif
|
||||
|
||||
vec4 frag () {
|
||||
vec4 o = vec4(1, 1, 1, 1);
|
||||
|
||||
#if USE_TEXTURE
|
||||
o *= CCSampleWithAlphaSeparated(cc_spriteTexture, uv0);
|
||||
#if IS_GRAY
|
||||
float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;
|
||||
o.r = o.g = o.b = gray;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
vec2 uv = (uv0 - color.xy) / color.zw;
|
||||
float d = sdStar5(uv - 0.5, star5Params.x, star5Params.y);
|
||||
float c = smoothstep(star5Params.z, star5Params.w, d);
|
||||
o.a *= c;
|
||||
return o;
|
||||
}
|
||||
}%
|
11
assets/resources/effects/color_sdf2d_star5.effect.meta
Normal file
11
assets/resources/effects/color_sdf2d_star5.effect.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "1.7.1",
|
||||
"importer": "effect",
|
||||
"imported": true,
|
||||
"uuid": "254577e6-4c95-47b4-9cb2-36ec930c286d",
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user