Disable/Enable a ShadowVolumeSceneNode

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Xplod
Posts: 32
Joined: Sat Mar 29, 2008 5:48 pm
Contact:

Disable/Enable a ShadowVolumeSceneNode

Post 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]
Xplod
Posts: 32
Joined: Sat Mar 29, 2008 5:48 pm
Contact:

Post by Xplod »

Another little change to enhance performances :

CShadowVolumeSceneNode.cpp

Code: Select all

AFTER 
void CShadowVolumeSceneNode::OnRegisterSceneNode()
{


ADD
	if (!Enabled)
		return;

hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I'd use setVisible with the current implementation...
Xplod
Posts: 32
Joined: Sat Mar 29, 2008 5:48 pm
Contact:

Post 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...
Post Reply