From c5921163d3f793ca019399d0c5655493d0ae8d85 Mon Sep 17 00:00:00 2001 From: Dmitry Stepanov Date: Thu, 24 Oct 2024 16:27:17 +0300 Subject: [PATCH] fixed visible borders around point lights - reduced code bloat a bit --- fyrox-impl/src/renderer/light/mod.rs | 99 ++++++++++------------------ 1 file changed, 36 insertions(+), 63 deletions(-) diff --git a/fyrox-impl/src/renderer/light/mod.rs b/fyrox-impl/src/renderer/light/mod.rs index bc878647e..98a83db87 100644 --- a/fyrox-impl/src/renderer/light/mod.rs +++ b/fyrox-impl/src/renderer/light/mod.rs @@ -188,7 +188,7 @@ impl DeferredLightRenderer { server, )?, sphere: ::from_surface_data( - &SurfaceData::make_sphere(6, 6, 1.0, &Matrix4::identity()), + &SurfaceData::make_sphere(10, 10, 1.0, &Matrix4::identity()), BufferUsage::StaticDraw, server, )?, @@ -541,74 +541,47 @@ impl DeferredLightRenderer { let mut light_view_projection = Matrix4::identity(); - // Mark lighted areas in stencil buffer to do light calculations only on them. + // Mark lit areas in stencil buffer to do light calculations only on them. let uniform_buffer = uniform_buffer_cache.write( StaticUniformBuffer::<256>::new().with(&(view_projection * bounding_shape_matrix)), )?; - pass_stats += frame_buffer.draw( - &**bounding_shape, - viewport, - &*self.flat_shader.program, - &DrawParameters { - cull_face: Some(CullFace::Front), - color_write: ColorMask::all(false), - depth_write: false, - stencil_test: Some(StencilFunc { - func: CompareFunc::Always, - ..Default::default() - }), - stencil_op: StencilOp { - zfail: StencilAction::Incr, - ..Default::default() - }, - depth_test: Some(CompareFunc::Less), - blend: None, - scissor_box: None, - }, - &[ResourceBindGroup { - bindings: &[ResourceBinding::Buffer { - buffer: uniform_buffer, - binding: BufferLocation::Auto { - shader_location: self.flat_shader.uniform_buffer_binding, + for (cull_face, stencil_action) in [ + (CullFace::Front, StencilAction::Incr), + (CullFace::Back, StencilAction::Decr), + ] { + pass_stats += frame_buffer.draw( + &**bounding_shape, + viewport, + &*self.flat_shader.program, + &DrawParameters { + cull_face: Some(cull_face), + color_write: ColorMask::all(false), + depth_write: false, + stencil_test: Some(StencilFunc { + func: CompareFunc::Always, + ..Default::default() + }), + stencil_op: StencilOp { + zfail: stencil_action, + ..Default::default() }, - data_usage: Default::default(), - }], - }], - ElementRange::Full, - )?; - - pass_stats += frame_buffer.draw( - &**bounding_shape, - viewport, - &*self.flat_shader.program, - &DrawParameters { - cull_face: Some(CullFace::Back), - color_write: ColorMask::all(false), - depth_write: false, - stencil_test: Some(StencilFunc { - func: CompareFunc::Always, - ..Default::default() - }), - stencil_op: StencilOp { - zfail: StencilAction::Decr, - ..Default::default() + depth_test: Some(CompareFunc::Less), + blend: None, + scissor_box: None, }, - depth_test: Some(CompareFunc::Less), - blend: None, - scissor_box: None, - }, - &[ResourceBindGroup { - bindings: &[ResourceBinding::Buffer { - buffer: uniform_buffer, - binding: BufferLocation::Auto { - shader_location: self.flat_shader.uniform_buffer_binding, - }, - data_usage: Default::default(), + &[ResourceBindGroup { + bindings: &[ResourceBinding::Buffer { + buffer: uniform_buffer, + binding: BufferLocation::Auto { + shader_location: self.flat_shader.uniform_buffer_binding, + }, + data_usage: Default::default(), + }], }], - }], - ElementRange::Full, - )?; + ElementRange::Full, + )?; + } // Directional light sources cannot be optimized via occlusion culling, because they're // usually cover the entire screen anyway. TODO: This might still be optimizable, but @@ -635,7 +608,7 @@ impl DeferredLightRenderer { func: CompareFunc::NotEqual, ..Default::default() }), - depth_test: Some(CompareFunc::Less), + depth_test: None, blend: None, stencil_op: Default::default(), scissor_box: None,