y4my4my4m / kde-shader-wallpaper

KDE / Plasma - Shader Wallpaper plugin
GNU General Public License v3.0
224 stars 12 forks source link

Recompiling shader is not having any effect #55

Closed Woovie closed 3 weeks ago

Woovie commented 1 month ago

Here is a modified version of the PS3 menu shader I've updated to be compatible with the latest developer instructions.

#version 450

layout(location = 0) in vec2 qt_TexCoord0;
layout(location = 0) out vec4 fragColor;

layout(std140, binding = 0) uniform buf {
    mat4 qt_Matrix;
    float qt_Opacity;
    float iTime;
    float iTimeDelta;
    float iFrameRate;
    float iSampleRate;
    int iFrame;
    vec4 iDate;
    vec4 iMouse;
    vec3 iResolution;
    float iChannelTime[4];
    vec3 iChannelResolution[4];
} ubuf;

layout(binding = 1) uniform sampler2D iChannel0;
layout(binding = 1) uniform sampler2D iChannel1;
layout(binding = 1) uniform sampler2D iChannel2;
layout(binding = 1) uniform sampler2D iChannel3;

vec2 fragCoord = vec2(qt_TexCoord0.x, 1.0 - qt_TexCoord0.y) * ubuf.iResolution.xy;

float iTime = ubuf.iTime;
vec3 iResolution = ubuf.iResolution;

// https://www.shadertoy.com/view/4ddGzj
// Credits to jabudcha

const float speed = 0.4;
const float widthFactor = 2.0;

vec3 calcSine(vec2 uv,
              float frequency, float amplitude, float shift, float offset,
              vec3 color, float width, float exponent, bool dir)
{
    float angle = iTime * speed * frequency + (shift + uv.x) * 0.75;

    float y = sin(angle) * amplitude + offset;
    float clampY = clamp(0.0,y,y);
    float diffY = y - uv.y;

    float dsqr = distance(y,uv.y);
    float scale = 1.0;

    if(dir && diffY > 0.0)
    {
        dsqr = dsqr * 4.0;
    }
    else if(!dir && diffY < 0.0)
    {
        dsqr = dsqr * 4.0;
    }

    scale = pow(smoothstep(width * widthFactor, 0.0, dsqr), exponent);

    return min(color * scale, color);
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 uv = fragCoord.xy / iResolution.xy;
    vec3 color = vec3(0.0);

    float t1 = (sin(iTime/20.0) / 3.14) + 0.2;
    float t2 = (sin(iTime/10.0) / 3.14) + 0.2;

    color += calcSine(uv, 0.20, 0.2, 0.0, 0.5,  vec3(0.5, 0.5, 0.5), 0.1, 15.0,false);
    color += calcSine(uv, 0.40, 0.15, 0.0, 0.5, vec3(0.5, 0.5, 0.5), 0.1, 17.0,false);
    color += calcSine(uv, 0.60, 0.15, 0.0, 0.5, vec3(0.5, 0.5, 0.5), 0.05, 23.0,false);

    color += calcSine(uv, 0.26, 0.07, 0.0, 0.3, vec3(0.5, 0.5, 0.5), 0.1, 17.0,true);
    color += calcSine(uv, 0.46, 0.07, 0.0, 0.3, vec3(0.5, 0.5, 0.5), 0.05, 23.0,true);
    color += calcSine(uv, 0.58, 0.05, 0.0, 0.3, vec3(0.5, 0.5, 0.5), 0.2, 15.0,true);

    color.x += (0.9-uv.y);
    color.y += (0.7176-uv.y);
    color.z += (0.77-uv.y);

    fragColor = vec4(color,1.0);
}

void main() {
    vec4 color = vec4(0.0);
    mainImage(color, fragCoord);
    fragColor = color;
}

As you can see, I've modified the color x, y, z to fixed values. Here is my expected look from shadertoy:

image

I originally compiled this file with the same name using the original colors, without modification. The original changes the red and green channel values only, based on the t1 and t2 values.

I chose another shader in wallpaper selector, then performed this command:

❯ ls -lah
total 24K
drwxr-xr-x  2 jbanasik jbanasik 4.0K May 21 23:46 .
drwxr-xr-x 50 jbanasik jbanasik 4.0K May 21 23:46 ..
-rw-r--r--  1 jbanasik jbanasik 2.5K May 21 23:46 jb-test2.frag
-rw-r--r--  1 jbanasik jbanasik 2.5K May 21 23:39 jb-test.frag
-rw-r--r--  1 jbanasik jbanasik 5.5K May 21 23:46 jb-test.frag.qsb
❯ rm -v jb-test.frag.qsb; rm -v /home/jbanasik/.local/share/plasma/wallpapers/online.knowmad.shaderwallpaper/contents/ui/Shaders6/jb-test.frag.qsb; qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -o jb-test.frag.qsb jb-test.frag && cp -v jb-test.frag.qsb /home/jbanasik/.local/share/plasma/wallpapers/online.knowmad.shaderwallpaper/contents/ui/Shaders6/
removed 'jb-test.frag.qsb'
removed '/home/jbanasik/.local/share/plasma/wallpapers/online.knowmad.shaderwallpaper/contents/ui/Shaders6/jb-test.frag.qsb'
'jb-test.frag.qsb' -> '/home/jbanasik/.local/share/plasma/wallpapers/online.knowmad.shaderwallpaper/contents/ui/Shaders6/jb-test.frag.qsb'

I reselect the jb-test.frag.qsb, and I get the same exact results. I copied my file, adding a 2 to the name, and reran this command a couple of times just to be sure before selecting the shader.

❯ rm -v jb-test2.frag.qsb; rm -v /home/jbanasik/.local/share/plasma/wallpapers/online.knowmad.shaderwallpaper/contents/ui/Shaders6/jb-test2.frag.qsb; qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -o jb-test2.frag.qsb jb-test2.frag && cp -v jb-test2.frag.qsb /home/jbanasik/.local/share/plasma/wallpapers/online.knowmad.shaderwallpaper/contents/ui/Shaders6/
removed 'jb-test2.frag.qsb'
removed '/home/jbanasik/.local/share/plasma/wallpapers/online.knowmad.shaderwallpaper/contents/ui/Shaders6/jb-test2.frag.qsb'
'jb-test2.frag.qsb' -> '/home/jbanasik/.local/share/plasma/wallpapers/online.knowmad.shaderwallpaper/contents/ui/Shaders6/jb-test2.frag.qsb'

It is now correct. The files are identical, but one works and the other doesn't:

❯ diff -q /home/jbanasik/.local/share/plasma/wallpapers/online.knowmad.shaderwallpaper/contents/ui/Shaders6/jb-test2.frag.qsb /home/jbanasik/.local/share/plasma/wallpapers/online.knowmad.shaderwallpaper/contents/ui/Shaders6/jb-test.frag.qsb
❯ stat /home/jbanasik/.local/share/plasma/wallpapers/online.knowmad.shaderwallpaper/contents/ui/Shaders6/jb-test2.frag.qsb; stat /home/jbanasik/.local/share/plasma/wallpapers/online.knowmad.shaderwallpaper/contents/ui/Shaders6/jb-test.frag.qsb
  File: /home/jbanasik/.local/share/plasma/wallpapers/online.knowmad.shaderwallpaper/contents/ui/Shaders6/jb-test2.frag.qsb
  Size: 5560        Blocks: 16         IO Block: 4096   regular file
Device: 254,0   Inode: 88630918    Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/jbanasik)   Gid: ( 1000/jbanasik)
Access: 2024-05-21 23:49:25.660685445 -0700
Modify: 2024-05-21 23:49:25.020685465 -0700
Change: 2024-05-21 23:49:25.020685465 -0700
 Birth: 2024-05-21 23:49:25.020685465 -0700
  File: /home/jbanasik/.local/share/plasma/wallpapers/online.knowmad.shaderwallpaper/contents/ui/Shaders6/jb-test.frag.qsb
  Size: 5560        Blocks: 16         IO Block: 4096   regular file
Device: 254,0   Inode: 88630917    Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/jbanasik)   Gid: ( 1000/jbanasik)
Access: 2024-05-21 23:48:02.570688013 -0700
Modify: 2024-05-21 23:48:01.910688033 -0700
Change: 2024-05-21 23:48:01.910688033 -0700
 Birth: 2024-05-21 23:48:01.910688033 -0700

What mechanism is leading to this being cached and how can I avoid it for rapid development?

Thanks!

y4my4my4m commented 1 month ago

I believe the cached version is just how plasma's wallpaper functions.

What I'm doing during dev is simply killing the plasmashell and restarting it.

pkill plasmashell && plasmashell and then you can just Ctrl+C to stop the process and call plasmashell again to refresh it while you dev.

Another thing to try if killing and reloading doesn't clear the cache, change the wallpaper plugin type back to "image" and back again to "shader"

@Woovie

Woovie commented 1 month ago

I see, I'll give that a shot and see how it goes. Thanks!

y4my4my4m commented 3 weeks ago

@Woovie did it work?

Woovie commented 3 weeks ago

Sorry, it's been a hot minute since I worked on this, but I'll give it a shot today and report back.

Woovie commented 3 weeks ago

That works well enough for me and correctly loaded the shader. Thanks for the help, I'll stick to that for now.