[SOLVED] Shadows over terrain

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
Buckcherry
Goblin
Posts: 279
Joined: Tue Oct 04, 2005 4:28 pm

[SOLVED] Shadows over terrain

Post by Buckcherry »

Hello everybody,

How could it be possible to do the character casts shadows over the terrain?.

In the tutorial is explained how to do it defining a plane. But, what about when we have an irregular terrain? (mSceneMgr->setWorldGeometry( "terrain.cfg" );)

Thanks.
Last edited by Buckcherry on Sat Dec 10, 2005 3:15 pm, edited 1 time in total.
User avatar
celic
Gnome
Posts: 363
Joined: Wed Mar 23, 2005 11:05 am
Location: Chisinau/Moldova
Contact:

Post by celic »

you should use the following function:
mSceneMgr->setShadowTechnique()

and be sure that your terrain material has receive_shadows on attribute.
Buckcherry
Goblin
Posts: 279
Joined: Tue Oct 04, 2005 4:28 pm

receive_shadows

Post by Buckcherry »

Where should I have to put the "receive_shadows" attribute?.

I am using the map by default: terrain.cfg
User avatar
celic
Gnome
Posts: 363
Joined: Wed Mar 23, 2005 11:05 am
Location: Chisinau/Moldova
Contact:

Post by celic »

does your map point to a material script?

I don't know how it's organized, but I think the terrain should use a material, so, add this attribute at the beginning of the script, juts after material material_name{
Buckcherry
Goblin
Posts: 279
Joined: Tue Oct 04, 2005 4:28 pm

terrain.cfg

Post by Buckcherry »

Well... I am quite newbie managing terrain.

This is the terrain.cfg:

Code: Select all

# The main world texture (if you wish the terrain manager to create a material for you)
WorldTexture=terrain_texture.jpg

# The detail texture (if you wish the terrain manager to create a material for you)
DetailTexture=terrain_detail.jpg

#number of times the detail texture will tile in a terrain tile
DetailTile=3

# Heightmap source
PageSource=Heightmap

# Heightmap-source specific settings
Heightmap.image=terrain.png

# If you use RAW, fill in the below too
# RAW-specific setting - size (horizontal/vertical)
#Heightmap.raw.size=513
# RAW-specific setting - bytes per pixel (1 = 8bit, 2=16bit)
#Heightmap.raw.bpp=2
# Use this if you want to flip the terrain (eg Terragen exports raw upside down)
#Heightmap.flip=true

# How large is a page of tiles (in vertices)? Must be (2^n)+1
PageSize=513

# How large is each tile? Must be (2^n)+1 and be smaller than PageSize
TileSize=65

# The maximum error allowed when determining which LOD to use
MaxPixelError=3

# The size of a terrain page, in world units
PageWorldX=1500
PageWorldZ=1500
# Maximum height of the terrain 
MaxHeight=100

# Upper LOD limit
MaxMipMapLevel=5

#VertexNormals=yes
#VertexColors=yes
#UseTriStrips=yes

# Use vertex program to morph LODs, if available
VertexProgramMorph=yes

# The proportional distance range at which the LOD morph starts to take effect
# This is as a proportion of the distance between the current LODs effective range,
# and the effective range of the next lower LOD
LODMorphStart=0.2

# This following section is for if you want to provide your own terrain shading routine
# Note that since you define your textures within the material this makes the 
# WorldTexture and DetailTexture settings redundant

# The name of the vertex program parameter you wish to bind the morph LOD factor to
# this is 0 when there is no adjustment (highest) to 1 when the morph takes it completely
# to the same position as the next lower LOD
# USE THIS IF YOU USE HIGH-LEVEL VERTEX PROGRAMS WITH LOD MORPHING
#MorphLODFactorParamName=morphFactor

# The index of the vertex program parameter you wish to bind the morph LOD factor to
# this is 0 when there is no adjustment (highest) to 1 when the morph takes it completely
# to the same position as the next lower LOD
# USE THIS IF YOU USE ASSEMBLER VERTEX PROGRAMS WITH LOD MORPHING
#MorphLODFactorParamIndex=4

# The name of the material you will define to shade the terrain
#CustomMaterialName=TestTerrainMaterial
I don't know the name of the .material file where it should be the script. Do I have to look for 'TestTerrainMaterial' within the .material files?.

Thanks
User avatar
snipexv
Halfling
Posts: 66
Joined: Thu Jan 27, 2005 3:20 pm

Post by snipexv »

Code: Select all

#CustomMaterialName=TestTerrainMaterial
This line is commented out right now. You have to uncomment that line and then create the material script for TestTerrainMaterial (or you can name it whatever you like). There is no material script by default though, afaik.
Buckcherry
Goblin
Posts: 279
Joined: Tue Oct 04, 2005 4:28 pm

TerrainMaterial

Post by Buckcherry »

Ok, I have uncommented that line, so in my terrain.cfg apperas the following line:

Code: Select all

CustomMaterialName=TerrainMaterial 
And I have created a file called TerrainMaterial.material which has the following code inside:

Code: Select all

material TerrainMaterial
{

	receive_shadows on;

}
But nothing happens... (The program works as always: without shadows)

What is wrong?
User avatar
celic
Gnome
Posts: 363
Joined: Wed Mar 23, 2005 11:05 am
Location: Chisinau/Moldova
Contact:

Post by celic »

be sure that:
- your light cast shadows
- your character mesh contains tangent space generated
- your terrain material receives shadows

good luck! :D
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 »

Make sure you're using a directional light. There is a known issue that spotlights don't work for casting texture shadows on the terrain at the moment if you have vertex program morphing enabled. Using a directional light or turning off the morphing should work.

That material script isn't valid (it has no techniques or passes), get rid of it or read the manual or refer to existing material scripts to see how to write a correct material script.
Buckcherry
Goblin
Posts: 279
Joined: Tue Oct 04, 2005 4:28 pm

Ok

Post by Buckcherry »

Ok, thanks. I will try with a directional light.
User avatar
SuperMegaMau
Greenskin
Posts: 104
Joined: Mon Mar 21, 2005 3:31 am
Location: Portugal

Post by SuperMegaMau »

Make sure you have the flag "VertexNormals=yes" in the configuration file of the terrain "terrain.cfg"
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 »

SuperMegaMau wrote:Make sure you have the flag "VertexNormals=yes" in the configuration file of the terrain "terrain.cfg"
You don't need that for modulative shadows, only for dynamic lighting or additive shadows.
User avatar
SuperMegaMau
Greenskin
Posts: 104
Joined: Mon Mar 21, 2005 3:31 am
Location: Portugal

Post by SuperMegaMau »

:? if the terrain has no normals, then you can't apply any kind of light or shadows! Am I right?
User avatar
Falagard
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2060
Joined: Thu Feb 26, 2004 12:11 am
Location: Toronto, Canada
x 3
Contact:

Post by Falagard »

Wrong. You can't light the terrain itself dynamically if it doesn't have normals, but you can cast shadows onto it.
User avatar
SuperMegaMau
Greenskin
Posts: 104
Joined: Mon Mar 21, 2005 3:31 am
Location: Portugal

Post by SuperMegaMau »

true...
Buckcherry
Goblin
Posts: 279
Joined: Tue Oct 04, 2005 4:28 pm

Ok

Post by Buckcherry »

I have done the following:

- set an Ambient light
- set a directional light
- mSceneMgr->setShadowTechnique(ADDITIVE_STENCIL)
- set receive_shadows on in the .material file associated to the terrain.cfg

After doing this shadows appear over the character rather than casting over the terrain.

What is wrong?.

You mention something about tangents. What is that?. What do I need to generate tangents?.

Thanks.
Buckcherry
Goblin
Posts: 279
Joined: Tue Oct 04, 2005 4:28 pm

Come on

Post by Buckcherry »

This topic has been posted a lot of time ago and I do not believe that nobody knows how to use shadows over a terrain created using:

setWorldGeometry("terrain.cfg");

Please, help!.

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 »

Shadows over terrain works out of the box with modulative stencil and texture shadows (from directional lights).

You're using additive shadows, which means you should have read the manual: http://www.ogre3d.org/docs/manual/manual_61.html#SEC235
This explains how additive lighting works, and reveals that it only works if the objects being shadowed are dynamically lit, because it works by masking out light, not by darkening areas. Since terrain is not dynamically lit out of the box (vertex lighting looks awful on LODed terrain, although you can use pixel shaders to do a better job with a custom material), it won't work. Use modulative shadows.
Post Reply