+1 vote

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...

in Engine by (28,738 points)
edited by

1 Answer

+1 vote
Best answer

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.

by (822 points)
selected by

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!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.