Simple Shadows

Started by
25 comments, last by XorMultiPleXus 17 years, 10 months ago
^^^^ Have to figure out why gamedev (only site by the way) doesn't remember my login :-)
- http://vlab.dk
Advertisement
i haven't been working with soft shadows, but that does not means i won't in the future (in one or two months). I know only one way to do soft shadows - througth shaders. Look on www.nvidia.com. I have downloaded their sdk and there is a lot of shaders (in cg and hlsl) to create soft shadows and other kind of shadows and a lot of effects.

XorMultiPleXus
Ok. Is the Nvidia thing better than GLSL or am I missing something?

[Edited by - Kohaar on June 8, 2006 10:54:07 AM]
- http://vlab.dk
well it's because i have an nvidia card in my computer and they have so many things for free to download. So i've decided to try it. I have also read the spec for OGSL, but i did not find there anything about shader model 3.0. I want to use shader 3 so i have decided to use cg instead of GLSL. But you know i could miss something. You can use whatever you want. Cg is not perfect. But i have a little practive with it so i use it. And HLSL only in the worst case, because i dont wont to use directx. So it depends on what you need and what you like.

XorMultiPleXus
GLSL's shader level support depends on the card its running on, its perfectly acceptable todo SM3.0 things in GLSL, infact in some regards it goes beyond SM3.0 in what it lets you do in the language.
Just implemented it today, and the shadows work great. Thanks!

Now I just have to draw them in the correct perspective (from the light source).
- http://vlab.dk
Quote:Original post by Anonymous Poster
As I understand it you actually render the model 3 times.

One for the stencil buffer one for the shadow and one for the character?

The characters are bone animated and some of them have up to 20k polygons. I think this would be a little too expensive in computational power?

Hope you will bear with me if my questions seem extremely stupid :-)


No twice....

Once you rendered into the stencil buffer you can use a quad that covers the entire screen to fill in the shading.
----------------------------

http://djoubert.co.uk
Quote:Original post by Kohaar
Just implemented it today, and the shadows work great. Thanks!

Now I just have to draw them in the correct perspective (from the light source).



No what you need to do is extrude each edge into infinite from the light's point of view, this gives you volume shadows which are more than simple. Problem with this is the complexity of finding which edges to extrude.

Ofcourse if you plan on rendering the scene into a texture from the light source and then using the technique of depth lookup for shadowing you will be fine. All though kinda doesn't make sense to have stencil buffer then.
----------------------------

http://djoubert.co.uk
Couldn't you do it in one draw with something like:

// before frameglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);// draw shadowglDisable(GL_DEPTH_TEST);// setup normal blendingglEnable(GL_BLEND);glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);// render only where stencil is 0 (all of it, initially), but as the character// renders, pixels that render cause the stencil value to increment, thus // future attempts to render over that pixel failglEnable(GL_STENCIL_TEST);glStencilFunc(GL_EQUAL, 0, 0xFFFFFFFF);glStencilOp(GL_KEEP, GL_INCR, GL_INCR);renderShadow();glDisable(GL_STENCIL_TEST);glDisable(GL_BLEND);glEnable(GL_DEPTH_TEST);


I tested it briefly and it seemed to work, though I stayed up the whole night and I'm really tired, so perhaps I made an error.
Here is an example of the shadows



As you can see the shadows look odd because they don’t match the lighting. Otherwise I'm satisfied with the result. Any idea to how this could be accomplished.

I don’t have the time to start learning about advanced shadowing techniques, but if there are other methods of shadowing that are rather simple, I’m of course open for suggestions.

I would of course prefer that it could be implemented in my current code (using stencils) :-)
- http://vlab.dk

This topic is closed to new replies.

Advertisement