simple shader algorithm
simple shader algorithm
v=kbKtFN71Lfs&ab_channel=Numberphile
// You can basically do whatever transformations you want, which makes it really
fun.
// The shader is projecting points, then splatting them on the screen.
// Great demo which uses this effect - https://www.youtube.com/watch?
v=xLN3mTRlugs&ab_channel=AssemblyTV
// Example/tutorial on doing chaos game in compute.toys -
https://compute.toys/view/120
#define COL_CNT 4
global kCols = array<v3, COL_CNT>(
vec3(1.,1,1), vec3(0.8,0.4,0.7),
vec3(1,1,1.)*1.5, vec3(1,1,1.)*1.5
);
fn mix_cols(_idx: float)->v3{
let idx = _idx%1.;
var cols_idx = int(idx*float(COL_CNT));
var fract_idx = fract(idx*float(COL_CNT));
fract_idx = smoothstep(0.,1.,fract_idx);
//return oklab_mix( kCols[cols_idx], kCols[(cols_idx + 1)%COL_CNT],
fract_idx );
return mix( kCols[cols_idx], kCols[(cols_idx + 1)%COL_CNT], fract_idx );
}
#storage h array<u32>
let t = T*1.;
p += v3(
sin(t+ 0.1)*0.1,
sin(t)*0.1,
sin(t)*0.2,
)*1.;
// p.z += 4.7;
// p *= rotZ(pow(sin_add(T),2.)*pi*2. * float(floor(T/pi/2.)%4 > 2.) );
// p /= p.z*0.2;
p *= 1. + sin(t*0.9 + sin(t*0.8))*0.05;
// p.x /= dpp;
// p.y /= dpp;
p.z = _p.z;
p.x /= R.x/R.y;
return p;
}
#workgroup_count Splat 64 64 12
@compute @workgroup_size(256, 1,1)
fn Splat(@builtin(global_invocation_id) id: uint3) {
let Ru = uint2(textureDimensions(screen));
if (id.x >= Ru.x || id.y >= Ru.y) { return; }
R = v2(Ru); U = v2(id.xy); muv = (v2(mouse.pos) - 0.5*R)/R.y;
let md = 5.0;
var env = ((floor(t))%md);
var env_next = ((floor(t + 1))%md);
var env_fr = fract(t);
env = mix(
env,
env_next,
smoothstep(0.,1.,
smoothstep(0.,1.,
smoothstep(0.,1.,
smoothstep(0.,1.,
env_fr
)
)
)
)
);
}
// let focusDist = (custom.DOF_Focal_Dist*2. - 1.)*5.;
let dofFac = 1./vec2(R.x/R.y,1.)*custom.DOF_Amount;
p *= rotZ(t*0.1);
p *= rotY(t*0.1);
}
// p = mix(p,next_p,0.4 + sin(T)*0.);
var q = projParticle(p);
var k = q.xy;
R = v2(res);
U = v2(id.xy);
let U = float2(float(id.x) + .5, float(res.y - id.y) - .5);
//col = smoothstep(v3(0.),v3(1.),col*mix_cols(col.x*1.));
col = max(col,v3(0.1));
col = pow((col), float3(1./0.25454545))*4.;
col = min(col,v3(0.6));
col = clamp(col,v3(0.002),v3(0.8));
textureStore(screen, int2(id.xy), float4(col, 1.));
// clear flame
// hist[id.x + uint(R.x) * id.y] = 0;
atomicStore(&hist_atomic[hist_id],0);
atomicStore(&hist_atomic[hist_id + res.x*res.y],0);
}