Skip to main content
gamedev.net
🔒 Locked

Simultaneously Shadowmapping and Texturing

Started by Geometrian 10 replies 1.5k views
Original Post
Geometrian
Geometrian
Hi, The problem here is not shadowmapping nor texturing, but doing the two together. The shadowmapping algorithm I have renders to a texture (obviously) and uses the texture to make the shadows. It works in three passes--one to generate the appropriate texture matrix, one to render in light, and one to render in shadow. The problem arises when trying to combine the two. The shadowmapping works fine when using color materials, but it does not work at all if any of the occluding or shadowed objects are textured. (This means, by the way, that the program runs, I just don't see any shadows). My guess about this is that when the object's texture is bound to, the shadowmap is unbound. That means that the shadowmap is no longer available to be used for shadowing, so no shadows appear. So, what is a workaround to this? Thanks, G
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]
megatron242
megatron242
Did you check your blending function?

Btw, if your problem is multi texturing (which I don't think it really is), you can use GL_ARB_multitexture to bind several textures.
Geometrian
Geometrian
Yes.
It is first set with:
glBlendFunc(GL_SRC_COLOR,GL_DST_COLOR)glEnable(GL_BLEND)
then disabled with:
glDisable(GL_BLEND)glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
Here's what I get visually:
Texturing and Shadowing
The demo draws that object shadowing the landscape. The fish texture is supposed to be mapped over the landscape itself, but instead, it is being used as a shadowmap, perhaps?

The object and light are moveable, and the light's view always centers closely around the object. Moving either moves the fishes over the map.

G
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]
megatron242
megatron242
I think you should set

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

before the blending.
Geometrian
Geometrian
That doesn't work either. Basically I see the same thing, but now the texture is darker (opaque).
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]
Lord_Evil
Lord_Evil
Assuming the first texture is the diffuse map (actual texture), the second is the shadow map and you want the final color to be tex1 x tex2, you could use glBlendFunc(GL_DST_COLOR, GL_ZERO).

The blending equation is colorsource*factorsource+colordest*factordest so using factorsource = GL_DST_COLOR and factordest = GL_ZERO would result in the final color being multiplied with the shadow/light map (dark areas being the shadows).
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Geometrian
Geometrian
That doesn't work either--but again, I think the problem is using the shadowmap and the diffuse texture simultaneously. I need to have both going together. How do I do that?
Thanks,
-G
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]
Lord_Evil
Lord_Evil
Does your lighting pass work with textures, i.e. do you have correct shading?
Do you disable texturing for the shadowmap generation, i.e. is the shadowmap gray scale?
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
aresio
aresio
I met the same difficulty, and solved with multitexturing.

I just put the shadow map in the last texture unit, and everything works fine.

http://img151.imageshack.us/img151/315/aresiosmallwu3.jpg
Geometrian
Geometrian
Thank you.
As far as disabling textures for the shadowmap generation--I don't see how that is possible, as the shadowmap is itself a texture...
I think you're right about solving this with multitexturing. I think I can figure out how to work multitexturing into the shadowmapping algorithm if I knew how to do multitexturing. Anyone have good examples of multitexturing (not using shadowmapping)?
Thank you,
-G
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]
aresio
aresio
it's quite simple, conceptually.

there are N texture units on your videocard (can use OpenGL primitives to enumearate them).

you can assign textures to them by using

glActiveTexture (GL_TEXTUREn); // change n with the texture unit number you want
glEnable (GL_TEXTURE_2D); // from here on it's the common texturing code you already know
...



In SM, the third pass is, usually, when you need multitexturing. I do it this way (pseudocode):

glAlphaFunc(GL_GREATER, 0.99f); glEnable(GL_ALPHA_TEST); activeTextureUnit(LAST_AVAILABLE_TEXTURE_UNIT);setupShadowMapTextures(); // tex genactiveTextureUnit(0); // can be anyone but LAST_AVAILABLE_TEXTURE_UNITsetupObjectsTextures();turnOnLights();drawPrimitives();



edit: I forgot mentioning you must specify your (multi)texture coordinates using glMultiTexCoord2f().

[Edited by - aresio on October 14, 2008 6:08:39 AM]
Geometrian
Geometrian
I feel foolish. I can't seem to get it working. I don't really know how to implement the multitexturing at all in shadowmapping, although from the look of it, it should be simple.

I know people aren't very receptive to downloadable code, but I think the only way to fix this is to actually work with the code we're talking about. Here it is: http://www.geometrian.com/1.5.2.zip. The shadow file is "10 -- ShadowExample.py" and the shadow functions file is "OpenGLLibrary/glLibShadow.py"

Please have a look at this; I think it will make discussions much easier.

Thank you so very much,
Geometrian
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.