[orx-fx] Fix GLES compatibility for FrameBlur and MipBloom
This commit is contained in:
@@ -4,6 +4,7 @@ package org.openrndr.extra.fx.blur
|
|||||||
|
|
||||||
import org.openrndr.color.ColorRGBa
|
import org.openrndr.color.ColorRGBa
|
||||||
import org.openrndr.draw.*
|
import org.openrndr.draw.*
|
||||||
|
import org.openrndr.extra.fx.blend.Passthrough
|
||||||
import org.openrndr.extra.fx.fx_frame_blur
|
import org.openrndr.extra.fx.fx_frame_blur
|
||||||
import org.openrndr.extra.fx.mppFilterShader
|
import org.openrndr.extra.fx.mppFilterShader
|
||||||
import org.openrndr.extra.parameters.Description
|
import org.openrndr.extra.parameters.Description
|
||||||
@@ -17,7 +18,10 @@ class FrameBlur(val colorType: ColorType = ColorType.FLOAT16) :
|
|||||||
@DoubleParameter("blend", 0.0, 1.0)
|
@DoubleParameter("blend", 0.0, 1.0)
|
||||||
var blend: Double by parameters
|
var blend: Double by parameters
|
||||||
|
|
||||||
|
|
||||||
|
val pt = Passthrough()
|
||||||
private var intermediate: ColorBuffer? = null
|
private var intermediate: ColorBuffer? = null
|
||||||
|
private var intermediate2: ColorBuffer? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
blend = 0.5
|
blend = 0.5
|
||||||
@@ -32,14 +36,26 @@ class FrameBlur(val colorType: ColorType = ColorType.FLOAT16) :
|
|||||||
intermediate = null
|
intermediate = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
intermediate2?.let {
|
||||||
|
if (it.isEquivalentTo(target[0], ignoreFormat = true, ignoreLevels = true)) {
|
||||||
|
it.destroy()
|
||||||
|
intermediate2 = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (intermediate == null) {
|
if (intermediate == null) {
|
||||||
intermediate = target[0].createEquivalent(type = colorType)
|
intermediate = target[0].createEquivalent(type = colorType)
|
||||||
intermediate?.fill(ColorRGBa.TRANSPARENT)
|
intermediate?.fill(ColorRGBa.TRANSPARENT)
|
||||||
}
|
}
|
||||||
|
if (intermediate2 == null) {
|
||||||
|
intermediate2 = target[0].createEquivalent(type = colorType)
|
||||||
|
intermediate2?.fill(ColorRGBa.TRANSPARENT)
|
||||||
|
}
|
||||||
|
|
||||||
super.apply(arrayOf(source[0], intermediate!!), arrayOf(intermediate!!), clip)
|
super.apply(arrayOf(source[0], intermediate!!), arrayOf(intermediate2!!), clip)
|
||||||
intermediate!!.copyTo(target[0])
|
|
||||||
|
pt.apply(intermediate2!!, intermediate!!)
|
||||||
|
pt.apply(intermediate!!, target[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,12 +66,8 @@ open class MipBloom<T : Filter>(val blur: T) : Filter1to1(mppFilterShader(fx_blo
|
|||||||
|
|
||||||
@DoubleParameter("noise seed", 0.0, 1000.0)
|
@DoubleParameter("noise seed", 0.0, 1000.0)
|
||||||
var noiseSeed: Double = 0.0
|
var noiseSeed: Double = 0.0
|
||||||
|
|
||||||
@BooleanParameter("sRGB")
|
|
||||||
var sRGB = true
|
|
||||||
|
|
||||||
var intermediates = mutableListOf<ColorBuffer>()
|
var intermediates = mutableListOf<ColorBuffer>()
|
||||||
var sourceCopy: ColorBuffer? = null
|
var blurred = mutableListOf<ColorBuffer>()
|
||||||
|
|
||||||
val upscale = BloomUpscale()
|
val upscale = BloomUpscale()
|
||||||
val downScale = BloomDownscale()
|
val downScale = BloomDownscale()
|
||||||
@@ -79,17 +75,6 @@ open class MipBloom<T : Filter>(val blur: T) : Filter1to1(mppFilterShader(fx_blo
|
|||||||
|
|
||||||
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, clip: Rectangle?) {
|
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, clip: Rectangle?) {
|
||||||
require(clip == null)
|
require(clip == null)
|
||||||
sourceCopy?.let {
|
|
||||||
if (!it.isEquivalentTo(source[0], ignoreType = true)) {
|
|
||||||
it.destroy()
|
|
||||||
sourceCopy = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (sourceCopy == null) {
|
|
||||||
sourceCopy = source[0].createEquivalent(type = ColorType.FLOAT16)
|
|
||||||
}
|
|
||||||
|
|
||||||
source[0].copyTo(sourceCopy!!)
|
|
||||||
|
|
||||||
upscale.shape = shape
|
upscale.shape = shape
|
||||||
if (intermediates.size != passes
|
if (intermediates.size != passes
|
||||||
@@ -97,38 +82,35 @@ open class MipBloom<T : Filter>(val blur: T) : Filter1to1(mppFilterShader(fx_blo
|
|||||||
intermediates.forEach {
|
intermediates.forEach {
|
||||||
it.destroy()
|
it.destroy()
|
||||||
}
|
}
|
||||||
|
blurred.forEach {
|
||||||
|
it.destroy()
|
||||||
|
}
|
||||||
intermediates.clear()
|
intermediates.clear()
|
||||||
|
blurred.clear()
|
||||||
|
|
||||||
for (pass in 0 until passes) {
|
for (pass in 0 until passes) {
|
||||||
val tdiv = 1 shl (pass + 1)
|
val tdiv = 1 shl (pass + 1)
|
||||||
val cb = colorBuffer(target[0].width / tdiv, target[0].height / tdiv, type = ColorType.FLOAT16)
|
val cb = colorBuffer(target[0].width / tdiv, target[0].height / tdiv, type = ColorType.FLOAT32)
|
||||||
intermediates.add(cb)
|
intermediates.add(cb)
|
||||||
|
val cbb = colorBuffer(target[0].width / tdiv, target[0].height / tdiv, type = ColorType.FLOAT32)
|
||||||
|
blurred.add(cbb)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (sRGB) {
|
|
||||||
linearize.apply(sourceCopy!!, sourceCopy!!, clip)
|
|
||||||
}
|
|
||||||
|
|
||||||
upscale.noiseGain = noiseGain
|
upscale.noiseGain = noiseGain
|
||||||
upscale.noiseSeed = noiseSeed
|
upscale.noiseSeed = noiseSeed
|
||||||
downScale.apply(sourceCopy!!, intermediates[0], clip)
|
downScale.apply(source[0], intermediates[0], clip)
|
||||||
blur.apply(intermediates[0], intermediates[0], clip)
|
blur.apply(intermediates[0], blurred[0], clip)
|
||||||
|
|
||||||
for (pass in 1 until passes) {
|
for (pass in 1 until passes) {
|
||||||
downScale.apply(intermediates[pass - 1], intermediates[pass], clip)
|
downScale.apply(blurred[pass - 1], intermediates[pass], clip)
|
||||||
blur.apply(intermediates[pass], intermediates[pass], clip)
|
blur.apply(intermediates[pass], blurred[pass], clip)
|
||||||
}
|
}
|
||||||
|
|
||||||
upscale.apply(intermediates.toTypedArray(), arrayOf(target[0]), clip)
|
upscale.apply(blurred.toTypedArray(), arrayOf(target[0]), clip)
|
||||||
combine.gain = gain
|
combine.gain = gain
|
||||||
combine.pregain = pregain
|
combine.pregain = pregain
|
||||||
combine.apply(arrayOf(sourceCopy!!, target[0]), target, clip)
|
combine.apply(arrayOf(source[0], target[0]), target, clip)
|
||||||
|
|
||||||
if (sRGB) {
|
|
||||||
delinearize.apply(target[0], target[0], clip)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,11 +19,7 @@ void main() {
|
|||||||
for (int x = -w; x <= w; ++x) {
|
for (int x = -w; x <= w; ++x) {
|
||||||
float lw = exp( float(-(x*x)) / (2.0 * sigma * sigma) ) ;
|
float lw = exp( float(-(x*x)) / (2.0 * sigma * sigma) ) ;
|
||||||
vec2 tc = v_texCoord0 + float(x) * blurDirection * s;// * spread;
|
vec2 tc = v_texCoord0 + float(x) * blurDirection * s;// * spread;
|
||||||
#ifndef OR_WEBGL2
|
sum += texture(tex0, tc) * lw;
|
||||||
sum += textureLod(tex0, tc, float(sourceLevel)) * lw;
|
|
||||||
#else
|
|
||||||
sum += texture(tex0, tc);
|
|
||||||
#endif
|
|
||||||
weight += lw;
|
weight += lw;
|
||||||
}
|
}
|
||||||
o_color = (sum / weight) * gain;
|
o_color = (sum / weight) * gain;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
out vec4 o_output;
|
highp out vec4 o_output;
|
||||||
in vec2 v_texCoord0;
|
highp in vec2 v_texCoord0;
|
||||||
uniform sampler2D tex0;
|
uniform highp sampler2D tex0;
|
||||||
|
|
||||||
|
|
||||||
// -- based on https://github.com/excess-demogroup/even-laster-engine/blob/a451a89f6bd6d3c6017d5890b92d9f72823bc742/src/shaders/bloom.fra
|
// -- based on https://github.com/excess-demogroup/even-laster-engine/blob/a451a89f6bd6d3c6017d5890b92d9f72823bc742/src/shaders/bloom.fra
|
||||||
@@ -11,9 +11,9 @@ void main()
|
|||||||
vec4 offsets = vec4(-diagonalOffsets.xy, +diagonalOffsets.xy) / vec2(textureSize(tex0, 0)).xyxy;
|
vec4 offsets = vec4(-diagonalOffsets.xy, +diagonalOffsets.xy) / vec2(textureSize(tex0, 0)).xyxy;
|
||||||
float diagonalWeight = 0.2085034734347498;
|
float diagonalWeight = 0.2085034734347498;
|
||||||
|
|
||||||
o_output = textureLod(tex0, v_texCoord0, 0.0) * centerWeight +
|
o_output = texture(tex0, v_texCoord0) * centerWeight +
|
||||||
textureLod(tex0, v_texCoord0 + offsets.xy, 0.0) * diagonalWeight +
|
texture(tex0, v_texCoord0 + offsets.xy) * diagonalWeight +
|
||||||
textureLod(tex0, v_texCoord0 + offsets.wx, 0.0) * diagonalWeight +
|
texture(tex0, v_texCoord0 + offsets.wx) * diagonalWeight +
|
||||||
textureLod(tex0, v_texCoord0 + offsets.zw, 0.0) * diagonalWeight +
|
texture(tex0, v_texCoord0 + offsets.zw) * diagonalWeight +
|
||||||
textureLod(tex0, v_texCoord0 + offsets.yz, 0.0) * diagonalWeight;
|
texture(tex0, v_texCoord0 + offsets.yz) * diagonalWeight;
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,6 @@ float nrand(vec2 n) {
|
|||||||
uniform float noiseSeed;
|
uniform float noiseSeed;
|
||||||
uniform float shape;
|
uniform float shape;
|
||||||
uniform float gain;
|
uniform float gain;
|
||||||
|
|
||||||
uniform float noiseGain;
|
uniform float noiseGain;
|
||||||
|
|
||||||
in vec2 v_texCoord0;
|
in vec2 v_texCoord0;
|
||||||
@@ -28,7 +27,7 @@ vec4 sampleBloom(vec2 pos, float shape) {
|
|||||||
vec2 rnd = vec2(nrand(3.0 + 0.0 + pos.xy + noiseSeed),
|
vec2 rnd = vec2(nrand(3.0 + 0.0 + pos.xy + noiseSeed),
|
||||||
nrand(5.0 + 0.0 + pos.yx - noiseSeed));
|
nrand(5.0 + 0.0 + pos.yx - noiseSeed));
|
||||||
rnd = (rnd * 2.0 - 1.0) / vec2(textureSize(tex0, 0));
|
rnd = (rnd * 2.0 - 1.0) / vec2(textureSize(tex0, 0));
|
||||||
sum += textureLod(tex0, pos + rnd * noiseGain, 0.0) * weight;
|
sum += texture(tex0, pos + rnd * noiseGain) * weight;
|
||||||
total += weight;
|
total += weight;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@@ -36,7 +35,7 @@ vec4 sampleBloom(vec2 pos, float shape) {
|
|||||||
vec2 rnd = vec2(nrand(3.0 + 0.0 + pos.xy + noiseSeed),
|
vec2 rnd = vec2(nrand(3.0 + 0.0 + pos.xy + noiseSeed),
|
||||||
nrand(5.0 + 0.0 + pos.yx - noiseSeed));
|
nrand(5.0 + 0.0 + pos.yx - noiseSeed));
|
||||||
rnd = (rnd * 2.0 - 1.0) / vec2(textureSize(tex0, 0));
|
rnd = (rnd * 2.0 - 1.0) / vec2(textureSize(tex0, 0));
|
||||||
sum += textureLod(tex1, pos + rnd * noiseGain, 0.0) * weight;
|
sum += texture(tex1, pos + rnd * noiseGain, 0.0) * weight;
|
||||||
total += weight;
|
total += weight;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@@ -44,7 +43,7 @@ vec4 sampleBloom(vec2 pos, float shape) {
|
|||||||
vec2 rnd = vec2(nrand(3.0 + 0.0 + pos.xy + noiseSeed),
|
vec2 rnd = vec2(nrand(3.0 + 0.0 + pos.xy + noiseSeed),
|
||||||
nrand(5.0 + 0.0 + pos.yx - noiseSeed));
|
nrand(5.0 + 0.0 + pos.yx - noiseSeed));
|
||||||
rnd = (rnd * 2.0 - 1.0) / vec2(textureSize(tex0, 0));
|
rnd = (rnd * 2.0 - 1.0) / vec2(textureSize(tex0, 0));
|
||||||
sum += textureLod(tex2, pos + rnd * noiseGain, 0.0) * weight;
|
sum += texture(tex2, pos + rnd * noiseGain) * weight;
|
||||||
total += weight;
|
total += weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +52,7 @@ vec4 sampleBloom(vec2 pos, float shape) {
|
|||||||
vec2 rnd = vec2(nrand(3.0 + 0.0 + pos.xy + noiseSeed),
|
vec2 rnd = vec2(nrand(3.0 + 0.0 + pos.xy + noiseSeed),
|
||||||
nrand(5.0 + 0.0 + pos.yx - noiseSeed));
|
nrand(5.0 + 0.0 + pos.yx - noiseSeed));
|
||||||
rnd = (rnd * 3.0 - 1.0) / vec2(textureSize(tex0, 0));
|
rnd = (rnd * 3.0 - 1.0) / vec2(textureSize(tex0, 0));
|
||||||
sum += textureLod(tex3, pos + rnd * noiseGain, 0.0) * weight;
|
sum += texture(tex3, pos + rnd * noiseGain) * weight;
|
||||||
total += weight;
|
total += weight;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@@ -61,7 +60,7 @@ vec4 sampleBloom(vec2 pos, float shape) {
|
|||||||
vec2 rnd = vec2(nrand(3.0 + 0.0 + pos.xy + noiseSeed),
|
vec2 rnd = vec2(nrand(3.0 + 0.0 + pos.xy + noiseSeed),
|
||||||
nrand(5.0 + 0.0 + pos.yx - noiseSeed));
|
nrand(5.0 + 0.0 + pos.yx - noiseSeed));
|
||||||
rnd = (rnd * 3.0 - 1.0) / vec2(textureSize(tex0, 0));
|
rnd = (rnd * 3.0 - 1.0) / vec2(textureSize(tex0, 0));
|
||||||
sum += textureLod(tex4, pos + rnd * noiseGain, 0.0) * weight;
|
sum += texture(tex4, pos + rnd * noiseGain) * weight;
|
||||||
total += weight;
|
total += weight;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@@ -69,7 +68,7 @@ vec4 sampleBloom(vec2 pos, float shape) {
|
|||||||
vec2 rnd = vec2(nrand(3.0 + 0.0 + pos.xy + noiseSeed),
|
vec2 rnd = vec2(nrand(3.0 + 0.0 + pos.xy + noiseSeed),
|
||||||
nrand(5.0 + 0.0 + pos.yx - noiseSeed));
|
nrand(5.0 + 0.0 + pos.yx - noiseSeed));
|
||||||
rnd = (rnd * 3.0 - 1.0) / vec2(textureSize(tex0, 0));
|
rnd = (rnd * 3.0 - 1.0) / vec2(textureSize(tex0, 0));
|
||||||
sum += textureLod(tex5, pos + rnd * noiseGain, 0.0) * weight;
|
sum += texture(tex5, pos + rnd * noiseGain) * weight;
|
||||||
total += weight;
|
total += weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,24 +6,20 @@ uniform float sigma;
|
|||||||
uniform float spread;
|
uniform float spread;
|
||||||
uniform float gain;
|
uniform float gain;
|
||||||
|
|
||||||
|
|
||||||
out vec4 o_color;
|
out vec4 o_color;
|
||||||
void main() {
|
void main() {
|
||||||
|
vec2 s = vec2(textureSize(tex0, 0).xy);
|
||||||
vec2 s = vec2(textureSize(tex0, 0).xy);
|
s = vec2(1.0 / s.x, 1.0 / s.y);
|
||||||
s = vec2(1.0/s.x, 1.0/s.y);
|
|
||||||
|
|
||||||
int w = window;
|
int w = window;
|
||||||
|
|
||||||
vec4 sum = vec4(0.0, 0.0, 0.0, 0.0);
|
vec4 sum = vec4(0.0, 0.0, 0.0, 0.0);
|
||||||
float weight = 0.0;
|
float weight = 0.0;
|
||||||
for (int y = -w; y<= w; ++y) {
|
for (int y = -w; y <= w; ++y) {
|
||||||
for (int x = -w; x<= w; ++x) {
|
for (int x = -w; x <= w; ++x) {
|
||||||
float lw = exp(-float(x*x+y*y) / (2.0 * sigma * sigma));
|
float lw = exp(-float(x * x + y * y) / (2.0 * sigma * sigma));
|
||||||
sum+=texture(tex0, v_texCoord0 + vec2(x, y) * s * spread) * lw;
|
sum += texture(tex0, v_texCoord0 + vec2(x, y) * s * 1.0) * lw;
|
||||||
weight+=lw;
|
weight += lw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
o_color = (sum / weight) * gain;
|
o_color = (sum / weight) * gain;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user