Author Topic: projective/shadows on UV+ENV objects  (Read 13464 times)

Offline Klaudiusz

  • int
  • **
  • Posts: 75
    • View Profile
projective/shadows on UV+ENV objects
« on: October 22, 2007, 10:11:19 am »
Hi,

I'm using many objects with UV and ENV mapping together (two stages). I want to use also projective textures or self-shadowing, but seems like it's possible to use only with UV or only with ENV... Can i do something with this?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: projective/shadows on UV+ENV objects
« Reply #1 on: October 22, 2007, 10:17:32 am »
Maybe your hardware doesn't support more than 2 texture stages. In that case, adding a third one (for shadows) won't work. But then again, a hardware that has this limitation shouldn't be able to do the shadows anyway. Which hardware is this and what does the renderer prints out about the number of available stages on init?

Offline Klaudiusz

  • int
  • **
  • Posts: 75
    • View Profile
Re: projective/shadows on UV+ENV objects
« Reply #2 on: October 22, 2007, 10:53:55 am »
No, my graphics cart support it, OpenGL renderee has been initialised correctly:

Code: [Select]
Driver is: idisw2km/2.50.4136.2000 on Intel / Intel 915G
FBO not supported or disabled!
OpenGL renderer initialized (using 4 texture stages)

Seems like first projective texture is forced to second stage... whatever i have on second stage (i've used also Config.glForceEnvMapToSecondStage to check it) it is replaced by projector.

Shadows also works here but also i can't shadow object with env+uv. Shadows has differend behaviour as on ATI. I'll post it later.

« Last Edit: October 22, 2007, 11:01:50 am by Klaudiusz »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: projective/shadows on UV+ENV objects
« Reply #3 on: October 22, 2007, 11:52:30 am »
No, it's not forced to the second stage. It will be added to next free stage (excluding the first). Maybe you are initializing the shadows before setting your own texture information?
« Last Edit: October 22, 2007, 12:38:49 pm by EgonOlsen »

Offline Klaudiusz

  • int
  • **
  • Posts: 75
    • View Profile
Re: projective/shadows on UV+ENV objects
« Reply #4 on: October 22, 2007, 12:35:33 pm »
Yes, You right. Works fine. Thanks:)

Offline Klaudiusz

  • int
  • **
  • Posts: 75
    • View Profile
Re: projective/shadows on UV+ENV objects
« Reply #5 on: October 22, 2007, 08:14:11 pm »
One more question. Shadow, as a next texture stage has as i suppose TextureInfo.MODE_BLEND mixing mode? I think so because only one texture is shadowed. Could You add TextureInfo.MODE_MODULATE? It makes darkness all texture stages.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: projective/shadows on UV+ENV objects
« Reply #6 on: October 22, 2007, 09:28:24 pm »
It is MODE_MODULATE, which is what it has to be because of the way the shadowing works. The shadowing renders the scene twice. The first pass happens with ambient lighting only, the second with full lighting but limited to the parts that are not shadowed determined by a render time depth level comparision between the shadow map and the pixel to draw. I don't see how a stage can be excluded from this process except when using ambient lighting only doesn't affect the look of that stage for whatever reason.
Maybe you can post a screen shot that illustrates the problem?

Offline Klaudiusz

  • int
  • **
  • Posts: 75
    • View Profile
Re: projective/shadows on UV+ENV objects
« Reply #7 on: October 23, 2007, 08:19:37 pm »
Sure, i can post the screenshots. Please take a look:

1. UV only: one texture, everything is ok



2. ENV only: one texture, ok



3. ENV(first stage)+UV(second stage) with MODE_ADD, there is no black shadow :(



4. UV texture with black dots, just to show You the texture on the object:




5. The same as in point 3, so ENV+UV(MODE_ADD) + UV white texture with black dots(3th stage)MODE_MODULATE



As You can see the shadow on the object should be black, but it's not. The black fragments of texture on 3th stage with MODE_MODULATE are black, but shadow not....

I've checked it and this is for sure not MODE_BLEND...i don't know why the shadow is not covering the firt texture...  Maybe could You do something with this?


Everywhere the same parameters,the ambients colors:
world=(50,50,50)
shadow=(5,5,5)

« Last Edit: October 24, 2007, 09:10:25 pm by Klaudiusz »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: projective/shadows on UV+ENV objects
« Reply #8 on: October 23, 2007, 10:52:50 pm »
My best guess is, that this is related to this: http://www.jpct.net/forum2/index.php/topic,924.0.html, which relates to  http://www.jpct.net/forum2/index.php/topic,853.msg5377.html#msg5377. Does it work when adding the env-map with MODE_MODULATE? If so, we have to think about a possibility to exclude the env-map from the shadow pass...maybe by using a kind of callback from the helper before and after the shadow pass...i'm not sure... ???

Offline Klaudiusz

  • int
  • **
  • Posts: 75
    • View Profile
Re: projective/shadows on UV+ENV objects
« Reply #9 on: October 24, 2007, 09:19:02 pm »
First of all i corrected my last post, because ofcorse ENV was on first stage and UV on second.

I discovered that there is problem with secoud stage only. For example the same situation as in point 3 of my previous post:

ENV+UV. ENV forced to second stage:



As You see, now only UV map discovered.




And one more thing, because it make's me stupid:

There is something wrong with trasnsparentions. The same situation as above but the object has setTransparency(255)



It's funny, i don't know why one part of shadow dissaperd and second part not:) Maybe You know?

Offline Klaudiusz

  • int
  • **
  • Posts: 75
    • View Profile
Re: projective/shadows on UV+ENV objects
« Reply #10 on: October 24, 2007, 09:47:12 pm »
OK, i know. No matter what is on 2,3,4... stages. You are calculating the shadow only for first stage. If fist stage has black texture, shadow won't be calculated.

But i still have no idea why is the problem with transparention.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: projective/shadows on UV+ENV objects
« Reply #11 on: October 24, 2007, 10:27:31 pm »
OK, i know. No matter what is on 2,3,4... stages. You are calculating the shadow only for first stage. If fist stage has black texture, shadow won't be calculated.
No, i don't. As mentioned, the scene is rendered once with ambient only and a second time with all lights enabled. I don't care about how many stages are being used as long as there is one left for the shadow map. I still think that this is simply caused by blending mode you are using to combine UV and ENV. Have you tried to use a modulate mode?
The transparency problem may have something to do with the alpha channel, which is used for the mapping process of the shadow. I'll write myself a simple test case to verify these problems.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: projective/shadows on UV+ENV objects
« Reply #12 on: October 24, 2007, 10:54:43 pm »
Ok, i've written myself a test case. The problem with the missing shadow (or not really missing, but "limited"...) definitely comes from the effect that i've described in the linked thread ealier. It's caused by the MODE_ADD, because when doing an ADD, the color blending doesn't count. color*first*second is 0 when color is 0, but color*first+second is second, when color is 0. That's what you are getting: The second stage in all it's glory. It would look exactly the same if you weren't doing any shadows at all and just disabling the light sources so that the scene should be black...but it won't be, which is also mentioned in the linked thread. Possible solutions to this:

a) don't use add but another mode (modulate)
edit:a.1) automatically revert from add to modulate only when doing the shadow pass...i'll try that...
b) somehow disable the added stages with doing the shadows. This is currently not possible and maybe not really helpful, when doing shadows with another color than black (or almost black)
c) Detect (or force) a black-shadow-only-mode and don't do the first pass at all in that case. But this will have some other drawbacks...i think...maybe it's worth to think a little more about it.

About the transparency: I can't reproduce this problem in my test case. When setting my objects to transparent, it looks exactly like it's supposed to look. I'm not sure what you did to create this effect. Maybe you can provide a test case for me that shows it?
« Last Edit: October 24, 2007, 11:02:50 pm by EgonOlsen »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: projective/shadows on UV+ENV objects
« Reply #13 on: October 24, 2007, 11:27:06 pm »
You can try this: http://www.jpct.net/download/beta/jpctapi116.zip
It adds an option to the ShadowHelper to revert additive to modulate blending in the shadow pass. It should help a little.

Offline Klaudiusz

  • int
  • **
  • Posts: 75
    • View Profile
Re: projective/shadows on UV+ENV objects
« Reply #14 on: October 24, 2007, 11:37:13 pm »
That's truth.... MODE_ADD was the reason :-\.... I'm sending the example. Please check the mail.