View Full Version : Project Shadows over terrain model
01-09-2011, 01:52 PM
i`ve recently started my own opengl app , so far i`ve got some models , which i made in 3ds max , and i imported them using the GLM library into my opengl app. my models are a terrain , a skydome and a castle , which are also textured.
i`ve managed to rotate , scale and translate the objects so that every one is at they`re correct place in the scene .
i also can move "the camera" through the scene with W A S D keys and look around with the mouse.
i also defined a simple directional light.
so i`m at the point where i want to add shadows to my scene , and that`s the reason why i`m posting... i can`t seem to have a good ideea for the shadows , because of the terrain... if i would have a plain surface , it wouldn`t be a problem... but , again , because of the terrain , i can`t figure out how to calculate my shadows.
someone pls help
here are also some pics of how things look so far :
01-09-2011, 02:42 PM
There are many ways. Some are perspective shadow mapping(psm),tsm, etc. The most popular being cascaded shadow mapping (csm). The simplest form of it is a simple orthographic projection of the scene to get the shadow map and do your comparison test with it. I had found an example of the simplest form that uses xna and didn't find it hard to read through and convert it to opengl.
xna version (http://create.msdn.com/en-US/education/catalog/sample/shadow_mapping_1)
01-09-2011, 03:18 PM
thanks a lot , i`ll give it a shot , i`m really a beginner , hope i`ll manage to convert it to opengl
l.e. i can`t open that project with VS2008...what do i need to open the project ?
l.e.2 also if i use directional light , like the sun , and i want to use shadow mapping , i have to change to orthographic projection from perpective ? i tryed changing to orthographic proj and my scene isn`t visible anymore . how can i correctly do that ?
gluOrtho2D(-1.0f, 1.0f, -1.0f, 1.0f);
01-10-2011, 01:55 AM
All the XNA stuff is in C#. You could download Visual C# from MS web site if the files you downloaded were an SDK or wizard. But if your download files are just C# code (they should end with *.cs ) using an advanced text based editor (one that will open more than *.txt and *.rtf files, a good one is SciTe 2.23) you should be able to see the code, to "reverse engineer" what you need
01-10-2011, 03:05 AM
i checked and i have ms vs08 fully installed , including C# support , but i can`t open any files from the project , the microsoft visual studio solution from that project says unrecognized version ...
i downloaded SciTe and i`m viewing the code right now , i ll try to convert it to C, hope i`ll succeed
01-10-2011, 04:04 AM
Try to google for "opengl shadow mapping", it will give you several interresting tutorials and examples. I think it will be better than using a C# Direct3D example to do C++ OpenGL...
01-10-2011, 04:33 AM
yep , i realised it would be very difficult for me to convert that code ... maybe impossible :(
i`m currently searching for shadow mapping , but as i said in the previous post , i have a directional light in my scene and from what i`ve read, i need to change to an orthographic projection , but after changing from :
gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 1000.0);
gluOrtho2D(-1.0f, 1.0f, -1.0f, 1.0f);
i can`t see anything of my scene no more...
01-10-2011, 08:25 AM
the ortho matrix is just for rendering the scene depth from the point of view of the directional light.
you will still use your perspective projection for your scene.
shadow mapping works by comparing the pixel from the base rendered scene to the cooresponding pixel from the light's PoV to decide if that pixel is in shadow or not.
It is a technique similar/derived from projective texturing.
Ortho matrix is used for directional light lookup because the 'light rays' are all parallel, where as with a point/spot light the 'rays' spread out from the source.
The sun can be treated as a parallel source due to its distance away from Earth.
There is plenty of material available on shadow maps on the web. The theory is the same regardless of your chosen API & prog-language.
So the xna example above(not looked at it) will still be relevent - matrices will need to be passed to shaders, set up same techniques, syntax aside the methodology of the shaders in HLSL will be the same as in GLSL apart from the obvious stuff like the opposite order of matrix multiplication between the two.
Nvidia's Cg tutorial outlines the theory: http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter09.html
scroll down to section 9.4
Nvidia also has a decent page dedicated to shadows:
01-10-2011, 11:46 AM
I think it won't open the project because you don't have the xna studio installed. Even though it's c# to vs it more like "xna c#".
Look into framebuffer/render to texture. that way you can render the create the shadowmap just by rendering the scene with the ortho projection. Then switch back to the original perspective projection. when rendering the scene to display.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.