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.

Code Snippets / [DBP] - [DBP] - CSM - Cubic Shadow Mapping made easy!

Author
Message
Broken_Code
13
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 10th Nov 2013 17:01 Edited at: 9th Jan 2014 15:04
NEW!!! V 1.1

All code written for V1 will work for V1.1 without modification!

I've now added per-object Alpha to the CSM System! Check it out!

[DOWNLOAD IN NEXT POST]

With CSM you can add cubic shadow mapping to your games with just 4 commands!


I've written a fully commented example to go with it so it's easy to understand how to use it.

Current Features (new Features in bold):
->Shadow & Normal mapping
->Light flashes
->Pulsating lights (colour and/or range)
->Lights can be dynamically added/deleted
->Debugging functionalliy
->Per Object Alpha
->Optimisation (+2%FPS for me, your milage may vary )

New functions (also explained in example code!):
->CSM_ObjectAlphaEnable(ObjectID as integer, Enable as boolean) ->Enable or disable Alpha for an object
->CSM_ObjectAlphaSet(ObjectID as integer, Alpha as float)
->CSM_Flush() ->Reset the CSM system


Current limitations:
->6 lights max

Next to do (Need help with this):
->Packing shadow maps into colour chanels (allowing upto 18 lights)

Here's the shader code (same as V1):


"... Why the hell did I chose game creation as a hobby!?" - Burning Feet Man
Broken_Code
13
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 10th Nov 2013 17:01 Edited at: 8th Jan 2014 23:27
[Continued message]

And the code for the V1.1 CSM System:


And here is the example's code:


All these and the DBP project file are in the download along with a compiled .exe of the example (7MB total).

Comments welcome!

Thanks,
Bruce

"... Why the hell did I chose game creation as a hobby!?" - Burning Feet Man

Attachments

Login to view attachments
Broken_Code
13
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 10th Nov 2013 17:08
Screen shot #1

Attachments

Login to view attachments
Broken_Code
13
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 10th Nov 2013 17:08
Screenshot #2

Attachments

Login to view attachments
Broken_Code
13
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 10th Nov 2013 17:09
Screenshot #3

Attachments

Login to view attachments
Broken_Code
13
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 10th Nov 2013 19:43 Edited at: 10th Nov 2013 19:44
Screenshot #4 - on-screen debug text

Attachments

Login to view attachments
wattywatts
14
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 11th Nov 2013 00:17 Edited at: 11th Nov 2013 04:09
This is pretty awesome! The only downside (correct me if I'm wrong) is that this shader doesn't support animation. I also always wanted the shadow area to be bigger when I used the original shader.

EDIT I was wrong about it not shadowing boned and animated models, just tried it out and works wonderfully. Thanks for donating this, I think I may have a use for it soon.

http://www.indiedb.com/games/max-vs-mars
Broken_Code
13
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 11th Nov 2013 13:25
Quote: "This is pretty awesome! The only downside (correct me if I'm wrong) is that this shader doesn't support animation. I also always wanted the shadow area to be bigger when I used the original shader."


You had me worried for a minute!

Quote: "I think I may have a use for it soon"


Glad I could help!

FYI I plan to come back to this after my current project and add more lights (upto 18, this is almost done already) and spotlights too!

Thanks for the feedback!
Stab in the Dark software
Valued Member
20
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 11th Nov 2013 17:59
Nicely Done.

Excellent coding style. So many people write great code examples
except the poor coding style prevents reusing the code with out a rewrite.

Quote: "FYI I plan to come back to this after my current project and add more lights (up to 18, this is almost done already) and spotlights too!"


Would adding that many lights slow down the FPS too much to make it useable in a project?

Thanks for posting.


[img][/img]


WindowsXP SP3,Vista,Windows 7 SP1, DBpro v7.7RC7
Stab In The Dark Editor
The coffee is lovely dark and deep,and I have code to write before I sleep.
Broken_Code
13
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 12th Nov 2013 17:09
Quote: "Excellent coding style. So many people write great code examples
except the poor coding style prevents reusing the code with out a rewrite."


Thanks!

Quote: "Would adding that many lights slow down the FPS too much to make it useable in a project?"


Yes and no. It depends on how many lights you use: the light-for-light performance should be the same (if you use 6 lights with this shader you'll get the same performance when you use 6 lights with the next one) but with the advantage of being able to use more lights!

Thanks,
Bruce
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Nov 2013 00:28
I would like to add this to my website if I may.

Broken_Code
13
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 14th Nov 2013 09:23
Quote: "I would like to add this to my website if I may."


Please do! Remember to check back later for the next Version too!

Thanks,
Bruce
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 28th Nov 2013 19:17
Looks like a good program; will have an observation some time soon.

GreenDixy
15
Years of Service
User Offline
Joined: 24th Jul 2008
Location: Toronto
Posted: 4th Dec 2013 05:37
Very nice will come in handy hopefully you will get more lights going.

.:: Http://DeanWorks.Ca ::.
My software never has bugs. It just develops random features.
Broken_Code
13
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 4th Dec 2013 09:44
Thanks for the comments!

Quote: "hopefully you will get more lights going."


Yeah, I'm working on another project at the moment and will probably focus on getting alpha working first, no doubt I'll make a new thread asking for help with this shader at some point!

Take care,
Bruce

"... Why the hell did I chose game creation as a hobby!?" - Burning Feet Man
Broken_Code
13
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 8th Jan 2014 23:35
Bump for the new Version!

Check out the example for advice on how to use the new functions!


Take care,
Bruce

"... Why the hell did I chose game creation as a hobby!?" - Burning Feet Man

Login to post a reply

Server time is: 2023-09-21 14:06:57
Your offset time is: 2023-09-21 14:06:57