完善外发光

This commit is contained in:
caizhitao 2019-12-25 18:51:43 +08:00
parent af35b03f72
commit 7e147d61f6
4 changed files with 75 additions and 154 deletions

View File

@ -50,11 +50,13 @@ CCProgram vs %{
#include <cc-global> #include <cc-global>
#include <cc-local> #include <cc-local>
// a_position 是笛卡尔坐标右手系也是OpenGL的坐标系原点在左下角X轴正方向往右Y轴正方向往上Z轴正方向往外
in vec3 a_position; in vec3 a_position;
in vec4 a_color; in vec4 a_color;
out vec4 v_color; out vec4 v_color;
#if USE_TEXTURE #if USE_TEXTURE
// a_uv0 是标准屏幕坐标系即原点在左上角X轴正方向往右Y轴正方向往下
in vec2 a_uv0; in vec2 a_uv0;
out vec2 v_uv0; out vec2 v_uv0;
#endif #endif
@ -70,10 +72,32 @@ CCProgram vs %{
#if USE_TEXTURE #if USE_TEXTURE
v_uv0 = a_uv0; v_uv0 = a_uv0;
// // 左移
// v_uv0 = a_uv0 + vec2(0.1, 0.0);
// // 右移
// v_uv0 = a_uv0 + vec2(-0.1, 0.0);
// // 上移
// v_uv0 = a_uv0 + vec2(0.0, 0.1);
// // 下移
// v_uv0 = a_uv0 + vec2(0.0, -0.1);
// // x轴拉伸
// v_uv0 = a_uv0 * vec2(0.5, 1.0);
// // x轴压缩
// v_uv0 = a_uv0 * vec2(2.0, 1.0);
// // y轴拉伸
// v_uv0 = a_uv0 * vec2(1.0, 0.5);
// // y轴压缩
// v_uv0 = a_uv0 * vec2(1.0, 2.0);
// v_uv0 = clamp(a_uv0 + vec2(0.5, 0.0), vec2(0.0, 0.0), vec2(1.0, 1.0));
// v_uv0 = a_uv0 * vec2(2.0, 2.0) + vec2(-0.5, -0.5);
#endif #endif
v_color = a_color; v_color = a_color;
// pos *= vec4(2.0, 2.0, 1.0, 1.0);
gl_Position = pos; gl_Position = pos;
} }
}% }%
@ -91,6 +115,18 @@ CCProgram fs %{
uniform sampler2D texture; uniform sampler2D texture;
#endif #endif
/**
* 获取纹理uv颜色
*
* 超出边界的统一返回 vec4(0.0, 0.0, 0.0, 0.0)
*/
vec4 getTexture(sampler2D texture, vec2 v_uv0) {
if (v_uv0.x > 1.0 || v_uv0.x < 0.0 || v_uv0.y > 1.0 || v_uv0.y < 0.0) {
return vec4(0.0, 0.0, 0.0, 0.0);
}
return texture(texture, v_uv0);
}
#if SHOW_OUTTER_GLOW #if SHOW_OUTTER_GLOW
uniform glow { uniform glow {
@ -103,6 +139,7 @@ CCProgram fs %{
// 特别地,必须是 vec4 先于 float 声明 // 特别地,必须是 vec4 先于 float 声明
}; };
/** /**
* 获取指定角度方向距离为xxx的像素的透明度 * 获取指定角度方向距离为xxx的像素的透明度
* *
@ -114,7 +151,7 @@ CCProgram fs %{
float getColorAlpha(float angle, float dist) { float getColorAlpha(float angle, float dist) {
// 角度转弧度,公式为:弧度 = 角度 * (pi / 180) // 角度转弧度,公式为:弧度 = 角度 * (pi / 180)
float radian = angle * 0.01745329252; // 这个浮点数是 pi / 180 float radian = angle * 0.01745329252; // 这个浮点数是 pi / 180
vec4 color = texture(texture, v_uv0 + vec2(dist * cos(radian), dist * sin(radian))); vec4 color = getTexture(texture, v_uv0 + vec2(dist * cos(radian), dist * sin(radian)));
return color.a; return color.a;
} }
@ -192,7 +229,7 @@ CCProgram fs %{
vec4 o = vec4(1, 1, 1, 1); vec4 o = vec4(1, 1, 1, 1);
#if USE_TEXTURE #if USE_TEXTURE
o *= texture(texture, v_uv0); o *= getTexture(texture, v_uv0);
#if CC_USE_ALPHA_ATLAS_TEXTURE #if CC_USE_ALPHA_ATLAS_TEXTURE
o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r; o.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;
#endif #endif

View File

@ -4,12 +4,12 @@
"compiledShaders": [ "compiledShaders": [
{ {
"glsl1": { "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", "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\n\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\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 SHOW_OUTTER_GLOW\n\nuniform vec4 glowColor;\nuniform float glowColorSize;\nuniform float glowThreshold;\n\n/**\n * 获取指定角度方向距离为xxx的像素的透明度\n *\n * @param angle 角度 [0.0, 360.0]\n * @param dist 距离 [0.0, 1.0]\n *\n * @return alpha [0.0, 1.0]\n */\nfloat getColorAlpha(float angle, float dist) {\n\n float radian = angle * 0.01745329252;\n\n vec4 color = texture2D(texture, v_uv0 + vec2(dist * cos(radian), dist * sin(radian))); \n return color.a;\n}\n\n/**\n * 获取指定距离的周边像素的透明度平均值\n *\n * @param dist 距离 [0.0, 1.0]\n *\n * @return average alpha [0.0, 1.0]\n */\nfloat getAverageAlpha(float dist) {\n float totalAlpha = 0.0;\n\n totalAlpha += getColorAlpha(0.0, dist);\n totalAlpha += getColorAlpha(30.0, dist);\n totalAlpha += getColorAlpha(60.0, dist);\n totalAlpha += getColorAlpha(90.0, dist);\n totalAlpha += getColorAlpha(120.0, dist);\n totalAlpha += getColorAlpha(150.0, dist);\n totalAlpha += getColorAlpha(180.0, dist);\n totalAlpha += getColorAlpha(210.0, dist);\n totalAlpha += getColorAlpha(240.0, dist);\n totalAlpha += getColorAlpha(270.0, dist);\n totalAlpha += getColorAlpha(300.0, dist);\n totalAlpha += getColorAlpha(330.0, dist);\n return totalAlpha * 0.0833;\n\n}\n\n/**\n * 获取发光的透明度\n */\nfloat getGlowAlpha() {\n\n if (glowColorSize == 0.0) {\n return 0.0;\n }\n\n float totalAlpha = 0.0;\n totalAlpha += getAverageAlpha(glowColorSize * 0.1);\n totalAlpha += getAverageAlpha(glowColorSize * 0.2);\n totalAlpha += getAverageAlpha(glowColorSize * 0.3);\n totalAlpha += getAverageAlpha(glowColorSize * 0.4);\n totalAlpha += getAverageAlpha(glowColorSize * 0.5);\n totalAlpha += getAverageAlpha(glowColorSize * 0.6);\n totalAlpha += getAverageAlpha(glowColorSize * 0.7);\n totalAlpha += getAverageAlpha(glowColorSize * 0.8);\n totalAlpha += getAverageAlpha(glowColorSize * 0.9);\n totalAlpha += getAverageAlpha(glowColorSize * 1.0);\n return totalAlpha * 0.1;\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\n #if SHOW_OUTTER_GLOW\n\n float alpha = getGlowAlpha();\n\n if (alpha <= glowThreshold) {\n\n alpha = alpha / glowThreshold;\n\n alpha = -1.0 * (alpha - 1.0) * (alpha - 1.0) * (alpha - 1.0) * (alpha - 1.0) + 1.0;\n } else {\n\n alpha = 0.0;\n }\n\n vec4 color_dest = glowColor * alpha;\n vec4 color_src = o;\n\n gl_FragColor = color_src * color_src.a + color_dest * (1.0 - color_src.a);\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/**\n * 获取纹理uv颜色 \n *\n * 超出边界的统一返回 vec4(0.0, 0.0, 0.0, 0.0)\n */\nvec4 getTexture(sampler2D texture, vec2 v_uv0) {\n if (v_uv0.x > 1.0 || v_uv0.x < 0.0 || v_uv0.y > 1.0 || v_uv0.y < 0.0) {\n return vec4(0.0, 0.0, 0.0, 0.0);\n }\n return texture2D(texture, v_uv0);\n}\n\n#if SHOW_OUTTER_GLOW\n\nuniform vec4 glowColor;\nuniform float glowColorSize;\nuniform float glowThreshold;\n\n/**\n * 获取指定角度方向距离为xxx的像素的透明度\n *\n * @param angle 角度 [0.0, 360.0]\n * @param dist 距离 [0.0, 1.0]\n *\n * @return alpha [0.0, 1.0]\n */\nfloat getColorAlpha(float angle, float dist) {\n\n float radian = angle * 0.01745329252;\n\n vec4 color = getTexture(texture, v_uv0 + vec2(dist * cos(radian), dist * sin(radian))); \n return color.a;\n}\n\n/**\n * 获取指定距离的周边像素的透明度平均值\n *\n * @param dist 距离 [0.0, 1.0]\n *\n * @return average alpha [0.0, 1.0]\n */\nfloat getAverageAlpha(float dist) {\n float totalAlpha = 0.0;\n\n totalAlpha += getColorAlpha(0.0, dist);\n totalAlpha += getColorAlpha(30.0, dist);\n totalAlpha += getColorAlpha(60.0, dist);\n totalAlpha += getColorAlpha(90.0, dist);\n totalAlpha += getColorAlpha(120.0, dist);\n totalAlpha += getColorAlpha(150.0, dist);\n totalAlpha += getColorAlpha(180.0, dist);\n totalAlpha += getColorAlpha(210.0, dist);\n totalAlpha += getColorAlpha(240.0, dist);\n totalAlpha += getColorAlpha(270.0, dist);\n totalAlpha += getColorAlpha(300.0, dist);\n totalAlpha += getColorAlpha(330.0, dist);\n return totalAlpha * 0.0833;\n\n}\n\n/**\n * 获取发光的透明度\n */\nfloat getGlowAlpha() {\n\n if (glowColorSize == 0.0) {\n return 0.0;\n }\n\n float totalAlpha = 0.0;\n totalAlpha += getAverageAlpha(glowColorSize * 0.1);\n totalAlpha += getAverageAlpha(glowColorSize * 0.2);\n totalAlpha += getAverageAlpha(glowColorSize * 0.3);\n totalAlpha += getAverageAlpha(glowColorSize * 0.4);\n totalAlpha += getAverageAlpha(glowColorSize * 0.5);\n totalAlpha += getAverageAlpha(glowColorSize * 0.6);\n totalAlpha += getAverageAlpha(glowColorSize * 0.7);\n totalAlpha += getAverageAlpha(glowColorSize * 0.8);\n totalAlpha += getAverageAlpha(glowColorSize * 0.9);\n totalAlpha += getAverageAlpha(glowColorSize * 1.0);\n return totalAlpha * 0.1;\n}\n\n#endif\n\nvoid main () {\n vec4 o = vec4(1, 1, 1, 1);\n\n #if USE_TEXTURE\n o *= getTexture(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 SHOW_OUTTER_GLOW\n\n float alpha = getGlowAlpha();\n\n if (alpha <= glowThreshold) {\n\n alpha = alpha / glowThreshold;\n\n alpha = -1.0 * (alpha - 1.0) * (alpha - 1.0) * (alpha - 1.0) * (alpha - 1.0) + 1.0;\n } else {\n\n alpha = 0.0;\n }\n\n vec4 color_dest = glowColor * alpha;\n vec4 color_src = o;\n\n gl_FragColor = color_src * color_src.a + color_dest * (1.0 - color_src.a);\n #endif\n}\n"
}, },
"glsl3": { "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", "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\n\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\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 SHOW_OUTTER_GLOW\n\nuniform glow {\n\n vec4 glowColor;\n\n float glowColorSize;\n\n float glowThreshold;\n\n};\n\n/**\n * 获取指定角度方向距离为xxx的像素的透明度\n *\n * @param angle 角度 [0.0, 360.0]\n * @param dist 距离 [0.0, 1.0]\n *\n * @return alpha [0.0, 1.0]\n */\nfloat getColorAlpha(float angle, float dist) {\n\n float radian = angle * 0.01745329252;\n\n vec4 color = texture(texture, v_uv0 + vec2(dist * cos(radian), dist * sin(radian))); \n return color.a;\n}\n\n/**\n * 获取指定距离的周边像素的透明度平均值\n *\n * @param dist 距离 [0.0, 1.0]\n *\n * @return average alpha [0.0, 1.0]\n */\nfloat getAverageAlpha(float dist) {\n float totalAlpha = 0.0;\n\n totalAlpha += getColorAlpha(0.0, dist);\n totalAlpha += getColorAlpha(30.0, dist);\n totalAlpha += getColorAlpha(60.0, dist);\n totalAlpha += getColorAlpha(90.0, dist);\n totalAlpha += getColorAlpha(120.0, dist);\n totalAlpha += getColorAlpha(150.0, dist);\n totalAlpha += getColorAlpha(180.0, dist);\n totalAlpha += getColorAlpha(210.0, dist);\n totalAlpha += getColorAlpha(240.0, dist);\n totalAlpha += getColorAlpha(270.0, dist);\n totalAlpha += getColorAlpha(300.0, dist);\n totalAlpha += getColorAlpha(330.0, dist);\n return totalAlpha * 0.0833;\n\n}\n\n/**\n * 获取发光的透明度\n */\nfloat getGlowAlpha() {\n\n if (glowColorSize == 0.0) {\n return 0.0;\n }\n\n float totalAlpha = 0.0;\n totalAlpha += getAverageAlpha(glowColorSize * 0.1);\n totalAlpha += getAverageAlpha(glowColorSize * 0.2);\n totalAlpha += getAverageAlpha(glowColorSize * 0.3);\n totalAlpha += getAverageAlpha(glowColorSize * 0.4);\n totalAlpha += getAverageAlpha(glowColorSize * 0.5);\n totalAlpha += getAverageAlpha(glowColorSize * 0.6);\n totalAlpha += getAverageAlpha(glowColorSize * 0.7);\n totalAlpha += getAverageAlpha(glowColorSize * 0.8);\n totalAlpha += getAverageAlpha(glowColorSize * 0.9);\n totalAlpha += getAverageAlpha(glowColorSize * 1.0);\n return totalAlpha * 0.1;\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\n #if SHOW_OUTTER_GLOW\n\n float alpha = getGlowAlpha();\n\n if (alpha <= glowThreshold) {\n\n alpha = alpha / glowThreshold;\n\n alpha = -1.0 * (alpha - 1.0) * (alpha - 1.0) * (alpha - 1.0) * (alpha - 1.0) + 1.0;\n } else {\n\n alpha = 0.0;\n }\n\n vec4 color_dest = glowColor * alpha;\n vec4 color_src = o;\n\n gl_FragColor = color_src * color_src.a + color_dest * (1.0 - color_src.a);\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/**\n * 获取纹理uv颜色 \n *\n * 超出边界的统一返回 vec4(0.0, 0.0, 0.0, 0.0)\n */\nvec4 getTexture(sampler2D texture, vec2 v_uv0) {\n if (v_uv0.x > 1.0 || v_uv0.x < 0.0 || v_uv0.y > 1.0 || v_uv0.y < 0.0) {\n return vec4(0.0, 0.0, 0.0, 0.0);\n }\n return texture(texture, v_uv0);\n}\n\n#if SHOW_OUTTER_GLOW\n\nuniform glow {\n\n vec4 glowColor;\n\n float glowColorSize;\n\n float glowThreshold;\n\n};\n\n/**\n * 获取指定角度方向距离为xxx的像素的透明度\n *\n * @param angle 角度 [0.0, 360.0]\n * @param dist 距离 [0.0, 1.0]\n *\n * @return alpha [0.0, 1.0]\n */\nfloat getColorAlpha(float angle, float dist) {\n\n float radian = angle * 0.01745329252;\n\n vec4 color = getTexture(texture, v_uv0 + vec2(dist * cos(radian), dist * sin(radian))); \n return color.a;\n}\n\n/**\n * 获取指定距离的周边像素的透明度平均值\n *\n * @param dist 距离 [0.0, 1.0]\n *\n * @return average alpha [0.0, 1.0]\n */\nfloat getAverageAlpha(float dist) {\n float totalAlpha = 0.0;\n\n totalAlpha += getColorAlpha(0.0, dist);\n totalAlpha += getColorAlpha(30.0, dist);\n totalAlpha += getColorAlpha(60.0, dist);\n totalAlpha += getColorAlpha(90.0, dist);\n totalAlpha += getColorAlpha(120.0, dist);\n totalAlpha += getColorAlpha(150.0, dist);\n totalAlpha += getColorAlpha(180.0, dist);\n totalAlpha += getColorAlpha(210.0, dist);\n totalAlpha += getColorAlpha(240.0, dist);\n totalAlpha += getColorAlpha(270.0, dist);\n totalAlpha += getColorAlpha(300.0, dist);\n totalAlpha += getColorAlpha(330.0, dist);\n return totalAlpha * 0.0833;\n\n}\n\n/**\n * 获取发光的透明度\n */\nfloat getGlowAlpha() {\n\n if (glowColorSize == 0.0) {\n return 0.0;\n }\n\n float totalAlpha = 0.0;\n totalAlpha += getAverageAlpha(glowColorSize * 0.1);\n totalAlpha += getAverageAlpha(glowColorSize * 0.2);\n totalAlpha += getAverageAlpha(glowColorSize * 0.3);\n totalAlpha += getAverageAlpha(glowColorSize * 0.4);\n totalAlpha += getAverageAlpha(glowColorSize * 0.5);\n totalAlpha += getAverageAlpha(glowColorSize * 0.6);\n totalAlpha += getAverageAlpha(glowColorSize * 0.7);\n totalAlpha += getAverageAlpha(glowColorSize * 0.8);\n totalAlpha += getAverageAlpha(glowColorSize * 0.9);\n totalAlpha += getAverageAlpha(glowColorSize * 1.0);\n return totalAlpha * 0.1;\n}\n\n#endif\n\nvoid main () {\n vec4 o = vec4(1, 1, 1, 1);\n\n #if USE_TEXTURE\n o *= getTexture(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 SHOW_OUTTER_GLOW\n\n float alpha = getGlowAlpha();\n\n if (alpha <= glowThreshold) {\n\n alpha = alpha / glowThreshold;\n\n alpha = -1.0 * (alpha - 1.0) * (alpha - 1.0) * (alpha - 1.0) * (alpha - 1.0) + 1.0;\n } else {\n\n alpha = 0.0;\n }\n\n vec4 color_dest = glowColor * alpha;\n vec4 color_src = o;\n\n gl_FragColor = color_src * color_src.a + color_dest * (1.0 - color_src.a);\n #endif\n}\n"
} }
} }
], ],

View File

@ -78,10 +78,10 @@
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 134 "__id__": 130
}, },
{ {
"__id__": 135 "__id__": 131
} }
], ],
"_prefab": null, "_prefab": null,
@ -251,7 +251,7 @@
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 133 "__id__": 129
} }
], ],
"_prefab": null, "_prefab": null,
@ -5148,28 +5148,28 @@
"__id__": 115 "__id__": 115
}, },
{ {
"__id__": 118 "__id__": 117
},
{
"__id__": 119
}, },
{ {
"__id__": 121 "__id__": 121
}, },
{ {
"__id__": 124 "__id__": 123
}, },
{ {
"__id__": 127 "__id__": 125
},
{
"__id__": 129
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 131 "__id__": 127
}, },
{ {
"__id__": 132 "__id__": 128
} }
], ],
"_prefab": null, "_prefab": null,
@ -5184,7 +5184,7 @@
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 384, "width": 384,
"height": 567.3299999999999 "height": 603.3299999999999
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
@ -5196,7 +5196,7 @@
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
288, 288,
283.66499999999996, 301.66499999999996,
0, 0,
0, 0,
0, 0,
@ -5232,9 +5232,6 @@
"_components": [ "_components": [
{ {
"__id__": 116 "__id__": 116
},
{
"__id__": 117
} }
], ],
"_prefab": null, "_prefab": null,
@ -5317,33 +5314,6 @@
"_atlas": null, "_atlas": null,
"_id": "94vIBMHVlAN4EGbkr2wRvX" "_id": "94vIBMHVlAN4EGbkr2wRvX"
}, },
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 115
},
"_enabled": true,
"alignMode": 1,
"_target": null,
"_alignFlags": 16,
"_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": 0,
"_originalHeight": 0,
"_id": "c2R02zD6FJWbRRKfsWc+5P"
},
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "cocos_logo", "_name": "cocos_logo",
@ -5355,10 +5325,7 @@
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 119 "__id__": 118
},
{
"__id__": 120
} }
], ],
"_prefab": null, "_prefab": null,
@ -5385,7 +5352,7 @@
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
0, 0,
-243, -255,
0, 0,
0, 0,
0, 0,
@ -5414,7 +5381,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 118 "__id__": 117
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -5441,33 +5408,6 @@
"_atlas": null, "_atlas": null,
"_id": "74+WCqN01NIbcSpr5gcxmE" "_id": "74+WCqN01NIbcSpr5gcxmE"
}, },
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 118
},
"_enabled": true,
"alignMode": 1,
"_target": null,
"_alignFlags": 16,
"_left": 0,
"_right": 0,
"_top": 60,
"_bottom": 0,
"_verticalCenter": 0,
"_horizontalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 0,
"_id": "edEKpqZyRGTYfw+r3bBtzV"
},
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "ball_1", "_name": "ball_1",
@ -5479,10 +5419,7 @@
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 122 "__id__": 120
},
{
"__id__": 123
} }
], ],
"_prefab": null, "_prefab": null,
@ -5509,7 +5446,7 @@
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
0, 0,
-456, -480,
0, 0,
0, 0,
0, 0,
@ -5538,7 +5475,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 121 "__id__": 119
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -5565,33 +5502,6 @@
"_atlas": null, "_atlas": null,
"_id": "4bH5hzKe9LsLQeXjLynIHQ" "_id": "4bH5hzKe9LsLQeXjLynIHQ"
}, },
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 121
},
"_enabled": true,
"alignMode": 1,
"_target": null,
"_alignFlags": 16,
"_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": 0,
"_originalHeight": 0,
"_id": "b0cIibhqpDE4frsR3khU/c"
},
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "video_btn", "_name": "video_btn",
@ -5603,10 +5513,7 @@
"_active": false, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 125 "__id__": 122
},
{
"__id__": 126
} }
], ],
"_prefab": null, "_prefab": null,
@ -5662,7 +5569,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 124 "__id__": 121
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -5689,33 +5596,6 @@
"_atlas": null, "_atlas": null,
"_id": "f43fJCjNdOS5VHAEhp0yDU" "_id": "f43fJCjNdOS5VHAEhp0yDU"
}, },
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 124
},
"_enabled": true,
"alignMode": 1,
"_target": null,
"_alignFlags": 16,
"_left": 0,
"_right": 0,
"_top": 0,
"_bottom": 0,
"_verticalCenter": -195,
"_horizontalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 0,
"_id": "27r/pOzQhOrJIV7E87RRJH"
},
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "SystemFont", "_name": "SystemFont",
@ -5727,7 +5607,7 @@
"_active": false, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 128 "__id__": 124
} }
], ],
"_prefab": null, "_prefab": null,
@ -5783,7 +5663,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 127 "__id__": 123
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -5819,7 +5699,7 @@
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 130 "__id__": 126
} }
], ],
"_prefab": null, "_prefab": null,
@ -5846,7 +5726,7 @@
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
0, 0,
-550.665, -586.665,
0, 0,
0, 0,
0, 0,
@ -5875,7 +5755,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 129 "__id__": 125
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -5940,7 +5820,7 @@
"_layoutSize": { "_layoutSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 384, "width": 384,
"height": 567.3299999999999 "height": 603.3299999999999
}, },
"_resize": 1, "_resize": 1,
"_N$layoutType": 2, "_N$layoutType": 2,
@ -5956,7 +5836,7 @@
"_N$paddingTop": 0, "_N$paddingTop": 0,
"_N$paddingBottom": 0, "_N$paddingBottom": 0,
"_N$spacingX": 48, "_N$spacingX": 48,
"_N$spacingY": 48, "_N$spacingY": 60,
"_N$verticalDirection": 1, "_N$verticalDirection": 1,
"_N$horizontalDirection": 0, "_N$horizontalDirection": 0,
"_N$affectedByScale": false, "_N$affectedByScale": false,

View File

@ -23,6 +23,10 @@ export default class GlowOutterEffectScene extends cc.Component {
private _examplesParentNode: cc.Node = null; private _examplesParentNode: cc.Node = null;
onLoad() { onLoad() {
// 关闭动态合图
cc.dynamicAtlasManager.enabled = false;
// cc.dynamicAtlasManager.showDebug(true);
this._redSlider = cc.find("Canvas/Content/Sliders/ColorRedSlider/Slider").getComponent(cc.Slider); this._redSlider = cc.find("Canvas/Content/Sliders/ColorRedSlider/Slider").getComponent(cc.Slider);
this._redSliderLabel = cc.find("Canvas/Content/Sliders/ColorRedSlider/ValueLabel").getComponent(cc.Label); this._redSliderLabel = cc.find("Canvas/Content/Sliders/ColorRedSlider/ValueLabel").getComponent(cc.Label);