#Porting a Godot shader to Unity

1 messages · Page 1 of 1 (latest)

keen ibex
#

https://gamedev.stackexchange.com/questions/213251/recreating-a-3d-pixel-art-water-effect

Been slowly working my way through the Godot shader that was posted as an answer to my question that I posted on gamedev.stackexchange. Most of it was pretty easy, but I'm completely stuck on what the equivalent of this line would be in HLSL

    vec2 uv_shift = (inverse(MODEL_NORMAL_MATRIX) * cam_dir_wd).xz;

Specifically

inverse(MODEL_NORMAL_MATRIX)

The closest I think is something like this, but the results I get in the final shader differ from what the expected result is so I can only assume that this is incorrect

float2 uv_shift = TransformObjectToWorldNormal(camDirWd).xz;

Can anyone help here?

vivid garnet
#

I think unity most often calculated the matrix inverse on the cpu and passes it into the shader a parameter to improve the shader performance.
I'm not sure what MODEL_NORMAL_MATRIX here stands for, but if it's one of the default matrices used during normal rendering, it's likely that unity already provides an inverse of it.

If you really need it calculated in the shader, you'll need to implement your own matrix inverse function.

keen ibex
#

at the risk of sounding like an asshole, I have to say your entire message could've been

I'm not sure what MODEL_NORMAL_MATRIX here stands for

which could've just not been sent at all

vivid garnet
# keen ibex at the risk of sounding like an asshole, I have to say your entire message could...

I mean, you didn't ask about what that matrix was specifically. And since it's Godot specific api, it's something that you were expected to research yourself.
A quick google shows:

in mat3 MODEL_NORMAL_MATRIX

Model/local space to world space transform for normals. This is the same as MODEL_MATRIX by default unless the object is scaled non-uniformly, in which case this is set to transpose(inverse(mat3(MODEL_MATRIX))).

In unity that would be GetVertexNormalInputs in URP(assuming URP, since you mentioned hlsl).
https://docs.unity3d.com/6000.1/Documentation/Manual/urp/use-built-in-shader-methods-transformations.html