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
  4. Dismiss Notice

Bug matrix mul in custom function different from Multiply node?

Discussion in 'Shader Graph' started by chrismarch, May 21, 2020.

  1. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    465
    When I use mul(matrix, position) inside a custom function, I get a different result coming out of that function node than if I send the exact same inputs to the Multiply node. The Multiply node output matches what I get if I write my own fragment shader, the Custom Function output does not. Am I doing something wrong? I'd like to be able to use mul(matrix, vector) in my custom functions.

    While the previews look the same, if I send this Custom Function output to the color input for the Unlit Master Node, and compare with sending the Multiply output to that same color input, they look very different.
    upload_2020-5-21_13-23-13.png
     
  2. acnestis

    acnestis

    Joined:
    Sep 11, 2019
    Posts:
    8
    Your custom function's input should be Vector4 because your custom matrix is 4x4;
    -------------------------------------------------
    The vertex 【position】 node's output seems to be a Vector3, but I guess it implicitly contains w which is equal to 1——in Homogeneous Coordinates w=1 indicates that it is a point not a vector;
    The 【Multiply】node takes the vertex position in and gets(or sets?) its w=1,
    while your custom function takes a Vector3 position in and the mul() method has to set the position.w = 0;
    that's why the outputs are different;
    As long as you allow the custom function to take a Vector4 in, it will atutomatically gets(or sets?) position.w=1;
    upload_2023-4-27_17-14-54.png
     
    Qriva likes this.