Add screenshot generation
This commit is contained in:
30
orx-fx/src/demo/kotlin/DemoFluidDistort01.kt
Normal file
30
orx-fx/src/demo/kotlin/DemoFluidDistort01.kt
Normal file
@@ -0,0 +1,30 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.draw.colorBuffer
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.fx.distort.FluidDistort
|
||||
import org.openrndr.extra.fx.patterns.Checkers
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
val fd = FluidDistort()
|
||||
val checkers = Checkers()
|
||||
|
||||
val image = colorBuffer(width, height)
|
||||
val distorted = image.createEquivalent()
|
||||
checkers.size = 64.0
|
||||
checkers.apply(emptyArray(), image)
|
||||
|
||||
if (System.getProperty("takeScreenshot") == "true") {
|
||||
extend(SingleScreenshot()) {
|
||||
this.outputFile = System.getProperty("screenshotPath")
|
||||
}
|
||||
}
|
||||
extend {
|
||||
fd.blend = mouse.position.x/width
|
||||
fd.apply(image, distorted)
|
||||
drawer.image(distorted)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
orx-fx/src/main/kotlin/color/Colorspaces.kt
Normal file
8
orx-fx/src/main/kotlin/color/Colorspaces.kt
Normal file
@@ -0,0 +1,8 @@
|
||||
package org.openrndr.extra.fx.color
|
||||
|
||||
import org.openrndr.draw.Filter
|
||||
import org.openrndr.draw.filterShaderFromUrl
|
||||
import org.openrndr.extra.fx.filterFragmentUrl
|
||||
|
||||
class RgbToYCbcr : Filter(filterShaderFromUrl(filterFragmentUrl("color/rgb-to-ycbcr.frag")))
|
||||
class YcbcrToRgb : Filter(filterShaderFromUrl(filterFragmentUrl("color/ycbcr-to-rgb.frag")))
|
||||
68
orx-fx/src/main/kotlin/distort/FluidDistort.kt
Normal file
68
orx-fx/src/main/kotlin/distort/FluidDistort.kt
Normal file
@@ -0,0 +1,68 @@
|
||||
package org.openrndr.extra.fx.distort
|
||||
|
||||
import org.openrndr.draw.ColorBuffer
|
||||
import org.openrndr.draw.Filter
|
||||
import org.openrndr.draw.filterShaderFromUrl
|
||||
import org.openrndr.extra.fx.filterFragmentUrl
|
||||
import kotlin.math.cos
|
||||
|
||||
private class UVMap: Filter(filterShaderFromUrl(filterFragmentUrl("distort/uvmap.frag"))) {
|
||||
|
||||
}
|
||||
|
||||
private class FluidDistortFilter : Filter(filterShaderFromUrl(filterFragmentUrl("distort/fluid-distort.frag"))) {
|
||||
var blend : Double by parameters
|
||||
var random: Double by parameters
|
||||
init {
|
||||
blend = 0.0
|
||||
random = 0.0
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class FluidDistort : Filter() {
|
||||
var blend: Double = 1.0
|
||||
|
||||
var outputUV = false
|
||||
|
||||
private val distort = FluidDistortFilter()
|
||||
private val uvmap = UVMap()
|
||||
|
||||
private var buffer0: ColorBuffer? = null
|
||||
private var buffer1: ColorBuffer? = null
|
||||
private var index = 0
|
||||
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
|
||||
|
||||
distort.blend = blend
|
||||
distort.random = cos(index*0.5)*0.5+0.5
|
||||
|
||||
buffer0?.let {
|
||||
if (!it.isEquivalentTo(target[0])) {
|
||||
it.destroy()
|
||||
}
|
||||
}
|
||||
if (buffer0 == null) {
|
||||
buffer0 = target[0].createEquivalent()
|
||||
}
|
||||
|
||||
buffer1?.let {
|
||||
if (!it.isEquivalentTo(target[0])) {
|
||||
it.destroy()
|
||||
}
|
||||
}
|
||||
if (buffer1 == null) {
|
||||
buffer1 = target[0].createEquivalent()
|
||||
}
|
||||
val buffers = arrayOf(buffer0!!, buffer1!!)
|
||||
distort.apply(buffers[index%2], buffers[(index+1)%2])
|
||||
|
||||
if (!outputUV) {
|
||||
uvmap.apply(arrayOf(buffers[(index + 1) % 2], source[0]), target[0])
|
||||
} else {
|
||||
buffers[(index+1)%2].copyTo(target[0])
|
||||
}
|
||||
index++
|
||||
blend = 0.0
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,9 +2,8 @@ package org.openrndr.extra.fx.distort
|
||||
|
||||
import org.openrndr.draw.*
|
||||
import org.openrndr.extra.fx.filterFragmentUrl
|
||||
import org.openrndr.extra.parameters.Description
|
||||
import org.openrndr.extra.parameters.DoubleParameter
|
||||
import org.openrndr.extra.parameters.IntParameter
|
||||
import org.openrndr.extra.parameters.*
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.math.Vector4
|
||||
|
||||
@@ -15,37 +14,41 @@ class Perturb : Filter(filterShaderFromUrl(filterFragmentUrl("distort/perturb.fr
|
||||
/**
|
||||
* base noise scale, default is Vector3(1.0, 1.0, 1.0)
|
||||
*/
|
||||
@DoubleParameter("scale", 0.01, 8.0)
|
||||
@DoubleParameter("scale", 0.01, 8.0, order = 0)
|
||||
var scale: Double by parameters
|
||||
|
||||
@DoubleParameter("phase", -2.0, 2.0)
|
||||
@DoubleParameter("phase", -2.0, 2.0, order = 1)
|
||||
var phase: Double by parameters
|
||||
|
||||
/**
|
||||
* lacunarity is the amount by which scale is modulated per octave, default is Vector3(2.0, 2.0, 2.0)
|
||||
*/
|
||||
@DoubleParameter("lacunarity", 0.0, 1.0)
|
||||
@DoubleParameter("lacunarity", 0.0, 1.0, order = 2)
|
||||
var lacunarity: Double by parameters
|
||||
|
||||
@DoubleParameter("gain", 0.0, 1.0)
|
||||
@DoubleParameter("gain", 0.0, 1.0, order = 3)
|
||||
var gain: Double by parameters
|
||||
|
||||
@DoubleParameter("decay", 0.0, 1.0)
|
||||
@DoubleParameter("decay", 0.0, 1.0, order = 4)
|
||||
var decay: Double by parameters
|
||||
|
||||
/**
|
||||
* the number of octaves of noise to generate, default is 4
|
||||
*/
|
||||
@IntParameter("octaves", 1, 10)
|
||||
@IntParameter("octaves", 1, 10, order = 5)
|
||||
var octaves: Int by parameters
|
||||
|
||||
|
||||
@IntParameter("x segments", 0, 256)
|
||||
@IntParameter("x segments", 0, 256, order = 6)
|
||||
var xSegments: Int by parameters
|
||||
|
||||
@IntParameter("y segments", 0, 256)
|
||||
@IntParameter("y segments", 0, 256, order = 7)
|
||||
var ySegments: Int by parameters
|
||||
|
||||
@BooleanParameter("output UV", order = 8)
|
||||
var outputUV: Boolean by parameters
|
||||
|
||||
@Vector2Parameter("offset", -1.0, 1.0, order = 9)
|
||||
var offset: Vector2 by parameters
|
||||
|
||||
|
||||
init {
|
||||
@@ -58,6 +61,8 @@ class Perturb : Filter(filterShaderFromUrl(filterFragmentUrl("distort/perturb.fr
|
||||
phase = 0.0
|
||||
xSegments = 0
|
||||
ySegments = 0
|
||||
outputUV = false
|
||||
offset = Vector2.ZERO
|
||||
|
||||
}
|
||||
var bicubicFiltering = true
|
||||
@@ -68,5 +73,4 @@ class Perturb : Filter(filterShaderFromUrl(filterFragmentUrl("distort/perturb.fr
|
||||
}
|
||||
super.apply(source, target)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#version 330
|
||||
|
||||
uniform vec4 tint;
|
||||
in vec2 v_texCoord0;
|
||||
uniform sampler2D tex0;
|
||||
|
||||
out vec4 o_color;
|
||||
void main() {
|
||||
vec4 c = texture(tex0, v_texCoord0);
|
||||
if (c.a != 0.0) {
|
||||
c.rgb /= c.a;
|
||||
}
|
||||
c.rgb *= 255.0;
|
||||
float y = 0.0 + 0.299 * c.r + 0.587 * c.g + 0.114 * c.b;
|
||||
float cb = 128 - (0.168736 * c.r) - (0.331264 * c.g) + (0.5 * c.b);
|
||||
float cr = 128 + (0.5 * c.r) - 0.418688 * c.g - 0.081312 * c.b;
|
||||
o_color = vec4(y/255.0, cb/255.0, cr/255.0, 1.0) * c.a;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#version 330
|
||||
|
||||
uniform vec4 tint;
|
||||
in vec2 v_texCoord0;
|
||||
uniform sampler2D tex0;
|
||||
|
||||
out vec4 o_color;
|
||||
void main() {
|
||||
vec2 ts = textureSize(tex0, 0);
|
||||
vec4 c = texture(tex0, v_texCoord0);
|
||||
|
||||
if (c.a != 0.0) {
|
||||
c.rgb /= c.a;
|
||||
}
|
||||
c.rgb *= 255.0;
|
||||
|
||||
float y = c.r;
|
||||
float cb = c.g;
|
||||
float cr = c.b;
|
||||
|
||||
float r = y + 1.402 * (cr - 128.0);
|
||||
float g = y - 0.344136 * (cb - 128.0) - 0.714136 * (cr - 128.0);
|
||||
float b = y + 1.772 * (cb - 128.0);
|
||||
|
||||
o_color = vec4(r/255.0, g/255.0, b/255.0, 1.0) * c.a;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
#version 330
|
||||
|
||||
// created by florian berger (flockaroo) - 2016
|
||||
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
|
||||
|
||||
// single pass CFD
|
||||
// ---------------
|
||||
// this is some "computational flockarooid dynamics" ;)
|
||||
// the self-advection is done purely rotational on all scales.
|
||||
// therefore i dont need any divergence-free velocity field.
|
||||
// with stochastic sampling i get the proper "mean values" of rotations
|
||||
// over time for higher order scales.
|
||||
//
|
||||
// try changing "RotNum" for different accuracies of rotation calculation
|
||||
// for even RotNum uncomment the line #define SUPPORT_EVEN_ROTNUM
|
||||
|
||||
#define RotNum 5
|
||||
//#define SUPPORT_EVEN_ROTNUM
|
||||
|
||||
//#define keyTex iChannel3
|
||||
//#define KEY_I texture(keyTex,vec2((105.5-32.0)/256.0,(0.5+0.0)/3.0)).x
|
||||
|
||||
const float ang = 2.0*3.1415926535/float(RotNum);
|
||||
mat2 m = mat2(cos(ang), sin(ang), -sin(ang), cos(ang));
|
||||
mat2 mh = mat2(cos(ang*0.5), sin(ang*0.5), -sin(ang*0.5), cos(ang*0.5));
|
||||
|
||||
uniform sampler2D tex0;
|
||||
uniform float time;
|
||||
uniform float random;
|
||||
|
||||
in vec2 v_texCoord0;
|
||||
uniform vec2 targetSize;
|
||||
|
||||
uniform float blend;
|
||||
|
||||
out vec4 o_color;
|
||||
|
||||
float getRot(vec2 pos, vec2 b) {
|
||||
vec2 Res = textureSize(tex0, 0);
|
||||
vec2 p = b;
|
||||
float rot = 0.0;
|
||||
for (int i = 0; i < RotNum; i++) {
|
||||
rot += dot(texture(tex0, fract((pos + p) / Res.xy)).xy -vec2(0.5), p.yx * vec2(1, -1));
|
||||
p = m * p;
|
||||
}
|
||||
return rot / float(RotNum)/dot(b, b);
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 pos = v_texCoord0 * targetSize;
|
||||
vec2 Res = textureSize(tex0, 0);
|
||||
|
||||
vec2 b = vec2(cos(ang * random), sin(ang * random));
|
||||
vec2 v = vec2(0);
|
||||
float bbMax = 0.5 * Res.y;
|
||||
bbMax *= bbMax;
|
||||
for (int l = 0; l < 20; l++) {
|
||||
if (dot(b, b) > bbMax) break;
|
||||
vec2 p = b;
|
||||
for (int i = 0; i < RotNum; i++) {
|
||||
#ifdef SUPPORT_EVEN_ROTNUM
|
||||
v += p.yx * getRot(pos + p, -mh * b);
|
||||
#else
|
||||
// this is faster but works only for odd RotNum
|
||||
v += p.yx * getRot(pos + p, b);
|
||||
#endif
|
||||
p = m*p;
|
||||
}
|
||||
b *= 2.0;
|
||||
}
|
||||
o_color = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
o_color.xy = texture(tex0, fract((pos + v * vec2(-1, 1) * 2.0) / Res.xy)).xy * (1.0-blend) + v_texCoord0 * blend;
|
||||
}
|
||||
@@ -15,6 +15,9 @@ uniform sampler2D tex0;
|
||||
uniform int xSegments;
|
||||
uniform int ySegments;
|
||||
|
||||
uniform bool outputUV;
|
||||
uniform vec2 offset;
|
||||
|
||||
// varyings
|
||||
in vec2 v_texCoord0;
|
||||
|
||||
@@ -143,7 +146,7 @@ void main() {
|
||||
vec3 xseed = vec3(seed.xy, seed.z+cos(phase*3.1415926535));
|
||||
vec3 yseed = vec3(seed.yx, seed.z+sin(phase*3.1415926535));
|
||||
|
||||
vec3 uv = vec3(v_texCoord0, 1.0) * 2.0 - 1.0;
|
||||
vec3 uv = vec3(v_texCoord0 + offset, 1.0) * 2.0 - 1.0;
|
||||
vec3 px = ((segment(uv, xSegments, ySegments) + xseed) * scale);
|
||||
vec3 py = ((segment(uv, xSegments, ySegments) + yseed + vec3(100.37, 40.51, 9.43)) * scale);
|
||||
|
||||
@@ -157,14 +160,17 @@ void main() {
|
||||
|
||||
vec2 distCoord = v_texCoord0 + vec2(tx, ty);
|
||||
|
||||
if (distCoord.x >= 0.0 && distCoord.y >= 0.0 && distCoord.x < 1.0 && distCoord.y < 1.0) {
|
||||
|
||||
if (xSegments == 0 && ySegments == 0) {
|
||||
o_output = texture(tex0, distCoord);
|
||||
if (!outputUV) {
|
||||
if (distCoord.x >= 0.0 && distCoord.y >= 0.0 && distCoord.x < 1.0 && distCoord.y < 1.0) {
|
||||
if (xSegments == 0 && ySegments == 0) {
|
||||
o_output = texture(tex0, distCoord);
|
||||
} else {
|
||||
o_output = textureLod(tex0, distCoord, 0.0);
|
||||
}
|
||||
} else {
|
||||
o_output = textureLod(tex0, distCoord, 0.0);
|
||||
o_output = vec4(0.0);
|
||||
}
|
||||
} else {
|
||||
o_output = vec4(0.0);
|
||||
o_output = vec4(distCoord, 0.0, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#version 330 core
|
||||
|
||||
in vec2 v_texCoord0;
|
||||
uniform sampler2D tex0;// uvmap
|
||||
uniform sampler2D tex1;// input
|
||||
out vec4 o_color;
|
||||
|
||||
void main() {
|
||||
vec2 uv = texture(tex0, v_texCoord0).xy;
|
||||
o_color = texture(tex1, uv);
|
||||
}
|
||||
Reference in New Issue
Block a user