Skip to content

Instantly share code, notes, and snippets.

@CIOSAI
Created October 26, 2024 15:39
Show Gist options
  • Save CIOSAI/4399c23293707371748fa0ab5686d084 to your computer and use it in GitHub Desktop.
Save CIOSAI/4399c23293707371748fa0ab5686d084 to your computer and use it in GitHub Desktop.
bonzo comp-some attractor thing-26.10.2024
// by CIOSAI_tw at 26 OCT 2024
// runs on bonzo comp (wrighter)
// capture : https://imgur.com/E707RnL
#version 420 core
uniform float fGlobalTime; // in seconds
uniform vec2 v2Resolution; // viewport resolution (in pixels)
uniform float fFrameTime; // duration of the last frame, in seconds
uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
uniform sampler1D texFFTIntegrated; // this is continually increasing
uniform sampler2D texPreviousFrame; // screenshot of the previous frame
uniform sampler2D texChecker;
uniform sampler2D texNoise;
uniform sampler2D texTex1;
uniform sampler2D texTex2;
uniform sampler2D texTex3;
uniform sampler2D texTex4;
layout(r32ui) uniform coherent uimage2D[3] computeTex;
layout(r32ui) uniform coherent uimage2D[3] computeTexBack;
layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything
#define U gl_FragCoord.xy
#define R vec2(v2Resolution.xy)
#define T fGlobalTime
#define pi acos(-1.)
#define tau (acos(-1.)*2.)
#define rot(a) mat2(cos(a),-sin(a),sin(a),cos(a))
// hashes
uint seed = 12512;
uint hashi( uint x){
x ^= x >> 16;x *= 0x7feb352dU;x ^= x >> 15;x *= 0x846ca68bU;x ^= x >> 16;
return x;
}
#define hash_f_s(s) ( float( hashi(uint(s)) ) / float( 0xffffffffU ) )
#define hash_f() ( float( seed = hashi(seed) ) / float( 0xffffffffU ) )
#define hash_v2() vec2(hash_f(),hash_f())
#define hash_v3() vec3(hash_f(),hash_f(),hash_f())
#define hash_v4() vec3(hash_f(),hash_f(),hash_f(),hash_f())
vec2 sample_disk(){
vec2 r = hash_v2();
return vec2(sin(r.x*tau),cos(r.x*tau))*sqrt(r.y);
}
// point projection
ivec2 proj_p(vec3 p, float t){
// arbitrary camera stuff
// perspective proj
p.xy /= p.z*0.5;
// depth of field
p.xy += sample_disk() * abs(p.z - 5. + sin(T))*0.01;
// convert point to ivec2. From 0 to resolution.xy
ivec2 q = ivec2((p.xy + vec2(R.x/R.y,1)*0.5)*vec2(R.y/R.x,1)*R);
if(any(greaterThan(q, ivec2(R))) || any(lessThan(q, ivec2(0)))){
q = ivec2(-1);
}
return q;
}
void store_pixel(ivec2 px_coord, vec3 col){
// colour quantized to integer.
ivec3 quant_col = ivec3(col * 1000);
// no clue why it wants ivec4() here...
imageStore(computeTex[0], px_coord, ivec4(quant_col.x));
imageStore(computeTex[1], px_coord, ivec4(quant_col.y));
imageStore(computeTex[2], px_coord, ivec4(quant_col.z));
}
void add_to_pixel(ivec2 px_coord, vec3 col){
// colour quantized to integer.
ivec3 quant_col = ivec3(col * 1000);
imageAtomicAdd(computeTex[0], px_coord, quant_col.x);
imageAtomicAdd(computeTex[1], px_coord, quant_col.y);
imageAtomicAdd(computeTex[2], px_coord, quant_col.z);
}
vec3 read_pixel(ivec2 px_coord){
return 0.001*vec3(
imageLoad(computeTexBack[0],px_coord).x,
imageLoad(computeTexBack[1],px_coord).x,
imageLoad(computeTexBack[2],px_coord).x
);
}
void main()
{
vec2 uv = vec2(gl_FragCoord.x / v2Resolution.x, gl_FragCoord.y / v2Resolution.y);
uv -= 0.5;
uv /= vec2(v2Resolution.y / v2Resolution.x, 1);
// Init hash
seed = 215125125;
seed += hashi(uint(U.x)) + hashi(uint(U.y)*125);
if(gl_FragCoord.x < 100){
vec3 p = hash_v3()-.5;
float t = T - hash_f()*1./30;
for(int i=0; i<30; i++){
vec3 toward = normalize(sin((vec3(4.6,1.3,9.3)+vec3(.5,-.4,.2)*T)+floor(hash_f_s(uint(U.x))*32.)+T))*8.;
p += toward * pow(length(toward-p),.1);
//adhere to sphere
p -= normalize(p)*(length(p)-.2)*hash_f();
ivec2 q = proj_p(p+vec3(0,0,5),t);
// if inside screen
if(q.x >= 0){
add_to_pixel(
q, vec3(1)
);
}
}
}
vec2 n_uv = uv;
vec2 i_n_uv = floor(n_uv*4.),
f_n_uv = fract(n_uv*4.);
for(int i=0; i<4; i++){
seed = 225125;
seed = hashi(uint(i_n_uv.x+step(.5,f_n_uv.x))) + hashi(uint(i_n_uv.y+step(.5,f_n_uv.y))*125) + hashi(uint(T*6.)*55456);
float chance = step(.5,hash_f());
i_n_uv = mix(i_n_uv+floor((hash_v2()-.5)*3.)/float(1<<i), i_n_uv, chance);
f_n_uv = mix(f_n_uv, f_n_uv*float(1<<i)-i_n_uv, chance);
}
n_uv = (i_n_uv.yx+f_n_uv)/4.;
vec3 s = read_pixel(ivec2( (n_uv*vec2(R.y/R.x,1.)+.5)*R ))*0.1;
// tonemap stuff
s = s/(1+s*1.);
s = mix(s,smoothstep(0.,1.,s),0.);
//s *= 1.2;
vec3 col = vec3(1.,.5,.7)*.5;
col -= pow(s,vec3(2.,1.,1.5));
col = pow(col,vec3(.45454));
out_color = vec4(col,0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment