[orx-fx] Add super sampling to Contour filter
This commit is contained in:
@@ -7,6 +7,7 @@ import org.openrndr.extra.fx.mppFilterShader
|
||||
import org.openrndr.extra.parameters.ColorParameter
|
||||
import org.openrndr.extra.parameters.Description
|
||||
import org.openrndr.extra.parameters.DoubleParameter
|
||||
import org.openrndr.extra.parameters.IntParameter
|
||||
|
||||
@Description("Contour")
|
||||
class Contour : Filter(mppFilterShader(fx_contour, "contour")) {
|
||||
@@ -25,11 +26,15 @@ class Contour : Filter(mppFilterShader(fx_contour, "contour")) {
|
||||
@ColorParameter("contour color")
|
||||
var contourColor: ColorRGBa by parameters
|
||||
|
||||
@IntParameter("window", 0, 10)
|
||||
var window: Int by parameters
|
||||
|
||||
init {
|
||||
levels = 6.0
|
||||
contourWidth = 0.4
|
||||
contourColor = ColorRGBa.BLACK
|
||||
backgroundOpacity = 1.0
|
||||
contourOpacity = 1.0
|
||||
window = 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,21 +6,28 @@ uniform float contourWidth;
|
||||
uniform float contourOpacity;
|
||||
uniform vec4 contourColor;
|
||||
uniform float backgroundOpacity;
|
||||
uniform int window;
|
||||
|
||||
float calc_contour(vec2 uv) {
|
||||
vec4 box = texture(tex0, uv);
|
||||
float v = sin(3.1415926535 * levels * dot(vec3(1.0/3.0),box.xyz));
|
||||
float level = floor(dot(vec3(1.0/3.0),box.xyz) * levels) / levels;
|
||||
float contour = 1.0 - smoothstep(0., contourWidth, 0.5 * abs(v) / fwidth(v));
|
||||
return contour;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 step = 1.0 / textureSize(tex0, 0);
|
||||
vec4 box = vec4(0.0);
|
||||
for (int j = -1; j <=1; ++j) {
|
||||
for (int i = -1; i <= 1; ++i) {
|
||||
box += texture(tex0, v_texCoord0 + step * vec2(i, j));
|
||||
float contour = 0.0;
|
||||
float weight = 0.0;
|
||||
|
||||
for (int i = -window; i <= window; ++i) {
|
||||
for (int j = -window; j <= window; ++j) {
|
||||
contour += calc_contour(v_texCoord0 + step/(window+1.0) * vec2(i, j));
|
||||
weight += 1.0;
|
||||
}
|
||||
}
|
||||
box /= 9.0;
|
||||
float v = sin(3.1415926535 * levels * dot(vec3(1.0/3.0),box.xyz));
|
||||
float level = floor(dot(vec3(1.0/3.0),box.xyz) * levels) / levels;
|
||||
//int plateauIndex = min(levels-1, int(level * levels));
|
||||
float contour = 1.0 - smoothstep(0., contourWidth, 0.5 * abs(v) / fwidth(v));
|
||||
|
||||
contour /= weight;
|
||||
vec4 t = texture(tex0, v_texCoord0);
|
||||
o_output = t * backgroundOpacity * (1.0-contour) + contour * contourColor * contourOpacity * t.a;
|
||||
}
|
||||
Reference in New Issue
Block a user