mirror of
https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git
synced 2025-01-07 01:43:35 +08:00
SpherizeUV node added
This commit is contained in:
parent
09707d3911
commit
e829baa34b
69
addons/ShaderLib/UV/SpherizeUV.gd
Normal file
69
addons/ShaderLib/UV/SpherizeUV.gd
Normal file
@ -0,0 +1,69 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeUVSpherize extends VisualShaderNodeCustom
|
||||
|
||||
func _init() -> void:
|
||||
_set_input_port_default_value(1, Vector2(0.5, 0.5));
|
||||
_set_input_port_default_value(2, 10.0);
|
||||
_set_input_port_default_value(3, Vector2(0.0, 0.0));
|
||||
|
||||
set_output_port_for_preview(0)
|
||||
|
||||
func _get_name() -> String:
|
||||
return "Spherize"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "UV"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Applies a spherical warping effect similar to a fisheye camera lens to the value of input UV."
|
||||
|
||||
func _get_return_icon_type() -> VisualShaderNode.PortType:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 4
|
||||
|
||||
func _get_input_port_name(port: int) -> String:
|
||||
match port:
|
||||
0:
|
||||
return "uv"
|
||||
1:
|
||||
return "center"
|
||||
2:
|
||||
return "strength"
|
||||
3:
|
||||
return "offset"
|
||||
return ""
|
||||
|
||||
func _get_input_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
match port:
|
||||
0, 1, 3:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
2:
|
||||
return PORT_TYPE_SCALAR
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_output_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_output_port_name(port: int) -> String:
|
||||
return "uv"
|
||||
|
||||
func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
var code: String = preload("SpherizeUV.gdshaderinc").code
|
||||
return code
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var uv: String = "UV"
|
||||
|
||||
if input_vars[0]:
|
||||
uv = input_vars[0]
|
||||
|
||||
var center: String = input_vars[1]
|
||||
var strength: String = input_vars[2]
|
||||
var offset: String = input_vars[3]
|
||||
|
||||
return output_vars[0] + " = spherize_uv(%s, %s, %s, %s);" % [uv, center, strength, offset]
|
7
addons/ShaderLib/UV/SpherizeUV.gdshaderinc
Normal file
7
addons/ShaderLib/UV/SpherizeUV.gdshaderinc
Normal file
@ -0,0 +1,7 @@
|
||||
vec2 spherize_uv(vec2 uv, vec2 center, float strength, vec2 offset){
|
||||
vec2 _delta = uv - center;
|
||||
float _delta2 = dot(_delta.xy, _delta.xy);
|
||||
float _delta4 = _delta2 * _delta2;
|
||||
vec2 _delta_offset = vec2(_delta4 * strength);
|
||||
return uv + _delta * _delta_offset + offset;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user