How can I get the normal of the model in a 3D fragment shader?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Zylann
:warning: Old Version Published before Godot 3 was released.

I need to use the normal of the model in a shader to blend a different texture depending on the steepness of a slope.
I tried to use NORMAL, however NORMAL is a view-space vector, and it changes when the camera moves, that’s not what I need.
There is SRC_NORMAL, but it is only available in vertex shaders (I’m writing a fragment shader).
Is there any way to get this normal?

I also tried what the doc indicates:

vec3 world_normal = NORMAL * mat3(INV_CAMERA_MATRIX);

However this produces an error, mat3 cannot be used with INV_CAMERA_MATRIX

:bust_in_silhouette: Reply From: GlaDOSik

You can pass the normal in model space to fragment shader using VAR1 or VAR2. In VS: VAR1.rgb = SRC_NORMAL, in FS: vec3 normal_model_space = VAR1.rgb.

Wow, I didn’t know you could pass variables like that. I thought it was not possible in Godot’s shader language (in GLSL it would be varying/in/out).
Thanks!

Zylann | 2016-07-23 19:56