I’m learning how to setup a lighting system. I have a directional light acting as a sun that rotates based on a day/night cycle and the RenderSettings.ambientLight based on a gradient I’ve set in the editor.
I want the world to be completely dark at night, but lit well during the day.
Anything the sun shines on is lit well, but the opposite sides are completely black. I want some level of light coming from all sides so you can at least see things.
Do I need to dive into advanced lighting setups like global illumination/ambient occlusion or is there a simpler step I’m missing?
The fastest, easiest, and cheapest way to deal with this is to setup some basic ambient lighting in your scene and adjust that based on your time of day. Look at your Lighting tab in the scene (usually up next to the inspector tab) and then look at the Environment Lighting sub section.
It can get really complicated and be set up based on your environment’s skybox and assigned sun light source or it can simply be set to a color of your choosing that you can manually adjust in your code based on time of day. As long as the shaders you are using support ambient lighting in their model (and pretty much most do) then it’ll just work.
Thanks, I think I’ve probably messed something up because the dark areas never change unless I switch the environmental lighting off the “skybox” option. Even setting RenderSettings.ambientLight to pure white doesn’t seem to do anything. I’ll keep playing around and I guess I need to do more reading and watch some more tutorials.
No because it’s only in the GameScene which isn’t loaded first, I have a menu screen the player starts with and switches to the game scene when they hit play.
I’ll try to set it dynamically, but when I assign it in play mode it doesn’t seem to help.
Setting the sun doesn’t do anything. Unity docs say the brightest light in the scene will be used so it should be using it already anyway - I have no other lights. But even setting it via RenderSettings.sun doesn’t seem to help, the lighting panel still says None for “Sun Source”
I tried a little more and Gradient mode for environment lighting does help a bit, so it’s definitely something with the skybox environment lighting that’s causing this issue.
Yeah that is weird. Out of curiosity, are you using Unity 6? I notice suspiciously that there is another thread just a little below this one with a similar issue and they are using Unity 6. It could be a red herring but maybe worth looking in to.
Have you tried setting up a new scene, perhaps even a new project just to test this out? And if you are using Unity 6, perhaps you could try to set up something similar in an older version and see what the result is? Also, are you using standard shaders or are they something super custom that perhaps doesn’t use ambient lighting? I hate to send people on wild goose chases like this but really, it kinda should just be working.
Ok, in a new project, I noticed that under “Baked Lightmaps” of the lighting window, the Lighting Data Asset was set. In my project, it’s unset when I enter play mode. If I re-add it, the harsh shadows lighten to be closer to what I expect. I’m not sure why it’s being unset.
Not sure if it’s related but the lighting data seems to be scene-specific as it’s stored in each scene file, yet the lighting window isn’t… it never changes based on the scene/active scene. When the GameScene loads in play mode, the field unsets to “None”
Usually there’s a default one when you bake light maps. If you disable auto baking then it might not generate one? Not too sure since I haven’t bothered with much baking since… oh, I dunno, Unity 4.6 maybe? lol
I’m assuming your goal is to try to use ambient light based on the skybox settings, right? And not just a flat color that you set manually?
I just doubled checked and it seems gradients for the environment lighting source don’t require any light map baking (the same way a solid color doesn’t) so really it should just work. As for the null asset that shouldn’t matter. My is always null since I never bother with baking or GI of any kind.
I just played with the gradient in my own scene. Seems I was slightly mistaken, it appears to be averaging the three values somehow so if you have a very bright day then even when the sun is facing away the ambient is still going to be quite bright it seems.
Anway, I’d say if setting the ambient light is having no effect on the scene then that’s a bug and likely should be reported. It really should be as simple as setting the source to Color and then setting the ambient color to whatever you want. In code it would be the following:
Before I saw this post I realized that if I’m just setting the color, and the lighting panel kept showing skybox, it probably wasn’t using my color because the mode wasn’t right. So I tried RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Flat which solved the problem. Then I noticed you posted that in your snippet!
Thanks for all of the help, it seems like it’s working.