WorldPlanarProjection3D VisualShaderNode 4.4
For use with the WorldPosition node: https://godotshaders.com/shader/worldposition-visualshadernode-4-4/
Gives a simple scaled / offsetted world space UV projection with the input vectors exposed so you can manipulate or replace them as you wish.
Copy this into a new .gd file. It will show up in the “Addons/UV” category in the RMB menu when adding a new shader node in the visual shader editor. Attached is an image of the default use case.
Shader code
@tool
extends VisualShaderNodeCustom
class_name VSNode_WorldPlanarProjection3D
func _get_name() -> String:
return "WorldPlanarProjection3D"
func _get_category() -> String:
return "UV"
func _get_description() -> String:
return "Returns a planar projection based on input coordinates. Meant for use with the WorldPosition node."
func _get_return_icon_type() -> PortType:
return PORT_TYPE_VECTOR_3D
func _get_input_port_count() -> int:
return 3
func _get_input_port_name(port: int) -> String:
match port:
0: return "WorldPosition (Required)"
1: return "Mapping Scale"
2: return "Mapping Offset"
return ""
func _get_input_port_default_value(port: int) -> Variant:
match port:
0: return Vector3(0, 0, 0)
1: return Vector3(1, 1, 1)
2: return Vector3(0, 0, 0)
return Vector3(0, 0, 0)
func _get_input_port_type(port: int) -> PortType:
return PORT_TYPE_VECTOR_3D
func _get_output_port_count() -> int:
return 3
func _get_output_port_name(port: int) -> String:
match port:
0:
return "Front"
1:
return "Side"
2:
return "Top"
return "Result"
func _get_output_port_type(port: int) -> PortType:
return PORT_TYPE_VECTOR_2D
func _get_code(input_vars: Array[String], output_vars: Array[String],
mode: Shader.Mode, type: VisualShader.Type) -> String:
return """
vec3 world_pos = %s;
//vec3 world_pos = fract((INV_VIEW_MATRIX * vec4(VERTEX, 1.0)).xyz);
world_pos = fract(world_pos * %s + %s);
%s = world_pos.xy;
%s = world_pos.yz;
%s = world_pos.xz;
""" % [ input_vars[0], input_vars[1],input_vars[2], output_vars[0], output_vars[1], output_vars[2]]




