完善内发光demo
This commit is contained in:
parent
5f5e4a9287
commit
5da364c862
@ -88,7 +88,7 @@ CCProgram fs %{
|
||||
// 角度转弧度,公式为:弧度 = 角度 * (pi / 180)
|
||||
float radian = angle * 0.01745329252; // 这个浮点数是 pi / 180
|
||||
vec4 color = texture(texture, v_uv0 + vec2(distance * cos(radian), distance * sin(radian)));
|
||||
return 1.0 - color.a;
|
||||
return color.a;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -119,6 +119,13 @@ CCProgram fs %{
|
||||
* 获取发光的透明度
|
||||
*/
|
||||
float getGlowAlpha() {
|
||||
// 原来已经透明的点不处理
|
||||
vec4 srcColor = texture(texture, v_uv0);
|
||||
if (srcColor.a < 0.0000000001) {
|
||||
return srcColor.a;
|
||||
}
|
||||
|
||||
// 处理原来不透明的点,求周边平均透明度
|
||||
float totalAlpha = 0.0;
|
||||
totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.1);
|
||||
totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.2);
|
||||
@ -152,26 +159,34 @@ CCProgram fs %{
|
||||
gl_FragColor = o;
|
||||
|
||||
#if SHOW_INNER_GLOW
|
||||
// 先画图案
|
||||
// 目标颜色(图像)
|
||||
vec4 color_dest = o;
|
||||
|
||||
// 然后在图案上叠加内发光
|
||||
vec4 color_src = glowColor * getGlowAlpha();
|
||||
// 源颜色(内发光)
|
||||
float alpha = getGlowAlpha();
|
||||
// 此时我们得到的是内部透明度为1,靠近边缘的为接近0的透明度
|
||||
// 而内发光恰恰相反,是需要内部透明度为0,靠近边缘的接近1的透明度
|
||||
// 因此我们需要翻转一下透明度
|
||||
// 如果图像边缘有大量渐变,那么如果我们取 0.0 的话,那么可能边缘会出现锯齿
|
||||
// 因此我们取0.1作为翻转临界值,0.1也不是绝对的,可以自行修改这里的值
|
||||
if (alpha > 0.1) {
|
||||
alpha = 1.0 - alpha;
|
||||
}
|
||||
vec4 color_src = glowColor * alpha;
|
||||
|
||||
// 按照这个顺序,源颜色就是内发光颜色,目标颜色就是图案颜色色
|
||||
// 所以命名就是 color_src, color_dest
|
||||
|
||||
// 按照混合颜色规则 http://docs.cocos.com/creator/manual/zh/advanced-topics/ui-auto-batch.html#blend-%E6%A8%A1%E5%BC%8F
|
||||
// 要在图案上方,叠加一个内发光,将两者颜色混合起来,那么最终选择的混合模式如下:
|
||||
// color_src: GL_SRC_ALPHA
|
||||
// color_dest: GL_ONE_MINUS_SRC_ALPHA
|
||||
//
|
||||
// (内发光)color_src: GL_SRC_ALPHA
|
||||
// (原图像)color_dest: GL_ONE
|
||||
//
|
||||
// 即最终颜色如下:
|
||||
// color_src * GL_SRC_ALPHA + color_dest * GL_ONE_MINUS_SRC_ALPHA
|
||||
gl_FragColor = color_src * color_src.a + color_dest * (1.0 - color_src.a);
|
||||
// gl_FragColor = color_src + color_dest * (1.0 - color_src.a);
|
||||
// gl_FragColor = color_src * (1.0 - color_src.a) + color_dest * color_src.a;
|
||||
// gl_FragColor = color_src;
|
||||
// gl_FragColor = color_dest * color_dest.a + color_src * (1.0 - color_dest.a);
|
||||
// color_src * GL_SRC_ALPHA + color_dest * GL_ONE
|
||||
|
||||
gl_FragColor = color_src * color_src.a + color_dest;
|
||||
#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 SHOW_INNER_GLOW\n\nuniform vec4 glowColor;\nuniform float glowColorSize;\n\n/**\n * 获取指定角度方向,距离为xxx的像素的透明度\n *\n * @param angle 角度 [0.0, 360.0]\n * @param distance 距离 [0.0, 1.0]\n *\n * @return alpha [0.0, 1.0]\n */\nfloat getColorAlpha(float angle, float distance) {\n\n float radian = angle * 0.01745329252;\n\n vec4 color = texture2D(texture, v_uv0 + vec2(distance * cos(radian), distance * sin(radian))); \n return 1.0 - color.a;\n}\n\n/**\n * 获取指定距离的周边像素的透明度平均值\n *\n * @param distance 距离 [0.0, 1.0]\n *\n * @return average alpha [0.0, 1.0]\n */\nfloat getDistanceAverageAlpha(float distance) {\n float totalAlpha = 0.0;\n totalAlpha += getColorAlpha(0.0, distance);\n totalAlpha += getColorAlpha(30.0, distance);\n totalAlpha += getColorAlpha(60.0, distance);\n totalAlpha += getColorAlpha(90.0, distance);\n totalAlpha += getColorAlpha(120.0, distance);\n totalAlpha += getColorAlpha(150.0, distance);\n totalAlpha += getColorAlpha(180.0, distance);\n totalAlpha += getColorAlpha(210.0, distance);\n totalAlpha += getColorAlpha(240.0, distance);\n totalAlpha += getColorAlpha(270.0, distance);\n totalAlpha += getColorAlpha(300.0, distance);\n totalAlpha += getColorAlpha(330.0, distance);\n return totalAlpha * (1.0 / 12.0);\n}\n\n/**\n * 获取发光的透明度\n */\nfloat getGlowAlpha() {\n float totalAlpha = 0.0;\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.1);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.2);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.3);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.4);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.5);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.6);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.7);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.8);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.9);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 1.0);\n return 1.0 - totalAlpha * (1.0 / 10.0);\n\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_INNER_GLOW\n\n vec4 color_dest = o;\n\n vec4 color_src = glowColor * getGlowAlpha();\n\n gl_FragColor = color_src * color_src.a + color_dest * (1.0 - color_src.a);\n\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 SHOW_INNER_GLOW\n\nuniform vec4 glowColor;\nuniform float glowColorSize;\n\n/**\n * 获取指定角度方向,距离为xxx的像素的透明度\n *\n * @param angle 角度 [0.0, 360.0]\n * @param distance 距离 [0.0, 1.0]\n *\n * @return alpha [0.0, 1.0]\n */\nfloat getColorAlpha(float angle, float distance) {\n\n float radian = angle * 0.01745329252;\n\n vec4 color = texture2D(texture, v_uv0 + vec2(distance * cos(radian), distance * sin(radian))); \n return color.a;\n}\n\n/**\n * 获取指定距离的周边像素的透明度平均值\n *\n * @param distance 距离 [0.0, 1.0]\n *\n * @return average alpha [0.0, 1.0]\n */\nfloat getDistanceAverageAlpha(float distance) {\n float totalAlpha = 0.0;\n totalAlpha += getColorAlpha(0.0, distance);\n totalAlpha += getColorAlpha(30.0, distance);\n totalAlpha += getColorAlpha(60.0, distance);\n totalAlpha += getColorAlpha(90.0, distance);\n totalAlpha += getColorAlpha(120.0, distance);\n totalAlpha += getColorAlpha(150.0, distance);\n totalAlpha += getColorAlpha(180.0, distance);\n totalAlpha += getColorAlpha(210.0, distance);\n totalAlpha += getColorAlpha(240.0, distance);\n totalAlpha += getColorAlpha(270.0, distance);\n totalAlpha += getColorAlpha(300.0, distance);\n totalAlpha += getColorAlpha(330.0, distance);\n return totalAlpha * (1.0 / 12.0);\n}\n\n/**\n * 获取发光的透明度\n */\nfloat getGlowAlpha() {\n\n vec4 srcColor = texture2D(texture, v_uv0);\n if (srcColor.a < 0.0000000001) {\n return srcColor.a;\n }\n\n float totalAlpha = 0.0;\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.1);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.2);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.3);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.4);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.5);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.6);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.7);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.8);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.9);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 1.0);\n return totalAlpha * (1.0 / 10.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\n #if SHOW_INNER_GLOW\n\n vec4 color_dest = o;\n\n float alpha = getGlowAlpha();\n\n if (alpha > 0.1) {\n alpha = 1.0 - alpha;\n }\n vec4 color_src = glowColor * alpha;\n\n gl_FragColor = color_src * color_src.a + color_dest;\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 SHOW_INNER_GLOW\n\nuniform glow {\n\n vec4 glowColor;\n\n float glowColorSize;\n\n};\n\n/**\n * 获取指定角度方向,距离为xxx的像素的透明度\n *\n * @param angle 角度 [0.0, 360.0]\n * @param distance 距离 [0.0, 1.0]\n *\n * @return alpha [0.0, 1.0]\n */\nfloat getColorAlpha(float angle, float distance) {\n\n float radian = angle * 0.01745329252;\n\n vec4 color = texture(texture, v_uv0 + vec2(distance * cos(radian), distance * sin(radian))); \n return 1.0 - color.a;\n}\n\n/**\n * 获取指定距离的周边像素的透明度平均值\n *\n * @param distance 距离 [0.0, 1.0]\n *\n * @return average alpha [0.0, 1.0]\n */\nfloat getDistanceAverageAlpha(float distance) {\n float totalAlpha = 0.0;\n totalAlpha += getColorAlpha(0.0, distance);\n totalAlpha += getColorAlpha(30.0, distance);\n totalAlpha += getColorAlpha(60.0, distance);\n totalAlpha += getColorAlpha(90.0, distance);\n totalAlpha += getColorAlpha(120.0, distance);\n totalAlpha += getColorAlpha(150.0, distance);\n totalAlpha += getColorAlpha(180.0, distance);\n totalAlpha += getColorAlpha(210.0, distance);\n totalAlpha += getColorAlpha(240.0, distance);\n totalAlpha += getColorAlpha(270.0, distance);\n totalAlpha += getColorAlpha(300.0, distance);\n totalAlpha += getColorAlpha(330.0, distance);\n return totalAlpha * (1.0 / 12.0);\n}\n\n/**\n * 获取发光的透明度\n */\nfloat getGlowAlpha() {\n float totalAlpha = 0.0;\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.1);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.2);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.3);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.4);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.5);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.6);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.7);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.8);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.9);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 1.0);\n return 1.0 - totalAlpha * (1.0 / 10.0);\n\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_INNER_GLOW\n\n vec4 color_dest = o;\n\n vec4 color_src = glowColor * getGlowAlpha();\n\n gl_FragColor = color_src * color_src.a + color_dest * (1.0 - color_src.a);\n\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 SHOW_INNER_GLOW\n\nuniform glow {\n\n vec4 glowColor;\n\n float glowColorSize;\n\n};\n\n/**\n * 获取指定角度方向,距离为xxx的像素的透明度\n *\n * @param angle 角度 [0.0, 360.0]\n * @param distance 距离 [0.0, 1.0]\n *\n * @return alpha [0.0, 1.0]\n */\nfloat getColorAlpha(float angle, float distance) {\n\n float radian = angle * 0.01745329252;\n\n vec4 color = texture(texture, v_uv0 + vec2(distance * cos(radian), distance * sin(radian))); \n return color.a;\n}\n\n/**\n * 获取指定距离的周边像素的透明度平均值\n *\n * @param distance 距离 [0.0, 1.0]\n *\n * @return average alpha [0.0, 1.0]\n */\nfloat getDistanceAverageAlpha(float distance) {\n float totalAlpha = 0.0;\n totalAlpha += getColorAlpha(0.0, distance);\n totalAlpha += getColorAlpha(30.0, distance);\n totalAlpha += getColorAlpha(60.0, distance);\n totalAlpha += getColorAlpha(90.0, distance);\n totalAlpha += getColorAlpha(120.0, distance);\n totalAlpha += getColorAlpha(150.0, distance);\n totalAlpha += getColorAlpha(180.0, distance);\n totalAlpha += getColorAlpha(210.0, distance);\n totalAlpha += getColorAlpha(240.0, distance);\n totalAlpha += getColorAlpha(270.0, distance);\n totalAlpha += getColorAlpha(300.0, distance);\n totalAlpha += getColorAlpha(330.0, distance);\n return totalAlpha * (1.0 / 12.0);\n}\n\n/**\n * 获取发光的透明度\n */\nfloat getGlowAlpha() {\n\n vec4 srcColor = texture(texture, v_uv0);\n if (srcColor.a < 0.0000000001) {\n return srcColor.a;\n }\n\n float totalAlpha = 0.0;\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.1);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.2);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.3);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.4);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.5);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.6);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.7);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.8);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 0.9);\n totalAlpha += getDistanceAverageAlpha(glowColorSize * 1.0);\n return totalAlpha * (1.0 / 10.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\n #if SHOW_INNER_GLOW\n\n vec4 color_dest = o;\n\n float alpha = getGlowAlpha();\n\n if (alpha > 0.1) {\n alpha = 1.0 - alpha;\n }\n vec4 color_src = glowColor * alpha;\n\n gl_FragColor = color_src * color_src.a + color_dest;\n #endif\n}\n"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@ -12,6 +12,14 @@
|
||||
"SHOW_INNER_GLOW": true
|
||||
},
|
||||
"_props": {
|
||||
"texture": null
|
||||
"texture": null,
|
||||
"glowColor": {
|
||||
"__type__": "cc.Vec4",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 1,
|
||||
"w": 1
|
||||
},
|
||||
"glowColorSize": 0.5
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -2,15 +2,47 @@ const { ccclass, property } = cc._decorator;
|
||||
|
||||
@ccclass
|
||||
export default class GlowInnerEffectScene extends cc.Component {
|
||||
@property(cc.Node)
|
||||
examplesParentNode: cc.Node = null;
|
||||
private _redSlider: cc.Slider = null;
|
||||
private _greenSlider: cc.Slider = null;
|
||||
private _blueSlider: cc.Slider = null;
|
||||
private _alphaSlider: cc.Slider = null;
|
||||
private _widthSlider: cc.Slider = null;
|
||||
private _examplesParentNode: cc.Node = null;
|
||||
|
||||
start() {
|
||||
this._updateRenderComponentOutterGlowMaterial(0);
|
||||
onLoad() {
|
||||
this._redSlider = cc.find("Canvas/SliderLayouts/RedSlider/Slider").getComponent(cc.Slider);
|
||||
this._greenSlider = cc.find("Canvas/SliderLayouts/GreenSlider/Slider").getComponent(cc.Slider);
|
||||
this._blueSlider = cc.find("Canvas/SliderLayouts/BlueSlider/Slider").getComponent(cc.Slider);
|
||||
this._alphaSlider = cc.find("Canvas/SliderLayouts/AlphaSlider/Slider").getComponent(cc.Slider);
|
||||
this._widthSlider = cc.find("Canvas/SliderLayouts/WidthSlider/Slider").getComponent(cc.Slider);
|
||||
this._examplesParentNode = cc.find("Canvas/Examples");
|
||||
}
|
||||
|
||||
onSideCallBack(slider: cc.Slider, customEventData: string) {
|
||||
this._updateRenderComponentOutterGlowMaterial(slider.progress / 100);
|
||||
onEnable() {
|
||||
this._redSlider.node.on("slide", this._onSliderChanged, this);
|
||||
this._greenSlider.node.on("slide", this._onSliderChanged, this);
|
||||
this._blueSlider.node.on("slide", this._onSliderChanged, this);
|
||||
this._alphaSlider.node.on("slide", this._onSliderChanged, this);
|
||||
this._widthSlider.node.on("slide", this._onSliderChanged, this);
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
this._redSlider.node.off("slide", this._onSliderChanged, this);
|
||||
this._greenSlider.node.off("slide", this._onSliderChanged, this);
|
||||
this._blueSlider.node.off("slide", this._onSliderChanged, this);
|
||||
this._alphaSlider.node.off("slide", this._onSliderChanged, this);
|
||||
this._widthSlider.node.off("slide", this._onSliderChanged, this);
|
||||
}
|
||||
|
||||
start() {
|
||||
this._onSliderChanged();
|
||||
}
|
||||
|
||||
private _onSliderChanged() {
|
||||
this._updateRenderComponentOutterGlowMaterial({
|
||||
glowColor: cc.v4(this._redSlider.progress, this._greenSlider.progress, this._blueSlider.progress, this._alphaSlider.progress),
|
||||
glowColorSize: this._widthSlider.progress / 100
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -19,14 +51,23 @@ export default class GlowInnerEffectScene extends cc.Component {
|
||||
* 1. 获取材质
|
||||
* 2. 给材质的自定义 unitform 变量赋值
|
||||
* 3. 重新将材质赋值回去
|
||||
*
|
||||
* @param size 描边长度比例[0,1] 比如0.5,那么就是宽*0.5 高*0.5
|
||||
*/
|
||||
private _updateRenderComponentOutterGlowMaterial(size: number) {
|
||||
this.examplesParentNode.children.forEach(childNode => {
|
||||
private _updateRenderComponentOutterGlowMaterial(param: {
|
||||
/**
|
||||
* 发光宽度 [0.0, 1.0]
|
||||
*/
|
||||
glowColorSize: number;
|
||||
|
||||
/**
|
||||
* 发光颜色 [0.0, 1.0]
|
||||
*/
|
||||
glowColor: cc.Vec4;
|
||||
}) {
|
||||
this._examplesParentNode.children.forEach(childNode => {
|
||||
childNode.getComponents(cc.RenderComponent).forEach(renderComponent => {
|
||||
let material: cc.Material = renderComponent.getMaterial(0);
|
||||
material.setProperty("glowColorSize", size);
|
||||
material.setProperty("glowColorSize", param.glowColorSize);
|
||||
material.setProperty("glowColor", param.glowColor);
|
||||
renderComponent.setMaterial(0, material);
|
||||
});
|
||||
});
|
||||
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
@ -9,7 +9,7 @@
|
||||
"packable": true,
|
||||
"platformSettings": {},
|
||||
"subMetas": {
|
||||
"ball_00": {
|
||||
"ball_0": {
|
||||
"ver": "1.0.4",
|
||||
"uuid": "d0b78623-4e79-4de1-b1d2-ea211bf4652c",
|
||||
"rawTextureUuid": "c996c862-3d09-4bc6-915d-e8a8e7226933",
|
Before Width: | Height: | Size: 9.6 KiB After Width: | Height: | Size: 9.6 KiB |
@ -9,7 +9,7 @@
|
||||
"packable": true,
|
||||
"platformSettings": {},
|
||||
"subMetas": {
|
||||
"prestige_04_big": {
|
||||
"ball_1": {
|
||||
"ver": "1.0.4",
|
||||
"uuid": "969fa66a-ae10-4157-b16e-4c1a4665920c",
|
||||
"rawTextureUuid": "bdfd3151-8c13-406b-8f94-1f101c972e7e",
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
@ -9,7 +9,7 @@
|
||||
"packable": true,
|
||||
"platformSettings": {},
|
||||
"subMetas": {
|
||||
"start_0": {
|
||||
"video_btn": {
|
||||
"ver": "1.0.4",
|
||||
"uuid": "54142b08-a163-426e-a75e-4c7b21046413",
|
||||
"rawTextureUuid": "2453b01d-4364-4d87-ab53-391d1a42d07d",
|
2
creator.d.ts
vendored
2
creator.d.ts
vendored
@ -1633,7 +1633,7 @@ declare namespace cc {
|
||||
var v4 = cc.v4({x: 100, y: 100, z: 0});
|
||||
```
|
||||
*/
|
||||
export function v4(x?: number|any, y?: number, z?: number): Vec4;
|
||||
export function v4(x?: number|any, y?: number, z?: number, w?: number): Vec4;
|
||||
export var dynamicAtlasManager: DynamicAtlasManager;
|
||||
/** !#en
|
||||
cc.NodePool is the cache pool designed for node type.<br/>
|
||||
|
Loading…
Reference in New Issue
Block a user