# 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.

## 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 on other sites
Try one of these two extensions

##### 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 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 hardwareglTexParameteri(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 lightingglTexParameterf(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 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 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 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:

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 on other sites
To that paper - well I've written just several lines, now preparing demo to demonstrate effect of PCML shadow maps ;) - anyway I have to work primarily on the engine, I'm writing that paper in my "free-time".

##### 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 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 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 on other sites
Maybe this'll sound crazy, but your app running ok (with shadow mapping) - it's not black (it's "blended" into colors of sorrounding enviroment). I haven't got property linear filter, cause I've got ATi card (and it's not giving bilinear PCF by hardware).

Image:

##### Share on other sites
Looks like its an NVIDIA bug then :(

Doesn't ARB mean it should be supported across all GCs?

How could I achieve the same effect? Another render pass?

Neutrinohunter

##### Share on other sites
Well, that should be possible in several ways, i'm gonna to look at that today later (afternoon) ;) - I need some sleep and it's around 1 AM - oh almost morning again :D - here in Czech Republic (GMT+1)

##### 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 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 :)

##### 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 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 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 on other sites
I believe that is what I used and it worked fine. The value appeared to scale each fragments colour between the full un-shadowed colour and black.

##### 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 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 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 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.

## 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