#[macro_use] extern crate shadiertoy; use shadiertoy::{Window, Game, Shader}; use std::time::Instant; pipeline!(globals { time: Global, resolution: Global<[f32; 2]>, color: RenderTarget, }); struct Basic { shader: Shader, start: Instant, } impl Game for Basic { fn new(window: &mut Window) -> Self { let shader = window.shader(globals::new(), b" uniform vec2 resolution; uniform float time; varying out vec4 color; void main() { vec2 uv = gl_FragCoord.xy / resolution; vec3 col = 0.5 + 0.5 * cos(time + uv.xyx + vec3(0, 2, 4)); color = vec4(col, 1.0); } ").unwrap(); Basic { shader, start: Instant::now(), } } fn draw(&mut self, window: &mut Window) { let time = self.start.elapsed(); let time = time.as_secs() as f32 + time.subsec_nanos() as f32 * 1e-9; let resolution = window.size() .map(|(w, h)| [w as f32, h as f32]) .unwrap_or([0.0; 2]); window.draw(&self.shader, |color, _| globals::Data { time: &time, resolution: &resolution, color, }); } } pub fn main() { Basic::run() }