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 / Oh great gods of Shader knowledge!

Author
Message
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 31st Aug 2011 07:53
Hi all, I try my best not to bug people on here with the same question too much as I like to learn rather than have things done for me, but I seem to be at a total impasse.

I've been coding for days trying to use multiple lights with shaders. What I would LIKE the program to do is to cast shadows and make use of some sort of normal/parallax/relief mapping on my surfaces, but I would like it to be able to do this using MULTIPLE lights that I have in my scene. I know that it's a memory hog, etc, but it happens in so many games (not baked lighting, but dynamic lighting) that I feel like I'm missing something simple.

So I've coded up a small mockup of what I'm trying to achieve and attached it to this post to see if anyone knowledgeable in shaders would be willing to take a look at it and tell me what I'm doing wrong.

What you'll find in the zip is a project and assets to load up a demo level created using cloned geometry which the player can move around in using a grid-based movement system (not smooth scrolling, I'm afraid, as I'm trying to simulate what I'll be using this for)

I've put a constant at the top of the code that when set to 1 will enable shaders. That way you can see what the level looks like first. When I enable shaders, however, it just all goes black. I've been researching this, reading up on it, trialling examples and doing my head in trying to make it work, but I'm finally completely stuck, so if someone could please give me a hand, that would be amazing.

Please note, I'm not looking for someone to write this for me. I want to learn so that I can better understand what I'm working with here!

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 31st Aug 2011 08:00
To help illustrate what I'm trying to achieve, here is another version of the project. Run this and walk around until you find the big black door. Stand back from it a bit and press the space bar and it will open. When it opens, light spills into the corridor from the room beyond, and it look great! However, I want my level to have MORE than just one light source able to cast shadows.

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: 31st Aug 2011 08:04
I would just recommend using Advanced Lightning. It's extremely simple, actually. You simply put parallax mapping on an object, add a point light (or several), position, color, and etc. Multiple lights and shadows automatically done!
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 31st Aug 2011 08:11 Edited at: 31st Aug 2011 08:11
That's what I've used in my code, and it won't work for me It's why I'd like someone to take a look and tell me where I've messed up...

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
taylor design
18
Years of Service
User Offline
Joined: 28th May 2008
Location: Germany
Posted: 31st Aug 2011 10:00
The shader has to calculate for each light source. I am not sure about the multiple shadows, but multiple lights are rendering the same pass for each light and add the pixelcolor to the previous rendered. Loops are possible within the shaders. If you want multiple shadows, you could try stencil shadows, too.

I use the same "CubicShadowMapping.fx" like u, and I gonna make a multiple-light shader. If it is done, I will post it here.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 31st Aug 2011 12:06
Thank you. I'll keep an eye out for it. I'll be doing the same as I am still experimenting while trying to get help! I made some small progress today, but nothing as to what I need

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 31st Aug 2011 12:53 Edited at: 31st Aug 2011 13:50
Well, I've made a little progress. I can place multiple lights in my scene using shaders, however, they turn on and off depending on the camera's distance/angle from them... It's strange. I'll place one at one end of a hallway and another at the other end, but when I place the second one, the first one goes out. Then when I go down to that end to try and turn it back on, it turns itself back on, then goes out again... Any ideas?

*EDIT: I've attached my code so far*

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 31st Aug 2011 14:32 Edited at: 31st Aug 2011 14:34
Quote: "To help illustrate what I'm trying to achieve, here is another version of the project. Run this and walk around until you find the big black door. Stand back from it a bit and press the space bar and it will open. When it opens, light spills into the corridor from the room beyond, and it look great! However, I want my level to have MORE than just one light source able to cast shadows."


Well it does look amazing yes, but the door shadow never moves so you could still hard bake it, and just switch textures on the wall. You would need real shadows if it had a candle in there, and the shadow moved around.

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 31st Aug 2011 14:53
Thank you Yes, I'd like the level to be able to have 3 or 4 static lights that cast shadows when doors are open, etc, but I'd also like the player to be able to carry a candle or torch to provide a moving light that will also cast shadows.

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 16:17
Hi again CumQuaT, I looked through your demo and I noticed a few strange things.

You CANNOT mix and match random shaders with the advanced lighting system. Only shaders which are specifically written for advanced lighting can be expected to function properly.

Darkshader (the dll which this advanced lighting uses to render point light shadowmaps) only supports 9 dynamic cubemaps, which means a maximum of 9 shadow-casting point lights. When you call "AdvancedLighting_SetUp()", the last parameter should never be higher than 9.

Only objects which are expected to move should be dynamic ('Object_Set_Dynamic()'), all others should be set to static ('Object_Set_Static()').

Animated objects don't really count as "moving" objects. That is because their position/rotation may not have actually changed, yet still require a shadow update. "Object_Render_Shadows()" should be called each loop for objects which are animating.

"COLOR OBJECT" and most of the other DBPro object appearance commands dont work with shaders. That includes: Diffuse, Emissive, Specular, Ambient, etc...

Typo: In the "UseShaders = 1" statement just before the main loop, you created light2 but then defined properties for light1

note:
---------------
Spot lights should be used in favor of point lights when ever possible. Spot lights are much faster to update because they only require a sixth of the information for their shadowmaps.

I have attached a mostly fixed version of your demo. I would advise that you remove all of non advanced lighting shaders from your project folder.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 31st Aug 2011 16:39 Edited at: 31st Aug 2011 16:39
You, sir, are a gentleman and a scholar.

Interesting to know about the animated objects being static. So really, all of my "level" objects that technically aren't moving are static, except things such as enemies that will cast shadows. That's good to know.

Definitely going to keep playing around with this demo project and see how far I can push it and work out the ins and outs of how this all works.

I can't thank you enough! Let me know if you ever need some 3D or art assets for your projects and I'll help you out

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 31st Aug 2011 16:44
You need to get the game slowed down as well, the door demo was so fast on my computer that I had to edit it. Even 60fps was too fast.

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 31st Aug 2011 16:55
Yeah, what I sent was just a little test map I could use to get the shaders working. The actual game is using CometSYNC which sorts that problem out nicely

@Pincho and @Revenant - What can I credit you two with in the game's credits for helping out?

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 31st Aug 2011 18:46
You don't need to credit me. I have only made suggestions.

revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 31st Aug 2011 19:01
You don't need to credit me either, but I may take you up on that 3D art assistance.
enderleit
19
Years of Service
User Offline
Joined: 30th May 2007
Location: Denmark
Posted: 31st Aug 2011 21:49
Put a "Special Thanks" section in the credits...

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 1st Sep 2011 01:32
@revenant any time!

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

Login to post a reply

Server time is: 2026-07-10 20:57:50
Your offset time is: 2026-07-10 20:57:50