render: cull back faces, code cleanup to fix warnings
This commit is contained in:
parent
fd65f754cf
commit
6d57b40629
|
@ -136,6 +136,12 @@ fn setup_scene_plugin(game: &mut Game) {
|
||||||
Transform::from_xyz(0.0, -2.0, -5.0),
|
Transform::from_xyz(0.0, -2.0, -5.0),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
world.spawn((
|
||||||
|
cube_mesh.clone(),
|
||||||
|
WorldTransform::default(),
|
||||||
|
Transform::from_xyz(3.0, -3.75, -5.0),
|
||||||
|
));
|
||||||
|
|
||||||
world.spawn((
|
world.spawn((
|
||||||
platform_mesh.clone(),
|
platform_mesh.clone(),
|
||||||
WorldTransform::default(),
|
WorldTransform::default(),
|
||||||
|
|
|
@ -80,7 +80,7 @@ impl MeshPass {
|
||||||
impl Node for MeshPass {
|
impl Node for MeshPass {
|
||||||
fn desc(
|
fn desc(
|
||||||
&mut self,
|
&mut self,
|
||||||
graph: &mut crate::render::graph::RenderGraph,
|
_: &mut crate::render::graph::RenderGraph,
|
||||||
) -> crate::render::graph::NodeDesc {
|
) -> crate::render::graph::NodeDesc {
|
||||||
// load the default texture
|
// load the default texture
|
||||||
//let bytes = include_bytes!("../../default_texture.png");
|
//let bytes = include_bytes!("../../default_texture.png");
|
||||||
|
@ -244,7 +244,10 @@ impl Node for MeshPass {
|
||||||
stencil: wgpu::StencilState::default(), // TODO: stencil buffer
|
stencil: wgpu::StencilState::default(), // TODO: stencil buffer
|
||||||
bias: wgpu::DepthBiasState::default(),
|
bias: wgpu::DepthBiasState::default(),
|
||||||
}),
|
}),
|
||||||
primitive: wgpu::PrimitiveState::default(),
|
primitive: wgpu::PrimitiveState {
|
||||||
|
cull_mode: Some(wgpu::Face::Back),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
multisample: wgpu::MultisampleState::default(),
|
multisample: wgpu::MultisampleState::default(),
|
||||||
multiview: None,
|
multiview: None,
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use std::{mem, num::NonZeroU64, rc::Rc, sync::Arc};
|
use std::{mem, num::NonZeroU64, rc::Rc, sync::Arc};
|
||||||
|
|
||||||
use lyra_ecs::{query::Entities, AtomicRef, Entity, ResourceData};
|
use lyra_ecs::{query::{filter::Has, Entities}, AtomicRef, Entity, ResourceData};
|
||||||
use lyra_game_derive::RenderGraphLabel;
|
use lyra_game_derive::RenderGraphLabel;
|
||||||
use lyra_math::{Transform, OPENGL_TO_WGPU_MATRIX};
|
use lyra_math::Transform;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use tracing::{debug, warn};
|
use tracing::{debug, warn};
|
||||||
use wgpu::util::DeviceExt;
|
use wgpu::util::DeviceExt;
|
||||||
|
@ -11,7 +11,7 @@ use crate::render::{
|
||||||
graph::{Node, NodeDesc, NodeType, SlotAttribute, SlotValue},
|
graph::{Node, NodeDesc, NodeType, SlotAttribute, SlotValue},
|
||||||
light::directional::DirectionalLight,
|
light::directional::DirectionalLight,
|
||||||
resource::{
|
resource::{
|
||||||
FragmentState, PipelineDescriptor, RenderPipeline, RenderPipelineDescriptor, Shader,
|
RenderPipeline, RenderPipelineDescriptor, Shader,
|
||||||
VertexState,
|
VertexState,
|
||||||
},
|
},
|
||||||
transform_buffer_storage::TransformBuffers,
|
transform_buffer_storage::TransformBuffers,
|
||||||
|
@ -181,7 +181,7 @@ impl ShadowMapsPass {
|
||||||
impl Node for ShadowMapsPass {
|
impl Node for ShadowMapsPass {
|
||||||
fn desc(
|
fn desc(
|
||||||
&mut self,
|
&mut self,
|
||||||
graph: &mut crate::render::graph::RenderGraph,
|
_: &mut crate::render::graph::RenderGraph,
|
||||||
) -> crate::render::graph::NodeDesc {
|
) -> crate::render::graph::NodeDesc {
|
||||||
let mut node = NodeDesc::new(NodeType::Render, None, vec![]);
|
let mut node = NodeDesc::new(NodeType::Render, None, vec![]);
|
||||||
|
|
||||||
|
@ -216,13 +216,13 @@ impl Node for ShadowMapsPass {
|
||||||
&mut self,
|
&mut self,
|
||||||
graph: &mut crate::render::graph::RenderGraph,
|
graph: &mut crate::render::graph::RenderGraph,
|
||||||
world: &mut lyra_ecs::World,
|
world: &mut lyra_ecs::World,
|
||||||
context: &mut crate::render::graph::RenderGraphContext,
|
_: &mut crate::render::graph::RenderGraphContext,
|
||||||
) {
|
) {
|
||||||
self.render_meshes = world.try_get_resource_data::<RenderMeshes>();
|
self.render_meshes = world.try_get_resource_data::<RenderMeshes>();
|
||||||
self.transform_buffers = world.try_get_resource_data::<TransformBuffers>();
|
self.transform_buffers = world.try_get_resource_data::<TransformBuffers>();
|
||||||
self.mesh_buffers = world.try_get_resource_data::<RenderAssets<MeshBufferStorage>>();
|
self.mesh_buffers = world.try_get_resource_data::<RenderAssets<MeshBufferStorage>>();
|
||||||
|
|
||||||
for (entity, pos, light) in world.view_iter::<(Entities, &Transform, &DirectionalLight)>() {
|
for (entity, pos, _) in world.view_iter::<(Entities, &Transform, Has<DirectionalLight>)>() {
|
||||||
if !self.depth_maps.contains_key(&entity) {
|
if !self.depth_maps.contains_key(&entity) {
|
||||||
self.create_depth_map(graph.device(), entity, *pos);
|
self.create_depth_map(graph.device(), entity, *pos);
|
||||||
debug!("Created depth map for {:?} light entity", entity);
|
debug!("Created depth map for {:?} light entity", entity);
|
||||||
|
@ -267,7 +267,10 @@ impl Node for ShadowMapsPass {
|
||||||
stencil: wgpu::StencilState::default(),
|
stencil: wgpu::StencilState::default(),
|
||||||
bias: wgpu::DepthBiasState::default(),
|
bias: wgpu::DepthBiasState::default(),
|
||||||
}),
|
}),
|
||||||
primitive: wgpu::PrimitiveState::default(),
|
primitive: wgpu::PrimitiveState {
|
||||||
|
cull_mode: Some(wgpu::Face::Back),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
multisample: wgpu::MultisampleState::default(),
|
multisample: wgpu::MultisampleState::default(),
|
||||||
multiview: None,
|
multiview: None,
|
||||||
},
|
},
|
||||||
|
@ -278,8 +281,8 @@ impl Node for ShadowMapsPass {
|
||||||
|
|
||||||
fn execute(
|
fn execute(
|
||||||
&mut self,
|
&mut self,
|
||||||
graph: &mut crate::render::graph::RenderGraph,
|
_: &mut crate::render::graph::RenderGraph,
|
||||||
desc: &crate::render::graph::NodeDesc,
|
_: &crate::render::graph::NodeDesc,
|
||||||
context: &mut crate::render::graph::RenderGraphContext,
|
context: &mut crate::render::graph::RenderGraphContext,
|
||||||
) {
|
) {
|
||||||
let encoder = context.encoder.as_mut().unwrap();
|
let encoder = context.encoder.as_mut().unwrap();
|
||||||
|
|
|
@ -149,25 +149,7 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
|
||||||
let light: Light = u_lights.data[light_index];
|
let light: Light = u_lights.data[light_index];
|
||||||
|
|
||||||
if (light.light_ty == LIGHT_TY_DIRECTIONAL) {
|
if (light.light_ty == LIGHT_TY_DIRECTIONAL) {
|
||||||
/*let shadow = calc_shadow(in.frag_pos_light_space);
|
|
||||||
return vec4<f32>(vec3<f32>(shadow), 1.0);*/
|
|
||||||
|
|
||||||
/*var proj_coords = in.frag_pos_light_space / in.frag_pos_light_space.w;
|
|
||||||
proj_coords = proj_coords * 0.5 + 0.5;
|
|
||||||
|
|
||||||
let closest_depth = textureSampleLevel(t_shadow_maps_atlas, s_shadow_maps_atlas, proj_coords.xy, 0.0);
|
|
||||||
let current_depth = proj_coords.z;
|
|
||||||
|
|
||||||
if current_depth > closest_depth {
|
|
||||||
return vec4<f32>(vec3<f32>(current_depth), 1.0);
|
|
||||||
} else {
|
|
||||||
return vec4<f32>(vec3<f32>(closest_depth), 1.0);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
//return vec4<f32>(vec3<f32>(closest_depth), 1.0);
|
|
||||||
//let shadow = select(0.0, 1.0, current_depth > closest_depth);
|
|
||||||
let light_dir = normalize(-light.direction);
|
let light_dir = normalize(-light.direction);
|
||||||
|
|
||||||
let shadow = calc_shadow(in.world_normal, light_dir, in.frag_pos_light_space);
|
let shadow = calc_shadow(in.world_normal, light_dir, in.frag_pos_light_space);
|
||||||
light_res += blinn_phong_dir_light(in.world_position, in.world_normal, light, u_material, specular_color, shadow);
|
light_res += blinn_phong_dir_light(in.world_position, in.world_normal, light, u_material, specular_color, shadow);
|
||||||
} else if (light.light_ty == LIGHT_TY_POINT) {
|
} else if (light.light_ty == LIGHT_TY_POINT) {
|
||||||
|
|
Loading…
Reference in New Issue