add strokeBlur property (default 1.0, larger values blur more) to achieve a gradient effect
fixes #194
This commit is contained in:
@@ -131,6 +131,7 @@ struct TextClass {
|
||||
Color color = {{ 0, 0, 0, 1 }};
|
||||
Color halo = {{ 1, 1, 1, 0.75 }};
|
||||
FunctionProperty haloRadius = 0.25f;
|
||||
FunctionProperty haloBlur = 1.0f;
|
||||
FunctionProperty size = 12.0f;
|
||||
FunctionProperty rotate = 0.0f;
|
||||
FunctionProperty alwaysVisible = false;
|
||||
@@ -144,6 +145,7 @@ struct TextProperties {
|
||||
Color color = {{ 0, 0, 0, 1 }};
|
||||
Color halo = {{ 1, 1, 1, 0.75 }};
|
||||
float haloRadius = 0.25f;
|
||||
float haloBlur = 1.0f;
|
||||
float size = 12.0f;
|
||||
float rotate = 0.0f;
|
||||
bool alwaysVisible = false;
|
||||
|
||||
@@ -41,8 +41,6 @@ void Painter::renderText(TextBucket& bucket, const std::string& layer_name, cons
|
||||
textShader->setTextureSize({{static_cast<float>(map.getGlyphAtlas().width),
|
||||
static_cast<float>(map.getGlyphAtlas().height)}});
|
||||
|
||||
textShader->setGamma(2.5f / fontSize / map.getState().getPixelRatio());
|
||||
|
||||
// Convert the -pi..pi to an int8 range.
|
||||
float angle = round((map.getState().getAngle() + rotate) / M_PI * 128);
|
||||
|
||||
@@ -98,15 +96,19 @@ void Painter::renderText(TextBucket& bucket, const std::string& layer_name, cons
|
||||
// We're drawing in the translucent pass which is bottom-to-top, so we need
|
||||
// to draw the halo first.
|
||||
if (properties.halo[3] > 0.0f) {
|
||||
textShader->setGamma(properties.haloBlur * 2.4f / fontSize / map.getState().getPixelRatio());
|
||||
textShader->setColor(properties.halo);
|
||||
textShader->setBuffer(properties.haloRadius);
|
||||
glDepthRange(strata, 1.0f);
|
||||
bucket.drawGlyphs(*textShader);
|
||||
}
|
||||
|
||||
// Then, we draw the text over the halo
|
||||
textShader->setColor(properties.color);
|
||||
textShader->setBuffer((256.0f - 64.0f) / 256.0f);
|
||||
glDepthRange(strata + strata_epsilon, 1.0f);
|
||||
bucket.drawGlyphs(*textShader);
|
||||
if (properties.color[3] > 0.0f) {
|
||||
// Then, we draw the text over the halo
|
||||
textShader->setGamma(2.4f / fontSize / map.getState().getPixelRatio());
|
||||
textShader->setColor(properties.color);
|
||||
textShader->setBuffer((256.0f - 64.0f) / 256.0f);
|
||||
glDepthRange(strata + strata_epsilon, 1.0f);
|
||||
bucket.drawGlyphs(*textShader);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +102,7 @@ void Style::cascade(float z) {
|
||||
text.size = layer.size.evaluate<float>(z);
|
||||
text.halo = layer.halo;
|
||||
text.haloRadius = layer.haloRadius.evaluate<float>(z);
|
||||
text.haloBlur = layer.haloBlur.evaluate<float>(z);
|
||||
text.rotate = layer.rotate.evaluate<float>(z);
|
||||
text.alwaysVisible = layer.alwaysVisible.evaluate<bool>(z);
|
||||
text.opacity = layer.opacity.evaluate<float>(z);
|
||||
|
||||
@@ -571,6 +571,10 @@ TextClass StyleParser::parseTextClass(JSVal value) {
|
||||
klass.haloRadius = parseFunction(value["strokeWidth"]);
|
||||
}
|
||||
|
||||
if (value.HasMember("strokeBlur")) {
|
||||
klass.haloBlur = parseFunction(value["strokeBlur"]);
|
||||
}
|
||||
|
||||
if (value.HasMember("size")) {
|
||||
klass.size = parseFunction(value["size"]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user