Performance improvement of shadow code, fixed the self-shadowing artifacts, removed push_bias. For infinitely-thin objects, a DepthOffsetAttrib can be applied if necessary.

This commit is contained in:
rdb 2009-07-04 09:19:40 +00:00
parent 5b088c851c
commit cd80487c05
4 changed files with 12 additions and 21 deletions

View File

@ -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;
}

View File

@ -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 &copy) :
_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());
}

View File

@ -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 &copy);
@ -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<PT(GraphicsStateGuardianBase), PT(GraphicsOutputBase) > ShadowBuffers;

View File

@ -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";
}
}
}