Environment lighting orientation

I have recently been moving my project over to use Unity 5 and have run into an issue regarding its lighting system.

As far as I can tell, the environment lighting such as using a skybox or using ambient gradients (sky, equator and ground) assume that +Y is up. In the project I’m working on, what is considered to be up could be any direction.

Is there any trick or way setting the reference rotation for the environment lighting?

Apart from using different skybox for the different UP direction… can you elaborate a little bit more on the “any direction”? In our current work we use different environment in the same scene. I have a script that sets the skybox for those environment programatically using RenderSettings.skybox. If you use non-procedural skybox, you could reshuffle the different 6 images of the cubemap. The problem though is that you would be limited to ±Y ±X ±Z as UP direction… which I’m afraid is far from any. As for gradient I don’t think you can change this but I suppose you can emulate this with cubemap too…

Well by the way why don’t you attach your entire scene on a parent node on which you set the orientation… it would be easier and produce the same effect. Just thought of that trick. I don’t think it would impact performance at all but I’m not sure, you’ll have to test as I can’t try myself right now. The only caveat would be physics maybe.

What I meant was by up being any direction was that the ground plane as it were could be any rotation, rather than axis locked. The idea of using a parent node for the scene is an interesting one, but like you said, the problem would be the physics plus I have an unconventional scene setup which makes this idea difficult to work with.

The one thing I have come up with so far after looking at the standard skybox procedural shader was to create a new skybox shader which procedurally defines the gradients of the sky and within the shader I can set the orientation of the world. This does also however require me to setup a reflection probe that only picks up this skybox so that objects in the scene can use it. Currently I can’t quite get the visual results I’m after because I haven’t been able to replicate the ambient sky/equator/ground gradient setting which I’m fond of, but it’s the best I can come up with at the moment…

The joys of unconventional setup! Hehe.That physics would be a major concern to me as well, I know one can change gravity but I have serious doubts about the results of changing that repeatedly… well if that’s what you really do with your shader and its orientation property, you know more about your use case than I.

Great for you if you have managed to create that shader already, I’m quite of a novice in that matter. I would be interested to know if you finally obtain what you wanted. I myself had to create some skybox with custom reflective probes to mimick reflection effects of an existing pre-rendered image… independently of the ambient lighting used… quite tricky. Anyway, I have no idea how its computed but, could it be that the ambient lighting properties sky/equator/ground is completely treated differently for that matter in the standard shader? Ambient vs skybox reflection… I might be wrong, as I said I’m no expert in shaders… yet.

For anyone interested, here is my ambient lighting sky box shader. Be warned, it’s a bit crude. To use it:

  1. Add it to your Resources folder.
  2. Create a material for the shader.
  3. Go to Window/Lighting and assign the material to Skybox and set “Ambient Source” to skybox. Ensure “continous baking” is ticked.

It’s supposed to be similar to ambient source gradient setting. Ideally I would like to know exactly how it works so I can make sure my shader is mathematically the same…

One other thing, I’m not sure if the environment lighting skybox is designed to be updated in real time. When I change the material, it has no effect after the the game is launched… so that’s something I still need to figure out.

2094235–137045–AmbientSkyBox.shader (1.55 KB)

1 Like

Thank you for sharing your shader. I’ve just tested it and this could prove useful to me (with some modifications) to do exactly what I was trying to do without shader. As soon as I have some time I’ll continue to do some research about getting similar results than with ambient source gradient.

As for the environment lighting update in real time… I realized that switching skybox only affect background in real time. Gradient ambient color can change in real time (at least in Play mode) but if you choose to take skybox as source for ambient lighting it seems the ambient colors are computed only once when you enter Play mode (and I suppose on player too). Right?

That’s how it seems to me yes :frowning: I think if you change the skybox to a new material it will update. So one idea might be to write some code that instantiates two copies of the material and then have it alternate between them each frame (whilst you change the properties of the materials in real time). However I’m unsure if it’s really meant to be used this way and what performance implications it might have…