summaryrefslogtreecommitdiff
path: root/client/src/scene_render.rs
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/scene_render.rs')
-rw-r--r--client/src/scene_render.rs142
1 files changed, 14 insertions, 128 deletions
diff --git a/client/src/scene_render.rs b/client/src/scene_render.rs
index 77217d6..d621ba6 100644
--- a/client/src/scene_render.rs
+++ b/client/src/scene_render.rs
@@ -14,42 +14,28 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+use crate::scene_prepare::{DemandMap, RPrefab};
use glam::{EulerRot, Mat3, Mat4};
use std::sync::Arc;
use weareshared::{packets::Resource, resources::Prefab, tree::SceneTree};
use wgpu::{
- BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, BlendState,
- 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,
- RenderPipelineDescriptor, SamplerBindingType, ShaderStages, StencilState, StoreOp,
- TextureFormat, TextureSampleType, TextureView, TextureViewDimension, VertexAttribute,
- VertexBufferLayout, VertexFormat, VertexState, VertexStepMode, include_wgsl,
+ BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType,
+ BufferBindingType, Color, CommandEncoder, Device, IndexFormat, LoadOp, Operations,
+ RenderPassColorAttachment, RenderPassDepthStencilAttachment, RenderPassDescriptor,
+ SamplerBindingType, ShaderStages, StoreOp, TextureSampleType, TextureView,
+ TextureViewDimension,
};
-use crate::scene_prepare::{DemandMap, RPrefab};
-
-pub struct ScenePipeline {
- pipeline: RenderPipeline,
- pipeline_no_cull: RenderPipeline,
-}
+pub struct ScenePipeline;
pub struct SceneBgLayouts {
pub texture: BindGroupLayout,
pub material: BindGroupLayout,
pub joints: BindGroupLayout,
}
-
-impl ScenePipeline {
- pub fn new(device: &Device, format: TextureFormat) -> (Self, SceneBgLayouts) {
- let fragment_pbr = device.create_shader_module(include_wgsl!("shaders/fragment_pbr.wgsl"));
- let vertex_world = device.create_shader_module(include_wgsl!("shaders/vertex_world.wgsl"));
- let _vertex_world_skin =
- device.create_shader_module(include_wgsl!("shaders/vertex_world_skin.wgsl"));
-
- let layouts = SceneBgLayouts {
+impl SceneBgLayouts {
+ pub fn load(device: &Device) -> Self {
+ Self {
texture: device.create_bind_group_layout(&BindGroupLayoutDescriptor {
entries: &[
BindGroupLayoutEntry {
@@ -97,105 +83,11 @@ impl ScenePipeline {
}],
label: None,
}),
- };
-
- let pipeline_layout = device.create_pipeline_layout(&PipelineLayoutDescriptor {
- label: None,
- bind_group_layouts: &[&layouts.texture, &layouts.texture, &layouts.material],
- push_constant_ranges: &[PushConstantRange {
- range: 0..((4 * 4 + 3 * 4) * size_of::<f32>() as u32),
- stages: ShaderStages::VERTEX,
- }],
- });
- let [pipeline, pipeline_no_cull] = [Some(Face::Back), None].map(|cull_mode| {
- device.create_render_pipeline(&RenderPipelineDescriptor {
- label: None,
- layout: Some(&pipeline_layout),
- fragment: Some(FragmentState {
- module: &fragment_pbr,
- entry_point: Some("main"),
- targets: &[Some(ColorTargetState {
- blend: Some(BlendState::PREMULTIPLIED_ALPHA_BLENDING),
- format,
- write_mask: ColorWrites::all(),
- })],
- compilation_options: PipelineCompilationOptions::default(),
- }),
- vertex: VertexState {
- module: &vertex_world,
- entry_point: Some("main"),
- buffers: &[
- // position
- VertexBufferLayout {
- step_mode: VertexStepMode::Vertex,
- array_stride: 3 * size_of::<f32>() as u64,
- attributes: &[VertexAttribute {
- format: VertexFormat::Float32x3,
- offset: 0,
- shader_location: 0,
- }],
- },
- // normal
- VertexBufferLayout {
- step_mode: VertexStepMode::Vertex,
- array_stride: 3 * size_of::<f32>() as u64,
- attributes: &[VertexAttribute {
- format: VertexFormat::Float32x3,
- offset: 0,
- shader_location: 1,
- }],
- },
- // tangent
- VertexBufferLayout {
- step_mode: VertexStepMode::Vertex,
- array_stride: 3 * size_of::<f32>() as u64,
- attributes: &[VertexAttribute {
- format: VertexFormat::Float32x3,
- offset: 0,
- shader_location: 2,
- }],
- },
- // texcoord
- VertexBufferLayout {
- step_mode: VertexStepMode::Vertex,
- array_stride: 2 * size_of::<f32>() as u64,
- attributes: &[VertexAttribute {
- format: VertexFormat::Float32x2,
- offset: 0,
- shader_location: 3,
- }],
- },
- ],
- compilation_options: PipelineCompilationOptions::default(),
- },
- primitive: PrimitiveState {
- topology: PrimitiveTopology::TriangleList,
- front_face: FrontFace::Ccw,
- cull_mode,
- polygon_mode: PolygonMode::Fill,
- ..Default::default()
- },
- depth_stencil: Some(DepthStencilState {
- depth_write_enabled: true,
- depth_compare: CompareFunction::Less,
- format: TextureFormat::Depth32Float,
- bias: DepthBiasState::default(),
- stencil: StencilState::default(),
- }),
- multisample: MultisampleState::default(),
- multiview: None,
- cache: None,
- })
- });
- (
- Self {
- pipeline,
- pipeline_no_cull,
- },
- layouts,
- )
+ }
}
+}
+impl ScenePipeline {
pub fn draw(
&mut self,
commands: &mut CommandEncoder,
@@ -255,13 +147,7 @@ impl ScenePipeline {
];
let model_basis = bytemuck::cast_slice(&model_basis);
- let pipeline = if part.double_sided {
- &self.pipeline_no_cull
- } else {
- &self.pipeline
- };
-
- rpass.set_pipeline(pipeline);
+ rpass.set_pipeline(&part.pipeline);
rpass.set_bind_group(0, &*part.tex_albedo, &[]);
rpass.set_bind_group(1, &*part.tex_normal, &[]);
rpass.set_bind_group(2, &*part.material, &[]);