add mix shader for ES3
TODO: translate shader
This commit is contained in:
parent
d4b86f5026
commit
cfb5502dd3
2 changed files with 74 additions and 0 deletions
59
data/ofxMsdfgen/shaders/mix/ES3/shader.frag
Normal file
59
data/ofxMsdfgen/shaders/mix/ES3/shader.frag
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
#version 300 es
|
||||||
|
precision highp float;
|
||||||
|
|
||||||
|
// these are our textures
|
||||||
|
uniform sampler2D msdf;
|
||||||
|
|
||||||
|
uniform vec4 fontColor;
|
||||||
|
uniform vec2 unitRange;
|
||||||
|
uniform float msdf_mix;
|
||||||
|
uniform vec2 translation_a;
|
||||||
|
uniform vec2 scale_a;
|
||||||
|
uniform vec2 translation_b;
|
||||||
|
uniform vec2 scale_b;
|
||||||
|
|
||||||
|
// this comes from the vertex shader
|
||||||
|
in vec2 texCoordVarying;
|
||||||
|
out vec4 outputColor;
|
||||||
|
|
||||||
|
float median(float r, float g, float b) {
|
||||||
|
return max(min(r, g), min(max(r, g), b));
|
||||||
|
}
|
||||||
|
|
||||||
|
float screenPxRange() {
|
||||||
|
//ivec2 ts = textureSize(msdf, 0);
|
||||||
|
//vec2 unitRange = vec2(pxRange)/vec2(ts);
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
vec4 bgColor = vec4(fontColor.rgb,0.0);
|
||||||
|
vec4 fgColor = fontColor;
|
||||||
|
|
||||||
|
vec2 texCoord_a = (texCoordVarying * scale_a) + translation_a;
|
||||||
|
vec2 texCoord_b = (texCoordVarying * scale_b) + translation_b;
|
||||||
|
|
||||||
|
vec3 msdf_rgb_total = texture(msdf, texCoordVarying).rgb;
|
||||||
|
vec3 msdf_rgb_a = texture(msdf, texCoord_a).rgb;
|
||||||
|
vec3 msdf_rgb_b = texture(msdf, texCoord_b).rgb;
|
||||||
|
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);
|
||||||
|
}
|
15
data/ofxMsdfgen/shaders/mix/ES3/shader.vert
Normal file
15
data/ofxMsdfgen/shaders/mix/ES3/shader.vert
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#version 300 es
|
||||||
|
|
||||||
|
// whoops these are for the programmable pipeline system
|
||||||
|
uniform mat4 modelViewProjectionMatrix;
|
||||||
|
|
||||||
|
in vec4 position;
|
||||||
|
in vec2 texcoord;
|
||||||
|
|
||||||
|
out vec2 texCoordVarying;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
texCoordVarying = texcoord;
|
||||||
|
gl_Position = modelViewProjectionMatrix * position;
|
||||||
|
}
|
Loading…
Reference in a new issue