diff options
Diffstat (limited to 'client/src/scene_render.rs')
-rw-r--r-- | client/src/scene_render.rs | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/client/src/scene_render.rs b/client/src/scene_render.rs index 3ec96b3..2100d28 100644 --- a/client/src/scene_render.rs +++ b/client/src/scene_render.rs @@ -19,8 +19,8 @@ use std::sync::Arc; use weareshared::{packets::Resource, resources::Prefab, tree::SceneTree}; use wgpu::{ BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, BlendState, - Color, ColorTargetState, ColorWrites, CommandEncoder, CompareFunction, DepthBiasState, - DepthStencilState, Device, Face, FragmentState, FrontFace, IndexFormat, LoadOp, + BufferBindingType, Color, ColorTargetState, ColorWrites, CommandEncoder, CompareFunction, + DepthBiasState, DepthStencilState, Device, Face, FragmentState, FrontFace, IndexFormat, LoadOp, MultisampleState, Operations, PipelineCompilationOptions, PipelineLayoutDescriptor, PolygonMode, PrimitiveState, PrimitiveTopology, PushConstantRange, RenderPassColorAttachment, RenderPassDepthStencilAttachment, RenderPassDescriptor, RenderPipeline, @@ -37,10 +37,10 @@ pub struct ScenePipeline { } impl ScenePipeline { - pub fn new(device: &Device, format: TextureFormat) -> (Self, BindGroupLayout) { + pub fn new(device: &Device, format: TextureFormat) -> (Self, BindGroupLayout, BindGroupLayout) { let module = device.create_shader_module(include_wgsl!("shader.wgsl")); - let bind_group_layout = device.create_bind_group_layout(&BindGroupLayoutDescriptor { + let texture_bgl = device.create_bind_group_layout(&BindGroupLayoutDescriptor { entries: &[ BindGroupLayoutEntry { binding: 0, @@ -61,9 +61,22 @@ impl ScenePipeline { ], label: None, }); + let material_bgl = device.create_bind_group_layout(&BindGroupLayoutDescriptor { + entries: &[BindGroupLayoutEntry { + binding: 0, + count: None, + visibility: ShaderStages::FRAGMENT, + ty: BindingType::Buffer { + ty: BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: None, + }, + }], + label: None, + }); let pipeline_layout = device.create_pipeline_layout(&PipelineLayoutDescriptor { label: None, - bind_group_layouts: &[&bind_group_layout, &bind_group_layout], + bind_group_layouts: &[&texture_bgl, &texture_bgl, &material_bgl], push_constant_ranges: &[PushConstantRange { range: 0..((4 * 4 + 3 * 4) * size_of::<f32>() as u32), stages: ShaderStages::VERTEX, @@ -154,7 +167,8 @@ impl ScenePipeline { pipeline, pipeline_no_cull, }, - bind_group_layout, + texture_bgl, + material_bgl, ) } @@ -226,6 +240,7 @@ impl ScenePipeline { rpass.set_pipeline(pipeline); rpass.set_bind_group(0, &*part.tex_albedo, &[]); rpass.set_bind_group(1, &*part.tex_normal, &[]); + rpass.set_bind_group(2, &*part.material, &[]); rpass.set_push_constants(ShaderStages::VERTEX, 0, projection.as_flattened()); rpass.set_push_constants(ShaderStages::VERTEX, 64, model_basis); rpass.set_index_buffer(part.index.slice(..), IndexFormat::Uint32); |