Static shadows with ITerrainSceneNode

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
nake
Posts: 3
Joined: Wed Mar 02, 2011 7:57 pm

Static shadows with ITerrainSceneNode

Post by nake »

First of all, hi to everyone. I'm quite new with Irrlicht, and I think the stuff I'm trying to do is a bit advanced to start with.

What I want is to have static ray-traced shadows in a ITerrainSceneNode. I do know the algorithms to get the shadow map, but what I don't know is how to get that data into my ITerrainSceneNode.

I've searching through google and in the forums and got this thread: http://irrlicht.sourceforge.net/phpBB2/ ... 326efd542a

However they did not achieve anything at all.

What I was trying to do is to access each vertex and change the color, and this is the function I made using assembled pieces of code and my own xD:

Code: Select all

void setVertexLight(irr::scene::ITerrainSceneNode* node, unsigned char *lightmap)
{
	irr::scene::CDynamicMeshBuffer* buffer = NULL;
	unsigned int vertexCount = 0;

	// we need to know the total number of vertices
	const unsigned int numVertices = node->getMesh()->getMeshBuffer(0)->getVertexCount();

	try
	{   
		// a fount this in the Irllicht's sources of CTerrainSceneNode
		if (numVertices <= 65536)
		{
			 //small enough for 16bit buffers
			 buffer = new irr::scene::CDynamicMeshBuffer(irr::video::EVT_2TCOORDS, irr::video::EIT_16BIT);
		}
		else
		{
			 //we need 32bit buffers
			 buffer = new irr::scene::CDynamicMeshBuffer(irr::video::EVT_2TCOORDS, irr::video::EIT_32BIT);
		}

		// get the mesh data for LOD 0
		node->getMeshBufferForLOD(*buffer, 0);

		// should be the same as the numVertices - you can test for that
		vertexCount = buffer->getVertexCount();
	}
	catch (std::bad_alloc)
	{
		// If the heightMap allocation fails, this will be already allocated.
		if (buffer != NULL) buffer->drop();

		return;
	}
	
	for (unsigned int i = 0; i < vertexCount; i++)
	{
		buffer->getVertexBuffer()[i].Color.set(255, lightmap[i],lightmap[i],lightmap[i]);
	}

	buffer->drop();
}
I think there must be a simpler way to do that, or maybe I just messed up something because nothing changes in the terrain.
And, maybe I'm wrong, but I supposed that changing the color of a vertex meant changing the color of the texture on top of it (something as OpenGL does).

Just to be sure that the piece of code that didn't work was that I changed lightmap with zeros and 255's and nothing happened.

I'm running out of ideas :? , please help.

And thanks in advance.
nake
Posts: 3
Joined: Wed Mar 02, 2011 7:57 pm

Post by nake »

No one?

I tried using getMesh() instead of getMeshBufferForLOD(), but whatever I change doesn't seem to update in the render.
I also tried using setDirty() but it didn't change anything at all.

To be sure that I'm doing something wrong I tried to change heights instead of the color, but nothing seems to change.

Code: Select all

// node is defined as: irr::scene::ITerrainSceneNode* node

irr::scene::IMesh *ms = node->getMesh();
	
	unsigned int meshcount = ms->getMeshBufferCount();
	unsigned int vertcnt = 0;
	printf("mesh count = %i\n", meshcount); // This outputs 1 (as expected)
	
	for(unsigned int actmsh = 0; actmsh < meshcount; actmsh++)
	{
		vertcnt = ms->getMeshBuffer(actmsh)->getVertexCount();
		printf("Vertex count = %i\n", vertcnt); (This also outputs what it should)
		for(unsigned int vert = 0; vert<vertcnt; vert++)
		{
			ms->getMeshBuffer(actmsh)->getPosition(vert).Y = 0; // Try to make a flat terrain?
		}
		ms->getMeshBuffer(actmsh)->setDirty(); // Is this necessary to update graphic's RAM?
	}
	
	ms->setDirty(); // Again, just in case
tmp
Posts: 1
Joined: Fri Dec 04, 2015 1:33 pm

Re: Static shadows with ITerrainSceneNode

Post by tmp »

For ITerrainSceneNode, you should use getRenderBuffer to get TerrainSceneNode render mesh buffer instead of getMeshBuffer.
Post Reply