mirror of https://github.com/sotrh/learn-wgpu
reflections seem correct
parent
fa43eb6172
commit
49c2cbc8f6
@ -0,0 +1,14 @@
|
||||
# Blender MTL File: 'cobble_sphere.blend'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl Material
|
||||
Ns 250.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Bump cobble-normal.png
|
||||
map_Kd cobble-diffuse.png
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,13 @@
|
||||
# Blender 3.6.4 MTL File: 'floor.blend'
|
||||
# www.blender.org
|
||||
|
||||
newmtl Material
|
||||
Ns 250.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd cobble-diffuse.png
|
||||
map_Bump cobble-normal.png
|
@ -0,0 +1,16 @@
|
||||
# Blender 3.6.4
|
||||
# www.blender.org
|
||||
mtllib floor.mtl
|
||||
o Plane
|
||||
v -1.000000 0.000000 1.000000
|
||||
v 1.000000 0.000000 1.000000
|
||||
v -1.000000 0.000000 -1.000000
|
||||
v 1.000000 0.000000 -1.000000
|
||||
vn -0.0000 1.0000 -0.0000
|
||||
vt 0.000000 0.000000
|
||||
vt 1.000000 0.000000
|
||||
vt 1.000000 1.000000
|
||||
vt 0.000000 1.000000
|
||||
s 0
|
||||
usemtl Material
|
||||
f 1/1/1 2/2/1 4/3/1 3/4/1
|
@ -0,0 +1,99 @@
|
||||
use std::mem::size_of;
|
||||
|
||||
use wgpu::util::{BufferInitDescriptor, DeviceExt};
|
||||
|
||||
use crate::create_render_pipeline;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
|
||||
pub struct PositionColor {
|
||||
position: [f32; 3],
|
||||
color: [f32; 3],
|
||||
}
|
||||
|
||||
const AXIS_COLORS: &'static [PositionColor] = &[
|
||||
// X
|
||||
PositionColor {
|
||||
position: [0.0, 0.0, 0.0],
|
||||
color: [0.5, 0.0, 0.0],
|
||||
},
|
||||
PositionColor {
|
||||
position: [1.0, 0.0, 0.0],
|
||||
color: [1.0, 0.0, 0.0],
|
||||
},
|
||||
// Y
|
||||
PositionColor {
|
||||
position: [0.0, 0.0, 0.0],
|
||||
color: [0.0, 0.5, 0.0],
|
||||
},
|
||||
PositionColor {
|
||||
position: [0.0, 1.0, 0.0],
|
||||
color: [0.0, 1.0, 0.0],
|
||||
},
|
||||
// Z
|
||||
PositionColor {
|
||||
position: [0.0, 0.0, 0.0],
|
||||
color: [0.0, 0.0, 0.5],
|
||||
},
|
||||
PositionColor {
|
||||
position: [0.0, 0.0, 1.0],
|
||||
color: [0.0, 0.0, 1.0],
|
||||
},
|
||||
];
|
||||
|
||||
const POSITION_COLOR_LAYOUT: wgpu::VertexBufferLayout<'static> = wgpu::VertexBufferLayout {
|
||||
array_stride: size_of::<PositionColor>() as _,
|
||||
step_mode: wgpu::VertexStepMode::Vertex,
|
||||
attributes: &wgpu::vertex_attr_array![
|
||||
0 => Float32x3,
|
||||
1 => Float32x3,
|
||||
],
|
||||
};
|
||||
|
||||
pub struct Debug {
|
||||
color_lines: wgpu::RenderPipeline,
|
||||
axis: wgpu::Buffer,
|
||||
}
|
||||
|
||||
impl Debug {
|
||||
pub fn new(
|
||||
device: &wgpu::Device,
|
||||
camera_layout: &wgpu::BindGroupLayout,
|
||||
color_format: wgpu::TextureFormat,
|
||||
) -> Self {
|
||||
let axis = device.create_buffer_init(&BufferInitDescriptor {
|
||||
label: Some("Debug::axis"),
|
||||
contents: bytemuck::cast_slice(AXIS_COLORS),
|
||||
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::VERTEX,
|
||||
});
|
||||
|
||||
let shader = wgpu::include_wgsl!("debug.wgsl");
|
||||
let layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: None,
|
||||
bind_group_layouts: &[camera_layout],
|
||||
push_constant_ranges: &[],
|
||||
});
|
||||
let color_lines = create_render_pipeline(
|
||||
device,
|
||||
&layout,
|
||||
color_format,
|
||||
None,
|
||||
&[POSITION_COLOR_LAYOUT],
|
||||
wgpu::PrimitiveTopology::LineList,
|
||||
shader,
|
||||
);
|
||||
|
||||
Self { color_lines, axis }
|
||||
}
|
||||
|
||||
pub fn draw_axis<'a: 'b, 'b>(
|
||||
&'a self,
|
||||
pass: &'b mut wgpu::RenderPass<'a>,
|
||||
camera: &'a wgpu::BindGroup,
|
||||
) {
|
||||
pass.set_pipeline(&self.color_lines);
|
||||
pass.set_bind_group(0, camera, &[]);
|
||||
pass.set_vertex_buffer(0, self.axis.slice(..));
|
||||
pass.draw(0..AXIS_COLORS.len() as u32, 0..1);
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
struct Camera {
|
||||
view_pos: vec4<f32>,
|
||||
view: mat4x4<f32>,
|
||||
view_proj: mat4x4<f32>,
|
||||
inv_proj: mat4x4<f32>,
|
||||
inv_view: mat4x4<f32>,
|
||||
}
|
||||
@group(0) @binding(0)
|
||||
var<uniform> camera: Camera;
|
||||
|
||||
struct PositionColor {
|
||||
@location(0) position: vec3<f32>,
|
||||
@location(1) color: vec3<f32>,
|
||||
}
|
||||
|
||||
struct VsOut {
|
||||
@builtin(position) frag_position: vec4<f32>,
|
||||
@location(0) color: vec3<f32>,
|
||||
}
|
||||
|
||||
@vertex
|
||||
fn vs_main(
|
||||
v: PositionColor,
|
||||
) -> VsOut {
|
||||
let frag_position = camera.view_proj * vec4(v.position, 1.0);
|
||||
return VsOut(frag_position, v.color);
|
||||
}
|
||||
|
||||
@fragment
|
||||
fn fs_main(
|
||||
v: VsOut,
|
||||
) -> @location(0) vec4<f32> {
|
||||
return vec4(v.color, 1.0);
|
||||
}
|
Loading…
Reference in New Issue