PDA

View Full Version : Fake Shadows with alpha blending



Rodrix
03-02-2006, 03:56 PM
Hi everyone! :)
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,
Rodrix

songho
03-02-2006, 07:16 PM
Rodrix,
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.

Rodrix
03-03-2006, 07:45 AM
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,
Best regards,
Rodrix

songho
03-03-2006, 01:08 PM
Rodrix,
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. :D

Anyway, here is a snippet using stencil;

...
glEnable(GL_STENCIL_TEST);
glDisable(GL_LIGHTING);

// 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);

drawObject();


// 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);
glColor3f(0,0,0);

drawObject(); // draw object again, or big quad here

glDisable(GL_STENCIL_TEST);
glEnable(GL_LIGHTING);
...I wrote a program and download it from here:
StencilFill.zip (http://www.songho.ca/opengl/files/stencilFill.zip)

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.
==song==

Rodrix
03-11-2006, 10:38 PM
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. :confused:

Is there any demo or program that would let me get a picture of the projected shadow only?!

Thank you so much for all! :)

Rodrix

Rodrix
03-11-2006, 10:42 PM
The first icon is a typo! It was meant to be :)
Good night! :D