Hey,
I have created a Triplanar shader with VisualShader so that i can have separate textures on the X,Y and Z Axis for a custom mesh. I have copied a shader i created in Unity (which works) however it seems not to act the same as in Godot. When I reorientate the camera the shader seems to shift depending on the orientation of the camera. I was wondering if anyone has any ideas on what i have done wrong ? Any help would be greatly appreciated.

Images

  • xyz replied to this.
  • scruff You need to use only a 3x3 subset of the 4x4 matrix when transforming direction/normal vectors, as opposed to using the full matrix when transforming positions. So switch the mode in multiplication node to A x B (3x3)

    scruff You need to transform the input normal from view space into world space.

      xyz Thanks for the incredibly quick reply, I have an "abs" after the normal input, do I have to do something additional to this? sorry if i have misunderstood still very new to Godot

      • xyz replied to this.

        scruff Disregard my previous remark. The absolute thing is not the problem.

        In order for triplanar to work as expected, your normal vector must be in world space or in object space. Unity's normal input lets you select normal's space. We can see it's set to object.

        However, in Godot, the normal input in the fragment shader is always in camera space. So you need to manually transform it to world space by multiplying this vector with inv_view_matrix input.

          xyz Thank again,
          So i have added the transform (i think correctly) however now i get the below.

          • xyz replied to this.

            scruff You need to use only a 3x3 subset of the 4x4 matrix when transforming direction/normal vectors, as opposed to using the full matrix when transforming positions. So switch the mode in multiplication node to A x B (3x3)

              xyz You are a wizard !!!! thank you sooooo much !!!!

              12 days later

              Tried following your example but mine is still locked to camera perspective rather than object world, also changed the matrix to 3x3 A-B, if you could post your completed shader that would be really helpful 🙂

                2 months later

                Emkani @scruff @xyz Hello Emkani I've managed to get this working in v4.2.1, but I don't know why it all of a sudden requires this extra transformation on the vertex input when the above example seemingly did not. I do not understand why this appears to fix it, it was only guess and check. Input from a more experienced visual shader user would be greatly appreciated: