|
|
|
@ -3,7 +3,6 @@ use rayon::prelude::*;
|
|
|
|
|
use std::iter;
|
|
|
|
|
use wgpu::util::DeviceExt;
|
|
|
|
|
use winit::{
|
|
|
|
|
dpi::PhysicalPosition,
|
|
|
|
|
event::*,
|
|
|
|
|
event_loop::{ControlFlow, EventLoop},
|
|
|
|
|
window::Window,
|
|
|
|
@ -134,7 +133,6 @@ struct State {
|
|
|
|
|
light_render_pipeline: wgpu::RenderPipeline,
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
debug_material: model::Material,
|
|
|
|
|
last_mouse_pos: PhysicalPosition<f64>,
|
|
|
|
|
mouse_pressed: bool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -143,12 +141,12 @@ fn create_render_pipeline(
|
|
|
|
|
layout: &wgpu::PipelineLayout,
|
|
|
|
|
color_format: wgpu::TextureFormat,
|
|
|
|
|
depth_format: Option<wgpu::TextureFormat>,
|
|
|
|
|
vertex_descs: &[wgpu::VertexBufferLayout],
|
|
|
|
|
vs_src: wgpu::ShaderModuleSource,
|
|
|
|
|
fs_src: wgpu::ShaderModuleSource,
|
|
|
|
|
vertex_layouts: &[wgpu::VertexBufferLayout],
|
|
|
|
|
vs_src: wgpu::ShaderModuleDescriptor,
|
|
|
|
|
fs_src: wgpu::ShaderModuleDescriptor,
|
|
|
|
|
) -> wgpu::RenderPipeline {
|
|
|
|
|
let vs_module = device.create_shader_module(vs_src);
|
|
|
|
|
let fs_module = device.create_shader_module(fs_src);
|
|
|
|
|
let vs_module = device.create_shader_module(&vs_src);
|
|
|
|
|
let fs_module = device.create_shader_module(&fs_src);
|
|
|
|
|
|
|
|
|
|
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
|
|
|
|
label: Some("Render Pipeline"),
|
|
|
|
@ -156,18 +154,17 @@ fn create_render_pipeline(
|
|
|
|
|
vertex: wgpu::VertexState {
|
|
|
|
|
module: &vs_module,
|
|
|
|
|
entry_point: "main",
|
|
|
|
|
buffers: vertex_layouts,
|
|
|
|
|
},
|
|
|
|
|
fragment: Some(wgpu::FragmentState {
|
|
|
|
|
module: &fs_module,
|
|
|
|
|
entry_point: "main",
|
|
|
|
|
}),
|
|
|
|
|
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
|
|
|
|
|
front_face: wgpu::FrontFace::Ccw,
|
|
|
|
|
cull_mode: wgpu::CullMode::Back,
|
|
|
|
|
depth_bias: 0,
|
|
|
|
|
depth_bias_slope_scale: 0.0,
|
|
|
|
|
depth_bias_clamp: 0.0,
|
|
|
|
|
clamp_depth: false,
|
|
|
|
|
targets: &[wgpu::ColorTargetState {
|
|
|
|
|
format: color_format,
|
|
|
|
|
alpha_blend: wgpu::BlendState::REPLACE,
|
|
|
|
|
color_blend: wgpu::BlendState::REPLACE,
|
|
|
|
|
write_mask: wgpu::ColorWrite::ALL,
|
|
|
|
|
}],
|
|
|
|
|
}),
|
|
|
|
|
primitive: wgpu::PrimitiveState {
|
|
|
|
|
topology: wgpu::PrimitiveTopology::TriangleList,
|
|
|
|
@ -177,26 +174,19 @@ fn create_render_pipeline(
|
|
|
|
|
// Setting this to anything other than Fill requires Features::NON_FILL_POLYGON_MODE
|
|
|
|
|
polygon_mode: wgpu::PolygonMode::Fill,
|
|
|
|
|
},
|
|
|
|
|
color_states: &[wgpu::ColorStateDescriptor {
|
|
|
|
|
format: color_format,
|
|
|
|
|
color_blend: wgpu::BlendDescriptor::REPLACE,
|
|
|
|
|
alpha_blend: wgpu::BlendDescriptor::REPLACE,
|
|
|
|
|
write_mask: wgpu::ColorWrite::ALL,
|
|
|
|
|
}],
|
|
|
|
|
depth_stencil: depth_format.map(|format| wgpu::DepthStencilState {
|
|
|
|
|
format,
|
|
|
|
|
depth_write_enabled: true,
|
|
|
|
|
depth_compare: wgpu::CompareFunction::Less,
|
|
|
|
|
stencil: wgpu::StencilState::default(),
|
|
|
|
|
bias: wgpu::DepthBiasState::default(),
|
|
|
|
|
// Setting this to true requires Features::DEPTH_CLAMPING
|
|
|
|
|
clamp_depth: false, }),
|
|
|
|
|
sample_count: 1,
|
|
|
|
|
sample_mask: !0,
|
|
|
|
|
alpha_to_coverage_enabled: false,
|
|
|
|
|
vertex_state: wgpu::VertexStateDescriptor {
|
|
|
|
|
index_format: wgpu::IndexFormat::Uint32,
|
|
|
|
|
vertex_buffers: vertex_descs,
|
|
|
|
|
bias: wgpu::DepthBiasState::default(),
|
|
|
|
|
// Setting this to true requires Features::DEPTH_CLAMPING
|
|
|
|
|
clamp_depth: false,
|
|
|
|
|
}),
|
|
|
|
|
multisample: wgpu::MultisampleState {
|
|
|
|
|
count: 1,
|
|
|
|
|
mask: !0,
|
|
|
|
|
alpha_to_coverage_enabled: false,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
@ -244,10 +234,10 @@ impl State {
|
|
|
|
|
wgpu::BindGroupLayoutEntry {
|
|
|
|
|
binding: 0,
|
|
|
|
|
visibility: wgpu::ShaderStage::FRAGMENT,
|
|
|
|
|
ty: wgpu::BindingType::SampledTexture {
|
|
|
|
|
ty: wgpu::BindingType::Texture {
|
|
|
|
|
multisampled: false,
|
|
|
|
|
component_type: wgpu::TextureComponentType::Float,
|
|
|
|
|
dimension: wgpu::TextureViewDimension::D2,
|
|
|
|
|
sample_type: wgpu::TextureSampleType::Float { filterable: true },
|
|
|
|
|
view_dimension: wgpu::TextureViewDimension::D2,
|
|
|
|
|
},
|
|
|
|
|
count: None,
|
|
|
|
|
},
|
|
|
|
@ -264,10 +254,10 @@ impl State {
|
|
|
|
|
wgpu::BindGroupLayoutEntry {
|
|
|
|
|
binding: 2,
|
|
|
|
|
visibility: wgpu::ShaderStage::FRAGMENT,
|
|
|
|
|
ty: wgpu::BindingType::SampledTexture {
|
|
|
|
|
ty: wgpu::BindingType::Texture {
|
|
|
|
|
multisampled: false,
|
|
|
|
|
component_type: wgpu::TextureComponentType::Float,
|
|
|
|
|
dimension: wgpu::TextureViewDimension::D2,
|
|
|
|
|
sample_type: wgpu::TextureSampleType::Float { filterable: true },
|
|
|
|
|
view_dimension: wgpu::TextureViewDimension::D2,
|
|
|
|
|
},
|
|
|
|
|
count: None,
|
|
|
|
|
},
|
|
|
|
@ -398,7 +388,7 @@ impl State {
|
|
|
|
|
layout: &light_bind_group_layout,
|
|
|
|
|
entries: &[wgpu::BindGroupEntry {
|
|
|
|
|
binding: 0,
|
|
|
|
|
resource: wgpu::BindingResource::Buffer(light_buffer.slice(..)),
|
|
|
|
|
resource: light_buffer.as_entire_binding(),
|
|
|
|
|
}],
|
|
|
|
|
label: None,
|
|
|
|
|
});
|
|
|
|
@ -499,7 +489,6 @@ impl State {
|
|
|
|
|
light_render_pipeline,
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
debug_material,
|
|
|
|
|
last_mouse_pos: (0.0, 0.0).into(),
|
|
|
|
|
mouse_pressed: false,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|