Can someone "illuminate" me on novertexlights?

So first off, project is in Forward rendering path, not VertexLit. Only one custom Quality setting where pixel lights is 0.

There is only ever one light source active in the scene. In total there are 2 directional lights and 1 point light but the latter is currently always disabled and between the 2 directional lights, only one is ever active, never both.

So this is how I understand Forward rendering with 0 pixel lights and 1 directional light source (plus ambient) in the scene: lighting is done per-pixel in forwardbase, additional lights (if they existed, which they don’t right now) would be per-pixel in forwardadds up to the number specified in current Quality settings (currently 0), all additional would be per-vertex in, I suppose, forwardbase?

If that’s correct, I don’t get why my surface shader renders so differently when I use novertexlights? Remember, only 1 directional light source so should be per-pixel in forwardbase and the novertexlights shouldn’t affect my visuals at all right now.

My pragmas:

		#pragma target 3.0
		#pragma glsl
		#pragma only_renderers opengl gles
		#include "_azShared.cginc"
		#pragma surface surf BlinnPhong exclude_path:prepass nolightmap noforwardadd novertexlights

Two screenshots illustrating shading differences. Light source has not been changed! Nothing has changed (except the moving water), except novertexlights in the surface shader.

Here’s without novertexlights:

https://dl.dropboxusercontent.com/u/136375/img/screens/unity-surface-vertexon.png

Here’s with novertexlights:

https://dl.dropboxusercontent.com/u/136375/img/screens/unity-surface-vertexoff.png

You can see, lighting isn’t turned off, in both cases the lit areas are lighter than the unlit areas. But with novertexlights, the surface is only “half as illuminated”. What I’m not getting: there shouldn’t be any vertex-lighting in this very scene, in theory there’s only a per-pixel forwardbase as there’s only 1 directional light plus ambient.

Is this a bug or what am I not getting about novertexlights?

Do you still see the same lighting discontinuity if you set the ambient light color to Black?

What happens if you set the pixel lights property in the quality settings to 1?

I suspect that the first directional light still counts as a pixel light, Unity can get a bit confused if you’ve had one in the scene then remove it (I think it caches light values for the forwardbase pass).

I don’t – you got it! So ambient term is for some reason contributed per-vertex rather than combining it with lightcolor0 just once? The more you know… really I thought this is toggled with noambient. I did actually want a surface shader that is lit by dir+amb while ignoring all other lights. Since I don’t have pixel lights (multi-pass / forwardadd is simply out of question for my target platform and project), I thought this would do it but I didn’t want it to lose ambient too :confused:

1 Like

My guess is this :-

Because you are using only one directional light this is done per pixel in the Base Pass. The ambient color is being calculated and stored as part of the SH phase and computed per vertex -which is also calculated in this pass, which you then turn off in your shader which is why you lose your ambient. If you have no additional lights you should be able to re-enable vertex lights without any hit.

Interesting… well I “may” have some dynamic secondary vertex lights later on and I was for this particular surface to not use them but still be dir+amb lit… but OK, will see how to deal with this “later on”.

I gotta read me up to speed on that Spherical Harmonics phase… considering this is something that can’t be tweaked or toggled anywhere in the editor or via shader directive (from what I’ve seen so far), seems like a pretty core thing… :smile:

I’m not sure what it is you are trying to do exactly but you could always just add the ambient yourself in your shader using the built in shader variable UNITY_LIGHTMODEL_AMBIENT

Of course – just tried to grok why ambient is part of vertex lighting but I’m sure there’s a good reason :wink: