1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Real-time 3D light and shadows V2.0

Discussion in 'Work in Progress' started by lolslayer, Aug 8, 2016.

Tags:
  1. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    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: Oct 14, 2016
    Rukola, JacPete, Kahvana and 9 others like this.
  2. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    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:
    [​IMG]

    Game Maker's built-in vertex point-light system:
    [​IMG]

    My per-pixel point-light system:
    [​IMG]

    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. :)
     
  3. NoobsWeStand

    NoobsWeStand Member

    Joined:
    Jun 20, 2016
    Posts:
    147
    Looks great!
     
    Last edited: Aug 11, 2016
    Misty likes this.
  4. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    Thank you! :)
     
  5. Dogarooski

    Dogarooski Member

    Joined:
    Jun 21, 2016
    Posts:
    66
    This looks awesome! Just add texture filtering and MSAA and it'll look 934x better.
     
    Kahvana likes this.
  6. elementbound

    elementbound Member

    Joined:
    Jun 30, 2016
    Posts:
    114
    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.
     
  7. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    Don't ask too much from me :0
     
  8. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    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
     
  9. elementbound

    elementbound Member

    Joined:
    Jun 30, 2016
    Posts:
    114
    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 )
     
  10. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    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: Aug 17, 2016
  11. Roa

    Roa Member

    Joined:
    Jun 20, 2016
    Posts:
    570
    I understand the principles behind lighting, but I have never been able to figure it out in a shader. I'm glad we have people on here willing to do that :p
     
    Kahvana and KingdomOfGamez like this.
  12. Kahvana

    Kahvana Member

    Joined:
    Aug 16, 2016
    Posts:
    13
    ...Or gamma correction :3.

    @lolslayer nice work!, looks interesting n.n
     
  13. Alvare

    Alvare Member

    Joined:
    Aug 11, 2016
    Posts:
    48
    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.
     
  14. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    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 :/
     
    Kahvana likes this.
  15. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    Believe me, it takes less code to make this than you probably think it does ;P
     
    Kahvana likes this.
  16. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    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.
     
    Kahvana likes this.
  17. Multimagyar

    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?
     
  18. elementbound

    elementbound Member

    Joined:
    Jun 30, 2016
    Posts:
    114
    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 :)
     
    Kahvana likes this.
  19. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    forward as far as I got it right, but not deferred, and thx : 3
     
    Kahvana likes this.
  20. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    True that
     
    Kahvana likes this.
  21. Multimagyar

    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).
     
  22. Kahvana

    Kahvana Member

    Joined:
    Aug 16, 2016
    Posts:
    13
    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?
     
  23. Kahvana

    Kahvana Member

    Joined:
    Aug 16, 2016
    Posts:
    13
    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.
     
    elementbound likes this.
  24. Alvare

    Alvare Member

    Joined:
    Aug 11, 2016
    Posts:
    48
    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.
     
  25. Multimagyar

    Multimagyar Guest

    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.

    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)
     
    Kahvana likes this.
  26. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    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
     
  27. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    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
     
    Kahvana likes this.
  28. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    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 :)
     
    Alvare likes this.
  29. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    Some more news, I added cube mapping to the list of 3D graphical utilities, I'll probably show it when I'm home from vacation :)
     
    xygthop3 likes this.
  30. xygthop3

    xygthop3 Member

    Joined:
    Jun 20, 2016
    Posts:
    116
    Got an EXE demo we can check out?
     
  31. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    I was working on one for somebody who wanted to performance test it, when I'm back from vacation I'll upload it here aswell ;)
     
  32. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    upload_2016-10-12_14-53-59.png

    Little sneak peak for my new and more practical light and shadow project ;)
     
  33. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    upload_2016-10-12_20-21-13.png

    Another sneak-peak before the video
     
  34. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    upload_2016-10-12_22-58-53.png
    Just a little more teasing before the video is up, now in sexy fullscreen ;)
     
    Zek likes this.
  35. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    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 ;)
     
    Seabass (The Human) and Zek like this.
  36. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    No responds? :(
     
  37. Misu

    Misu The forum's immigrant

    Joined:
    Jun 20, 2016
    Posts:
    680
    Was hoping a downloabable link to try this out myself to do fps compare. Anyway keep up the good work.
     
  38. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    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?
     
  39. Misu

    Misu The forum's immigrant

    Joined:
    Jun 20, 2016
    Posts:
    680
    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.
     
  40. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    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 :)
     
  41. Fredrik

    Fredrik Member

    Joined:
    Jun 21, 2016
    Posts:
    190
  42. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    Oh my, how didn't I see YOU!

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

    Misty Member

    Joined:
    Jun 22, 2016
    Posts:
    1,073
    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.
     
    Aragon likes this.
  44. lolslayer

    lolslayer Member

    Joined:
    Jun 23, 2016
    Posts:
    695
    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.
     
  45. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    4,214
    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~)
     
    Roa likes this.
  46. Misty

    Misty Member

    Joined:
    Jun 22, 2016
    Posts:
    1,073
    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.
     

Share This Page