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 / How to use Hardware Shader for SHADOWS

Author
Message
Tom Taylor
20
Years of Service
User Offline
Joined: 29th Dec 2003
Location: Germany
Posted: 22nd May 2008 13:59
In my current "DarkSDKBasic3D.h" header file I found this command to enable shadow shading:

Quote: "void dbSetShadowShadingOn( int iID );"


But how do I activate the hardware shader (stencilshadow.fx) ?


After searching the forum, I couldn't find any working code example or any hints. Please let me know, how to activate shadows. I need this for bone animations, too.

I allready have two different versions of stencilshadow.fx, one for statics and one for bone animations. If I can use them in DarkGDK, I will be very satisfied

Thanks, Tom

Tom Taylor
Pixel Perfect
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: UK
Posted: 24th May 2008 13:39
Hi Tom. The following is an extract from the DBPro help file which covers this command. I have included this as the help in the DGDK file is as good as useless. Unfortunately, the extended syntax is not available in DGDK as yet, I believe the shader is probably on by default:


*****************************************************************
SET SHADOW SHADING ON

This command will set the specified object to cast a hardware shadow. This command requires hardware
specifically designed for this feature, as it's a very intensive calculation. Use this command sparingly for
best performance. Shader based shadows cannot be used in combination with animated bone models. You
must use CPU based shadow rendering for this. To change the offset to reduce/increase self-shadowing
artifact described above, simply copy the stencilshadow.fx from the effects folder of the compiler
directory, and paste it into your project folder. Open it up and you can change the shader near the bottom
to a value other than 0.1 to choose your own value.

Syntax

SET SHADOW SHADING ON Object Number
SET SHADOW SHADING ON Object Number, Mesh Number, Shadow Range, Use Shader

*****************************************************************

Please note the warning about shader use and bone animation!

In practice, I have found the built in support of hardware (stencil) shading to be unworkable in DbPro and DGDK with anything other than simple primitives.

No matter how good your code is, someone will improve on it
tobi453
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location:
Posted: 24th May 2008 13:56
To use shadow shading you must do the following steps:

-put the shaderfile in your projects folder
-ensure that your current path is the directory where the shader is(dbSetDir(..))
-then write: dbSetShadowShadingOn(ObjNum,MeshNumber(-1 for no mesh), Shadow Range (for example 100), 1);

FINAL VERSION RELEASED!!!!
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 24th May 2008 15:16
I think the point Tom Taylor is trying to make is that there is only one forward declaration for the dbSetShadowShadingOn() function, and this one only takes 1 parameter, or at least I only have one.

Pixel Perfect
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: UK
Posted: 24th May 2008 17:04
Exactly ... as previously posted:

Quote: "Unfortunately, the extended syntax is not available in DGDK as yet"


Along with that the dbSetShadingOff command is in the include file but not available in the library. You just get an unresolved external symbol error when linking!

I logged these in the Bug Reports thread some time ago but there has been no response.

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: 24th May 2008 17:20
tobi453 is right, I just tried it and of course it fails to compile. But place the following forward declaration and it links ok:

void dbSetShadowShadingOn(int obj, int mesh, int range, int shader);

so it looks like the declaration has just been missed from the header file, which is better news.

No matter how good your code is, someone will improve on it
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 24th May 2008 19:02
Guys you MIGHT be able to make it work. I have found a number of missing commands and others who have sought them have found things hidden in the DarkSDK.h (and the others). Also, Lost In Thought pointed to me to a drop in replacement for a command that just wasn't there regarding the DirectX GetMatrix4 Element (dbGetMatrix4Element I think)...

Anyways... Maybe the Shadow "variant" is in the lib but NOT the header. Maybe ... dunno... but here is a snippet of some things in my JGC Lib that I keep handy due to this kind of thing - missing calls, or whatever:

jgc_gdk.h



Other relevant stuff from...
jgc_common.cpp - snippet


And here is more light shed on that D Mitry thing...

Note: In the original DarkSDK - the declaration existed, but it didn't make roll call to the current release most of us are using now.


So, I'm thinking, if you know the data types to the call of the missing dbShadow... call, you might beable to make your own declaration like I did for some DarkGDK functions above. If its just not in the library, perhaps someone can take a gander at the old sdk headers to see if its there maybe with a different name or something.

Tom Taylor
20
Years of Service
User Offline
Joined: 29th Dec 2003
Location: Germany
Posted: 25th May 2008 02:50
I could not work it out for DarkGDK !

Quote: "In practice, I have found the built in support of hardware (stencil) shading to be unworkable in DbPro and DGDK with anything other than simple primitives."


Well, I have a perfect working FX shader file for complex model shading. It works for Direct X bone animations, too. I have used this in DBPRO. Now i wanted to use it the same way in Dark GDK... BUT I don't know the secret behind that command:



I included the declaration line into the header file, but it simply does not activate the hardware shader (shader = 1). I see the shadows if I use software shader (shader = 0)...

I copied the ".fx" file into the project folder etc...

Any more hints please?! Does anyone have a working spinning cube example with hardware shaders?


Thanks, Tom

Tom Taylor
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 25th May 2008 03:45
Where is the "Stock" FX file? I wonder if it should be backed up and replaced with yours. Maybe it doesn't look for the file the same way as DarkBasic?

(Just grabbing at straws with ya... I'm routing for you because we all want successful soft shadows!)

Pixel Perfect
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: UK
Posted: 25th May 2008 12:15
@Tom

Quote: "I don't know the secret behind that command:

void dbSetShadowShadingOn(int obj, int mesh, int range, int shader);"


I'm not aware of any secrets or 'Dark Knowledge' as I like to call it

In my test program yesterday if I included the above forward declaration then the command worked on the objects I was using, either in cpu or shader mode. I renamed the 'stencilshadow.fx' shader in the project directory to confirm it was indeed using it and the shadows ceased. I'm assuming you have named your variant 'stencilshadow.fx' as this is seemingly hard coded in.

Quote: "Well, I have a perfect working FX shader file for complex model shading."

I have seen plenty of good fx shaders, evolved has produced a few excellent ones but I have never got any to, or seen any, work with complex level designs where all objects are casting shadows dynamically, let alone at an acceptable frame rate. If you've cracked this them you are probably the first and that’s a great achievement which I'm sure many people here would be really grateful if your prepared to share that knowledge. I wish you good luck.

TVB has been showing off some dynamic shadowing examples using shaders .... still very simplistic in terms of scene complexity but showing promise!

I personally have jumped to the Leadwerks engine and in a separate endeavour programming the DirectX API directly. The TGC products have proved too buggy for me with far too much reliance on 'Dark Knowledge' due to the lack of proper documentation or in many cases ... any documentation. On top of this their support seems almost non existent and there is little to no communication to customers of where they are going in the future. DarkGDK is several steps out of line with Dark Basic with no indication as to when future releases/bug fixes will be. Some people seem to love working this way, finding workarounds and non documented commands. I just find it very unprofessional.

I will continue to use them as prototyping tools and I intend keeping a close eye on what's happening here still. There are some inventive and very capable programmers in these forums and the forums themselves are in my experience the best Indie development forums out there!

No matter how good your code is, someone will improve on it
Tom Taylor
20
Years of Service
User Offline
Joined: 29th Dec 2003
Location: Germany
Posted: 25th May 2008 19:22 Edited at: 25th May 2008 21:42
Oh... this is bitter sweet. I have hardware shadow now in DarkGDK, but only for primitives.

Thanks for your information so far. I will give some code etc here to let you experiment with.




This code actually DOES a hardware shadow if you have placed the original "stencilshadow.fx" file inside your project folder. So I did some test with following results:

Works:

DBPRO + PRIMITIVES + ORIGINAL STENCILSHADOW.FX
DBPRO + PRIMITIVES + EXTENDED STENCILSHADOW.FX
DBPRO + BONE ANIMATION MODEL + EXTENDED STENCILSHADOW.FX
DarkGDK + PRIMITIVES + ORIGINAL STENCILSHADOW.FX

Works NOT:

DBPRO + BONE ANIMATION MODEL + ORIGINAL STENCILSHADOW.FX
DarkGDK + PRIMITIVES + EXTENDED STENCILSHADOW.FX
DarkGDK + BONE ANIMATION MODEL + ORIGINAL STENCILSHADOW.FX
DarkGDK + BONE ANIMATION MODEL + EXTENDED STENCILSHADOW.FX

Hm, why does my EXTENDED and the ORIGINAL shader not work for meshfiles? I will take a closer look at the media now, if it depends on the creation/format or whatever from the object.

BTW, I have looked at the definitions in "DBOData.h".

sObjectProperties:
bool bStencilObject; // flagged if object uses the stencil layer
LPVOID pShadowMesh; // holds the pointer to the shadow mesh

I think if you turn on "dbShadowShadingOn()" the bStencilObject is set to true. But what is about that "ShadowMesh"?

This CAN be very interesting, compared to my experience with the shader programming. Actually I tested the shaders with "FX Composer 2" from NVidia and all stencil shaders create a "ShadowMesh". I can give more information about this if anybody think this might be a right way...

EDIT: DOWNLOAD THE .FX FILES FROM THE ATTACHMENT.

Thanks, Tom

Tom Taylor

Attachments

Login to view attachments
Pixel Perfect
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: UK
Posted: 25th May 2008 22:25
Hi again Tom. The pShadowMesh as I understand it is the mesh that will be used to build the shadow from. By default it's the target mesh but the extended syntax allows for a substitute shadow mesh to be specified (persumably a low poly one). So in the command:

dbSetShadowShadingOn(Object Number, Mesh Number, Shadow Range, Use Shader)

the mesh number determins the mesh used to generate the shadow. Use -1 for the default mesh ... that is the mesh belonging to the object or specify a new mesh.

There are some other problems associated with stencil shadows and their implementation in DBPro and DGDK that I've not mentioned so far. If you are interested take a look at the following thread, there is a workaround there so beit not a very practical one!

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

The other option to the one I explored in that thread is to limit the lenght of the cast shadows to prevent them touching other object faces but this kind of looks un-natural and defeats the whole illusion!

By the way, I have successfully cast stencil shadows from animated objects in DGDK. However, if the objects are scaled in any way the shadow size seems to get completely screwed.

No matter how good your code is, someone will improve on it
Tom Taylor
20
Years of Service
User Offline
Joined: 29th Dec 2003
Location: Germany
Posted: 26th May 2008 01:56 Edited at: 26th May 2008 01:59
I need some information about the "BoneMatrixPalette". It is related to DBPRO internal data. It looks like it is not available for DarkDGK. That might be a reason why my extended shader does not work with DarkGDK.

I guess it holds the bone matrix. From the shader file:


If thats right, it is linked to the bones from the model. If I can link it manually, I think the shader will work for DarkGDK, too.

Thanks, Tom

Tom Taylor
Tom Taylor
20
Years of Service
User Offline
Joined: 29th Dec 2003
Location: Germany
Posted: 26th May 2008 20:50
Ok, I will try to set the boneMatrix manually.

I need the dbSetEffectConstantMatrix to work with arrays and I need to get the bone matrix from the mesh.

Any ideas how to get the bone matrix quick with db-commands? The bone is a limb object from the mesh and has its own matrix.

Thanks, Tom

Tom Taylor
taylor design
16
Years of Service
User Offline
Joined: 28th May 2008
Location: Germany
Posted: 28th May 2008 21:32
Hi again,

I changed my account from "tom taylor" to "taylor design".


I have had a deep research about shaders and specially about shadow shading. Volume shadows is not an easy task, but I think we are very close!

1. Creating the shadow mesh is easy to do with the shader.



2. Setting the passes to render. This lets the engine use the stencil buffer (if used with "dbShadowShadingOn").



So this is working nice so long, as I use "dbShadowShadingOn" on a non-vertexbased animation model. All the trouble is about the renderpasses.

If I use the shader loaded from file, I see the volume mesh rendered, but not as expected shadow. I think the object(s) don't have the right setup to use the stencilbuffer at rendertime (dbSync), which "dbShadowShadingOn" might to set correct.

Well, for bone animations, the shader simply needs the BONE MATRIX. In DBPRO the shader works! That leads me to the fact that DarkGDK simple does not understand the SEMANTIC "BoneMatrixPalette", like DBPRO does.

I searched for the common semantic for bones, but even in the lates "FX Composer 2.0" (NVidia), there is no working semantic for bones.

So the solution for shadowing bone-animated models is in filling the BONE MATRIX. Will there be a DarkGDK update to match DBPRO?

If not, I need to set the Matrix Array. But as I understand the DarkGDK commands, its only possible to set the shader values by names. So how can I set the array of matrices?

If even this is not possible, I could create a special "converter", which reads the mesh bones and creates a NEW shader file with FIXED arrays. So the shader will have his bone matrix filled...

Ideas and comments are allways welcome

Best regards, Tom

Login to post a reply

Server time is: 2024-11-20 11:21:20
Your offset time is: 2024-11-20 11:21:20