Page 1 of 1

Disable/Enable a ShadowVolumeSceneNode

Posted: Thu Jun 19, 2008 10:54 am
by Xplod
I'm currently using ShadowVolumeSceneNode, and found that there is no way to disable or delete a Shadow as soon as you use ->addShadowVolumeSceneNode();

So I made a small change in IShadowVolumeSceneNode/CShadowVolumeSceneNode files, a setEnabled function, to enable or disable the rendering of a shadow.

Tested with latest SVN, but it should work with Irr 1.4/1.4.1 too.

IShadowVolumeSceneNode.h

Code: Select all

AFTER 
virtual void setMeshToRenderFrom(const IMesh* mesh) = 0;

ADD
virtual void setEnabled(bool enabled) = 0;
CShadowVolumeSceneNode.h

Code: Select all

AFTER
 
//! Returns type of the scene node
		virtual ESCENE_NODE_TYPE getType() const { return ESNT_SHADOW_VOLUME; }


ADD
//! enable or disable shadow
		virtual void setEnabled(bool enabled);


AFTER

bool* FaceData; // used for zfail method, if face is front facing
		bool UseZFailMethod;

ADD

bool Enabled;

CShadowVolumeSceneNode.cpp

Code: Select all

AFTER
	setAutomaticCulling(scene::EAC_OFF);

ADD
	Enabled = true;


AFTER
void CShadowVolumeSceneNode::render()
{

ADD
	if (!Enabled)
		return;

BEFORE !!

} // end namespace scene
} // end namespace irr


ADD


//! enable or disable shadow
void CShadowVolumeSceneNode::setEnabled(bool enabled)
{
	Enabled = enabled;
}



Compile, and rulez !
Shadow is enabled by default.

To use it, it's very easy :

IShadowVolumeSceneNode* myShadow = node->addShadowVolumeSceneNode();

myShadow->setEnabled(true); to enable shadow
myShadow->setEnabled(false); to disable shadow


[/b]

Posted: Thu Jun 19, 2008 11:03 am
by Xplod
Another little change to enhance performances :

CShadowVolumeSceneNode.cpp

Code: Select all

AFTER 
void CShadowVolumeSceneNode::OnRegisterSceneNode()
{


ADD
	if (!Enabled)
		return;


Posted: Thu Jun 19, 2008 11:11 am
by hybrid
I'd use setVisible with the current implementation...

Posted: Thu Jun 19, 2008 11:29 am
by Xplod
Oh yeah, I must sleep more... I didn't saw it at all ! I was searching for something that could replace ->remove(); because myShadow->remove(); doesn't work...