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.

DarkBASIC Professional Discussion / Shadow Mapping for bone animated models

Author
Message
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th May 2012 14:19
Over the last fortnight or so MMM and I have been working on getting Evolved's Shadow Mapping shader to work with GPU bone animated models. At the same time we fixed a few other issues. For example the new shader uses accurate pixel fog rather than vertex fog and also works correctly with unwelded models.

I'm pleased to report that we've resolved the main issues. The result is the attached demo which shows shadow mapping for bumpmapped animated boned models plus fog.

The demo uses two shaders - one for boned models, the other for simple objects (such as the floor in this demo). On my machine the demo runs at up to 1400 fps (with vsync off - with vsync on I get a steady 60). A comparable unboned shader reduces the fps considerably when vsync is off.

[Technical stuff]Shader connoisseurs might be interested to know the following.

There were two problems developing the shader. The first main one was a new one to me and held us up for quite a while till Lee kindly confirmed what the problem was. When a vertex or pixel shader is compiled by DBPro something called a constant register table is set up. This table contains all the variables that the application - i.e. the DBPro program - has to pass to the vertex or pixel shader. In the case of the boned version of the vertex shader this includes the bone matrix palette which in this demo has size 60. Some of the models we were using needed the full 60. Each entry in the palette requires 16 floats (corresponding to a 4x4 matrix) and each register in the constant table can contain 4 floats. This means that the bone matrix palette used 240 of the available 256 entries in the constant table. The others were needed for things like fog distance, world matrix, view matrix and so on. It turned out we had exceeded the limit of 256 for Shader Model 2 (neither Dark Shader or DBPro gave any warning this was happening). We managed to get around that problem by moving some of the vertex shader code into the pixel shader - that helps because some of the registers are no longer need by the vertex shader and are used by the pixel shader instead where there was plenty of room. We now come to the second problem.

The original version of the shader had a pixel shader near its instruction count limit - and that was exceeded when certain instructions were moved into it from the vertex shader. We were able to overcome that by compiling the shader under Shader Model 3 instead of Shader Model 2. However, not everyone has a GFX card that supports SM2. Since several instructions were consumed by the repeated shadow map samples (needed to soften the shadow edges somewhat) a simple solution was to reduce the number of samples. So the attached demo has two main techniques for shadow mapping: one for SM3 which uses the full 3x3 sampling grid used by Evolved, and one for SM2 which uses a simple triangular sampling pattern.

[End of Technical stuff]
The demo uses dark red fog so you can see it working clearly. Just change the colour to something that suits your taste.

The demo uses two animated boned models - one from the MS DX9 SDK ("tiny.x") and one from an FPSC Model Pack "vikingwarrior1.x". [Note that the latter had to have vertex colour removed so bumpmapping would work - you'll see the file has been renamed "vikingwarrior1nodiffuse.x" for that reason.] Some of you will notice that the sword doesn't have its own bump map - if you know how to fix that easily please let me know.

Move the camera using the mouse to turn and up/down keys to move back and forth.


[This post was originally buried in one of the related threads but we decided that anyone interested in shadow mapping for boned animated models would have difficulty finding it. Hence this thread. I've also taken the opportunity to make two minor changes to the dba code: the animated model now uses a smaller shadow map sampling width (the other shader still uses Evolved's fixed width and could be edited in the same way); the shadow map has been changed to use R32F format. This allows depth to be calculated more accurately.]
MrValentine
AGK Backer
14
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 14th May 2012 21:20 Edited at: 15th May 2012 05:28
Very interesting...

Will hopefully give this a try later after I wake up hehe...

EDIT

Typo fixed in bold

Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 15th May 2012 00:20
Yeah that's perfect. One day I will rig a model!

Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 15th May 2012 04:13 Edited at: 15th May 2012 04:14
Very Cool!

I can see the shadowmap effecting the tiny.x and vikingwarrior1.x models. But, I can not see the floor object. I can remark out the "set object effect 2,2" to see a white square floor, but when it's not remarked out, the floor object simply does not show up for me.

I have the NVidia G-Force 560 with latest Graphics driver which is 296.10 at this point in time.

I assume I am suppose to see the shadow mapped to the floor, right??

ExoDev.Com - A Game Development Tools Website! Featuring: XBOX360 CONTROLLER LIBRARY
MrValentine
AGK Backer
14
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 15th May 2012 06:29 Edited at: 15th May 2012 06:37
Finally woke up at 3am lol

EPIC demonstration there GG works great



EDIT

Mind you I am currently at this point in time testing this on an NVidia 430GT 1GB PNY

EDIT

@ Todd Riggins - try resetting your NVidia settings to let the application decide...

Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 15th May 2012 07:22 Edited at: 15th May 2012 07:27
@ MrValentine


I never muck around changing my NVidia settings... Sooo I'm at a lost on how to "Reset it".

BEFORE I can figure out how to reset it, what will the application decide? What do you mean by that? Thanks

ExoDev.Com - A Game Development Tools Website! Featuring: XBOX360 CONTROLLER LIBRARY
Mage
Valued Member
18
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 15th May 2012 07:58 Edited at: 15th May 2012 08:07

1. There's a spotlight but how does one make an omnidirectional light?
2. How many lights are supported?
3. Is there an ambient light level setting?



Just musing Here:
I'm just trying to think how this would be setup in a real game, because if it's just one light... wouldn't be that good.
Now, 4-5 Lights, with ambiance, and you could manage which lights were closest for each object... would seem more helpful.
Then again this method seems to require syncing a camera for each light per frame. Anymore then a few lights and there would be problems... like a Quake or COD level.
And Bone Shader + Shadows is really awesome.
How would this be setup to cover an area with several dozen lights with some overlapping...


This is awesome great work. I'm just not sure how to manage more than one light with this (as would be needed), or whether another method would be better.

MrValentine
AGK Backer
14
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 15th May 2012 08:47
@ Todd Riggins

right click your desktop and select control panel... first page has the options... ask me if you need more detailed instructions...


@ Mage

DARK SOURCE =
InfiniteDynamicLights


eXtends =
Lights3D


DS uses a 6 hardware lights sequence... based on how close they are to you...

eX uses 7 lights which switch dependent on distance too...

so you have two options to buy either product

I recommend them both!

Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 15th May 2012 11:06
@ MrValentine

Quote: "..., what will the application decide? What do you mean by that? Thanks"


I'm still waiting an answer. Thanks

BTW, I did restore my global settings. It didn't change any of the settings because nothing had ever changed. Plus, it did not make the "ShadowMappingFix" shader work for the floor.

ExoDev.Com - A Game Development Tools Website! Featuring: XBOX360 CONTROLLER LIBRARY
MrValentine
AGK Backer
14
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 15th May 2012 11:21
Quote: "Quote: "..., what will the application decide? What do you mean by that? Thanks""


these are set by your application, say you specify AntiAlias 2X your NVidia drivers can up this to 8X+ and ignore your settings...

if that makes sense...

set it to balanced, the third option which enables the slider...

are you using any other hardware applications like PerfHD or something?

Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 15th May 2012 11:55 Edited at: 15th May 2012 11:56
Quote: "are you using any other hardware applications like PerfHD or something?"


No. I don't change video card setting for anything. Never found the need to. I'm not an OC'r.

I have as default global settings:

Ambient Occlusion = Off
Anisotropic filtering = Application-controlled
Antialiasing - Gamma correction = ON
Antialiasing - Mode = Application-controlled
Antialiasing - Setting = Application-controlled
Antialiasing - Transparency = Off
CUDA - GPUs = All
Max pre-rendered frames = 3
Multi-display/mixed-GPU acceleration = Multiple display performance mode
Power management mode = Adaptive
Texture filtering - Anisotropic sample optimization = Off
Texture filtering - Negative LOD bia = Allow
Texture filtering - Quality = Quality
Texture filtering - Trilinear optimization = On
Threaded optimization = Auto
Triple buffering = Off
Vertical sync = Use the 3D application setting


* If you are thinking if it's my Antialiasing settings then they are set to Application-controlled as I have listed.

I don't have any option for "balanced"

ExoDev.Com - A Game Development Tools Website! Featuring: XBOX360 CONTROLLER LIBRARY
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th May 2012 13:05 Edited at: 15th May 2012 13:06
@Todd Riggins

That's a very weird problem. I would expect the more complicated bone shader to fail, not the simpler one that's used for the floor.

What do you see when you press "1" for the depth map?

This is what I see before I move the camera, etc:



Have you tried switching to the SM2 versions in these lines?



Does that change anything?
Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 15th May 2012 13:23 Edited at: 15th May 2012 13:24
Yes, I tried both versions and get the same result.

Mine will only show the character in the depth map



ExoDev.Com - A Game Development Tools Website! Featuring: XBOX360 CONTROLLER LIBRARY
MrValentine
AGK Backer
14
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 15th May 2012 13:50 Edited at: 15th May 2012 13:54
Todd Riggins - try reinstalling DX9.0c

just a farshot...

EDIT

also

@ Todd Riggins


Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th May 2012 13:58 Edited at: 15th May 2012 14:17
@Todd Riggins

I can only reproduce your symptoms by deliberately introducing an error into the second shader code so it doesn't compile when loaded by DBPro.

If you have Dark Shader could you try compiling the "ShadowMappingFix.fx" shader and see if it compiles OK?

I still find it odd that the bone version works but the simpler unboned one doesn't - and that is essentially Evolved's shader with just a few changes here and there.

If you haven't got Dark Shader could you try the PERFORM CHECKLIST FOR EFFECT VALUES and PERFORM CHECKLIST FOR EFFECT ERRORS commands and list out what's found just in case there's a clue there?

Edit This is a bit of a longshot. You could try changing all the texture samplers so they match those in the shader that works, e.g. the working shader has:



whereas your non-working shader has:



i.e. try changing all the references to sampler2D to just sampler. If that doesn't work add the filtering commands, etc.

I've noticed some minor differences between machines because of that sort of thing.
Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 15th May 2012 14:14
@Green Gandalf

Yes it compiles ok in Dark Shader.

I'll try to figure out these commands you mentioned and see if I can get anything from them.

ExoDev.Com - A Game Development Tools Website! Featuring: XBOX360 CONTROLLER LIBRARY
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th May 2012 14:18 Edited at: 15th May 2012 14:20
Try changing the samplers first - see my previous edit which was posted just too late.

Quote: "with latest Graphics driver which is 296.10 at this point in time"


I haven't tried the latest yet. Perhaps I shouldn't. I often get problems when I try the driver upgrades.
MrValentine
AGK Backer
14
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 15th May 2012 14:19
and my previous post I added a picture for you Todd

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th May 2012 14:24
Yes, I saw that. As I said, I get exactly your symptoms when the shader doesn't compile - including your depth map image. But if it compiles in DS it should compile in DBPro so something else is messing things up.

Anyway, see what the samplers do before delving into the shader checklists (which I haven't done for years).
Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 15th May 2012 14:33
@GG To Late ! But, Will do

Quote: "I haven't tried the latest yet. Perhaps I shouldn't. I often get problems when I try the driver upgrades."


Try it.

Would this be correct code to test with for those commands?


testing the sampler stuff...

@MrValentine
I will not re-install DX9 unless it's the only other option. I respect your suggestion, but I'm leaning towards that not being it ... at the moment.

Can you give me a link to that picture? I don't see it.

ExoDev.Com - A Game Development Tools Website! Featuring: XBOX360 CONTROLLER LIBRARY
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th May 2012 14:40 Edited at: 15th May 2012 14:43
Quote: "Can you give me a link to that picture? I don't see it."


You should be able to just right click it, click Properties and find the link then copy it into your address bar. Here it is anyway:

http://www.akaneaya.co.uk/tgcforum/DOWNLOADS/nvidiacontrolpanel.JPG

Computers are fun.

Edit

Quote: "Would this be correct code to test with for those commands?
"


Looks fine to me. Whether it helps is another matter.
MrValentine
AGK Backer
14
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 15th May 2012 14:41
Thanks GG

Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 15th May 2012 14:51 Edited at: 15th May 2012 14:52
Ok, I'm a bit slow... trying to catch up here...

I tried the commands first... and I get these warnings and error exactly the same for both checklist commands:

warning X3206: 'mul': implicit truncation of vector type
warning X3206: implicit truncation of vector type
warning X3206: implicit truncation of vector type
warning X3206: implicit truncation of vector type
warning X3206: implicit truncation of vector type
warning X3206: implicit truncation of vector type
warning X3206: implicit truncation of vector type
warning X3206: implicit truncation of vector type
warning X3206: implicit truncation of vector type
warning X3206: implicit truncation of vector type
error X3003: redefinition of 'DepthMap'

** ! Also, what version of DBPro you guys running? I'm running off the U77 public Beta.

Ok trying the GG sampler trick...

EDIT:

Tried the balanced thing with the nvidia setting still didn't work that way.

ExoDev.Com - A Game Development Tools Website! Featuring: XBOX360 CONTROLLER LIBRARY
Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 15th May 2012 14:58 Edited at: 15th May 2012 15:05
ok..ok... error X3003: redefinition of 'DepthMap'

change the technique DepthMap name to DepthMap2 in ShadowMappingFix

also edit the dbpro line to reflect it

set effect technique 2,"DepthMap2"

It works!!! Very Pretty stuff

Thanks for putting up with me

ExoDev.Com - A Game Development Tools Website! Featuring: XBOX360 CONTROLLER LIBRARY
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th May 2012 15:17
Quote: "It works!!!"


Which? Changing the samplers?

Quote: "Thanks for putting up with me"


No problem.

[By the way, you need to put empty checklist between the two sets of perform checklist commands - except it sounds like you don't need them at all now. ]

Quote: "change the technique DepthMap name to DepthMap2 in ShadowMappingFix"


That's interesting. I usually try to avoid giving different variables the same name even when the context tells the compiler they are different things. Sounds like you must be using a different version of the shader compiler - and a more sensible version at that. I'm using U77RC7 so I guess the difference must be in DX somewhere. No idea where though.
Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 15th May 2012 15:28 Edited at: 15th May 2012 15:33
Quote: "Which? Changing the samplers?"


No, just the technique name change

Quote: "By the way, you need to put empty checklist between the two sets of perform checklist commands - except it sounds like you don't need them at all now."


Ah, I probably got lucky seeing that error then. But that's right, I needed to do that.

Quote: "...I'm using U77RC7 so I guess the difference must be in DX somewhere. No idea where though."


I'm using U77RC7 Also, I do have the latest June 2010 DirectX installed.

Edit: Actaully I have compiled the google DBPro source code with DirectX June 2010 version (ie: dropping the obsolete DirectPlay support ) and mabie that's where the diff is.

ExoDev.Com - A Game Development Tools Website! Featuring: XBOX360 CONTROLLER LIBRARY
MrValentine
AGK Backer
14
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 15th May 2012 15:33
Hi Todd...

If you have Dark Game Studio... Install the DX that comes with that... Please dont argue just do it...

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th May 2012 15:39
Quote: "Actaully I have compiled the google DBPro source code with DirectX June 2010 version (ie: dropping the obsolete DirectPlay support ) and mabie that's where the diff is."


I'm sure it is. I'm still using one of the 2007 versions of DX. MS keeps messing about with details so later versions don't quite work the same way.

Quote: "Please dont argue just do it"


Will that do anything if it detects a later version?
Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 15th May 2012 15:48 Edited at: 15th May 2012 16:15
Quote: "If you have Dark Game Studio... Install the DX that comes with that... Please dont argue just do it..."


Biting my tongue... I program using the latest DirectX technology so I will not ruin my setup. No, I don't have Dark Studio. I bought the DBPro online version back in 2004.

Not arguing, I would just simply like to know WHY... this time... on why you want me to do that?? Thanks

ExoDev.Com - A Game Development Tools Website! Featuring: XBOX360 CONTROLLER LIBRARY
MrValentine
AGK Backer
14
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 15th May 2012 15:56
Long story short... DX is a LIBRARY... In that it is added upon... So don't worry about your latest editions... You can get more detail on my blog...

I am currently out so I can not explain in full...

The link for my blog explains a lot for Windows Based Devs... Have a read

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th May 2012 15:56
Quote: "Not arguing, I would just simply like to know WHY... this time... on why you want me to do that?? Thanks"


In the hope you would have a version of DX that's consistent with DBPro perhaps?

Quote: "I program using the latest DirectX technology so I will not ruin my setup"


It would seem that the latest version HAD ruined your setup.

At least there seemed to be a simple solution this time so everyone is happy.

Looks like I need to go through the latest demo and adjust all the variable names in the shaders - then it'll be TR-proof as well.
MrValentine
AGK Backer
14
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 15th May 2012 16:01
I realised I no longer have the link for the DX that is required on my blog page... I will upload it soon if you need it...

And haha yeah I like what GG wrote above haha...

Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 15th May 2012 16:45
Quote: "then it'll be TR-proof as well"


I'll admit I deserved that. sorry. I'll try to remember to take having the latest DirectX into consideration next time before I ask for help.

ExoDev.Com - A Game Development Tools Website! Featuring: XBOX360 CONTROLLER LIBRARY
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th May 2012 16:51
At least you've alerted us to yet another DX quirk.
MrValentine
AGK Backer
14
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 15th May 2012 17:13
Quote: "At least you've alerted us to yet another DX quirk."


indeed he has... ...sort of...

I am wondering whether or not it will be worth uploading that DX version in case anybody needs it...

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th May 2012 19:59
@Mage

Sorry - your questions got overlooked because of the "Todd Riggins diversion".

Quote: "1. There's a spotlight but how does one make an omnidirectional light?
2. How many lights are supported?
3. Is there an ambient light level setting?"


1. I'm planning on applying the bone method to this shader demo too:

shadow mapping for two lights

That demo uses two omnidirectional lights. That might allow two lights if it works with the bone version - but not sure till I check out the constant registers.

2. One light at the moment - but two if I can apply this to the above demo as well.

3. Yes there is - but the demo just uses the default value at the moment. You can check the shader code to see which constant needs to be changed if you want a different ambient setting.

Login to post a reply

Server time is: 2025-08-08 11:11:19
Your offset time is: 2025-08-08 11:11:19