Shadow and lighting on terrain(heightmap)

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
User avatar
Mexx
Halfling
Posts: 51
Joined: Sat Apr 08, 2006 4:38 pm
Location: Netherlands

Shadow and lighting on terrain(heightmap)

Post by Mexx »

Hello,


My goal yesterday was to implement basic lighting and shadows. Knowing ogres uses( i am happy):
- 4 shadow types

Code: Select all

  
SHADOWTYPE_TEXTURE_MODULATIVE
  SHADOWTYPE_TEXTURE_ADDITIVE
  SHADOWTYPE_STENCIL_MODULATIVE
  SHADOWTYPE_STENCIL_ADDITIVE
- 3 light types

Code: Select all

  
DIRECTIONAL
  POINT
  SPOTLIGHT
My scene is equipped with the following resources:
- a Heightmap
- Entities(player model, world objects) directly attached to sceneNode.
- Static geometry for nature objects(trees for now)
- Water plane with Ocean Shader(from ogre's demo)
- Skyplane
- SkySphere

After my issues arrived i went looking for more information in the manual and on the forum.

Issues i met:
- Flickering shadows due to ocean.
- Black heightmap
- Shadows not cast by static geometry
- Shadows moving thru objects (showing multiple shadow)
- With addtive shadows a black area.


This brought me to the shadow demo. after examening it i came to the conclusion of using SHADOWTYPE_TEXTURE_MODULATIVE in combination with a SPOTLIGHT. And this i tried resulting in the following picture:

Image

Problem: Tree is not casting a shadow, neither is teh player model, some Black shadow line is crossing the screen, can't find out where it is comming from ?



Code used for this:

Code: Select all


// settings on
mSceneMgr->setShowDebugShadows(true);
mSceneMgr->setShadowTextureSelfShadow(true);


// SHADOW
sceneMgrTerrain->setShadowColour(Ogre::ColourValue(0.1, 0.1, 0.1));
sceneMgrTerrain->setShadowTextureSettings(512, 2);
sceneMgrTerrain->setShadowTechnique( SHADOWTYPE_TEXTURE_MODULATIVE ); 
sceneMgrTerrain->setShadowFarDistance( 200 );


// LIGHT		
Ogre::Light* light = sceneMgrTerrain->createLight( "ABCDLIGHT" );
light->setType( Ogre::Light::LT_SPOTLIGHT );		
light->setCastShadows( true );
light->setPosition( 175, 400, 175);
light->setDirection( Ogre::Vector3::NEGATIVE_UNIT_Z );
light->setDiffuseColour( 1, 1, 1 );
light->setSpecularColour( 1, 1, 1 );			
light->setAttenuation(8000, 1, 0.5005, 0);
light->setSpotlightRange(Ogre::Degree(80), Ogre::Degree(90));


// Tree
Entity* ent5 = mSceneMgr->createEntity("PAlmTree1", "palm.mesh" );
ent5->setCastShadows(true);	
ent5->setNormaliseNormals(true);

SceneNode* Node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("PalmtreeX");
Node2->attachObject(ent5);
Node2->translate(190, 65, 160);


// static geometry
sgNature->setCastShadows(true);
sgNature->build();


Can anybody help me?
Tell me what i'm doing wrong or a better way in accomplishing the task at hand.

Thank you
Those who find ugly meanings in beautiful things are corrupt without being charming.Those who find beautiful meaning in beautiful things are the cultivated. For these there is hope.They are the elect to whom beautiful things mean only beauty.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

Did you turn on VertexNormals in your terrain configuration?
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Mexx
Halfling
Posts: 51
Joined: Sat Apr 08, 2006 4:38 pm
Location: Netherlands

Post by Mexx »

Sorry to have posted in the general thread, totally didn't stood still by it.


If you refer to the VertexNormals = Yes in the terrain.cfg file i tried it with and without.


I found a new position on the terrain with weird results.

Image


Mabye this result is known to some on?


When directional light used instead of Spotlight i get the following result:


Image


Th image below is when i added the following code to the Ogre Terrain demo(black area's flicker):

Code: Select all

	// SHADOW 
	mSceneMgr->setShadowColour(Ogre::ColourValue(0.1, 0.1, 0.1)); 
	mSceneMgr->setShadowTextureSettings(512, 2); 
	mSceneMgr->setShadowTechnique( SHADOWTYPE_TEXTURE_MODULATIVE ); 
	mSceneMgr->setShadowFarDistance( 200 ); 

	// Tree 
	Entity* ent5 = mSceneMgr->createEntity("PAlmTree1", "palm.mesh" ); 
	ent5->setCastShadows(true);    
	ent5->setNormaliseNormals(true); 

	SceneNode* Node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("PalmtreeX"); 
	Node2->attachObject(ent5); 
	Node2->translate(100, 40, 100); 

Image




I'm rather clueless. (if you read this and you have no idea or your thinking i'm walking the stupid road, feel free to post that) :)
Those who find ugly meanings in beautiful things are corrupt without being charming.Those who find beautiful meaning in beautiful things are the cultivated. For these there is hope.They are the elect to whom beautiful things mean only beauty.
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 66
Contact:

Post by sinbad »

Try a directional light. I believe there may still be a bug with the TSM when using texture shadows with spotlights, when vertex morphing is enabled.
User avatar
Mexx
Halfling
Posts: 51
Joined: Sat Apr 08, 2006 4:38 pm
Location: Netherlands

Post by Mexx »

Thanks for the information.

I got it sorta to work. Except 1 fault.

When i use "SHADOWTYPE_TEXTURE_MODULATIVE" and i add a static geometry List with shadows enabled my whole terrain(area) turns dark(shadowed)?

have i mis read something somewhere or should i have enabled a certain setting ?
Those who find ugly meanings in beautiful things are corrupt without being charming.Those who find beautiful meaning in beautiful things are the cultivated. For these there is hope.They are the elect to whom beautiful things mean only beauty.
User avatar
avee
Halfling
Posts: 44
Joined: Fri Dec 23, 2005 8:36 am
Location: Bandung, Indonesia

Post by avee »

I have a similiar problem when lighting a terrain.. I'm using Dagon 1.2.0, and using TSM as the scene manager.

Just like Mexx, I'm trying cast shadows into terrain from my entities (not StaticGeometry).
When I used SHADOWTYPE_STENCIL_MODULATIVE, everything works fine, even when the VertexNormals option was not set to Yes.
Then I tried to use SHADOWTYPE_STENCIL_ADDITIVE, it didn't work, so I changed VertexNormals to Yes, and it worked..
I played around with the options a little bit, and now SHADOWTYPE_STENCIL_ADDITIVE is not working on the terrain (it works on other objects, but not the terrain).. I've tried to do a lot of things, even reverting to my old source code, but still it didn't work...

So I switch back to SHADOWTYPE _STENCIL_MODULATIVE.. And found out that when using this technique, the transparent portion of my mesh is shaded, which is not very good..

Here's the picture..
Image

What should I do to re-enable STENCIL ADDITIVE shadows on terrains?
Do you guys have any idea how to work aound the tree shadow problem? The tree consists of planes using transparent materials.. so far the only way is to set the setCastShadows to false.. But this is not good since I want the tree to cast shadows...

Thanks..
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 66
Contact:

Post by sinbad »

You can't use stencil shadows on transparent meshes, it can never work because it's a geometric, not per-pixel, effect. Your only option is to turn off shadow casting for those objects and perhaps use a static lighting map.

Additive shadows only work if the objects receiving shadows are dynamically lit, that's why you need vertex normals on the terrain for it to work. I can't tell you how to 'fix' it in your environment unless you tell me what you changed since it did work ;)
User avatar
avee
Halfling
Posts: 44
Joined: Fri Dec 23, 2005 8:36 am
Location: Bandung, Indonesia

Post by avee »

Wow, thanks Sinbad, you da man!!

I successfully used stencil additive with the terrain after I added the ambient, diffuse, specular and emissive settings to the terrain's material script. It's weird though, because I when it worked the first time, I didn't use those settings.. I don't know, must've been my bad.. :D

Hmm, so stencil shadow is a geometric effect.. And according to other threads, we can't combine texture shadow with stencil shadows right? I think I need to find other way to do it.. hmm..

Sinbad, if you don't mind, what's your suggestion on doing shadows on a flight-sim type game?
My team is developing a PLSM-like (but not exactly the same) scene manager that can create a pseudo unlimited terrain (blocks of meshes repeated over and over again).. And we want to achieve that sunlight shadow effect on trees.. Should I use texture shadows with shaders?

Thanks alot..
Post Reply