Distance field EffectMode (#1546)

* Distance field EffectMode (supports MSDF and the regular sort)
This commit is contained in:
Flameshadowxeroshin
2017-10-02 05:54:05 -07:00
committed by Colby Klein
parent e246e3d5f8
commit c1088c1abc
5 changed files with 49 additions and 1 deletions
+27
View File
@@ -0,0 +1,27 @@
uniform sampler2D Texture1;
varying vec2 texCoords;
varying vec4 vertexColor;
float aastep(float threshold, float dist) {
float afwidth = 0.75 * length(vec2(dFdx(dist), dFdy(dist)));
return smoothstep(threshold - afwidth, threshold + afwidth, dist);
}
float median(float r, float g, float b) {
return max(min(r, g), min(max(r, g), b));
}
const float distanceThreshold = 0.5;
float sample(vec2 tc) {
vec3 texel = texture2D(Texture1, tc).rgb;
float dist = median(texel.r, texel.g, texel.b);
return aastep(distanceThreshold, dist);
}
void main(void)
{
float dfValue = sample(texCoords);
gl_FragColor = vec4(vertexColor.rgb, vertexColor.a * dfValue);
}
+10
View File
@@ -0,0 +1,10 @@
//We need this shader to pass the vertex color to the frag shader
varying vec4 vertexColor;
varying vec2 texCoords;
void main(void) {
vertexColor = gl_Color;
texCoords = gl_MultiTexCoord0.st;
gl_Position = gl_Vertex * gl_ModelViewProjectionMatrix;
}