1

Even with a 20 point Laplacian operator there are still coordinate system artifacts with a circularly symmetric seed.

enter image description here

That is one reason to try a spectral solver.

The main code for the above mentioned simplest Laplacian with a forward Euler solver is:

#define A(U) texture(iChannel0,(U)/iResolution.xy)
void mainImage( out vec4 Q, in vec2 U )
{
    // Lookup Field 
    Q = A(U);
    // Mean Field 
    // Two way: horizontal, vertical
    vec4 sum2 = A(U+vec2(0,1))+A(U+vec2(1,0))+A(U-vec2(0,1))+A(U-vec2(1,0));
    vec4 mean2 = 1./4.*(sum2);
    // Laplacian 
    vec4 laplacian2 = (mean2 - Q);
    
    // Diffuse each variable differently : 
    Q += laplacian2 * vec4(1, .4, 1, 1);
    // Compute reactions:
    Q.x = Q.x * .99 + 0.01 * Q.y;
    Q.y = Q.y + .05 * Q.y * (1. - Q.y) - .03 * Q.x - 1e-3;
    
    // Prevent Negative Values (depends on system):
    Q = max(Q, 0.);
}

How can this be rewritten to a spectral solver on Shadertoy?

David Jonsson
  • 318
  • 5
  • 19
  • 1
    You want to do something similar to https://stackoverflow.com/questions/29617089/implement-pseudo-spectral-method-with-rk4-in-python, https://stackoverflow.com/questions/29803342/error-in-rk4-algorithm-in-python, only in 2D? The question might be off-topic here, more suited to scientific computing or computer graphics. – Lutz Lehmann Sep 27 '21 at 09:12
  • @LutzLehmann It is not a theoretical challenge and that is why I ask here. It is about implementation. I have already asked this question in a somewhat different form at https://scicomp.stackexchange.com/questions/35596/how-avoid-square-shape-with-laplacian-operator-in-reaction-diffusion-calculation – David Jonsson Sep 27 '21 at 09:37
  • I believe that the spectral implementation of the diffusion will still preserve the spatial symmetry with its axial-symmetric deviations from perfect radial symmetry of the initial pattern, which is unavoidable due to rasterization, even using anti-aliasing. One could try to break the symmetry by rotating the image by some little angle between steps, in the hope that the new truncation errors will smooth out the existing ones. Or add some small random noise to the initial pattern to break the symmetry, but I think this is the opposite of what you want to achieve. – Lutz Lehmann Sep 27 '21 at 11:27

0 Answers0