XNA Creators Club Online
Page 1 of 1 (5 items)
Sort Posts: Previous Next

Shadows in terrain

Last post 10/4/2009 6:29 PM by Ben Andersen. 4 replies.
  • 10/2/2009 8:45 AM

    Shadows in terrain

    Hi

    I build a terrain with trianglestripes and put a simple texture on it. In this terrain are hills and mountains. If I put a spotlight in the scene the backsides of the mountains are dark (through the normals) but there is no shadow? I found a lot of information about shadows that are thrown from other objects, but my terrain is one large object. There is no other object in the scene. I guess what I need is a way to put a shadow on a object itself ? Does anybody know what I mean and way to solve this?

    Thomas
  • 10/2/2009 9:32 AM In reply to

    Re: Shadows in terrain

    Answer
    Reply Quote

    Assuming you are talking about 3D shadows.

    The effect you are seeing at the moment is just the basic lighting effect in whatever shader you are using, probably BasicEffect.
    In simple terms it calculates where the light is in ralation to the normal (which way it is facing) of the vertex that it is about to draw and changes the colour if it is facing away from the light.  It does not take in to account other objects or other vertices blocking the light.

    It's a nice effect but is nothing to do with shadows.

    There's a lot of work on shadows available on the internet, a basic example in the Creator Club and I also have an example on my web site.
    Look at the Shadow Map tutorials on the NVidia developers web site.

    There is no quick fix.  3D Shadows require a lot of effort and you will need to learn how to programme shaders (.fx files.)
    I worked on shadows for months and although mine work, they still need more time to make them look nicer.

    Regards


    **

    Well on the way to creating a 3D First person controls shooter with Over the Shoulder view... Another few YEARS and it'll be done!

    http://games.discoverthat.co.uk/ - Skinning Sample Dude for Blender and XNA Parallel Spilt Shadow Maps plus other stuff...

    My game development blog - Well a few notes from time to time...
  • 10/2/2009 11:00 AM In reply to

    Re: Shadows in terrain

    Thanks for the information. Ich checked out your website. But you also only describe how one object throws a shadow to a second object.
    I understand how the basic light effect works, but I have no hint how to change it to my requirements. Should I raytrace the hole thing by myself ?

  • 10/2/2009 1:20 PM In reply to

    Re: Shadows in terrain

    TFreudi1:
    ... you also only describe how one object throws a shadow to a second object.
    ... Should I raytrace the hole thing by myself ?


    I am not sure exactly what your needs are but shadow maps are by far the most common method.  I think ray tracing would be too slow.  The XNA Matrix provides a sort of shadow function, but it is only likely to be of any use on flat surfaces.

    If you are asking if there is a built in way to do shadows on a terrain, the answer is no, you do have to do all the code yourself.

    I thought my sample had two objects in it and the terrain.  They can cast shadows on themselves although if I remember correctly the light is so high in my scene that there are only a few places on the terrain that you can see it.  It was intended to demonstrate shadows cast by a moving model so the other things it can do are just consequential.

    If you change the scale of the terrain you can get higher peaks which cast more shadows.  Check the Draw() methods as I might have made the terrain a shadow receiver but not a caster.  It can cast shadows on itself if necessary.

    Regards
    **

    Well on the way to creating a 3D First person controls shooter with Over the Shoulder view... Another few YEARS and it'll be done!

    http://games.discoverthat.co.uk/ - Skinning Sample Dude for Blender and XNA Parallel Spilt Shadow Maps plus other stuff...

    My game development blog - Well a few notes from time to time...
  • 10/4/2009 6:29 PM In reply to

    Re: Shadows in terrain

    Here is something I wrote a while back in my diary concerning a thoughts for a shader that would handle one light casting shadows from any number of objects onto any number of objects, as it utilizes a depth buffer from the camera's perspective and a depth buffer from the lights perspective, and some linear algebra to determine if a given pixel on the screen should be in the shade or not.

    Shadow Map:

    Create a dynamic environment depth buffer map from the light's perspective. The depth buffer of the screen is taken, and then for each point on the screen, the depth is considered and a point in 3d space is derived, then that point's location on the light's environment depth map is compared to the actual depth of said point. If the point is deeper than the lights environment depth map, the point is shaded, if it is equivalent (or closer just in case) it is lit. An occlusion map may be provided to ensure that objects a given distance and or angles from the light are shaded. If a point is lit it's normal is taken into account relative to the light to derive the amount of lighting.

    Multiple lights can be used, their effect should be additive, such that no pixel is shaded by a light when another light is lighting it. The Light Map is a gray scale texture that is derived from all this, and is overlaid onto the rendering providing dark where light is occluded.

    Possible alterations give a light distance map for the shaded pixels. If a shaded area is far enough from the light and close enough to the shadow's boundary the point could be lit a bit more to simulate the curvature of light paths.


    So there's this, I haven't gone into actually implementing it. But this is a good general solution. However you'll have to do a pass for each of these lights you want.
Page 1 of 1 (5 items) Previous Next