From 4e241aca6cf0dda324a2dd0ffda75b3e47ca0428 Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Wed, 5 Feb 2020 14:15:42 +0100 Subject: [PATCH] Add ColorTint, LumaThreshold, HorizontalWave, VerticalWave, FrameBlur filters to orx-fx --- orx-fx/src/main/kotlin/blur/FrameBlur.kt | 41 +++++++++++++++++ orx-fx/src/main/kotlin/color/ColorMix.kt | 16 ++++++- orx-fx/src/main/kotlin/color/LumaThreshold.kt | 38 ++++++++++++++++ orx-fx/src/main/kotlin/distort/Wave.kt | 44 +++++++++++++++++++ .../extra/fx/gl3/blur/frame-blur.frag | 15 +++++++ .../extra/fx/gl3/color/color-tint.frag | 11 +++++ .../extra/fx/gl3/color/luma-threshold.frag | 18 ++++++++ .../extra/fx/gl3/distort/horizontal-wave.frag | 18 ++++++++ .../extra/fx/gl3/distort/vertical-wave.frag | 18 ++++++++ 9 files changed, 218 insertions(+), 1 deletion(-) create mode 100644 orx-fx/src/main/kotlin/blur/FrameBlur.kt create mode 100644 orx-fx/src/main/kotlin/color/LumaThreshold.kt create mode 100644 orx-fx/src/main/kotlin/distort/Wave.kt create mode 100644 orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/blur/frame-blur.frag create mode 100644 orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/color/color-tint.frag create mode 100644 orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/color/luma-threshold.frag create mode 100644 orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/distort/horizontal-wave.frag create mode 100644 orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/distort/vertical-wave.frag diff --git a/orx-fx/src/main/kotlin/blur/FrameBlur.kt b/orx-fx/src/main/kotlin/blur/FrameBlur.kt new file mode 100644 index 00000000..76a2b474 --- /dev/null +++ b/orx-fx/src/main/kotlin/blur/FrameBlur.kt @@ -0,0 +1,41 @@ +package org.openrndr.extra.fx.blur + +import org.openrndr.draw.* +import org.openrndr.extra.fx.filterFragmentCode +import org.openrndr.extra.parameters.Description +import org.openrndr.extra.parameters.DoubleParameter +import org.openrndr.extra.parameters.IntParameter + +@Description("Frame blur") +class FrameBlur : Filter(Shader.createFromCode(Filter.filterVertexCode, + filterFragmentCode("blur/frame-blur.frag"))) { + + @DoubleParameter("blend", 0.0, 1.0) + var blend: Double by parameters + + private var intermediate: ColorBuffer? = null + + init { + blend = 0.5 + } + + override fun apply(source: Array, target: Array) { + if (target.isNotEmpty()) { + intermediate?.let { + if (it.width != target[0].width || it.height != target[0].height) { + it.destroy() + intermediate = null + } + + } + + if (intermediate == null) { + intermediate = colorBuffer(target[0].width, target[0].height, type = ColorType.FLOAT16) + } + + super.apply(arrayOf(source[0], intermediate!!), arrayOf(intermediate!!)) + intermediate!!.copyTo(target[0]) + } + } + +} diff --git a/orx-fx/src/main/kotlin/color/ColorMix.kt b/orx-fx/src/main/kotlin/color/ColorMix.kt index 2c80c288..1f4f5b28 100644 --- a/orx-fx/src/main/kotlin/color/ColorMix.kt +++ b/orx-fx/src/main/kotlin/color/ColorMix.kt @@ -1,7 +1,21 @@ package org.openrndr.extra.fx.color +import org.openrndr.color.ColorRGBa import org.openrndr.draw.Filter import org.openrndr.draw.Shader import org.openrndr.extra.fx.filterFragmentCode +import org.openrndr.extra.parameters.ColorParameter +import org.openrndr.extra.parameters.Description -class ColorMix : Filter(Shader.createFromCode(Filter.filterVertexCode, filterFragmentCode("color/color-mix.frag"))) \ No newline at end of file +class ColorMix : Filter(Shader.createFromCode(Filter.filterVertexCode, filterFragmentCode("color/color-mix.frag"))) + +@Description("Tint") +class ColorTint : Filter(Shader.createFromCode(Filter.filterVertexCode, filterFragmentCode("color/color-tint.frag"))) { + @ColorParameter("tint") + var tint: ColorRGBa by parameters + + init { + tint = ColorRGBa.PINK + } + +} diff --git a/orx-fx/src/main/kotlin/color/LumaThreshold.kt b/orx-fx/src/main/kotlin/color/LumaThreshold.kt new file mode 100644 index 00000000..825923a0 --- /dev/null +++ b/orx-fx/src/main/kotlin/color/LumaThreshold.kt @@ -0,0 +1,38 @@ +package org.openrndr.extra.fx.color + +import org.openrndr.color.ColorRGBa +import org.openrndr.draw.Filter +import org.openrndr.draw.Shader +import org.openrndr.extra.fx.filterFragmentCode +import org.openrndr.extra.parameters.BooleanParameter +import org.openrndr.extra.parameters.ColorParameter +import org.openrndr.extra.parameters.Description +import org.openrndr.extra.parameters.DoubleParameter + +@Description("Luma threshold ") +class Threshold : Filter(Shader.createFromCode(Filter.filterVertexCode, filterFragmentCode("color/luma-threshold.frag"))) { + + @DoubleParameter("threshold value", 0.0, 1.0) + var threshold: Double by parameters + + @ColorParameter("foreground color") + var foreground: ColorRGBa by parameters + + @ColorParameter("background color") + var background: ColorRGBa by parameters + + @DoubleParameter("background opacity", 0.0, 1.0) + var backgroundOpacity: Double by parameters + + @DoubleParameter("foreground opacity", 0.0, 1.0) + var foregroundOpacity: Double by parameters + + init { + threshold = 0.5 + foreground = ColorRGBa.WHITE + background = ColorRGBa.BLACK + foregroundOpacity = 1.0 + backgroundOpacity = 1.0 + } + +} \ No newline at end of file diff --git a/orx-fx/src/main/kotlin/distort/Wave.kt b/orx-fx/src/main/kotlin/distort/Wave.kt new file mode 100644 index 00000000..e48dbb16 --- /dev/null +++ b/orx-fx/src/main/kotlin/distort/Wave.kt @@ -0,0 +1,44 @@ +package org.openrndr.extra.fx.distort + +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("Horizontal wave") +class HorizontalWave : Filter(Shader.createFromCode(filterVertexCode, filterFragmentCode("distort/horizontal-wave.frag"))) { + @DoubleParameter("frequency", 0.0, 64.0) + var frequency: Double by parameters + + @DoubleParameter("amplitude", 0.0, 1.0) + var amplitude: Double by parameters + + @DoubleParameter("phase", -0.5, 0.5) + var phase: Double by parameters + + init { + frequency = 1.0 + amplitude = 0.1 + phase = 0.0 + } +} + +@Description("Vertical wave") +class VerticalWave : Filter(Shader.createFromCode(filterVertexCode, filterFragmentCode("distort/vertical-wave.frag"))) { + @DoubleParameter("frequency", 0.0, 64.0) + var frequency: Double by parameters + + @DoubleParameter("amplitude", 0.0, 1.0) + var amplitude: Double by parameters + + @DoubleParameter("phase", -0.5, 0.5) + var phase: Double by parameters + + init { + frequency = 1.0 + amplitude = 0.1 + phase = 0.0 + } + +} \ No newline at end of file diff --git a/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/blur/frame-blur.frag b/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/blur/frame-blur.frag new file mode 100644 index 00000000..7bcf05ba --- /dev/null +++ b/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/blur/frame-blur.frag @@ -0,0 +1,15 @@ +// openrndr - gl3 - frame-blur + +#version 330 core + +in vec2 v_texCoord0; +uniform sampler2D tex0; // input image +uniform sampler2D tex1; // accumulator image +uniform float blend; +out vec4 o_color; +void main() { + + vec4 inputColor = texture(tex0, v_texCoord0); + vec4 accumulator = texture(tex1, v_texCoord0); + o_color = accumulator * (1.0 - blend) + inputColor * blend; +} \ No newline at end of file diff --git a/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/color/color-tint.frag b/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/color/color-tint.frag new file mode 100644 index 00000000..2bdd1414 --- /dev/null +++ b/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/color/color-tint.frag @@ -0,0 +1,11 @@ +#version 330 + +uniform vec4 tint; +in vec2 v_texCoord0; +uniform sampler2D tex0; + +out vec4 o_color; +void main() { + vec4 c = texture(tex0, v_texCoord0); + o_color = vec4(c.rgb * tint.rgb, c.a) * tint.a; +} \ No newline at end of file diff --git a/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/color/luma-threshold.frag b/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/color/luma-threshold.frag new file mode 100644 index 00000000..c82b1f75 --- /dev/null +++ b/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/color/luma-threshold.frag @@ -0,0 +1,18 @@ +#version 330 core + +in vec2 v_texCoord0; +uniform sampler2D tex0; // input +uniform vec4 foreground; +uniform vec4 background; +uniform float foregroundOpacity; +uniform float backgroundOpacity; +uniform float threshold; + +out vec4 o_color; +void main() { + vec4 c = texture(tex0, v_texCoord0); + vec4 fgc = foreground * foregroundOpacity; + vec4 bgc = background * backgroundOpacity; + float luma = dot(c.rgb, vec3(1.0/3.0)); + o_color = mix(bgc, fgc, step(threshold, luma )); +} diff --git a/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/distort/horizontal-wave.frag b/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/distort/horizontal-wave.frag new file mode 100644 index 00000000..8d22147c --- /dev/null +++ b/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/distort/horizontal-wave.frag @@ -0,0 +1,18 @@ +#version 330 core + +in vec2 v_texCoord0; +uniform sampler2D tex0; // input +uniform float phase; +uniform float amplitude; +uniform float frequency; + +out vec4 o_color; +void main() { + vec2 uv = v_texCoord0; + uv.x += amplitude * cos(uv.y * 3.1415926535 * frequency + phase * 3.1415926535); + if (uv.x >= 0.0 && uv.x < 1.0) { + o_color = texture(tex0, uv); + } else { + o_color = vec4(0.0); + } +} diff --git a/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/distort/vertical-wave.frag b/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/distort/vertical-wave.frag new file mode 100644 index 00000000..e11993aa --- /dev/null +++ b/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/distort/vertical-wave.frag @@ -0,0 +1,18 @@ +#version 330 core + +in vec2 v_texCoord0; +uniform sampler2D tex0; // input +uniform float phase; +uniform float amplitude; +uniform float frequency; + +out vec4 o_color; +void main() { + vec2 uv = v_texCoord0; + uv.y += amplitude * sin(uv.x * 3.1415926535 * frequency + phase * 3.1415926535); + if (uv.y >= 0.0 && uv.y < 1.0) { + o_color = texture(tex0, uv); + } else { + o_color = vec4(0.0); + } +}