Merge branch 'reinvdwoerd-master'

This commit is contained in:
Edwin Jakobs
2020-02-16 17:47:14 +01:00
2 changed files with 85 additions and 0 deletions

View File

@@ -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
}
}

View File

@@ -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);
vec3 demultiplied = color.a == 0.0 ? vec3(0.0) : color.rgb/color.a;
o_color = vec4(crosshatch(demultiplied, t1, t2, t3, t4), 1.0) * color.a;
}