114 lines
2.4 KiB
Plaintext
114 lines
2.4 KiB
Plaintext
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
CCEffect %{
|
|
techniques:
|
|
- passes:
|
|
- vert: vs
|
|
frag: fs
|
|
blendState:
|
|
targets:
|
|
- blend: true
|
|
rasterizerState:
|
|
cullMode: none
|
|
properties:
|
|
texture: { value: white }
|
|
alphaThreshold: { value: 0.5 }
|
|
glyphRect: { value: [0, 0, 1, 1] }
|
|
glyphSize: { value: [50, 62] }
|
|
}%
|
|
|
|
|
|
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>
|
|
#include <texture>
|
|
|
|
in vec4 v_color;
|
|
|
|
#if USE_TEXTURE
|
|
in vec2 v_uv0;
|
|
uniform sampler2D texture;
|
|
#endif
|
|
|
|
uniform Glyph {
|
|
vec4 glyphRect;
|
|
vec2 glyphSize;
|
|
};
|
|
|
|
#if USE_TEXTURE
|
|
float maskAt(vec2 point) {
|
|
vec2 uv = point / glyphSize;
|
|
if (uv.x < 0.0 || uv.y < 0.0 || uv.x > 1.0 || uv.y > 1.0) return 0.0;
|
|
vec4 sampleColor = vec4(1.0);
|
|
CCTexture(texture, glyphRect.xy + uv * glyphRect.zw, sampleColor);
|
|
return sampleColor.a * sampleColor.r;
|
|
}
|
|
#endif
|
|
|
|
void main () {
|
|
vec4 o = v_color;
|
|
#if USE_TEXTURE
|
|
// Reserve 8 pixels around the original glyph inside this single sprite's quad.
|
|
vec2 point = (v_uv0 - glyphRect.xy) / glyphRect.zw * (glyphSize + vec2(16.0)) - vec2(8.0);
|
|
float fill = maskAt(point);
|
|
float outer = 0.0;
|
|
float inner = 0.0;
|
|
for (int i = 0; i < 16; i++) {
|
|
float angle = float(i) * 0.3926990817;
|
|
vec2 direction = vec2(cos(angle), sin(angle));
|
|
outer = 1.0 - (1.0 - outer) * (1.0 - maskAt(point + direction * 8.0));
|
|
inner = 1.0 - (1.0 - inner) * (1.0 - maskAt(point + direction * 4.0));
|
|
}
|
|
float alpha = fill + (1.0 - fill) * (inner + (1.0 - inner) * outer);
|
|
vec3 color = vec3(1.0, 242.0 / 255.0, 0.0) * fill
|
|
+ (1.0 - fill) * (vec3(164.0, 61.0, 19.0) / 255.0 * inner
|
|
+ (1.0 - inner) * vec3(outer));
|
|
o = vec4(color / max(alpha, 0.0001), alpha * v_color.a);
|
|
#endif
|
|
|
|
ALPHA_TEST(o);
|
|
|
|
#if USE_BGRA
|
|
gl_FragColor = o.bgra;
|
|
#else
|
|
gl_FragColor = o.rgba;
|
|
#endif
|
|
}
|
|
}%
|