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 / Multiple lights with Shaders

Author
Message
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 30th Aug 2011 05:17
Hello all, so I'm doing some work with Shaders for the first time and I'd like a little help.

Lets say I want to have a box with a pretty texture appplied to it that uses Parallax Mapping. I light the scene not with ambient light or DB lights, but instead using the lightposition feature of the shader itself (applied using a vector). To do this, I'd use something like this:



This applies one light to the object, set up by the vector.

What I want to be able to do, is to apply MORE than one light to the object. Is this possible? I tried creating another shader and applying both shaders to the object, but the second one just cancels out the first one...

When I use normal DB lights I can use 7 different lights, but basically I want to be able to replicate that using Shaders... Any ideas?

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
Bluespark
15
Years of Service
User Offline
Joined: 18th Mar 2011
Location:
Posted: 30th Aug 2011 07:15
Why not look into the Multiple Lights code by the same person that made the shader you use?
Essentially you have to run through multiple passes of the object to get the multiple lights effect.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 30th Aug 2011 07:17 Edited at: 30th Aug 2011 07:18
I looked around his site, but couldn't actually find anything like that... Or are you referring to the multi-pass lighting effect?

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
Bluespark
15
Years of Service
User Offline
Joined: 18th Mar 2011
Location:
Posted: 30th Aug 2011 07:19
Yes, that.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 30th Aug 2011 07:41
Hmm... Applying it to the demo map I've made up seems to render all of my objects black... I'll have to have a play around. Thank you, though!

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 30th Aug 2011 09:24
If you would upload the shader I am sure someone could add more lights to it, though they would come with a performance hit.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 30th Aug 2011 17:08
I'm actually just using the CubicShadowMapping.fx available from Evolved Software. I'd like to have access to 6 lights. I know that would normally melt a CPU, but their being spaced out quite a bit so they will be being disabled when the player is not near them and there'll be no more than 2 at a time.

If anyone would be able (or willing) to help out, I've attached the Evolved Software shader here.

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 30th Aug 2011 19:16
You didn't originally mention that you wanted dynamic shadows as well. That being the case I would guess that Evolved's Advanced Lighting would be your best bet.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 31st Aug 2011 03:15
Thanks, revenant. But if the lights in a scene weren't dynamic, wouldn't people just bake in the lighting?

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 31st Aug 2011 13:21
Quote: "But if the lights in a scene weren't dynamic, wouldn't people just bake in the lighting?"
Yes, they would use pre-rendered shadows. The important bit is not the dynamic lights, but the dynamic shadows which they cast (they are not the same thing).

With this type of shader, the extra lights/shadows would be added via additional "passes". That means that each of the object's on-screen pixels are calculated more than once and combined into the final result. The more lights active in a scene, the more times each pixel is re-drawn (Keep in mind that the re-drawing doesn't only occur for illuminated areas).

With deferred shading (Advanced Lighting), point lights are drawn onto inverted cubes and each light has it's own cube (and its own shader). That means that additional lights (and their shadows) don't require additional passes, and that each light doesn't require an entire re-draw of each object.

There are many other reasons to use deferred shading for multiple shadows (much easier to manage multiple lights, separation of material and lighting calculations, etc..), but If you insist on using this particular shader I'll see what I can do about adding more lights.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 31st Aug 2011 13:49
That explains it really well, thanks for that Revenant I'm really interested to learn the theory of it.

On some recommendations I have started playing around with Advanced Lighting (which I imagine uses the Advanced Lighting you are talking about) but I've been running into some problems. You can read the forum post about it here:

http://forum.thegamecreators.com/?m=forum_view&t=188822&b=1

I've made a bit of progress getting it to work, but am still having trouble getting multiple lights to co-operate and due to that haven't really gotten close to projected shadows... If you wouldn't mind taking a look at my code I'd really love to hear your opinion. With luck once I've learned a bit more I can do my part to help others in the future!

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame

Login to post a reply

Server time is: 2026-07-10 10:19:48
Your offset time is: 2026-07-10 10:19:48