gles 3 shaders
This commit is contained in:
parent
c4252e6748
commit
21c7c3efd0
2 changed files with 50 additions and 0 deletions
35
data/ofxMsdfgen/shaders/simple/ES3/shader.frag
Normal file
35
data/ofxMsdfgen/shaders/simple/ES3/shader.frag
Normal file
|
@ -0,0 +1,35 @@
|
|||
#version 300 es
|
||||
precision highp float;
|
||||
|
||||
// these are our textures
|
||||
uniform sampler2D msdf;
|
||||
|
||||
uniform vec4 fontColor;
|
||||
uniform float pxRange;
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 bgColor = vec4(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);
|
||||
outputColor = mix(bgColor, fgColor, opacity);
|
||||
}
|
15
data/ofxMsdfgen/shaders/simple/ES3/shader.vert
Normal file
15
data/ofxMsdfgen/shaders/simple/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