How are you doing!?
Let’s see if anyone can help me: I got a 3D enviroment consisting of only 2 objects and a skybox. The 2 objects never change, although they are made of many, many vertices, so I consider it very expensive to apply volume render shadowing techniques, or etc.
Therefore I thought that using a texture with a shadow drawn in the shape of the object and stretching it according to “sun coordinates” would cause a respectable effect.
However I have problems generating that shadow texture map. Is there any 3D program that draws the object from top with it’s shadow and permits me to hide the object so that I may copy the shadow only?
Thank you so much,
I think you can simply write a program yourself.
Move the camera(view point) to the position of the light, for your case, it is the top of an object. Then 2-pass rendering the scene: draw to stencil buffer only in the first pass, and draw a quad to color buffer in the 2nd pass, which covers whole screen with black surface color and white background.
And read the rendered image back to your application.
Songho thanks for your answer!
I am kind of a newbie, and I never used the stencil buffer. Could you explain me how to draw in the stencil buffer first pass, and then in the color buffer 2nd pass!? What commands should I use.
Thank you so much,
I think there is much easier and simpler way than using stencil: rendering the object with no lighting , flat shading and black color on white background.
Anyway, here is a snippet using stencil;
// PASS 1: draw to stencil buffer only
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // disable writing to color buffer
glStencilFunc(GL_ALWAYS, 0x1, 0x1);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
// PASS 2: draw color buffer
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // enable writing to color buffer
glStencilFunc(GL_EQUAL, 0x1, 0x1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
drawObject(); // draw object again, or big quad here
I wrote a program and download it from here:
Press SPACE key to toggle to 2-pass stencil fill.
You can also rotate and move around the object with mouse.
Capture the screen with glReadPixels() then, make it a little soften using blur filter.
Thanks everyone for your time and anwers! :eek: )
Well, it took me some time to work it around, and I finally got a shadow with the sun pointing directly from top.
However, do you think there is a method so I can a shadow with another sun position!? The problem is that if the sun position is not directly pointing from top, then the shadow is a projection of the 3d model into the floor. However with the previous method I can’t do this unless I implement real-time shadowing technics, and that is not wanted for a program with only one model.
Is there any demo or program that would let me get a picture of the projected shadow only?!
Thank you so much for all!
The first icon is a typo! It was meant to be