unity-builder icon indicating copy to clipboard operation
unity-builder copied to clipboard

Environment / Ambient Lighting from Skybox is Missing

Open jfoshee opened this issue 3 years ago • 12 comments
trafficstars

Environment / Ambient Lighting from the Skybox is missing. Surfaces lit exclusively by the skybox will appear black.

How to reproduce

See https://github.com/jfoshee/Hello-Cube/actions for a repro case

  • Create a new Unity project using 3D template
  • Select the default SampleScene for the build
  • Add a default Cube to the Scene
  • Add a behavior to rotate the camera to be able to see all sides of the cube
  • Build the project using GameCI and observe that 3 sides of the cube are black (unlit)

Expected behavior

You should see all sides of the cube are illuminated. 3 sides will be brighter because they face the default directional light. The three opposite sides will be dimly lit because they are only lit by environment/ambient light.

Additional details

The relevant settings are found in the Unity editor under:

  • Window > Rendering > Lighting
  • Environment tab
  • Under Environment Lighting header, select Source drop-down

I tested to see if this occurs with a non-default skybox, and verified it does still occur in that case.

Work-Around

Using a solid-color ambient lighting seems to work fine. That is, change the Environment Lighting Source to Color and select an appropriate color.

jfoshee avatar Nov 30 '21 00:11 jfoshee

I have experienced this same bug, so I can confirm it's happening as well.

As I'm not very experienced with Unity I wasn't able to make such a detailed write-up. Thanks especially for the additional details. This might be a bug in Unity for Linux, or our Docker image having a missing dependency that causes this.

Anyone know how to determine how to solve this?

webbertakken avatar Nov 30 '21 01:11 webbertakken

Thanks, @webbertakken. I wish I knew more about the resolution, but it's still somewhat of a mystery.

I have found that there is a second closely related lighting issue. Even with the work-around above the visual output is noticeably darker.

Referring to the same tab mentioned above, notice the Environment Reflections Intensity Multiple.

image

The Environment Reflections Intensity Multiple defaults to 1.0. However, it does not seem to be respected with the Game-CI build.
When I set the Intensity Multiple to 0.0 I get the same output locally as produced by the build.

I can provide a few more details if needed. @webbertakken would you like me to open a separate issue for this? They seem closely related, though I can't predict if they will have the same fix.

jfoshee avatar Nov 30 '21 20:11 jfoshee

Since both seem to be differences between host-platforms, or otherwise difference between GameCI and local builds I feel we might keep one issue until it starts clouding the issues at hand. But as you prefer!

webbertakken avatar Nov 30 '21 23:11 webbertakken

I had a similar issue where my intensity multiplier wasn't working. Even though I wasn't using baked illumination, after generating lighting data, the intensity multiplier worked

zmays avatar Dec 10 '21 17:12 zmays

I got the same bug. I first thought that my repository was missing something, so I made a new clone of my repository and switch to WebGL and directly build it without opening my scene. And i got the bug. Then i opened my scene to check out wat the problem was but couldn't find anything. So i tried the build again and the bug is gone. 🧐 Looks like opening the scene generates the lighting data needed.

KoenRijpstra avatar Jan 09 '22 17:01 KoenRijpstra

I found a solution:

  1. Open your scene
  2. Go to Lighting > Scene > Click on New Lighting Settings
  3. Click on Generate Lighting
  4. Commit and push newly created files

KoenRijpstra avatar Jan 09 '22 18:01 KoenRijpstra

@KoenRijpstra that is great! Thank you for sharing your solution with us.

I believe a logical next step for us would be to try and see if we're able to programatically do that in our build script, so that we can effectively solve this "bug" for everyone.

webbertakken avatar Jan 10 '22 13:01 webbertakken

@webbertakken No problem! Maybe it's better to give an error message that there are files missing with the solution how to fix? I prefer educating the user over magic fixes.

KoenRijpstra avatar Jan 10 '22 14:01 KoenRijpstra

I agree with your sentiment. We're also not in the habit of making any magic fixes.

The way I understand the issue is that it works as normal in a local build and the issue only appears in CI (i.e. only in GameCI), so replicating a "normal" build in CI might be preferable in this case.

That said, if we have an elegant way to detect some files are not there, and we know for sure that they should be there, we might error our.

However there may be downsides to that approach:

  • there may be exceptions (i.e. server builds) and
  • it would make setting up GameCI a bit harder, as you'd have to deal with an additional step to make. Note that an error would be thrown from the javascript part of the action (as in CI you want to error out as soon as possible) and the javascript part is not replaceable like the default build script is.

webbertakken avatar Jan 10 '22 17:01 webbertakken

I think the simple solution may be to use the Unity Editor to open each scene in the build settings. If any lighting files are generated, the build would fail if allowDirty isn't set to true. Idk if it currently works this way, but if a build fails because allowDirty is false, we should clearly list out which files are new or modified, which should allow the user to fix it from their end. Or they could choose to set allowDirty to true.

EDIT: I thought about it some more, and automatically trying to generate lighting files for each scene is a bad idea, even with the above. For example, my project is entirely unlit 2D, but it is still possible to generate useless lighting files. I wouldn't want to add these files to my repo; I wouldn't want to set allowDirty to true; and I obviously wouldn't want my build to fail just because some useless lighting files are not in my project. Maybe we could have additional option like checkLighting, which may be true by default, and if so, that would trigger the test of opening each scene file to see if lighting can be generated. And in my project, I would set checkLighting to false.

davidmfinol avatar Jan 10 '22 21:01 davidmfinol

The thing is that in CI these files aren't automatically generated afaik.

Adding another parameter to our public api doesn't feel quite right either, because builds should "just work" (if they do so locally), even when you use lit shaders.

I'm thinking perhaps we can somehow check if there are any lit shaders, and if there are, make sure that the lighting settings for those shaders exist. then generate them or error out as defined behaviour for GameCI. What do you think?

webbertakken avatar Jan 10 '22 23:01 webbertakken

If we want to generate lighting in CI, we can call lightmapping.bake : https://docs.unity3d.com/ScriptReference/Lightmapping.Bake.html

How would we check every material in every scene for lit shaders? Even if we are able determine if any scene has materials with lit shaders but no lightmaps, how would we know if the user actually even wants to bake in those lights? For example, what if they have a scene that would require lighting, but they know they're going to change the offending material/shader at runtime, so they intentionally don't bake in the lights? Also, it's generally considered a bad practice to include lightmaps in git, but what if a user does? We could assume that their lightmaps are correct and therefore skip generating new lightmaps, but I feel like we should actually watch out for users and suggest they update their .gitignore.

I think we should add some code to unity-builder that automatically checks users' lighting settings+lightmaps, but I also think we need to have a way for users to opt out of that check.

davidmfinol avatar Jan 11 '22 01:01 davidmfinol