calc unitRange on cpu
This commit is contained in:
parent
21c7c3efd0
commit
ea928d0190
8 changed files with 190 additions and 0 deletions
32
data/ofxMsdfgen/shaders/unitRange/ES2/shader.frag
Normal file
32
data/ofxMsdfgen/shaders/unitRange/ES2/shader.frag
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
precision highp float;
|
||||||
|
|
||||||
|
// these are our textures
|
||||||
|
uniform sampler2D msdf;
|
||||||
|
|
||||||
|
uniform vec4 fontColor;
|
||||||
|
uniform float pxRange;
|
||||||
|
|
||||||
|
// this comes from the vertex shader
|
||||||
|
varying vec2 texCoordVarying;
|
||||||
|
|
||||||
|
float median(float r, float g, float b) {
|
||||||
|
return max(min(r, g), min(max(r, g), b));
|
||||||
|
}
|
||||||
|
|
||||||
|
float screenPxRange() {
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
vec4 bgColor = vec4(fontColor.rgb,0);
|
||||||
|
vec4 fgColor = fontColor;
|
||||||
|
|
||||||
|
vec3 msdf_rgb = texture2D(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);
|
||||||
|
gl_FragColor = mix(bgColor, fgColor, opacity);
|
||||||
|
}
|
14
data/ofxMsdfgen/shaders/unitRange/ES2/shader.vert
Normal file
14
data/ofxMsdfgen/shaders/unitRange/ES2/shader.vert
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
|
||||||
|
// these are for the programmable pipeline system
|
||||||
|
uniform mat4 modelViewProjectionMatrix;
|
||||||
|
|
||||||
|
attribute vec4 position;
|
||||||
|
attribute vec2 texcoord;
|
||||||
|
|
||||||
|
varying vec2 texCoordVarying;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
texCoordVarying = texcoord;
|
||||||
|
gl_Position = modelViewProjectionMatrix * position;
|
||||||
|
}
|
35
data/ofxMsdfgen/shaders/unitRange/ES3/shader.frag
Normal file
35
data/ofxMsdfgen/shaders/unitRange/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 unitRange;
|
||||||
|
|
||||||
|
// 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/unitRange/ES3/shader.vert
Normal file
15
data/ofxMsdfgen/shaders/unitRange/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;
|
||||||
|
}
|
33
data/ofxMsdfgen/shaders/unitRange/GL2/shader.frag
Normal file
33
data/ofxMsdfgen/shaders/unitRange/GL2/shader.frag
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#version 120
|
||||||
|
precision highp float;
|
||||||
|
|
||||||
|
// these are our textures
|
||||||
|
uniform sampler2DRect msdf_0;
|
||||||
|
|
||||||
|
uniform vec4 fontColor;
|
||||||
|
uniform float pxRange;
|
||||||
|
|
||||||
|
// this comes from the vertex shader
|
||||||
|
varying vec2 texCoordVarying;
|
||||||
|
|
||||||
|
float median(float r, float g, float b) {
|
||||||
|
return max(min(r, g), min(max(r, g), b));
|
||||||
|
}
|
||||||
|
|
||||||
|
float screenPxRange() {
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
vec4 bgColor = vec4(fontColor.rgb,0);
|
||||||
|
vec4 fgColor = fontColor;
|
||||||
|
|
||||||
|
vec3 msdf_rgb = texture2DRect(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);
|
||||||
|
gl_FragColor = mix(bgColor, fgColor, opacity);
|
||||||
|
}
|
9
data/ofxMsdfgen/shaders/unitRange/GL2/shader.vert
Normal file
9
data/ofxMsdfgen/shaders/unitRange/GL2/shader.vert
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#version 120
|
||||||
|
|
||||||
|
varying vec2 texCoordVarying;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
texCoordVarying = gl_MultiTexCoord0.xy;
|
||||||
|
gl_Position = ftransform();
|
||||||
|
}
|
36
data/ofxMsdfgen/shaders/unitRange/GL3/shader.frag
Normal file
36
data/ofxMsdfgen/shaders/unitRange/GL3/shader.frag
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#version 150
|
||||||
|
precision highp float;
|
||||||
|
|
||||||
|
// these are our textures
|
||||||
|
uniform sampler2DRect msdf;
|
||||||
|
|
||||||
|
uniform vec4 fontColor;
|
||||||
|
uniform float unitRange;
|
||||||
|
|
||||||
|
// this comes from the vertex shader
|
||||||
|
in vec2 texCoordVarying;
|
||||||
|
|
||||||
|
// this is the output of the fragment shader
|
||||||
|
out vec4 outputColor;
|
||||||
|
|
||||||
|
float median(float r, float g, float b) {
|
||||||
|
return max(min(r, g), min(max(r, g), b));
|
||||||
|
}
|
||||||
|
|
||||||
|
float screenPxRange() {
|
||||||
|
//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()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
16
data/ofxMsdfgen/shaders/unitRange/GL3/shader.vert
Normal file
16
data/ofxMsdfgen/shaders/unitRange/GL3/shader.vert
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#version 150
|
||||||
|
|
||||||
|
// these come from the programmable pipeline
|
||||||
|
uniform mat4 modelViewProjectionMatrix;
|
||||||
|
|
||||||
|
in vec4 position;
|
||||||
|
in vec2 texcoord;
|
||||||
|
|
||||||
|
// texture coordinates are sent to fragment shader
|
||||||
|
out vec2 texCoordVarying;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
texCoordVarying = texcoord;
|
||||||
|
gl_Position = modelViewProjectionMatrix * position;
|
||||||
|
}
|
Loading…
Reference in a new issue