Distance field EffectMode (#1546)
* Distance field EffectMode (supports MSDF and the regular sort)
This commit is contained in:
committed by
Colby Klein
parent
e246e3d5f8
commit
c1088c1abc
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user