Compare commits
33 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
c897d7f000 | ||
|
261f390687 | ||
|
d967209a71 | ||
|
72f9037fea | ||
|
7cd2edc0df | ||
|
286fa64ba0 | ||
|
500d0a1614 | ||
|
f2d62a70cb | ||
|
20f72cfd27 | ||
|
cbdbc85ef3 | ||
|
b5390ea84f | ||
|
02d94a943d | ||
|
f9198a3b14 | ||
|
75d4d024bf | ||
|
1c5012ab65 | ||
|
c65106941e | ||
|
c2693616d0 | ||
|
b1196e3808 | ||
|
9865eedc34 | ||
|
f109455742 | ||
|
95a7a51357 | ||
|
4ed91e0a3e | ||
|
f3c0ad079a | ||
|
f1256c5185 | ||
|
f58540ead2 | ||
|
bfe61e6494 | ||
|
c64f1ab144 | ||
|
c047efb715 | ||
|
deebc64aa2 | ||
|
af8aa46786 | ||
|
4ca3fe34b0 | ||
|
eff439ef20 | ||
|
e257d1f8b9 |
12
CHANGELOG.md
12
CHANGELOG.md
@@ -1,5 +1,17 @@
|
||||
# ChangeLog
|
||||
|
||||
## 0.8.0 (2020-02-07)
|
||||
|
||||
- 支持 Cocos Creator v2.2.2
|
||||
|
||||
## 0.7.0 (2020-02-07)
|
||||
|
||||
- 加入高斯模糊V1版本(纯原理篇)
|
||||
|
||||
## 0.6.0 (2020-01-17)
|
||||
|
||||
- 加入新的圆角裁剪特效 v2 ,支持任意宽高纹理圆角裁剪
|
||||
|
||||
## 0.5.0 (2020-01-13)
|
||||
|
||||
- 加入扫光特效
|
||||
|
39
README.md
39
README.md
@@ -1,6 +1,6 @@
|
||||
# Cocos Creator Shader Effect Demo
|
||||
|
||||
[](CHANGELOG.md)
|
||||
[](CHANGELOG.md)
|
||||
[](LICENSE)
|
||||
[](http://www.cocos.com/creator)
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
* [Cocos Creator Shader Effect 系列 - 4 - 老照片特效](https://www.jianshu.com/p/711a54ff2fa0)
|
||||
* [Cocos Creator Shader Effect 系列 - 5 - 马赛克/像素化特效](https://www.jianshu.com/p/40e72ab76afd)
|
||||
* [Cocos Creator Shader Effect 系列 - 6 - 内发光特效](https://www.jianshu.com/p/326b73f86ecc)
|
||||
* [Cocos Creator Shader Effect 系列 - 7 - 点光/扫光特效](https://www.jianshu.com/p/8ff03b34b0bd)
|
||||
* [Cocos Creator Shader Effect 系列 - 8 - 高斯模糊](https://www.jianshu.com/p/9e42cbb1d4a8)
|
||||
|
||||
|
||||
* 编写中...
|
||||
|
||||
@@ -26,13 +29,7 @@
|
||||
|
||||
## 三、特效预览
|
||||
|
||||
### 扫光(实现原理,可能在编写中,催更可到底部扫码,支持急件~🤣)(2020.01.13更新)
|
||||
|
||||

|
||||
|
||||
### 点光(实现原理,可能在编写中,催更可到底部扫码,支持急件~🤣)(2020.01.12更新)
|
||||
|
||||

|
||||
|
||||
### 内发光([实现原理](https://www.jianshu.com/p/326b73f86ecc))
|
||||
|
||||
@@ -50,14 +47,38 @@
|
||||
|
||||

|
||||
|
||||
### 圆角裁剪
|
||||
### 点光([实现原理](https://www.jianshu.com/p/8ff03b34b0bd))(2020.01.12更新)
|
||||
|
||||

|
||||
|
||||
### 扫光(实现原理同点光一样,可参考[点光实现原理文章](https://www.jianshu.com/p/711a54ff2fa0))(2020.01.13更新)
|
||||
|
||||

|
||||
|
||||
### 圆角裁剪-v1(2020.01.17更新)
|
||||
|
||||
> * 声明:此特效为搬运过来的特效,非原创。
|
||||
> * 修改的地方:搬运后,在原来的主要代码上加入了自己的理解注释
|
||||
> * 实现原理:参考文章 [《圆角计算 Shader》](https://www.cnblogs.com/jqm304775992/p/4987793.html)
|
||||
> * 参考代码:Cocos 论坛帖子[《分享更高效的 creator 裁圆角头像 shader》](https://forum.cocos.org/t/creator-shader-2019-10-22-2-2-0/82548) 和对应的 [实现代码](https://github.com/yanjifa/shaderDemo/blob/master/assets/Effect/CircleAvatar.effect)
|
||||
|
||||

|
||||
**此版本存在局限性:只有在正方形纹理上,才能裁剪出圆角,在非正方形上,无法裁剪出圆角,具体变现为有拉伸效果**
|
||||
|
||||
如:下面GIF中第3到5秒演示所示,黄色和红色的非正方形纹理的圆角明显被拉伸
|
||||
|
||||

|
||||
|
||||
### 圆角裁剪-v2(2020.01.17更新)
|
||||
|
||||
在 **圆角裁剪-v1** 的原理基础上,新增支持任意宽高纹理的圆角裁剪
|
||||
|
||||
如:下面Gif中第3到5秒演示所示,黄色和红色的非正方形纹理也能裁剪出圆角效果
|
||||
|
||||

|
||||
|
||||
### 高斯模糊-V1([实现原理](https://www.jianshu.com/p/9e42cbb1d4a8))2020.02.07更新)
|
||||
|
||||

|
||||
|
||||
### 外发光(完善中...)
|
||||
|
||||
|
196
assets/effects/sprite-gaussian-blur-v1.effect
Normal file
196
assets/effects/sprite-gaussian-blur-v1.effect
Normal file
@@ -0,0 +1,196 @@
|
||||
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
// 高斯模糊
|
||||
//
|
||||
// 参考资料(必读)
|
||||
// * http://www.ruanyifeng.com/blog/2012/11/gaussian_blur.html
|
||||
// * https://zh.wikipedia.org/wiki/%E9%AB%98%E6%96%AF%E6%A8%A1%E7%B3%8A
|
||||
|
||||
|
||||
CCEffect %{
|
||||
techniques:
|
||||
- passes:
|
||||
- vert: vs
|
||||
frag: fs
|
||||
blendState:
|
||||
targets:
|
||||
- blend: true
|
||||
rasterizerState:
|
||||
cullMode: none
|
||||
properties:
|
||||
texture: { value: white }
|
||||
alphaThreshold: { value: 0.5 }
|
||||
# # 标准方差值
|
||||
# stDev: {
|
||||
# value: 0.84089642,
|
||||
# inspector: {
|
||||
# tooltip: "标准方差值"
|
||||
# }
|
||||
# }
|
||||
|
||||
# 纹理尺寸
|
||||
textureSize: {
|
||||
value: [100.0, 100.0],
|
||||
inspector: {
|
||||
tooltip: "纹理尺寸px(宽 x 高)"
|
||||
}
|
||||
}
|
||||
}%
|
||||
|
||||
|
||||
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 <alpha-test>
|
||||
|
||||
in vec4 v_color;
|
||||
|
||||
#if USE_TEXTURE
|
||||
in vec2 v_uv0;
|
||||
uniform sampler2D texture;
|
||||
#endif
|
||||
|
||||
#if ENABLE_GAUSSIAN_BLUR
|
||||
|
||||
// 定义无理数
|
||||
#define e 2.718281828459045
|
||||
|
||||
// 定义标准方差值(方差值越大,越模糊,但是需要计算的高斯矩阵范围会变大,从而带来巨大的计算量)
|
||||
// #define stDev 0.84089642
|
||||
#define stDev 1.5
|
||||
// #define stDev 5.0
|
||||
// #define stDev 10.0
|
||||
|
||||
// 定义π
|
||||
#define pi 3.141592653589793
|
||||
|
||||
// 接收外部变量
|
||||
uniform GaussianBlur {
|
||||
// 纹理尺寸(宽 x 高)(px)
|
||||
vec2 textureSize;
|
||||
|
||||
// // 标准方差值
|
||||
// float stDev;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取权重(对应二维高斯函数公式,见 https://zh.wikipedia.org/wiki/%E9%AB%98%E6%96%AF%E6%A8%A1%E7%B3%8A )
|
||||
*/
|
||||
float getWeight(float x, float y) {
|
||||
return (1.0 / (2.0 * pi * pow(stDev, 2.0))) * pow(1.0 / e, (pow(x, 2.0) + pow(y, 2.0)) / (2.0 * pow(stDev, 2.0)));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void main () {
|
||||
vec4 o = vec4(1, 1, 1, 1);
|
||||
|
||||
#if USE_TEXTURE
|
||||
o *= texture(texture, v_uv0);
|
||||
#if CC_USE_ALPHA_ATLAS_TEXTURE
|
||||
o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
o *= v_color;
|
||||
|
||||
ALPHA_TEST(o);
|
||||
|
||||
gl_FragColor = o;
|
||||
#if ENABLE_GAUSSIAN_BLUR
|
||||
|
||||
// 根据高斯分布(也叫正态分布),在3个标准差范围内的分布比例占到99%的权重,因此我们只需要计算矩阵范围 [6 * stDev + 1, 6 * stDev +1] 上的权重
|
||||
const float size = floor(stDev * 6.0 + 1.0);
|
||||
const float halfSize = floor(size / 2.0);
|
||||
|
||||
// 步骤一:计算高斯矩阵上所有权重的和
|
||||
|
||||
// // v1:遍历所有点,每个点都计算权重
|
||||
// float totalWeight = 0.0;
|
||||
// for(float x = -halfSize; x<= halfSize; x++) {
|
||||
// for (float y = -halfSize; y<= halfSize; y++) {
|
||||
// totalWeight += getWeight(x, y);
|
||||
// }
|
||||
// }
|
||||
|
||||
// v2:因为高斯分布是对称的,所以只计算原点、X轴正方向 * 2 、Y轴正方向 * 2 、第一象限的权重 * 4即可求出所有权重之和,相比起v1版本,减少很多循环计算
|
||||
|
||||
// 原点
|
||||
float totalWeight = getWeight(0.0, 0.0);
|
||||
|
||||
// X轴正方向上的权重 * 2.0 就是整个X轴上的权重
|
||||
for(float x = 1.0; x <= halfSize; x++) {
|
||||
totalWeight += getWeight(x, 0.0) * 2.0;
|
||||
}
|
||||
// Y轴正方向上的权重 * 2.0 就是整个Y轴上的权重
|
||||
for(float y = 1.0; y <= halfSize; y++) {
|
||||
totalWeight += getWeight(0.0, y) * 2.0;
|
||||
}
|
||||
// 第一象限的权重 * 4.0 就是4个象限的权重
|
||||
for(float x = 1.0; x <= halfSize; x++) {
|
||||
for (float y = 1.0; y<= halfSize; y++) {
|
||||
totalWeight += getWeight(x, y) * 4.0;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO:
|
||||
//
|
||||
// 因为权重矩阵是一次性计算即可不断应用,因此可以将权重矩阵的计算放到CPU计算,并传入到Shader直接渲染,因此有以下优化方案
|
||||
//
|
||||
// v3:原始权重矩阵在CPU计算并传入到Shader
|
||||
// v4:加权平均后的权重矩阵在CPU计算并传入Shader
|
||||
|
||||
|
||||
// 步骤二:采样周边像素并应用加权平均值,得出最终像素值
|
||||
vec4 finalColor = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
// float divider = 0.01;
|
||||
float onePxWidth = 1.0 / textureSize.x;
|
||||
float onePxHeight = 1.0 / textureSize.y;
|
||||
for(float x = -halfSize; x<= halfSize; x++) {
|
||||
for (float y = -halfSize; y<= halfSize; y++) {
|
||||
// 求出对应坐标的真正权重(对应权重矩阵)
|
||||
float weight = getWeight(x, y) / totalWeight;
|
||||
|
||||
// 求出对应坐标像素颜色值的加权值
|
||||
// finalColor += texture(texture, v_uv0 + vec2(divider * x, divider * y)) * weight;
|
||||
finalColor += texture(texture, v_uv0 + vec2(onePxWidth * x, onePxHeight * y)) * weight;
|
||||
}
|
||||
}
|
||||
gl_FragColor = finalColor;
|
||||
#endif
|
||||
}
|
||||
}%
|
17
assets/effects/sprite-gaussian-blur-v1.effect.meta
Normal file
17
assets/effects/sprite-gaussian-blur-v1.effect.meta
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"ver": "1.0.23",
|
||||
"uuid": "41f4d474-d707-45bb-af93-637573f92d54",
|
||||
"compiledShaders": [
|
||||
{
|
||||
"glsl1": {
|
||||
"vert": "\nprecision highp float;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matWorld;\n\nattribute vec3 a_position;\nattribute vec4 a_color;\nvarying vec4 v_color;\n\n#if USE_TEXTURE\nattribute vec2 a_uv0;\nvarying vec2 v_uv0;\n#endif\n\nvoid main () {\n vec4 pos = vec4(a_position, 1);\n\n #if CC_USE_MODEL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n\n #if USE_TEXTURE\n v_uv0 = a_uv0;\n #endif\n\n v_color = a_color;\n\n gl_Position = pos;\n}\n",
|
||||
"frag": "\nprecision highp float;\n\n#if USE_ALPHA_TEST\n \n uniform float alphaThreshold;\n#endif\n\nvoid ALPHA_TEST (in vec4 color) {\n #if USE_ALPHA_TEST\n if (color.a < alphaThreshold) discard;\n #endif\n}\n\nvoid ALPHA_TEST (in float alpha) {\n #if USE_ALPHA_TEST\n if (alpha < alphaThreshold) discard;\n #endif\n}\n\nvarying vec4 v_color;\n\n#if USE_TEXTURE\nvarying vec2 v_uv0;\nuniform sampler2D texture;\n#endif\n\n#if ENABLE_GAUSSIAN_BLUR\n\nuniform vec2 textureSize;\n/**\n * 获取权重(对应二维高斯函数公式,见 https:\n\n */\nfloat getWeight(float x, float y) {\n return (1.0 / (2.0 * 3.141592653589793 * pow(1.5, 2.0))) * pow(1.0 / 2.718281828459045, (pow(x, 2.0) + pow(y, 2.0)) / (2.0 * pow(1.5, 2.0)));\n}\n\n#endif\n\nvoid main () {\n vec4 o = vec4(1, 1, 1, 1);\n\n #if USE_TEXTURE\n o *= texture2D(texture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_TEXTURE\n o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #endif\n\n o *= v_color;\n\n ALPHA_TEST(o);\n\n gl_FragColor = o;\n #if ENABLE_GAUSSIAN_BLUR\n\n const float size = floor(1.5 * 6.0 + 1.0);\n const float halfSize = floor(size / 2.0);\n\n float totalWeight = getWeight(0.0, 0.0);\n\n for(float x = 1.0; x <= halfSize; x++) {\n totalWeight += getWeight(x, 0.0) * 2.0;\n }\n\n for(float y = 1.0; y <= halfSize; y++) {\n totalWeight += getWeight(0.0, y) * 2.0;\n }\n\n for(float x = 1.0; x <= halfSize; x++) {\n for (float y = 1.0; y<= halfSize; y++) {\n totalWeight += getWeight(x, y) * 4.0;\n }\n }\n\n vec4 finalColor = vec4(0.0, 0.0, 0.0, 0.0);\n\n float onePxWidth = 1.0 / textureSize.x;\n float onePxHeight = 1.0 / textureSize.y;\n for(float x = -halfSize; x<= halfSize; x++) {\n for (float y = -halfSize; y<= halfSize; y++) {\n\n float weight = getWeight(x, y) / totalWeight;\n\n finalColor += texture2D(texture, v_uv0 + vec2(onePxWidth * x, onePxHeight * y)) * weight;\n }\n }\n gl_FragColor = finalColor;\n #endif\n}\n"
|
||||
},
|
||||
"glsl3": {
|
||||
"vert": "\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time;\n\n vec4 cc_screenSize;\n\n vec4 cc_screenScale;\n\n vec4 cc_nativeSize;\n\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n\n vec4 cc_exposure;\n\n vec4 cc_mainLitDir;\n\n vec4 cc_mainLitColor;\n\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\n\nin vec3 a_position;\nin vec4 a_color;\nout vec4 v_color;\n\n#if USE_TEXTURE\nin vec2 a_uv0;\nout vec2 v_uv0;\n#endif\n\nvoid main () {\n vec4 pos = vec4(a_position, 1);\n\n #if CC_USE_MODEL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n\n #if USE_TEXTURE\n v_uv0 = a_uv0;\n #endif\n\n v_color = a_color;\n\n gl_Position = pos;\n}\n",
|
||||
"frag": "\nprecision highp float;\n\n#if USE_ALPHA_TEST\n \n uniform ALPHA_TEST {\n float alphaThreshold;\n }\n#endif\n\nvoid ALPHA_TEST (in vec4 color) {\n #if USE_ALPHA_TEST\n if (color.a < alphaThreshold) discard;\n #endif\n}\n\nvoid ALPHA_TEST (in float alpha) {\n #if USE_ALPHA_TEST\n if (alpha < alphaThreshold) discard;\n #endif\n}\n\nin vec4 v_color;\n\n#if USE_TEXTURE\nin vec2 v_uv0;\nuniform sampler2D texture;\n#endif\n\n#if ENABLE_GAUSSIAN_BLUR\n\nuniform GaussianBlur {\n\n vec2 textureSize;\n\n}\n\n/**\n * 获取权重(对应二维高斯函数公式,见 https:\n\n */\nfloat getWeight(float x, float y) {\n return (1.0 / (2.0 * 3.141592653589793 * pow(1.5, 2.0))) * pow(1.0 / 2.718281828459045, (pow(x, 2.0) + pow(y, 2.0)) / (2.0 * pow(1.5, 2.0)));\n}\n\n#endif\n\nvoid main () {\n vec4 o = vec4(1, 1, 1, 1);\n\n #if USE_TEXTURE\n o *= texture(texture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_TEXTURE\n o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #endif\n\n o *= v_color;\n\n ALPHA_TEST(o);\n\n gl_FragColor = o;\n #if ENABLE_GAUSSIAN_BLUR\n\n const float size = floor(1.5 * 6.0 + 1.0);\n const float halfSize = floor(size / 2.0);\n\n float totalWeight = getWeight(0.0, 0.0);\n\n for(float x = 1.0; x <= halfSize; x++) {\n totalWeight += getWeight(x, 0.0) * 2.0;\n }\n\n for(float y = 1.0; y <= halfSize; y++) {\n totalWeight += getWeight(0.0, y) * 2.0;\n }\n\n for(float x = 1.0; x <= halfSize; x++) {\n for (float y = 1.0; y<= halfSize; y++) {\n totalWeight += getWeight(x, y) * 4.0;\n }\n }\n\n vec4 finalColor = vec4(0.0, 0.0, 0.0, 0.0);\n\n float onePxWidth = 1.0 / textureSize.x;\n float onePxHeight = 1.0 / textureSize.y;\n for(float x = -halfSize; x<= halfSize; x++) {\n for (float y = -halfSize; y<= halfSize; y++) {\n\n float weight = getWeight(x, y) / totalWeight;\n\n finalColor += texture(texture, v_uv0 + vec2(onePxWidth * x, onePxHeight * y)) * weight;\n }\n }\n gl_FragColor = finalColor;\n #endif\n}\n"
|
||||
}
|
||||
}
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
@@ -117,7 +117,7 @@ CCProgram fs %{
|
||||
* 添加某个扩散点后混合后的纹理颜色
|
||||
*/
|
||||
vec4 addLightColor(vec4 textureColor, vec2 centerPoint, float radius, vec4 centerColor) {
|
||||
// 计算当前 uv 到扩散起点的距离
|
||||
// 计算当前 uv 到圆心起点的距离
|
||||
float dis = distance(v_uv0, centerPoint);
|
||||
|
||||
float a = 1.0 ;
|
||||
@@ -127,7 +127,7 @@ CCProgram fs %{
|
||||
a *= step(0.01, textureColor.a);
|
||||
}
|
||||
|
||||
// 裁剪掉扩散范围外的uv(迷雾效果)
|
||||
// 裁剪掉圆范围外的uv(迷雾效果)
|
||||
if (!enableFog) {
|
||||
a *= step(dis, radius);
|
||||
}
|
||||
@@ -135,11 +135,11 @@ CCProgram fs %{
|
||||
// 加入从中心往外渐变的效果
|
||||
a *= 1.0 - (dis / radius);
|
||||
|
||||
// 计算出扩散范围内,不同 uv 对应的实际扩散颜色值
|
||||
vec4 diffusionColor = centerColor * a;
|
||||
// 计算出圆范围内,不同 uv 对应的实际颜色值
|
||||
vec4 lightColor = centerColor * a;
|
||||
|
||||
// 混合颜色:在原始图像颜色上叠加扩散颜色
|
||||
return textureColor * textureColor.a + diffusionColor;
|
||||
// 混合颜色:在原始图像颜色上叠加圆颜色
|
||||
return textureColor * textureColor.a + lightColor;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@@ -5,11 +5,11 @@
|
||||
{
|
||||
"glsl1": {
|
||||
"vert": "\nprecision highp float;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matWorld;\n\nattribute vec3 a_position;\nattribute vec4 a_color;\nvarying vec4 v_color;\n\n#if USE_TEXTURE\nattribute vec2 a_uv0;\nvarying vec2 v_uv0;\n#endif\n\nvoid main () {\n vec4 pos = vec4(a_position, 1);\n\n #if CC_USE_MODEL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n\n #if USE_TEXTURE\n v_uv0 = a_uv0;\n #endif\n\n v_color = a_color;\n\n gl_Position = pos;\n}\n",
|
||||
"frag": "\nprecision highp float;\n\n#if USE_ALPHA_TEST\n \n uniform float alphaThreshold;\n#endif\n\nvoid ALPHA_TEST (in vec4 color) {\n #if USE_ALPHA_TEST\n if (color.a < alphaThreshold) discard;\n #endif\n}\n\nvoid ALPHA_TEST (in float alpha) {\n #if USE_ALPHA_TEST\n if (alpha < alphaThreshold) discard;\n #endif\n}\n\nvarying vec4 v_color;\n\n#if USE_TEXTURE\nvarying vec2 v_uv0;\nuniform sampler2D texture;\n#endif\n\n#if ENABLE_DIFFUSION\nuniform vec4 centerColor;\nuniform vec2 centerPoint;\nuniform float radius;\nuniform bool cropAlpha;\nuniform bool enableFog;\n/**\n * 添加某个扩散点后混合后的纹理颜色\n */\nvec4 addLightColor(vec4 textureColor, vec2 centerPoint, float radius, vec4 centerColor) {\n\n float dis = distance(v_uv0, centerPoint);\n\n float a = 1.0 ;\n\n if (cropAlpha) {\n a *= step(0.01, textureColor.a);\n }\n\n if (!enableFog) {\n a *= step(dis, radius);\n }\n\n a *= 1.0 - (dis / radius);\n\n vec4 diffusionColor = centerColor * a;\n\n return textureColor * textureColor.a + diffusionColor;\n}\n#endif\n\nvoid main () {\n vec4 o = vec4(1, 1, 1, 1);\n\n #if USE_TEXTURE\n o *= texture2D(texture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_TEXTURE\n o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #endif\n\n o *= v_color;\n\n ALPHA_TEST(o);\n\n gl_FragColor = o;\n \n #if ENABLE_DIFFUSION\n gl_FragColor = addLightColor(gl_FragColor, centerPoint, radius, centerColor);\n #endif\n}\n"
|
||||
"frag": "\nprecision highp float;\n\n#if USE_ALPHA_TEST\n \n uniform float alphaThreshold;\n#endif\n\nvoid ALPHA_TEST (in vec4 color) {\n #if USE_ALPHA_TEST\n if (color.a < alphaThreshold) discard;\n #endif\n}\n\nvoid ALPHA_TEST (in float alpha) {\n #if USE_ALPHA_TEST\n if (alpha < alphaThreshold) discard;\n #endif\n}\n\nvarying vec4 v_color;\n\n#if USE_TEXTURE\nvarying vec2 v_uv0;\nuniform sampler2D texture;\n#endif\n\n#if ENABLE_DIFFUSION\nuniform vec4 centerColor;\nuniform vec2 centerPoint;\nuniform float radius;\nuniform bool cropAlpha;\nuniform bool enableFog;\n/**\n * 添加某个扩散点后混合后的纹理颜色\n */\nvec4 addLightColor(vec4 textureColor, vec2 centerPoint, float radius, vec4 centerColor) {\n\n float dis = distance(v_uv0, centerPoint);\n\n float a = 1.0 ;\n\n if (cropAlpha) {\n a *= step(0.01, textureColor.a);\n }\n\n if (!enableFog) {\n a *= step(dis, radius);\n }\n\n a *= 1.0 - (dis / radius);\n\n vec4 lightColor = centerColor * a;\n\n return textureColor * textureColor.a + lightColor;\n}\n#endif\n\nvoid main () {\n vec4 o = vec4(1, 1, 1, 1);\n\n #if USE_TEXTURE\n o *= texture2D(texture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_TEXTURE\n o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #endif\n\n o *= v_color;\n\n ALPHA_TEST(o);\n\n gl_FragColor = o;\n \n #if ENABLE_DIFFUSION\n gl_FragColor = addLightColor(gl_FragColor, centerPoint, radius, centerColor);\n #endif\n}\n"
|
||||
},
|
||||
"glsl3": {
|
||||
"vert": "\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time;\n\n vec4 cc_screenSize;\n\n vec4 cc_screenScale;\n\n vec4 cc_nativeSize;\n\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n\n vec4 cc_exposure;\n\n vec4 cc_mainLitDir;\n\n vec4 cc_mainLitColor;\n\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\n\nin vec3 a_position;\nin vec4 a_color;\nout vec4 v_color;\n\n#if USE_TEXTURE\nin vec2 a_uv0;\nout vec2 v_uv0;\n#endif\n\nvoid main () {\n vec4 pos = vec4(a_position, 1);\n\n #if CC_USE_MODEL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n\n #if USE_TEXTURE\n v_uv0 = a_uv0;\n #endif\n\n v_color = a_color;\n\n gl_Position = pos;\n}\n",
|
||||
"frag": "\nprecision highp float;\n\n#if USE_ALPHA_TEST\n \n uniform ALPHA_TEST {\n float alphaThreshold;\n }\n#endif\n\nvoid ALPHA_TEST (in vec4 color) {\n #if USE_ALPHA_TEST\n if (color.a < alphaThreshold) discard;\n #endif\n}\n\nvoid ALPHA_TEST (in float alpha) {\n #if USE_ALPHA_TEST\n if (alpha < alphaThreshold) discard;\n #endif\n}\n\nin vec4 v_color;\n\n#if USE_TEXTURE\nin vec2 v_uv0;\nuniform sampler2D texture;\n#endif\n\n#if ENABLE_DIFFUSION\nuniform Diffusion {\n\n vec4 centerColor;\n\n vec2 centerPoint;\n\n float radius;\n\n bool cropAlpha;\n\n bool enableFog;\n}\n\n/**\n * 添加某个扩散点后混合后的纹理颜色\n */\nvec4 addLightColor(vec4 textureColor, vec2 centerPoint, float radius, vec4 centerColor) {\n\n float dis = distance(v_uv0, centerPoint);\n\n float a = 1.0 ;\n\n if (cropAlpha) {\n a *= step(0.01, textureColor.a);\n }\n\n if (!enableFog) {\n a *= step(dis, radius);\n }\n\n a *= 1.0 - (dis / radius);\n\n vec4 diffusionColor = centerColor * a;\n\n return textureColor * textureColor.a + diffusionColor;\n}\n#endif\n\nvoid main () {\n vec4 o = vec4(1, 1, 1, 1);\n\n #if USE_TEXTURE\n o *= texture(texture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_TEXTURE\n o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #endif\n\n o *= v_color;\n\n ALPHA_TEST(o);\n\n gl_FragColor = o;\n \n #if ENABLE_DIFFUSION\n gl_FragColor = addLightColor(gl_FragColor, centerPoint, radius, centerColor);\n #endif\n}\n"
|
||||
"frag": "\nprecision highp float;\n\n#if USE_ALPHA_TEST\n \n uniform ALPHA_TEST {\n float alphaThreshold;\n }\n#endif\n\nvoid ALPHA_TEST (in vec4 color) {\n #if USE_ALPHA_TEST\n if (color.a < alphaThreshold) discard;\n #endif\n}\n\nvoid ALPHA_TEST (in float alpha) {\n #if USE_ALPHA_TEST\n if (alpha < alphaThreshold) discard;\n #endif\n}\n\nin vec4 v_color;\n\n#if USE_TEXTURE\nin vec2 v_uv0;\nuniform sampler2D texture;\n#endif\n\n#if ENABLE_DIFFUSION\nuniform Diffusion {\n\n vec4 centerColor;\n\n vec2 centerPoint;\n\n float radius;\n\n bool cropAlpha;\n\n bool enableFog;\n}\n\n/**\n * 添加某个扩散点后混合后的纹理颜色\n */\nvec4 addLightColor(vec4 textureColor, vec2 centerPoint, float radius, vec4 centerColor) {\n\n float dis = distance(v_uv0, centerPoint);\n\n float a = 1.0 ;\n\n if (cropAlpha) {\n a *= step(0.01, textureColor.a);\n }\n\n if (!enableFog) {\n a *= step(dis, radius);\n }\n\n a *= 1.0 - (dis / radius);\n\n vec4 lightColor = centerColor * a;\n\n return textureColor * textureColor.a + lightColor;\n}\n#endif\n\nvoid main () {\n vec4 o = vec4(1, 1, 1, 1);\n\n #if USE_TEXTURE\n o *= texture(texture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_TEXTURE\n o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #endif\n\n o *= v_color;\n\n ALPHA_TEST(o);\n\n gl_FragColor = o;\n \n #if ENABLE_DIFFUSION\n gl_FragColor = addLightColor(gl_FragColor, centerPoint, radius, centerColor);\n #endif\n}\n"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@@ -1,5 +1,7 @@
|
||||
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
// 圆角裁剪
|
||||
//
|
||||
// 圆角裁剪(仅支持正方形纹理)
|
||||
//
|
||||
// 原理:https://www.cnblogs.com/jqm304775992/p/4987793.html
|
||||
// 代码:复制 yanjifa/shaderDemor 的 https://github.com/yanjifa/shaderDemo/blob/master/assets/Effect/CircleAvatar.effect
|
||||
|
||||
@@ -17,8 +19,8 @@ CCEffect %{
|
||||
texture: { value: white }
|
||||
alphaThreshold: { value: 0.5 }
|
||||
# 圆角半径
|
||||
roundCornerRadius: {
|
||||
value: 0.1,
|
||||
radius: {
|
||||
value: 0.4,
|
||||
inspector: {
|
||||
tooltip: "圆角半径",
|
||||
range: [0.0, 0.5]
|
||||
@@ -77,7 +79,7 @@ CCProgram fs %{
|
||||
#if ENABLE_ROUNDCORNER
|
||||
uniform RoundCorner {
|
||||
// 圆角半径
|
||||
float roundCornerRadius;
|
||||
float radius;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -97,17 +99,17 @@ CCProgram fs %{
|
||||
|
||||
#if ENABLE_ROUNDCORNER
|
||||
// 约束圆角半径范围在 [0.0, 0.5]
|
||||
float radius = clamp(0.0, 0.5, roundCornerRadius);
|
||||
float circleRadius = clamp(0.0, 0.5, radius);
|
||||
|
||||
// 将纹理uv往左下偏移,实现偏移后的纹理中心点在 OpenGL 坐标系的原点
|
||||
// 将纹理uv往左上偏移,实现偏移后的坐标系原点在纹理中心
|
||||
vec2 uv = v_uv0.xy - vec2(0.5, 0.5);
|
||||
|
||||
// uv.x , uv.y : 为偏移后的的uv
|
||||
// abs(uv.x) , abs(uv.y) : 将第二、三、四象限的点都投影到第一象限上,这样子只需要处理第一象限的情况就可以,简化判断
|
||||
// 0.5 - radius : 计算出第一象限的圆角所在圆的圆心坐标
|
||||
// (rx, ry) : 偏移映射后的 新的uv 坐标,相对于 第一象限圆角坐在圆心坐标 的相对坐标
|
||||
float rx = abs(uv.x) - (0.5 - radius);
|
||||
float ry = abs(uv.y) - (0.5 - radius);
|
||||
float rx = abs(uv.x) - (0.5 - circleRadius);
|
||||
float ry = abs(uv.y) - (0.5 - circleRadius);
|
||||
|
||||
// 区分 以第一象限圆角所在圆心坐标为原点的坐标的四个象限
|
||||
//
|
||||
@@ -117,26 +119,26 @@ CCProgram fs %{
|
||||
// 第四象限 mx = 1, my = 0
|
||||
//
|
||||
// 当 mx * my 时,只要等于1,那就是标识第一象限(实际对应圆角区域所在矩形),否则就是第二、三、四象限
|
||||
float mx = step(0.5 - radius, abs(uv.x));
|
||||
float my = step(0.5 - radius, abs(uv.y));
|
||||
float mx = step(0.5 - circleRadius, abs(uv.x));
|
||||
float my = step(0.5 - circleRadius, abs(uv.y));
|
||||
|
||||
// 计算相对uv坐标到圆心的距离
|
||||
float len = length(vec2(rx, ry));
|
||||
|
||||
// mx * my = 0 时,代表非圆角区域,a 值为1,代表完全采用原始纹理的透明度
|
||||
// mx * my = 1 时,代表园所所在矩形区域
|
||||
// step(radius, len) 可以区分出圆角所在矩形区域的 圆角区域 和 非圆角区域
|
||||
// step(circleRadius, len) 可以区分出圆角所在矩形区域的 圆角区域 和 非圆角区域
|
||||
// 其中圆角区域值为0,非圆角区域值为1
|
||||
// 当为圆角区域时,a 值为1,代表完全采用原始纹理透明度
|
||||
// 当为非圆角区域时,a 值为0,代表完全透明
|
||||
// 至此已经实现圆角裁剪
|
||||
//
|
||||
// smoothstep(0., radius * 0.01, len - radius) 是用于抗锯齿优化
|
||||
// smoothstep(0., circleRadius * 0.01, len - circleRadius) 是用于抗锯齿优化
|
||||
// 原理:针对点在非圆角区域的情况,针对点在大于「圆半径一点点」地方的区域,进行平滑过渡,以实现抗锯齿
|
||||
// 其中,
|
||||
// 「圆半径一点点」用 radius * 0.01 表示(0.01 可自行改变)
|
||||
// 点在大于圆半径的区域用 len - radius ,此值会在 [0.0, radius * 0.01] 之间时会平滑过渡
|
||||
float a = 1.0 - mx * my * step(radius, len) * smoothstep(0., radius * 0.01, len - radius);
|
||||
// 「圆半径一点点」用 circleRadius * 0.01 表示(0.01 可自行改变)
|
||||
// 点在大于圆半径的区域用 len - circleRadius ,此值会在 [0.0, circleRadius * 0.01] 之间时会平滑过渡
|
||||
float a = 1.0 - mx * my * step(circleRadius, len) * smoothstep(0., circleRadius * 0.01, len - circleRadius);
|
||||
o = vec4(o.rgb, o.a * a);
|
||||
#endif
|
||||
gl_FragColor = o;
|
@@ -5,11 +5,11 @@
|
||||
{
|
||||
"glsl1": {
|
||||
"vert": "\nprecision highp float;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matWorld;\n\nattribute vec3 a_position;\nattribute vec4 a_color;\nvarying vec4 v_color;\n\n#if USE_TEXTURE\nattribute vec2 a_uv0;\nvarying vec2 v_uv0;\n#endif\n\nvoid main () {\n vec4 pos = vec4(a_position, 1);\n\n #if CC_USE_MODEL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n\n #if USE_TEXTURE\n v_uv0 = a_uv0;\n #endif\n\n v_color = a_color;\n\n gl_Position = pos;\n}\n",
|
||||
"frag": "\nprecision highp float;\n\n#if USE_ALPHA_TEST\n \n uniform float alphaThreshold;\n#endif\n\nvoid ALPHA_TEST (in vec4 color) {\n #if USE_ALPHA_TEST\n if (color.a < alphaThreshold) discard;\n #endif\n}\n\nvoid ALPHA_TEST (in float alpha) {\n #if USE_ALPHA_TEST\n if (alpha < alphaThreshold) discard;\n #endif\n}\n\nvarying vec4 v_color;\n\n#if USE_TEXTURE\nvarying vec2 v_uv0;\nuniform sampler2D texture;\n#endif\n\n#if ENABLE_ROUNDCORNER\nuniform float roundCornerRadius;\n#endif\n\nvoid main () {\n vec4 o = vec4(1, 1, 1, 1);\n\n #if USE_TEXTURE\n o *= texture2D(texture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_TEXTURE\n o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #endif\n\n o *= v_color;\n\n ALPHA_TEST(o);\n\n #if ENABLE_ROUNDCORNER\n\n float radius = clamp(0.0, 0.5, roundCornerRadius);\n\n vec2 uv = v_uv0.xy - vec2(0.5, 0.5);\n\n float rx = abs(uv.x) - (0.5 - radius);\n float ry = abs(uv.y) - (0.5 - radius);\n\n float mx = step(0.5 - radius, abs(uv.x));\n float my = step(0.5 - radius, abs(uv.y));\n\n float len = length(vec2(rx, ry));\n\n float a = 1.0 - mx * my * step(radius, len) * smoothstep(0., radius * 0.01, len - radius);\n o = vec4(o.rgb, o.a * a);\n #endif\n gl_FragColor = o;\n}\n"
|
||||
"frag": "\nprecision highp float;\n\n#if USE_ALPHA_TEST\n \n uniform float alphaThreshold;\n#endif\n\nvoid ALPHA_TEST (in vec4 color) {\n #if USE_ALPHA_TEST\n if (color.a < alphaThreshold) discard;\n #endif\n}\n\nvoid ALPHA_TEST (in float alpha) {\n #if USE_ALPHA_TEST\n if (alpha < alphaThreshold) discard;\n #endif\n}\n\nvarying vec4 v_color;\n\n#if USE_TEXTURE\nvarying vec2 v_uv0;\nuniform sampler2D texture;\n#endif\n\n#if ENABLE_ROUNDCORNER\nuniform float radius;\n#endif\n\nvoid main () {\n vec4 o = vec4(1, 1, 1, 1);\n\n #if USE_TEXTURE\n o *= texture2D(texture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_TEXTURE\n o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #endif\n\n o *= v_color;\n\n ALPHA_TEST(o);\n\n #if ENABLE_ROUNDCORNER\n\n float circleRadius = clamp(0.0, 0.5, radius);\n\n vec2 uv = v_uv0.xy - vec2(0.5, 0.5);\n\n float rx = abs(uv.x) - (0.5 - circleRadius);\n float ry = abs(uv.y) - (0.5 - circleRadius);\n\n float mx = step(0.5 - circleRadius, abs(uv.x));\n float my = step(0.5 - circleRadius, abs(uv.y));\n\n float len = length(vec2(rx, ry));\n\n float a = 1.0 - mx * my * step(circleRadius, len) * smoothstep(0., circleRadius * 0.01, len - circleRadius);\n o = vec4(o.rgb, o.a * a);\n #endif\n gl_FragColor = o;\n}\n"
|
||||
},
|
||||
"glsl3": {
|
||||
"vert": "\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time;\n\n vec4 cc_screenSize;\n\n vec4 cc_screenScale;\n\n vec4 cc_nativeSize;\n\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n\n vec4 cc_exposure;\n\n vec4 cc_mainLitDir;\n\n vec4 cc_mainLitColor;\n\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\n\nin vec3 a_position;\nin vec4 a_color;\nout vec4 v_color;\n\n#if USE_TEXTURE\nin vec2 a_uv0;\nout vec2 v_uv0;\n#endif\n\nvoid main () {\n vec4 pos = vec4(a_position, 1);\n\n #if CC_USE_MODEL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n\n #if USE_TEXTURE\n v_uv0 = a_uv0;\n #endif\n\n v_color = a_color;\n\n gl_Position = pos;\n}\n",
|
||||
"frag": "\nprecision highp float;\n\n#if USE_ALPHA_TEST\n \n uniform ALPHA_TEST {\n float alphaThreshold;\n }\n#endif\n\nvoid ALPHA_TEST (in vec4 color) {\n #if USE_ALPHA_TEST\n if (color.a < alphaThreshold) discard;\n #endif\n}\n\nvoid ALPHA_TEST (in float alpha) {\n #if USE_ALPHA_TEST\n if (alpha < alphaThreshold) discard;\n #endif\n}\n\nin vec4 v_color;\n\n#if USE_TEXTURE\nin vec2 v_uv0;\nuniform sampler2D texture;\n#endif\n\n#if ENABLE_ROUNDCORNER\nuniform RoundCorner {\n\n float roundCornerRadius;\n}\n#endif\n\nvoid main () {\n vec4 o = vec4(1, 1, 1, 1);\n\n #if USE_TEXTURE\n o *= texture(texture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_TEXTURE\n o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #endif\n\n o *= v_color;\n\n ALPHA_TEST(o);\n\n #if ENABLE_ROUNDCORNER\n\n float radius = clamp(0.0, 0.5, roundCornerRadius);\n\n vec2 uv = v_uv0.xy - vec2(0.5, 0.5);\n\n float rx = abs(uv.x) - (0.5 - radius);\n float ry = abs(uv.y) - (0.5 - radius);\n\n float mx = step(0.5 - radius, abs(uv.x));\n float my = step(0.5 - radius, abs(uv.y));\n\n float len = length(vec2(rx, ry));\n\n float a = 1.0 - mx * my * step(radius, len) * smoothstep(0., radius * 0.01, len - radius);\n o = vec4(o.rgb, o.a * a);\n #endif\n gl_FragColor = o;\n}\n"
|
||||
"frag": "\nprecision highp float;\n\n#if USE_ALPHA_TEST\n \n uniform ALPHA_TEST {\n float alphaThreshold;\n }\n#endif\n\nvoid ALPHA_TEST (in vec4 color) {\n #if USE_ALPHA_TEST\n if (color.a < alphaThreshold) discard;\n #endif\n}\n\nvoid ALPHA_TEST (in float alpha) {\n #if USE_ALPHA_TEST\n if (alpha < alphaThreshold) discard;\n #endif\n}\n\nin vec4 v_color;\n\n#if USE_TEXTURE\nin vec2 v_uv0;\nuniform sampler2D texture;\n#endif\n\n#if ENABLE_ROUNDCORNER\nuniform RoundCorner {\n\n float radius;\n}\n#endif\n\nvoid main () {\n vec4 o = vec4(1, 1, 1, 1);\n\n #if USE_TEXTURE\n o *= texture(texture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_TEXTURE\n o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #endif\n\n o *= v_color;\n\n ALPHA_TEST(o);\n\n #if ENABLE_ROUNDCORNER\n\n float circleRadius = clamp(0.0, 0.5, radius);\n\n vec2 uv = v_uv0.xy - vec2(0.5, 0.5);\n\n float rx = abs(uv.x) - (0.5 - circleRadius);\n float ry = abs(uv.y) - (0.5 - circleRadius);\n\n float mx = step(0.5 - circleRadius, abs(uv.x));\n float my = step(0.5 - circleRadius, abs(uv.y));\n\n float len = length(vec2(rx, ry));\n\n float a = 1.0 - mx * my * step(circleRadius, len) * smoothstep(0., circleRadius * 0.01, len - circleRadius);\n o = vec4(o.rgb, o.a * a);\n #endif\n gl_FragColor = o;\n}\n"
|
||||
}
|
||||
}
|
||||
],
|
194
assets/effects/sprite-round-corner-crop-v2.effect
Normal file
194
assets/effects/sprite-round-corner-crop-v2.effect
Normal file
@@ -0,0 +1,194 @@
|
||||
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
//
|
||||
// 圆角裁剪(支持任意宽高纹理)
|
||||
//
|
||||
// 原理:
|
||||
// 1. 正方形纹理的圆角原理参考 https://www.cnblogs.com/jqm304775992/p/4987793.html
|
||||
// 2. 正方形纹理的圆角代码参考 yanjifa/shaderDemor 的 https://github.com/yanjifa/shaderDemo/blob/master/assets/Effect/CircleAvatar.effect
|
||||
// 3. 上述皆为只针对正方形纹理做的操作,如果是长方形的纹理,那么圆角就会有拉伸后的效果,最后变成看起来就不是圆角了,本特效支持任意长方形做圆角
|
||||
|
||||
CCEffect %{
|
||||
techniques:
|
||||
- passes:
|
||||
- vert: vs
|
||||
frag: fs
|
||||
blendState:
|
||||
targets:
|
||||
- blend: true
|
||||
rasterizerState:
|
||||
cullMode: none
|
||||
properties:
|
||||
texture: { value: white }
|
||||
alphaThreshold: { value: 0.5 }
|
||||
|
||||
# 圆角x轴半径长度(相对于纹理宽度)
|
||||
xRadius: {
|
||||
value: 0.4,
|
||||
inspector: {
|
||||
tooltip: "圆角x轴半径长度(相对于纹理宽度)",
|
||||
range: [0.0, 0.5]
|
||||
}
|
||||
}
|
||||
|
||||
# 圆角y轴半径长度(相对于纹理高度)
|
||||
yRadius: {
|
||||
value: 0.4,
|
||||
inspector: {
|
||||
tooltip: "圆角y轴半径长度(相对于纹理高度)",
|
||||
range: [0.0, 0.5]
|
||||
}
|
||||
}
|
||||
}%
|
||||
|
||||
|
||||
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 <alpha-test>
|
||||
|
||||
in vec4 v_color;
|
||||
|
||||
#if USE_TEXTURE
|
||||
in vec2 v_uv0;
|
||||
uniform sampler2D texture;
|
||||
#endif
|
||||
|
||||
#if ENABLE_ROUNDCORNER
|
||||
uniform RoundCorner {
|
||||
// 圆角x轴半径长度(相对于纹理宽度)
|
||||
float xRadius;
|
||||
|
||||
// 圆角y轴半径长度(相对于纹理高度)
|
||||
float yRadius;
|
||||
}
|
||||
#endif
|
||||
|
||||
void main () {
|
||||
vec4 o = vec4(1, 1, 1, 1);
|
||||
|
||||
#if USE_TEXTURE
|
||||
o *= texture(texture, v_uv0);
|
||||
#if CC_USE_ALPHA_ATLAS_TEXTURE
|
||||
o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
o *= v_color;
|
||||
|
||||
ALPHA_TEST(o);
|
||||
|
||||
#if ENABLE_ROUNDCORNER
|
||||
|
||||
// 约束圆角半径范围在 [0.0, 0.5]
|
||||
//
|
||||
// 请注意这里我是用椭圆前缀去命名的半径
|
||||
//
|
||||
// 为什么是椭圆?
|
||||
//
|
||||
// 因为圆角,相对于长方形的纹理的宽高来说,归一化后值并不一样,不是圆,而是一个椭圆
|
||||
//
|
||||
// 比如:
|
||||
//
|
||||
// 纹理是 200 x 100 的像素,圆角半径是20像素,那么归一化后
|
||||
// X轴上的半径就是 20 / 200 = 0.1
|
||||
// Y轴上的半径就是 20 / 100 = 0.2
|
||||
//
|
||||
// 这就会变成是椭圆,而不是圆
|
||||
float ellipseXRadius = clamp(0.0, 0.5, xRadius);
|
||||
float ellipseYRadius = clamp(0.0, 0.5, yRadius);
|
||||
|
||||
// 将纹理uv往左上偏移,实现偏移后的坐标系原点在纹理中心
|
||||
vec2 uv = v_uv0.xy - vec2(0.5, 0.5);
|
||||
|
||||
// uv.x , uv.y : 为偏移后的的uv
|
||||
// abs(uv.x) , abs(uv.y) : 将第二、三、四象限的点都投影到第一象限上,这样子只需要处理第一象限的情况就可以,简化判断
|
||||
// 0.5 - radius : 计算出第一象限的圆角所在圆的圆心坐标
|
||||
// (rx, ry) : 偏移映射后的 新的uv 坐标,相对于 第一象限圆角坐在圆心坐标 的相对坐标
|
||||
float rx = abs(uv.x) - (0.5 - ellipseXRadius);
|
||||
float ry = abs(uv.y) - (0.5 - ellipseYRadius);
|
||||
|
||||
// 区分 以第一象限圆角所在圆心坐标为原点的坐标的四个象限
|
||||
//
|
||||
// 第一象限 mx = 1, my = 1
|
||||
// 第二象限 mx = 0, my = 1
|
||||
// 第三象限 mx = 0, my = 0
|
||||
// 第四象限 mx = 1, my = 0
|
||||
//
|
||||
// 当 mx * my 时,只要等于1,那就是标识第一象限(实际对应圆角区域所在矩形),否则就是第二、三、四象限
|
||||
float mx = step(0.5 - ellipseXRadius, abs(uv.x));
|
||||
float my = step(0.5 - ellipseYRadius, abs(uv.y));
|
||||
|
||||
// 判断点(rx, ry)是否在椭圆外部(应用椭圆公式)
|
||||
float isOutOfEllipse = step(1.0, pow(rx, 2.0) / pow(xRadius, 2.0) + pow(ry, 2.0) / pow(yRadius, 2.0));
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 抗锯齿
|
||||
// 1. 先计算当前点到椭圆中心的角度
|
||||
float angleInRadian = atan(ry / rx);
|
||||
|
||||
// 2. 计算这个角度下,对于对应圆角(椭圆)上的点
|
||||
vec2 pointInEllipse = vec2(xRadius * cos(angleInRadian), yRadius * sin(angleInRadian));
|
||||
|
||||
// 3. 计算这个角度下,比当前圆角大一点椭圆上的点
|
||||
vec2 pointInBigEllipse = vec2((xRadius * 1.01) * cos(angleInRadian), (yRadius * 1.01)* sin(angleInRadian));
|
||||
|
||||
// 4. 计算最远点到当前椭圆的距离
|
||||
float maxDis = distance(pointInBigEllipse, pointInEllipse);
|
||||
|
||||
// 5. 计算当前点到当前椭圆的距离
|
||||
float curDis = distance(vec2(rx, ry), pointInEllipse);
|
||||
|
||||
// 6. 生成插值
|
||||
float smo = smoothstep(0.0, maxDis, curDis);
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// mx * my = 0 时,代表非椭圆角区域,alpha 值为1,代表完全采用原始纹理的透明度
|
||||
// mx * my = 1 时,代表椭圆角所在矩形区域
|
||||
// isOutOfEllipse:
|
||||
// 当点在椭圆外部时,此值为1,导致 alpha 最终值为0.0,即表示不显示椭圆外部的像素
|
||||
// 当点在椭圆内部时,此值为0,导致 alpha 最终值为1.0,即表示显示椭圆内部的像素
|
||||
// smo : 抗锯齿实现
|
||||
// float alpha = 1.0 - mx * my * isOutOfEllipse;
|
||||
float alpha = 1.0 - mx * my * isOutOfEllipse * smo;
|
||||
|
||||
o = vec4(o.rgb, o.a * alpha);
|
||||
|
||||
#endif
|
||||
gl_FragColor = o;
|
||||
}
|
||||
}%
|
17
assets/effects/sprite-round-corner-crop-v2.effect.meta
Normal file
17
assets/effects/sprite-round-corner-crop-v2.effect.meta
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"ver": "1.0.23",
|
||||
"uuid": "7c24b57e-e819-4fc9-a8d2-b06cf61b782d",
|
||||
"compiledShaders": [
|
||||
{
|
||||
"glsl1": {
|
||||
"vert": "\nprecision highp float;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matWorld;\n\nattribute vec3 a_position;\nattribute vec4 a_color;\nvarying vec4 v_color;\n\n#if USE_TEXTURE\nattribute vec2 a_uv0;\nvarying vec2 v_uv0;\n#endif\n\nvoid main () {\n vec4 pos = vec4(a_position, 1);\n\n #if CC_USE_MODEL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n\n #if USE_TEXTURE\n v_uv0 = a_uv0;\n #endif\n\n v_color = a_color;\n\n gl_Position = pos;\n}\n",
|
||||
"frag": "\nprecision highp float;\n\n#if USE_ALPHA_TEST\n \n uniform float alphaThreshold;\n#endif\n\nvoid ALPHA_TEST (in vec4 color) {\n #if USE_ALPHA_TEST\n if (color.a < alphaThreshold) discard;\n #endif\n}\n\nvoid ALPHA_TEST (in float alpha) {\n #if USE_ALPHA_TEST\n if (alpha < alphaThreshold) discard;\n #endif\n}\n\nvarying vec4 v_color;\n\n#if USE_TEXTURE\nvarying vec2 v_uv0;\nuniform sampler2D texture;\n#endif\n\n#if ENABLE_ROUNDCORNER\nuniform float xRadius;\nuniform float yRadius;\n#endif\n\nvoid main () {\n vec4 o = vec4(1, 1, 1, 1);\n\n #if USE_TEXTURE\n o *= texture2D(texture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_TEXTURE\n o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #endif\n\n o *= v_color;\n\n ALPHA_TEST(o);\n\n #if ENABLE_ROUNDCORNER\n\n float ellipseXRadius = clamp(0.0, 0.5, xRadius);\n float ellipseYRadius = clamp(0.0, 0.5, yRadius);\n\n vec2 uv = v_uv0.xy - vec2(0.5, 0.5);\n\n float rx = abs(uv.x) - (0.5 - ellipseXRadius);\n float ry = abs(uv.y) - (0.5 - ellipseYRadius);\n\n float mx = step(0.5 - ellipseXRadius, abs(uv.x));\n float my = step(0.5 - ellipseYRadius, abs(uv.y));\n\n float isOutOfEllipse = step(1.0, pow(rx, 2.0) / pow(xRadius, 2.0) + pow(ry, 2.0) / pow(yRadius, 2.0));\n\n float angleInRadian = atan(ry / rx);\n\n vec2 pointInEllipse = vec2(xRadius * cos(angleInRadian), yRadius * sin(angleInRadian));\n\n vec2 pointInBigEllipse = vec2((xRadius * 1.01) * cos(angleInRadian), (yRadius * 1.01)* sin(angleInRadian));\n\n float maxDis = distance(pointInBigEllipse, pointInEllipse);\n\n float curDis = distance(vec2(rx, ry), pointInEllipse);\n\n float smo = smoothstep(0.0, maxDis, curDis);\n\n float alpha = 1.0 - mx * my * isOutOfEllipse * smo;\n\n o = vec4(o.rgb, o.a * alpha);\n\n #endif\n gl_FragColor = o;\n}\n"
|
||||
},
|
||||
"glsl3": {
|
||||
"vert": "\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time;\n\n vec4 cc_screenSize;\n\n vec4 cc_screenScale;\n\n vec4 cc_nativeSize;\n\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n\n vec4 cc_exposure;\n\n vec4 cc_mainLitDir;\n\n vec4 cc_mainLitColor;\n\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\n\nin vec3 a_position;\nin vec4 a_color;\nout vec4 v_color;\n\n#if USE_TEXTURE\nin vec2 a_uv0;\nout vec2 v_uv0;\n#endif\n\nvoid main () {\n vec4 pos = vec4(a_position, 1);\n\n #if CC_USE_MODEL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n\n #if USE_TEXTURE\n v_uv0 = a_uv0;\n #endif\n\n v_color = a_color;\n\n gl_Position = pos;\n}\n",
|
||||
"frag": "\nprecision highp float;\n\n#if USE_ALPHA_TEST\n \n uniform ALPHA_TEST {\n float alphaThreshold;\n }\n#endif\n\nvoid ALPHA_TEST (in vec4 color) {\n #if USE_ALPHA_TEST\n if (color.a < alphaThreshold) discard;\n #endif\n}\n\nvoid ALPHA_TEST (in float alpha) {\n #if USE_ALPHA_TEST\n if (alpha < alphaThreshold) discard;\n #endif\n}\n\nin vec4 v_color;\n\n#if USE_TEXTURE\nin vec2 v_uv0;\nuniform sampler2D texture;\n#endif\n\n#if ENABLE_ROUNDCORNER\nuniform RoundCorner {\n\n float xRadius;\n\n float yRadius;\n}\n#endif\n\nvoid main () {\n vec4 o = vec4(1, 1, 1, 1);\n\n #if USE_TEXTURE\n o *= texture(texture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_TEXTURE\n o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #endif\n\n o *= v_color;\n\n ALPHA_TEST(o);\n\n #if ENABLE_ROUNDCORNER\n\n float ellipseXRadius = clamp(0.0, 0.5, xRadius);\n float ellipseYRadius = clamp(0.0, 0.5, yRadius);\n\n vec2 uv = v_uv0.xy - vec2(0.5, 0.5);\n\n float rx = abs(uv.x) - (0.5 - ellipseXRadius);\n float ry = abs(uv.y) - (0.5 - ellipseYRadius);\n\n float mx = step(0.5 - ellipseXRadius, abs(uv.x));\n float my = step(0.5 - ellipseYRadius, abs(uv.y));\n\n float isOutOfEllipse = step(1.0, pow(rx, 2.0) / pow(xRadius, 2.0) + pow(ry, 2.0) / pow(yRadius, 2.0));\n\n float angleInRadian = atan(ry / rx);\n\n vec2 pointInEllipse = vec2(xRadius * cos(angleInRadian), yRadius * sin(angleInRadian));\n\n vec2 pointInBigEllipse = vec2((xRadius * 1.01) * cos(angleInRadian), (yRadius * 1.01)* sin(angleInRadian));\n\n float maxDis = distance(pointInBigEllipse, pointInEllipse);\n\n float curDis = distance(vec2(rx, ry), pointInEllipse);\n\n float smo = smoothstep(0.0, maxDis, curDis);\n\n float alpha = 1.0 - mx * my * isOutOfEllipse * smo;\n\n o = vec4(o.rgb, o.a * alpha);\n\n #endif\n gl_FragColor = o;\n}\n"
|
||||
}
|
||||
}
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
14
assets/materials/sprite-gaussian-blur-v1.mtl
Normal file
14
assets/materials/sprite-gaussian-blur-v1.mtl
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"__type__": "cc.Material",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
"_effectAsset": {
|
||||
"__uuid__": "41f4d474-d707-45bb-af93-637573f92d54"
|
||||
},
|
||||
"_defines": {
|
||||
"USE_TEXTURE": true,
|
||||
"ENABLE_GAUSSIAN_BLUR": true
|
||||
},
|
||||
"_props": {}
|
||||
}
|
6
assets/materials/sprite-gaussian-blur-v1.mtl.meta
Normal file
6
assets/materials/sprite-gaussian-blur-v1.mtl.meta
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"ver": "1.0.2",
|
||||
"uuid": "dd3d8f78-9b79-4ca7-9bf7-7a09f7b34108",
|
||||
"dataAsSubAsset": null,
|
||||
"subMetas": {}
|
||||
}
|
@@ -10,7 +10,5 @@
|
||||
"USE_TEXTURE": true,
|
||||
"ENABLE_ROUNDCORNER": true
|
||||
},
|
||||
"_props": {
|
||||
"roundCornerRadius": 0.1
|
||||
}
|
||||
"_props": {}
|
||||
}
|
14
assets/materials/sprite-round-corner-crop-v2.mtl
Normal file
14
assets/materials/sprite-round-corner-crop-v2.mtl
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"__type__": "cc.Material",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
"_effectAsset": {
|
||||
"__uuid__": "7c24b57e-e819-4fc9-a8d2-b06cf61b782d"
|
||||
},
|
||||
"_defines": {
|
||||
"USE_TEXTURE": true,
|
||||
"ENABLE_ROUNDCORNER": true
|
||||
},
|
||||
"_props": {}
|
||||
}
|
6
assets/materials/sprite-round-corner-crop-v2.mtl.meta
Normal file
6
assets/materials/sprite-round-corner-crop-v2.mtl.meta
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"ver": "1.0.2",
|
||||
"uuid": "a86e8864-5390-443f-b41b-b38e9d584c43",
|
||||
"dataAsSubAsset": null,
|
||||
"subMetas": {}
|
||||
}
|
@@ -58,7 +58,7 @@
|
||||
"_groupIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"autoReleaseAssets": false,
|
||||
"_id": "6c351889-b6c8-409f-b36c-4263b06d0b23"
|
||||
"_id": "147d5b9f-b769-4112-9daf-2e28236161fa"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
@@ -171,7 +171,7 @@
|
||||
"array": [
|
||||
0,
|
||||
0,
|
||||
418.2902700278839,
|
||||
491.9024293495612,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
@@ -428,7 +428,7 @@
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "Sliders",
|
||||
"_name": "Controller",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 5
|
||||
@@ -459,7 +459,7 @@
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 576,
|
||||
"height": 60
|
||||
"height": -36
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
@@ -497,7 +497,7 @@
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "RoundCornerRadiusSlider",
|
||||
"_name": "BlurSlider",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 9
|
||||
@@ -513,7 +513,7 @@
|
||||
"__id__": 23
|
||||
}
|
||||
],
|
||||
"_active": true,
|
||||
"_active": false,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 26
|
||||
@@ -646,8 +646,8 @@
|
||||
}
|
||||
],
|
||||
"_useOriginalSize": false,
|
||||
"_string": "圆角半径:",
|
||||
"_N$string": "圆角半径:",
|
||||
"_string": "模糊程度:",
|
||||
"_N$string": "模糊程度:",
|
||||
"_fontSize": 40,
|
||||
"_lineHeight": 40,
|
||||
"_enableWrapText": true,
|
||||
@@ -1294,7 +1294,7 @@
|
||||
"_layoutSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 576,
|
||||
"height": 60
|
||||
"height": -36
|
||||
},
|
||||
"_resize": 1,
|
||||
"_N$layoutType": 2,
|
||||
@@ -1367,7 +1367,7 @@
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 384,
|
||||
"height": 629.73
|
||||
"height": 805.73
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
@@ -1411,7 +1411,7 @@
|
||||
"__id__": 29
|
||||
},
|
||||
"_children": [],
|
||||
"_active": false,
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 31
|
||||
@@ -1475,7 +1475,7 @@
|
||||
"_enabled": true,
|
||||
"_materials": [
|
||||
{
|
||||
"__uuid__": "642c2d0e-7eb6-4d65-96f2-d6e0d0305310"
|
||||
"__uuid__": "dd3d8f78-9b79-4ca7-9bf7-7a09f7b34108"
|
||||
}
|
||||
],
|
||||
"_srcBlendFactor": 770,
|
||||
@@ -1499,7 +1499,7 @@
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "freedom",
|
||||
"_name": "gaussian_blur",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 29
|
||||
@@ -1522,8 +1522,8 @@
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 240,
|
||||
"height": 240
|
||||
"width": 316,
|
||||
"height": 210
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
@@ -1535,7 +1535,7 @@
|
||||
"ctor": "Float64Array",
|
||||
"array": [
|
||||
0,
|
||||
-120,
|
||||
-177,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
@@ -1557,7 +1557,7 @@
|
||||
"_is3DNode": false,
|
||||
"_groupIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": "47hFX2oHFLvrpZ4r0ouXPs"
|
||||
"_id": "0c1gWopWlLwLl+GiSUizBJ"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Sprite",
|
||||
@@ -1569,16 +1569,16 @@
|
||||
"_enabled": true,
|
||||
"_materials": [
|
||||
{
|
||||
"__uuid__": "642c2d0e-7eb6-4d65-96f2-d6e0d0305310"
|
||||
"__uuid__": "dd3d8f78-9b79-4ca7-9bf7-7a09f7b34108"
|
||||
}
|
||||
],
|
||||
"_srcBlendFactor": 770,
|
||||
"_dstBlendFactor": 771,
|
||||
"_spriteFrame": {
|
||||
"__uuid__": "dbc8f785-d78b-4179-bfce-ffbf69396712"
|
||||
"__uuid__": "91f28953-0d5f-4379-9ae6-f3f6afb3241c"
|
||||
},
|
||||
"_type": 0,
|
||||
"_sizeMode": 0,
|
||||
"_sizeMode": 1,
|
||||
"_fillType": 0,
|
||||
"_fillCenter": {
|
||||
"__type__": "cc.Vec2",
|
||||
@@ -1589,7 +1589,7 @@
|
||||
"_fillRange": 0,
|
||||
"_isTrimmedMode": true,
|
||||
"_atlas": null,
|
||||
"_id": "f61+UyKJdOyIJQABsng1SX"
|
||||
"_id": "eckV5v4lpDULdq2uKByFTd"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
@@ -1629,7 +1629,7 @@
|
||||
"ctor": "Float64Array",
|
||||
"array": [
|
||||
0,
|
||||
-387,
|
||||
-429,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
@@ -1663,7 +1663,7 @@
|
||||
"_enabled": true,
|
||||
"_materials": [
|
||||
{
|
||||
"__uuid__": "642c2d0e-7eb6-4d65-96f2-d6e0d0305310"
|
||||
"__uuid__": "dd3d8f78-9b79-4ca7-9bf7-7a09f7b34108"
|
||||
}
|
||||
],
|
||||
"_srcBlendFactor": 770,
|
||||
@@ -1693,7 +1693,7 @@
|
||||
"__id__": 29
|
||||
},
|
||||
"_children": [],
|
||||
"_active": false,
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 37
|
||||
@@ -1723,7 +1723,7 @@
|
||||
"ctor": "Float64Array",
|
||||
"array": [
|
||||
0,
|
||||
-564,
|
||||
-606,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
@@ -1757,7 +1757,7 @@
|
||||
"_enabled": true,
|
||||
"_materials": [
|
||||
{
|
||||
"__uuid__": "642c2d0e-7eb6-4d65-96f2-d6e0d0305310"
|
||||
"__uuid__": "dd3d8f78-9b79-4ca7-9bf7-7a09f7b34108"
|
||||
}
|
||||
],
|
||||
"_srcBlendFactor": 770,
|
||||
@@ -1787,7 +1787,7 @@
|
||||
"__id__": 29
|
||||
},
|
||||
"_children": [],
|
||||
"_active": false,
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 39
|
||||
@@ -1817,7 +1817,7 @@
|
||||
"ctor": "Float64Array",
|
||||
"array": [
|
||||
0,
|
||||
-631,
|
||||
-673,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
@@ -1851,7 +1851,7 @@
|
||||
"_enabled": true,
|
||||
"_materials": [
|
||||
{
|
||||
"__uuid__": "642c2d0e-7eb6-4d65-96f2-d6e0d0305310"
|
||||
"__uuid__": "dd3d8f78-9b79-4ca7-9bf7-7a09f7b34108"
|
||||
}
|
||||
],
|
||||
"_srcBlendFactor": 770,
|
||||
@@ -1911,7 +1911,7 @@
|
||||
"ctor": "Float64Array",
|
||||
"array": [
|
||||
0,
|
||||
-559.2,
|
||||
-735.2,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
@@ -1945,7 +1945,7 @@
|
||||
"_enabled": true,
|
||||
"_materials": [
|
||||
{
|
||||
"__uuid__": "642c2d0e-7eb6-4d65-96f2-d6e0d0305310"
|
||||
"__uuid__": "dd3d8f78-9b79-4ca7-9bf7-7a09f7b34108"
|
||||
}
|
||||
],
|
||||
"_useOriginalSize": false,
|
||||
@@ -2003,7 +2003,7 @@
|
||||
"ctor": "Float64Array",
|
||||
"array": [
|
||||
0,
|
||||
-613.065,
|
||||
-789.065,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
@@ -2037,7 +2037,7 @@
|
||||
"_enabled": true,
|
||||
"_materials": [
|
||||
{
|
||||
"__uuid__": "642c2d0e-7eb6-4d65-96f2-d6e0d0305310"
|
||||
"__uuid__": "dd3d8f78-9b79-4ca7-9bf7-7a09f7b34108"
|
||||
}
|
||||
],
|
||||
"_useOriginalSize": false,
|
||||
@@ -2097,7 +2097,7 @@
|
||||
"_layoutSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 384,
|
||||
"height": 629.73
|
||||
"height": 805.73
|
||||
},
|
||||
"_resize": 1,
|
||||
"_N$layoutType": 2,
|
||||
@@ -2147,13 +2147,13 @@
|
||||
"_id": "4bz2+ak99DBYVlSVIMFGN0"
|
||||
},
|
||||
{
|
||||
"__type__": "d3d2b7nIXNDbKEclKMbIFTC",
|
||||
"__type__": "f460djPUfdEdrpZFw3saPVi",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_enabled": true,
|
||||
"_id": "9ayfD37bZP1IEjPxGKO6+/"
|
||||
"_id": "77Tlx8YKFO6aLFI6G67OJ+"
|
||||
}
|
||||
]
|
7
assets/scenes/GaussianBlurV1EffectScene.fire.meta
Normal file
7
assets/scenes/GaussianBlurV1EffectScene.fire.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"ver": "1.2.5",
|
||||
"uuid": "147d5b9f-b769-4112-9daf-2e28236161fa",
|
||||
"asyncLoadAssets": false,
|
||||
"autoReleaseAssets": false,
|
||||
"subMetas": {}
|
||||
}
|
@@ -78,10 +78,10 @@
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 67
|
||||
"__id__": 81
|
||||
},
|
||||
{
|
||||
"__id__": 68
|
||||
"__id__": 82
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
@@ -245,13 +245,13 @@
|
||||
"__id__": 9
|
||||
},
|
||||
{
|
||||
"__id__": 63
|
||||
"__id__": 77
|
||||
}
|
||||
],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 66
|
||||
"__id__": 80
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
@@ -444,7 +444,7 @@
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 62
|
||||
"__id__": 76
|
||||
},
|
||||
{
|
||||
"__id__": 14
|
||||
@@ -516,10 +516,10 @@
|
||||
"__id__": 13
|
||||
},
|
||||
{
|
||||
"__id__": 60
|
||||
"__id__": 74
|
||||
},
|
||||
{
|
||||
"__id__": 61
|
||||
"__id__": 75
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
@@ -738,15 +738,21 @@
|
||||
},
|
||||
{
|
||||
"__id__": 51
|
||||
},
|
||||
{
|
||||
"__id__": 58
|
||||
},
|
||||
{
|
||||
"__id__": 65
|
||||
}
|
||||
],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 58
|
||||
"__id__": 72
|
||||
},
|
||||
{
|
||||
"__id__": 59
|
||||
"__id__": 73
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
@@ -761,7 +767,7 @@
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 960,
|
||||
"height": 688.8
|
||||
"height": 1025.2
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
@@ -2332,7 +2338,7 @@
|
||||
"_enabled": true,
|
||||
"_materials": [
|
||||
{
|
||||
"__uuid__": "642c2d0e-7eb6-4d65-96f2-d6e0d0305310"
|
||||
"__uuid__": "a86e8864-5390-443f-b41b-b38e9d584c43"
|
||||
}
|
||||
],
|
||||
"_srcBlendFactor": 770,
|
||||
@@ -2705,6 +2711,642 @@
|
||||
"_N$affectedByScale": false,
|
||||
"_id": "87SQn11LJK8LSoPIN0g/TI"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "FlashLight",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 15
|
||||
},
|
||||
"_children": [
|
||||
{
|
||||
"__id__": 59
|
||||
},
|
||||
{
|
||||
"__id__": 62
|
||||
}
|
||||
],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 64
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 260,
|
||||
"height": 320.4
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_trs": {
|
||||
"__type__": "TypedArray",
|
||||
"ctor": "Float64Array",
|
||||
"array": [
|
||||
-334,
|
||||
-849,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
]
|
||||
},
|
||||
"_eulerAngles": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_is3DNode": false,
|
||||
"_groupIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": "e26JcB/cRAdJ9F2/8dC4Ps"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "Desc",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 58
|
||||
},
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 60
|
||||
},
|
||||
{
|
||||
"__id__": 61
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 260,
|
||||
"height": 50.4
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_trs": {
|
||||
"__type__": "TypedArray",
|
||||
"ctor": "Float64Array",
|
||||
"array": [
|
||||
0,
|
||||
135,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
]
|
||||
},
|
||||
"_eulerAngles": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_is3DNode": false,
|
||||
"_groupIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": "0cICJzfMhPC6HKH6XkovKi"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Widget",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 59
|
||||
},
|
||||
"_enabled": true,
|
||||
"alignMode": 1,
|
||||
"_target": null,
|
||||
"_alignFlags": 40,
|
||||
"_left": 0,
|
||||
"_right": 0,
|
||||
"_top": 0,
|
||||
"_bottom": 0,
|
||||
"_verticalCenter": 0,
|
||||
"_horizontalCenter": 0,
|
||||
"_isAbsLeft": true,
|
||||
"_isAbsRight": true,
|
||||
"_isAbsTop": true,
|
||||
"_isAbsBottom": true,
|
||||
"_isAbsHorizontalCenter": true,
|
||||
"_isAbsVerticalCenter": true,
|
||||
"_originalWidth": 120,
|
||||
"_originalHeight": 0,
|
||||
"_id": "06QW1Iw/JJ6JrueKHmlJxn"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Label",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 59
|
||||
},
|
||||
"_enabled": true,
|
||||
"_materials": [
|
||||
{
|
||||
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
|
||||
}
|
||||
],
|
||||
"_useOriginalSize": false,
|
||||
"_string": "扫光",
|
||||
"_N$string": "扫光",
|
||||
"_fontSize": 40,
|
||||
"_lineHeight": 40,
|
||||
"_enableWrapText": true,
|
||||
"_N$file": null,
|
||||
"_isSystemFontUsed": true,
|
||||
"_spacingX": 0,
|
||||
"_batchAsBitmap": false,
|
||||
"_N$horizontalAlign": 1,
|
||||
"_N$verticalAlign": 1,
|
||||
"_N$fontFamily": "Arial",
|
||||
"_N$overflow": 2,
|
||||
"_N$cacheMode": 0,
|
||||
"_id": "39Rl1S5YpMCZBL0hZ4CbrE"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "Sprite",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 58
|
||||
},
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 63
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 195,
|
||||
"height": 270
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_trs": {
|
||||
"__type__": "TypedArray",
|
||||
"ctor": "Float64Array",
|
||||
"array": [
|
||||
0,
|
||||
-25.200000000000003,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
]
|
||||
},
|
||||
"_eulerAngles": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_is3DNode": false,
|
||||
"_groupIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": "0bICBpJO9Cs5B6u5KwtOTP"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Sprite",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 62
|
||||
},
|
||||
"_enabled": true,
|
||||
"_materials": [
|
||||
{
|
||||
"__uuid__": "43a22f18-72fc-4399-b5ae-8305705861f4"
|
||||
}
|
||||
],
|
||||
"_srcBlendFactor": 770,
|
||||
"_dstBlendFactor": 771,
|
||||
"_spriteFrame": {
|
||||
"__uuid__": "31bc895a-c003-4566-a9f3-2e54ae1c17dc"
|
||||
},
|
||||
"_type": 0,
|
||||
"_sizeMode": 1,
|
||||
"_fillType": 0,
|
||||
"_fillCenter": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"_fillStart": 0,
|
||||
"_fillRange": 0,
|
||||
"_isTrimmedMode": true,
|
||||
"_atlas": null,
|
||||
"_id": "8bGDB+EpZMTq52S0HrfFmI"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Layout",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 58
|
||||
},
|
||||
"_enabled": true,
|
||||
"_layoutSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 260,
|
||||
"height": 320.4
|
||||
},
|
||||
"_resize": 1,
|
||||
"_N$layoutType": 2,
|
||||
"_N$padding": 0,
|
||||
"_N$cellSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 40,
|
||||
"height": 40
|
||||
},
|
||||
"_N$startAxis": 0,
|
||||
"_N$paddingLeft": 0,
|
||||
"_N$paddingRight": 0,
|
||||
"_N$paddingTop": 0,
|
||||
"_N$paddingBottom": 0,
|
||||
"_N$spacingX": 0,
|
||||
"_N$spacingY": 0,
|
||||
"_N$verticalDirection": 1,
|
||||
"_N$horizontalDirection": 0,
|
||||
"_N$affectedByScale": false,
|
||||
"_id": "f5ScM1NrdKF6FTjeq/h+Bj"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "GaussianBlur",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 15
|
||||
},
|
||||
"_children": [
|
||||
{
|
||||
"__id__": 66
|
||||
},
|
||||
{
|
||||
"__id__": 69
|
||||
}
|
||||
],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 71
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 260,
|
||||
"height": 320.4
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_trs": {
|
||||
"__type__": "TypedArray",
|
||||
"ctor": "Float64Array",
|
||||
"array": [
|
||||
-58,
|
||||
-849,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
]
|
||||
},
|
||||
"_eulerAngles": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_is3DNode": false,
|
||||
"_groupIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": "c7EbMAcO1CPYSl8IFqizWb"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "Desc",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 65
|
||||
},
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 67
|
||||
},
|
||||
{
|
||||
"__id__": 68
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 260,
|
||||
"height": 50.4
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_trs": {
|
||||
"__type__": "TypedArray",
|
||||
"ctor": "Float64Array",
|
||||
"array": [
|
||||
0,
|
||||
135,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
]
|
||||
},
|
||||
"_eulerAngles": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_is3DNode": false,
|
||||
"_groupIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": "acSrkkDmpAFYh9NiU/laBt"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Widget",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 66
|
||||
},
|
||||
"_enabled": true,
|
||||
"alignMode": 1,
|
||||
"_target": null,
|
||||
"_alignFlags": 40,
|
||||
"_left": 0,
|
||||
"_right": 0,
|
||||
"_top": 0,
|
||||
"_bottom": 0,
|
||||
"_verticalCenter": 0,
|
||||
"_horizontalCenter": 0,
|
||||
"_isAbsLeft": true,
|
||||
"_isAbsRight": true,
|
||||
"_isAbsTop": true,
|
||||
"_isAbsBottom": true,
|
||||
"_isAbsHorizontalCenter": true,
|
||||
"_isAbsVerticalCenter": true,
|
||||
"_originalWidth": 120,
|
||||
"_originalHeight": 0,
|
||||
"_id": "cc6PQ3Og9EK7pwLA+Qvgnc"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Label",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 66
|
||||
},
|
||||
"_enabled": true,
|
||||
"_materials": [
|
||||
{
|
||||
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
|
||||
}
|
||||
],
|
||||
"_useOriginalSize": false,
|
||||
"_string": "高斯模糊",
|
||||
"_N$string": "高斯模糊",
|
||||
"_fontSize": 40,
|
||||
"_lineHeight": 40,
|
||||
"_enableWrapText": true,
|
||||
"_N$file": null,
|
||||
"_isSystemFontUsed": true,
|
||||
"_spacingX": 0,
|
||||
"_batchAsBitmap": false,
|
||||
"_N$horizontalAlign": 1,
|
||||
"_N$verticalAlign": 1,
|
||||
"_N$fontFamily": "Arial",
|
||||
"_N$overflow": 2,
|
||||
"_N$cacheMode": 0,
|
||||
"_id": "b90QlEd+9GhIDA3c7EnSyG"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "Sprite",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 65
|
||||
},
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 70
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 195,
|
||||
"height": 270
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_trs": {
|
||||
"__type__": "TypedArray",
|
||||
"ctor": "Float64Array",
|
||||
"array": [
|
||||
0,
|
||||
-25.200000000000003,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
]
|
||||
},
|
||||
"_eulerAngles": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_is3DNode": false,
|
||||
"_groupIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": "a7siexXvFC+ZekYQX2vUad"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Sprite",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 69
|
||||
},
|
||||
"_enabled": true,
|
||||
"_materials": [
|
||||
{
|
||||
"__uuid__": "dd3d8f78-9b79-4ca7-9bf7-7a09f7b34108"
|
||||
}
|
||||
],
|
||||
"_srcBlendFactor": 770,
|
||||
"_dstBlendFactor": 771,
|
||||
"_spriteFrame": {
|
||||
"__uuid__": "31bc895a-c003-4566-a9f3-2e54ae1c17dc"
|
||||
},
|
||||
"_type": 0,
|
||||
"_sizeMode": 1,
|
||||
"_fillType": 0,
|
||||
"_fillCenter": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"_fillStart": 0,
|
||||
"_fillRange": 0,
|
||||
"_isTrimmedMode": true,
|
||||
"_atlas": null,
|
||||
"_id": "3fCXDRFtVMFqH5CPA6AJug"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Layout",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 65
|
||||
},
|
||||
"_enabled": true,
|
||||
"_layoutSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 260,
|
||||
"height": 320.4
|
||||
},
|
||||
"_resize": 1,
|
||||
"_N$layoutType": 2,
|
||||
"_N$padding": 0,
|
||||
"_N$cellSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 40,
|
||||
"height": 40
|
||||
},
|
||||
"_N$startAxis": 0,
|
||||
"_N$paddingLeft": 0,
|
||||
"_N$paddingRight": 0,
|
||||
"_N$paddingTop": 0,
|
||||
"_N$paddingBottom": 0,
|
||||
"_N$spacingX": 0,
|
||||
"_N$spacingY": 0,
|
||||
"_N$verticalDirection": 1,
|
||||
"_N$horizontalDirection": 0,
|
||||
"_N$affectedByScale": false,
|
||||
"_id": "fd8A1grOlMH4IDJnmVok0F"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Widget",
|
||||
"_name": "",
|
||||
@@ -2743,7 +3385,7 @@
|
||||
"_layoutSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 960,
|
||||
"height": 688.8
|
||||
"height": 1025.2
|
||||
},
|
||||
"_resize": 1,
|
||||
"_N$layoutType": 3,
|
||||
@@ -2862,10 +3504,10 @@
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 64
|
||||
"__id__": 78
|
||||
},
|
||||
{
|
||||
"__id__": 65
|
||||
"__id__": 79
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
@@ -2921,7 +3563,7 @@
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 63
|
||||
"__id__": 77
|
||||
},
|
||||
"_enabled": true,
|
||||
"_materials": [
|
||||
@@ -2951,7 +3593,7 @@
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 63
|
||||
"__id__": 77
|
||||
},
|
||||
"_enabled": true,
|
||||
"alignMode": 1,
|
||||
|
1773
assets/scenes/RoundCornerCropV1EffectScene.fire
Executable file
1773
assets/scenes/RoundCornerCropV1EffectScene.fire
Executable file
File diff suppressed because it is too large
Load Diff
1773
assets/scenes/RoundCornerCropV2EffectScene.fire
Executable file
1773
assets/scenes/RoundCornerCropV2EffectScene.fire
Executable file
File diff suppressed because it is too large
Load Diff
7
assets/scenes/RoundCornerCropV2EffectScene.fire.meta
Normal file
7
assets/scenes/RoundCornerCropV2EffectScene.fire.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"ver": "1.2.5",
|
||||
"uuid": "c2dec4ed-8129-40a2-9a1e-2440da772015",
|
||||
"asyncLoadAssets": false,
|
||||
"autoReleaseAssets": false,
|
||||
"subMetas": {}
|
||||
}
|
54
assets/scripts/GaussianBlurV1EffectScene.ts
Normal file
54
assets/scripts/GaussianBlurV1EffectScene.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
const { ccclass, property } = cc._decorator;
|
||||
|
||||
@ccclass
|
||||
export default class GaussianBlurV1EffectScene extends cc.Component {
|
||||
private _blurSlider: cc.Slider = null;
|
||||
private _blurSliderLabel: cc.Label = null;
|
||||
|
||||
private _examplesParentNode: cc.Node = null;
|
||||
|
||||
onLoad() {
|
||||
cc.dynamicAtlasManager.enabled = false;
|
||||
|
||||
this._blurSlider = cc.find("Canvas/Content/Controller/BlurSlider/Slider").getComponent(cc.Slider);
|
||||
this._blurSliderLabel = cc.find("Canvas/Content/Controller/BlurSlider/ValueLabel").getComponent(cc.Label);
|
||||
|
||||
this._examplesParentNode = cc.find("Canvas/Content/Examples");
|
||||
}
|
||||
|
||||
onEnable() {
|
||||
this._blurSlider.node.on("slide", this._onSliderChanged, this);
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
this._blurSlider.node.off("slide", this._onSliderChanged, this);
|
||||
}
|
||||
|
||||
start() {
|
||||
this._onSliderChanged();
|
||||
}
|
||||
|
||||
private _onSliderChanged() {
|
||||
this._blurSliderLabel.string = `${this._blurSlider.progress.toFixed(2)}`;
|
||||
|
||||
// 更新材质
|
||||
this._updateRenderComponentMaterial({});
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新渲染组件的材质
|
||||
*
|
||||
* 1. 获取材质
|
||||
* 2. 给材质的 unitform 变量赋值
|
||||
* 3. 重新将材质赋值回去
|
||||
*/
|
||||
private _updateRenderComponentMaterial(param: {}) {
|
||||
this._examplesParentNode.children.forEach(childNode => {
|
||||
childNode.getComponents(cc.RenderComponent).forEach(renderComponent => {
|
||||
let material: cc.Material = renderComponent.getMaterial(0);
|
||||
material.setProperty("textureSize", cc.v2(childNode.width, childNode.height));
|
||||
renderComponent.setMaterial(0, material);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "d3d2bee7-2173-436c-a11c-94a31b2054c2",
|
||||
"uuid": "f460d8cf-51f7-4476-ba59-170dec68f562",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
@@ -1,9 +1,9 @@
|
||||
const { ccclass, property } = cc._decorator;
|
||||
|
||||
@ccclass
|
||||
export default class RoundCornerCropEffectScene extends cc.Component {
|
||||
private _roundCornerRadiuSlider: cc.Slider = null;
|
||||
private _roundCornerRadiuLabel: cc.Label = null;
|
||||
export default class RoundCornerCropV1EffectScene extends cc.Component {
|
||||
private _radiuSlider: cc.Slider = null;
|
||||
private _radiuLabel: cc.Label = null;
|
||||
|
||||
private _examplesParentNode: cc.Node = null;
|
||||
|
||||
@@ -11,18 +11,18 @@ export default class RoundCornerCropEffectScene extends cc.Component {
|
||||
// 关闭动态合图
|
||||
cc.dynamicAtlasManager.enabled = false;
|
||||
|
||||
this._roundCornerRadiuSlider = cc.find("Canvas/Content/Sliders/RoundCornerRadiusSlider/Slider").getComponent(cc.Slider);
|
||||
this._roundCornerRadiuLabel = cc.find("Canvas/Content/Sliders/RoundCornerRadiusSlider/ValueLabel").getComponent(cc.Label);
|
||||
this._radiuSlider = cc.find("Canvas/Content/Controller/RadiusSlider/Slider").getComponent(cc.Slider);
|
||||
this._radiuLabel = cc.find("Canvas/Content/Controller/RadiusSlider/ValueLabel").getComponent(cc.Label);
|
||||
|
||||
this._examplesParentNode = cc.find("Canvas/Content/Examples");
|
||||
}
|
||||
|
||||
onEnable() {
|
||||
this._roundCornerRadiuSlider.node.on("slide", this._onSliderChanged, this);
|
||||
this._radiuSlider.node.on("slide", this._onSliderChanged, this);
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
this._roundCornerRadiuSlider.node.off("slide", this._onSliderChanged, this);
|
||||
this._radiuSlider.node.off("slide", this._onSliderChanged, this);
|
||||
}
|
||||
|
||||
start() {
|
||||
@@ -30,11 +30,11 @@ export default class RoundCornerCropEffectScene extends cc.Component {
|
||||
}
|
||||
|
||||
private _onSliderChanged() {
|
||||
this._roundCornerRadiuLabel.string = `${this._roundCornerRadiuSlider.progress.toFixed(2)}`;
|
||||
this._radiuLabel.string = `${this._radiuSlider.progress.toFixed(2)}`;
|
||||
|
||||
// 更新材质
|
||||
this._updateRenderComponentMaterial({
|
||||
roundCornerRadius: this._roundCornerRadiuSlider.progress
|
||||
radius: this._radiuSlider.progress
|
||||
});
|
||||
}
|
||||
|
||||
@@ -49,12 +49,12 @@ export default class RoundCornerCropEffectScene extends cc.Component {
|
||||
/**
|
||||
* 圆角半径 [0.0, 0.5] ,0.5 表示圆形裁剪
|
||||
*/
|
||||
roundCornerRadius: number;
|
||||
radius: number;
|
||||
}) {
|
||||
this._examplesParentNode.children.forEach(childNode => {
|
||||
childNode.getComponents(cc.RenderComponent).forEach(renderComponent => {
|
||||
let material: cc.Material = renderComponent.getMaterial(0);
|
||||
material.setProperty("roundCornerRadius", param.roundCornerRadius);
|
||||
material.setProperty("radius", param.radius);
|
||||
renderComponent.setMaterial(0, material);
|
||||
});
|
||||
});
|
9
assets/scripts/RoundCornerCropV1EffectScene.ts.meta
Normal file
9
assets/scripts/RoundCornerCropV1EffectScene.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "d27658c5-a966-4e50-a162-09c7af01579e",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
80
assets/scripts/RoundCornerCropV2EffectScene.ts
Normal file
80
assets/scripts/RoundCornerCropV2EffectScene.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
const { ccclass, property } = cc._decorator;
|
||||
|
||||
@ccclass
|
||||
export default class RoundCornerCropV2EffectScene extends cc.Component {
|
||||
private _radiuSlider: cc.Slider = null;
|
||||
private _radiuLabel: cc.Label = null;
|
||||
|
||||
private _examplesParentNode: cc.Node = null;
|
||||
|
||||
onLoad() {
|
||||
// 关闭动态合图
|
||||
cc.dynamicAtlasManager.enabled = false;
|
||||
|
||||
this._radiuSlider = cc.find("Canvas/Content/Controller/RadiusSlider/Slider").getComponent(cc.Slider);
|
||||
this._radiuLabel = cc.find("Canvas/Content/Controller/RadiusSlider/ValueLabel").getComponent(cc.Label);
|
||||
|
||||
this._examplesParentNode = cc.find("Canvas/Content/Examples");
|
||||
}
|
||||
|
||||
onEnable() {
|
||||
this._radiuSlider.node.on("slide", this._onSliderChanged, this);
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
this._radiuSlider.node.off("slide", this._onSliderChanged, this);
|
||||
}
|
||||
|
||||
start() {
|
||||
this._onSliderChanged();
|
||||
}
|
||||
|
||||
private _onSliderChanged() {
|
||||
// 计算半径px
|
||||
let radiusInPx = Math.floor(100 * this._radiuSlider.progress);
|
||||
this._radiuLabel.string = radiusInPx + "";
|
||||
|
||||
// 更新材质
|
||||
this._updateRenderComponentMaterial({
|
||||
radiusInPx: radiusInPx
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新渲染组件的材质
|
||||
*
|
||||
* 1. 获取材质
|
||||
* 2. 给材质的 unitform 变量赋值
|
||||
* 3. 重新将材质赋值回去
|
||||
*/
|
||||
private _updateRenderComponentMaterial(param: {
|
||||
/**
|
||||
* 圆角半径px
|
||||
*/
|
||||
radiusInPx: number;
|
||||
}) {
|
||||
this._examplesParentNode.children.forEach(childNode => {
|
||||
childNode.getComponents(cc.RenderComponent).forEach(renderComponent => {
|
||||
// 计算半径px分别相对于纹理宽高的比例(也叫归一化)
|
||||
let xRadiux = param.radiusInPx / childNode.width;
|
||||
// 约束范围在区间 [0.0, 0.5]
|
||||
xRadiux = xRadiux >= 0.5 ? 0.5 : xRadiux;
|
||||
|
||||
let yRadius = param.radiusInPx / childNode.height;
|
||||
yRadius = yRadius >= 0.5 ? 0.5 : yRadius;
|
||||
|
||||
if (childNode.name === "Rectangle1") cc.log(`${childNode.name} : (${xRadiux}, ${yRadius})`);
|
||||
|
||||
// 更新材质
|
||||
let material: cc.Material = renderComponent.getMaterial(0);
|
||||
|
||||
// 圆角x轴半径长度(相对于纹理宽度)[0.0, 0.5]
|
||||
material.setProperty("xRadius", xRadiux);
|
||||
|
||||
// 圆角y轴半径长度(相对于纹理高度)[0.0, 0.5]
|
||||
material.setProperty("yRadius", yRadius);
|
||||
renderComponent.setMaterial(0, material);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
9
assets/scripts/RoundCornerCropV2EffectScene.ts.meta
Normal file
9
assets/scripts/RoundCornerCropV2EffectScene.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "24bbe7ba-5d1e-42d9-b2dd-f219fef90367",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
BIN
assets/textures/gaussian_blur.png
Normal file
BIN
assets/textures/gaussian_blur.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 130 KiB |
34
assets/textures/gaussian_blur.png.meta
Normal file
34
assets/textures/gaussian_blur.png.meta
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"ver": "2.3.3",
|
||||
"uuid": "c879710d-0419-46be-bf96-92ee1ca52324",
|
||||
"type": "sprite",
|
||||
"wrapMode": "clamp",
|
||||
"filterMode": "bilinear",
|
||||
"premultiplyAlpha": false,
|
||||
"genMipmaps": false,
|
||||
"packable": true,
|
||||
"platformSettings": {},
|
||||
"subMetas": {
|
||||
"gaussian_blur": {
|
||||
"ver": "1.0.4",
|
||||
"uuid": "91f28953-0d5f-4379-9ae6-f3f6afb3241c",
|
||||
"rawTextureUuid": "c879710d-0419-46be-bf96-92ee1ca52324",
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 0,
|
||||
"trimY": 0,
|
||||
"width": 317,
|
||||
"height": 178,
|
||||
"rawWidth": 317,
|
||||
"rawHeight": 178,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"subMetas": {}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"engine": "cocos2d-html5",
|
||||
"packages": "packages",
|
||||
"version": "2.2.1",
|
||||
"version": "2.2.2",
|
||||
"id": "7e74e9ed-5c28-4e81-ae0e-5a67f548022c"
|
||||
}
|
BIN
static/effects/2d-sprite-gaussian-blur-v1.png
Normal file
BIN
static/effects/2d-sprite-gaussian-blur-v1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 225 KiB |
BIN
static/effects/2d-sprite-round-corner-crop-v1.gif
Normal file
BIN
static/effects/2d-sprite-round-corner-crop-v1.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 323 KiB |
BIN
static/effects/2d-sprite-round-corner-crop-v2.gif
Normal file
BIN
static/effects/2d-sprite-round-corner-crop-v2.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 434 KiB |
Binary file not shown.
Before Width: | Height: | Size: 267 KiB |
Reference in New Issue
Block a user