|
| 1 | +//! Ported to Rust from <https://www.shadertoy.com/view/MdXSzS> |
| 2 | +//! |
| 3 | +//! Original comment: |
| 4 | +//! ```glsl |
| 5 | +//! // https://www.shadertoy.com/view/MdXSzS |
| 6 | +//! // The Big Bang - just a small explosion somewhere in a massive Galaxy of Universes. |
| 7 | +//! // Outside of this there's a massive galaxy of 'Galaxy of Universes'... etc etc. :D |
| 8 | +//! |
| 9 | +//! // To fake a perspective it takes advantage of the screen being wider than it is tall. |
| 10 | +//! ``` |
| 11 | +
|
| 12 | +use shared::*; |
| 13 | +use spirv_std::glam::{Mat2, Vec2, Vec3, Vec3Swizzles, Vec4}; |
| 14 | + |
| 15 | +// Note: This cfg is incorrect on its surface, it really should be "are we compiling with std", but |
| 16 | +// we tie #[no_std] above to the same condition, so it's fine. |
| 17 | +#[cfg(target_arch = "spirv")] |
| 18 | +use spirv_std::num_traits::Float; |
| 19 | + |
| 20 | +pub struct Inputs { |
| 21 | + pub resolution: Vec3, |
| 22 | + pub time: f32, |
| 23 | +} |
| 24 | + |
| 25 | +impl Inputs { |
| 26 | + pub fn main_image(&self, frag_color: &mut Vec4, frag_coord: Vec2) { |
| 27 | + let uv: Vec2 = (frag_coord / self.resolution.xy()) - Vec2::splat(0.5); |
| 28 | + let t: f32 = self.time * 0.1 + (0.25 + 0.05 * (self.time * 0.1).sin()); |
| 29 | + let si: f32 = t.sin(); |
| 30 | + let co: f32 = t.cos(); |
| 31 | + let ma: Mat2 = Mat2::from_cols_array(&[co, si, -si, co]); |
| 32 | + |
| 33 | + let mut v1: f32 = 0.0; |
| 34 | + let mut v2: f32 = 0.0; |
| 35 | + let mut v3: f32 = 0.0; |
| 36 | + |
| 37 | + let mut s: f32 = 0.0; |
| 38 | + |
| 39 | + let mut i = 0; |
| 40 | + while i < 90 { |
| 41 | + let mut p: Vec3 = s * uv.extend(0.0); |
| 42 | + p = (ma.transpose() * p.xy()).extend(p.z); |
| 43 | + p += Vec3::new(0.22, 0.3, s - 1.5 - (self.time * 0.13).sin() * 0.1); |
| 44 | + { |
| 45 | + let mut i = 0; |
| 46 | + while i < 8 { |
| 47 | + p = p.abs() / p.dot(p) - Vec3::splat(0.659); |
| 48 | + i += 1; |
| 49 | + } |
| 50 | + } |
| 51 | + v1 += p.dot(p) * 0.0015 * (1.8 + ((uv * 13.0).length() + 0.5 - self.time * 0.2).sin()); |
| 52 | + v2 += p.dot(p) * 0.0013 * (1.5 + ((uv * 14.5).length() + 1.2 - self.time * 0.3).sin()); |
| 53 | + v3 += (p.xy() * 10.0).length() * 0.0003; |
| 54 | + s += 0.035; |
| 55 | + i += 1; |
| 56 | + } |
| 57 | + |
| 58 | + let len: f32 = uv.length(); |
| 59 | + v1 *= smoothstep(0.7, 0.0, len); |
| 60 | + v2 *= smoothstep(0.5, 0.0, len); |
| 61 | + v3 *= smoothstep(0.9, 0.0, len); |
| 62 | + |
| 63 | + let col: Vec3 = Vec3::new( |
| 64 | + v3 * (1.5 + (self.time * 0.2).sin() * 0.4), |
| 65 | + (v1 + v3) * 0.3, |
| 66 | + v2, |
| 67 | + ) + Vec3::splat(smoothstep(0.2, 0.0, len) * 0.85) |
| 68 | + + Vec3::splat(smoothstep(0.0, 0.6, v3) * 0.3); |
| 69 | + |
| 70 | + *frag_color = col |
| 71 | + .abs() |
| 72 | + .powf_vec(Vec3::splat(1.2)) |
| 73 | + .min(Vec3::splat(1.0)) |
| 74 | + .extend(1.0); |
| 75 | + } |
| 76 | +} |
0 commit comments