From f68bfab7a96c63eaea62d80199d2a714f8d42d84 Mon Sep 17 00:00:00 2001 From: rdb Date: Thu, 17 Mar 2016 15:26:12 +0100 Subject: [PATCH] Add light.shadow_caster and light.shadow_buffer_size --- panda/src/display/graphicsStateGuardian.cxx | 10 ++++----- panda/src/pgraphnodes/lightLensNode.I | 24 ++++++++++++++++++--- panda/src/pgraphnodes/lightLensNode.cxx | 10 ++++----- panda/src/pgraphnodes/lightLensNode.h | 10 ++++++++- 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 6f5e873779..d294dc47f3 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -3101,7 +3101,7 @@ make_shadow_buffer(const NodePath &light_np, GraphicsOutputBase *host) { if (display_cat.is_debug()) { display_cat.debug() << "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"; } @@ -3109,7 +3109,7 @@ make_shadow_buffer(const NodePath &light_np, GraphicsOutputBase *host) { FrameBufferProperties fbp; 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; if (is_point) { flags |= GraphicsPipe::BF_size_square; @@ -3124,13 +3124,13 @@ make_shadow_buffer(const NodePath &light_np, GraphicsOutputBase *host) { // error PT(Texture) tex = new Texture(light->get_name()); if (is_point) { - if (light->_sb_xsize != light->_sb_ysize) { + if (light->_sb_size[0] != light->_sb_size[1]) { display_cat.error() << "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 { - 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(); sbuffer->add_render_texture(tex, GraphicsOutput::RTM_bind_or_copy, GraphicsOutput::RTP_depth); diff --git a/panda/src/pgraphnodes/lightLensNode.I b/panda/src/pgraphnodes/lightLensNode.I index 8cf9ea7eb6..ddb2808e86 100644 --- a/panda/src/pgraphnodes/lightLensNode.I +++ b/panda/src/pgraphnodes/lightLensNode.I @@ -42,12 +42,11 @@ set_shadow_caster(bool caster) { */ INLINE void LightLensNode:: 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(); } _shadow_caster = caster; - _sb_xsize = buffer_xsize; - _sb_ysize = buffer_ysize; + _sb_size.set(buffer_xsize, buffer_ysize); if (buffer_sort != _sb_sort) { ShadowBuffers::iterator it; @@ -59,6 +58,25 @@ set_shadow_caster(bool caster, int buffer_xsize, int buffer_ysize, int buffer_so 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 * such buffer has (yet) been constructed. This should be used for debugging diff --git a/panda/src/pgraphnodes/lightLensNode.cxx b/panda/src/pgraphnodes/lightLensNode.cxx index ba1e93acac..bc3e134116 100644 --- a/panda/src/pgraphnodes/lightLensNode.cxx +++ b/panda/src/pgraphnodes/lightLensNode.cxx @@ -31,8 +31,7 @@ LightLensNode(const string &name, Lens *lens) : { set_active(false); _shadow_caster = false; - _sb_xsize = 512; - _sb_ysize = 512; + _sb_size.set(512, 512); _sb_sort = -10; // set_initial_state(RenderState::make(ShaderAttrib::make_off(), 1000)); // Backface culling helps eliminating artifacts. @@ -57,8 +56,7 @@ LightLensNode(const LightLensNode ©) : Light(copy), Camera(copy), _shadow_caster(copy._shadow_caster), - _sb_xsize(copy._sb_xsize), - _sb_ysize(copy._sb_ysize), + _sb_size(copy._sb_size), _sb_sort(-10) { } @@ -126,8 +124,8 @@ write_datagram(BamWriter *manager, Datagram &dg) { Light::write_datagram(manager, dg); dg.add_bool(_shadow_caster); - dg.add_int32(_sb_xsize); - dg.add_int32(_sb_ysize); + dg.add_int32(_sb_size[0]); + dg.add_int32(_sb_size[1]); dg.add_int32(_sb_sort); } diff --git a/panda/src/pgraphnodes/lightLensNode.h b/panda/src/pgraphnodes/lightLensNode.h index 205a58b660..d4e0c7385d 100644 --- a/panda/src/pgraphnodes/lightLensNode.h +++ b/panda/src/pgraphnodes/lightLensNode.h @@ -38,14 +38,22 @@ PUBLISHED: INLINE void set_shadow_caster(bool caster); 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); +PUBLISHED: + MAKE_PROPERTY(shadow_caster, is_shadow_caster); + MAKE_PROPERTY(shadow_buffer_size, get_shadow_buffer_size, set_shadow_buffer_size); + protected: LightLensNode(const LightLensNode ©); void clear_shadow_buffers(); + LVecBase2i _sb_size; bool _shadow_caster; - int _sb_xsize, _sb_ysize, _sb_sort; + int _sb_sort; // This is really a map of GSG -> GraphicsOutput. typedef pmap ShadowBuffers;