Cosmic Dust
High-density procedural starfield using complex noise functions to create nebulae.
60 FPS • WebGPU
WGSL Shader Source
struct Uniforms { resolution: vec2f, time: f32, padding: f32, mouse: vec2f, density: f32, }
@group(0) @binding(0) var<uniform> u: Uniforms;
@vertex fn vs_main(@builtin(vertex_index) vi: u32) -> @builtin(position) vec4f {
let pos = array(vec2f(-1.0,-1.0), vec2f(3.0,-1.0), vec2f(-1.0,3.0));
return vec4f(pos[vi], 0.0, 1.0);
}
fn hash3(p: vec3f) -> f32 {
var p3 = fract(p * 0.1031);
p3 = p3 + dot(p3, p3.zyx + 31.32);
return fract((p3.x + p3.y) * p3.z);
}
@fragment fn fs_main(@builtin(position) fc: vec4f) -> @location(0) vec4f {
var uv = (fc.xy - 0.5*u.resolution) / u.resolution.y;
uv = uv + (u.mouse - 0.5)*0.5;
var col = vec3f(0.0);
for(var i=0.0; i<60.0; i+=1.0) {
let z = fract(i/60.0 - u.time*0.1);
let size = mix(15.0, 0.1, z);
let fade = smoothstep(0.0, 0.1, z) * smoothstep(1.0, 0.8, z);
var p = uv * size;
let h = hash3(vec3f(floor(p), i));
if (h > (1.0 - u.density*0.01)) {
let d = length(fract(p) - 0.5);
col = col + vec3f(0.5+0.5*sin(i), 0.6+0.4*cos(i*2.0), 1.0) * smoothstep(0.3, 0.0, d) * fade;
}
}
return vec4f(col, 1.0);
} Properties
#webgpu#particles#space
Author: Math Art Core Target: 60 FPS