Search Unity

_LightMatrix0 and Directional Light

Discussion in 'Shaders' started by MaT227, Jan 5, 2016.

  1. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    628
    I am trying to access the _LightMatrix0 in a forward base pass to calculate some light point of view coordinate but it seems that the _LightMatrix0 is empty with directional light. Any idea how can I solve this and how could I access to the _LightMatrix0 with directional light (without cookies) ?

    I am trying to do this kind of thing.
    Code (CSharp):
    1. float4 position = mul(_LightMatrix0, worldPos);
     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    In this specific case, I can imagine you just manually set the matrix of the main directional light as global variable. With this specific case I mean that is intended for a forward base pass.

    For a more generic approach in deferred rendering you'd have to create a custom light shader and execute it using a commandbuffer. But that all depends on what you want to do with it.

    For a more specific solution, I'll need to know why exactly you want to calculate the position of the surface from the view of the main directional light.
     
  3. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    628
    Thanks for you answer @jvo3dc, I am trying to calculate transmittance using the directional light depth map/shadow map. That's why I am trying to access this matrix.
    The problem is that directional lights are computed in screen space so I need to access two things :
    The directional light depth map before it is computed in screen space as Aras explained in this thread : http://forum.unity3d.com/threads/un...ordinates-and-stuff-shader-pro-needed.376875/
    and the directional light matrix to compute the position.

    Then I'll be able to get the transmittance but the Unity pipeline doesn't ease the pain of doing that :)

    If you have some advice, I'll be glad to read them.
     
  4. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    628
    @jvo3dc And the next question would be, what's the content of the directional light matrix.
     
  5. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    Did you look at the atmospheric scattering package that aras mentioned? There seem to be some shaders in there that could lead as an example.
     
  6. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    628
    Yes, I found a way to access the depth map, I think, because I can't test for the moment, but there nothing about the matrix. :(