Search Unity

Getting the per-pixel light intensity

Discussion in 'Shaders' started by m0nkeybl1tz, Jun 17, 2019.

  1. m0nkeybl1tz

    m0nkeybl1tz

    Joined:
    Feb 10, 2013
    Posts:
    35
    I’m trying to make a shader that reacts to the light it receives, but not in a direct PBR sort of way. I want to see how much light a given pixel is receiving, clamp it between some min and max value, then adjust the emission value accordingly.

    I’ve seen _LightColor0 which seems close but as I understand it that’s more about the light overall rather than the light hitting that particular pixel. Is there a way to calculate the intensity per pixel?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    That's dependant on the shader model you're using. The short version is you'd have to calculate some kind of shading model, be it the full fat Standard shading model Unity uses, or something simpler like your basic Lambert. That'll mean you need the light position or direction, surface normal, light color, and potentially the falloff attenuation and shadow. Basically you have to fully compute the lighting for that light.