123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- CCEffect %{
- # techniques 是一个数组
- techniques:
- # passes 是 techniques 数组的第0项
- - passes:
- - vert: vs #参数指定了顶点着色器 还可以 vs:vert 这时候就是vert() 函数替代 main() 入口了
- frag: fs #参数指定了片元着色器
- # 混合模式开启 Pass 可选配置参数
- blendState:
- targets:
- - blend: true #true, false
- rasterizerState: #光栅器状态 光栅也称衍射光栅。是利用多缝衍射原理使光发生色散(分解为光谱)的光学元件 该接口表示用于配置管线光栅化阶段的状态组
- cullMode: none #设置材质的裁减模式。front, back, none https://www.cnblogs.com/zeppelin5/p/10042863.html
- properties: # properties 列出可以在 Inspector 编辑器编辑的属性
- texture: { value: white }
- alphaThreshold: { value: 0.5 }
- size: { value: [960.0, 640.0], editor: { tooltip: '节点尺寸' } }
- center: { value: [0.5, 0.5], editor: { tooltip: '中心点 (左上角为原点)' } }
- radius: { value: 0.2, editor: { tooltip: '半径 (目标宽度 / 节点宽度)' } }
- feather: { value: 0.1, editor: { tooltip: '边缘虚化宽度' } }
- #设置alpha阈值, 只有模板(stencil)的alpha像素大于alpha阈值(alphaThreshold)时内容才会被绘制。 alpha阈值(threshold)范围应是0到1之间的浮点数。 alpha阈值(threshold)默认为1
- #https://forum.cocos.org/t/cocos-creator-etc1-alpha/78024 ETC1 + Alpha 纹理压缩
- }%
- CCProgram vs %{
- precision highp float;
-
-
-
-
-
- #include <cc-global> //http://blog.sina.com.cn/s/blog_4aff14d50100y86y.html
- #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 /*如果使用了模型 针对3D */ // cc_matWorld:本地空间转世界空间
- 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>
- #include <texture>
-
- in vec4 v_color;
- #if USE_TEXTURE
-
-
- in vec2 v_uv0;
-
-
-
- uniform sampler2D texture;
- #endif
-
- uniform ARGS {
- vec2 center;
- vec2 size;
- float radius;
- float feather;
- };
- void main () {
- vec4 color = v_color;
- color *= texture(texture, v_uv0);
- float ratio = size.x / size.y;
- float dis = distance(vec2(v_uv0.x, v_uv0.y / ratio), vec2(center.x, center.y / ratio));
- color.a = smoothstep(radius - feather, radius, dis) * color.a;
- color.a *= v_color.a;
- gl_FragColor = color;
- }
- }%
|