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 / How do you create shadows in DBP?

Author
Message
MjG0001
15
Years of Service
User Offline
Joined: 19th Jan 2011
Location: U.S.A. - Indiana - Cedar Lake
Posted: 25th Jan 2011 13:53
I'm curious if anyone here knows how to make shadows using DBP? I'm loading a character / model into DBP, but they don't have a shadow. I considered using a plain but there are problems with that approach.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 25th Jan 2011 15:08
SET SHADOW MAPPING ON Obj,range,shader

Range being the range of the shadow, and shader being 1 - so it uses the new shadow shader.

Works fine for me, there are other commands for it, and it can be sensitive to camera range, but it's a good start. If it doesn't tick all the boxes, maybe looking at some shader based shadows would be an idea.

Health, Ammo, and bacon and eggs!
C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 25th Jan 2011 15:53
Don't you mean, set shadow shading on.

I can't find any reference to a shadow mapping command.

set shadow shading on has one extra parameter as well:



Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 25th Jan 2011 15:59
My bad, it's been a long day - plus I knew someone would have the real answer before very long. There is a command to setup shadows as well, I can't remember it, and it's not documented - lets you set the colour of shadows etc.

Cheers!

Health, Ammo, and bacon and eggs!
C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 25th Jan 2011 16:26
Yeah, there's a set shadow position command but I don't know of the colour one.

revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 25th Jan 2011 17:12
That would be: set global shadow color R,G,B,A
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 25th Jan 2011 17:16 Edited at: 25th Jan 2011 17:17
These are all I could find (just do a filename search of the Help folder):

MjG0001
15
Years of Service
User Offline
Joined: 19th Jan 2011
Location: U.S.A. - Indiana - Cedar Lake
Posted: 25th Jan 2011 19:52
Yeap, all I had to do was type shadow in the search box under the help files and all the shadow commands pop up. Subconsciously I must have decided that DBP didn't do shadows, otherwise I should have realized to search the keyword shadow... gosh.. duh, silly me. Thanks guys.

I will search keywords before asking noob questions again. Lesson learned.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 26th Jan 2011 13:18
Quote: "I will search keywords before asking noob questions again. Lesson learned."


No problem. It only occurred to me yesterday to do it that way too.
enderleit
19
Years of Service
User Offline
Joined: 30th May 2007
Location: Denmark
Posted: 27th Jan 2011 12:37
Is the built in shadow commands viable in the end if you are making a really proffesional game. (One that needs to be optimized alot)
Or would shaders be the way to go for that?

MjG0001
15
Years of Service
User Offline
Joined: 19th Jan 2011
Location: U.S.A. - Indiana - Cedar Lake
Posted: 27th Jan 2011 12:42
1.) I have not used the built in shadow commands yet. I plan on doing that soon to see what that looks like.

2.) I am not sure specifically what you mean by "optimized a lot".

3.) I don't know what shaders are or how to impliment them.

I'm a very aggressive learner and I have a lot of time on my hands, and I would love to learn all this.

I appreciate you letting me know that shaders are more pro than the built in commands. This is the kind of supplimental advice I am looking for.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 27th Jan 2011 13:08
The built in shadows look very nice when they are working - but it's a distinct, sharp shadow. If you need soft shadows, or shadows with smoother edges then you have to really look at shaders. Of course, you should weigh up all your options, download some shadow shader examples and try out the built in shadows.

Personally, I would use the built in shadows when using a lot of objects, lots of detail, because when your objects have more detail, they can over-stretch most shadow shaders. The shadows look like they come from a very direct light source, so they are good for outdoor scenes and strongly lit indoor scenes. The thing that concerns me with shadow shaders, is that to get a good effect over the whole level, it can take a lot of memory, often these shaders rely on seperate camera renders, often they look ropey from certain angles. Built in shadows are a real option - I've used them in some test projects, they looked great in an outdoor daylit city environment, they looked great on a Marble Madness style physics game. I tend to prefer to use built in most of the time.

Health, Ammo, and bacon and eggs!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th Jan 2011 14:00
And the built-in one has a shader option.

For cheap shadows look at bond1's recent threads using planar shadows in the FPSC forums. He has a nice one which uses transparency to achieve a softish shadow effect.
MjG0001
15
Years of Service
User Offline
Joined: 19th Jan 2011
Location: U.S.A. - Indiana - Cedar Lake
Posted: 27th Jan 2011 15:06
Issue:

I created a small quick program to learn how to use the 'set shadow shader on' command. I tried various parameters to get it to work. Once I got it to work without crashing DBP, the shadow that it generated didn't correspond to the object casting the shadow at all.

There are four parameters for this command:

1.) Object Number
2.) Mesh Number
3.) Range
4.) Shader Number

My Questions:

1.) Is the Object Number the object that is casting the shadow, receiving the shadow, or is the shadow?

2.) Is the Mesh Number the object that is casting the shadow, receiving the shadow, or is the shadow?

3.) What is a good range ratio for object height? I'm using 1 meter to 5.

4.) How many shaders are there? Whats the difference in them?

Code Attached:

revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 27th Jan 2011 15:30
The "Object Number" is the object to cast the shadow.
The "Mesh Number" is an optional parameter which allows you to use a separate mesh to cast the shadow (the mesh usually being lower-poly than the actual object). Set this to -1 if you want to use the actual object.

Quote: "How many shaders are there?"
There are 2 which can be found somewhere in the DBPro folder, but that flag only defines weather or not to use a shader (0 or 1). I think DBPro automatically applies the "stencilshadowbone.FX" shader to bone-animated objects, while using "stencilshadow.FX" for the rest.

If you copy the shaders into your project's directory, then your application will use that copy of the shader (which allows you to modify them).
revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 27th Jan 2011 15:30 Edited at: 27th Jan 2011 15:32
[Edit] Sorry, double post....
MjG0001
15
Years of Service
User Offline
Joined: 19th Jan 2011
Location: U.S.A. - Indiana - Cedar Lake
Posted: 27th Jan 2011 15:51
Okay, let me make sure I understood:

1.) The Mesh Number tells DBP to 'calculate the shadow shape' using a different object than the object your telling it to cast the shadow from. Example: A man could cast the shadow of a bear.

2.) The last parameter just toggles the shadow function on/off. Example: A man walks out of a room ( shader off, no shadow ) and into the daylight ( shader turns on, casts shadow ).
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 27th Jan 2011 16:09
1) Yes, you might want to use a lower detail and faster version of the mesh for the shadow casting, to improve performance or even improve looks. If you have a building for instance, you might want to have lots of little details on the visible mesh, but then those would probably not be seen on the shadow - or you might want to have the windows removed on the shadow version, because the shadow shader doesn't care about transparency.

2) No, originally the shadow system was all CPU calculated, basically a mesh created for the shadow, so very sharp and accurate lines, but slow. Nowadays there is a shadow shader, which is much faster. That last value is a flag, 0 for old fashioned non-shader, or 1 for the new fast shadow shader.

Health, Ammo, and bacon and eggs!
MjG0001
15
Years of Service
User Offline
Joined: 19th Jan 2011
Location: U.S.A. - Indiana - Cedar Lake
Posted: 30th Jan 2011 08:24 Edited at: 30th Jan 2011 08:26
Two Problems:

The Shadow Only Appears When The Objects Touch

When I use the shadow command it only creates a shadow when the shadow casting object is touching the shadow receiving object.

The Shadow Does Not Correspond To All Objects In A Character

Because the characters I have created are made up of more than one object in 3DS Max, the shadow only represents the object that is in contact with the shadow receiving object, and not any other objects that comprise the character.

* I make the characters in 3DS Max using multiple objects. I then load the characters into DBP as one object. However it seems like DBP can see that the single object is an array of objects, and this has something to do with how it is calculating shadows.[b][/b]
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 30th Jan 2011 12:02
At a guess, this sounds like you don't have the shadow range set high enough and hence only the limbs that touch the surface are close enough to cast a shadow.

MjG0001
15
Years of Service
User Offline
Joined: 19th Jan 2011
Location: U.S.A. - Indiana - Cedar Lake
Posted: 30th Jan 2011 14:45 Edited at: 30th Jan 2011 15:09
Thanks for the advice Andrew. However, I did vary the range a great deal to no avail.

The solution for my case turned out to be three things:

1.) I added the 'Set Shadow Position' command. This allowed me to position the light that casts the shadow above all of the objects that comprise my character. The default position is apparently y=0 or something close to that, because only the feet and legs of my character were casting the shadow.

2.) I used the '-1' mode to set the default position. The 'Set Shadow Position' command doesn't work if you use mode 0. Well it works, but the shadow's shape is a mess that doesn't correspond to the character.

3.) I placed the Shadow commands in the body of the program instead of the header, essentially updating the shadow to the position of the object that casts the shadow ( otherwise the shadow goes nuts and runs off the screen if the position of the object moves ).

Also, I should mention that Van B is 100% correct about NOT using the CPU shader. The shadow does NOT correspond to the character at all. Set the flag to 1 or the results will be terrible.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Jan 2011 15:08
Here's a demo Spooky posted some time back. I found it very useful.

MjG0001
15
Years of Service
User Offline
Joined: 19th Jan 2011
Location: U.S.A. - Indiana - Cedar Lake
Posted: 31st Jan 2011 10:10
Thanks Gandalf, that was a very cool shadow demo.

Login to post a reply

Server time is: 2026-07-18 21:03:54
Your offset time is: 2026-07-18 21:03:54