summaryrefslogtreecommitdiff
path: root/client/src/scene_render.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-01-19 20:36:21 +0100
committermetamuffin <metamuffin@disroot.org>2025-01-19 20:36:21 +0100
commit5ef0fc14d1d12cc5e7cc6a1fb896953d6d668891 (patch)
tree7a8a3258965b250e7c6bce39cfad3b8c0c452a5e /client/src/scene_render.rs
parent736c0c34b9e727bf4b25e800f748199d13ff561f (diff)
downloadweareserver-5ef0fc14d1d12cc5e7cc6a1fb896953d6d668891.tar
weareserver-5ef0fc14d1d12cc5e7cc6a1fb896953d6d668891.tar.bz2
weareserver-5ef0fc14d1d12cc5e7cc6a1fb896953d6d668891.tar.zst
client: send material data to shader
Diffstat (limited to 'client/src/scene_render.rs')
-rw-r--r--client/src/scene_render.rs27
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);