upgraded to 0.7.0
This commit is contained in:
15
Cargo.toml
15
Cargo.toml
@@ -4,10 +4,7 @@ version = "0.1.0"
|
|||||||
authors = ["mitchellhansen <mitchellhansen0@gmail.com>"]
|
authors = ["mitchellhansen <mitchellhansen0@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wgpu = "0.6.0"
|
|
||||||
arrayvec = "0.5"
|
arrayvec = "0.5"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
parking_lot = "0.11"
|
parking_lot = "0.11"
|
||||||
@@ -16,8 +13,6 @@ smallvec = "1"
|
|||||||
tracing = { version = "0.1", default-features = false, features = ["std"] }
|
tracing = { version = "0.1", default-features = false, features = ["std"] }
|
||||||
typed-arena = "2.0.1"
|
typed-arena = "2.0.1"
|
||||||
serde = { version = "1", features = ["derive"], optional = true }
|
serde = { version = "1", features = ["derive"], optional = true }
|
||||||
gfx-backend-vulkan = { version = "0.6", features = ["x11"] }
|
|
||||||
cgmath = "0.17"
|
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
png = "0.16"
|
png = "0.16"
|
||||||
winit = { version = "0.22.1", features = ["web-sys"] }
|
winit = { version = "0.22.1", features = ["web-sys"] }
|
||||||
@@ -27,7 +22,11 @@ noise = "0.6"
|
|||||||
ddsfile = "0.4"
|
ddsfile = "0.4"
|
||||||
wgpu-subscriber = "0.1.0"
|
wgpu-subscriber = "0.1.0"
|
||||||
tobj = "2.0.3"
|
tobj = "2.0.3"
|
||||||
legion = "0.3.1"
|
|
||||||
nalgebra = "0.24.1"
|
|
||||||
rapier3d = { version = "0.5.0", features = [ "simd-nightly", "parallel" ] }
|
|
||||||
gilrs = "0.8.0"
|
gilrs = "0.8.0"
|
||||||
|
gfx-backend-vulkan = { version = "0.6", features = ["x11"] }
|
||||||
|
|
||||||
|
cgmath = "0.18.0"
|
||||||
|
rapier3d = { version = "0.5.0", features = ["simd-nightly", "parallel"] }
|
||||||
|
nalgebra = "0.24.1"
|
||||||
|
legion = "0.3.1"
|
||||||
|
wgpu = "0.7.0"
|
||||||
@@ -50,6 +50,7 @@ pub struct RangeCopy<Idx> {
|
|||||||
pub struct Mesh {
|
pub struct Mesh {
|
||||||
pub index_buffer: Arc<Buffer>,
|
pub index_buffer: Arc<Buffer>,
|
||||||
pub index_count: usize,
|
pub index_count: usize,
|
||||||
|
pub index_format: wgpu::IndexFormat,
|
||||||
pub vertex_buffer: Arc<Buffer>,
|
pub vertex_buffer: Arc<Buffer>,
|
||||||
pub uniform_buffer: Arc<Buffer>,
|
pub uniform_buffer: Arc<Buffer>,
|
||||||
pub bind_group: Arc<BindGroup>,
|
pub bind_group: Arc<BindGroup>,
|
||||||
|
|||||||
@@ -19,18 +19,12 @@ pub fn vertex(pos: [f32; 3], nor: [f32; 3]) -> Vertex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn import_mesh(mesh_path: &str) -> (Vec<Vertex>, Vec<u32>) {
|
pub fn import_mesh(mesh_path: &str) -> (Vec<Vertex>, Vec<u32>) {
|
||||||
//let obj_file = "/home/mrh/source/3d-min-viable-eng/resources/Tree_01.obj";
|
|
||||||
//let mtl_file = "/home/mrh/source/3d-min-viable-eng/resources/Tree_01.mtl";
|
|
||||||
let (models, materials) = tobj::load_obj(mesh_path, false).expect("Failed to load file");
|
|
||||||
|
|
||||||
//let q = tobj::load_mtl(mtl_file).unwrap();
|
let (models, materials) = tobj::load_obj(mesh_path, false).expect("Failed to load file");
|
||||||
|
|
||||||
println!("# of models: {}", models.len());
|
println!("# of models: {}", models.len());
|
||||||
println!("# of materials: {}", materials.len());
|
println!("# of materials: {}", materials.len());
|
||||||
|
|
||||||
//let model = models.get(2).unwrap();
|
|
||||||
//let mesh = &model.mesh;
|
|
||||||
|
|
||||||
let mut index_data : Vec<u32> = Vec::new();
|
let mut index_data : Vec<u32> = Vec::new();
|
||||||
let mut vertex_data = Vec::new();
|
let mut vertex_data = Vec::new();
|
||||||
|
|
||||||
@@ -44,13 +38,10 @@ pub fn import_mesh(mesh_path: &str) -> (Vec<Vertex>, Vec<u32>) {
|
|||||||
for i in face_indices {
|
for i in face_indices {
|
||||||
index_data.push(*i);
|
index_data.push(*i);
|
||||||
}
|
}
|
||||||
|
|
||||||
//println!(" face[{}] = {:?}", f, face_indices);
|
|
||||||
next_face = end;
|
next_face = end;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normals and texture coordinates are also loaded, but not printed in this example
|
// Normals and texture coordinates are also loaded, but not printed in this example
|
||||||
//println!("model[{}].vertices: {}", i, mesh.positions.len() / 3);
|
|
||||||
assert!(mesh.positions.len() % 3 == 0);
|
assert!(mesh.positions.len() % 3 == 0);
|
||||||
|
|
||||||
for v in 0..mesh.positions.len() / 3 {
|
for v in 0..mesh.positions.len() / 3 {
|
||||||
@@ -68,7 +59,6 @@ pub fn import_mesh(mesh_path: &str) -> (Vec<Vertex>, Vec<u32>) {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//println!("{:?}\n\n\n\n\n {:?}", vertex_data, index_data);
|
|
||||||
(vertex_data.to_vec(), index_data.to_vec())
|
(vertex_data.to_vec(), index_data.to_vec())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
167
src/render.rs
167
src/render.rs
@@ -13,8 +13,9 @@ use legion::*;
|
|||||||
use rapier3d::parry::motion::RigidMotionComposition;
|
use rapier3d::parry::motion::RigidMotionComposition;
|
||||||
use wgpu::util::DeviceExt;
|
use wgpu::util::DeviceExt;
|
||||||
use wgpu::{
|
use wgpu::{
|
||||||
BackendBit, BindGroup, BindGroupLayout, Buffer, Device, Instance, Queue, Surface, SwapChain,
|
BackendBit, BindGroup, BindGroupLayout, Buffer, BufferBindingType, Device, FragmentState,
|
||||||
SwapChainDescriptor, SwapChainFrame, TextureView,
|
Instance, Queue, Surface, SwapChain, SwapChainDescriptor, SwapChainFrame, TextureView,
|
||||||
|
VertexState,
|
||||||
};
|
};
|
||||||
use winit::dpi::PhysicalSize;
|
use winit::dpi::PhysicalSize;
|
||||||
use winit::platform::unix::x11::ffi::Time;
|
use winit::platform::unix::x11::ffi::Time;
|
||||||
@@ -160,6 +161,7 @@ pub fn render_test(world: &mut SubWorld, #[resource] renderer: &mut Renderer) {
|
|||||||
encoder.insert_debug_marker("render entities");
|
encoder.insert_debug_marker("render entities");
|
||||||
|
|
||||||
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||||
|
label: Some("render pass"),
|
||||||
color_attachments: &[],
|
color_attachments: &[],
|
||||||
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor {
|
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor {
|
||||||
attachment: &light.target_view,
|
attachment: &light.target_view,
|
||||||
@@ -175,7 +177,8 @@ pub fn render_test(world: &mut SubWorld, #[resource] renderer: &mut Renderer) {
|
|||||||
|
|
||||||
for mesh in &mesh_stack {
|
for mesh in &mesh_stack {
|
||||||
pass.set_bind_group(1, &mesh.bind_group, &[]);
|
pass.set_bind_group(1, &mesh.bind_group, &[]);
|
||||||
pass.set_index_buffer(mesh.index_buffer.slice(..));
|
// TODO, pipe through this index format through the mesh
|
||||||
|
pass.set_index_buffer(mesh.index_buffer.slice(..), mesh.index_format);
|
||||||
pass.set_vertex_buffer(0, mesh.vertex_buffer.slice(..));
|
pass.set_vertex_buffer(0, mesh.vertex_buffer.slice(..));
|
||||||
pass.draw_indexed(0..mesh.index_count as u32, 0, 0..1);
|
pass.draw_indexed(0..mesh.index_count as u32, 0, 0..1);
|
||||||
}
|
}
|
||||||
@@ -185,6 +188,7 @@ pub fn render_test(world: &mut SubWorld, #[resource] renderer: &mut Renderer) {
|
|||||||
encoder.push_debug_group("forward rendering pass");
|
encoder.push_debug_group("forward rendering pass");
|
||||||
{
|
{
|
||||||
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||||
|
label: Some("forward render pass"),
|
||||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||||
attachment: &frame.output.view,
|
attachment: &frame.output.view,
|
||||||
resolve_target: None,
|
resolve_target: None,
|
||||||
@@ -214,7 +218,8 @@ pub fn render_test(world: &mut SubWorld, #[resource] renderer: &mut Renderer) {
|
|||||||
|
|
||||||
for (pos, mesh, color) in query.iter_mut(world) {
|
for (pos, mesh, color) in query.iter_mut(world) {
|
||||||
pass.set_bind_group(1, &mesh.bind_group, &[]);
|
pass.set_bind_group(1, &mesh.bind_group, &[]);
|
||||||
pass.set_index_buffer(mesh.index_buffer.slice(..));
|
// TODO: Pipe this in through the mesh
|
||||||
|
pass.set_index_buffer(mesh.index_buffer.slice(..), mesh.index_format);
|
||||||
pass.set_vertex_buffer(0, mesh.vertex_buffer.slice(..));
|
pass.set_vertex_buffer(0, mesh.vertex_buffer.slice(..));
|
||||||
pass.draw_indexed(0..mesh.index_count as u32, 0, 0..1);
|
pass.draw_indexed(0..mesh.index_count as u32, 0, 0..1);
|
||||||
}
|
}
|
||||||
@@ -355,25 +360,33 @@ impl Renderer {
|
|||||||
let index_count = indices.len();
|
let index_count = indices.len();
|
||||||
let (vertex_buf, index_buf) = Renderer::create_buffer(&self.device, indices, vertices);
|
let (vertex_buf, index_buf) = Renderer::create_buffer(&self.device, indices, vertices);
|
||||||
|
|
||||||
|
let uniform_size = mem::size_of::<EntityUniforms>() as wgpu::BufferAddress;
|
||||||
|
|
||||||
let uniform_buf = Arc::new(self.device.create_buffer(&wgpu::BufferDescriptor {
|
let uniform_buf = Arc::new(self.device.create_buffer(&wgpu::BufferDescriptor {
|
||||||
label: Some("Mesh Uniform Buf"),
|
label: Some("Mesh Uniform Buf"),
|
||||||
size: mem::size_of::<EntityUniforms>() as wgpu::BufferAddress,
|
size: uniform_size,
|
||||||
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
|
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
|
||||||
mapped_at_creation: false,
|
mapped_at_creation: false,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let bind_group = Arc::new(self.device.create_bind_group(&wgpu::BindGroupDescriptor {
|
let bind_group = Arc::new(self.device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||||
|
label: Some("Mesh Bind Group"),
|
||||||
layout: &self.entity_bind_group_layout,
|
layout: &self.entity_bind_group_layout,
|
||||||
entries: &[wgpu::BindGroupEntry {
|
entries: &[wgpu::BindGroupEntry {
|
||||||
binding: 0,
|
binding: 0,
|
||||||
resource: wgpu::BindingResource::Buffer(uniform_buf.slice(..)),
|
resource: wgpu::BindingResource::Buffer {
|
||||||
|
buffer: &uniform_buf,
|
||||||
|
offset: 0,
|
||||||
|
size: wgpu::BufferSize::new(uniform_size),
|
||||||
|
},
|
||||||
}],
|
}],
|
||||||
label: Some("Mesh Bind Group"),
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Mesh {
|
Mesh {
|
||||||
index_buffer: index_buf,
|
index_buffer: index_buf,
|
||||||
index_count: index_count,
|
index_count: index_count,
|
||||||
|
// TODO: This is hardcoded by tobj, maybe think about doing something a little more clever?
|
||||||
|
index_format: wgpu::IndexFormat::Uint32,
|
||||||
vertex_buffer: vertex_buf,
|
vertex_buffer: vertex_buf,
|
||||||
uniform_buffer: uniform_buf,
|
uniform_buffer: uniform_buf,
|
||||||
bind_group: bind_group,
|
bind_group: bind_group,
|
||||||
@@ -407,9 +420,9 @@ impl Renderer {
|
|||||||
// And then get the device we want
|
// And then get the device we want
|
||||||
let device = adapter.request_device(
|
let device = adapter.request_device(
|
||||||
&wgpu::DeviceDescriptor {
|
&wgpu::DeviceDescriptor {
|
||||||
|
label: Some("device descriptor"),
|
||||||
features: (optional_features & adapter_features) | required_features,
|
features: (optional_features & adapter_features) | required_features,
|
||||||
limits: needed_limits,
|
limits: needed_limits,
|
||||||
shader_validation: true,
|
|
||||||
},
|
},
|
||||||
trace_dir.ok().as_ref().map(std::path::Path::new),
|
trace_dir.ok().as_ref().map(std::path::Path::new),
|
||||||
);
|
);
|
||||||
@@ -421,7 +434,7 @@ impl Renderer {
|
|||||||
|
|
||||||
let mut sc_desc = (wgpu::SwapChainDescriptor {
|
let mut sc_desc = (wgpu::SwapChainDescriptor {
|
||||||
// Allows a texture to be a output attachment of a renderpass.
|
// Allows a texture to be a output attachment of a renderpass.
|
||||||
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
|
||||||
format: if cfg!(target_arch = "wasm32") {
|
format: if cfg!(target_arch = "wasm32") {
|
||||||
wgpu::TextureFormat::Bgra8Unorm
|
wgpu::TextureFormat::Bgra8Unorm
|
||||||
} else {
|
} else {
|
||||||
@@ -442,8 +455,8 @@ impl Renderer {
|
|||||||
// I wanted to get tricky with the 0,1 types
|
// I wanted to get tricky with the 0,1 types
|
||||||
let vertex_size = mem::size_of::<Vertex>();
|
let vertex_size = mem::size_of::<Vertex>();
|
||||||
let vertex_attr = wgpu::vertex_attr_array![0 => Float4, 1 => Float4];
|
let vertex_attr = wgpu::vertex_attr_array![0 => Float4, 1 => Float4];
|
||||||
let vb_desc = wgpu::VertexBufferDescriptor {
|
let vb_desc = wgpu::VertexBufferLayout {
|
||||||
stride: vertex_size as wgpu::BufferAddress,
|
array_stride: vertex_size as wgpu::BufferAddress,
|
||||||
step_mode: wgpu::InputStepMode::Vertex,
|
step_mode: wgpu::InputStepMode::Vertex,
|
||||||
attributes: &vertex_attr,
|
attributes: &vertex_attr,
|
||||||
};
|
};
|
||||||
@@ -456,11 +469,12 @@ impl Renderer {
|
|||||||
binding: 0,
|
binding: 0,
|
||||||
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
||||||
count: None,
|
count: None,
|
||||||
ty: wgpu::BindingType::UniformBuffer {
|
ty: wgpu::BindingType::Buffer {
|
||||||
dynamic: false,
|
ty: wgpu::BufferBindingType::Uniform,
|
||||||
min_binding_size: wgpu::BufferSize::new(
|
min_binding_size: wgpu::BufferSize::new(
|
||||||
mem::size_of::<EntityUniforms>() as _
|
mem::size_of::<EntityUniforms>() as _
|
||||||
),
|
),
|
||||||
|
has_dynamic_offset: false,
|
||||||
},
|
},
|
||||||
}],
|
}],
|
||||||
});
|
});
|
||||||
@@ -480,9 +494,10 @@ impl Renderer {
|
|||||||
entries: &[wgpu::BindGroupLayoutEntry {
|
entries: &[wgpu::BindGroupLayoutEntry {
|
||||||
binding: 0, // global
|
binding: 0, // global
|
||||||
visibility: wgpu::ShaderStage::VERTEX,
|
visibility: wgpu::ShaderStage::VERTEX,
|
||||||
ty: wgpu::BindingType::UniformBuffer {
|
ty: wgpu::BindingType::Buffer {
|
||||||
dynamic: false,
|
ty: wgpu::BufferBindingType::Uniform,
|
||||||
min_binding_size: wgpu::BufferSize::new(uniform_size),
|
min_binding_size: wgpu::BufferSize::new(uniform_size),
|
||||||
|
has_dynamic_offset: false,
|
||||||
},
|
},
|
||||||
count: None,
|
count: None,
|
||||||
}],
|
}],
|
||||||
@@ -508,51 +523,56 @@ impl Renderer {
|
|||||||
layout: &bind_group_layout,
|
layout: &bind_group_layout,
|
||||||
entries: &[wgpu::BindGroupEntry {
|
entries: &[wgpu::BindGroupEntry {
|
||||||
binding: 0,
|
binding: 0,
|
||||||
resource: wgpu::BindingResource::Buffer(uniform_buf.slice(..)),
|
resource: wgpu::BindingResource::Buffer {
|
||||||
|
buffer: &uniform_buf,
|
||||||
|
offset: 0,
|
||||||
|
size: wgpu::BufferSize::new(uniform_size),
|
||||||
|
},
|
||||||
}],
|
}],
|
||||||
label: Some("Shadow uniform bind group"),
|
label: Some("Shadow uniform bind group"),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create the render pipeline
|
// Create the render pipeline
|
||||||
let vs_module =
|
let vs_module =
|
||||||
device.create_shader_module(wgpu::include_spirv!("../resources/bake.vert.spv"));
|
device.create_shader_module(&wgpu::include_spirv!("../resources/bake.vert.spv"));
|
||||||
let fs_module =
|
let fs_module =
|
||||||
device.create_shader_module(wgpu::include_spirv!("../resources/bake.frag.spv"));
|
device.create_shader_module(&wgpu::include_spirv!("../resources/bake.frag.spv"));
|
||||||
|
|
||||||
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||||
label: Some("shadow"),
|
label: Some("shadow"),
|
||||||
layout: Some(&pipeline_layout),
|
layout: Some(&pipeline_layout),
|
||||||
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
|
||||||
|
vertex: VertexState {
|
||||||
module: &vs_module,
|
module: &vs_module,
|
||||||
entry_point: "main",
|
entry_point: "main",
|
||||||
|
buffers: &[vb_desc.clone()],
|
||||||
},
|
},
|
||||||
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
|
fragment: Some(FragmentState {
|
||||||
module: &fs_module,
|
module: &fs_module,
|
||||||
entry_point: "main",
|
entry_point: "main",
|
||||||
|
targets: &[],
|
||||||
}),
|
}),
|
||||||
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
|
primitive: wgpu::PrimitiveState {
|
||||||
|
topology: wgpu::PrimitiveTopology::TriangleList,
|
||||||
front_face: wgpu::FrontFace::Ccw,
|
front_face: wgpu::FrontFace::Ccw,
|
||||||
cull_mode: wgpu::CullMode::Back,
|
cull_mode: wgpu::CullMode::Back,
|
||||||
depth_bias: 2, // corresponds to bilinear filtering
|
..Default::default()
|
||||||
depth_bias_slope_scale: 2.0,
|
},
|
||||||
depth_bias_clamp: 0.0,
|
depth_stencil: Some(wgpu::DepthStencilState {
|
||||||
clamp_depth: device.features().contains(wgpu::Features::DEPTH_CLAMPING),
|
|
||||||
}),
|
|
||||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
|
||||||
color_states: &[],
|
|
||||||
depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor {
|
|
||||||
format: Self::SHADOW_FORMAT,
|
format: Self::SHADOW_FORMAT,
|
||||||
depth_write_enabled: true,
|
depth_write_enabled: true,
|
||||||
depth_compare: wgpu::CompareFunction::LessEqual,
|
depth_compare: wgpu::CompareFunction::LessEqual,
|
||||||
stencil: wgpu::StencilStateDescriptor::default(),
|
stencil: wgpu::StencilState::default(),
|
||||||
|
bias: wgpu::DepthBiasState {
|
||||||
|
constant: 2, // corresponds to bilinear filtering
|
||||||
|
slope_scale: 2.0,
|
||||||
|
clamp: 0.0,
|
||||||
|
},
|
||||||
|
clamp_depth: device.features().contains(
|
||||||
|
wgpu::Features::DEPTH_CLAMPING
|
||||||
|
),
|
||||||
}),
|
}),
|
||||||
vertex_state: wgpu::VertexStateDescriptor {
|
multisample: wgpu::MultisampleState::default(),
|
||||||
index_format: wgpu::IndexFormat::Uint32,
|
|
||||||
vertex_buffers: &[vb_desc.clone()],
|
|
||||||
},
|
|
||||||
sample_count: 1,
|
|
||||||
sample_mask: !0,
|
|
||||||
alpha_to_coverage_enabled: false,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Pass {
|
Pass {
|
||||||
@@ -581,7 +601,7 @@ impl Renderer {
|
|||||||
sample_count: 1,
|
sample_count: 1,
|
||||||
dimension: wgpu::TextureDimension::D2,
|
dimension: wgpu::TextureDimension::D2,
|
||||||
format: Self::SHADOW_FORMAT,
|
format: Self::SHADOW_FORMAT,
|
||||||
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT | wgpu::TextureUsage::SAMPLED,
|
usage: wgpu::TextureUsage::RENDER_ATTACHMENT | wgpu::TextureUsage::SAMPLED,
|
||||||
label: Some("Shadow texture"),
|
label: Some("Shadow texture"),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -615,39 +635,44 @@ impl Renderer {
|
|||||||
wgpu::BindGroupLayoutEntry {
|
wgpu::BindGroupLayoutEntry {
|
||||||
binding: 0, // global
|
binding: 0, // global
|
||||||
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
||||||
ty: wgpu::BindingType::UniformBuffer {
|
ty: wgpu::BindingType::Buffer {
|
||||||
dynamic: false,
|
ty: wgpu::BufferBindingType::Uniform,
|
||||||
min_binding_size: wgpu::BufferSize::new(mem::size_of::<
|
min_binding_size: wgpu::BufferSize::new(mem::size_of::<
|
||||||
ForwardUniforms,
|
ForwardUniforms,
|
||||||
>(
|
>(
|
||||||
)
|
)
|
||||||
as _),
|
as _),
|
||||||
|
has_dynamic_offset: false,
|
||||||
},
|
},
|
||||||
count: None,
|
count: None,
|
||||||
},
|
},
|
||||||
wgpu::BindGroupLayoutEntry {
|
wgpu::BindGroupLayoutEntry {
|
||||||
binding: 1, // lights
|
binding: 1, // lights
|
||||||
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
||||||
ty: wgpu::BindingType::UniformBuffer {
|
ty: wgpu::BindingType::Buffer {
|
||||||
dynamic: false,
|
ty: BufferBindingType::Uniform,
|
||||||
min_binding_size: wgpu::BufferSize::new(light_uniform_size),
|
min_binding_size: wgpu::BufferSize::new(light_uniform_size),
|
||||||
|
has_dynamic_offset: false,
|
||||||
},
|
},
|
||||||
count: None,
|
count: None,
|
||||||
},
|
},
|
||||||
wgpu::BindGroupLayoutEntry {
|
wgpu::BindGroupLayoutEntry {
|
||||||
binding: 2,
|
binding: 2,
|
||||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
visibility: wgpu::ShaderStage::FRAGMENT,
|
||||||
ty: wgpu::BindingType::SampledTexture {
|
ty: wgpu::BindingType::Texture {
|
||||||
multisampled: false,
|
multisampled: false,
|
||||||
component_type: wgpu::TextureComponentType::Float,
|
sample_type: wgpu::TextureSampleType::Depth,
|
||||||
dimension: wgpu::TextureViewDimension::D2Array,
|
view_dimension: wgpu::TextureViewDimension::D2Array,
|
||||||
},
|
},
|
||||||
count: None,
|
count: None,
|
||||||
},
|
},
|
||||||
wgpu::BindGroupLayoutEntry {
|
wgpu::BindGroupLayoutEntry {
|
||||||
binding: 3,
|
binding: 3,
|
||||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
visibility: wgpu::ShaderStage::FRAGMENT,
|
||||||
ty: wgpu::BindingType::Sampler { comparison: true },
|
ty: wgpu::BindingType::Sampler {
|
||||||
|
filtering: false,
|
||||||
|
comparison: true,
|
||||||
|
},
|
||||||
count: None,
|
count: None,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -687,17 +712,29 @@ impl Renderer {
|
|||||||
|
|
||||||
let shadow_view = shadow_texture.create_view(&wgpu::TextureViewDescriptor::default());
|
let shadow_view = shadow_texture.create_view(&wgpu::TextureViewDescriptor::default());
|
||||||
|
|
||||||
|
let forward_uniform_size =
|
||||||
|
wgpu::BufferSize::new(mem::size_of::<ForwardUniforms>() as wgpu::BufferAddress);
|
||||||
|
let light_uniform_size = wgpu::BufferSize::new(light_uniform_size);
|
||||||
|
|
||||||
// Create bind group
|
// Create bind group
|
||||||
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||||
layout: &bind_group_layout,
|
layout: &bind_group_layout,
|
||||||
entries: &[
|
entries: &[
|
||||||
wgpu::BindGroupEntry {
|
wgpu::BindGroupEntry {
|
||||||
binding: 0,
|
binding: 0,
|
||||||
resource: wgpu::BindingResource::Buffer(uniform_buf.slice(..)),
|
resource: wgpu::BindingResource::Buffer {
|
||||||
|
buffer: &uniform_buf,
|
||||||
|
offset: 0,
|
||||||
|
size: forward_uniform_size,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
wgpu::BindGroupEntry {
|
wgpu::BindGroupEntry {
|
||||||
binding: 1,
|
binding: 1,
|
||||||
resource: wgpu::BindingResource::Buffer(light_uniform_buf.slice(..)),
|
resource: wgpu::BindingResource::Buffer {
|
||||||
|
buffer: &light_uniform_buf,
|
||||||
|
offset: 0,
|
||||||
|
size: light_uniform_size,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
wgpu::BindGroupEntry {
|
wgpu::BindGroupEntry {
|
||||||
binding: 2,
|
binding: 2,
|
||||||
@@ -713,41 +750,37 @@ impl Renderer {
|
|||||||
|
|
||||||
// Create the render pipeline
|
// Create the render pipeline
|
||||||
let vs_module =
|
let vs_module =
|
||||||
device.create_shader_module(wgpu::include_spirv!("../resources/forward.vert.spv"));
|
device.create_shader_module(&wgpu::include_spirv!("../resources/forward.vert.spv"));
|
||||||
let fs_module =
|
let fs_module =
|
||||||
device.create_shader_module(wgpu::include_spirv!("../resources/forward.frag.spv"));
|
device.create_shader_module(&wgpu::include_spirv!("../resources/forward.frag.spv"));
|
||||||
|
|
||||||
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||||
label: Some("main"),
|
label: Some("main"),
|
||||||
layout: Some(&pipeline_layout),
|
layout: Some(&pipeline_layout),
|
||||||
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
vertex: VertexState {
|
||||||
module: &vs_module,
|
module: &vs_module,
|
||||||
entry_point: "main",
|
entry_point: "main",
|
||||||
|
buffers: &[vb_desc],
|
||||||
},
|
},
|
||||||
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
|
fragment: Some(FragmentState {
|
||||||
module: &fs_module,
|
module: &fs_module,
|
||||||
entry_point: "main",
|
entry_point: "main",
|
||||||
|
targets: &[sc_desc.format.into()],
|
||||||
}),
|
}),
|
||||||
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
|
primitive: wgpu::PrimitiveState {
|
||||||
front_face: wgpu::FrontFace::Ccw,
|
front_face: wgpu::FrontFace::Ccw,
|
||||||
cull_mode: wgpu::CullMode::Back,
|
cull_mode: wgpu::CullMode::Back,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
},
|
||||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
depth_stencil: Some(wgpu::DepthStencilState {
|
||||||
color_states: &[sc_desc.format.into()],
|
|
||||||
depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor {
|
|
||||||
format: Self::DEPTH_FORMAT,
|
format: Self::DEPTH_FORMAT,
|
||||||
depth_write_enabled: true,
|
depth_write_enabled: true,
|
||||||
depth_compare: wgpu::CompareFunction::Less,
|
depth_compare: wgpu::CompareFunction::Less,
|
||||||
stencil: wgpu::StencilStateDescriptor::default(),
|
stencil: wgpu::StencilState::default(),
|
||||||
|
bias: wgpu::DepthBiasState::default(),
|
||||||
|
clamp_depth: false,
|
||||||
}),
|
}),
|
||||||
vertex_state: wgpu::VertexStateDescriptor {
|
multisample: Default::default(),
|
||||||
index_format: wgpu::IndexFormat::Uint32,
|
|
||||||
vertex_buffers: &[vb_desc],
|
|
||||||
},
|
|
||||||
sample_count: 1,
|
|
||||||
sample_mask: !0,
|
|
||||||
alpha_to_coverage_enabled: false,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Pass {
|
Pass {
|
||||||
@@ -767,7 +800,7 @@ impl Renderer {
|
|||||||
sample_count: 1,
|
sample_count: 1,
|
||||||
dimension: wgpu::TextureDimension::D2,
|
dimension: wgpu::TextureDimension::D2,
|
||||||
format: Self::DEPTH_FORMAT,
|
format: Self::DEPTH_FORMAT,
|
||||||
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
|
||||||
label: Some("Depth Texture"),
|
label: Some("Depth Texture"),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -825,7 +858,7 @@ impl Renderer {
|
|||||||
sample_count: 1,
|
sample_count: 1,
|
||||||
dimension: wgpu::TextureDimension::D2,
|
dimension: wgpu::TextureDimension::D2,
|
||||||
format: Self::DEPTH_FORMAT,
|
format: Self::DEPTH_FORMAT,
|
||||||
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
|
||||||
label: Some("Depth Texture"),
|
label: Some("Depth Texture"),
|
||||||
});
|
});
|
||||||
self.forward_depth = depth_texture.create_view(&wgpu::TextureViewDescriptor::default());
|
self.forward_depth = depth_texture.create_view(&wgpu::TextureViewDescriptor::default());
|
||||||
|
|||||||
Reference in New Issue
Block a user