From cd80487c05c21d5a9a35b9463a7c3604f4468bb9 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 4 Jul 2009 09:19:40 +0000 Subject: [PATCH] Performance improvement of shadow code, fixed the self-shadowing artifacts, removed push_bias. For infinitely-thin objects, a DepthOffsetAttrib can be applied if necessary. --- panda/src/pgraphnodes/lightLensNode.I | 11 ----------- panda/src/pgraphnodes/lightLensNode.cxx | 14 ++++++++++---- panda/src/pgraphnodes/lightLensNode.h | 2 -- panda/src/pgraphnodes/shaderGenerator.cxx | 6 ++---- 4 files changed, 12 insertions(+), 21 deletions(-) diff --git a/panda/src/pgraphnodes/lightLensNode.I b/panda/src/pgraphnodes/lightLensNode.I index d1f1d5cd60..a979d83da3 100644 --- a/panda/src/pgraphnodes/lightLensNode.I +++ b/panda/src/pgraphnodes/lightLensNode.I @@ -70,14 +70,3 @@ set_shadow_caster(bool caster, int buffer_xsize, int buffer_ysize, int buffer_so set_active(caster); } -//////////////////////////////////////////////////////////////////// -// Function: LightLensNode::set_push_bias -// Access: Published -// Description: Sets the push bias value, this is used to eliminate -// depth texture precision errors in shadows. Change -// this value if your shadows look strange. -//////////////////////////////////////////////////////////////////// -INLINE void LightLensNode:: -set_push_bias(float push_bias) { - _push_bias = push_bias; -} diff --git a/panda/src/pgraphnodes/lightLensNode.cxx b/panda/src/pgraphnodes/lightLensNode.cxx index 19c0e892f1..2036f63a29 100644 --- a/panda/src/pgraphnodes/lightLensNode.cxx +++ b/panda/src/pgraphnodes/lightLensNode.cxx @@ -17,6 +17,9 @@ #include "bamReader.h" #include "datagram.h" #include "datagramIterator.h" +#include "renderState.h" +#include "cullFaceAttrib.h" +#include "colorWriteAttrib.h" TypeHandle LightLensNode::_type_handle; @@ -34,7 +37,9 @@ LightLensNode(const string &name, Lens *lens) : _sb_xsize = 512; _sb_ysize = 512; _sb_sort = -10; - _push_bias = 0.5; + // Backface culling helps eliminating artifacts. + set_initial_state(RenderState::make(CullFaceAttrib::make_reverse(), + ColorWriteAttrib::make(ColorWriteAttrib::C_off))); } //////////////////////////////////////////////////////////////////// @@ -62,7 +67,9 @@ LightLensNode(const LightLensNode ©) : _sb_xsize = 512; _sb_ysize = 512; _sb_sort = -10; - _push_bias = 0.5; + // Backface culling helps eliminating artifacts. + set_initial_state(RenderState::make(CullFaceAttrib::make_reverse(), + ColorWriteAttrib::make(ColorWriteAttrib::C_off))); } //////////////////////////////////////////////////////////////////// @@ -138,7 +145,6 @@ write_datagram(BamWriter *manager, Datagram &dg) { dg.add_int32(_sb_xsize); dg.add_int32(_sb_ysize); dg.add_int32(_sb_sort); - dg.add_float64(_push_bias); } //////////////////////////////////////////////////////////////////// @@ -158,5 +164,5 @@ fillin(DatagramIterator &scan, BamReader *manager) { int sb_ysize = scan.get_int32(); int sb_sort = scan.get_int32(); set_shadow_caster(shadow_caster, sb_xsize, sb_ysize, sb_sort); - set_push_bias(scan.get_float64()); } + diff --git a/panda/src/pgraphnodes/lightLensNode.h b/panda/src/pgraphnodes/lightLensNode.h index 6b787cce77..b5e51e43f1 100644 --- a/panda/src/pgraphnodes/lightLensNode.h +++ b/panda/src/pgraphnodes/lightLensNode.h @@ -40,7 +40,6 @@ PUBLISHED: INLINE bool is_shadow_caster(); INLINE void set_shadow_caster(bool caster); INLINE void set_shadow_caster(bool caster, int buffer_xsize, int buffer_ysize, int sort = -10); - INLINE void set_push_bias(float push_bias); protected: LightLensNode(const LightLensNode ©); @@ -48,7 +47,6 @@ protected: bool _shadow_caster; int _sb_xsize, _sb_ysize, _sb_sort; - double _push_bias; // This is really a map of GSG -> GraphicsOutput. typedef pmap ShadowBuffers; diff --git a/panda/src/pgraphnodes/shaderGenerator.cxx b/panda/src/pgraphnodes/shaderGenerator.cxx index 8bae5c42ce..89da0cbb9d 100644 --- a/panda/src/pgraphnodes/shaderGenerator.cxx +++ b/panda/src/pgraphnodes/shaderGenerator.cxx @@ -705,14 +705,12 @@ synthesize_shader(const RenderState *rs) { text << "\t float4x4 biasmat = {0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.0f, 0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f};\n"; for (int i=0; i<(int)_dlights.size(); i++) { if (_dlights[i]->_shadow_caster) { - text << "\t l_dlightcoord" << i << " = mul(biasmat, mul(trans_model_to_clip_of_dlight" - << i << ", vtx_position + " << _dlights[i]->_push_bias << " * vtx_normal));\n"; + text << "\t l_dlightcoord" << i << " = mul(biasmat, mul(trans_model_to_clip_of_dlight" << i << ", vtx_position));\n"; } } for (int i=0; i<(int)_slights.size(); i++) { if (_slights[i]->_shadow_caster) { - text << "\t l_slightcoord" << i << " = mul(biasmat, mul(trans_model_to_clip_of_slight" - << i << ", vtx_position + " << _slights[i]->_push_bias << " * vtx_normal));\n"; + text << "\t l_slightcoord" << i << " = mul(biasmat, mul(trans_model_to_clip_of_slight" << i << ", vtx_position));\n"; } } }