Static geometry + Normal map shaders = Static lighting

Problems building or running the engine, queries about how to use features etc.
User avatar
Evak
Orc Shaman
Posts: 707
Joined: Sun Apr 02, 2006 7:51 pm
Location: Sacramento, CA
x 1

Static geometry + Normal map shaders = Static lighting

Post by Evak »

Hi, I've been playing with Normal mapped Shaders on a mesh terrain. I decided to try using Static geometry groups.

The static geometry loaded just fine, but on flying around the scene I realised that the normal map lighting, bump and shinyness was no longer adjusting dynamicly to the camera position and instead just looked baked in place.

Is this normal, meaning that Static geometry can not be used with shaders that have certain shader effect materials applied? In my instance the material looks very bright and the shiny specular parts are static when you fly around the scene.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67

Post by sinbad »

It shouldn't do - however I just realised there is a bug here - StaticGeometry doesn't change the VES_TANGENT entries when you re-orient an object when you bake it into the static geometry. This would cause the normal mapping to be off. However it would not be static.

Depends on how your normal map shader has been written of course.
User avatar
Evak
Orc Shaman
Posts: 707
Joined: Sun Apr 02, 2006 7:51 pm
Location: Sacramento, CA
x 1

Post by Evak »

Hmm, I'm an artist so I'm not too good with the technical stuff behind this.

I can try and illustrate exactly whats happening in either a video comparrison or sample app that will let you load a couple of scenes, one with and one without static geometry. Would be nice to get to the bottom of the problem :)
User avatar
Evak
Orc Shaman
Posts: 707
Joined: Sun Apr 02, 2006 7:51 pm
Location: Sacramento, CA
x 1

Post by Evak »

Hi Sinbad I PM'd you with a couple of example scenes and a viewer, incase this turns out to be a bug. In which case it will be handy for you to see it first hand.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67

Post by sinbad »

Ok, it's actually easier for me to recreate it probably, will try to look at it soon.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67

Post by sinbad »

Definitely not a bug in Ogre as far as I can tell.

Test code:

Code: Select all

		// Set ambient light
		mSceneMgr->setAmbientLight(ColourValue(0, 0, 0));

		// Create a point light
		Light* l = mSceneMgr->createLight("MainLight");
		l->setDiffuseColour(1.0, 0.7, 0.0);
		l->setSpecularColour(ColourValue::White);

		SceneNode* animNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
		Animation* anim = mSceneMgr->createAnimation("an1", 20);
		anim->setInterpolationMode(Animation::IM_SPLINE);
		NodeAnimationTrack* track = anim->createNodeTrack(1, animNode);
		TransformKeyFrame* kf = track->createNodeKeyFrame(0);
		kf->setTranslate(Vector3(2300, 600, 2300));
		kf = track->createNodeKeyFrame(5);
		kf->setTranslate(Vector3(-2300, 600, 2300));
		kf = track->createNodeKeyFrame(10);
		kf->setTranslate(Vector3(-2300, 600, -2300));
		kf = track->createNodeKeyFrame(15);
		kf->setTranslate(Vector3(2300, 600, -2300));
		kf = track->createNodeKeyFrame(20);
		kf->setTranslate(Vector3(2300, 600, 2300));

		animNode->attachObject(l);

		AnimationState* animState = mSceneMgr->createAnimationState("an1");
		animState->setEnabled(true);
		mAnimStateList.push_back(animState);
		


		Plane plane;
		plane.normal = Vector3::UNIT_Y;
		plane.d = 0;
		MeshManager::getSingleton().createPlane("Myplane",
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
			4500,4500,10,10,true,1,5,5,Vector3::UNIT_Z);
		Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
		pPlaneEnt->setMaterialName("Examples/GrassFloor");
		pPlaneEnt->setCastShadows(false);
		mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);

		Vector3 min(-2000,30,-2000);
		Vector3 max(2000,30,2000);


		MeshPtr msh = MeshManager::getSingleton().load("ogrehead.mesh", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		msh->buildTangentVectors();

		Entity* e = mSceneMgr->createEntity("1", "ogrehead.mesh");
		e->setMaterialName("Examples/BumpMapping/MultiLightSpecular");
		
		StaticGeometry* s = mSceneMgr->createStaticGeometry("bing");
		s->setCastShadows(true);
		s->setRegionDimensions(Vector3(500,500,500));
		for (int i = 0; i < 10; ++i)
		{
			Vector3 pos;
			pos.x = Math::RangeRandom(min.x, max.x);
			pos.y = Math::RangeRandom(min.y, max.y);
			pos.z = Math::RangeRandom(min.z, max.z);

			s->addEntity(e, pos);
			Entity* e2 = e->clone("clone" + StringConverter::toString(i));
			mSceneMgr->getRootSceneNode()->createChildSceneNode(pos+Vector3(0,60,0))->attachObject(e2);

		}

		s->build();
This creates a series of Ogre HEADs with normal mapping and specular in a static geometry, and directly above them puts a standard entity for comparison. Camera and light move. Screenshots show they look identical, they both light dynamically as expected. There's no orientation being introduced here so the bug I fixed with tangents isn't an issue.
Image Image

Sorry, I haven't had time to look at your stuff specifically, it's faster for me to test pure Ogre to eliminate 3rd-party issues. This suggests that there's a problem elsewhere, perhaps in the shaders you're using.
User avatar
Evak
Orc Shaman
Posts: 707
Joined: Sun Apr 02, 2006 7:51 pm
Location: Sacramento, CA
x 1

Post by Evak »

hmm, interesting. I'm not sure why the shaders would work with a regular mesh but not a static one. Maybe its a Ofusion mesh problem?

http://www.kineticrealities.com/shinyprob.avi

The above link is a side by side video, the difference can be quite subtle but if you look at the specular highlights you can see that they do not adapt to the camera position in the capture on the right. So it looks almost static.

The Static geometry is the capture on the right hand side of the screen
Last edited by Evak on Thu Aug 09, 2007 11:53 pm, edited 1 time in total.
User avatar
Evak
Orc Shaman
Posts: 707
Joined: Sun Apr 02, 2006 7:51 pm
Location: Sacramento, CA
x 1

Post by Evak »

Our Programmer said
The camera angle makes no difference to the shinyness. It's like it has been computed once, then ignored.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67

Post by sinbad »

And as I said, it works fine with my normal mapping shaders which include specular. So this appears to be localised to your app. If I get time I'll download it to see but I'm pretty sure this is nothing to do with Ogre.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67

Post by sinbad »

I've had a quick look, and your shaders are rather inefficient because they're passing camera position and light position in world space then inverse transforming it, instead of using the object space positions in the first place (camera_position_object_space / light_position_object_space). I tweaked that and it seemed to work.
User avatar
Evak
Orc Shaman
Posts: 707
Joined: Sun Apr 02, 2006 7:51 pm
Location: Sacramento, CA
x 1

Post by Evak »

hmm, ok. I Don't really know anything about shaders, I just selected tangent space and exported the .fx file. This was because the the shader profiler showed showed tangent space using less instructions being used on my GPU than the world space version. Was only one instruction less.

I'll get one of our coders to convert a world space version, unfortunately no one in our team knows much about shaders, but one of our coders figured out a step by step method to convert an FX file my shader tool creates for me.

Thanks for checking it out and hopefully showing your post to our coder will put us on the right track :)

UPDATE:

One of our coders worked it out from Sinbads comments in his last post :)