Real-time 3D light and shadows V2.0

lolslayer

Member
So I've been learning how to use shaders lately, and I wanted to give per-pixel point lights and shadows a try, and well, I succeeded doing that! :D

A gif of this project is found in my signature and by following this link: http://imgur.com/a/SkDhr (It was too big to upload on the forum)

In this scene there is one test room, one ball casting shadows and 2 light sources, one red light and one blue light.

Shadows aren't even close to being finished, so I'm not sure if I'll ever release them, but the point-light per-pixel lighting seems to work perfectly, so you can expect them to be released. Just remember me once if I forget, I tend to do that. ;)

upload_2016-8-8_23-45-4.png

P.S. I can confirm that it's 60 FPS, unlike the gif, but that's because of the gif convertor :/

P.P.S. This is a project where I test all my shaders, and my very first shader was based on a tutorial by xor, that's why you can see his test texture in my backgrounds folders, it also explains why there is a 💩💩💩💩 ton of shaders xD

Video:

Little sneak peak for my new and more practical light and shadow project ;)
upload_2016-10-12_14-59-51.png

Another sneak peak before the video:
upload_2016-10-12_20-22-4.png

Just some sexy fullscreen peaking:
upload_2016-10-12_23-0-28.png

IT'S FINALLY HERE!

A nice video showcasing my shadowmapping system, I'll probably update it in the future if I've got time for that. :)

Somebody also suggested me to make a tutorial about this, so I could give that a look aswell, maybe I'll do it, but it will be a little bit simplified compared to this then.

The reason for me to change the system was because the raycasted shadow system was too calculation intensive, it wasn't really practical for in-game use, this one is though.

Atm it's pre-baked, but I'll try to make it real-time ;)
 
Last edited:

lolslayer

Member
Showcase time!

This time I compare my point light system to the vertex light system of game maker and an unlit scene. Note, there won't be any shadows in it, only lighting.

Unlit scene:


Game Maker's built-in vertex point-light system:


My per-pixel point-light system:


Pros and cons of my point-light system compared to Game Maker's:

Pros:
-per-pixel lighting instead of vertex-lighting
-not limited to 8 lights only
-because of that this is already a shader, this lighting is easier to implement into other shaders

Cons:
-probably worse performance compared to GM's, but I only assumed this, I didn't really research it. This scene gave me an average real-fps of
around 2400 at a room_speed of 60
-a little bit harder to use at the moment

Everybody is welcome to ask questions about this project. :)
 
E

elementbound

Guest
-not limited to 8 lights only
I'm interested in how you achieve this. My solution was to draw everything lit by the first light as usual, set blend mode to bm_add, then draw it all again for each light. This is suboptimal but works for small scenes, so it was fine for me :D
Do you happen to do anything clever behind the scenes? I'd like to hear about your approach.
 

lolslayer

Member
I'm interested in how you achieve this. My solution was to draw everything lit by the first light as usual, set blend mode to bm_add, then draw it all again for each light. This is suboptimal but works for small scenes, so it was fine for me :D
Do you happen to do anything clever behind the scenes? I'd like to hear about your approach.
I didn't use game maker's vertex lighting at all, I just wrote a shader that did my lighting, shaders use another programming language then GML, so it can't even use GM's built-in lighting
 
E

elementbound

Guest
Yes, I know this, I did shader-based lighting myself too. But you have to pass light data to shaders too, and they also have a limited amount of uniforms and varyings to store data about the lights that need to be evaluated. So some workaround still needs to happen, I'm interested if you did that, and if so, how. I mean, only if you don't mind sharing.

( *than )
 

lolslayer

Member
Yes, I know this, I did shader-based lighting myself too. But you have to pass light data to shaders too, and they also have a limited amount of uniforms and varyings to store data about the lights that need to be evaluated. So some workaround still needs to happen, I'm interested if you did that, and if so, how. I mean, only if you don't mind sharing.

( *than )
I'm okay to share the code with you if you want to see how I did it, PM me about it.

NOTE I won't be doing this for everybody, so please don't all immidiatly ask me for it. xD

Also, I made a video about the light and shadow version of this system, here it is:
 
Last edited:

Alvare

Member
Lol, even though I have no shader knowledge, I'm not impressed by this anymore. Maybe it's because I have seen a couple of variants now, and it didn't work out for me, technically.
And when it did, gamemaker studio's compatibility messed it up for me.
"a little bit harder to use at the moment". What do you mean by that? A moving camera or the light source being moved?

I would be impressed if it is possible to have 2000 light sources in room that automatically deactivate in distance while keeping priority for the number that is closest to the projection.
And if shadows could overlap without looking bad.
 

lolslayer

Member
Lol, even though I have no shader knowledge, I'm not impressed by this anymore. Maybe it's because I have seen a couple of variants now, and it didn't work out for me, technically.
And when it did, gamemaker studio's compatibility messed it up for me.
"a little bit harder to use at the moment". What do you mean by that? A moving camera or the light source being moved?

I would be impressed if it is possible to have 2000 light sources in room that automatically deactivate in distance while keeping priority for the number that is closest to the projection.
And if shadows could overlap without looking bad.
I don't think that this one wouldn't work for you technically, what errors did you have? Because shaders have settings based on the operating system you use, so sometimes you need to change your shader settings to get shaders to work.

I don't have an automatic light injection method atm, so until I added that, you need to add in the lightpoint checking manually through my light shader.

2000 light sources? You know, giving them a priority automatically already takes a lot of calculations xD, for that I need to know how to use a quicksort mechanism and as far as now I don't.
 
M

Multimagyar

Guest
Pretty nice and smooth as I see! Kind of lacks of Normal and Spec mapping as I see, do you work in forward rendering or deferred?
 
E

elementbound

Guest
for that I need to know how to use a quicksort mechanism and as far as now I don't.
Lol, no you don't. Put your lights into a priority queue based on distance and take out the first few closest and done. You can use some more sophisticated methods for calculating a value to sort by, but the priority queues will most probably be sufficient :)
 
M

Multimagyar

Guest
Right. As a last question how many dynamic lights can it handle? (if it can handle 8 with smooth frame rate then I change that pretty nice to a pretty impressive).
 
K

Kahvana

Guest
Thanks :)

But man, all those suggestions

Please, let me try to add in specular lighting first xD, after that I'll give those suggestions a look, but they sound really complicated :/
Gamma correction is a full-screen post-process shader like sunshafts, so you might want to make that after the lighting x3 (example of gamma correction: this).
As for the lighting algorithm, do you use Phong or Blinn-Phong?
 
K

Kahvana

Guest
Lol, even though I have no shader knowledge, I'm not impressed by this anymore. Maybe it's because I have seen a couple of variants now, and it didn't work out for me, technically.
And when it did, gamemaker studio's compatibility messed it up for me.
"a little bit harder to use at the moment". What do you mean by that? A moving camera or the light source being moved?

I would be impressed if it is possible to have 2000 light sources in room that automatically deactivate in distance while keeping priority for the number that is closest to the projection.
And if shadows could overlap without looking bad.
The fact that we are able to run this s*** in game maker is already inpressive, right?. can't recall that realtime shadows where feasable in game maker 8, as far as I've got shadow working without DLL's. I think you should check if the configurations of the shader settings (aka OpenGLES/OpenGL/DirectX) are alright. and for 2000 lights, why don't you use deferred rendering or bake the lighting and import it on runtime?. Both approaches are faster than doing it in forward rendering :p.
 

Alvare

Member
Easier than done, no can do. I have mixed knowledge on both programming and artist/design with modeling software but I'm not specialized on any field in particular.
 
M

Multimagyar

Guest
The fact that we are able to run this s*** in game maker is already inpressive, right?. can't recall that realtime shadows where feasable in game maker 8, as far as I've got shadow working without DLL's. I think you should check if the configurations of the shader settings (aka OpenGLES/OpenGL/DirectX) are alright. and for 2000 lights, why don't you use deferred rendering or bake the lighting and import it on runtime?. Both approaches are faster than doing it in forward rendering :p.
Deferred rendering is nice for large amount of dynamic lights but that would also require a depth test from the perspective of the light to the model. you would not get away with a simple depth test from the player perspective unfortunately. Even without that, around 2000 lights your pc would cry in agony. Not to mention that deferred rendering on it's own has the unfortunate limitations of simple shader usage and a different demand for graphics cards. As bad as forward is today it's still can be superior on something like a mid range laptop than deferred rendering. Forward plus would be nice, and supposedly superior to both method.

Easier than done, no can do. I have mixed knowledge on both programming and artist/design with modeling software but I'm not specialized on any field in particular.
Alternatively you can have less active lights on the scene if you really cannot pre-render the lights onto the map nor to the vertex structure. but ideally you would want to pre-render these so you would get a faster game in general even if the loading time slightly increase. (partially the reason why I started researching how to import brush based maps into a vertex buffer)
 

lolslayer

Member
Right. As a last question how many dynamic lights can it handle? (if it can handle 8 with smooth frame rate then I change that pretty nice to a pretty impressive).
Didn't check that, but this scene with 5 lights gave me an average real_fps of 2000 at a room_speed of 60, I could give you an executable if you want where you add in lights to see what real_fps it gives to you ;)

PM me for that
 

lolslayer

Member
Gamma correction is a full-screen post-process shader like sunshafts, so you might want to make that after the lighting x3 (example of gamma correction: this).
As for the lighting algorithm, do you use Phong or Blinn-Phong?
I only did diffuse lighting atm, so no Phong or Blinn-Phong algorithm is present atm, I think I'll go for the Blinn-Phong algorithm though when implementing it, and thanks for the explenation
 

lolslayer

Member
Alternatively you can have less active lights on the scene if you really cannot pre-render the lights onto the map nor to the vertex structure. but ideally you would want to pre-render these so you would get a faster game in general even if the loading time slightly increase. (partially the reason why I started researching how to import brush based maps into a vertex buffer)
Just if you want to know, I'm researching multiple texture channels, so pre-baked light and shadows + normal mapping could be a thing soon :)
 

lolslayer

Member
IT'S FINALLY HERE!

A nice video showcasing my shadowmapping system, I'll probably update it in the future if I've got time for that. :)

Somebody also suggested me to make a tutorial about this, so I could give that a look aswell, maybe I'll do it, but it will be a little bit simplified compared to this then.

The reason for me to change the system was because the raycasted shadow system was too calculation intensive, it wasn't really practical for in-game use, this one is though.

Atm it's pre-baked, but I'll try to make it real-time ;)
 
M

Misu

Guest
Was hoping a downloabable link to try this out myself to do fps compare. Anyway keep up the good work.
 

lolslayer

Member
Was hoping a downloabable link to try this out myself to do fps compare. Anyway keep up the good work.
It is barely optimized atm, but it runs decent

In what way do you want to compare the fps? A real-fps counter which updates every 10 frames or so?
 
M

Misu

Guest
As in if it runs fast on a regular pc or not. I formly use Davve's shadow casting shader because it has a smooth shade transition (beautifully) and is real quick (easy) to set up. However performance is slow and comes with bugs (depending on the GPU. Wanted to know if this makes it any better.
 

lolslayer

Member
As in if it runs fast on a regular pc or not. I formly use Davve's shadow casting shader because it has a smooth shade transition (beautifully) and is real quick (easy) to set up. However performance is slow and comes with bugs (depending on the GPU. Wanted to know if this makes it any better.
Atm it works fine as far as I know on normal computers

It will work better though if I get to implement my ideas for performance upgrading, it will cost 24x less calculations if I get my performance improvement tests working :)
 

lolslayer

Member
Is this avable somewhere, like on yoyogames market place or some place similar to it? I'd love to use something like this in my own 3D game, if it's easy to implement into a project! :)
I really like the pixealted shadows as seen in one of the images. It could really fit into my pixel styled game :D
(https://forum.yoyogames.com/index.p...ed-first-person-dungeon-crawler-demo-2.20230/)
Oh my, how didn't I see YOU!

If you're still interested, PM me, then I can see how I can help you :)
 
M

Misty

Guest
I will pay 5 dollars for this.

Please have an option to keep it pre-baked, I want it pre-baked for the map but real time for the guns.
 

lolslayer

Member
I will pay 5 dollars for this.

Please have an option to keep it pre-baked, I want it pre-baked for the map but real time for the guns.
Sorry for the WAAAAY too late reply, I didn't get a notification lmao

That could work, but atm I'm trying to figure out deferred rendering which is imo really necessary for this aswell.
 

Yal

🐧 *penguin noises*
GMC Elder
Sorry for a random 2-year necrobump, but since you're still active on the GMC and have a GIF of your realtime lighting shader in your signature I'll assume this is still in active development.

Any plans to release this on the marketplace (or Itchio, or some other market platform)? Every existing 3D lighting example on the marketplace currently is either so limited it's essentially unusable (one of them is a shader with all 3D objects in the scene hardcoded into the shader code!) or does a lot of surface and object trickery that makes it too much work to be practically usable (and crashes whenever you change rooms because of memory issues). If all of this is handled by a shader that just sort of "just works" you've got access to the best available 3D lightning engine in GM, might as well profit off of it, right?

(You've got at least one presumtive buyer~)
 
M

Misty

Guest
it is against the rules to bump topics as old as these. I have discussed his technology with him. It will be done when and if it is done.
 

lolslayer

Member
Sorry for a random 2-year necrobump, but since you're still active on the GMC and have a GIF of your realtime lighting shader in your signature I'll assume this is still in active development.

Any plans to release this on the marketplace (or Itchio, or some other market platform)? Every existing 3D lighting example on the marketplace currently is either so limited it's essentially unusable (one of them is a shader with all 3D objects in the scene hardcoded into the shader code!) or does a lot of surface and object trickery that makes it too much work to be practically usable (and crashes whenever you change rooms because of memory issues). If all of this is handled by a shader that just sort of "just works" you've got access to the best available 3D lightning engine in GM, might as well profit off of it, right?

(You've got at least one presumtive buyer~)
Sorry for the extremely late response, I apparently don't receive pings when somebody responds to a thread of mine, so don't be afraid to mention me next time.
I'm not really planning to release this asset due to the extremely strong limitations that it imposes on the user. Basically, this system is a hybrid 2D/3D lighting+shadowing system where the shadows are 2D and the lighting 3D. Because of this, only maps that have perfectly vertical walls, only one level of a floor, and only one level of a ceiling, can work. I would love to finish up a practical 3D lighting+shadowing system one day but the problem is that it simply takes a very long time to polish such a system up, which I don't have at the moment :(
 

Yal

🐧 *penguin noises*
GMC Elder
Because of this, only maps that have perfectly vertical walls, only one level of a floor, and only one level of a ceiling, can work.
Doom 1 had those limitations and people still make maps for it to this day :p A flawed system is still better than no system, people that don't even have any idea how to reach that point would gladly use it and just work around the limitations.

(In the 4½ months since I posted that thing, I've basically focused super hard on making my own engine from the ground up, and I also have a system with 2D shadows placed in a 3D world - I currently just transform shadow coordinates into world space coordinates and mix the colors of a texture with shadows-as-seen-from-above-ignoring-z-levels together based on X/Y, but only for surfaces whose normal faces upwards... it has a lot of limitations and looks buggy in certain places, but it's better than nothing and looks pretty reasonable if the level doesn't make the limitations appearant)
 

Yal

🐧 *penguin noises*
GMC Elder
And oh yeah, didn't you make that sonic engine? 👀
The very same! And I'm still working on it to this day, actually. (It's a long story). I'm mostly done with converting it from GM8 to GMS2 standards, right now I'm focusing on adding some flair like dynamically rendered water and dynamic lightning. Now when this "let's finally make GM 3D a mainstream thing" arms race is ongoing and I finally am sort of competent, I'm not gonna get left behind in the dust :p

watereffects_stillimage.PNG
 
Top