Compare commits
No commits in common. "059e98c3e352065a42f8330746ee829660004798" and "653788d456bdf929f8f275b4946de235cdc1c96c" have entirely different histories.
059e98c3e3
...
653788d456
|
|
@ -20,12 +20,6 @@ impl OrbitalCamera {
|
||||||
self.distance * vec3(xy * x, xy * y, z)
|
self.distance * vec3(xy * x, xy * y, z)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn direction(&self) -> Vec3 {
|
|
||||||
let (y, x) = self.position_yaw.sin_cos();
|
|
||||||
let (z, xy) = self.position_pitch.sin_cos();
|
|
||||||
-vec3(xy * x, xy * y, z)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn transform(&self) -> Mat4 {
|
pub fn transform(&self) -> Mat4 {
|
||||||
// for yaw=0, pitch=0:
|
// for yaw=0, pitch=0:
|
||||||
// X -> -Z
|
// X -> -Z
|
||||||
|
|
|
||||||
|
|
@ -393,15 +393,12 @@ impl Core {
|
||||||
.map(|&v| {
|
.map(|&v| {
|
||||||
let pos = obj.position + obj.radius * v;
|
let pos = obj.position + obj.radius * v;
|
||||||
let normal = v;
|
let normal = v;
|
||||||
let mut dir = (pos - camera.position()).normalize();
|
let dir = (pos - camera.position()).normalize();
|
||||||
if !dir.is_finite() {
|
|
||||||
dir = camera.direction();
|
|
||||||
}
|
|
||||||
let light = light_at(Hit {
|
let light = light_at(Hit {
|
||||||
incident: Ray::new(pos, dir),
|
incident: Ray::new(pos, dir),
|
||||||
normal,
|
normal,
|
||||||
});
|
});
|
||||||
let color = Vec3::splat(light);
|
let color = colormap(light);
|
||||||
render::faces::Vertex { pos, color }
|
render::faces::Vertex { pos, color }
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
|
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
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<uniform> 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);
|
|
||||||
}
|
|
||||||
|
|
@ -79,7 +79,7 @@ impl Pipeline {
|
||||||
|
|
||||||
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
|
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
|
||||||
label: None,
|
label: None,
|
||||||
source: wgpu::ShaderSource::Wgsl(super::COLORMAP_SHADER.into()),
|
source: wgpu::ShaderSource::Wgsl(super::SIMPLE_SHADER.into()),
|
||||||
});
|
});
|
||||||
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||||
label: None,
|
label: None,
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ pub mod faces;
|
||||||
pub mod lines;
|
pub mod lines;
|
||||||
|
|
||||||
static SIMPLE_SHADER: &str = include_str!("simple.wgsl");
|
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 OUTPUT_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8UnormSrgb;
|
||||||
pub const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth24Plus;
|
pub const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth24Plus;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user