ve recently started my own opengl app , so far ive 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.
ve managed to rotate , scale and translate the objects so that every one is at theyre 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.
m at the point where i want to add shadows to my scene , and thats the reason why i
m posting... i cant 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 cant figure out how to calculate my shadows.
someone pls help
here are also some pics of how things look so far :
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.
thanks a lot , i
ll give it a shot , im 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);
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
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 ill succeed
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…
yep , i realised it would be very difficult for me to convert that code … maybe impossible
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 ive 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…
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:
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.