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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

UNITY_MATRIX_MVP =? UNITY_MATRIX_M * UNITY_MATRIX_V * UNITY_MATRIX_P

Discussion in 'Shaders' started by Trexug, Jan 24, 2018.

  1. Trexug

    Trexug

    Joined:
    Dec 2, 2013
    Posts:
    88
    Code (csharp):
    1.  
    2. Shader "Cg basic shader"
    3. {
    4.    SubShader
    5.    {
    6.       Pass
    7.       {
    8.          CGPROGRAM
    9.  
    10.          #pragma vertex vert
    11.          #pragma fragment frag
    12.  
    13.          float4 vert(float4 vertexPos : POSITION) : SV_POSITION
    14.          {
    15.            
    16.             //float4x4 myMatrix = UNITY_MATRIX_P * UNITY_MATRIX_V *  unity_ObjectToWorld;
    17.             //float4x4 myMatrix = unity_ObjectToWorld * UNITY_MATRIX_V * UNITY_MATRIX_P;
    18.             float4x4 myMatrix = UNITY_MATRIX_MVP;
    19.             return mul(myMatrix, vertexPos);
    20.          }
    21.  
    22.          float4 frag(void) : COLOR
    23.          {
    24.             return float4(1.0, 0.0, 0.0, 1.0);
    25.          }
    26.  
    27.          ENDCG
    28.       }
    29.    }
    30. }
    31.  
    32.  
    33.  
    Replacing line 18 with line 17 does not produce the same result. What am I misunderstanding?
     
  2. Trexug

    Trexug

    Joined:
    Dec 2, 2013
    Posts:
    88
    Bah...
    Multiplying matrices with * is not the same as using mul()
    :oops:
     
  3. Dr-Game

    Dr-Game

    Joined:
    Mar 12, 2015
    Posts:
    161
    return vertexPos*myMatrix; ??
    is not work for me!!
     
  4. Dr-Game

    Dr-Game

    Joined:
    Mar 12, 2015
    Posts:
    161
    return vertexPos*myMatrix; ??
    is not work for me!!
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,245
    I mean ... you just quoted the answer to your question. Don't use *, use mul().