Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

When/where is the model matrix set?

Discussion in 'Scripting' started by sebj, May 2, 2016.

  1. sebj

    sebj

    Joined:
    Dec 4, 2013
    Posts:
    70
    Hi,

    I have a procedural shader dispatched with a DrawProcedural() call inside OnRenderObject() for one of my components.

    While UNITY_MATRIX_MVP contains the correct camera and projection transforms, the transform for the object the component is attached to are not present.

    When does Unity set the model/world transforms?
    (Or, in what callback should I call DrawProcedural() to ensure they are in UNITY_MATRIX_MVP?)

    Sj
     
  2. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    What do you mean by "not present"?

    see:
    http://docs.unity3d.com/Manual/ExecutionOrder.html

    When OnRenderObject is called the matrices should be updated to match whatever has been done in Update, LateUpdate, FixedUpdate, ...
     
  3. sebj

    sebj

    Joined:
    Dec 4, 2013
    Posts:
    70
    Thanks ericbegue, I will give that link a thorough look. By "not present" I mean the transform supplied to the shader remains the same, regardless of the parameters of the Transform of the gameobject to which the component script is attached.
     
  4. S_LAB

    S_LAB

    Joined:
    Nov 25, 2016
    Posts:
    2
    Was this ever resolved? I am having a similar problem.
     
  5. S_LAB

    S_LAB

    Joined:
    Nov 25, 2016
    Posts:
    2
    Ok I solved this by using a CommandBuffer, the DrawProcedural function in the CommandBuffer class takes a matrix. I then just used Graphics.ExecuteCommandBuffer