cgvirus / Olive-Editor-Community-Effects

A community effort to populate effects for Olive-Editor
60 stars 7 forks source link

"Denoise" not work #13

Closed ghost closed 5 years ago

ghost commented 5 years ago

Here is terminal log:

...
2019-04-11T13:25:09 [INFO] Vertex shader added successfully
2019-04-11T13:25:09 [WARNING] QOpenGLShader::compile(Fragment): 0:38(22): error: could not implicitly convert operands to arithmetic operator
0:38(18): error: no matching function for call to `min(error, float)'; candidates are:
0:38(18): error:    float min(float, float)
0:38(18): error:    vec2 min(vec2, float)
0:38(18): error:    vec3 min(vec3, float)
0:38(18): error:    vec4 min(vec4, float)
0:38(18): error:    vec2 min(vec2, vec2)
0:38(18): error:    vec3 min(vec3, vec3)
0:38(18): error:    vec4 min(vec4, vec4)
0:38(18): error:    int min(int, int)
0:38(18): error:    ivec2 min(ivec2, int)
0:38(18): error:    ivec3 min(ivec3, int)
0:38(18): error:    ivec4 min(ivec4, int)
0:38(18): error:    ivec2 min(ivec2, ivec2)
0:38(18): error:    ivec3 min(ivec3, ivec3)
0:38(18): error:    ivec4 min(ivec4, ivec4)
0:38(14): error: cannot construct `int' from a non-numeric data type
0:44(23): warning: `kSize' used uninitialized
0:46(9): warning: `kSize' used uninitialized
0:46(27): warning: `kSize' used uninitialized
0:54(14): warning: `kSize' used uninitialized
0:54(26): warning: `kSize' used uninitialized
0:56(14): warning: `kSize' used uninitialized
0:56(26): warning: `kSize' used uninitialized
0:59(52): warning: `kSize' used uninitialized
0:59(68): warning: `kSize' used uninitialized

2019-04-11T13:25:09 [WARNING] *** Problematic Fragment shader source code ***
#define lowp
#define mediump
#define highp
#line 1
/***

    Port of https://www.shadertoy.com/view/4dfGDH
    Adapted by CGVIRUS for the Olive-Editor Community

***/

uniform sampler2D tex;
varying vec2 vTexCoord;
uniform vec2 resolution;
const vec2 renderScale = vec2(1.,1.);

//Effects Parameter
uniform float sigma_s;
uniform float sigma_r;

#define MSIZE 30

float normpdf(in float x, in float sigma)
{
    return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;
}

float normpdf3(in vec3 v, in float sigma)
{
    return 0.39894*exp(-0.5*dot(v,v)/(sigma*sigma))/sigma;
}

void main()
{
    vec2 uv = gl_FragCoord.xy / resolution.xy;
    vec3 c = texture2D(tex, uv).rgb;
    {
        //declare stuff
        int kSize = int(min((MSIZE-1)/2., 1.5*(sigma_s*0.5)*renderScale.x));
        float kernel[MSIZE];
        vec3 final_colour = vec3(0.0);

        //create the 1-D kernel
        float Z = 0.0;
        for (int j = 0; j <= kSize; ++j)
        {
            kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j), (sigma_s*0.5)*renderScale.x);
        }

        vec3 cc;
        float factor;
        float bZ = 1.0/normpdf(0.0, (sigma_r*.001));
        //read out the texels
        for (int i=-kSize; i <= kSize; ++i)
        {
            for (int j=-kSize; j <= kSize; ++j)
            {
                cc = texture2D(tex, uv + (vec2(float(i),float(j))) / resolution.xy).rgb;
                factor = normpdf3(cc-c, (sigma_r*.001))*bZ*kernel[kSize+j]*kernel[kSize+i];
                Z += factor;
                final_colour += factor*cc;

            }
        }

        gl_FragColor = vec4(final_colour/Z, texture2D( tex, uv ).a);
    }
}

***
2019-04-11T13:25:09 [WARNING] Fragment shader could not be added
cgvirus commented 5 years ago

Possible reason: Older OpenGL profile. If not then feel free to reopen the issue.

MassiminoilTrace commented 5 years ago

I have the same issue too, I'm on Fedora Linux 29 KDE.

MassiminoilTrace commented 5 years ago

It seems to appear also a similar issue on other effects, such as "bokeh blur" and "Kaleidoscope". The others work fine.

cgvirus commented 5 years ago

@MassiminoilTrace can you replace this code with denoise.frag? just copy it and replace the code in denoise.frag. Also what is your GPU spec?

/***

    Port of https://www.shadertoy.com/view/4dfGDH
    Adapted by CGVIRUS for the Olive-Editor Community

***/

uniform sampler2D tex;
varying vec2 vTexCoord;
uniform vec2 resolution;
const vec2 renderScale = vec2(1.,1.);

//Effects Parameter
uniform float sigma_s;
uniform float sigma_r;

#define MSIZE 30.0

float normpdf(in float x, in float sigma)
{
    return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;
}

float normpdf3(in vec3 v, in float sigma)
{
    return 0.39894*exp(-0.5*dot(v,v)/(sigma*sigma))/sigma;
}

void main()
{
    vec2 uv = gl_FragCoord.xy / resolution.xy;
    vec3 c = texture2D(tex, uv).rgb;
    {
        //declare stuff
        int kSize = int(min((MSIZE-1)/2., 1.5*(sigma_s*0.5)*renderScale.x));
        float kernel[int(MSIZE)];
        vec3 final_colour = vec3(0.0);

        //create the 1-D kernel
        float Z = 0.0;
        for (int j = 0; j <= kSize; ++j)
        {
            kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j), (sigma_s*0.5)*renderScale.x);
        }

        vec3 cc;
        float factor;
        float bZ = 1.0/normpdf(0.0, (sigma_r*.001));
        //read out the texels
        for (int i=-kSize; i <= kSize; ++i)
        {
            for (int j=-kSize; j <= kSize; ++j)
            {
                cc = texture2D(tex, uv + (vec2(float(i),float(j))) / resolution.xy).rgb;
                factor = normpdf3(cc-c, (sigma_r*.001))*bZ*kernel[kSize+j]*kernel[kSize+i];
                Z += factor;
                final_colour += factor*cc;

            }
        }

        gl_FragColor = vec4(final_colour/Z, texture2D( tex, uv ).a);
    }
}
cgvirus commented 5 years ago

Also rather then similar would be nice to have some trace like terminal report. But I highly suspect it's happening due to hardware profile. The current hack may work for some older profiles as well as newer one. Let me know. Thanks.

MassiminoilTrace commented 5 years ago

Thank you for the fast response. I have a nvidia GTX 940 MX with "nouveau" linux drivers.

Here's the complete terminal output after adding the denoise effect.

2019-04-21T16:47:06 [WARNING] QOpenGLShader::compile(Fragment): 0:38(23): error: could not implicitly convert operands to arithmetic operator
0:38(22): error: operands to arithmetic operators must be numeric
0:38(18): error: no matching function for call to `min(error, float)'; candidates are:
0:38(18): error:    float min(float, float)
0:38(18): error:    vec2 min(vec2, float)
0:38(18): error:    vec3 min(vec3, float)
0:38(18): error:    vec4 min(vec4, float)
0:38(18): error:    vec2 min(vec2, vec2)
0:38(18): error:    vec3 min(vec3, vec3)
0:38(18): error:    vec4 min(vec4, vec4)
0:38(18): error:    int min(int, int)
0:38(18): error:    ivec2 min(ivec2, int)
0:38(18): error:    ivec3 min(ivec3, int)
0:38(18): error:    ivec4 min(ivec4, int)
0:38(18): error:    ivec2 min(ivec2, ivec2)
0:38(18): error:    ivec3 min(ivec3, ivec3)
0:38(18): error:    ivec4 min(ivec4, ivec4)
0:38(14): error: cannot construct `int' from a non-numeric data type
0:44(23): warning: `kSize' used uninitialized
0:46(9): warning: `kSize' used uninitialized
0:46(27): warning: `kSize' used uninitialized
0:54(14): warning: `kSize' used uninitialized
0:54(26): warning: `kSize' used uninitialized
0:56(14): warning: `kSize' used uninitialized
0:56(26): warning: `kSize' used uninitialized
0:59(52): warning: `kSize' used uninitialized
0:59(68): warning: `kSize' used uninitialized

2019-04-21T16:47:06 [WARNING] *** Problematic Fragment shader source code ***
#define lowp
#define mediump
#define highp
#line 1
/***

    Port of https://www.shadertoy.com/view/4dfGDH
    Adapted by CGVIRUS for the Olive-Editor Community

***/

uniform sampler2D tex;
varying vec2 vTexCoord;
uniform vec2 resolution;
const vec2 renderScale = vec2(1.,1.);

//Effects Parameter
uniform float sigma_s;
uniform float sigma_r;

#define MSIZE 30.0

float normpdf(in float x, in float sigma)
{
        return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;
}

float normpdf3(in vec3 v, in float sigma)
{
        return 0.39894*exp(-0.5*dot(v,v)/(sigma*sigma))/sigma;
}

void main()
{
        vec2 uv = gl_FragCoord.xy / resolution.xy;
        vec3 c = texture2D(tex, uv).rgb;
        {
                //declare stuff
                int kSize = int(min((MSIZE-1)/2., 1.5*(sigma_s*0.5)*renderScale.x));
                float kernel[int(MSIZE)];
                vec3 final_colour = vec3(0.0);

                //create the 1-D kernel
                float Z = 0.0;
                for (int j = 0; j <= kSize; ++j)
                {
                        kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j), (sigma_s*0.5)*renderScale.x);
                }

                vec3 cc;
                float factor;
                float bZ = 1.0/normpdf(0.0, (sigma_r*.001));
                //read out the texels
                for (int i=-kSize; i <= kSize; ++i)
                {
                        for (int j=-kSize; j <= kSize; ++j)
                        {
                                cc = texture2D(tex, uv + (vec2(float(i),float(j))) / resolution.xy).rgb;
                                factor = normpdf3(cc-c, (sigma_r*.001))*bZ*kernel[kSize+j]*kernel[kSize+i];
                                Z += factor;
                                final_colour += factor*cc;

                        }
                }

                gl_FragColor = vec4(final_colour/Z, texture2D( tex, uv ).a);
        }
}

***
2019-04-21T16:47:06 [WARNING] Fragment shader could not be added
2019-04-21T16:47:06 [WARNING] Tried to start a closed effect - opening
cgvirus commented 5 years ago

That's what I suspect. MESA is not in optimal state right now. Try this: https://rpmfusion.org/Howto/NVIDIA Also Fedora now has Bumblebee auto detection. Should work nicely

cgvirus commented 5 years ago

Also revert to the actual code as the hack will leak the memory.

ghost commented 5 years ago

MattKC himself advised not to use Noveau drivers for Olive

cgvirus commented 5 years ago

Possible reason: Older OpenGL profile. If not then feel free to reopen the issue.