Search Unity

Question Odd behavior in compute shader when replicating my shadertoy algorithm

Discussion in 'Shaders' started by G8S, Jul 18, 2020.

  1. G8S

    G8S

    Joined:
    Feb 7, 2017
    Posts:
    18
    Hello! I am trying to replicate my working 2d fluid shadertoy in a compute shader in Unity, with the hopes of moving it to 3D soon. When I replicate the algorithm the same way, I get some very weird behavior (seen in this video I took). I have tried to debug everything I can think of, but I can't figure out why they aren't the same. I am visualizing the vector matrix in this capture (the same as pressing Space while viewing my shadertoy)

    I created a pastebin with the code that I am using to perform the Navier-Stokes equations that drive the velocity matrix. It should be pretty straightforward, i did my best to comment the shadertoy excessively to make it easy to understand (they are the same code, setup for different environments). Here is the C# code that is driving the simulation.

    I know its kind of an inconvenient request to ask someone to dive into my code, but I am not at all sure what I am doing wrong. I have the exact same algorithm working on shadertoy but it behaves very strangely in Unity compute shaders and I can't figure out why. Every time I "step" i make sure to switch the read/write textures as to cleanly move forward in the simulation and not interfere.

    Any ideas/tips towards fixing my issue would be greatly appreciated.
     
    Last edited: Jul 20, 2020