Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Light Bleed

Discussion in 'General Graphics' started by boxhallowed, Jan 4, 2018.

  1. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    I'm a bit stuck, and I've tried just about every solution I can find from:
    - Deferred Rendering
    - Casting Two Sided Shadow
    - Point Light Casting Shadows Is On
    - Tanking the Normal Bias
    - The walls have thickness.
    - The walls are overlapping, tried perfect butting too.
    ect

    There are no directional or ambient lights. I've tried all of the lighting settings for compression, pixel, ect. Not sure where to go from here.

    I have rooms which are procedurally generated by chunks, and I'm getting light bleed from the next room. I can not bake as everything is 100% procedurally generated. If I have to buy an asset that's fine. I don't need AAA lighting, actually something more akin to Doom 3 would be fine with me.

    Example, see light bleed on edges and ceiling from next room.
    upload_2018-1-4_17-29-57.png

    Screenshots and Vid: https://forum.unity.com/threads/light-bleed.511212/#post-3345113
     
    Last edited: Jan 7, 2018
  2. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    If you could turn off all the lights except for the one in the other room that's bleeding through, It would help diagnose the issue faster.
     
  3. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    I'll go one further, a single pointlight.

    upload_2018-1-4_23-4-50.png

    The walls do have thickness, I intersected them at 4 points to seal them as a test, and I even tried Two Sided for shadows on them.
     
  4. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    I went ahead and pumped up the wall thickness, same deal.
    upload_2018-1-4_23-23-4.png
     
  5. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646

    see how the shadow from the inside wall look offset to where the red arrow is. if you change shadow bias (not the normal bias) really close to 0, like 0.001, that will bring that red arrow closer to where the shadow should actually start.

    also set normal bias to zero.
     
  6. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    I did so, and that seemed to help a bit, but I'm still getting light leak from the corner. I didn't mean to take up your time with this tonight, I do appreciate the help anyhow.

    upload_2018-1-4_23-48-6.png

    upload_2018-1-4_23-48-26.png
     
    Last edited: Jan 5, 2018
  7. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Are you changing this setting on every light? You have to do it for every one.

    Last thing to check is what quality your shadows are set to, Check unity quality settings and put them in the highest to see if that helps. Unity's shadows are pretty bad...
     
  8. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    Yeah, I'm instantiating a prefab with a point light, so when I change the settings for it, they are all changed. I restart the game just to make sure the graphics setting changes have taken full effect. The shadow quality is set to "Very High Resolution". No dice.
     
  9. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,866
    Send me your model
     
  10. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    There are no models, the floors, are simple 1x1 quads and the walls are simple 1x1 cubes with .5 thickness. To reiterate my first post, there is no lightmap baking, this game is 100% procedural. There are no premade models outside of those pieces, that it assembles the room with.
     
  11. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,866
    1. Your problem is related to Edit->Project->Quality settings (Specially shadows)
    2. Your model scale is too small . Increase its scale according to 1x1 metter simple unity cube
     
    jumisko likes this.
  12. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    If I make the model any bigger it won't work, a model of 1 x 1 x .5 should be plenty thick enough for shadows. For a test I doubled the size and it didn't help.

    I have tried every solution related to quality settings. I've searched through every post on Unity Forums related to this matter. I've been through several pages of Google. The only solution I can come up with is going to be custom shaders.
     
  13. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    Should I report this as a bug? I can't seem to find anyone who has had this problem, and found a solution to it. If I had to guess, a pieced together procedural room isn't possible without shadow acne and light bleed, regardless of settings.
     
  14. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Not sure if you're lightmapping or it's all realtime lighting. Honestly confused sorry :/
     
  15. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    All realtime. No lightmapping. The rooms are assembled from pieces, the rooms are dynamically generated. Thanks for any tips, pointers, help, anything. Additionally, I tried to find if there was a way to generate lightmaps while the game is running, so when I generate a room I can generate the lightmap on the fly. No dice.
     
  16. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    OK some more questions which I need clear answers to:
    1. do you have a screenshot of a game's visuals you want to copy
    2. does it need to be modular at runtime or modular at edit time
    3. is it for mobile devices or VR?
    4. Do you refer to the bleeding on the vertical wall segment here and NOT what Lexie is talking about?
    upload_2018-1-7_15-53-5.png
     
  17. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    1. I'm alright with Unity's default lighting system if I can get it to work. I would prefer a style of idTech 3's engine, but Unity is fine.
    2. Modular at run time. The rooms are generated from pieces, the rooms are destroyed and made on the fly.
    3. PC only no VR.
    4. It happens on the horizontal and vertical where the walls meet and the ceiling/floor meets the walls, it doesn't happen between wall pieces. In that image that wall is 3 units high, that means it has 3 1x1x.5 meshes stack on top of each-other and extending the length of the wall.
     
  18. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    Small example of bleeding. Associated screenshots, these aren't the only settings I've tried either, this is just the current attempt with Unity's lighting system. To clarify, once again, this is all 101% procedurally placed. Nothing in the scene is placed before it starts. The rooms are created and destroyed on the fly.

    http://sendvid.com/dyon7vul

    upload_2018-1-7_11-16-37.png

    upload_2018-1-7_11-16-49.png

    upload_2018-1-7_11-17-12.png



    upload_2018-1-7_11-17-46.png

    upload_2018-1-7_11-18-1.png
     
    Last edited: Jan 7, 2018
    KtrlZed likes this.
  19. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Any lights which aren't set to cast shadows will cause bleeding. Because of how realtime rendering works: lights always have an effect* but shadows mask it. If the light does not cast shadows, or the shadow distance is too small, your lights will appear to be bleeding.

    In reality, the shadow simply isn't being rendered either due to max range or the mesh cannot receive shadows or the light is not set to cast shadows.

    Note: you will not get an exact Quake 1/2/3 look because you have no radiosity in your scene, only realtime shadows. This is easily fixed later and we can address that separately if it's even required.

    *Assuming no tile based light culling is taking place and it won't be for legacy unity renderers - you can disregard this until SRP HD.
     
  20. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    I might be wrong here, but all of my settings above have the light casting shadows, and I even set the meshes to Two Sided as an experiment at one point. You can see the settings of my lights in the above images. I have the environmental light set to nothing so I can have a completely pitch black room if I want one. So the lights are set to cast shadows, I tried hard and soft, and the meshes are set to cast shadows.
     
  21. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Onx likes this.
  22. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    That's a lot of lights. I suspect the issue is being caused by how Unity handles large numbers of dynamic lights.

    There's a Quality setting for "Pixel Light Count" that defaults to 4. That means only the first 4 lights closest / brightest for an object will be rendered per pixel, the next 4 after are rendered per vertex and only per pixel lights have shadows.

    Try increasing that number to 99. Your framerate might die, but you can at least test to see if that's the problem.
     
  23. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
  24. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    I took it 99, no difference. I've tried to cut the number of lights by 2/3 and it still does it, even with a single light it still does it. See the dark picture above.

    upload_2018-1-7_13-25-6.png
     
  25. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    I went ahead and made Ultra the only option as well.
     

    Attached Files:

  26. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    It really does look like you're baking lightmaps though. That behaviour would be normal for a lightmap (and has it's own set of solutions) but you said that it's realtime.
     
  27. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    100%, nothing exist in the scene until I hit "play" behavior is both in PIE and in the compiled game.

    Not running.

    upload_2018-1-7_13-44-47.png

    Running.

    upload_2018-1-7_13-42-53.png

    Another room generated.

    upload_2018-1-7_13-43-16.png
     
  28. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,631
    Try reducing shadow distance and see if that helps.

    Also, is there any way you can get away with using spotlights instead of point lights?
     
  29. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    I will give spotlights a try and I will set shadow distance to 1 and see what happens. I want to clarify any confusion, that this thing is built with pieces.

    upload_2018-1-7_13-46-39.png
     
  30. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    A shadow distance of 1 exaggerated the problem greatly, I can not get the look I want with spotlights, I can barely get it with point lights.
     
  31. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,631
    1 is probably too low, I had something like 20 in mind.
     
  32. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    No dice, but I appreciate the help though. Does not seem to have worked.

    upload_2018-1-7_13-51-40.png
     
    Legion555 likes this.
  33. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,631
    Something's iffy. I tried recreating it, but it seems to work fine for me:

    Screen Shot 2018-01-07 at 20.58.08.png

    And I think the thickness of the wall is similar (I took a basic unity cube and scaled it to 0.1 on one axis), so I'm not sure what's going on.

    EDIT: NVM I did it, let me try some things.
     
  34. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    Did you place that in the level, and then put the light in, and then click "play", or did you dynamically place it via code and then place the light, and then generate another adjoining structure and do the same? None of this is placed at all before runtime, it's dynamically generated and destroyed.
     
  35. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,631
    I did it manually, anyway it doesn't matter, I think I recreated it, I just needed to place a point light further away from the wall.

    Screen Shot 2018-01-07 at 21.08.00.png

    This is it, right?

    And you're right, it doesn't get better than this, regardless of bias settings.

    So the conclusions are:

    1. Point lights suck. But spots don't work for you.
    2. Since it happens from lights that are further away from the wall, maybe reducing the range of all the lights may reduce the issue. But that might or might not work for you.
    3. Double the width of the walls. That should take care of it.
     
    bgolus likes this.
  36. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    I took the walls to a thickness of 1 unit and it was still happening. Also no, the lights are procedurally placed based upon an algorithm, including things like lamps and other light sources. I can't control how close to the wall they get. I would also like to add, that even if increasing the wall size did help, it would thicken it to such an extent that it would be a small hallway instead of a door frame. I've tried a thickness all the way to 1 unit just to exaggerate it, and it's just not fixing the issue.

    upload_2018-1-7_14-19-58.png
     
    Last edited: Jan 7, 2018
  37. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Looking at the screenshots closer (and not just on my phone) I can tell you with complete certainty that @Lexie ‘s original explanation is essentially the correct one, and @AcidArrow further proved that, though the solution is not as straightforward. Basically, Unity’s point light shadows suck for legacy reasons and act differently than spot lights and directional lights.

    That is to say ... they’re always bad.

    A fully custom system might work better, but like I said in another thread, that’s a ton of work. Also, having that many shadow casting lights is going to be really bad for performance.

    What you want is to bake the lighting, but at runtime. Unity doesn’t offer any tools for this, but others have implemented it themselves before. For example:
    https://forum.unity.com/threads/procedural-static-point-lights-with-source.349155/

    I don’t know if that project still works, but it’s pretty much exactly what you want. I also don’t know if it will actually fix the light bleeding issue though depending on how they implemented their point lights.
     
    maya-papaya and theANMATOR2b like this.
  38. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    I will happily give this a shot and see what happens. I really appreciate all the feedback, this has had me pulling my hair out. I had no idea that pointlights were separate from other lights until this thread.
     
  39. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    Ah bummer, got it to compile and I can drop the piplights in, but they don't seem to have any effect. It needs to be set to linear with deffered rendering, but I can't seem to get it to work. I will experiment with it some more tonight and see what I can do. I can see it in the command buffer, there are some custom shaders, but they are intentionally hidden so I assume I'm not suppose to do anything manual with those.

    upload_2018-1-7_14-48-7.png
     
  40. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    On the topic of lighting quality you've mentioned Quake, idtech 3, and Doom 3. That's three very different engines, with the first two using precomputed light maps which are, perhaps surprisingly, still difficulty to replicate in real time. Especially idtech 3 (Quake 3 Arena being the first game to use that engine) which while the lightmaps are low resolution and have ugly compression artifacts, are generated at quite high quality even by today's standards. Quake 1 is less complex with only baked direct lighting, but is still much more accurate in terms of preventing light bleeding than almost any modern real time shadowing system.

    Doom 3's stencil based shadow volumes are much more accurate, but would behave poorly with how you're generating your levels. That technique really heavily prefers extremely low poly meshes, low numbers of meshes, and welded vertices. Building your walls out of hundreds of individual quads will produce tons of seams in the shadows. I've also not seen anyone successfully get stencil shadow volumes working in Unity 5, though it should be possible.
     
  41. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    So my best bet is to fake a directional light using shaders as in my previous attempt. Then for anything that has a "shadow" outside of the simulated directional, I need to use a blob decal. Since I don't want to rewrite the entire shader engine. As in what I'm trying here:
    https://forum.unity.com/threads/custom-lighting.511491

    So my question comes back, instead of plugging my camera position into the DOT function, what do I use to specify another position, to simulate directional lighting?
     
  42. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    What happens when you bump the res of the point light shadows up a bit? And what version of Unity are you working on?
     
  43. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    Doesn't help, latest stable.
     
  44. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Nothing, since the problem is the depth resolution rather than the shadow map's pixel resolution.
     
  45. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    I'll answer this back in the other thread to keep the topic separate.
     
  46. Neil-M

    Neil-M

    Joined:
    Mar 13, 2015
    Posts:
    3
    Hey @The-Britain . I was having same issue with light bleeding through edges. But there is a workaround for this issue. The light bleed appears when two different meshes are in contact. But if you keep all the walls as a single mesh in blender, there would be no light bleeding. For me, this is the only workaround. Hope this helps...
     
  47. karl_kent

    karl_kent

    Joined:
    Feb 1, 2018
    Posts:
    10
    that looks like peter panning, from a bias that is too high on the shadow properties
     
  48. SongAngel

    SongAngel

    Joined:
    Jan 21, 2013
    Posts:
    4
    I know this is an old thread but it still shows up in search results and my response may help someone else. The fix for me was to change the default rendering path on the main camera to deferred. That stopped the point lights from bleeding through the walls and created proper shadows.
     
    Graham-B, jumisko, HurlyBurly and 3 others like this.
  49. HurlyBurly

    HurlyBurly

    Joined:
    Jun 28, 2018
    Posts:
    5
    Thank you! Switching to deferred stops all the light bleed for me. Phew! Was wasting so much time.
     
    Graham-B and jumisko like this.
  50. Onx

    Onx

    Joined:
    Jun 4, 2018
    Posts:
    4