From 22381c94d455f501b7364ba11296f459e44d66f4 Mon Sep 17 00:00:00 2001 From: rdb Date: Thu, 14 Nov 2024 20:11:39 +0100 Subject: [PATCH] pgraphnodes: Disable lighting when rendering shadow cam This prevents accessing a texture (the shadow map) that we're currently rendering into. Hopefully a reasonable driver was already optimizing out the access properly due to the color write being off, but it could cause unnecessary work in the driver This will have the effect of the shader generator generating a different shader for the shadow pass than for the main pass, ideally we optimize the shader generator a bit more so that there are fewer shaders generated for the shadow pass. --- panda/src/pgraphnodes/lightLensNode.cxx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/panda/src/pgraphnodes/lightLensNode.cxx b/panda/src/pgraphnodes/lightLensNode.cxx index 0aabcb07b4..cb84c28dfb 100644 --- a/panda/src/pgraphnodes/lightLensNode.cxx +++ b/panda/src/pgraphnodes/lightLensNode.cxx @@ -19,6 +19,7 @@ #include "renderState.h" #include "cullFaceAttrib.h" #include "colorWriteAttrib.h" +#include "lightAttrib.h" #include "graphicsStateGuardianBase.h" TypeHandle LightLensNode::_type_handle; @@ -37,10 +38,14 @@ LightLensNode(const std::string &name, Lens *lens) : _shadow_caster = false; _sb_size.set(512, 512); _sb_sort = -10; - // set_initial_state(RenderState::make(ShaderAttrib::make_off(), 1000)); + // Backface culling helps eliminating artifacts. - set_initial_state(RenderState::make(CullFaceAttrib::make_reverse(), - ColorWriteAttrib::make(ColorWriteAttrib::C_off))); + static CPT(RenderState) default_initial_state = + RenderState::make( + CullFaceAttrib::make_reverse(), + ColorWriteAttrib::make(ColorWriteAttrib::C_off) + )->set_attrib(LightAttrib::make_all_off(), RenderState::get_max_priority()); + set_initial_state(default_initial_state); } /**