diff --git a/orx-fx/src/main/kotlin/dither/Crosshatch.kt b/orx-fx/src/main/kotlin/dither/Crosshatch.kt new file mode 100644 index 00000000..b4006e2d --- /dev/null +++ b/orx-fx/src/main/kotlin/dither/Crosshatch.kt @@ -0,0 +1,30 @@ +package org.openrndr.extra.fx.dither + +import org.openrndr.draw.Filter +import org.openrndr.draw.Shader +import org.openrndr.extra.fx.filterFragmentCode +import org.openrndr.extra.parameters.Description +import org.openrndr.extra.parameters.DoubleParameter + + +@Description("Crosshatch") +class Crosshatch: Filter(Shader.createFromCode(filterVertexCode, filterFragmentCode("dither/crosshatch.frag"))) { + @DoubleParameter("threshold 1", 0.0, 1.0) + var t1: Double by parameters + + @DoubleParameter("threshold 2", 0.0, 1.0) + var t2: Double by parameters + + @DoubleParameter("threshold 3", 0.0, 1.0) + var t3: Double by parameters + + @DoubleParameter("threshold 4", 0.0, 1.0) + var t4: Double by parameters + + init { + t1 = 1.0 + t2 = 0.75 + t3 = 0.5 + t4 = 0.3 + } +} \ No newline at end of file diff --git a/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/dither/crosshatch.frag b/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/dither/crosshatch.frag new file mode 100644 index 00000000..8397a225 --- /dev/null +++ b/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/dither/crosshatch.frag @@ -0,0 +1,55 @@ +#version 330 + +in vec2 v_texCoord0; +uniform sampler2D tex0; +out vec4 o_color; + +// thresholds +uniform float t1; +uniform float t2; +uniform float t3; +uniform float t4; + + +// glsl-luma +float luma(vec3 color) { + return dot(color, vec3(0.299, 0.587, 0.114)); +} + +float luma(vec4 color) { + return dot(color.rgb, vec3(0.299, 0.587, 0.114)); +} + +// glsl-crosshatch +vec3 crosshatch(vec3 texColor, float t1, float t2, float t3, float t4) { + float lum = luma(texColor); + vec3 color = vec3(1.0); + if (lum < t1) { + if (mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) { + color = vec3(0.0); + } + } + if (lum < t2) { + if (mod(gl_FragCoord.x - gl_FragCoord.y, 10.0) == 0.0) { + color = vec3(0.0); + } + } + if (lum < t3) { + if (mod(gl_FragCoord.x + gl_FragCoord.y - 5.0, 10.0) == 0.0) { + color = vec3(0.0); + } + } + if (lum < t4) { + if (mod(gl_FragCoord.x - gl_FragCoord.y - 5.0, 10.0) == 0.0) { + color = vec3(0.0); + } + } + return color; +} + + +void main() { + vec4 color = texture(tex0, v_texCoord0); + o_color.rgb = crosshatch(color.rgb, t1, t2, t3, t4); + o_color.a = color.a; +} \ No newline at end of file