diff --git a/addon_config.mk b/addon_config.mk index 26352fc..35c03c5 100644 --- a/addon_config.mk +++ b/addon_config.mk @@ -54,7 +54,7 @@ common: # some addons need resources to be copied to the bin/data folder of the project # specify here any files that need to be copied, you can use wildcards like * and ? - # ADDON_DATA = + ADDON_DATA = data/ofxMsdfgen # when parsing the file system looking for libraries exclude this for all or # a specific platform diff --git a/data/ofxMsdfgen/shaders/ES2/shader.frag b/data/ofxMsdfgen/shaders/ES2/shader.frag new file mode 100644 index 0000000..d509ed2 --- /dev/null +++ b/data/ofxMsdfgen/shaders/ES2/shader.frag @@ -0,0 +1,34 @@ +precision highp float; + +// these are our textures +uniform sampler2D msdf_0; +uniform sampler2D msdf_1; + +uniform vec4 fontColor; +uniform float msdf_mix; +uniform float msdf_pxratio; + +// 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(float ratio) { + return ratio * 2.0; +} + +void main() +{ + vec4 bgColor = vec4(fontColor.rgb,0); + vec4 fgColor = fontColor; + + vec3 msd_0 = texture2D(msdf_0, texCoordVarying).rgb; + vec3 msd_1 = texture2D(msdf_1, texCoordVarying).rgb; + vec3 msd = mix(msd_0, msd_1,msdf_mix); + 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); + gl_FragColor = mix(bgColor, fgColor, opacity); +} diff --git a/data/ofxMsdfgen/shaders/ES2/shader.vert b/data/ofxMsdfgen/shaders/ES2/shader.vert new file mode 100644 index 0000000..2098e6d --- /dev/null +++ b/data/ofxMsdfgen/shaders/ES2/shader.vert @@ -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; +} \ No newline at end of file diff --git a/data/ofxMsdfgen/shaders/GL2/shader.frag b/data/ofxMsdfgen/shaders/GL2/shader.frag new file mode 100644 index 0000000..2226d46 --- /dev/null +++ b/data/ofxMsdfgen/shaders/GL2/shader.frag @@ -0,0 +1,35 @@ +#version 120 +precision highp float; + +// these are our textures +uniform sampler2DRect msdf_0; +uniform sampler2DRect msdf_1; + +uniform vec4 fontColor; +uniform float msdf_mix; +uniform float msdf_pxratio; + +// 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() { + return 2.0; +} + +void main() +{ + vec4 bgColor = vec4(fontColor.rgb,0); + vec4 fgColor = fontColor; + + vec3 msd_0 = texture2DRect(msdf_0, texCoordVarying).rgb; + vec3 msd_1 = texture2DRect(msdf_1, texCoordVarying).rgb; + 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 opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0); + gl_FragColor = mix(bgColor, fgColor, opacity); +} diff --git a/data/ofxMsdfgen/shaders/GL2/shader.vert b/data/ofxMsdfgen/shaders/GL2/shader.vert new file mode 100644 index 0000000..b7a5da6 --- /dev/null +++ b/data/ofxMsdfgen/shaders/GL2/shader.vert @@ -0,0 +1,9 @@ +#version 120 + +varying vec2 texCoordVarying; + +void main() +{ + texCoordVarying = gl_MultiTexCoord0.xy; + gl_Position = ftransform(); +} \ No newline at end of file diff --git a/data/ofxMsdfgen/shaders/GL3/shader.frag b/data/ofxMsdfgen/shaders/GL3/shader.frag new file mode 100644 index 0000000..4e8edc0 --- /dev/null +++ b/data/ofxMsdfgen/shaders/GL3/shader.frag @@ -0,0 +1,38 @@ +#version 150 +precision highp float; + +// these are our textures +uniform sampler2DRect msdf_0; +uniform sampler2DRect msdf_1; + +uniform vec4 fontColor; +uniform float msdf_mix; +uniform float msdf_pxratio; + +// 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(float ratio) { + return ratio * 2.0; +} + +void main() +{ + vec4 bgColor = vec4(fontColor.rgb,0); + vec4 fgColor = fontColor; + + vec3 msd_0 = texture(msdf_0, texCoordVarying).rgb; + vec3 msd_1 = texture(msdf_1, texCoordVarying).rgb; + vec3 msd = mix(msd_0, msd_1,msdf_mix); + 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); + outputColor = mix(bgColor, fgColor, opacity); +} diff --git a/data/ofxMsdfgen/shaders/GL3/shader.vert b/data/ofxMsdfgen/shaders/GL3/shader.vert new file mode 100644 index 0000000..0e63995 --- /dev/null +++ b/data/ofxMsdfgen/shaders/GL3/shader.vert @@ -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; +} \ No newline at end of file