Sign in to follow this  

Shadow Mapping Transparency (Making Shadows Not As Black)

This topic is 3585 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've noticed particularly in the latest methods of Shadow Mapping, (CSM,PSSM, TSM etc) that they can seem to blend the shadow map with the surrounding environment and I wondering how it is done. For geometry based methods, you just set the transparency of the geometry you want to run at a certain amount and set up the approriate blend functions, but I am assuming this doesn't work with Image Based methods. If this is incorrect, please enlighten me :) I couldn't find much on the internet about it,except that most demos that I see that people have created the shadow is always pitch black. I'm not using shaders for my current shadowing mapping implementation because the station I'm working on doesn't support shaders that well and I can't program in Shaders yet :P Thanks, Neutrinohunter

Share this post


Link to post
Share on other sites
Thats weird, I was using them all ready. I've read that spec and it doesn't mention anything, about when the texture comparison passes or should it be failing I'm looking at *scratches head*

When R > D where D is the stored value and R is the distance from the light, the pixel is shadowed, therefore aren't I using the opposite test?

Oh I solved the artefact problem which we discussed in an earlier topic, the problem was caused by shadow leakage and that I wasn't using radians for a call to tan() :). Now it looks fine, except for the transparency I think.

I should also mention that I fixed the FBO problem as well, which was a problem with a float to int conversion which I and the debugger missed :O

Looking over Pauls tutorial at paulsproject.net, it does look like I've made a mistake. I'll have a look over it, so far I get an image like this:



Neutrinohunter

[Edited by - Neutrinohunter on February 17, 2008 7:41:43 PM]

Share this post


Link to post
Share on other sites
Well, as far as I know about this extension, you need to set light parameters (I presume you've set them) - ambient (I think it has to be non-zero), diffuse, etc.
...

For shadow mapping you've to call this:

// Set compare mode for shadow mapping hardware
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
// We're gonna pass when it's less or equal (so we'll fail, whern it's greater)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);

// When we'll fail, we're gonna set 0.5f as shadow ambience lighting
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB, 0.5f);

Anyway dunno how it's when you've got just color and no textures (I tested that just with textures), so this could be in that (but I don't know that surely).

Share this post


Link to post
Share on other sites
Mmm, thats strange. Thats exactly what I'm doing Vilem, weird. I do have a GL Invalid Enumerant Error which could be the problem, I'll look into the lighting, I do have ambience and diffuse set up I'm sure.

Thanks
neutrinohunter

Share this post


Link to post
Share on other sites
I have the above. Is this needed?

glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);

Am setting the lighting as such:


GLfloat ambience [] = {0.4, 0.4, 0.4, 1.0};
glLightfv(GL_LIGHT0, GL_AMBIENT, ambience);
GLfloat diffuse [] = {0.4,0.4,0.4, 1.0};
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
GLfloat specular [] = {0.3,0.2,0.3, 1.0};
glLightfv(GL_LIGHT0, GL_SPECULAR, specular);



Are there any other lighting operands which need to be called? And thanks Vilem, you have been fantastic with all your help so far. Hows the paper coming along?

Neutrinohunter

Share this post


Link to post
Share on other sites
Maybe I've got something - just played a little with GL_ARB_shadow and GL_ARB_shadow_ambient (and with SGIX variants!). There are 2 errors, which I found:

1) You can't combine GL_ARB_shadow and GL_SGIX_shadow_ambient, or GL_SGIX_shadow and GL_ARB_shadow_ambient.

2) This is important, you've to set this glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB, 0.5f); as glTexParameterf (that "f" in the end is very very important, cause it's telling that value will be float, if you'd use glTexParameteri with "i" in the end it wouldn't work).

EDIT: I presume you've got GL_ARB_shadow_ambient supported by hardware, cause this could make issues too.

Share this post


Link to post
Share on other sites
PCML Shadows? Never heard of them, I'll google to see if I can find anything on them.

Well I'm using GL_ARB_Shadow, GL_ARB_shadow_ambient and using FBO's to render to.

All of which are supported by my GeForce 6200 GC. My loading of the texture is as such, which seems to work fine but I'm guessing it could be a parameter i'm missing or conflicting?

[source lang="cpp] glGenTextures(1, &ShadowTexture);
//glEnable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, ShadowTexture);
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
#if defined(GL_ARB_SHADOW)
std::cout << "ARB Shadow Available" << std::endl;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB,
GL_COMPARE_R_TO_TEXTURE_ARB);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
#endif

#if defined(GL_ARB_shadow_ambient)
std::cout << "GL_ARB_shadow_ambient Available" << std::endl;
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB, 0.3f);
#endif

std::cout << "Frame Buffer Object Available" << std::endl;
glGenFramebuffersEXT(1, &ShadowFBO);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, ShadowFBO);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_RENDERBUFFER_EXT, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
GL_TEXTURE_2D, ShadowTexture, 0);

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);



Did you test with a texture on the floor? Because I'll change that if thats the case.

Neutrinohunter

Share this post


Link to post
Share on other sites
PCML shadow maps are my algorythm (shortcut = PCMLSM). Anyway I've gotta look on that code....

That code should run properly, I haven't noticed any issues on my Radeon HD 2900 XT with these extensions, could you please send me program (executable for Windows XP - win32, maybe even source, if you're able to send it (email - vilem.otte@post.cz) - can't exactly tell, where could be issue - it was long time ago, when I used just Fixed function and no shaders). Anyway I tested with and without texture, so there souldn't be problem.

[Edited by - Vilem Otte on February 18, 2008 4:04:09 PM]

Share this post


Link to post
Share on other sites
I'm in the process of sending you an email, if that doesn't send (the src is nearly 5MB, class which is of interest is JShadowMappingAlgorithm.cpp though)

I've made the executable available from my website at www.jmecoding.com/Release.zip, should be uploaded in about 5 minutes.

Thanks very much Vilem, I just hope to god its not a driver issue otherwise I will go crazy!

Neutrinohunter

Share this post


Link to post
Share on other sites
I think its possible with another render pass, because thats how the tutorial at paulsproject.net works because he doesn't use GL_ARB_shadow_ambient.

I actually think I've got some code somewhere just in case it didn't work commented out (doh!). I'll have a try when I get back in, it was an all nighter at work, so will have a think while I'm travelling.

You said ATI cards don't have billinear filtering, is there an alternative than GL_NEAREST for targeting those cards? Your pictures of your shadows look beautiful, so I can't assume your using that filter. Again, correct me if I'm wrong.

Thank you very much for testing out the application, you have been very generous with your time and knowledge :) For now, I'll see if theres a driver fix or its a bug with my GC.

Just a quick question (isn't there always :)), how did the application run, did it crash/use up too much time/figure it out easily?

Maybe this'll sound crazy, but your app running ok (with shadow mapping)

Yeah its crazy it works on everybody elses machine and not mine! And thats not just the shadows :P

Thanks
Neutrinohunter

Share this post


Link to post
Share on other sites
Well, I found a way how to solve shadow mapping and ambient lighting WITHOUT extension :). It's multi pass algorythm (who'd expected that?) - 2 pass.

1. Pass - render scene into texture WITHOUT shadow mapping and without lighting (so everything would be in full colored texture or full color).

2. Pass - render scene normally (this means with lighting and with shadow mapping), then draw one fullscreen quad blended additively into rendered scene. And voilá - shadows and ambient lighting running without extensions :)

There's alternative for ATi cards, it's hand-coded linear filter in X and Y direction of texture (so it's bilinear filter), but i don't know if it's possible without shaders (I'm doing it using shaders). I'm using PCML shadow mapping filter, which uses bilinearly filtered shadow maps - but there's way to use bilinear filtered shadows using variance shadow maps (they've got several disadvantages, but much more advantages - and the major advantage is speed...). Anyway to your app - it crashed several times, Stencil shadows weren't working (Stencil shadow volumes), but that all can be fixed ;). Don't know why it doesn't running properly on your PC, but I can test that on several other PCs if you want.

Share this post


Link to post
Share on other sites
Yeah, the stencil shadows was working till I started messing with it :) Was trying to remove the stipulation that it could only work for closed objects, now it doesn't work :P

Yes, I thought it might. Its quite unstable in its current configuration, thats my job for today.

If you have an NVIDIA card that might be useful to know its specs/drivers so I can make a comparison on them and see if I need a particular driver to make it work. (You never know). If so I'd be very grateful if you could.

Thanks, I'll try adding the multi pass code in and get back to you.

Any idea what the errors were? I'm assuming you got something like "Access Violation 0xC00000005", looks like I've got a rogue pointer somewhere [rolleyes]

Yeah, I've seen people implement bi-linear filters in one of my books on the shelf, so I'll check on that.

Thanks, Neutrinohunter

Share this post


Link to post
Share on other sites
Thanks, Vilem.

Have managed to get a similar effect like you said using additive blending on a quad, so far I am unable to see why the GL_ARB_shadow_ambient extension doesn't work for NV cards, but thats a minor detail anyhow.

Have got an implementation that I'm happy with I just need to sort out problems with having textured objects in the scene because so far I get my model textured by the shadow map rather than its texture, no matter if I set two texture units up.

Neutrinohunter

Share this post


Link to post
Share on other sites
i think this is the line that is causing your invalid enumerant

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB, 0.5f);

but unfortunately i dont know how to correctly use this compare_fail_value. anyone?

Share this post


Link to post
Share on other sites
Maybe its a driver issue which is causing the problem, it seems to work on ATI cards at work and on Vilems computer.

If anyone does have a NVIDIA card which supports GL_ARB_shadow_ambient would they like to give me the specs of their card and drivers *please* :)

Update, currently I seem to have corrected the texture unit problems and so I get images such as these, the animation seems to ruin the Shadow Map effect though. Notice the artefacts around the seams of the polygons, biasing problem or polygonal?



Anybody have any suggestions? Or is just the model's lack of continous features/polygons :)

Neutrinohunter

Share this post


Link to post
Share on other sites
Thats biasing problem (issues at polygons with angle to light close to 180°). Well, first soulution is using bigger shadowmap with high precision (hdr textures), or some magnification filter should work.
Anyway if you're gonna lit that model with just direct illumination, biasing artefacts should be less visible.

Share this post


Link to post
Share on other sites
I'm using a magnification filter of GL_LINEAR on this and the shadow map texture is 2048 with an FBO, is it likely there is something wrong with the setup in that case. Really wish I could use shaders to do this, it seems like it would have more versatility. Might be an option later on down the line I suppose, want to learn GLSL and CG.

As for the illumination, there will only be spotlights of around about 30-60 field of view but I'm sure thats what the app has it setup as anyhow.

I'm gonna try putting in a lightmap texture to see if that helps with the realism.

Neutrinohunter

Share this post


Link to post
Share on other sites

This topic is 3585 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this