Using VERTEXLIGHT_ON in shader isn't working

Hi,

I’m using the VERTEXLIGHT_ON define in a vertex shader to run different code when no lights are present on the mesh. I’ve also set ‘multi_compile_fwdbase’ and the shader has created all the variants I need so that part seems ok.

When I run the game though it always seems to render using the shaders without VERTEXLIGHT_ON. I’ve definitely got a light in the scene and it’s intersecting with some of the meshes but it doesn’t seem to use the correct shader variant. Is there something obvious I’m missing? Do I need to do anything to the mesh or change any settings?

Thanks,
Tony

Let me guess, you’re testing VERTEXLIGHT_ON in the fragment shader as well as the vertex shader? It would seem that VERTEXLIGHT_ON only works for the vertex shader, and is always off for the fragment shader - even when the fragment shader is shading data it received from a vertex shader that had VERTEXLIGHT_ON set on. This makes it impossible to have your fragment portion of the shader avoid adding in the 4 point lights component which could be a significant optimization in some cases.

Thread made about it here: VERTEXLIGHT_ON always undefined in Fragment Shader - Unity Engine - Unity Discussions

Edit: Doh, I did not realize this was already on the same forum. Apologies for there now being two similar threads.