// cf: https://thebookofshaders.com/10/ fn random(uv: vec2) -> f32 { let c = vec2(12.9898, 78.233) * 43758.5453123; return fract(sin(dot(uv, c))); } struct VertexOutput { @builtin(position) position: vec4, @location(0) uv: vec2, } @vertex fn vs_main(@location(0) idx: u32) -> VertexOutput { var vertex: array, 4>; vertex[0] = vec2(-1.0, -1.0); vertex[1] = vec2(1.0, -1.0); vertex[2] = vec2(-1.0, 1.0); vertex[3] = vec2(1.0, 1.0); return VertexOutput(vec4(vertex[idx], 0.0, 1.0), vertex[idx]); } @fragment fn unicolor(@location(0) _uv: vec2) -> @location(0) vec4 { return vec4(0.2, 0.4, 0.6, 0.8); } @fragment fn random_texture(@location(0) uv: vec2) -> @location(0) vec4 { let r = random(uv); let g = random(uv.yx); let b = random(vec2(r, g)); return vec4(r, g, b, 1.0); } @fragment fn gradation_texture(@location(0) uv: vec2) -> @location(0) vec4 { let r = length(uv) / sqrt(2.0); let l = 1.0 - r; let col0 = vec3(r, r * r, r * r * r); let col1 = vec3(l * l * l, l, l * l); return vec4(clamp(col0 + col1, vec3(0.0), vec3(1.0)), 1.0); }