diff --git a/src/lib.rs b/src/lib.rs index 746879b..048a7cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -401,7 +401,7 @@ impl Core { incident: Ray::new(pos, dir), normal, }); - let color = colormap(light); + let color = Vec3::splat(light); render::faces::Vertex { pos, color } }) .collect::>(), diff --git a/src/render/colormap.wgsl b/src/render/colormap.wgsl new file mode 100644 index 0000000..e2af29d --- /dev/null +++ b/src/render/colormap.wgsl @@ -0,0 +1,32 @@ +struct LookParams { + m: mat4x4f, +} + +struct Vertex { + @location(0) pos: vec3f, + @location(1) color: vec3f, +} + +struct Varying { + @builtin(position) screen: vec4f, + @location(0) color: vec4f, +} + +@group(0) @binding(0) var look: LookParams; + +fn colormap(light: f32) -> vec3f { + let brightness = 3. * (1. - 1. / (1. + light)); + return vec3(brightness, brightness - 1., brightness - 2.); +} + +@vertex +fn on_vertex(in: Vertex) -> Varying { + let pos = look.m * vec4f(in.pos, 1.0); + let color = vec4f(in.color, 1.0); + return Varying(pos, color); +} + +@fragment +fn on_fragment(in: Varying) -> @location(0) vec4f { + return vec4f(colormap(in.color.x), 1.0); +} diff --git a/src/render/faces.rs b/src/render/faces.rs index b6a2a20..7879c30 100644 --- a/src/render/faces.rs +++ b/src/render/faces.rs @@ -79,7 +79,7 @@ impl Pipeline { let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, - source: wgpu::ShaderSource::Wgsl(super::SIMPLE_SHADER.into()), + source: wgpu::ShaderSource::Wgsl(super::COLORMAP_SHADER.into()), }); let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, diff --git a/src/render/mod.rs b/src/render/mod.rs index 2f629ee..3601ec0 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -2,6 +2,7 @@ pub mod faces; pub mod lines; static SIMPLE_SHADER: &str = include_str!("simple.wgsl"); +static COLORMAP_SHADER: &str = include_str!("colormap.wgsl"); pub const OUTPUT_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8UnormSrgb; pub const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth24Plus;