Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Stencil shadows show on the back faces of solid objects

Author
Message
Pixel Perfect
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: UK
Posted: 10th Apr 2008 01:08
Can anyone explain why if a solid object is swept by a stencil shadow cast by another object the shadow appears on the back face of the object as well as the front (the one facing the shadow). It's as if the solid object is transparent to shadows.
Surely this can't be right as the illusion of shadowing is ruined rendering the built in dynamic shadowing totally useless.

Is there any way of preventing this?

Also ... what happened to the extended syntax present in the DBPro command Set Shadow Shading On which appears to enable you to substitute a simpler mesh for shadow generation? It appears to be completely missing in DGDK!

Any help would be appreciated as it's getting frustrating now!

No matter how good your code is, someone will improve on it
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 10th Apr 2008 16:23
That is a common symptom when using infinitely thin (2D) polys in 3D applications. Backfaces are really not supposed to be seen in a 3D application. The troubles this has caused over the years is alot more than what you, or I experience. They actually don't really exist. I'm not surprised that they cause problems.

I was reading QIII source, and it had to be patched because you could see lights turn on in areas that were occluded only by this sort of polygon. Now, there are no 2D surfaces with the backface visible. Besides, it wreaks havoc with the visiblity culling in bsps.

I suppose you could give the poly some depth, or try culling, but I imagine that both are not really acceptable in your application.

I don't know of any other answer, however.
Sorry.
Pixel Perfect
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: UK
Posted: 10th Apr 2008 22:06
Thanks for the reply jinzai. Maybe I'm misunderstanding what you're saying or maybe I misled you by using the term back face. The objects which are exhibiting this effect are true 3D meshes with depth.

I've attached a screenshot demonstrating this. As the sun moves behind the tree it casts a shadow of the tree before it which sweeps across the standing stones in front of it. The camera is positioned behind the stones and in real life the shadow would not be visible on the rear faces of the stones (it would be masked by the stones) ... yet it clearly is! This is much more noticeable when watching the shadow sweep in real time.

Nothing I do seems to stop this behaviour which just destroys the illusion of true shadowing!

No matter how good your code is, someone will improve on it

Attachments

Login to view attachments
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 10th Apr 2008 22:27
Yes, I did misundertand. Sorry. But, does increasing the depth have any affect on that? Man, that is annoying! Maybe something to do with z depth on the stones?

btw, what is that GDKHenge? Looks pretty cool.
Pixel Perfect
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: UK
Posted: 10th Apr 2008 22:37
lol ... yeah kind of! It's a modified version of some demo code I found by 'spooky' showing dynamic lighting in DBPro in action. The demo graphics were very basic so I added some texture, foilage and a tree and some color cycling turning the sun red as it drops on the horizon. It it was only then that I noticed the unfortunate side effect on the back faces of the stones. Damn shame as the dynamic lighting and shadowing it produces looks well nice and its reasonably fast too. But unless I can find a solution to the back face shadowing then it's a non starter just when it was looking so promising!

I'll have a play with the z-order to see if I can gleen any more insight but I've always found that a bit hard in DGDK, we don't seem to have much control over it!

No matter how good your code is, someone will improve on it
Pixel Perfect
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: UK
Posted: 11th Apr 2008 10:32
I can confirm incresing the depth of the stones makes no difference. The shadows still display on the rear faces regardless of depth.

No matter how good your code is, someone will improve on it
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 11th Apr 2008 12:39
The shadows go thru any object that doesn't has 'dbSetShadowShadingOn' set on it.

Setting shadows on for an object, will turn the back side of the object darker with its own shadow, making impossible to tell if more shadows are overlapped thru it or not.

Therefore the solution is (or should be) to turn shadows on for all those blocks at your pic.

However I see they cast shadows too, so perhaps you should play (if available) with :



Whatever needed until you get the self-shadow of the blocks darkening its back side.
Pixel Perfect
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: UK
Posted: 11th Apr 2008 14:30
Thanks for your input Morcilla. As I think you have already deduced, dbSetShadowShadingOn is enabled for the stones and probably would darken the back face however the ambient light level is increased gradually as the sun rises (light 0) to emulate day night cycling which of course lightens the stone faces.

I could remove the ambient light and the dark back faces would probably mask the shadow leak but then I'm back to unrealistic world lighting during the day cycle.

Relying on the back face to be in shadow to mask other shadows appearing doesn't seem to be a very usefull device as in most real world situations you wouldn't get this.

Unfortunately, the extended syntax for dbSetShadowShadingOn is not available in DGDK. I did try that in DBPro and it made no difference unless you reduced the range to the point where the tree shadow failed to reach the stones which negates the whole purpose as it makes the shadows look unrealistic again.

I don't believe the dbSetShadowPosition command is available either but I'm currently at work so I'll check on that when I get home.

What I'm not sure of at the moment is how the stencil shading is implemented. Is this actually done as a post rendering process on the graphics card itself or is it implemented as part of the DB rendering engine ... if that makes sense?

No matter how good your code is, someone will improve on it
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 11th Apr 2008 18:37
You may leave the ambient light as you wish. It doesn't modify shadows effect itself.

Quote: "Relying on the back face to be in shadow to mask other shadows appearing doesn't seem to be a very usefull device as in most real world situations you wouldn't get this."


I could agree, even with that, the result is not that bad.

If you cannot position the shadow properly, then I suggest using this technique as workaround:

- For each object that should cast shadows, create another -twin- one. Usually with less-poly count, something like this:



Then make this twin object to be the one that cast shadows:




And hide that twin object using -limb- commands:



That is, instead of setting shadows on the 'real' object, cast shadows on the hidden twin.

- Now, each loop, position the twin object somewhere along the sun-object vector, until you get the self-shadow applied:



This tip can also be used to obtain fast shadows and better performance, using a low-poly mesh for the hidden object, and therefore casting low poly shadows.

Quote: "Is this actually done as a post rendering process on the graphics card itself or is it implemented as part of the DB rendering engine "

Both things make sense, don't they? It is a two-pass rendering using stencil buffer, and it is implemented thru the dbSetShadowShadingOn function
Pixel Perfect
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: UK
Posted: 11th Apr 2008 20:25
Morcilla ... thanks a lot. That's really helpfull and I can see that working. I will try that out tonight.

I was always planning on replacing any large poly meshes with simpler ones for shadowing purposes until I realised that the extended parameters for the dbSetShadowShadingOn command were missing in DarkGDK. Your suggestion gets round this with little extra work!

By the way, I checked the include file for the dbSetShadowPosition command and it is indeed missing in DGDK. I'll try that in DBPro though to see if a solution is achievable using that.

With regard to the rendering process, thanks for the clarification. I really need to learn more about the rendering pipeline so I understand the processes and concepts better.

No matter how good your code is, someone will improve on it
Pixel Perfect
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: UK
Posted: 12th Apr 2008 04:20
Just one slight problem with this strategy ... hidden objects do not cast shadows so can't be used to provide the self shadow.

I can position the cloned object in the same position and scale it slightly down and this works but leaves a fringe effect. But it's a big improvement on what was happening previously.

However, I'm starting to conclude that the DarkBasic stencil shadow functionality is only going to be visually effective (believable) when used with a single light source i.e. the one generating the shadows. Inside small volume rooms and other confined spaces it would be ideal, but outside scenes I can't see working as it's going to be too difficult to effectively mask everything given the need for a certain level of ambient lighting.

I think I need to start exploring some alternatives.

No matter how good your code is, someone will improve on it
Pixel Perfect
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: UK
Posted: 12th Apr 2008 12:03
I now have it working ... thanks again Morcilla

As the twin object can't be hidden I made it transparent so it can't be seen. Combined with your vector code to provide a suitable displacement it worked a treat!

If you want the shadows on the front faces as before (those facing the light source) then you have to set shadowing on both objects, which is a shame as that now means my higher poly objects have to cast shadows.

If I'm going to use this in real game levels I would really need the extended syntax available in DGDK as it is in DBPro. I could then substitute the target object mesh for a simpler one which would of course be the one used to create the twin, rather than cloning the original object as we are doing here.

Guess I'll have to log a request for this to be available in the next update. Also found the dbSetShadingOff(ObjID) command is in the include file but not available in the library. You just get an unresolved external symbol error when linking!

Attached screenshot shows the simple demo working correctly

No matter how good your code is, someone will improve on it

Attachments

Login to view attachments
Pixel Perfect
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: UK
Posted: 12th Apr 2008 22:43 Edited at: 12th Apr 2008 22:45
Here's a video (low res) of the day night cycle with dynamic lighting and shadows in action:

http://www.youtube.com/v/5CrjQ8UpbY4

No matter how good your code is, someone will improve on it
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 14th Apr 2008 14:35
Spectacular
Glad you got it working, that video looks good

I agree those missing commands should be added in an update, let's see when TGC comes with it.
Pixel Perfect
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: UK
Posted: 14th Apr 2008 20:31
Thanks Morcilla.

Quote: "I agree those missing commands should be added in an update"

Yes, I've logged one as a bug and asked for the missing ones to be made available in the same post. Had no other choice seeing that we currently have no dedicated TODO thread for DGDK unlike the stickied one for DGDK.NET. Maybe we should start one!

No matter how good your code is, someone will improve on it

Login to post a reply

Server time is: 2024-09-29 17:27:31
Your offset time is: 2024-09-29 17:27:31