Topic was automatically imported from the old Question2Answer platform.
Asked By
ugly_cat
Old Version
Published before Godot 3 was released.
I’m trying to figure out how to get the world space normal with the light shader. I know there is documentation about obtaining the world space normal in the fragment shader, but there doesn’t seem to be a way to do that easily in the light shader. Anybody now?
I see you can pass parameters between vertex and fragment shaders using VAR1 and VAR2, however I don’t see such variables in LightMaterial…
Do you need normal in view space? If not, you can compute world space normal in vertex shader, pass it to fragment shader using VAR1 or VAR2 and pass it to LIGHT part in NORMAL. Do you need specular color? If not, you can use SPECULAR to pass the normal. Another way would be to calculate inverse camera matrix and world matrix inside the script and use uniform matrix in LIGHT. Using them, you could compute world normal from view space normal.
And the knowledge that setting the NORMAL variable carries to the Lighting shader helped to make a shader that casts light on top of the model regardless of the orientation of the camera:
Fragment: