Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Is Forward Rendering the way to go instead of Deferred Rendering?

Discussion in 'General Graphics' started by ArachnidAnimal, May 16, 2015.

  1. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    After struggling now for many months with trying to work with only being able to exclude 4 layers from lights in deferred rendering, I am now wondering if forward rendering is the way to go.
    Basically, my scenes have many lights but most likely any given light needs to illuminate not more than 2 layers at a time.
    However with the inability to exclude more than 4 layers in deferred rendering mode is causing major headaches.

    Knowing this:
    The scene has many lights.
    Any given light does not have to illuminate more than 2 layers.
    I can exclude 30 layers in the culling mask instead of just 4.
    Major issues with working with the Unity standard shader in transparent mode with respect to the Pixel light counts needing to be increased to 8 just to get past the culling mask limitation
    More HW supports forward rendering vs deferred rending.


    Knowing this, is forward rendering the way to go?
     
  2. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Warning, lots of text incoming :)
    Summary: Deferred is in general alot better for many lights affecting stuff in the view at the same time. But even unity's current deferred could be quite a bit better/faster. Forward can be great for laptops, especially if your ok with dropping most of the lights.....)
    You could also modify forward to make better use of the 4 "per vertex" lights sent in together, however unity does talk about the same light being in both per pixel and vertex...

    This screams deferred if many are visible on the screen at any one time, especially if you have been needing to up your pixel light count to prevent flickering/popping.
    How many different layers in total do lights actually affect? (While unity has some limitations there are not to hard to implement workarounds I can explain).
    Well, sure, in theory if unity was a bit more kind they could allow us to "use" up to 4 layers, so any light could include or exclude that one layer. (Either exclude all+any number of the 4 layers, or include everything but a set of those layers).
    Umm, that's probably because the transparent mode -> Object is rendered in forward mode, so deferred vs forward wouldn't matter for those objects/culling masks against them I believe. So this point is moot. (I think that's how the word moot is meant to be used?)
    Are you targeting mobile? If so, then yes, for desktops, well, MRT's have been around for a long time, and the desktop hardware that doesn't support them isn't really expected to run ANY game today, at all.

    Personally I think clustered/tiled deferred is the way to go, but that's me. It also allows us stuff like deferred decals, ("projectors" that are fully lit / only modify say normalmap, or only modify diffuse ect).
    And while this might seem like a massive task, I know it can be done quite easily as we have done it. (Took approx 2 days of work for a simplified tiled version).
    (Forward clustered on laptops possibly).


    Actually "all" unity really needs to do to get the performance of forward mode with many lights ALOT better is to send more lights per pass! (Less draw calls, less texture samples, less state changes due to new light data sent.....)
    I have been considering trying something like this using the MaterialPropertyBlock but we made a simple world space tiling instead. (xz world position is used to sample the index texture, making the index texture not need so much updating, and the updating alot simpler math wise!)
     
    ArachnidAnimal likes this.
  3. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    All of this issues will be relieved once I complete the light baking. The forward vs deferred issue would not even be an issue anymore. I am currently baking lights into the scene then gradually eliminating the lights and reducing the pixel light counts down to 1 .I do not need more than 1 realitime light. If Unity made the process of lightbaking more easily done in baby steps (maybe in sections of the scene at a time) then allot of my issues would be resolved. The issue I am having is visualizing the scenes w/o the lightbaking which is what drove me to convert to a forward rendering scheme. I am now using a "forward -> deferred" development approach which is now working out well for my project, so far. (This approach was recommend by a buddy of mine who devs games for xbox and PS). lightBakComplete.png
    Completed 1st light bake.

    lightBakComplete2.png
    second area lightbake/reflections complete.

    lightBakComplete3.png
    third area lightbake complete
    so far it seems to be working. I hope to get the required pixel light counts down to 1.
     
  4. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Well, if you can use lightbaking, of course go for it!
    Perhaps don't delete the lights but set them to bake only?
    If your down to 1-2 lights that need realtime at the same time, then absolutely go forward mode!
    Can you explain why you need to bake the different parts of the scene separately? (Baked lights shadows will prevent them from passing trough walls if that's the issue). Generally it's simplest just telling an entire scene at a time to bake.
     
  5. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    Because i screwed up and didnt set the "continuous baking" box on when I first started the scene :-(.
    Now, to do the lightbaking for the entire scene at once is overwehlming Unity and I cant even complete the lightbaking at the lowest possible resolutions. It doesnt complete the lightbake, It is too overwhelming for Unity (5.0.1). This is why i went religious with setting 20 layers or so to not overwhelm unity during lightbakes.Really, I am not setting meshes to cast shadows that much which might be part of the problem of why I needed so many layers.
     
  6. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Well, loads of shadowcasting lights isn't really viable in realtime, so that's reasonable.
    And meshes are by defaults set to cast shadows.
    So your unity chrashes/locks when lightbaking your scene I take it? (Sad unity, sad!)
     
    ArachnidAnimal likes this.
  7. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    I really thing the light baking functionality needs work in Unity. there are loads of bug reports submitted with the same issues (getting stuck at phase 5/11, or 7/11) for no apparent reason. This is why i think they need to figure out a way to allow lightbaking to be performed on individual sections or individual lights, so we can do this in baby steps. Maybe there's already a way to do this, but I havent figured it out yet.
     
  8. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    I found this:
    http://serrarens.nl/en/lightmapping-issues-in-unity3d-solved-almost/
    it might be helpful to me
     
    theANMATOR2b likes this.
  9. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    It is a unity design flaw to make physics layer tie in with rendering layers, so unfortunately deferred is almost useless unless in simple scenes.
     
    ModLunar and ArachnidAnimal like this.
  10. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    with a scene with many lights and much geometry such as doors and walls and windows, the culling mask 4 layer limitation in deferred mode is quite the hassle. because you now essentially need everything to cast shadows to "block" light bleeding.
     
  11. GamerPET

    GamerPET

    Joined:
    Dec 25, 2013
    Posts:
    370
    So... it's 2017. Forward or Deferred?

    Or... let me ask more nicely. For a 3D scene where you are aiming for Realism, what should you use?
    Also, when is good to use Forward, when is it good to use Deferred?
     
  12. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    Probably deferred.

    Do you need a lot of real time lights?
    Deferred.

    Do you need to render with MSAA or a very high resolution or on a low end device?
    Forward.
     
    daleth90, ModLunar, pixelR and 5 others like this.
  13. GamerPET

    GamerPET

    Joined:
    Dec 25, 2013
    Posts:
    370
    What about Color Space? Linear or Gamma?
     
  14. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    Are you making a game with no lights (2d sprites, unlit or pre-lit textures)? Are you making a mobile game? Are you trying to make a game that looks like an old (early 2000's or prior) game?
    Gamma.

    Otherwise Linear.