Search Unity

Check if vertex light source is valid in shader

Discussion in 'Shaders' started by tonemcbride, Oct 30, 2014.

  1. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,089
    Hi,

    I've been using a shader that uses the vertex light position/colour from Unity to perform various calculations. This works fine if the vertex light in the scene is intersecting the mesh that is being rendered. When the light isn't covering the mesh I can't figure out of a way of knowing that the light values coming into the shader are invalid - e.g. unity_LightColor and unity_LightPosition

    On iOS it seems that the light is invalid if the 'w' value of the unity_LightPosition is very small (<0.001). On PC it's invalid if the colour values are near zero. Obviously these are pretty hacky ways of working that out so I was wondering if there was a better way of doing that?

    Thanks,
    Tony