mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
Fixing morphological shaders code
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
uniform float Radius;
|
||||
#define MAX_SIZE 5
|
||||
|
||||
vec3 dilation (sampler2D source, vec2 uv, vec2 uv_step, float R) {
|
||||
vec3 dilation (sampler2D source, vec2 uv, vec2 uv_step, float rad) {
|
||||
|
||||
vec3 maxValue = vec3(0.0);
|
||||
float D = length(vec2( R / 2.));
|
||||
float R = length(vec2(rad)) ;
|
||||
float D = rad;
|
||||
|
||||
for (float i=-R; i <= R; ++i)
|
||||
for (float i=-rad; i <= rad; ++i)
|
||||
{
|
||||
for (float j=-R; j <= R; ++j)
|
||||
for (float j=-rad; j <= rad; ++j)
|
||||
{
|
||||
vec2 delta = vec2(i, j);
|
||||
maxValue = max(texture(source, uv + delta * smoothstep(R, D, length(delta)) * uv_step ).rgb, maxValue);
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
uniform float Radius;
|
||||
#define MAX_SIZE 5
|
||||
|
||||
vec3 erosion (sampler2D source, vec2 uv, vec2 uv_step, float R)
|
||||
vec3 erosion (sampler2D source, vec2 uv, vec2 uv_step, float rad)
|
||||
{
|
||||
vec3 minValue = vec3(1.0);
|
||||
float D = length(vec2( R / 2.));
|
||||
float R = length(vec2(rad)) ;
|
||||
float D = rad;
|
||||
|
||||
for (float i=-R; i <= R; ++i)
|
||||
for (float i=-rad; i <= rad; ++i)
|
||||
{
|
||||
for (float j=-R; j <= R; ++j)
|
||||
for (float j=-rad; j <= rad; ++j)
|
||||
{
|
||||
vec2 delta = vec2(i, j);
|
||||
minValue = min(texture(source, uv + delta * smoothstep(R, D, length(delta)) * uv_step ).rgb, minValue);
|
||||
|
||||
@@ -14,31 +14,31 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
|
||||
int rad = int(Radius * 10.0);
|
||||
|
||||
vec2 src_size = iResolution.xy;
|
||||
vec2 uv_step = 1.0 / iResolution.xy;
|
||||
vec2 uv = fragCoord.xy / iResolution.xy;
|
||||
float n = float((rad + 1) * (rad + 1));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Bilateral difference-check, to speed up the processing of large flat areas //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
vec3 compare = texture(iChannel0, uv / src_size).rgb;
|
||||
vec3 compare = texture(iChannel0, uv).rgb;
|
||||
bool diffpix = false;
|
||||
for (int j = -rad; j <= rad; ++j) {
|
||||
if (texture(iChannel0, uv + vec2(0,j) / src_size).rgb != compare) {
|
||||
if (texture(iChannel0, uv + vec2(0,j) * uv_step).rgb != compare) {
|
||||
diffpix = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!diffpix) {
|
||||
for (int i = -rad; i <= rad; ++i) {
|
||||
if (texture(iChannel0, uv + vec2(i,0) / src_size).rgb != compare) {
|
||||
if (texture(iChannel0, uv + vec2(i,0) * uv_step).rgb != compare) {
|
||||
diffpix = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!diffpix) {
|
||||
outpix = vec4( texture(iChannel0, uv / src_size).rgb, 1.0);
|
||||
outpix = vec4( texture(iChannel0, uv).rgb, 1.0);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -49,10 +49,13 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
m[k] = vec3(0.0);
|
||||
s[k] = vec3(0.0);
|
||||
}
|
||||
float R = 0.1;
|
||||
float D = length(vec2(rad));
|
||||
|
||||
for (int j = -rad; j <= 0; ++j) {
|
||||
for (int i = -rad; i <= 0; ++i) {
|
||||
vec3 c = texture(iChannel0, uv + vec2(i,j) / src_size).rgb;
|
||||
vec2 delta = vec2(i, j);
|
||||
vec3 c = texture(iChannel0, uv + delta * smoothstep(R, D, length(delta)) * uv_step).rgb;
|
||||
m[0] += c;
|
||||
s[0] += c * c;
|
||||
}
|
||||
@@ -60,7 +63,8 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
|
||||
for (int j = -rad; j <= 0; ++j) {
|
||||
for (int i = 0; i <= rad; ++i) {
|
||||
vec3 c = texture(iChannel0, uv + vec2(i,j) / src_size).rgb;
|
||||
vec2 delta = vec2(i, j);
|
||||
vec3 c = texture(iChannel0, uv + delta * smoothstep(R, D, length(delta)) * uv_step).rgb;
|
||||
m[1] += c;
|
||||
s[1] += c * c;
|
||||
}
|
||||
@@ -68,7 +72,8 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
|
||||
for (int j = 0; j <= rad; ++j) {
|
||||
for (int i = 0; i <= rad; ++i) {
|
||||
vec3 c = texture(iChannel0, uv + vec2(i,j) / src_size).rgb;
|
||||
vec2 delta = vec2(i, j);
|
||||
vec3 c = texture(iChannel0, uv + delta * smoothstep(R, D, length(delta)) * uv_step).rgb;
|
||||
m[2] += c;
|
||||
s[2] += c * c;
|
||||
}
|
||||
@@ -76,7 +81,8 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
|
||||
for (int j = 0; j <= rad; ++j) {
|
||||
for (int i = -rad; i <= 0; ++i) {
|
||||
vec3 c = texture(iChannel0, uv + vec2(i,j) / src_size).rgb;
|
||||
vec2 delta = vec2(i, j);
|
||||
vec3 c = texture(iChannel0, uv + delta * smoothstep(R, D, length(delta)) * uv_step).rgb;
|
||||
m[3] += c;
|
||||
s[3] += c * c;
|
||||
}
|
||||
@@ -97,4 +103,3 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
fragColor = outpix;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user