mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 01:07:51 -04:00
Add light.shadow_caster and light.shadow_buffer_size
This commit is contained in:
parent
4ace5b5bc9
commit
f68bfab7a9
@ -3101,7 +3101,7 @@ make_shadow_buffer(const NodePath &light_np, GraphicsOutputBase *host) {
|
|||||||
if (display_cat.is_debug()) {
|
if (display_cat.is_debug()) {
|
||||||
display_cat.debug()
|
display_cat.debug()
|
||||||
<< "Constructing shadow buffer for light '" << light->get_name()
|
<< "Constructing shadow buffer for light '" << light->get_name()
|
||||||
<< "', size=" << light->_sb_xsize << "x" << light->_sb_ysize
|
<< "', size=" << light->_sb_size[0] << "x" << light->_sb_size[1]
|
||||||
<< ", sort=" << light->_sb_sort << "\n";
|
<< ", sort=" << light->_sb_sort << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3109,7 +3109,7 @@ make_shadow_buffer(const NodePath &light_np, GraphicsOutputBase *host) {
|
|||||||
FrameBufferProperties fbp;
|
FrameBufferProperties fbp;
|
||||||
fbp.set_depth_bits(shadow_depth_bits);
|
fbp.set_depth_bits(shadow_depth_bits);
|
||||||
|
|
||||||
WindowProperties props = WindowProperties::size(light->_sb_xsize, light->_sb_ysize);
|
WindowProperties props = WindowProperties::size(light->_sb_size[0], light->_sb_size[1]);
|
||||||
int flags = GraphicsPipe::BF_refuse_window;
|
int flags = GraphicsPipe::BF_refuse_window;
|
||||||
if (is_point) {
|
if (is_point) {
|
||||||
flags |= GraphicsPipe::BF_size_square;
|
flags |= GraphicsPipe::BF_size_square;
|
||||||
@ -3124,13 +3124,13 @@ make_shadow_buffer(const NodePath &light_np, GraphicsOutputBase *host) {
|
|||||||
// error
|
// error
|
||||||
PT(Texture) tex = new Texture(light->get_name());
|
PT(Texture) tex = new Texture(light->get_name());
|
||||||
if (is_point) {
|
if (is_point) {
|
||||||
if (light->_sb_xsize != light->_sb_ysize) {
|
if (light->_sb_size[0] != light->_sb_size[1]) {
|
||||||
display_cat.error()
|
display_cat.error()
|
||||||
<< "PointLight shadow buffers must have an equal width and height!\n";
|
<< "PointLight shadow buffers must have an equal width and height!\n";
|
||||||
}
|
}
|
||||||
tex->setup_cube_map(light->_sb_xsize, Texture::T_unsigned_byte, Texture::F_depth_component);
|
tex->setup_cube_map(light->_sb_size[0], Texture::T_unsigned_byte, Texture::F_depth_component);
|
||||||
} else {
|
} else {
|
||||||
tex->setup_2d_texture(light->_sb_xsize, light->_sb_ysize, Texture::T_unsigned_byte, Texture::F_depth_component);
|
tex->setup_2d_texture(light->_sb_size[0], light->_sb_size[1], Texture::T_unsigned_byte, Texture::F_depth_component);
|
||||||
}
|
}
|
||||||
tex->make_ram_image();
|
tex->make_ram_image();
|
||||||
sbuffer->add_render_texture(tex, GraphicsOutput::RTM_bind_or_copy, GraphicsOutput::RTP_depth);
|
sbuffer->add_render_texture(tex, GraphicsOutput::RTM_bind_or_copy, GraphicsOutput::RTP_depth);
|
||||||
|
@ -42,12 +42,11 @@ set_shadow_caster(bool caster) {
|
|||||||
*/
|
*/
|
||||||
INLINE void LightLensNode::
|
INLINE void LightLensNode::
|
||||||
set_shadow_caster(bool caster, int buffer_xsize, int buffer_ysize, int buffer_sort) {
|
set_shadow_caster(bool caster, int buffer_xsize, int buffer_ysize, int buffer_sort) {
|
||||||
if ((_shadow_caster && !caster) || buffer_xsize != _sb_xsize || buffer_ysize != _sb_ysize) {
|
if ((_shadow_caster && !caster) || buffer_xsize != _sb_size[0] || buffer_ysize != _sb_size[1]) {
|
||||||
clear_shadow_buffers();
|
clear_shadow_buffers();
|
||||||
}
|
}
|
||||||
_shadow_caster = caster;
|
_shadow_caster = caster;
|
||||||
_sb_xsize = buffer_xsize;
|
_sb_size.set(buffer_xsize, buffer_ysize);
|
||||||
_sb_ysize = buffer_ysize;
|
|
||||||
|
|
||||||
if (buffer_sort != _sb_sort) {
|
if (buffer_sort != _sb_sort) {
|
||||||
ShadowBuffers::iterator it;
|
ShadowBuffers::iterator it;
|
||||||
@ -59,6 +58,25 @@ set_shadow_caster(bool caster, int buffer_xsize, int buffer_ysize, int buffer_so
|
|||||||
set_active(caster);
|
set_active(caster);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the size of the shadow buffer to be created for this light source.
|
||||||
|
*/
|
||||||
|
INLINE LVecBase2i LightLensNode::
|
||||||
|
get_shadow_buffer_size() const {
|
||||||
|
return _sb_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the size of the shadow buffer to be created for this light source.
|
||||||
|
*/
|
||||||
|
INLINE void LightLensNode::
|
||||||
|
set_shadow_buffer_size(const LVecBase2i &size) {
|
||||||
|
if (size != _sb_size) {
|
||||||
|
clear_shadow_buffers();
|
||||||
|
}
|
||||||
|
_sb_size = size;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the buffer that has been constructed for a given GSG, or NULL if no
|
* Returns the buffer that has been constructed for a given GSG, or NULL if no
|
||||||
* such buffer has (yet) been constructed. This should be used for debugging
|
* such buffer has (yet) been constructed. This should be used for debugging
|
||||||
|
@ -31,8 +31,7 @@ LightLensNode(const string &name, Lens *lens) :
|
|||||||
{
|
{
|
||||||
set_active(false);
|
set_active(false);
|
||||||
_shadow_caster = false;
|
_shadow_caster = false;
|
||||||
_sb_xsize = 512;
|
_sb_size.set(512, 512);
|
||||||
_sb_ysize = 512;
|
|
||||||
_sb_sort = -10;
|
_sb_sort = -10;
|
||||||
// set_initial_state(RenderState::make(ShaderAttrib::make_off(), 1000));
|
// set_initial_state(RenderState::make(ShaderAttrib::make_off(), 1000));
|
||||||
// Backface culling helps eliminating artifacts.
|
// Backface culling helps eliminating artifacts.
|
||||||
@ -57,8 +56,7 @@ LightLensNode(const LightLensNode ©) :
|
|||||||
Light(copy),
|
Light(copy),
|
||||||
Camera(copy),
|
Camera(copy),
|
||||||
_shadow_caster(copy._shadow_caster),
|
_shadow_caster(copy._shadow_caster),
|
||||||
_sb_xsize(copy._sb_xsize),
|
_sb_size(copy._sb_size),
|
||||||
_sb_ysize(copy._sb_ysize),
|
|
||||||
_sb_sort(-10)
|
_sb_sort(-10)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -126,8 +124,8 @@ write_datagram(BamWriter *manager, Datagram &dg) {
|
|||||||
Light::write_datagram(manager, dg);
|
Light::write_datagram(manager, dg);
|
||||||
|
|
||||||
dg.add_bool(_shadow_caster);
|
dg.add_bool(_shadow_caster);
|
||||||
dg.add_int32(_sb_xsize);
|
dg.add_int32(_sb_size[0]);
|
||||||
dg.add_int32(_sb_ysize);
|
dg.add_int32(_sb_size[1]);
|
||||||
dg.add_int32(_sb_sort);
|
dg.add_int32(_sb_sort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,14 +38,22 @@ PUBLISHED:
|
|||||||
INLINE void set_shadow_caster(bool 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_shadow_caster(bool caster, int buffer_xsize, int buffer_ysize, int sort = -10);
|
||||||
|
|
||||||
|
INLINE LVecBase2i get_shadow_buffer_size() const;
|
||||||
|
INLINE void set_shadow_buffer_size(const LVecBase2i &size);
|
||||||
|
|
||||||
INLINE GraphicsOutputBase *get_shadow_buffer(GraphicsStateGuardianBase *gsg);
|
INLINE GraphicsOutputBase *get_shadow_buffer(GraphicsStateGuardianBase *gsg);
|
||||||
|
|
||||||
|
PUBLISHED:
|
||||||
|
MAKE_PROPERTY(shadow_caster, is_shadow_caster);
|
||||||
|
MAKE_PROPERTY(shadow_buffer_size, get_shadow_buffer_size, set_shadow_buffer_size);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
LightLensNode(const LightLensNode ©);
|
LightLensNode(const LightLensNode ©);
|
||||||
void clear_shadow_buffers();
|
void clear_shadow_buffers();
|
||||||
|
|
||||||
|
LVecBase2i _sb_size;
|
||||||
bool _shadow_caster;
|
bool _shadow_caster;
|
||||||
int _sb_xsize, _sb_ysize, _sb_sort;
|
int _sb_sort;
|
||||||
|
|
||||||
// This is really a map of GSG -> GraphicsOutput.
|
// This is really a map of GSG -> GraphicsOutput.
|
||||||
typedef pmap<PT(GraphicsStateGuardianBase), PT(GraphicsOutputBase) > ShadowBuffers;
|
typedef pmap<PT(GraphicsStateGuardianBase), PT(GraphicsOutputBase) > ShadowBuffers;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user