Search Unity

Light.shadowMatrixOverride

Discussion in 'General Graphics' started by whitexroft, Jan 22, 2021.

  1. whitexroft

    whitexroft

    Joined:
    Oct 22, 2012
    Posts:
    48
    Hi

    I'm writing my "custom" culling system, and trying to control the culling matrix on my spot light source.
    Ive tried any possible combinations of matrix multiplication, and haven't yet managed to get it even to the same matrix it uses by default (which is unknown). Documentation is lacking info on what the matrix is supposed to have. Is it in local space, is it in world, we don't know.
    The only thing i ve managed to find out is that zeroing it disables culling. Which partially what I wanted, but now it tries to render any objects off-screen.

    I hope someone could bring in some insight
     
    BoteRock likes this.
  2. whitexroft

    whitexroft

    Joined:
    Oct 22, 2012
    Posts:
    48
    well, if anyone needs it

    Code (CSharp):
    1.             var projM = Matrix4x4.Perspective(fovDeg, 1.0f, nearPlane, farPlane);
    2.             var scale = Matrix4x4.Scale(new Vector3(1f, 1f, -1f));
    3.             m_light.useShadowMatrixOverride = true;
    4.             m_light.shadowMatrixOverride = math.mul(projM, scale);
     
    ignarmezh, mattdevv and BoteRock like this.
  3. BoteRock

    BoteRock

    Joined:
    Jan 10, 2013
    Posts:
    9
    Thanks for posting back your solution =D