Terrain and Texture shadow.[!56k, many pics]

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49

Terrain and Texture shadow.[!56k, many pics]

Post by Crashy »

Well, I know this topic comes back many times.

Let me explain the situation.

With Kuranes help, I've(much Kuranes than me in fact) finally succeded to disable shadow casting from PagingLandscape Terrain.
With stencil shadow, no more errors(see here to see wat were the errors http://www.ogre3d.org/phpBB2/viewtopic. ... &start=325).

So without those errors, I'm sure the terrain doesn't cast shadows.
Here is the result with stencil shadows.
Image

So now, let try with texture shadows.
Scene condition: the light is a spotlight, oriented to the object position, and positionned just under the camera.

On this pic, you can see the athena shadow.
But there is a black surface on it.
Image

In this third pic, there is a very strange shadow. It is located just under the athena mesh.
Image

Any idea for where it comes(black surface and "arrow" shadow)?
Last edited by Crashy on Mon Dec 06, 2004 7:18 pm, edited 1 time in total.
Follow la Moustache on Twitter or on Facebook
Image
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49

Post by Crashy »

I've just taken two interesting screenshots.
This one with stencil shadows, it works fine. We can see the separation between zones where terrain is enlightened, and zones it isn't.(because of spotlight).
Image

Now, the same scene, with same light, but with texture shadows

Image

:shock: The enlightened zones of previous pic are coming black :?: :?: :?: :?: :?:
Follow la Moustache on Twitter or on Facebook
Image
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

Post by sinbad »

Texture shadows work by re-rendering shadow receivers with a modulative texture, which is white where there are no occluders and black where there are. When you use a spotlight, there is an additional layer which causes the shdaow to fade out around the edges, rather than hitting a hard edge (looks nicer).

It looks to me like at least come element of the terrain (can't be all of it, because otherwise it wouldn't be a shadow receiver) is being rendered into the shadow texture, or maybe the sky is? Whatever the case, the entire shadow texture is black - it just looks like a roundish blob because of the secondary texture fading it out around the edges of the spotlight. If you used a directional light the entire landscape will be black, I bet.

Find out what's rendering to the shadow texture (ie what still has shadow casting enabled) which is taking up the entire spotlight's field of view.
iq
Greenskin
Posts: 125
Joined: Mon Oct 20, 2003 8:25 pm

Post by iq »

Most likely the sky - when I was working with shadows I noticed that ogre tries to calculate shadow volumes for the skyplane. Did not find an obvious method to switch it off though.


While we are at the topic of shadowing - I wonder if it is somehow possible to mix shadowing techniques. I'm interested in stencil shadows, because it allows self shadowing, but for the whole scene it uses way to much processing resources.

One possible way would be having 2 shadow 'passes' - first the player vehicle renders shadows onto itself, and then the whole scene is shadowed with texture shadows.
Would that work at all, and is it possible to tack that onto ogre? RT shadows have become a checkbox item and it really can help to raise the immersion, but so far I have not found a satisfactory setting that is both visually pleasing and offers acceptable performance.
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49

Post by Crashy »

This is not the sky
cielEnt->setCastShadows(false);
I'm sure of this because if I use a default light, as said Sinbad, the terrain is black, but also the sky. So if with texture shadows a shadow caster cannot be a receiver, It is no the sky.



I also tried to disable the shadow casting from camera(I 've taken every eventuality).
I've nothing else loaded in this scene.

I've already imported the landscape in the shadow demo, but with the same result, so I'll try as soon as possible to make a simple sample with only a camera, a light, the athene mesh and the terrain to see if there is still an error.
Follow la Moustache on Twitter or on Facebook
Image
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

Post by sinbad »

iq wrote:Most likely the sky - when I was working with shadows I noticed that ogre tries to calculate shadow volumes for the skyplane. Did not find an obvious method to switch it off though.
You can amortise a huge amount of work as well as getting rid of shadows for large groups of objects by turning off shadow processing for a render queue. For example, this is what OGRE does automatically:

Code: Select all

    // init render queues that do not need shadows
    mRenderQueue->getQueueGroup(RENDER_QUEUE_BACKGROUND)->setShadowsEnabled(false);
    mRenderQueue->getQueueGroup(RENDER_QUEUE_OVERLAY)->setShadowsEnabled(false);
    mRenderQueue->getQueueGroup(RENDER_QUEUE_SKIES_EARLY)->setShadowsEnabled(false);
    mRenderQueue->getQueueGroup(RENDER_QUEUE_SKIES_LATE)->setShadowsEnabled(false);
This is why overlays and all the default skies don't cast shadows (the shadow demo would have problems otherwise since it has a skybox).
While we are at the topic of shadowing - I wonder if it is somehow possible to mix shadowing techniques. I'm interested in stencil shadows, because it allows self shadowing, but for the whole scene it uses way to much processing resources.
Practically speaking that's difficult, although mixing texture and modulative stencil might be doable, I think the contrast between them wouldn't look good. If you want stencil shadows, use agressive LOD on your meshes. It really does help - use the Knot in a shadow example and watch the triangle count drop as it recedes into the distance.
RT shadows have become a checkbox item and it really can help to raise the immersion, but so far I have not found a satisfactory setting that is both visually pleasing and offers acceptable performance.
Shadows are a bitch. Everyone wants them, but there still isn't a single solution which is both good looking, perfect in all cases, and fast. You just have to pick what's best for your scene and cheat as much as possible.

@Crashy: I can only assume it's something to do with the way paging landscape renders then. Are you sure shadow casting is turned off for everything that it renders? Texture shadows work ok on the standard terrain renderer.
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49

Post by Crashy »

I'm quite sure the shadow casting is disabled for landscape.
I explain me:

With stencil shadow, OGRE tests if each mesh has exactly two faces /edge.

And the terrain do'nt respect this constraint, because it is'nt manifoiled.
So as long as the landscape was casting shadows, I had error in the logfile.
-----------------------------------
Details:
-----------------------------------
Error #: 6
Function: EdgeListBuilder::createEdge
Description: Edge is shared by too many triangles.
File: \OGRE\ogrenew\OgreMain\src\OgreEdgeListBuilder.cpp
Line: 475
Stack unwinding: <<beginning of stack>>
13:05:36: Trying alternate edge building technique 2
13:05:36: An exception has been thrown!

-----------------------------------
Details:
-----------------------------------
Error #: 6
Function: EdgeListBuilder::createEdge
Description: Edge is shared by too many triangles.
File: \OGRE\ogrenew\OgreMain\src\OgreEdgeListBuilder.cpp
Line: 475
Stack unwinding: <<beginning of stack>>
13:05:36: Trying alternate edge building technique 3
13:05:36: An exception has been thrown!
(it is just a quote, it continues to level 5)



Kuranes finally find the solution to disable shadow casting frome paginglandscape.
Simply overide the setCastShadow function at the begining of Paging Landscape Renderable class.

So now I no more have errors with stencil shadows, so I suppose the landscape is not casting shadows.
I think it is logical, but I may be wrong.
Follow la Moustache on Twitter or on Facebook
Image
iq
Greenskin
Posts: 125
Joined: Mon Oct 20, 2003 8:25 pm

Post by iq »

sinbad wrote: You can amortise a huge amount of work as well as getting rid of shadows for large groups of objects by turning off shadow processing for a render queue. For example, this is what OGRE does automatically:

Code: Select all

    // init render queues that do not need shadows
    mRenderQueue->getQueueGroup(RENDER_QUEUE_BACKGROUND)->setShadowsEnabled(false);
    mRenderQueue->getQueueGroup(RENDER_QUEUE_OVERLAY)->setShadowsEnabled(false);
    mRenderQueue->getQueueGroup(RENDER_QUEUE_SKIES_EARLY)->setShadowsEnabled(false);
    mRenderQueue->getQueueGroup(RENDER_QUEUE_SKIES_LATE)->setShadowsEnabled(false);
This is why overlays and all the default skies don't cast shadows (the shadow demo would have problems otherwise since it has a skybox).
Ahh, didn't know that you can do that - nevertheless I seem to remember that I got a prepshadow file for the skyplane in debug mode - probably I just imagine things :? ... or it was an intermediate thing from a cvs build ...
Practically speaking that's difficult, although mixing texture and modulative stencil might be doable, I think the contrast between them wouldn't look good.
That's why I thought about restricting the stencils on pure selfshadowing the player vehicle - you get shadows from the roof, framing, controls etc, but the shadow that is cast on the ground is always using the same technique.
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49

Post by Crashy »

Ok I can add more information.

With a "clear" sample, here is what I get:
No (texture) shadow on the ground fo both Octree Terrain and Paging Landscape.

About the octree terrain: I 've read that to enable texture shadow receiving on this terrain, I've just to add "setCastShadow(false)" at the end of "TerrainRenderable::initialise" in the OgreTerrainRenderable.cpp file.
(I've rebuild the plugin and the sample). Is this really sufficent?(don't sure of this word in english)

Here is my sample code:




Code: Select all

#include "ExampleApplication.h"


 

class ShadowTest : public ExampleFrameListener
{
public:
    ShadowTest(RenderWindow* win, Camera* cam)
        : ExampleFrameListener(win, cam)
    {
        
        int mMoveSpeed = 50;

    }

    bool frameStarted(const FrameEvent& evt)
    {
		
	
       
        bool ret = ExampleFrameListener::frameStarted(evt);
      

//Just to switch between shadow techniques
		
		if(mInputDevice->isKeyDown(KC_S))
		{
		mCamera->getSceneManager()->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE);
		
		
		}
		if(mInputDevice->isKeyDown(KC_DOWN))
		{
		mCamera->getSceneManager()->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
	
		
		}

        return ret;

    }

};


class ShadowTestApplication : public ExampleApplication
{
public:
    ShadowTestApplication() {}

    ~ShadowTestApplication()
    {
     
    }

protected:


    virtual void chooseSceneManager(void)
    {
        
        mSceneMgr = mRoot->getSceneManager( ST_EXTERIOR_REAL_FAR );
	
    }

    virtual void createCamera(void)
    {
   
        mCamera = mSceneMgr->createCamera("PlayerCam");
        mCamera->setPosition(Vector3(128,0,128));
        mCamera->lookAt(Vector3(0,0,-300));
        mCamera->setNearClipDistance( 1 );
        mCamera->setFarClipDistance( 1000 );
		
    }
   
   
    void createScene(void)
    {
     
		mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE);
       
       mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
	   mSceneMgr->setShadowFarDistance(2000);
    
        Light* l = mSceneMgr->createLight("MainLight");
        
     
		
		l->setType(Light::LT_SPOTLIGHT);
		l->setSpotlightRange(Degree(60), Degree(70));
		l->setCastShadows(true);
		l->setPosition(1500,10000,1500);
       Vector3 dir;

		dir.x = 0;
		dir.y =- 1000;
		dir.z =0;
		dir.normalise();
        l->setDirection(dir);

        ColourValue fadeColour(0.93, 0.86, 0.76);
      
        mWindow->getViewport(0)->setBackgroundColour(fadeColour);
	 mSceneMgr -> setWorldGeometry( "paginglandscape2.cfg" );
       

    
        mCamera->setPosition(1500,250,1500);
      
        
		Entity*ent = mSceneMgr->createEntity("head", "athene.mesh");
		ent->setCastShadows(true);
    	SceneNode*playerNode=static_cast<SceneNode*>(mSceneMgr->getRootSceneNode()->createChild("PlayerNode"));
		
               playerNode->attachObject(ent);
		playerNode->setPosition(1500,250,1500);
		playerNode->setScale(1,1,1);

    }
 
    void createFrameListener(void)
    {
        mFrameListener= new ShadowTest(mWindow, mCamera);
        mRoot->addFrameListener(mFrameListener);
    }

};
//Edit:With a plane just under the object, still no shadow on it. I begin to think I've forgotten something crucial for texture shadows.
Plane sPlane;
sPlane.normal = Vector3::UNIT_Y;
sPlane.d = -150;
MeshManager::getSingleton().createPlane("Plane",sPlane,
30000,30000,10,10,true,1,5,5,Vector3::UNIT_Z);
Entity*pPlaneEnt;
pPlaneEnt = mSceneMgr->createEntity( "plane", "Plane" );
pPlaneEnt->setCastShadows(false);
mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
Follow la Moustache on Twitter or on Facebook
Image
iq
Greenskin
Posts: 125
Joined: Mon Oct 20, 2003 8:25 pm

Post by iq »

Bits I can add:

It is not the sky, as I can replicate that black blob (although the edge detect algo does process the skyplane with the resulting prepshadow file) turning off the skyplane changes nothing.
Similarly not generating any terrain renderables still resulted in wrong shadows.

It does not only affect my terrain renderables -other meshes are not shadowed correctly either - when the camera comes close to an object (direction in regard to the (directional) light does not matter) the whole mesh gets dark.

It happens with either OGL and DX and it happens with GF4 cards and a radeon 9800.

I use a scenemgr with renderables pretty similar to PLSM and switched to 15.1 release for testing.

Further testing indicates that this is a problem that objects cast shadows despite the entities being set to setCastShadows( false );
Using a test mesh it appears that meshes can cast shadows onto itself with texture shadows - which should be impossible.
iq
Greenskin
Posts: 125
Joined: Mon Oct 20, 2003 8:25 pm

Post by iq »

This is a screenshot of a single mesh (believed to be the only in the scene) with a nearly vertical directional light. the entity was set to setCastShadows(false).

You can clearly see where the shadow of the box overlays the both cylinders, and where the shadow of both cylinders overlays the box.

Image
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49

Post by Crashy »

I still do'nt know why shadows not appears in the ligh sample I've post, but I have a little question:Is it possible there is a conflict between texture shadow and other render to textures? (the ones I use for fresnel)?
Follow la Moustache on Twitter or on Facebook
Image
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

Post by sinbad »

I'm afraid I haven't had time to test your scenarios yet, but I can't get away from the fact that texture shadows work perfectly in the Demo_Shadows demo, and the OgreODE demos, so I can't help thinking this is a setup issue.
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49

Post by Crashy »

No problem, I think it is a setup issue too, but I really don't know what it is..


Forget my comments of the code above, I have a result, still the same result, but not only with terrain, with the plane too. So....it must be a problem of light or shadow setup.

stencil shadows
http://crashy.cartman.free.fr/pouet/screenshot_1.jpg
texture shadows (you can see that the black zone is not covering the totality
of the enlightened surface).
http://crashy.cartman.free.fr/pouet/screenshot_2.jpg

I hope my next post will give an answer.
Follow la Moustache on Twitter or on Facebook
Image
iq
Greenskin
Posts: 125
Joined: Mon Oct 20, 2003 8:25 pm

Post by iq »

We'll look into it further and share results.

I just ripped out the complete custom scene mgr - using ST_GENERIC directly, yet my test mesh still shadows itself. Something odd is going on ... delete button here I come ;)
iq
Greenskin
Posts: 125
Joined: Mon Oct 20, 2003 8:25 pm

Post by iq »

Current suspect is: manipulating the near clip distance.

If I comment out mCamera->setNearClipDistance(x) in my application and maneuver the camera that the mesh is visible it is never shadowed.

With changed nearclipdist the mesh is shadowed when the camera is closer to the mesh to be visible with standard near clip settings.

I notice in crashy's example he sets the nearclip too...
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49

Post by Crashy »

I'm going to be mad. :shock:

I was testing some things in my sample (no changes to light/shadows code), then, just to see, I switched to texture shadow ....and it worked perfectly...

http://crashy.cartman.free.fr/pouet/screenshot_11.jpg


I've relaunched the sample, and It does'nt works anymore.

:? :? :? :? :? :? :? :? :? :? :?
I really don't know why it has worken.....stranger and stranger...but there is another unbelievable thing...

















I've add a second entity, an athena mesh too, with same settings(just position was no the same, but it was under the light, I'm sure of it )...and this entity was not casting shadows.
Entity*ent2 = mSceneMgr->createEntity("head2", "athene.mesh");
ent2->setCastShadows(true);
SceneNode*playerNode2=static_cast<SceneNode*>(mSceneMgr->getRootSceneNode()->createChild("PlayerNode2"));
ent2->setMaterialName( "Examples/Athene/NormalMapped");
playerNode2->attachObject(ent2);

playerNode2->setScale(1,1,1);
Follow la Moustache on Twitter or on Facebook
Image
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

Post by sinbad »

You ought to read the manual section about using shader-based materials with texture shadows, it might explain your latter problems.

http://www.ogre3d.org/docs/manual/manual_21.html#SEC92
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49

Post by Crashy »

Are you saying that because of the "Examples/Athene/NormalMapped" material, wich use VertexProgram?
PS: excuse me if my post sounds "arrogant", it is really far of what I think.
Follow la Moustache on Twitter or on Facebook
Image
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

Post by sinbad »

It's just something to bear in mind. In my scenes I've not seen these sort of results so I'm guessing at this point. I have the 'TODO list from hell' this month so I'm afraid that given texture shadows in the demos work it might take a while for me to get time to look at this in any detail.
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49

Post by Crashy »

I understand this, and I'm wondering the job you've already made, and the job you are making.
So respect the todo list :) and don't think at my little problems. I think I'll resolve it this weekend.
Follow la Moustache on Twitter or on Facebook
Image
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49

Post by Crashy »

Ok I think I've found the error of my sample, something due to the light position. It works good for Terrain, but still not for paginglandscape.

The dark zone wich appears with PGSLM is also affecting the floor plane.

Here is the scene with Octree terrain(the terrain is under the floor plain).
http://crashy.cartman.free.fr/pouet/screenshot_12.jpg
The same sample, but with PGSLM, far pic:
http://crashy.cartman.free.fr/pouet/screenshot_13.jpg
and the near pic
http://crashy.cartman.free.fr/pouet/screenshot_14.jpg

No idea for where it comes at the moment, but I'm searching. I hope it can be usefull for other people who wants to use texture shadow with PGSLM.
Follow la Moustache on Twitter or on Facebook
Image
User avatar
Sternenstaub
Gnoblar
Posts: 23
Joined: Wed Apr 20, 2005 8:27 pm

Post by Sternenstaub »

Well, this is an old Thread, but i guess its better i write here, because it seems I have exactly the same problem.

I have no problem with stencil shadows. They run pretty fine in my little test scenes. But with texture modulative shadows I got some "effects" that look very similiar to the ones explained here.

Here is a scene reduced to nothing but one floor plane and one moving spotlight:
http://img274.echo.cx/img274/4963/texshadowsprob5uo.jpg

The spotlight just lit a little part of the area it should and causing a black "blobb" beside it. Additionally, there is a thick black line on the right side moving with the light. (You cant see thi sline very good in the screenshot, but it is easy visible when you would see the light and the line moving).

Here is a scene with the same spotlight and a few simple boxes and a static geometry ground:
http://img274.echo.cx/img274/5337/texsh ... ob20er.jpg


It does not matter if I use Direct3D or OpenGL, windowed or fullscreen mode. I played around a lot with the shadow and light properties (max. distances, shadow and light colors, the light params, texture settings etc etc), but I always got this wrong shadows.

I checked a dotzen times now the shadow-demo with the athene-mesh, the tutorials in the wiki about lighting, I tried differnt scene setting (and at least one without anything but one simple plane and just the spotlight without any other objects or a skybox in it), but i cant seem to find what is causing that problem.
Additionaly, all scenes work pretty well with stencil shadows. Just the texture shadows are causing this problems.


What the little programm basically does is (in this order):
- choosing the render system (for example DirectX9)
- creating the render window
- choosing the scene manager (octree)
- setting the shadow technique
- creating the camera and the viewport
- creating the light and the meshes/plane (I tried different orders here without any change in the results)

While setting the shadow technique, I also tried a lot of different things, from just choosing the shadow type and leaving all other paramters to ogre, or by setting all shadow parameters by myself or just parts of them (and also checked different initialzing orders here).

Does anyone have a clue what could causing this? Or what else I could try? This problem is going to give me a rally headache in the meanwhile (the last 2 days i spent just trying to search for the cause of this bug, without the smallest success, and i am running out of ideas).
I would be very, very glad if anyone could give me a hint here.
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

Post by sinbad »

Searchy searchy: http://www.ogre3d.org/phpBB2/viewtopic. ... ow+terrain

The issue with the specific combination of vertex morph, texture shadows, spotlights and terrain is logged as a bug. Changing any one of those factors will resolve it.