Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Directional Light still affecting objects in shadow (Def Lighting)

Discussion in 'Editor & General Support' started by Matthew Scott, Mar 3, 2014.

  1. Matthew Scott

    Matthew Scott

    Joined:
    Jan 16, 2013
    Posts:
    33
    It's a very frustrating problem. I have a directional light in my scene which will be rotated during gameplay to simulate day night cycles.

    The directional light (which is set to cast soft shadows) is working perfectly well for exterior of the house. The side of the house that is away from the light is shadowed, and, the correct amount of light pours through the windows onto the modular assets of the interior of the building.

    HOWEVER, the modular objects INSIDE the house, which (unless they're infront of a window) should be recieving no light at all from the directional light, still seems to be marginally affected by it when I rotate it.

    They aren't lit up like they would be if I set the DirLight to NO Shadows, but they have a glimmer/shimmer to them, which I originally thought was the specular/normals still taking the Dir light into account even when it shouldn't, the the same thing happens if I use a standard Diffuse only shader.

    I really don't want to have to set up light layers as I am using DEFERRED rendering and I only have a limited amount of those which need to be used for a far more important feature.

    Any else had this problem before?
     
  2. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    As far as I know, directional lights in Unity aren't really deferred, since they have infinite volume. I believe they are rendered as part of the main shaded pass, or in their own separate full screen pass. In any event, I'm guessing you're seeing shadow precision issues, you can try to tweak the number of cascades, cascade resolution, and shadow bias, but in the end you may find that layers is the least worst option.
     
  3. Matthew Scott

    Matthew Scott

    Joined:
    Jan 16, 2013
    Posts:
    33
    The problem isn't shadows though, the shadows are rendering correctly, the problem is when a object is meant to be sitting somewhere completely occluded by another object (can't be hit at all by the directional light rays), yet it still becomes lit.

    Lets say for example inside the house I have a glass vase using a transparent shader, sitting inside a cupboard with the door closed, the vase becomes pale and almost white because its becoming lit by the directional light, if I turn the light off, its fine...the cupboard walls are meant to leave the interior of that cupboard in shadow, which it is, except the vase refuses to be NOT lit...its toggled to cast/receive shadows...Could it be the shader approximating some lighting? Any default shader has the same problem though...
     
  4. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    Is it only transparent objects that are not receiving shadows? Some transparent shaders do have that problem. If you use a diffuse, opaque shader does that fix the problem?
     
  5. Matthew Scott

    Matthew Scott

    Joined:
    Jan 16, 2013
    Posts:
    33
    Well we were using a custom shader, out of curiosity we changed it to Unity's built in bog standard diffuse and it was still happening...Even other objects that aren't transparent suffer from the issue, its just that transparent objects seem to be more noticeably affected.

    You know, I just had a thought, it might be something to do with our Camera set-up, and that fact that we're layering...for FPS using depth only cameras and such...could it be that the lighting/shadows are being improperly overwritten by another camera? I think this happens with our guns...if you stand inside shadow..the camera that draws the weapon doesn't recognise the weapon is in shadow and it comes up fully lit..but I'm sure the problem even happens in the editor too which makes no sense....
     
    Last edited: Mar 12, 2014
  6. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    Can you post a screenshot or two? A picture, as they say, is worth 10^3 words.
     
  7. Matthew Scott

    Matthew Scott

    Joined:
    Jan 16, 2013
    Posts:
    33
    $Test1.jpg

    Sure! As you can see here, this a perfect and simple example...you can see in the larger shot, the box (a basic unity cube with its default shader) is clearly sitting within the shadow, the directional light is pointing directly onto the face that faces us, lighting it up brighter than the other faces (the box shouldn't getting hit at all by the directional light as it's sitting behind another object blocking the directional of the rays, the smaller insert shows that if I rotate the DIR light, it is now lighting up the face on the left side, but the box is still sitting within the shadow!! It's not completely lit (granted) but it's not right, when you have a shader with normals and spec this slight inaccuracy is really amplified making everything look incorrectly lit...This is taken from the editor window, so I don't think its a camera layer issue, otherwise it wouldn't happen in the editor..

    Both the floor, box and everything else is all on the dame default layer, the box is set to both cast and receive shadows. Deferred lighting...same thing happens in forward....
     
    Last edited: Mar 12, 2014
  8. Matthew Scott

    Matthew Scott

    Joined:
    Jan 16, 2013
    Posts:
    33
    Okay, so, by turning the shadow strength up to 1 (full strength) it has solved the issue with the box, and most of the other objects in the scene, but I'm getting the same still with any object that uses the transparent diffuse shader (Unity shader)...

    Transparent Cutout Diffuse doesn't seem to have a problem...so I guess it's a shader related issue or I need to tweak the trans shader....Any ideas, or anyone have this problem before and found a resolution?
     
  9. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Shadows don't work with transparent shaders in general.
     
  10. Matthew Scott

    Matthew Scott

    Joined:
    Jan 16, 2013
    Posts:
    33
    Hmmm, well isn't there anyway I can manage a workaround for this? I don't need transparent objects to cast or receive shadows but I certainly don't want a trans object being lit up weirdly for no good reason...Can't I set the transparent object to be unlit? Then use the color modifier to make it darker and lighter depending on the scene ambiance of where it is?
     
  11. Matthew Scott

    Matthew Scott

    Joined:
    Jan 16, 2013
    Posts:
    33
    For anyone experiencing the same issue, this is my workaround...a quick trans shader for approximating your lighting (greyscale-wise), stops the wierd lighting issue, it'll suffice as long as the lighting conditions on the door wont change dramatically....If anyone has a better suggestion...please enlighten me...

    Shader "Unlit/TransparentColorMod"{

    Properties{
    _Color ("Color Tint", Color) = (1,1,1,1)
    _MainTex ("Base (RGB) Alpha (A)", 2D) = "white"
    }

    Category{

    Lighting Off
    ZWrite Off
    Blend SrcAlpha OneMinusSrcAlpha
    Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}

    SubShader{

    Pass{

    SetTexture [_MainTex]{
    ConstantColor [_Color]
    Combine Texture * constant
    }
    }
    }
    }
    }
     
  12. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    I am having this exakt problem, first pic with directional lighting off, and second with it on. No dir.light hits this part of the scene. This is a cuustom shader to get both transparent and reflective behavior, but I get same result with the built in ones. Can you please tell me how I should use your above shader? Thanks
    light_off.png light_on.png
     
  13. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    One way of solving this was to move the transparent shader object(s) to a seperate layer and remove that layer from the dir.light culling mask. Is that the best way?

     

    Attached Files:

    buttmatrix likes this.
  14. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    THANK YOU SO MUCH
     
  15. Vagrod

    Vagrod

    Joined:
    Aug 4, 2017
    Posts:
    82
    Sorry for noob question, but I have "Directional Light still affecting objects in shadow" problem too. In my test scene I have totally sealed object with a sphere and camera inside. Sealed object is not one-sided, it's two-sided geometry with correct normals. I am using Linear/Deferred and Mixed for single Directional light in this scene. Light is moving during a day and changes its intensity.
    Both sealed object and sphere are using Standard shader with some texture. Cast shadows is On on both objects.
    Here is a question: why sphere clearly receives light and even shows lightspots if it is inside an object without any holes? And for the same reason I guess interior of this sealed object is lit. I expect in this case to see pitch black image, because I have no light to reach the camera.
    I can understand, why both this objects receive ambient light, but I cannot get how to configure and what exactly to configure to make such rooms with lighting that makes sense.
    For now, I'll make a script that will reduce sun intensity down to 0 as player pass into the cave, and bring intensity back if player will start approaching cave exit.
     

    Attached Files:

    Last edited: Oct 1, 2017
  16. Smith_076

    Smith_076

    Joined:
    Feb 6, 2020
    Posts:
    17
    I am in a similar situation, i have an underground level in my game and the direction light effects the walls of the rooms, something to do with layers?
     
  17. Smith_076

    Smith_076

    Joined:
    Feb 6, 2020
    Posts:
    17
    My workaround for this was to use light layers, i set the lights in my underground level to a specific light layer and then set the rendering layer mask in the mesh renderers as the same light layer as earlier. I use light layer 7 for both.