Adjust sdf frag shader alpha correctly

This commit is contained in:
Atlante45 2015-06-16 17:17:47 +02:00
parent bdaf8a8a32
commit ca98b378df
2 changed files with 5 additions and 5 deletions

View file

@ -429,8 +429,8 @@ void Font3D::drawString(gpu::Batch& batch, float x, float y, const QString& str,
setupGPU();
batch.setPipeline(_pipeline);
batch.setUniformTexture(_fontLoc, _texture);
batch._glUniform1f(_outlineLoc, (effectType == TextRenderer3D::OUTLINE_EFFECT) ? 1.0f : 0.0f);
batch._glUniform4fv(_colorLoc, 1, (const GLfloat*)&color);
batch._glUniform1i(_outlineLoc, (effectType == TextRenderer3D::OUTLINE_EFFECT));
batch.setInputFormat(_format);
batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride);

View file

@ -11,7 +11,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
uniform sampler2D Font;
uniform float Outline;
uniform bool Outline;
uniform vec4 Color;
const float gamma = 2.6;
@ -22,7 +22,7 @@ const float outlineExpansion = 0.2;
void main() {
// retrieve signed distance
float sdf = texture2D(Font, gl_TexCoord[0].xy).g;
if (Outline == 1.0f) {
if (Outline) {
if (sdf > interiorCutoff) {
sdf = 1.0 - sdf;
} else {
@ -31,7 +31,7 @@ void main() {
}
// perform adaptive anti-aliasing of the edges
// The larger we're rendering, the less anti-aliasing we need
float s = smoothing * length(fwidth(gl_TexCoord[0]));
float s = smoothing * length(fwidth(gl_TexCoord[0].xy));
float w = clamp( s, 0.0, 0.5);
float a = smoothstep(0.5 - w, 0.5 + w, sdf);
@ -43,5 +43,5 @@ void main() {
}
// final color
gl_FragColor = vec4(Color.rgb, a);
gl_FragColor = vec4(Color.rgb, Color.a * a);
}