adjust shaders
This commit is contained in:
parent
5fc06a177b
commit
971a9f089d
3 changed files with 50 additions and 32 deletions
|
@ -1,12 +1,10 @@
|
||||||
precision highp float;
|
precision highp float;
|
||||||
|
|
||||||
// these are our textures
|
// these are our textures
|
||||||
uniform sampler2D msdf_0;
|
uniform sampler2D msdf;
|
||||||
uniform sampler2D msdf_1;
|
|
||||||
|
|
||||||
uniform vec4 fontColor;
|
uniform vec4 fontColor;
|
||||||
uniform float msdf_mix;
|
uniform float pxRange;
|
||||||
uniform float msdf_pxratio;
|
|
||||||
|
|
||||||
// this comes from the vertex shader
|
// this comes from the vertex shader
|
||||||
varying vec2 texCoordVarying;
|
varying vec2 texCoordVarying;
|
||||||
|
@ -15,8 +13,10 @@ float median(float r, float g, float b) {
|
||||||
return max(min(r, g), min(max(r, g), b));
|
return max(min(r, g), min(max(r, g), b));
|
||||||
}
|
}
|
||||||
|
|
||||||
float screenPxRange(float ratio) {
|
float screenPxRange() {
|
||||||
return ratio * 2.0;
|
vec2 unitRange = vec2(pxRange)/vec2(textureSize(msdf));
|
||||||
|
vec2 screenTexSize = vec2(1.0)/fwidth(texCoordVarying);
|
||||||
|
return max(0.5*dot(unitRange, screenTexSize), 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
|
@ -24,11 +24,9 @@ void main()
|
||||||
vec4 bgColor = vec4(fontColor.rgb,0);
|
vec4 bgColor = vec4(fontColor.rgb,0);
|
||||||
vec4 fgColor = fontColor;
|
vec4 fgColor = fontColor;
|
||||||
|
|
||||||
vec3 msd_0 = texture2D(msdf_0, texCoordVarying).rgb;
|
vec3 msdf_rgb = texture2D(msdf, texCoordVarying).rgb;
|
||||||
vec3 msd_1 = texture2D(msdf_1, texCoordVarying).rgb;
|
float sd = median(msdf_rgb.r, msdf_rgb.g, msdf_rgb.b);
|
||||||
vec3 msd = mix(msd_0, msd_1,msdf_mix);
|
float screenPxDistance = screenPxRange()*(sd - 0.5);
|
||||||
float sd = median(msd.r, msd.g, msd.b);
|
|
||||||
float screenPxDistance = screenPxRange(msdf_pxratio)*(sd - 0.5);
|
|
||||||
float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0);
|
float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0);
|
||||||
gl_FragColor = mix(bgColor, fgColor, opacity);
|
gl_FragColor = mix(bgColor, fgColor, opacity);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,9 @@ precision highp float;
|
||||||
|
|
||||||
// these are our textures
|
// these are our textures
|
||||||
uniform sampler2DRect msdf_0;
|
uniform sampler2DRect msdf_0;
|
||||||
uniform sampler2DRect msdf_1;
|
|
||||||
|
|
||||||
uniform vec4 fontColor;
|
uniform vec4 fontColor;
|
||||||
uniform float msdf_mix;
|
uniform float pxRange;
|
||||||
uniform float msdf_pxratio;
|
|
||||||
|
|
||||||
// this comes from the vertex shader
|
// this comes from the vertex shader
|
||||||
varying vec2 texCoordVarying;
|
varying vec2 texCoordVarying;
|
||||||
|
@ -17,7 +15,9 @@ float median(float r, float g, float b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
float screenPxRange() {
|
float screenPxRange() {
|
||||||
return 2.0;
|
vec2 unitRange = vec2(pxRange)/vec2(textureSize(msdf));
|
||||||
|
vec2 screenTexSize = vec2(1.0)/fwidth(texCoordVarying);
|
||||||
|
return max(0.5*dot(unitRange, screenTexSize), 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
|
@ -25,10 +25,8 @@ void main()
|
||||||
vec4 bgColor = vec4(fontColor.rgb,0);
|
vec4 bgColor = vec4(fontColor.rgb,0);
|
||||||
vec4 fgColor = fontColor;
|
vec4 fgColor = fontColor;
|
||||||
|
|
||||||
vec3 msd_0 = texture2DRect(msdf_0, texCoordVarying).rgb;
|
vec3 msdf_rgb = texture2DRect(msdf, texCoordVarying).rgb;
|
||||||
vec3 msd_1 = texture2DRect(msdf_1, texCoordVarying).rgb;
|
float sd = median(msdf_rgb.r, msdf_rgb.g, msdf_rgb.b);
|
||||||
vec3 msd = mix(msd_0, msd_1,msdf_mix);
|
|
||||||
float sd = median(msd.r, msd.g, msd.b);
|
|
||||||
float screenPxDistance = screenPxRange()*(sd - 0.5);
|
float screenPxDistance = screenPxRange()*(sd - 0.5);
|
||||||
float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0);
|
float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0);
|
||||||
gl_FragColor = mix(bgColor, fgColor, opacity);
|
gl_FragColor = mix(bgColor, fgColor, opacity);
|
||||||
|
|
|
@ -2,12 +2,15 @@
|
||||||
precision highp float;
|
precision highp float;
|
||||||
|
|
||||||
// these are our textures
|
// these are our textures
|
||||||
uniform sampler2DRect msdf_0;
|
uniform sampler2DRect msdf;
|
||||||
uniform sampler2DRect msdf_1;
|
|
||||||
|
|
||||||
uniform vec4 fontColor;
|
uniform vec4 fontColor;
|
||||||
|
uniform vec2 unitRange;
|
||||||
uniform float msdf_mix;
|
uniform float msdf_mix;
|
||||||
uniform float msdf_pxratio;
|
uniform vec2 translation_a;
|
||||||
|
uniform vec2 scale_a;
|
||||||
|
uniform vec2 translation_b;
|
||||||
|
uniform vec2 scale_b;
|
||||||
|
|
||||||
// this comes from the vertex shader
|
// this comes from the vertex shader
|
||||||
in vec2 texCoordVarying;
|
in vec2 texCoordVarying;
|
||||||
|
@ -19,20 +22,39 @@ float median(float r, float g, float b) {
|
||||||
return max(min(r, g), min(max(r, g), b));
|
return max(min(r, g), min(max(r, g), b));
|
||||||
}
|
}
|
||||||
|
|
||||||
float screenPxRange(float ratio) {
|
float screenPxRange() {
|
||||||
return ratio * 2.0;
|
//vec2 unitRange = vec2(pxRange)/vec2(textureSize(msdf));
|
||||||
|
vec2 screenTexSize = vec2(1.0)/fwidth(texCoordVarying);
|
||||||
|
return max(0.5*dot(unitRange, screenTexSize), 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
float screenPxDistance(vec3 msdf_rgb) {
|
||||||
|
float sd = median(msdf_rgb.r, msdf_rgb.g, msdf_rgb.b);
|
||||||
|
return screenPxRange()*(sd - 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 bgColor = vec4(fontColor.rgb,0);
|
vec4 bgColor = vec4(fontColor.rgb,0.0);
|
||||||
vec4 fgColor = fontColor;
|
vec4 fgColor = fontColor;
|
||||||
|
|
||||||
vec3 msd_0 = texture(msdf_0, texCoordVarying).rgb;
|
vec2 texCoord_a = (texCoordVarying * scale_a) + translation_a;
|
||||||
vec3 msd_1 = texture(msdf_1, texCoordVarying).rgb;
|
vec2 texCoord_b = (texCoordVarying * scale_b) + translation_b;
|
||||||
vec3 msd = mix(msd_0, msd_1,msdf_mix);
|
|
||||||
float sd = median(msd.r, msd.g, msd.b);
|
vec3 msdf_rgb_total = texture(msdf, texCoordVarying).rgb;
|
||||||
float screenPxDistance = screenPxRange(msdf_pxratio)*(sd - 0.5);
|
vec3 msdf_rgb_a = texture(msdf, texCoord_a).rgb;
|
||||||
float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0);
|
vec3 msdf_rgb_b = texture(msdf, texCoord_b).rgb;
|
||||||
outputColor = mix(bgColor, fgColor, opacity);
|
float screenPxDistance_a = screenPxDistance(msdf_rgb_a);
|
||||||
|
float screenPxDistance_b = screenPxDistance(msdf_rgb_b);
|
||||||
|
float screenPxDistance_mix = mix(screenPxDistance_a, screenPxDistance_b, msdf_mix);
|
||||||
|
|
||||||
|
float opacity = clamp(screenPxDistance_mix + 0.5, 0.0, 1.0);
|
||||||
|
|
||||||
|
if (opacity < 0.5)
|
||||||
|
discard;
|
||||||
|
outputColor = vec4(vec3(fgColor),1.0); //mix(bgColor, fgColor, opacity);
|
||||||
|
|
||||||
|
//outputColor = vec4(opacity, 1.0-opacity, 0.0, 1.0);
|
||||||
|
//outputColor = vec4(1.0-msdf_rgb.rgb, 1.0);
|
||||||
|
//outputColor = vec4(1.0,0.0,1.0,1.0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue