Search Unity

Sun vs Directional Light and flare

Discussion in 'Editor & General Support' started by zumwalt, Mar 4, 2008.

  1. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm not sure what you mean...I don't see any lit walls here. If you're not seeing this, there's a problem somewhere.

    Edit: hang on, I think I left the shadow strength at .7 or .8 when I uploaded that. Have I mentioned that objects don't actually block light and that shadows are just added on top? ;) Any shadows with a strength of less than 1 will show the "natural" lighting underneath to some degree, depending on what the strength is.

    --Eric
     

    Attached Files:

  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Actually that is not true. Shadows do indeed block light (by default they don't block all light from a light source, but setting shadow strength to 1.0 will block the light from that light source).

    The end equation is roughly this:
    Code (csharp):
    1.  result = ambient + sum_for_each_light( light_computation * shadow_term * cookie )
    where 'light_computation' is evaluation of diffuse or some other lighting model. You can see that if shadow_term for some light is zero ("totally in shadow"), then contribution of that light to the final color is zero.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sorry, what I meant was, if the shadow strength is less than 1, you still have light shining "through" the objects. In real life, of course, there's no shadow strength...objects either block light or not. ;) (Well, except for translucent things.)

    --Eric
     
  4. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    I truely appreciate all of this help. I am still at work and used a remote machine which had an ATI graphics card with only 256 megs of ram to test your web player, at home I have NVidia 8600 GTX 512 DDR2 (think thats the card, would have to double check the numbers) and will test it from there when I get home, late night with installation of some server applications for a project due in the morning. I'll post asap when I get home and test it on the iMac 24".
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hey, I have an ATI graphics card with "only" 256 megs of RAM and shadows work fine. ;) I fiddled around a bit, so here's an updated project (+webplayer) with shadow strength set to 1, and a somewhat more interesting script that does lerping around the sunrise/sunset times for light intensity and color, plus ambient light strength and skybox tint strength. For a relatively quick hack, it actually doesn't seem all that bad. (Hold "f" to make the sun go faster, so you can fast-forward through the night, which is even more boring than the day....)

    --Eric
     

    Attached Files:

  6. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Ok this was tough to grab the shots to explain, so here it is, walls, floor get lighted up as the light hits them (aka bleed through) I will post all the 6 shots I took, if this is still not convincing, I will use FRAPS on my PC and video record to show the effect. These were taking on my iMac24" and it clearly shows what I am talking about, if there is still confusion, seriously, I will record with FRAPS and post the video.
     

    Attached Files:

  7. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Second set, 2 more shots, notice the light difference on the walls.
     

    Attached Files:

  8. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Same problem on your new build, still bleed through from light sources. True you got the light in the windows and door to be cool but the floor and walls light up as the light source gets in the right range and they shouldn't light up. It is a line of sight issue and both of your packages show it just like mine does. You have to watch the tint of the floor / walls and you will easily see it.
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Are you sure? Take a look; there's no external lighting effects at dawn through noon and then sunset. The ambient light is scripted to change, but the lighting is exactly the same for all walls. I can see how you'd get the lighting differences with the first build since I accidentally left the shadow strength at less than 1, but if that's still happening then there's something quite wrong....

    --Eric
     

    Attached Files:

  10. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Its still happening, with Nvidia and ATI in the PC along with Intel graphics set, along with my iMac video.

    I have probably taken up way to much of your time on this matter. You did an outstanding job trying to help me with my particular issue. I need to find a new solution to my problem. I'll sleep on this some and work on the lighting on the weekend, in the mean time I can continue to build up my interior zone elements.
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I wanted to play around with a dynamic day/night cycle thing anyway and never got around to it until now. ;) I find it very strange that if shadows work fine on my X800 that newer and better cards would have problems. Make sure you try the web player if you haven't already, as opposed to the Unity package where they might be some variables in how you have things set up.

    --Eric
     
  12. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Hey dudes. I'm trying to convert this to C# but have run into a wall (lack of knowledge) with these 2 parts:

    Code (csharp):
    1.     light.intensity = sunAngle < 90?
    2.         SuperLerp (minLightIntensity, maxLightIntensity, 0.0, fadeRange, sunAngle)
    3.         : SuperLerp (maxLightIntensity, minLightIntensity, 180.0-fadeRange, 180.0, sunAngle);
    and..
    Code (csharp):
    1. function SuperLerp (a : float, b : float, c : float, d : float, t : float) : float {
    2.     return Mathf.Lerp(a, b, Mathf.InverseLerp(c, d, t));
    3. }
    With the second one, I got as far as:
    Code (csharp):
    1. private void SuperLerp(float a, float b, float c, float d, float t)
    But that needs another float in there, so it's not quite right. Any help would appreciated!
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's not returning void, it's returning a float.

    --Eric
     
  14. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Why yes, yes it is. After talking to a buddy this is all sorted (names a bit different according to my project):

    Code (csharp):
    1. // Animate Sun Intensity
    2.         Sun.light.intensity = (SunAngle < 90)
    3.             ? SuperLerp (SunMin, SunMax, 0.0F, FadeRange, SunAngle)
    4.             : SuperLerp (SunMax, SunMin, 180.0F - FadeRange, 180.0F, SunAngle);
    And:
    Code (csharp):
    1. private float SuperLerp(float a, float b, float c, float d, float t)
    2.     {
    3.         return Mathf.Lerp(a, b, Mathf.InverseLerp(c, d, t));
    4.     }
     
  15. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Does anyone know what's up here? I'm trying to do a series of nested inline if statements to change the colours (using 4 rather than 2) from Dawn-Day, Day-Dusk, Dusk-Night, Night-Dawn. Vis Studio gives me the thumbs up, but Unity gives me this:

    Code (csharp):
    1. GLib: Cannot convert message: Conversion from character set 'UTF-8' to 'CP1252' is not supported
    2.  
    3. Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
    Code (csharp):
    1.         RenderSettings.ambientLight = (SunAngle < 90)
    2.             ? SuperColorLerp(AmbDawn, AmbDay, 0.0F, FadeRange, SunAngle)
    3.             : RenderSettings.ambientLight = (SunAngle < 180)
    4.                 ? SuperColorLerp(AmbDay, AmbDusk, 180.0F - FadeRange, 180.0F, SunAngle)
    5.                 : RenderSettings.ambientLight = (SunAngle < 270)
    6.                     ? SuperColorLerp(AmbDusk, AmbNight, 180.0F - FadeRange, 180.0F, SunAngle)
    7.                     : SuperColorLerp(AmbNight, AmbDawn, 180.0F - FadeRange, 180.0F, SunAngle);
     
  16. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Nevermind!

    if (do dawn-day)
    else if (do day-dusk)
    else if (do dusk-night)
    else (do night-dawn)
     
  17. alln2themusic

    alln2themusic

    Joined:
    Feb 3, 2011
    Posts:
    46
    I'm having a similar problem with our game. We have a directional light that is stationary (no day night cycle) and we have shadows turned on and everything looks fine inside buildings and outside. As soon as we turn shadows off, the directional light shines through buildings makes everything inside the building bright. We currently have our buildings on a culling layer called "camera medium".

    With shadows still turned off and the directional light shining into the buildings, I uncheck the "camera medium" layer from the "culling mask" drop down box on the directional light and everything in the building stops being really bright. Is there a reason why the directional light penetrates objects when shadows are turned off? Is there another way to keep the directional light from shining into a building other than unchecking the building layer from the culling mask menu on the directional light? Thanks for the help!