From f5ab40aad6410c44ac9df8182dbaad0ea36b8c65 Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Mon, 1 Feb 2021 21:19:34 +0100 Subject: [PATCH] [orx-fx] Add noiseGain and noiseSeed to MipBloom --- orx-fx/src/demo/kotlin/DemoBlur01.kt | 1 + orx-fx/src/main/kotlin/blur/MipBloom.kt | 19 +++++++-- .../extra/fx/gl3/blur/bloom-upscale.frag | 40 ++++++++++--------- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/orx-fx/src/demo/kotlin/DemoBlur01.kt b/orx-fx/src/demo/kotlin/DemoBlur01.kt index 025c5606..ec52850b 100644 --- a/orx-fx/src/demo/kotlin/DemoBlur01.kt +++ b/orx-fx/src/demo/kotlin/DemoBlur01.kt @@ -82,6 +82,7 @@ fun main() { blur.window = 5 blur.sigma = 3.0 blur.gain = 3.0 + blur.noiseSeed = seconds } is FrameBlur -> { blur.blend = 0.05 diff --git a/orx-fx/src/main/kotlin/blur/MipBloom.kt b/orx-fx/src/main/kotlin/blur/MipBloom.kt index 9330a8d7..46f2bc1d 100644 --- a/orx-fx/src/main/kotlin/blur/MipBloom.kt +++ b/orx-fx/src/main/kotlin/blur/MipBloom.kt @@ -17,12 +17,14 @@ class BloomDownscale : Filter(filterShaderFromUrl(filterFragmentUrl("blur/bloom- class BloomUpscale : Filter(filterShaderFromUrl(filterFragmentUrl("blur/bloom-upscale.frag"))) { var gain: Double by parameters var shape: Double by parameters - var seed: Double by parameters + var noiseSeed: Double by parameters + var noiseGain: Double by parameters init { gain = 1.0 shape = 1.0 - seed = 1.0 + noiseSeed = 1.0 + noiseGain = 0.25 } } @@ -46,6 +48,15 @@ open class MipBloom(val blur: T) : Filter(filterShaderFromUrl(filter @DoubleParameter("gain", 0.0, 4.0) var gain: Double = 1.0 + /** + * noise gain. low noise gains will result in visible banding of the image. default value is 0.25 + */ + @DoubleParameter("noise gain", 0.0, 1.0) + var noiseGain: Double = 0.25 + + @DoubleParameter("noise seed", 0.0, 1000.0) + var noiseSeed: Double = 0.0 + @BooleanParameter("sRGB") var sRGB = true @@ -89,6 +100,8 @@ open class MipBloom(val blur: T) : Filter(filterShaderFromUrl(filter linearize.apply(sourceCopy!!, sourceCopy!!) } + upscale.noiseGain = noiseGain + upscale.noiseSeed = noiseSeed downScale.apply(sourceCopy!!, intermediates[0]) blur.apply(intermediates[0], intermediates[0]) @@ -131,7 +144,6 @@ class HashBloom : MipBloom(blur = HashBlur()) { @Description("Gaussian bloom") class GaussianBloom : MipBloom(blur = GaussianBlur()) { - /** * blur sample window, default value is 5 */ @@ -144,6 +156,7 @@ class GaussianBloom : MipBloom(blur = GaussianBlur()) { @DoubleParameter("kernel sigma", 0.0, 25.0) var sigma: Double = 1.0 + override fun apply(source: Array, target: Array) { blur.window = window blur.sigma = sigma diff --git a/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/blur/bloom-upscale.frag b/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/blur/bloom-upscale.frag index 6ced4502..3e70de42 100644 --- a/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/blur/bloom-upscale.frag +++ b/orx-fx/src/main/resources/org/openrndr/extra/fx/gl3/blur/bloom-upscale.frag @@ -5,10 +5,12 @@ float nrand(vec2 n) { } // -- based on https://github.com/excess-demogroup/even-laster-engine/blob/a451a89f6bd6d3c6017d5890b92d9f72823bc742/src/shaders/bloom_upscale.frag -uniform float seed; +uniform float noiseSeed; uniform float shape; uniform float gain; +uniform float noiseGain; + in vec2 v_texCoord0; out vec4 o_output; @@ -25,51 +27,51 @@ vec4 sampleBloom(vec2 pos, float shape) { { float weight = pow(0.0, shape); - vec2 rnd = vec2(nrand(3 + 0.0 + pos.xy + seed), - nrand(5 + 0.0 + pos.yx - seed)); + vec2 rnd = vec2(nrand(3 + 0.0 + pos.xy + noiseSeed), + nrand(5 + 0.0 + pos.yx - noiseSeed)); rnd = (rnd * 2 - 1) / textureSize(tex0, 0); - sum += textureLod(tex0, pos + rnd * 0.25, 0.0) * weight; + sum += textureLod(tex0, pos + rnd * noiseGain, 0.0) * weight; total += weight; } { float weight = pow(1.0, shape); - vec2 rnd = vec2(nrand(3 + 0.0 + pos.xy + seed), - nrand(5 + 0.0 + pos.yx - seed)); + vec2 rnd = vec2(nrand(3 + 0.0 + pos.xy + noiseSeed), + nrand(5 + 0.0 + pos.yx - noiseSeed)); rnd = (rnd * 2 - 1) / textureSize(tex1, 0); - sum += textureLod(tex1, pos + rnd * 0.25, 0.0) * weight; + sum += textureLod(tex1, pos + rnd * noiseGain, 0.0) * weight; total += weight; } { float weight = pow(2.0, shape); - vec2 rnd = vec2(nrand(3 + 0.0 + pos.xy + seed), - nrand(5 + 0.0 + pos.yx - seed)); + vec2 rnd = vec2(nrand(3 + 0.0 + pos.xy + noiseSeed), + nrand(5 + 0.0 + pos.yx - noiseSeed)); rnd = (rnd * 2 - 1) / textureSize(tex2, 0); - sum += textureLod(tex2, pos + rnd * 0.25, 0.0) * weight; + sum += textureLod(tex2, pos + rnd * noiseGain, 0.0) * weight; total += weight; } { float weight = pow(3.0, shape); - vec2 rnd = vec2(nrand(3 + 0.0 + pos.xy + seed), - nrand(5 + 0.0 + pos.yx - seed)); + vec2 rnd = vec2(nrand(3 + 0.0 + pos.xy + noiseSeed), + nrand(5 + 0.0 + pos.yx - noiseSeed)); rnd = (rnd * 3 - 1) / textureSize(tex3, 0); - sum += textureLod(tex3, pos + rnd * 0.25, 0.0) * weight; + sum += textureLod(tex3, pos + rnd * noiseGain, 0.0) * weight; total += weight; } { float weight = pow(4.0, shape); - vec2 rnd = vec2(nrand(3 + 0.0 + pos.xy + seed), - nrand(5 + 0.0 + pos.yx - seed)); + vec2 rnd = vec2(nrand(3 + 0.0 + pos.xy + noiseSeed), + nrand(5 + 0.0 + pos.yx - noiseSeed)); rnd = (rnd * 3 - 1) / textureSize(tex3, 0); - sum += textureLod(tex4, pos + rnd * 0.25, 0.0) * weight; + sum += textureLod(tex4, pos + rnd * noiseGain, 0.0) * weight; total += weight; } { float weight = pow(5.0, shape); - vec2 rnd = vec2(nrand(3 + 0.0 + pos.xy + seed), - nrand(5 + 0.0 + pos.yx - seed)); + vec2 rnd = vec2(nrand(3 + 0.0 + pos.xy + noiseSeed), + nrand(5 + 0.0 + pos.yx - noiseSeed)); rnd = (rnd * 3 - 1) / textureSize(tex3, 0); - sum += textureLod(tex5, pos + rnd * 0.25, 0.0) * weight; + sum += textureLod(tex5, pos + rnd * noiseGain, 0.0) * weight; total += weight; }