Self lit blocks.

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
Gradualcheetah
Gnoblar
Posts: 2
Joined: Fri Jan 24, 2014 12:35 am

Self lit blocks.

Post by Gradualcheetah »

Hi, I am making a voxel world (har har I know focus on the question please ;) ) and I am attempting to make my blocks "self illuminating" but only the faces pointed "up".
Now I am trying to resolve this without using a material file but instead pure code. This is what I am at currently (I am new to ogre and graphics all together so feel free to correct my useless attempts):

Code: Select all

void TutorialApplication::createTexture (const TCHAR* pName, const TCHAR* pImageFilename)
{
	Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create(pName, "General", true );
	Ogre::Technique* tech = mat->getTechnique(0);
	Ogre::Pass* pass = tech->getPass(0);
	Ogre::TextureUnitState* tex = pass->createTextureUnitState();
 		pass->setVertexColourTracking(Ogre::TVC_DIFFUSE);
	tex->setTextureName(pImageFilename);
	tex->setNumMipmaps(4);
	tex->setTextureAnisotropy(1);
	tex->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_POINT, Ogre::FO_POINT);

	tex->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_DIFFUSE, Ogre::LBS_TEXTURE);
}
some of that I'm sure has no place here, but I am at a loss. I believe I am attempting to color my vertices white? here is my (attempted) code for that:

Code: Select all

                                        MeshChunk->position(x, y,   z+1);	MeshChunk->normal(-1,0,0);	MeshChunk->textureCoord(0, 1); MeshChunk->colour(1.0F, 1.0F, 1.0F);
					MeshChunk->position(x, y+1, z+1);	MeshChunk->normal(-1,0,0);	MeshChunk->textureCoord(1, 1); MeshChunk->colour(1.0F, 1.0F, 1.0F);
					MeshChunk->position(x, y+1, z);		MeshChunk->normal(-1,0,0);	MeshChunk->textureCoord(1, 0); MeshChunk->colour(1.0F, 1.0F, 1.0F);
					MeshChunk->position(x, y,   z);		MeshChunk->normal(-1,0,0);	MeshChunk->textureCoord(0, 0); MeshChunk->colour(1.0F, 1.0F, 1.0F);


Thanks in advance! :)
dbtx
Halfling
Posts: 66
Joined: Tue Nov 01, 2011 9:07 pm
x 10

Re: Self lit blocks.

Post by dbtx »

Hello, you're not far off-- as far as the material anyway-- probably not everything but here are a few easy things:
1) You are tracking vertex colors but you wanted TVC_EMISSIVE, not TVC_DIFFUSE for making some faces glow.
2) You need 24 vertices and the 6 of them making the 2 top faces need their colour to be something non-zero, but looks like you knew that
3) you want all the other vertices' colours to be 0,0,0
4) in the Pass, you need to setEmissive() with non-zero values. (default is black)
HTH
Gradualcheetah
Gnoblar
Posts: 2
Joined: Fri Jan 24, 2014 12:35 am

Re: Self lit blocks.

Post by Gradualcheetah »

wunderbar! You are amazing! The key was "set all other vertices to black" Thank you good sir :)
User avatar
areay
Bugbear
Posts: 819
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ
x 69

Re: Self lit blocks.

Post by areay »

For the 'only the faces pointed "up" ' another option would be to light them using a directional light that has a direction vector of (0,-1,0). That way the lighting will be consistent with any player character or other actor that goes across the blocks.
Post Reply