Skip to content

This is a VisualShader addon node to get the Z channel of a normal map from X & Y channels. This node only works in Godot 4.2 onwards.

License

Notifications You must be signed in to change notification settings

Foyezes/Godot-Derive-Z-Node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Godot Derive Z Node

Get the Z channel of a normal map from X & Y channels. This node only works in Godot 4.2 onwards. image

Method

The node take X & Y as inputs and outputs the full normal map.

vec3 deriveZ(float x_in, float y_in){
		
		vec2 normalXY = vec2(x_in * 2.0 - 1.0, y_in * 2.0 - 1.0);
		
		float z = sqrt(max(1.0 - dot(normalXY, normalXY), 0.0));
		
		vec3 normal = vec3(normalXY.x, normalXY.y, z);
		
		return normal;
	}

By default the normalization is set to No. You can normalize the result by selecting Yes if you need.

Yes

=normalize(deriveZ(%s, %s)) * 0.5 + 0.5;

No

=deriveZ(%s, %s) * 0.5 + 0.5;

This implementation gives users the flexibility to choose whether they need normalization, which is useful since sometimes you might want to skip normalization for performance if you know your inputs are already normalized or if perfect unit vectors aren't required.

Installation

Extract the zip file and copy the folder to your project. You'll need to restart the editor for the node to appear in visual shader. Alternatively, you can make a new gdscript file and copy the code.

About

This is a VisualShader addon node to get the Z channel of a normal map from X & Y channels. This node only works in Godot 4.2 onwards.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published