Label Plus - 基于 SDF 的 BMFont 生成和渲染的免费插件来了

这个是我们能免费用的? :joy:

mark 支持.

大佬,搞个2.*版本??可好?

//self defined effect         author:ljw 

CCEffect %{
techniques:

  • name: stroke
    passes:
    • vert: 2dvs:vert # builtin header
      frag: 2dfs:frag
      blendState:
      targets:
      • blend: true
        blendSrc: src_alpha
        blendDst: one_minus_src_alpha
        blendDstAlpha: one_minus_src_alpha
        properties: &props
        mainColor: { value: [1, 1, 1, 1], editor: { type: color } }
        strokeColor: {value: [1, 1, 1, 1] , editor: { type: color }}
        fillColor: {value: [1, 0, 0, 1], editor: { type: color }}
        strokeWidth: { value: 0.01}
  • name: stroke-drawShadow
    passes:
    • vert: 2dvs:vert # builtin header
      frag: 2dfs-shadow:frag
      blendState:
      targets:
      • blend: true
        blendSrc: src_alpha
        blendDst: one_minus_src_alpha
        blendDstAlpha: one_minus_src_alpha
        properties: &props
        mainColor: { value: [1, 1, 1, 1], editor: { type: color } }
        strokeColor: {value: [1, 1, 1, 1] , editor: { type: color }}
        fillColor: {value: [1, 0, 0, 1], editor: { type: color }}
        shaowColor: { value: [0,0,1,1], editor: { type: color }}
        strokeWidth: { value: 0.01}
        shadowWidth: {value: 0.02}
        }%

CCProgram 2dvs { precision highp float; #include <cc-global> #if USE_LOCAL #include <cc-local> #endif #if SAMPLE_FROM_RT #include <common> #endif in vec3 a_position; in vec2 a_texCoord; in vec4 a_color; out vec4 color; out vec2 uv0; vec4 vert () { vec4 pos = vec4(a_position, 1); #if USE_LOCAL pos = cc_matWorld * pos; #endif #if USE_PIXEL_ALIGNMENT pos = cc_matView * pos; pos.xyz = floor(pos.xyz); pos = cc_matProj * pos; #else pos = cc_matViewProj * pos; #endif uv0 = a_texCoord; #if SAMPLE_FROM_RT CC_HANDLE_RT_SAMPLE_FLIP(uv0); #endif color = a_color; return pos; } }

CCProgram 2dfs %{
precision highp float;
#include
#include

in vec2 uv0;

uniform Constant {
vec4 mainColor;
vec4 strokeColor;
vec4 fillColor;
float strokeWidth;
};
vec4 drawEdgeStroke(){
float alphaThreshold = 0.3;
vec4 col1 = texture(cc_spriteTexture, uv0);
if(col1.a>alphaThreshold) return fillColor;
else {
vec4 col2 = texture(cc_spriteTexture, uv0+vec2(strokeWidth,0.));
vec4 col3 = texture(cc_spriteTexture, uv0+vec2(-strokeWidth,0.));
vec4 col4 = texture(cc_spriteTexture, uv0+vec2(0.,strokeWidth));
vec4 col5 = texture(cc_spriteTexture, uv0+vec2(0.,-strokeWidth));
vec4 col6 = texture(cc_spriteTexture, uv0+vec2(strokeWidth,strokeWidth));
vec4 col7 = texture(cc_spriteTexture, uv0+vec2(strokeWidth,-strokeWidth));
vec4 col8 = texture(cc_spriteTexture, uv0+vec2(-strokeWidth,strokeWidth));
vec4 col9 = texture(cc_spriteTexture, uv0+vec2(-strokeWidth,-strokeWidth));
if(col2.a>alphaThreshold||col3.a>alphaThreshold||col4.a>alphaThreshold||col5.a>alphaThreshold
||col6.a>alphaThreshold||col7.a>alphaThreshold||col8.a>alphaThreshold||col9.a>alphaThreshold) return strokeColor;
else discard;
}
}
vec4 frag () {
vec4 col = drawEdgeStroke();
return CCFragOutput(col);
}
}%

CCProgram 2dfs-shadow %{
precision highp float;
#include
#include

in vec2 uv0;

uniform Constant {
vec4 mainColor;
vec4 strokeColor;
vec4 fillColor;
vec4 shaowColor;
float strokeWidth;
float shadowWidth;

};
vec4 drawEdgeStroke(){
float alphaThreshold = 0.3;
vec4 col1 = texture(cc_spriteTexture, uv0);
if(col1.a>alphaThreshold) return fillColor;//文字 正常渲染
else {
//上下左右偏移 strokeWidth个长度后的坐标
vec4 col2 = texture(cc_spriteTexture, uv0+vec2(strokeWidth,0.));
vec4 col3 = texture(cc_spriteTexture, uv0+vec2(-strokeWidth,0.));
vec4 col4 = texture(cc_spriteTexture, uv0+vec2(0.,strokeWidth));
vec4 col5 = texture(cc_spriteTexture, uv0+vec2(0.,-strokeWidth));
vec4 col6 = texture(cc_spriteTexture, uv0+vec2(strokeWidth,strokeWidth));
vec4 col7 = texture(cc_spriteTexture, uv0+vec2(strokeWidth,-strokeWidth));
vec4 col8 = texture(cc_spriteTexture, uv0+vec2(-strokeWidth,strokeWidth));
vec4 col9 = texture(cc_spriteTexture, uv0+vec2(-strokeWidth,-strokeWidth));
// 下右偏移
vec4 col10 = texture(cc_spriteTexture,uv0+vec2(-shadowWidth));
if(col2.a>alphaThreshold||col3.a>alphaThreshold||col4.a>alphaThreshold||col5.a>alphaThreshold
||col6.a>alphaThreshold||col7.a>alphaThreshold||col8.a>alphaThreshold||col9.a>alphaThreshold) return strokeColor;
else if(col10.a>alphaThreshold){
return shaowColor;
}else discard;
}
}
vec4 frag () {
vec4 col = drawEdgeStroke();
return CCFragOutput(col);
}
}%

看这个效果用shader写了个脚本,感觉比插件可能方便点。版本是3.5

1赞

不过看作者之前的帖子,他好像做了合批处理。 :grinning:

Label Plus 插件更新了!!!(v1.0.2)

1赞

大佬我只想对你说 爱你 爱你 爱你,如果没时间,我们可以用金钱来赞助,做的更好

问下,这个字是不是每次都要自己去生成?手动一个个往里面输入吗,如果想要继续添加,界面关闭后又没了

可以选择从文本文件去读, 弄个 txt 文件,放项目里

ok 了解哈哈

对了如果里面字体太多的话需要去重吗?

现在的版本需要, 今天有人反馈了, 我写了去重,但是有 bug,近期会更一版,把 bug 修了

意思是后面可以在里面随便写字,不用关心一样对吗

是的,以后不需要关心

哈哈坐等大牛更新

建了个 QQ 群,方便大家一起讨论和插件有关的问题

有没有可能做动态生成SDF纹理,基于LRU管理SDF纹理?

工作量太大,不考虑, 还要面临性能问题等等,一个人搞不了

顶支持,mark

Label Plus 插件更新了!!!(v1.0.4)