Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Access lighting info from .shader file

Discussion in 'Graphics Experimental Previews' started by MadeFromPolygons, Apr 23, 2018.

  1. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,982
    Is it possible to access lighting information etc such as to do a NdotL if we edit the shader code (copy from master node and paste in .shader file)? Need to know this before switching over to the SRP
     
  2. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,982
  3. Andre_Mcgrail

    Andre_Mcgrail

    Unity Technologies

    Joined:
    Dec 9, 2016
    Posts:
    244
    I can answer this for the Lightweight Pipeline.

    Theres are two function you can call from the Lighting.hlsl file and that is GetMainLight(float3 positionWS), which will return the main lights information(enough to do your own lighting calculation) and GetLight(int i, float3 positionWS) which will give you the same data but for the additional lights affecting the object.

    I'm not familiar enough with the HD Pipeline to comment but I can imagine there is a similar functionality, but it will probably be much more complex as there is a lot more going on there. And if you are making your own SRP then you will have to make your own functions to get the required data depending on what you are doing.
     
  4. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,982
    This is perfect, thank you very much.

    I mainly need this to implement some toon shading within the lightweight pipeline. This should more than suffice :)
     
  5. battou

    battou

    Joined:
    Jan 25, 2011
    Posts:
    222
    Is there a way to access Lighting.hlsl in CodeFunctionNode script?