Search Unity

Lighting question

Discussion in 'Editor & General Support' started by islanddreamer, Jul 19, 2006.

  1. islanddreamer

    islanddreamer

    Joined:
    Apr 29, 2006
    Posts:
    473
    Having lots of fun today playing with particles, but I've come across a lighting issue and I don't know what could be causing it. Please forgive the dark scene; I disabled ambient light to set the torch lights.



    There are 12 point light sources in this scene, each tucked inside the particle systems that make up the torches. If you look at the light on the lower left, it is not illuminating the area above it. There is another light (not visible) directly across from it that is also exhibiting this same behavior. Every light in the scene has the exact same settings (they were all duplicated from one another).

    Another question: how do you make lights dynamic?
     
  2. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Could it be that your level in that area is 1 mesh? A single mesh is only affected by the 8 brightest lights in Unity. If this is the case you could fix it by breaking up your mesh.

    What do you mean by dynamic lights? You can script the light's transform component so it moves around, attach the light to a rigidbody on a swaying hinge joint, alter the light's color at run time... even set the light's cookie at run time.

    So there's a ton you could do dynamically... what are you after?

    Cheers,
    -Jon
     
  3. islanddreamer

    islanddreamer

    Joined:
    Apr 29, 2006
    Posts:
    473
    Thanks. You're right; my level is all one mesh. It will be easy enough to split it up.

    What I was looking for is a way to make the lights from the torches flicker. What's the best way to do this: "wobble" the lights or change their intensity? Is there a code sample you can point me to?
     
  4. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    Really cool character! For flickering, I would think moving AND varying the intensity would be the nicest effect. To move smoothly, maybe you could have the light source parented just a bit off center from an empty gameobject. Then rotate the parent randomly (randomly nudge all 3 rotation axes?) making it "orbit." The farther from the parent it is, the more variation would result.

    Some color variation might be neat too.
     
  5. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Or use perlin noise. Don't know how performance would be for a huge amount of lights, but it should be ok. The perlin noise script is on the wiki with an example of using SmoothRandom to move objects.

    -Jeremy
     
  6. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Here is a package with perlin noise based, light intensity, transform rotation and transform position. All with tweakable variables in the inspector of course.

    Just open your project. Double click the package, it will install all scripts, which you can then drag on the light.
     

    Attached Files:

  7. islanddreamer

    islanddreamer

    Joined:
    Apr 29, 2006
    Posts:
    473
    You're awesome, Joachim! Thanks.

    Do you have any advice regarding how to compensate for gamma differences between the Mac and Windows displays?
     
  8. islanddreamer

    islanddreamer

    Joined:
    Apr 29, 2006
    Posts:
    473
    It's still dark, I know, but better... (And the flickering torch light helps a lot! :D )

     
  9. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Looks good, I like your character.

    This has been mentioned elsewhere too and I think it's down to either finding a happy medium, or you can use the Application.platform to find when it's running on windows and brighten all of your lights. A bit annoying to do, but I think it's the best option for now.

    -JEremy
     
  10. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    One thing you might want to do is lightmapping your building.

    So you have your radiosity lighting as the base and on top of it you can still have a couple of flickering torch lights.

    Lightmaps look great (because of radiosity) and are a lot faster than lots of small lights.

    Maya has excellent tools for lightmapping.
     
  11. CoherentInk

    CoherentInk

    Joined:
    Jul 16, 2006
    Posts:
    216
    So there's no way to adjust gamma in-game?
     
  12. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    You can't control the OS's gamma controls right now, no. There is that color correction filter for Pro users that one could use, but that's kind of an unneccsary performance hit. :/
     
  13. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    It's probably the wrong look for most games, but you could adjust the ambient light globally.
     
  14. islanddreamer

    islanddreamer

    Joined:
    Apr 29, 2006
    Posts:
    473
    I tried that but it really washes out the lighting on the Mac. I should probably go back and see what happens when I play the file over on the pc. It would be great to find a quick fix like: "raise ambient light by X% for Windows builds."

    I'll report back once I've had a chance to check this out.
     
  15. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Code (csharp):
    1. var testBoost = false;
    2. var ambientBoost = Color(0.1, 0.1, 0.1);
    3.  
    4. if (testBoost || Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsWebPlayer)
    5. {
    6.     RenderSettings.ambientLight += ambientBoost;
    7. }
    8.  
    Untested, sorry, but you'd just play with ambientBoost and then try it on a PC.

    Put this javascript on one object in each scene you'd like the ambient light boosted.

    I'd be really interested to hear how acceptable the results are, as I would like to do some cheap gamma correction on my games if possible. :)

    Cheers,
    -Jon
     
  16. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    What I do is set my gamma (in System Preferences) halfway between Mac and PC. Then everything I do is a little brighter on Macs and a little darker on PCs, but I'm doing all my work at a "happy medium."

    Different displays (and how people have them set) vary SO much anyway, that I haven't been bothered by that amount of variation.
     
  17. islanddreamer

    islanddreamer

    Joined:
    Apr 29, 2006
    Posts:
    473
    Ok, so this pic was grabbed from the pc. I turned the ambient light way up and it looked very washed out on the Mac.
     
  18. CoherentInk

    CoherentInk

    Joined:
    Jul 16, 2006
    Posts:
    216
    Why don't you add a control so users can adjust the ambient light in-game? Either step it up and down via key presses (F1 makes it darker, F2 makes it brighter) or add a slider as part of the preferences in-game. This would help to cater for the many different types of displays out there, too.
     
  19. Alpha-Loup

    Alpha-Loup

    Joined:
    Jun 23, 2006
    Posts:
    797
    Maybe its just the old mac/pc gamma correction problem?!
     
  20. islanddreamer

    islanddreamer

    Joined:
    Apr 29, 2006
    Posts:
    473
    Yes, it is. That is the problem on all the shots I've posted here. The latest just illustrates that you can alleviate it somewhat by raising the ambient light levels before exporting to Windows.
     
  21. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Did you try my script? It would save you the hassle of that.

    -Jon
     
  22. islanddreamer

    islanddreamer

    Joined:
    Apr 29, 2006
    Posts:
    473
    I haven't yet, but I'll let you know if that works. I assume the vars are percentages, correct? 1 would equal 255 of a color?
     
  23. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    ot... looking great!