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 / Shadow Mapping

Author
Message
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 13th Aug 2009 14:32
Hey people!

This is my first post here! TGC FORUM ROCKS!!!
I've been using this forum as a source for information on darkgdk for about half a year now and i check what's new in the tgc world on an almost daily basis...

So, i have to contribute something to this forum. i converted Evolved's Shadow Mapping Example to DarkGDK, because i need the ultimate method of shadowing for my current game. It's attached to this post. (media included)

But i have a problem with it! Everything runs well and fluid on my old laptop, but something doesn't work right with the shader. Everything seems to be shaded in grey! (looks like the objects are textured with the depth-test image)

Screenshot:


And when i play around with, i can see something like a 'normal' textured image of the scene in the background, when i press '1'!

Screenshot:


Can this be a hardware problem? i've tried it on another pc and it's the same! i use the newest update of the GDK.
How is this working for you guys?

Attachments

Login to view attachments
prasoc
16
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 13th Aug 2009 15:45
Thats what I see as well. It is really strange :S


Your signature has been erased by a mod
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 13th Aug 2009 16:23
Yes, getting nice shadows to work in darkgdk gave me serious headaches
But the good news is:
I finally got it to work!!!

Screenshot:


YEAH! looks nice - and i got a decent frame rate, too.
I tried a few things and all i did to get it to work was:
- swapped the two "dbSyncMask"-commands in lines 168 and 174

does this work for you too?
heyufool1
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 13th Aug 2009 19:14 Edited at: 13th Aug 2009 19:16
Oh dude that awesome! Thanks so much for this code! And yes the swapping of the dbSyncMasks made it work . You certainly made a good contribution

Constant 59 FPS unless I change textures then it drops down but comes back up to 59.

Use Google first... it's not rocket surgery!
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 13th Aug 2009 19:23
thanks! i am also so incredibly happy about this!
you can't imagine how many articles about Shadow Mapping i've read in the past days... and nothing worked! and now i end up with this stunning shader!
My next step would be to put the main instructions for this into functions, like 'SetupShadow ( int object )' and 'UpdateShadow ( int object )'. So it would be usable across different projects.
I think shadows are very important for 90% of game scenes!
heyufool1
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 13th Aug 2009 19:42 Edited at: 13th Aug 2009 20:05
The functions would be great! But I have a problem. When I try to put it in my project, I got and
Quote: "unhandled exception at 0x4fe55be1... Access violation reading location 0x00000028"

It points to this line of code:

followed by:

No syntax errors or linker errors though

I fixed it by loading the effect to use default textures but if I do that it doesn't work right. (no errors though)

Use Google first... it's not rocket surgery!
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 13th Aug 2009 21:18
looks strange! may be you should check if none of the IDs (images, effect,...) are in use by your code.
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 13th Aug 2009 22:10
ok people, i've finished the functions!
now we can use Shadow Mapping in multiple projects with ease!

Functions:

SetupShadowMapping
SetObjectShadow
UpdateShadows
SetShadowMappingLight


The required files are attached, complete with an example.
Cheers

Attachments

Login to view attachments
Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 14th Aug 2009 00:54
Nice work.

Is the shadowmapping shader evolved's ?

Ive got a demo of depth shadow mapping here(using evolved's shader) and generating the jittermap and shadowmask image procedurally(which I added to control the softness, more jitter = softer shadows to a certain point lol and the shadowmask is adjustable, just a white image with a thin black border really lol)

Anyway, just thought I'd ask which shader you are using, ill stik my demo code up in my shader thread when I get a chance.

Good job with this, looks like you made it easier for people to setup shadow mapping

If it ain't broke.... DONT FIX IT !!!
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 14th Aug 2009 01:25
thanks for your kind words!
i hope this will be as useful for others as it is for me right now.
Up to now i have not run into major bugs with it...

Yes, it is Evolved's shader, he has done great work!
If i could i would probably write my own, but after i've read through some articles about Shadow Mapping, i have to admit that it is just too much for me right now. I understand the principles, but the coding part gives me headaches!
And since i got this to work, i can return to focus on gameplay again

Looking forward to see your demo!
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 16th Aug 2009 12:09
Thank you very much for making this available!
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 16th Aug 2009 15:42
no problem! i'll upload a new version soon, with a bit of optimization...

does anybody have an idea how shadow mapping could work with a directional light? i'm trying to achieve a Sun-like effect...
do i have to use a different shader or could this be done in another way?
Xenocythe
19
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 17th Aug 2009 00:35
All I get is a blank screen, with a good 80-90 framerate. Is it because my graphics card is old?

My graphics card is definitely shader compatible... but I guess this shader is 3.0 or something.


Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 17th Aug 2009 01:12
Evolved's unmodified depth shadow mappin shader is ps/vs2.0 ... Most cards these days support it.

Have a look at some of the examples in this thread :

http://forum.thegamecreators.com/?m=forum_view&t=152491&b=22

If you have the same problem with some of those then I would have to say it is your system. Check graphics driver's are upto date is all I can suggest.

What graphics card do you have ? It could always be a hardware conflict if you have a slightly older or less mainstream card..

If it ain't broke.... DONT FIX IT !!!
sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 17th Aug 2009 04:18 Edited at: 17th Aug 2009 04:45
Quote: "does anybody have an idea how shadow mapping could work with a directional light?"


A directional light is just a simplified special case of a spotlight.
The shader should be simpler and faster for this sort of usage if done properly. I would imagine there must be a number of shaders available on the internet that can be applied if one looks around.
Not if ..... but when you solve the problem, please let the rest of us know of the solution. Your other sample using SetupShadowMapping, SetObjectShadow, UpdateShadows, SetShadowMappingLight, is a great way of presenting the material. Thanks for that.

EDIT: some interesting reading http://en.wikipedia.org/wiki/Shadow_mapping
Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 17th Aug 2009 05:15 Edited at: 17th Aug 2009 06:35
I get the black screen too. My video card has the latest driver and can do DX10 shader 4.0 stuff. I'm trying to see what's going on. In debug mode, when exiting the program, the visual studio debugger gives a runtime error saying this:

Run-Time Check Failure #2 - Stack around the variable 'Light' was corrupted.


not familiar with shader stuff yet... but looking...

Edit: Just ran evolved's dbpro version... it worked good. Now to compare...

Edit: The corrupted stack around var light is wierd to me. In release mode i dont get that runtime error. It happens when I exit the program. I used new and delete to create the Light array and I dont get that error anymore in debug mode. But, I still have a black sceen. I'll try porting evolved's dbpro code directly to see if I gets the same problem. It is wierd it works for some and not for others... As I too would love to be able to use shadow mapping.

_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 17th Aug 2009 16:52
hmm, don't know about the 'corrupted stack around var light', i've never seen an error like this!
what light array are you talking about? the shadowmapping in my demo just works with a single light. are you trying to set it up for multiple lights?

@sydbod: thanks, i've read through the article. i know that shadowmapping for a spotlight works with a perspective projection matrix. to set up a directional light it needs an orthographic projection matrix. that's about the theory... now i just need to figure that out for my code

does anybody have experience with the command 'dbBuildOrthoLHMatrix4' ???
Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 19th Aug 2009 08:18 Edited at: 19th Aug 2009 08:21
I just compile and run your code as is and I get the black screen.

I got the DBPro version from Evolved's site:
http://evolveduk.googlepages.com/Shaders_Shadowing.html
Shadowmapping.zip

I converted that to DGDK as close as I could.

The DBPro version runs 100% perfect for me.
But this DGDK version gave a black screen too.

So I did the dbSyncMask switch and then I can see stuff. It's not exactly what the DBPro version displayed as though. I think the dbSyncMask should not be switched. Because, the code below will not show the normal mapping on the textures and the shadow mapping is all funky... almost like it's reversed or something. I have the picture I get with below code attached.

This is as far I can go as I don't know how to proceed with shader stuff. I need a while to learn it so I can properly debug it. :

I would love to see it work though.

Note: I do have double slash in my paths to the media directories. This forum kills the slash for some reason... see if I can fix it...



Attachments

Login to view attachments
Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 19th Aug 2009 11:03
@Todd, I have a GDK version of evolved shadow depth mapping working perfectly here, ill post it up in my shader thread for you if you like.... im not sure what you have done differently to me.

If it ain't broke.... DONT FIX IT !!!
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 19th Aug 2009 13:33
i agree that the black screen has something to do with the dbSyncMask, as there must be something covering the screen (a wrong cam or sth.)

it's just strange that it works for me and others like this (with the SyncMask switched)
it even works on another system here and with other projects!

i'll try your code snippet later, as i'm a lil busy right now

They say it's better to burn out than it is to fade away...
Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 19th Aug 2009 17:16 Edited at: 19th Aug 2009 17:27
Thanks guys for looking into it. I would like at least try your version also, Mista Wilson. My code above has the "SyncMask switched" in it too. You'll see the commented out syncmasks there where it was suppose to be like.

I have the Nvidia GeForce 9800 GX2 card with the latest drivers.


Edit: Cool! Mista Wilson, your version worked perfect for me. Will try to see what the difference is.
Edit: Then hopefully that will help figure out how to get _Pauli_'s to work for me too...

Xenocythe
19
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 19th Aug 2009 17:32
Mista's version worked swell for me too. Hope you get it figured out Pauili


_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 19th Aug 2009 17:41
glad to hear you got at least one version to work!
i'm gonna check yours and Mista Wilson's later, and maybe we can get the Ultimate Shadow Mapping to work

by the way, if someone knows a good (working) shadow mapping shader for directional lighting: please tell me!

They say it's better to burn out, than it is to fade away...
Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 20th Aug 2009 04:36
Ok got back to it...

I was able to compile Mista Wilson's code with no problems and it worked.

From comparing my code to his, I noticed everybody has thier own way to set the dbSyncMask value. That's probably what is confusing me the most and why my code or _Pauli_'s code isnt working for me.

_Paulie_: the C/C++ symbol ' ^ ' doesn't mean the "power of" like like in DBPro. In C/C++, it's a bitwise operator meaning Exclusive OR (XOR). But why it still works for you and not me is still a mystery to me.

Mista Wilson: I did the dbSyncMask like you did with the bit Left Shifting. That made Depth Texture completely black for me. So, I was able to see the rotating teapot and the box underneath it all textured, but no light, normal maps and shadow maps. Again,

So, I retried my method of OR'ing bits to the default MASK ( 0xFFFFFFFF) where I have this code:



* As the DBPro docs explains ( Couldn't find it in the DGDK docs ) that in SyncMask bit 1 is camera 0, bit 2 is camera 1 and so on.

That ALMOST ran perfect for me!

Now, it runs at half speed ( or at 30 fps instead of 60fps ) and the whole screen flickers like from a white screen to the normal screen you are suppose to see... really bad. So, If ... some how ... I can figure that flickering out, then it will run exactly like evolves with that hexagon shape lighting/texturing or how ever it's doing that.

* It seems it all comes down on how to use dbSyncMask properly. I don't think I'm using it properly quite yet...


Here's my full updated code with the flickering problem...


Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 20th Aug 2009 04:56 Edited at: 20th Aug 2009 05:01
Ok, I forgot to uncomment dbSyncFast doing it your way, Mista Wilson. It finally works!



Except for some reason the teapot isn't lighting up correctly. hrmmm...


EDIT : Now _Pauli_'s code worked for me doing SyncMask like that. Sweet!

Login to post a reply

Server time is: 2024-11-20 17:38:15
Your offset time is: 2024-11-20 17:38:15