Created
January 13, 2025 15:13
-
-
Save maedoc/edbdaa14c8ebe4d5e380100fe85c2264 to your computer and use it in GitHub Desktop.
integrating brain network models with Shadertoy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// iChannel0 is buffer A | |
// iChannel1 is some texture to use for weights | |
float rand() | |
{ | |
return 0.0; | |
} | |
void mainImage( out vec4 fragColor, in vec2 fragCoord ) | |
{ | |
vec2 uv = fragCoord/iResolution.xy; | |
vec2 s = texture(iChannel0, uv).rg; | |
// params | |
float a = 0.58; // [0.9,1.1] | |
float tau = 3.0; // [1,3] | |
float dt = 0.1; | |
float dWt = 0.0*sqrt(dt); | |
// connectivity | |
float I = 0.0, r=1.0/90.0, k=uv.x*0.3; // [0.0, 0.2] | |
for (float i=0.0; i<0.25; i+=r) { | |
float wij = texture(iChannel1, vec2(uv.y, i)).x; | |
I += wij * texture(iChannel0, vec2(uv.x, i+mod(uv.y,0.25))).x; | |
} | |
float dx = (s.x - s.x*s.x*s.x + s.y)*tau; | |
float dy = (a - s.x - I*r*k)/tau; | |
float ix = s.x+dt*dx; | |
float iy = s.y + dt*dy + dWt*rand(); | |
float dx2 = (ix - ix*ix*ix + iy)*tau; | |
float dy2 = (a - s.x - I*r*k)/tau; | |
float nx = s.x+dt*0.5*(dx+dx2); | |
float ny = s.y + dt*0.5*(dy+dy2) + dWt*rand(); | |
fragColor = vec4( nx, ny, 0.0, 1.0 ); | |
//fragColor = vec4(0.0, 0.0, 0.0, 1.0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// iChannel0 is buffer A is the current states | |
// iChannel1 is buffer B is the metrics like mean/variance per node | |
void mainImage( out vec4 fragColor, in vec2 fragCoord ) | |
{ | |
vec2 uv = fragCoord/iResolution.xy; | |
vec2 xy = texture(iChannel0, uv).xy; | |
vec2 ms = texture(iChannel1, uv).xy; | |
ms.x = ms.x + 0.01*(xy.x - ms.x); | |
float v = xy.x - ms.x; | |
ms.y = ms.y + 0.01*(v*v - ms.y); | |
fragColor = vec4(ms, 0.0, 1.0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// iChannel0/1 like for BufferB | |
// this image shows red for average, green for variance | |
void mainImage( out vec4 fragColor, in vec2 fragCoord ) | |
{ | |
vec2 uv = fragCoord/iResolution.xy; | |
fragColor = vec4(texture(iChannel0,uv).xy,0.0,1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment