[orx-integral-image] Pad source image for npot inputs. Add demo

This commit is contained in:
Edwin Jakobs
2024-06-28 11:12:38 +02:00
parent ab04e6b001
commit b1f2984b3e
4 changed files with 133 additions and 84 deletions

View File

@@ -0,0 +1,42 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.*
import org.openrndr.extra.integralimage.*
fun main() = application {
configure {
width = 720
height = 720
}
program {
val fii = FastIntegralImage()
val target = colorBuffer(width, height, 1.0, ColorFormat.RGBa, ColorType.FLOAT32)
val rt = renderTarget(width, height) {
colorBuffer()
}
extend {
drawer.clear(ColorRGBa.PINK)
drawer.isolatedWithTarget(rt) {
drawer.ortho(rt)
drawer.clear(ColorRGBa.BLACK)
drawer.fill = ColorRGBa.PINK.shade(1.0)
drawer.circle(mouse.position, 128.0)
}
fii.apply(rt.colorBuffer(0), target)
// -- here we sample from the integral image
drawer.shadeStyle = shadeStyle {
fragmentTransform = """
float w = 64.0;
vec2 step = 1.0 / vec2(textureSize(image, 0));
vec4 t11 = texture(image, va_texCoord0 + step * vec2(w+1.0,w+1.0));
vec4 t01 = texture(image, va_texCoord0 + step * vec2(-w,w+1.0));
vec4 t00 = texture(image, va_texCoord0 + step * vec2(-w,-w));
vec4 t10 = texture(image, va_texCoord0 + step * vec2(w+1.0,-w));
x_fill = (t11 - t01 - t10 + t00) / ((2.0 * w +1.0) * (2.0 * w + 1.0));
""".trimIndent()
}
drawer.image(target)
}
}
}