Search Unity

Matrix construction help

Discussion in 'Shaders' started by metervara, Sep 18, 2009.

  1. metervara

    metervara

    Joined:
    Jun 15, 2006
    Posts:
    203
    I'm trying to construct a Matrix to use in a shader for a projector. Projection-shaders normaly use _Projection and _ProjectionClip Matrices, and I want to replace _ProjectionClip with my own Matrix. The goal is to use the second Texture step to cut a hole in the first texture. I'd like to move that hole too, so I need to update the Matrix at various points.

    I'm using orthographic projection and wanted to first see if I could replace _Projection with my own Matrix and get exactly the same result. Tried with MAtrix4x4.Ortho, feeding in the orthoSize and clipPlanes from the projector but I guess I need to transform it into world sapce too?

    Any help apprecieated, thanks,

    Patrik
     
  2. metervara

    metervara

    Joined:
    Jun 15, 2006
    Posts:
    203
    Added a camera (inactive) to the projector gameObject and set it up to match the projector. This code:

    Code (csharp):
    1. _ClipMatrix = c.projectionMatrix*c.worldToCameraMatrix;
    where c is the camera gets me closer to what I want. The projected image is offset and rotated, but not stretched or otherwise distorted.

    Moving on...

    /P