Lighting issues using the multi-light shader system

Problems building or running the engine, queries about how to use features etc.
Post Reply
shenjoku
Gremlin
Posts: 193
Joined: Sat Aug 06, 2011 11:02 pm
x 6

Lighting issues using the multi-light shader system

Post by shenjoku »

I've recently discovered a problem with the multi-light shader system that is causing the ground textures in my environment to appear completely black, but only if the textures are created after one frame has been rendered. We have our own rendering loop that is manually calling Ogre::Root::renderOneFrame(), and if I move the code so that it loads the ground texture after the first time this is called, instead of before, then everything appears black. I've attached some screenshots showing what it is supposed to look like and what the problem appears as.
This is what the ground texture looks like normally.
This is what the ground texture looks like normally.
ground_textured.png (45.46 KiB) Viewed 372 times
This is what the ground texture looks like after moving the creation after the first frame has been rendered.
This is what the ground texture looks like after moving the creation after the first frame has been rendered.
ground_black.png (10.98 KiB) Viewed 372 times
The whole reason why I'm moving the creation of the ground to after the first frame has been rendered is because I'm working on implementing saving/loading the game state, which means that there obviously needs to be things rendered before the main world is created (e.g. the main menu and whatever else might be in-between startup and actually loading a game).

So what could be happening during rendering that would break the ground texturing just because it doesn't exist yet? Is it not properly invalidating the shadow textures or something? That's all I can think of, but I'm not entirely sure what to do if that even is the case. I haven't worked with this code in months so I'm really rusty as to how it all works.
shenjoku
Gremlin
Posts: 193
Joined: Sat Aug 06, 2011 11:02 pm
x 6

Re: Lighting issues using the multi-light shader system

Post by shenjoku »

I sort of found the problem but I'm not sure what to do about it. While the first frame is rendered a new technique is being added to the material used on the ground plane, even though the material isn't being used for anything at this time. When the ground plane gets created right after the frame render, in Material::getBestTechnique() where it is looking up the scheme to use, in its mBestTechniquesBySchemeList container it finds the scheme that was added during rendering. The problem this causes is that _arbitrateMissingTechniqueForActiveScheme() is no longer called, which is what eventually trickles down to the ShaderGeneratorTechniqueResolverListener::handleSchemeNotFound() function and does all the magic of creating the correct shader technique for the material. Since handleSchemeNotFound() never gets called the shader technique is never created so the texture renders completely black, unable to handle the lighting situation.

As to what there is to do to fix this problem I have no clue. Any ideas?
shenjoku
Gremlin
Posts: 193
Joined: Sat Aug 06, 2011 11:02 pm
x 6

Re: Lighting issues using the multi-light shader system

Post by shenjoku »

Sorry for the triple post but I found a solution to this problem. It's extremely dirty, and if anybody can think of any other way to fix this I'm still open to suggestions. Here's the code snippet of what I'm doing to fix the issue:

Code: Select all

// BUGBUG: Remove all excess techniques from the base material that could have been added. This is a kludgey fix for the
// problem where a technique gets added to the material during rendering, which occurs before it actually get used, and
// causes the shader technique to never get added, breaking the lighting of the material.
//
// Since we know there should only be one technique in the material (that's all that's defined in the material file) we remove
// everything but the first technique.
if (baseMaterial->getNumTechniques() > 1)
{
	// Before removing the techniques we need to invalidate the scheme of the material so that it will know to rebuild its
	// scheme. This avoids crashing on shutdown since it would otherwise try to delete the techniques that are being
	// removed below.
	Ogre::RTShader::ShaderGenerator::getSingleton().invalidateMaterial(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, baseMaterial->getName());

	do
	{
		baseMaterial->removeTechnique(baseMaterial->getNumTechniques() - 1);
	}
	while (baseMaterial->getNumTechniques() > 1);
}
cyrfer
Orc
Posts: 424
Joined: Wed Aug 01, 2007 8:13 pm
Location: Venice, CA, USA
x 7

Re: Lighting issues using the multi-light shader system

Post by cyrfer »

I can't even get multi-pass materials to work for each light. If you don't mind sharing, how do you setup your materials?
shenjoku
Gremlin
Posts: 193
Joined: Sat Aug 06, 2011 11:02 pm
x 6

Re: Lighting issues using the multi-light shader system

Post by shenjoku »

It's all based on the sample the comes with Ogre 1.9: Sample_ShaderSystemMultiLight. If you haven't looked at it yet that's the place to start.
Post Reply