From a0af51fdb42743b4f3e4a3bef6accd8b89d32bd6 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Sat, 25 Mar 2023 13:48:54 +0100 Subject: [PATCH] shader discard alpha < 0.5 quick fix for depth with treshold alpha later: depth peeling --- data/ofxMsdfgen/shaders/unitRange/ES3/shader.frag | 7 ++++++- data/ofxMsdfgen/shaders/unitRange/GL3/shader.frag | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/data/ofxMsdfgen/shaders/unitRange/ES3/shader.frag b/data/ofxMsdfgen/shaders/unitRange/ES3/shader.frag index 068261a..6c13664 100644 --- a/data/ofxMsdfgen/shaders/unitRange/ES3/shader.frag +++ b/data/ofxMsdfgen/shaders/unitRange/ES3/shader.frag @@ -24,7 +24,7 @@ float screenPxRange() { void main() { - vec4 bgColor = vec4(fontColor.rgb,0); + vec4 bgColor = vec4(fontColor.rgb,0.0); vec4 fgColor = fontColor; vec3 msdf_rgb = texture(msdf, texCoordVarying).rgb; @@ -32,6 +32,11 @@ void main() float screenPxDistance = screenPxRange()*(sd - 0.5); float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0); + if (opacity < 0.5) + discard; outputColor = 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); } diff --git a/data/ofxMsdfgen/shaders/unitRange/GL3/shader.frag b/data/ofxMsdfgen/shaders/unitRange/GL3/shader.frag index fb9188d..f039352 100644 --- a/data/ofxMsdfgen/shaders/unitRange/GL3/shader.frag +++ b/data/ofxMsdfgen/shaders/unitRange/GL3/shader.frag @@ -25,12 +25,14 @@ float screenPxRange() { void main() { - vec4 bgColor = vec4(fontColor.rgb,0); + vec4 bgColor = vec4(1.0-fontColor.rgb,0); vec4 fgColor = fontColor; vec3 msdf_rgb = texture(msdf, texCoordVarying).rgb; float sd = median(msdf_rgb.r, msdf_rgb.g, msdf_rgb.b); float screenPxDistance = screenPxRange()*(sd - 0.5); float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0); + if (opacity < 0.5) + discard; outputColor = mix(bgColor, fgColor, opacity); }