└── addons └── ShaderLib_v2_2_4 ├── Artistic ├── Adjustment │ ├── Contrast.gd │ ├── Hue.gd │ ├── ReplaceColor.gd │ ├── Saturation.gd │ └── WhiteBalance.gd ├── Artistic.gdshaderinc └── Mask │ └── ColorMask.gd ├── Geometry ├── Geometry.gdshaderinc └── MeshNode.gd ├── LICENSE ├── Maths ├── Maths.gdshaderinc ├── Scalar │ ├── SmoothMax.gd │ └── SmoothMin.gd ├── Vector │ ├── Distance │ │ ├── ChebyshevDistance.gd │ │ └── ManhattanDistance.gd │ ├── Project.gd │ ├── ProjectOnPlane.gd │ └── VectorTransform.gd └── Wave │ ├── NoiseSineWave.gd │ ├── SawtoothWave.gd │ ├── SquareWave.gd │ └── TriangleWave.gd ├── Procedural ├── CheckerBoard.gd ├── Fractals │ └── KochFractal.gd ├── HeightToNormal.gd ├── Noise │ ├── GradientNoise.gd │ ├── GyroidNoise.gd │ ├── PseudoRandomNoise.gd │ ├── SimpleNoise.gd │ └── Voronoi.gd ├── Procedural.gdshaderinc └── Shapes │ ├── Ellipse.gd │ ├── Polygon.gd │ ├── Rectangle.gd │ ├── RoundedPolygon.gd │ └── RoundedRectangle.gd ├── RayMarching ├── RayMarch.gd ├── RayMarchCustomTemplate.gdshaderinc └── SignedDistanceFunctions.gdshaderinc ├── ShaderLib.gd └── UV ├── FlipbookUV.gd ├── ParallaxMappingUV.gd ├── RadialShearUV.gd ├── RotateUV.gd ├── SpherizeUV.gd ├── SwirlUV.gd ├── TilingAndOffsetUV.gd ├── TwirlUV.gd └── UV.gdshaderinc /addons/ShaderLib_v2_2_4/Artistic/Adjustment/Contrast.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeAdjustmentContrast extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "Contrast" 6 | 7 | func _get_category() -> String: 8 | return "Artistic/Adjustment" 9 | 10 | func _get_description() -> String: 11 | return "Adjusts the contrast of input in by the amount of input contrast." 12 | 13 | func _get_return_icon_type() -> PortType: 14 | return PORT_TYPE_VECTOR_3D 15 | 16 | func _get_input_port_count() -> int: 17 | return 2 18 | 19 | func _get_input_port_name(port: int) -> String: 20 | match port: 21 | 0: 22 | return "in" 23 | _: 24 | return "contrast" 25 | 26 | func _get_input_port_type(port: int) -> PortType: 27 | match port: 28 | 0: 29 | return PORT_TYPE_VECTOR_3D 30 | _: 31 | return PORT_TYPE_SCALAR 32 | 33 | func _get_input_port_default_value(port: int) -> Variant: 34 | match port: 35 | 1: 36 | return 1.0 37 | _: 38 | return Vector3(1.0, 1.0, 1.0) 39 | 40 | func _get_output_port_count() -> int: 41 | return 1 42 | 43 | func _get_output_port_name(port: int) -> String: 44 | return "out" 45 | 46 | func _get_output_port_type(port: int) -> PortType: 47 | return PORT_TYPE_VECTOR_3D 48 | 49 | func _get_global_code(mode: Shader.Mode) -> String: 50 | return "#include \"res://addons/ShaderLib_%s/Artistic/Artistic.gdshaderinc\"" % [version] 51 | 52 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 53 | var input: String = "vec3(1.0)" 54 | 55 | if input_vars[0]: 56 | input = input_vars[0] 57 | 58 | var contrast: String = input_vars[1] 59 | return output_vars[0] + " = contrast(%s, %s);" % [input, contrast] 60 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Artistic/Adjustment/Hue.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeAdjustmentHue extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "Hue" 6 | 7 | func _get_category() -> String: 8 | return "Artistic/Adjustment" 9 | 10 | func _get_description() -> String: 11 | return "Offsets the hue of input in by the amount of input offset." 12 | 13 | func _get_return_icon_type() -> PortType: 14 | return PORT_TYPE_VECTOR_3D 15 | 16 | func _get_input_port_count() -> int: 17 | return 2 18 | 19 | func _get_input_port_name(port: int) -> String: 20 | match port: 21 | 0: 22 | return "in" 23 | _: 24 | return "offset" 25 | 26 | func _get_input_port_type(port: int) -> PortType: 27 | match port: 28 | 0: 29 | return PORT_TYPE_VECTOR_3D 30 | _: 31 | return PORT_TYPE_SCALAR 32 | 33 | func _get_input_port_default_value(port: int) -> Variant: 34 | match port: 35 | 1: 36 | return 0.0 37 | _: 38 | return Vector3(1.0, 1.0, 1.0) 39 | 40 | func _get_output_port_count() -> int: 41 | return 1 42 | 43 | func _get_output_port_name(port: int) -> String: 44 | return "out" 45 | 46 | func _get_output_port_type(port: int) -> PortType: 47 | return PORT_TYPE_VECTOR_3D 48 | 49 | func _get_property_count() -> int: 50 | return 1 51 | 52 | func _get_property_default_index(index: int) -> int: 53 | return 0 54 | 55 | func _get_property_name(index: int) -> String: 56 | return "Range" 57 | 58 | func _get_property_options(index: int) -> PackedStringArray: 59 | return ["Degrees", "Normalize"] 60 | 61 | func _get_global_code(mode: Shader.Mode) -> String: 62 | return "#include \"res://addons/ShaderLib_%s/Artistic/Artistic.gdshaderinc\"" % [version] 63 | 64 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 65 | var range_index: int = get_option_index(0) 66 | var input: String = "vec3(1.0)" 67 | var offset: String = input_vars[1] 68 | 69 | if input_vars[0]: 70 | input = input_vars[0] 71 | 72 | return output_vars[0] + " = hue(%s, %s, %s);" % [input, offset, range_index] 73 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Artistic/Adjustment/ReplaceColor.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeAdjustmentReplaceColor extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "ReplaceColor" 6 | 7 | func _get_category() -> String: 8 | return "Artistic/Adjustment" 9 | 10 | func _get_description() -> String: 11 | return "Replaces values in input \"in\" equal to input \"from\" to the value of input \"to\"." 12 | 13 | func _get_return_icon_type() -> PortType: 14 | return PORT_TYPE_VECTOR_3D 15 | 16 | func _get_input_port_count() -> int: 17 | return 5 18 | 19 | func _get_input_port_name(port: int) -> String: 20 | match port: 21 | 0: 22 | return "in" 23 | 1: 24 | return "from" 25 | 2: 26 | return "to" 27 | 3: 28 | return "range" 29 | _: 30 | return "fuzziness" 31 | 32 | func _get_input_port_type(port: int) -> PortType: 33 | match port: 34 | 0, 1, 2: 35 | return PORT_TYPE_VECTOR_3D 36 | _: 37 | return PORT_TYPE_SCALAR 38 | 39 | func _get_input_port_default_value(port: int) -> Variant: 40 | match port: 41 | 1, 2: 42 | return Vector3(0.0, 0.0, 0.0) 43 | 3, 4: 44 | return 0.0 45 | _: 46 | return Vector3(1.0, 1.0, 1.0) 47 | 48 | func _get_output_port_count() -> int: 49 | return 1 50 | 51 | func _get_output_port_name(port: int) -> String: 52 | return "out" 53 | 54 | func _get_output_port_type(port: int) -> PortType: 55 | return PORT_TYPE_VECTOR_3D 56 | 57 | func _get_global_code(mode: Shader.Mode) -> String: 58 | return "#include \"res://addons/ShaderLib_%s/Artistic/Artistic.gdshaderinc\"" % [version] 59 | 60 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 61 | var input: String = "vec3(1.0)" 62 | var from: String = "vec3(1.0)" 63 | var to: String = "vec3(1.0)" 64 | 65 | if input_vars[0]: 66 | input = input_vars[0] 67 | 68 | if input_vars[1]: 69 | from = input_vars[1] 70 | 71 | if input_vars[2]: 72 | to = input_vars[2] 73 | 74 | var range: String = input_vars[3] 75 | var fuzziness: String = input_vars[4] 76 | 77 | return output_vars[0] + " = replace_color(%s, %s, %s, %s, %s);" % [input, from, to, range, fuzziness] 78 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Artistic/Adjustment/Saturation.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeAdjustmentSaturation extends ShaderLib 3 | 4 | 5 | func _get_name() -> String: 6 | return "Saturation" 7 | 8 | func _get_category() -> String: 9 | return "Artistic/Adjustment" 10 | 11 | func _get_description() -> String: 12 | return "Adjusts the saturation of input \"in\" by the amount of input \"saturation\"." 13 | 14 | func _get_return_icon_type() -> PortType: 15 | return PORT_TYPE_VECTOR_3D 16 | 17 | func _get_input_port_count() -> int: 18 | return 2 19 | 20 | func _get_input_port_name(port: int) -> String: 21 | match port: 22 | 0: 23 | return "in" 24 | _: 25 | return "saturation" 26 | 27 | func _get_input_port_type(port: int) -> PortType: 28 | match port: 29 | 0: 30 | return PORT_TYPE_VECTOR_3D 31 | _: 32 | return PORT_TYPE_SCALAR 33 | 34 | func _get_input_port_default_value(port: int) -> Variant: 35 | match port: 36 | 0: 37 | return Vector3(1.0, 1.0, 1.0) 38 | _: 39 | return 1.0 40 | 41 | func _get_output_port_count() -> int: 42 | return 1 43 | 44 | func _get_output_port_name(port: int) -> String: 45 | return "out" 46 | 47 | func _get_output_port_type(port: int) -> PortType: 48 | return PORT_TYPE_VECTOR_3D 49 | 50 | func _get_global_code(mode: Shader.Mode) -> String: 51 | return "#include \"res://addons/ShaderLib_%s/Artistic/Artistic.gdshaderinc\"" % [version] 52 | 53 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 54 | var input: String = "vec3(1.0)" 55 | 56 | if input_vars[0]: 57 | input = input_vars[0] 58 | 59 | var saturation = input_vars[1] 60 | return output_vars[0] + " = saturation(%s, %s);" % [input, saturation] 61 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Artistic/Adjustment/WhiteBalance.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeWhiteBalance extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "WhiteBalance" 6 | 7 | func _get_category() -> String: 8 | return "Artistic/Adjustment" 9 | 10 | func _get_description() -> String: 11 | return "Adjusts the temperature and tint of input \"in\" by the amount of inputs \"temperature\" and \"tint\" respectively." 12 | 13 | func _get_return_icon_type() -> PortType: 14 | return PORT_TYPE_VECTOR_3D 15 | 16 | func _get_input_port_count() -> int: 17 | return 3 18 | 19 | func _get_input_port_name(port: int) -> String: 20 | match port: 21 | 0: 22 | return "in" 23 | 1: 24 | return "temperature" 25 | _: 26 | return "tint" 27 | 28 | func _get_input_port_type(port: int) -> PortType: 29 | match port: 30 | 0: 31 | return PORT_TYPE_VECTOR_3D 32 | _: 33 | return PORT_TYPE_SCALAR 34 | 35 | func _get_input_port_default_value(port: int) -> Variant: 36 | match port: 37 | 1, 2: 38 | return 0.0 39 | _: 40 | return Vector3(1.0, 1.0, 1.0) 41 | 42 | func _get_output_port_count() -> int: 43 | return 1 44 | 45 | func _get_output_port_name(port: int) -> String: 46 | return "out" 47 | 48 | func _get_output_port_type(port: int) -> PortType: 49 | return PORT_TYPE_VECTOR_3D 50 | 51 | func _get_global_code(mode: Shader.Mode) -> String: 52 | return "#include \"res://addons/ShaderLib_%s/Artistic/Artistic.gdshaderinc\"" % [version] 53 | 54 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 55 | var input: String = "vec3(1.0)" 56 | 57 | if input_vars[0]: 58 | input = input_vars[0] 59 | 60 | var temperature: String = input_vars[1] 61 | var tint: String = input_vars[2] 62 | 63 | return output_vars[0] + " = white_balance(%s, %s, %s);" % [input, temperature, tint] 64 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Artistic/Artistic.gdshaderinc: -------------------------------------------------------------------------------- 1 | vec3 contrast(vec3 input, float contrast) { 2 | float midpoint = pow(0.5, 2.2); 3 | return (input - midpoint) * contrast + midpoint; 4 | } 5 | 6 | vec3 hue(vec3 input, float offset, int range_index) { 7 | // RGB to HSV 8 | vec4 k = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); 9 | vec4 p = mix(vec4(input.bg, k.wz), vec4(input.gb, k.xy), step(input.b, input.g)); 10 | vec4 q = mix(vec4(p.xyw, input.r), vec4(input.r, p.yzx), step(p.x, input.r)); 11 | float d = q.x - min(q.w, q.y); 12 | float e = 1.0e-10; 13 | vec3 hsv = vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); 14 | 15 | offset = (range_index == 0) ? offset / 360.0 : offset; 16 | float hue = hsv.x + offset; 17 | if(hue < 0.0){ 18 | hsv.x = hue + 1.; 19 | } 20 | else if(hue > 1.){ 21 | hsv.x = hue - 1.; 22 | } 23 | else{ 24 | hsv.x = hue; 25 | } 26 | 27 | // HSV to RGB 28 | vec4 k2 = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); 29 | vec3 p2 = abs(fract(hsv.xxx + k2.xyz) * 6.0 - k2.www); 30 | vec3 rgb = hsv.z * mix(k2.xxx, clamp(p2 - k2.xxx, 0.0, 1.0), hsv.y); 31 | return rgb; 32 | } 33 | 34 | vec3 replace_color(vec3 input, vec3 from, vec3 to, float range, float fuzziness) { 35 | float dist = distance(from, input); 36 | return mix(to, input, clamp((dist - range) / max(fuzziness, 1.0e-5), 0.0, 1.0)); 37 | } 38 | 39 | vec3 saturation(vec3 input, float saturation) { 40 | float luma = dot(input, vec3(0.2126729, 0.7151522, 0.0721750)); 41 | return luma + saturation * (input - vec3(luma)); 42 | } 43 | 44 | vec3 white_balance(vec3 input, float temperature, float tint) { 45 | float t1 = temperature * 10.0 / 6.0; 46 | float t2 = tint * 10.0 / 6.0; 47 | 48 | float x = 0.31271 - t1 * (t1 < 0.0 ? 0.1 : 0.05); 49 | float standard_illuminant_y = 2.87 * x - 3.0 * x * x - 0.27509507; 50 | float y = standard_illuminant_y + t2 * 0.05; 51 | 52 | vec3 w1 = vec3(0.949237, 1.03542, 1.08728); 53 | 54 | float Y = 1.; 55 | float X = Y * x / y; 56 | float Z = Y * (1. - x - y) / y; 57 | float L = 0.7328 * X + 0.4296 * Y - 0.1624 * Z; 58 | float M = -0.7036 * X + 1.6975 * Y + 0.0061 * Z; 59 | float S = 0.0030 * X + 0.0136 * Y + 0.9834 * Z; 60 | vec3 w2 = vec3(L, M, S); 61 | 62 | vec3 balance = vec3(w1.x / w2.x, w1.y / w2.y, w1.z / w2.z); 63 | 64 | mat3 LIN_2_LMS_MAT = mat3( 65 | vec3(3.90405e-1, 5.49941e-1, 8.92632e-3), 66 | vec3(7.08416e-2, 9.63172e-1, 1.35775e-3), 67 | vec3(2.31082e-2, 1.28021e-1, 9.36245e-1) 68 | ); 69 | 70 | mat3 LMS_2_LIN_MAT = mat3( 71 | vec3(2.85847, -1.62879, -2.48910), 72 | vec3(-2.10182e-1, 1.15820e+0, 3.24281e-4), 73 | vec3(-4.18120e-2, -1.18169e-1, 1.06867e+0) 74 | ); 75 | 76 | vec3 lms = LIN_2_LMS_MAT * input; 77 | lms *= balance; 78 | return LMS_2_LIN_MAT * lms; 79 | } 80 | 81 | vec4 color_mask(vec3 input, vec3 mask_color, float range, float fuzziness) { 82 | float dist = distance(mask_color, input); 83 | return vec4(clamp(1. - (dist - range) / max(fuzziness, 1e-5), 0., 1.)); 84 | } -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Artistic/Mask/ColorMask.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeMaskColorMask extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "ColorMask" 6 | 7 | func _get_category() -> String: 8 | return "Artistic/Mask" 9 | 10 | func _get_description() -> String: 11 | return "Creates a mask from values in input \"in\" equal to input \"mask color\"." 12 | 13 | func _get_return_icon_type() -> PortType: 14 | return PORT_TYPE_VECTOR_4D 15 | 16 | func _get_input_port_count() -> int: 17 | return 4 18 | 19 | func _get_input_port_name(port: int) -> String: 20 | match port: 21 | 0: 22 | return "in" 23 | 1: 24 | return "color mask" 25 | 2: 26 | return "range" 27 | _: 28 | return "fuzziness" 29 | 30 | func _get_input_port_type(port: int) -> PortType: 31 | match port: 32 | 0, 1: 33 | return PORT_TYPE_VECTOR_3D 34 | _: 35 | return PORT_TYPE_SCALAR 36 | 37 | func _get_input_port_default_value(port: int) -> Variant: 38 | match port: 39 | 0: 40 | return Vector3(1.0, 1.0, 1.0) 41 | 1: 42 | return Vector3(0.0, 0.0, 0.0) 43 | _: 44 | return 0.0 45 | 46 | func _get_output_port_count() -> int: 47 | return 1 48 | 49 | func _get_output_port_name(port: int) -> String: 50 | return "out" 51 | 52 | func _get_output_port_type(port: int) -> PortType: 53 | return PORT_TYPE_VECTOR_4D 54 | 55 | func _get_global_code(mode: Shader.Mode) -> String: 56 | return "#include \"res://addons/ShaderLib_%s/Artistic/Artistic.gdshaderinc\"" % [version] 57 | 58 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 59 | var input: String = "vec3(0.0)" 60 | 61 | if input_vars[0]: 62 | input = input_vars[0] 63 | 64 | var color_mask: String = input_vars[1] 65 | var range: String = input_vars[2] 66 | var fuzziness: String = input_vars[3] 67 | 68 | return output_vars[0] + " = color_mask(%s, %s, %s, %s);" % [input, color_mask, range, fuzziness] 69 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Geometry/Geometry.gdshaderinc: -------------------------------------------------------------------------------- 1 | vec3 node_scale_world(mat4 model_matrix) { 2 | vec3 axis_x = model_matrix[0].xyz; 3 | vec3 axis_y = model_matrix[1].xyz; 4 | vec3 axis_z = model_matrix[2].xyz; 5 | 6 | float scale_x = length(axis_x); 7 | float scale_y = length(axis_y); 8 | float scale_z = length(axis_z); 9 | 10 | return vec3(scale_x, scale_y, scale_z); 11 | } -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Geometry/MeshNode.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeGeometryMeshNode extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "MeshNode" 6 | 7 | func _get_category() -> String: 8 | return "Geometry" 9 | 10 | func _get_description() -> String: 11 | return "Provides accees to node scale in world space." 12 | 13 | func _get_input_port_count() -> int: 14 | return 0 15 | 16 | func _get_input_port_name(port: int) -> String: 17 | return "" 18 | 19 | func _get_return_icon_type() -> VisualShaderNode.PortType: 20 | return PORT_TYPE_VECTOR_3D 21 | 22 | func _get_output_port_count() -> int: 23 | return 2 24 | 25 | func _get_output_port_name(port: int) -> String: 26 | match port: 27 | 0: 28 | return "position" 29 | _: 30 | return "scale" 31 | 32 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 33 | return PORT_TYPE_VECTOR_3D 34 | 35 | func _is_available(mode: Shader.Mode, type: VisualShader.Type) -> bool: 36 | match mode: 37 | 0: 38 | return true 39 | 1: 40 | return type==0 41 | _: 42 | return false 43 | 44 | func _get_global_code(mode: Shader.Mode) -> String: 45 | return "#include \"res://addons/ShaderLib_%s/Geometry/Geometry.gdshaderinc\"" % [version] 46 | 47 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 48 | var code: String 49 | code = "%s = NODE_POSITION_WORLD;" % output_vars[0] 50 | code += "\n%s = node_scale_world(MODEL_MATRIX);" % output_vars[1] 51 | return code 52 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Digvijaysinh Gohil 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Maths/Maths.gdshaderinc: -------------------------------------------------------------------------------- 1 | float chebyshev_distance_2d(vec2 point1, vec2 point2, float power) { 2 | vec2 p = abs(point1 - point2); 3 | return pow(pow(p.x, power) + pow(p.y, power), 1. / power); 4 | } 5 | 6 | float chebyshev_distance_3d(vec3 point1, vec3 point2, float power) { 7 | vec3 p = abs(point1 - point2); 8 | return pow(pow(p.x, power) + pow(p.y, power) + pow(p.z, power), 1. / power); 9 | } 10 | 11 | float manhattan_distance_2d(vec2 point1, vec2 point2) { 12 | vec2 d = point1 - point2; 13 | return abs(d.x) + abs(d.y); 14 | } 15 | 16 | float manhattan_distance_3d(vec3 point1, vec3 point2) { 17 | vec3 d = point1 - point2; 18 | return abs(d.x) + abs(d.y) + abs(d.z); 19 | } 20 | 21 | vec2 project_2d(vec2 a, vec2 b) { 22 | return b * (dot(a, b) / dot(b, b)); 23 | } 24 | 25 | vec3 project_3d(vec3 a, vec3 b) { 26 | return b * (dot(a, b) / dot(b, b)); 27 | } 28 | 29 | vec3 project_on_plane(vec3 vector, vec3 plane_normal) { 30 | return vector - (plane_normal * (dot(vector, plane_normal) / dot(plane_normal, plane_normal))); 31 | } 32 | 33 | float smoothmin(float a, float b, float t) { 34 | float h = clamp(.5 + .5 * (b - a) / t, 0, 1); 35 | return mix(b, a, h) - t * h * (1. - h); 36 | } 37 | 38 | float smoothmax(float a, float b, float t) { 39 | float h = clamp(.5 + .5 * (b - a) / -t, 0, 1); 40 | return mix(b, a, h) + t * h * (1. - h); 41 | } 42 | 43 | vec3 vector_transform_world_to_local(mat4 model_matrix, vec3 vector) { 44 | return (inverse(model_matrix) * vec4(vector, 1.0)).xyz; 45 | } 46 | 47 | vec3 vector_transform_world_to_view(mat4 view_matrix, vec3 vector) { 48 | return (view_matrix * vec4(vector, 1.0)).xyz; 49 | } 50 | 51 | vec3 vector_transform_world_to_screen(mat4 view_matrix, mat4 projection_matrix, vec3 vector) { 52 | vec3 vector_view = vector_transform_world_to_view(view_matrix, vector); 53 | return (projection_matrix * vec4(vector_view, 1.0)).xyz; 54 | } 55 | 56 | vec3 vector_transform_world_to_tangent(mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) { 57 | mat3 local_to_tangent_matrix = mat3(tangent, binormal, normal); 58 | vec3 vector_local = vector_transform_world_to_local(model_matrix, vector); 59 | return local_to_tangent_matrix * vector_local; 60 | } 61 | 62 | vec3 vector_transform_local_to_world(mat4 model_matrix, vec3 vector) { 63 | return (model_matrix * vec4(vector, 1.0)).xyz; 64 | } 65 | 66 | vec3 vector_transform_local_to_view(mat4 model_matrix, mat4 view_matrix, vec3 vector) { 67 | vec3 vector_world = vector_transform_local_to_world(model_matrix, vector); 68 | return (view_matrix * vec4(vector_world, 1.0)).xyz; 69 | } 70 | 71 | vec3 vector_transform_local_to_screen(mat4 model_matrix, mat4 view_matrix, mat4 projection_matrix, vec3 vector) { 72 | vec3 vector_view = vector_transform_local_to_view(model_matrix, view_matrix, vector); 73 | return (projection_matrix * vec4(vector_view, 1.0)).xyz; 74 | } 75 | 76 | vec3 vector_transform_local_to_tangent(vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) { 77 | mat3 local_to_tangent_matrix = mat3(tangent, binormal, normal); 78 | return local_to_tangent_matrix * vector; 79 | } 80 | 81 | vec3 vector_transform_view_to_world(mat4 inv_view_matrix, vec3 vector) { 82 | return (inv_view_matrix * vec4(vector, 1.0)).xyz;; 83 | } 84 | 85 | vec3 vector_transform_view_to_local(mat4 inv_view_matrix, mat4 model_matrix, vec3 vector) { 86 | vec3 vector_world = vector_transform_view_to_world(inv_view_matrix, vector); 87 | return vector_transform_world_to_local(model_matrix, vector_world); 88 | } 89 | 90 | vec3 vector_transform_view_to_screen(mat4 projection_matrix, vec3 vector) { 91 | return (projection_matrix * vec4(vector, 1.0)).xyz; 92 | } 93 | 94 | vec3 vector_transform_view_to_tangent(mat4 inv_view_matrix, mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) { 95 | mat3 local_to_tangent_matrix = mat3(tangent, binormal, normal); 96 | vec3 vector_local = vector_transform_view_to_local(inv_view_matrix, model_matrix, vector); 97 | return vector_transform_local_to_tangent(normal, binormal, tangent, vector_local); 98 | } 99 | 100 | vec3 vector_transform_screen_to_view(mat4 inv_projection_matrix, vec3 vector) { 101 | return (inv_projection_matrix * vec4(vector, 1.0)).xyz;; 102 | } 103 | 104 | vec3 vector_transform_screen_to_local(mat4 inv_projection_matrix, mat4 inv_view_matrix, mat4 model_matrix, vec3 vector) { 105 | vec3 vector_view = vector_transform_screen_to_view(inv_projection_matrix, vector); 106 | return vector_transform_view_to_local(inv_view_matrix, model_matrix, vector_view); 107 | } 108 | 109 | vec3 vector_transform_screen_to_world(mat4 inv_projection_matrix, mat4 inv_view_matrix, vec3 vector) { 110 | vec3 vector_view = vector_transform_screen_to_view(inv_projection_matrix, vector); 111 | return vector_transform_view_to_world(inv_view_matrix, vector_view); 112 | } 113 | 114 | vec3 vector_transform_screen_to_tangent(mat4 inv_projection_matrix, mat4 inv_view_matrix, mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) { 115 | mat3 local_to_tangent_matrix = mat3(tangent, binormal, normal); 116 | vec3 vector_local = vector_transform_screen_to_local(inv_projection_matrix, inv_view_matrix, model_matrix, vector); 117 | return local_to_tangent_matrix * vector_local; 118 | } 119 | 120 | vec3 vector_transform_tangent_to_local(vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) { 121 | mat3 tangent_to_local_matrix = inverse(mat3(tangent, binormal, normal)); 122 | return tangent_to_local_matrix * vector; 123 | } 124 | 125 | vec3 vector_transform_tangent_to_world(mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) { 126 | mat3 tangent_to_local_matrix = inverse(mat3(tangent, binormal, normal)); 127 | vec3 vector_local = tangent_to_local_matrix * vector; 128 | return vector_transform_local_to_world(model_matrix, vector_local); 129 | } 130 | 131 | vec3 vector_transform_tangent_to_view(mat4 model_matrix, mat4 view_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) { 132 | mat3 tangent_to_local_matrix = inverse(mat3(tangent, binormal, normal)); 133 | vec3 vector_local = tangent_to_local_matrix * vector; 134 | return vector_transform_local_to_view(model_matrix, view_matrix, vector_local); 135 | } 136 | 137 | vec3 vector_transform_tangent_to_screen(mat4 model_matrix, mat4 view_matrix, mat4 projection_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) { 138 | mat3 tangent_to_local_matrix = inverse(mat3(tangent, binormal, normal)); 139 | vec3 vector_local = tangent_to_local_matrix * vector; 140 | return vector_transform_local_to_screen(model_matrix, view_matrix, projection_matrix, vector_local); 141 | } 142 | 143 | vec4 noise_sine_wave(vec4 input, vec2 min_max) { 144 | vec4 sin_in = sin(input); 145 | vec4 sin_in_offset = sin(input + 1.0); 146 | vec4 random_number = fract(sin((sin_in - sin_in_offset) * (12.9898 + 78.233)) * 43758.5453); 147 | float noise = mix(min_max.x, min_max.y, random_number.x); 148 | return sin_in + vec4(noise); 149 | } 150 | 151 | vec4 sawtooth_wave(vec4 input) { 152 | return 2. * (input - floor(.5 + input)); 153 | } 154 | 155 | vec4 square_wave(vec4 input) { 156 | return 1. - 2. * round(fract(input)); 157 | } 158 | 159 | vec4 triangle_wave(vec4 input) { 160 | return 2. * abs(2. * (input - floor(.5 + input))) - 1.; 161 | } -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Maths/Scalar/SmoothMax.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeScalarSmoothMax extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "SmoothMax" 6 | 7 | func _get_category() -> String: 8 | return "Maths/Scalar" 9 | 10 | func _get_description() -> String: 11 | return "Returns the maximum value between A and B, but smooths out the intersections of A and B based on T." 12 | 13 | func _get_return_icon_type() -> PortType: 14 | return PORT_TYPE_SCALAR 15 | 16 | func _get_input_port_count() -> int: 17 | return 3 18 | 19 | func _get_input_port_name(port: int) -> String: 20 | match port: 21 | 0: 22 | return "a" 23 | 1: 24 | return "b" 25 | _: 26 | return "t" 27 | 28 | func _get_input_port_type(port: int) -> PortType: 29 | return PORT_TYPE_SCALAR 30 | 31 | func _get_input_port_default_value(port: int) -> Variant: 32 | match port: 33 | 2: 34 | return 0.5 35 | _: 36 | return 0.0 37 | 38 | func _get_output_port_count() -> int: 39 | return 1 40 | 41 | func _get_output_port_name(port: int) -> String: 42 | return "op" 43 | 44 | func _get_output_port_type(port: int) -> PortType: 45 | return PORT_TYPE_SCALAR 46 | 47 | func _get_global_code(mode: Shader.Mode) -> String: 48 | return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version] 49 | 50 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 51 | var a: String = input_vars[0] 52 | var b: String = input_vars[1] 53 | var t: String = input_vars[2] 54 | 55 | return output_vars[0] + " = smoothmax(%s, %s, %s);" % [a, b, t] 56 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Maths/Scalar/SmoothMin.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeScalarSmoothMin extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "SmoothMin" 6 | 7 | func _get_category() -> String: 8 | return "Maths/Scalar" 9 | 10 | func _get_description() -> String: 11 | return "Returns the minimum value between A and B, but smooths out the intersections of A and B based on T." 12 | 13 | func _get_return_icon_type() -> PortType: 14 | return PORT_TYPE_SCALAR 15 | 16 | func _get_input_port_count() -> int: 17 | return 3 18 | 19 | func _get_input_port_name(port: int) -> String: 20 | match port: 21 | 0: 22 | return "a" 23 | 1: 24 | return "b" 25 | _: 26 | return "t" 27 | 28 | func _get_input_port_type(port: int) -> PortType: 29 | return PORT_TYPE_SCALAR 30 | 31 | func _get_input_port_default_value(port: int) -> Variant: 32 | match port: 33 | 2: 34 | return 0.5 35 | _: 36 | return 0.0 37 | 38 | func _get_output_port_count() -> int: 39 | return 1 40 | 41 | func _get_output_port_name(port: int) -> String: 42 | return "op" 43 | 44 | func _get_output_port_type(port: int) -> PortType: 45 | return PORT_TYPE_SCALAR 46 | 47 | func _get_global_code(mode: Shader.Mode) -> String: 48 | return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version] 49 | 50 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 51 | var a: String = input_vars[0] 52 | var b: String = input_vars[1] 53 | var t: String = input_vars[2] 54 | 55 | return output_vars[0] + " = smoothmin(%s, %s, %s);" % [a, b, t] 56 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Maths/Vector/Distance/ChebyshevDistance.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeMathsChebyshevDistance extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "ChebyshevDistance" 6 | 7 | func _get_category() -> String: 8 | return "Maths/Vector/Distance" 9 | 10 | func _get_description() -> String: 11 | return "Returns the distance between two points using Chebyshev distance matrix." 12 | 13 | func _get_return_icon_type() -> PortType: 14 | return PORT_TYPE_SCALAR 15 | 16 | func _get_input_port_count() -> int: 17 | return 3 18 | 19 | func _get_input_port_name(port: int) -> String: 20 | match port: 21 | 0: 22 | return "a" 23 | 1: 24 | return "b" 25 | _: 26 | return "power" 27 | 28 | func _get_input_port_type(port: int) -> PortType: 29 | var vector_index: int = get_option_index(0) 30 | match port: 31 | 2: 32 | return PORT_TYPE_SCALAR 33 | _: 34 | match vector_index: 35 | 0: 36 | return PORT_TYPE_VECTOR_2D 37 | _: 38 | return PORT_TYPE_VECTOR_3D 39 | 40 | func _get_input_port_default_value(port: int) -> Variant: 41 | match port: 42 | 2: 43 | return 2.0 44 | _: 45 | return null 46 | 47 | func _get_output_port_count() -> int: 48 | return 1 49 | 50 | func _get_output_port_name(port: int) -> String: 51 | return "distance" 52 | 53 | func _get_output_port_type(port: int) -> PortType: 54 | return PORT_TYPE_SCALAR 55 | 56 | func _get_property_count() -> int: 57 | return 1 58 | 59 | func _get_property_name(index: int) -> String: 60 | return "" 61 | 62 | func _get_property_default_index(index: int) -> int: 63 | return 0 64 | 65 | func _get_property_options(index: int) -> PackedStringArray: 66 | return ["Vector2", "Vector3"] 67 | 68 | func _get_global_code(mode: Shader.Mode) -> String: 69 | return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version] 70 | 71 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 72 | var point_a: String 73 | var point_b: String 74 | var power: String = input_vars[2] 75 | var vector_index: int = get_option_index(0) 76 | match vector_index: 77 | 0: 78 | point_a = "vec2(0)" 79 | point_b = "vec2(0)" 80 | _: 81 | point_b = "vec3(0)" 82 | point_a = "vec3(0)" 83 | 84 | if input_vars[0]: 85 | point_a = input_vars[0] 86 | 87 | if input_vars[1]: 88 | point_b = input_vars[1] 89 | 90 | match vector_index: 91 | 0: 92 | return output_vars[0] + " = chebyshev_distance_2d(%s, %s, %s);" % [point_a, point_b, power] 93 | _: 94 | return output_vars[0] + " = chebyshev_distance_3d(%s, %s, %s);" % [point_a, point_b, power] 95 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Maths/Vector/Distance/ManhattanDistance.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeMathsManhattanDistance extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "ManhattanDistance" 6 | 7 | func _get_category() -> String: 8 | return "Maths/Vector/Distance" 9 | 10 | func _get_description() -> String: 11 | return "Returns the distance between two points using Manhattan distance matrix." 12 | 13 | func _get_return_icon_type() -> PortType: 14 | return PORT_TYPE_SCALAR 15 | 16 | func _get_input_port_count() -> int: 17 | return 2 18 | 19 | func _get_input_port_name(port: int) -> String: 20 | match port: 21 | 0: 22 | return "a" 23 | _: 24 | return "b" 25 | 26 | func _get_input_port_type(port: int) -> PortType: 27 | var vector_index: int = get_option_index(0) 28 | match vector_index: 29 | 0: 30 | return PORT_TYPE_VECTOR_2D 31 | _: 32 | return PORT_TYPE_VECTOR_3D 33 | 34 | func _get_output_port_count() -> int: 35 | return 1 36 | 37 | func _get_output_port_name(port: int) -> String: 38 | return "distance" 39 | 40 | func _get_output_port_type(port: int) -> PortType: 41 | return PORT_TYPE_SCALAR 42 | 43 | func _get_property_count() -> int: 44 | return 1 45 | 46 | func _get_property_name(index: int) -> String: 47 | return "" 48 | 49 | func _get_property_default_index(index: int) -> int: 50 | return 0 51 | 52 | func _get_property_options(index: int) -> PackedStringArray: 53 | return ["Vector2", "Vector3"] 54 | 55 | func _get_global_code(mode: Shader.Mode) -> String: 56 | return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version] 57 | 58 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 59 | var point_a: String 60 | var point_b: String 61 | var vector_index: int = get_option_index(0) 62 | match vector_index: 63 | 0: 64 | point_a = "vec2(0)" 65 | point_b = "vec2(0)" 66 | _: 67 | point_b = "vec3(0)" 68 | point_a = "vec3(0)" 69 | 70 | if input_vars[0]: 71 | point_a = input_vars[0] 72 | 73 | if input_vars[1]: 74 | point_b = input_vars[1] 75 | 76 | match vector_index: 77 | 0: 78 | return output_vars[0] + " = manhattan_distance_2d(%s, %s);" % [point_a, point_b] 79 | _: 80 | return output_vars[0] + " = manhattan_distance_3d(%s, %s);" % [point_a, point_b] 81 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Maths/Vector/Project.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeVectorProject extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "Project" 6 | 7 | func _get_category() -> String: 8 | return "Maths/Vector" 9 | 10 | func _get_description() -> String: 11 | return "Projects vector A onto vector B." 12 | 13 | func _get_return_icon_type() -> PortType: 14 | var vector_index: int = get_option_index(0) 15 | match vector_index: 16 | 0: 17 | return PORT_TYPE_VECTOR_2D 18 | _: 19 | return PORT_TYPE_VECTOR_3D 20 | 21 | func _get_input_port_count() -> int: 22 | return 2 23 | 24 | func _get_input_port_name(port: int) -> String: 25 | match port: 26 | 0: 27 | return "vector A" 28 | _: 29 | return "vector B" 30 | 31 | func _get_input_port_type(port: int) -> PortType: 32 | var vector_index: int = get_option_index(0) 33 | match vector_index: 34 | 0: 35 | return PORT_TYPE_VECTOR_2D 36 | _: 37 | return PORT_TYPE_VECTOR_3D 38 | 39 | func _get_output_port_count() -> int: 40 | return 1 41 | 42 | func _get_output_port_name(port: int) -> String: 43 | return "vector" 44 | 45 | func _get_output_port_type(port: int) -> PortType: 46 | var vector_index: int = get_option_index(0) 47 | match vector_index: 48 | 0: 49 | return PORT_TYPE_VECTOR_2D 50 | _: 51 | return PORT_TYPE_VECTOR_3D 52 | 53 | func _get_property_count() -> int: 54 | return 1 55 | 56 | func _get_property_default_index(index: int) -> int: 57 | return 0 58 | 59 | func _get_property_name(index: int) -> String: 60 | return "" 61 | 62 | func _get_property_options(index: int) -> PackedStringArray: 63 | return ["Vector2", "Vector3"] 64 | 65 | func _get_global_code(mode: Shader.Mode) -> String: 66 | return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version] 67 | 68 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 69 | var vector_a: String = input_vars[0] 70 | var vector_b: String = input_vars[1] 71 | var vector_index: int = get_option_index(0) 72 | 73 | match vector_index: 74 | 0: 75 | return output_vars[0] + " = project_2d(%s, %s);" % [vector_a, vector_b] 76 | _: 77 | return output_vars[0] + " = project_3d(%s, %s);" % [vector_a, vector_b] 78 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Maths/Vector/ProjectOnPlane.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeVectorProjectOnPlane extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "ProjectOnPlane" 6 | 7 | func _get_category() -> String: 8 | return "Maths/Vector" 9 | 10 | func _get_description() -> String: 11 | return "Projects a vector onto a plane defined by a normal orthogonal to the plane." 12 | 13 | func _get_return_icon_type() -> PortType: 14 | return PORT_TYPE_VECTOR_3D 15 | 16 | func _get_input_port_count() -> int: 17 | return 2 18 | 19 | func _get_input_port_name(port: int) -> String: 20 | match port: 21 | 0: 22 | return "vector" 23 | _: 24 | return "plane normal" 25 | 26 | func _get_input_port_type(port: int) -> PortType: 27 | return PORT_TYPE_VECTOR_3D 28 | 29 | func _get_output_port_count() -> int: 30 | return 1 31 | 32 | func _get_output_port_name(port: int) -> String: 33 | return "vector" 34 | 35 | func _get_output_port_type(port: int) -> PortType: 36 | return PORT_TYPE_VECTOR_3D 37 | 38 | func _get_global_code(mode: Shader.Mode) -> String: 39 | return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version] 40 | 41 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 42 | var vector_a: String = input_vars[0] 43 | var plane_normal: String = input_vars[1] 44 | return output_vars[0] + " = project_on_plane(%s, %s);" % [vector_a, plane_normal] 45 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Maths/Vector/VectorTransform.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeVectorTransform extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "VectorTransform" 6 | 7 | func _get_category() -> String: 8 | return "Maths/Vector" 9 | 10 | func _get_description() -> String: 11 | return "Returns the transformed vector of the input value from one coordinate space to another." 12 | 13 | func _get_return_icon_type() -> PortType: 14 | return PORT_TYPE_VECTOR_3D 15 | 16 | func _get_input_port_count() -> int: 17 | return 1 18 | 19 | func _get_input_port_name(port: int) -> String: 20 | return "in" 21 | 22 | func _get_input_port_type(port: int) -> PortType: 23 | return PORT_TYPE_VECTOR_3D 24 | 25 | func _get_output_port_count() -> int: 26 | return 1 27 | 28 | func _get_output_port_name(port: int) -> String: 29 | return "out" 30 | 31 | func _get_output_port_type(port: int) -> PortType: 32 | return PORT_TYPE_VECTOR_3D 33 | 34 | func _get_property_count() -> int: 35 | return 2 36 | 37 | func _get_property_default_index(index: int) -> int: 38 | match index: 39 | 0: 40 | return 0 41 | _: 42 | return 1 43 | 44 | func _get_property_name(index: int) -> String: 45 | match index: 46 | 0: 47 | return "From" 48 | _: 49 | return "To" 50 | 51 | func _get_property_options(index: int) -> PackedStringArray: 52 | return ["Local", "World", "View", "Screen", "Tangent"] 53 | 54 | func _is_available(mode: Shader.Mode, type: VisualShader.Type) -> bool: 55 | return mode == Shader.MODE_SPATIAL 56 | 57 | func _get_global_code(mode: Shader.Mode) -> String: 58 | return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version] 59 | 60 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 61 | var code: String 62 | var from_coord_space_index: int = get_option_index(0) 63 | var to_coord_space_index: int = get_option_index(1) 64 | var input_vector: String = input_vars[0] if input_vars[0] else "vec3(0.0, 0.0, 0.0)" 65 | 66 | match from_coord_space_index: 67 | 0: 68 | match to_coord_space_index: 69 | 0: 70 | code = "%s = %s;" % [output_vars[0], input_vector] 71 | 1: 72 | code = "%s = vector_transform_local_to_world(MODEL_MATRIX, %s);" % [output_vars[0], input_vector] 73 | 2: 74 | code = "%s = vector_transform_local_to_view(MODEL_MATRIX, VIEW_MATRIX, %s);" % [output_vars[0], input_vector] 75 | 3: 76 | code = "%s = vector_transform_local_to_screen(MODEL_MATRIX, VIEW_MATRIX, PROJECTION_MATRIX, %s);" % [output_vars[0], input_vector] 77 | 4: 78 | code = "%s = vector_transform_local_to_tangent(NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector] 79 | 1: 80 | match to_coord_space_index: 81 | 0: 82 | code = "%s = vector_transform_world_to_local(MODEL_MATRIX, %s);" % [output_vars[0], input_vector] 83 | 1: 84 | code = "%s = %s;" % [output_vars[0], input_vector] 85 | 2: 86 | code = "%s = vector_transform_world_to_view(VIEW_MATRIX, %s);" % [output_vars[0], input_vector] 87 | 3: 88 | code = "%s = vector_transform_world_to_screen(VIEW_MATRIX, PROJECTION_MATRIX, %s);" % [output_vars[0], input_vector] 89 | 4: 90 | code = "%s = vector_transform_world_to_tangent(MODEL_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector] 91 | 2: 92 | match to_coord_space_index: 93 | 0: 94 | code = "%s = vector_transform_view_to_local(INV_VIEW_MATRIX, MODEL_MATRIX, %s);" % [output_vars[0], input_vector] 95 | 1: 96 | code = "%s = vector_transform_view_to_world(INV_VIEW_MATRIX, %s);" % [output_vars[0], input_vector] 97 | 2: 98 | code = "%s = %s;" % [output_vars[0], input_vector] 99 | 3: 100 | code = "%s = vector_transform_view_to_screen(PROJECTION_MATRIX, %s);" % [output_vars[0], input_vector] 101 | 4: 102 | code = "%s = vector_transform_view_to_tangent(INV_VIEW_MATRIX, MODEL_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector] 103 | 3: 104 | match to_coord_space_index: 105 | 0: 106 | code = "%s = vector_transform_screen_to_local(INV_PROJECTION_MATRIX, INV_VIEW_MATRIX, MODEL_MATRIX, %s);" % [output_vars[0], input_vector] 107 | 1: 108 | code = "%s = vector_transform_screen_to_world(INV_PROJECTION_MATRIX, INV_VIEW_MATRIX, %s);" % [output_vars[0], input_vector] 109 | 2: 110 | code = "%s = vector_transform_screen_to_view(INV_PROJECTION_MATRIX, %s);" % [output_vars[0], input_vector] 111 | 3: 112 | code = "%s = %s;" % [output_vars[0], input_vector] 113 | 4: 114 | code = "%s = vector_transform_screen_to_tangent(INV_PROJECTION_MATRIX, INV_VIEW_MATRIX, MODEL_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector] 115 | 4: 116 | match to_coord_space_index: 117 | 0: 118 | code = "%s = vector_transform_tangent_to_local(NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector] 119 | 1: 120 | code = "%s = vector_transform_tangent_to_world(MODEL_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector] 121 | 2: 122 | code = "%s = vector_transform_tangent_to_view(MODEL_MATRIX, VIEW_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector] 123 | 3: 124 | code = "%s = vector_transform_tangent_to_screen(MODEL_MATRIX, VIEW_MATRIX, PROJECTION_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector] 125 | 4: 126 | code = "%s = %s;" % [output_vars[0], input_vector] 127 | 128 | return code 129 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Maths/Wave/NoiseSineWave.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeMathsNoiseSineWave extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "NoiseSineWave" 6 | 7 | func _get_category() -> String: 8 | return "Maths/Wave" 9 | 10 | func _get_description() -> String: 11 | return "Returns the sine of the value of input in. For variance, psuedo-random noise is added to the amplitude of the sine wave, within a range determined by input min max." 12 | 13 | func _get_return_icon_type() -> VisualShaderNode.PortType: 14 | var vector_index: int = get_option_index(0) 15 | match vector_index: 16 | 0: 17 | return PORT_TYPE_SCALAR 18 | 1: 19 | return PORT_TYPE_VECTOR_2D 20 | 2: 21 | return PORT_TYPE_VECTOR_3D 22 | _: 23 | return PORT_TYPE_VECTOR_4D 24 | 25 | func _get_input_port_count() -> int: 26 | return 2 27 | 28 | func _get_input_port_name(port: int) -> String: 29 | match port: 30 | 0: 31 | return "in" 32 | 1, _: 33 | return "min max" 34 | 35 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 36 | match port: 37 | 0: 38 | var vector_index: int = get_option_index(0) 39 | match vector_index: 40 | 0: 41 | return PORT_TYPE_SCALAR 42 | 1: 43 | return PORT_TYPE_VECTOR_2D 44 | 2: 45 | return PORT_TYPE_VECTOR_3D 46 | _: 47 | return PORT_TYPE_VECTOR_4D 48 | 1: 49 | return PORT_TYPE_VECTOR_2D 50 | return PORT_TYPE_SCALAR 51 | 52 | func _get_input_port_default_value(port: int) -> Variant: 53 | match port: 54 | 1: 55 | return Vector2(0.0, 1.0) 56 | _: 57 | return null 58 | 59 | func _get_output_port_count() -> int: 60 | return 1 61 | 62 | func _get_output_port_name(port: int) -> String: 63 | return "out" 64 | 65 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 66 | var vector_index: int = get_option_index(0) 67 | match vector_index: 68 | 0: 69 | return PORT_TYPE_SCALAR 70 | 1: 71 | return PORT_TYPE_VECTOR_2D 72 | 2: 73 | return PORT_TYPE_VECTOR_3D 74 | _: 75 | return PORT_TYPE_VECTOR_4D 76 | 77 | func _get_property_count() -> int: 78 | return 1 79 | 80 | func _get_property_default_index(index: int) -> int: 81 | return 0 82 | 83 | func _get_property_name(index: int) -> String: 84 | return "" 85 | 86 | func _get_property_options(index: int) -> PackedStringArray: 87 | return ["Vector1", "Vector2", "Vector3", "Vector4"] 88 | 89 | func _get_global_code(mode: Shader.Mode) -> String: 90 | return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version] 91 | 92 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 93 | var input: String 94 | var vector_index: int = get_option_index(0) 95 | match vector_index: 96 | 0: 97 | input = "0.0" 98 | 1: 99 | input = "vec2(0.0)" 100 | 2: 101 | input = "vec3(0.0)" 102 | _: 103 | input = "vec4(0.0)" 104 | 105 | if input_vars[0]: 106 | input = input_vars[0] 107 | 108 | var min_max: String = input_vars[1] 109 | 110 | match vector_index: 111 | 0: 112 | return output_vars[0] + " = noise_sine_wave(vec4(%s), %s).x;" % [input, min_max] 113 | 1: 114 | return output_vars[0] + " = noise_sine_wave(vec4(%s, 0.0, 0.0), %s).xy;" % [input, min_max] 115 | 2: 116 | return output_vars[0] + " = noise_sine_wave(vec4(%s, 0.0), %s).xyz;" % [input, min_max] 117 | _: 118 | return output_vars[0] + " = noise_sine_wave(%s, %s);" % [input, min_max] 119 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Maths/Wave/SawtoothWave.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeMathsSawtoothWave extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "SawtoothWave" 6 | 7 | func _get_category() -> String: 8 | return "Maths/Wave" 9 | 10 | func _get_description() -> String: 11 | return "Returns a sawtooth wave from the value of input in. Resulting output values will be between -1 and 1." 12 | 13 | func _get_return_icon_type() -> VisualShaderNode.PortType: 14 | var vector_index: int = get_option_index(0) 15 | match vector_index: 16 | 0: 17 | return PORT_TYPE_SCALAR 18 | 1: 19 | return PORT_TYPE_VECTOR_2D 20 | 2: 21 | return PORT_TYPE_VECTOR_3D 22 | _: 23 | return PORT_TYPE_VECTOR_4D 24 | 25 | func _get_input_port_count() -> int: 26 | return 1 27 | 28 | func _get_input_port_name(port: int) -> String: 29 | return "in" 30 | 31 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 32 | var vector_index: int = get_option_index(0) 33 | match vector_index: 34 | 0: 35 | return PORT_TYPE_SCALAR 36 | 1: 37 | return PORT_TYPE_VECTOR_2D 38 | 2: 39 | return PORT_TYPE_VECTOR_3D 40 | _: 41 | return PORT_TYPE_VECTOR_4D 42 | 43 | func _get_output_port_count() -> int: 44 | return 1 45 | 46 | func _get_output_port_name(port: int) -> String: 47 | return "out" 48 | 49 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 50 | var vector_index: int = get_option_index(0) 51 | match vector_index: 52 | 0: 53 | return PORT_TYPE_SCALAR 54 | 1: 55 | return PORT_TYPE_VECTOR_2D 56 | 2: 57 | return PORT_TYPE_VECTOR_3D 58 | _: 59 | return PORT_TYPE_VECTOR_4D 60 | 61 | func _get_property_count() -> int: 62 | return 1 63 | 64 | func _get_property_default_index(index: int) -> int: 65 | return 0 66 | 67 | func _get_property_name(index: int) -> String: 68 | return "" 69 | 70 | func _get_property_options(index: int) -> PackedStringArray: 71 | return ["Vector1", "Vector2", "Vector3", "Vector4"] 72 | 73 | func _get_global_code(mode: Shader.Mode) -> String: 74 | return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version] 75 | 76 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 77 | var input: String 78 | var vector_index: int = get_option_index(0) 79 | match vector_index: 80 | 0: 81 | input = "0.0" 82 | 1: 83 | input = "vec2(0.0)" 84 | 2: 85 | input = "vec3(0.0)" 86 | _: 87 | input = "vec4(0.0)" 88 | 89 | if input_vars[0]: 90 | input = input_vars[0] 91 | 92 | match vector_index: 93 | 0: 94 | return output_vars[0] + " = sawtooth_wave(vec4(%s)).x;" % [input] 95 | 1: 96 | return output_vars[0] + " = sawtooth_wave(vec4(%s, 0.0, 0.0)).xy;" % [input] 97 | 2: 98 | return output_vars[0] + " = sawtooth_wave(vec4(%s, 0.0)).xyz;" % [input] 99 | _: 100 | return output_vars[0] + " = sawtooth_wave(%s);" % [input] 101 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Maths/Wave/SquareWave.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeMathsSquareWave extends ShaderLib 3 | 4 | 5 | func _get_name() -> String: 6 | return "SquareWave" 7 | 8 | func _get_category() -> String: 9 | return "Maths/Wave" 10 | 11 | func _get_description() -> String: 12 | return "Returns a square wave from the value of input in. Resulting output values will be between -1 and 1." 13 | 14 | func _get_return_icon_type() -> VisualShaderNode.PortType: 15 | var vector_index: int = get_option_index(0) 16 | match vector_index: 17 | 0: 18 | return PORT_TYPE_SCALAR 19 | 1: 20 | return PORT_TYPE_VECTOR_2D 21 | 2: 22 | return PORT_TYPE_VECTOR_3D 23 | _: 24 | return PORT_TYPE_VECTOR_4D 25 | 26 | func _get_input_port_count() -> int: 27 | return 1 28 | 29 | func _get_input_port_name(port: int) -> String: 30 | return "input" 31 | 32 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 33 | var vector_index: int = get_option_index(0) 34 | match vector_index: 35 | 0: 36 | return PORT_TYPE_SCALAR 37 | 1: 38 | return PORT_TYPE_VECTOR_2D 39 | 2: 40 | return PORT_TYPE_VECTOR_3D 41 | _: 42 | return PORT_TYPE_VECTOR_4D 43 | 44 | func _get_output_port_count() -> int: 45 | return 1 46 | 47 | func _get_output_port_name(port: int) -> String: 48 | return "out" 49 | 50 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 51 | var vector_index: int = get_option_index(0) 52 | match vector_index: 53 | 0: 54 | return PORT_TYPE_SCALAR 55 | 1: 56 | return PORT_TYPE_VECTOR_2D 57 | 2: 58 | return PORT_TYPE_VECTOR_3D 59 | _: 60 | return PORT_TYPE_VECTOR_4D 61 | 62 | func _get_property_count() -> int: 63 | return 1 64 | 65 | func _get_property_default_index(index: int) -> int: 66 | return 0 67 | 68 | func _get_property_name(index: int) -> String: 69 | return "" 70 | 71 | func _get_property_options(index: int) -> PackedStringArray: 72 | return ["Vector1", "Vector2", "Vector3", "Vector4"] 73 | 74 | func _get_global_code(mode: Shader.Mode) -> String: 75 | return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version] 76 | 77 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 78 | var input: String 79 | var vector_index: int = get_option_index(0) 80 | match vector_index: 81 | 0: 82 | input = "0.0" 83 | 1: 84 | input = "vec2(0.0)" 85 | 2: 86 | input = "vec3(0.0)" 87 | _: 88 | input = "vec4(0.0)" 89 | 90 | if input_vars[0]: 91 | input = input_vars[0] 92 | 93 | match vector_index: 94 | 0: 95 | return output_vars[0] + " = square_wave(vec4(%s)).x;" % [input] 96 | 1: 97 | return output_vars[0] + " = square_wave(vec4(%s, 0.0, 0.0)).xy;" % [input] 98 | 2: 99 | return output_vars[0] + " = square_wave(vec4(%s, 0.0)).xyz;" % [input] 100 | _: 101 | return output_vars[0] + " = square_wave(%s);" % [input] 102 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Maths/Wave/TriangleWave.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeMathsTriangleWave extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "TriangleWave" 6 | 7 | func _get_category() -> String: 8 | return "Maths/Wave" 9 | 10 | func _get_description() -> String: 11 | return "Returns a triangle wave from the value of input in. Resulting output values will be between -1 and 1." 12 | 13 | func _get_return_icon_type() -> VisualShaderNode.PortType: 14 | var vector_index: int = get_option_index(0) 15 | match vector_index: 16 | 0: 17 | return PORT_TYPE_SCALAR 18 | 1: 19 | return PORT_TYPE_VECTOR_2D 20 | 2: 21 | return PORT_TYPE_VECTOR_3D 22 | _: 23 | return PORT_TYPE_VECTOR_4D 24 | 25 | func _get_input_port_count() -> int: 26 | return 1 27 | 28 | func _get_input_port_name(port: int) -> String: 29 | return "in" 30 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 31 | var vector_index: int = get_option_index(0) 32 | match vector_index: 33 | 0: 34 | return PORT_TYPE_SCALAR 35 | 1: 36 | return PORT_TYPE_VECTOR_2D 37 | 2: 38 | return PORT_TYPE_VECTOR_3D 39 | _: 40 | return PORT_TYPE_VECTOR_4D 41 | 42 | func _get_output_port_count() -> int: 43 | return 1 44 | 45 | func _get_output_port_name(port: int) -> String: 46 | return "out" 47 | 48 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 49 | var vector_index: int = get_option_index(0) 50 | match vector_index: 51 | 0: 52 | return PORT_TYPE_SCALAR 53 | 1: 54 | return PORT_TYPE_VECTOR_2D 55 | 2: 56 | return PORT_TYPE_VECTOR_3D 57 | _: 58 | return PORT_TYPE_VECTOR_4D 59 | 60 | func _get_property_count() -> int: 61 | return 1 62 | 63 | func _get_property_default_index(index: int) -> int: 64 | return 0 65 | 66 | func _get_property_name(index: int) -> String: 67 | return "" 68 | 69 | func _get_property_options(index: int) -> PackedStringArray: 70 | return ["Vector1", "Vector2", "Vector3", "Vector4"] 71 | 72 | func _get_global_code(mode: Shader.Mode) -> String: 73 | return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version] 74 | 75 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 76 | var input: String 77 | var vector_index: int = get_option_index(0) 78 | match vector_index: 79 | 0: 80 | input = "0.0" 81 | 1: 82 | input = "vec2(0.0)" 83 | 2: 84 | input = "vec3(0.0)" 85 | _: 86 | input = "vec4(0.0)" 87 | 88 | if input_vars[0]: 89 | input = input_vars[0] 90 | 91 | match vector_index: 92 | 0: 93 | return output_vars[0] + " = triangle_wave(vec4(%s)).x;" % [input] 94 | 1: 95 | return output_vars[0] + " = triangle_wave(vec4(%s, 0.0, 0.0)).xy;" % [input] 96 | 2: 97 | return output_vars[0] + " = triangle_wave(vec4(%s, 0.0)).xyz;" % [input] 98 | _: 99 | return output_vars[0] + " = triangle_wave(%s);" % [input] 100 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Procedural/CheckerBoard.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeProceduralCheckerBoard extends ShaderLib 3 | 4 | func _init() -> void: 5 | output_port_for_preview = 0 6 | 7 | func _get_name() -> String: 8 | return "CheckerBoard" 9 | 10 | func _get_category() -> String: 11 | return "Procedural" 12 | 13 | func _get_description() -> String: 14 | return "Generates a checkerboard of alternating colors between inputs Color A and Color B based on input UV." 15 | 16 | func _get_return_icon_type() -> VisualShaderNode.PortType: 17 | return PORT_TYPE_VECTOR_3D 18 | 19 | func _get_input_port_count() -> int: 20 | return 4 21 | 22 | func _get_input_port_name(port: int) -> String: 23 | match port: 24 | 0: 25 | return "uv" 26 | 1: 27 | return "color A" 28 | 2: 29 | return "color B" 30 | 3: 31 | return "frequency" 32 | return "" 33 | 34 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 35 | match port: 36 | 0, 3: 37 | return PORT_TYPE_VECTOR_2D 38 | 1, 2: 39 | return PORT_TYPE_VECTOR_3D 40 | return PORT_TYPE_SCALAR 41 | 42 | func _get_input_port_default_value(port: int) -> Variant: 43 | match port: 44 | 1: 45 | return Vector3(1.0, 1.0, 1.0) 46 | 2: 47 | return Vector3(0.4, 0.4, 0.4) 48 | 3: 49 | return Vector2(1.0, 1.0) 50 | _: 51 | return null 52 | 53 | func _get_output_port_count() -> int: 54 | return 1 55 | 56 | func _get_output_port_name(port: int) -> String: 57 | return "output" 58 | 59 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 60 | return PORT_TYPE_VECTOR_3D 61 | 62 | func _get_global_code(mode: Shader.Mode) -> String: 63 | return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version] 64 | 65 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 66 | var uv: String = "UV" 67 | 68 | if input_vars[0]: 69 | uv = input_vars[0] 70 | 71 | var color_a: String = input_vars[1] 72 | var color_b: String = input_vars[2] 73 | var frequency: String = input_vars[3] 74 | 75 | return output_vars[0] + " = checker_board(%s, %s.xyz, %s.xyz, %s);" % [uv, color_a, color_b, frequency] 76 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Procedural/Fractals/KochFractal.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeProceduralKochFractal extends ShaderLib 3 | 4 | func _init() -> void: 5 | output_port_for_preview = 0 6 | 7 | func _get_name() -> String: 8 | return "KochFractal" 9 | 10 | func _get_category() -> String: 11 | return "Procedural/Fractals" 12 | 13 | func _get_description() -> String: 14 | return "Generates an koch curve similar to ice fractal shape based on input UV at the size specified by inputs width and height." 15 | 16 | func _get_return_icon_type() -> PortType: 17 | return PORT_TYPE_SCALAR 18 | 19 | func _get_input_port_count() -> int: 20 | return 5 21 | 22 | func _get_input_port_name(port: int) -> String: 23 | match port: 24 | 0: 25 | return "uv" 26 | 1: 27 | return "thickness" 28 | 2: 29 | return "iterations" 30 | 3: 31 | return "widht" 32 | _: 33 | return "height" 34 | 35 | func _get_input_port_type(port: int) -> PortType: 36 | match port: 37 | 0: 38 | return PORT_TYPE_VECTOR_2D 39 | 2: 40 | return PORT_TYPE_SCALAR_INT 41 | _: 42 | return PORT_TYPE_SCALAR 43 | 44 | func _get_input_port_default_value(port: int) -> Variant: 45 | match port: 46 | 1, 3, 4: 47 | return 1.0 48 | 2: 49 | return 3 50 | _: 51 | return null 52 | 53 | func _get_output_port_count() -> int: 54 | return 2 55 | 56 | func _get_output_port_name(port: int) -> String: 57 | match port: 58 | 0: 59 | return "out" 60 | _: 61 | return "uv" 62 | 63 | func _get_output_port_type(port: int) -> PortType: 64 | match port: 65 | 1: 66 | return PORT_TYPE_VECTOR_2D 67 | _: 68 | return PORT_TYPE_SCALAR 69 | 70 | func _get_global_code(mode: Shader.Mode) -> String: 71 | return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version] 72 | 73 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 74 | var uv: String = "UV" 75 | 76 | if input_vars[0]: 77 | uv = input_vars[0] 78 | 79 | var thickness: String = input_vars[1] 80 | var iterations: String = input_vars[2] 81 | var width: String = input_vars[3] 82 | var height: String = input_vars[4] 83 | 84 | return output_vars[0] + " = koch_fractal(%s, %s, %s, %s, %s, %s);" % [uv, thickness, iterations, width, height, output_vars[1]] 85 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Procedural/HeightToNormal.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeProceduralHeightToNormal extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "HeightToNormal" 6 | 7 | func _get_category() -> String: 8 | return "Procedural" 9 | 10 | func _get_description() -> String: 11 | return "Generates a normal map from a height map." 12 | 13 | func _get_return_icon_type() -> PortType: 14 | return PORT_TYPE_VECTOR_3D 15 | 16 | func _get_input_port_count() -> int: 17 | return 3 18 | 19 | func _get_input_port_name(port: int) -> String: 20 | match port: 21 | 0: 22 | return "height map" 23 | 1: 24 | return "uv" 25 | 2: 26 | return "bump strength" 27 | return "" 28 | 29 | func _get_input_port_type(port: int) -> PortType: 30 | match port: 31 | 0: 32 | return PORT_TYPE_SAMPLER 33 | 1: 34 | return PORT_TYPE_VECTOR_2D 35 | _: 36 | return PORT_TYPE_SCALAR 37 | 38 | func _get_input_port_default_value(port: int) -> Variant: 39 | match port: 40 | 2: 41 | return 8.0 42 | _: 43 | return null 44 | 45 | func _get_output_port_count() -> int: 46 | return 1 47 | 48 | func _get_output_port_name(port: int) -> String: 49 | return "normal" 50 | 51 | func _get_output_port_type(port: int) -> PortType: 52 | return PORT_TYPE_VECTOR_3D 53 | 54 | func _get_global_code(mode: Shader.Mode) -> String: 55 | return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version] 56 | 57 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 58 | var uv: String = "UV" 59 | if input_vars[1]: 60 | uv = input_vars[1] 61 | 62 | var sampler: String = input_vars[0] 63 | var bump: String = input_vars[2] 64 | 65 | return output_vars[0] + " = heigth_to_normal(%s, %s, %s);" % [sampler, uv, bump] 66 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Procedural/Noise/GradientNoise.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeProceduralGradientNoise extends ShaderLib 3 | 4 | func _init() -> void: 5 | output_port_for_preview = 0 6 | 7 | func _get_name() -> String: 8 | return "GradientNoise" 9 | 10 | func _get_category() -> String: 11 | return "Procedural/Noise" 12 | 13 | func _get_description() -> String: 14 | return "Generates a gradient, or Perlin noise based on input UV." 15 | 16 | func _get_return_icon_type() -> VisualShaderNode.PortType: 17 | return PORT_TYPE_SCALAR 18 | 19 | func _get_input_port_count() -> int: 20 | return 2 21 | 22 | func _get_input_port_name(port: int) -> String: 23 | match port: 24 | 0: 25 | return "uv" 26 | 1: 27 | return "scale" 28 | return "" 29 | 30 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 31 | match port: 32 | 0: 33 | return PORT_TYPE_VECTOR_2D 34 | 1: 35 | return PORT_TYPE_SCALAR 36 | return PORT_TYPE_SCALAR 37 | 38 | func _get_input_port_default_value(port: int) -> Variant: 39 | match port: 40 | 1: 41 | return 10.0 42 | _: 43 | return null 44 | 45 | func _get_output_port_count() -> int: 46 | return 1 47 | 48 | func _get_output_port_name(port: int) -> String: 49 | return "output" 50 | 51 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 52 | return PORT_TYPE_SCALAR 53 | 54 | func _get_global_code(mode: Shader.Mode) -> String: 55 | return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version] 56 | 57 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 58 | var uv: String = "UV" 59 | 60 | if input_vars[0]: 61 | uv = input_vars[0] 62 | 63 | var scale: String = input_vars[1] 64 | return output_vars[0] + " = gradient_noise(%s, %s);" % [uv, scale] 65 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Procedural/Noise/GyroidNoise.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeProceduralGyroidNoise extends ShaderLib 3 | 4 | func _init() -> void: 5 | output_port_for_preview = 0 6 | 7 | func _get_name() -> String: 8 | return "GyroidNoise" 9 | 10 | func _get_category() -> String: 11 | return "Procedural/Noise" 12 | 13 | func _get_description() -> String: 14 | return "Generates a gyroid noise based on input UV." 15 | 16 | func _get_return_icon_type() -> PortType: 17 | return PORT_TYPE_SCALAR 18 | 19 | func _get_input_port_count() -> int: 20 | return 5 21 | 22 | func _get_input_port_name(port: int) -> String: 23 | match port: 24 | 0: 25 | return "uv" 26 | 1: 27 | return "scale" 28 | 2: 29 | return "ratio" 30 | 3: 31 | return "height" 32 | _: 33 | return "thickness" 34 | 35 | func _get_input_port_type(port: int) -> PortType: 36 | match port: 37 | 0, 2: 38 | return PORT_TYPE_VECTOR_2D 39 | _: 40 | return PORT_TYPE_SCALAR 41 | 42 | func _get_input_port_default_value(port: int) -> Variant: 43 | match port: 44 | 1: 45 | return 2.0 46 | 2: 47 | return Vector2(1, 1) 48 | 3: 49 | return 0.5 50 | 4: 51 | return 0.0 52 | _: 53 | return null 54 | 55 | func _get_output_port_count() -> int: 56 | return 1 57 | 58 | func _get_output_port_name(port: int) -> String: 59 | return "output" 60 | 61 | func _get_output_port_type(port: int) -> PortType: 62 | return PORT_TYPE_SCALAR 63 | 64 | func _get_global_code(mode: Shader.Mode) -> String: 65 | return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version] 66 | 67 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 68 | var uv: String = "UV" 69 | 70 | if input_vars[0]: 71 | uv = input_vars[0] 72 | 73 | var scale: String = input_vars[1] 74 | var ratio: String = input_vars[2] 75 | var height: String = input_vars[3] 76 | var thickness: String = input_vars[4] 77 | 78 | return output_vars[0] + " = gyroid_noise(%s, %s, %s, %s, %s);" % [uv, scale, ratio, height, thickness] 79 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Procedural/Noise/PseudoRandomNoise.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodePseudoRandomNoise extends ShaderLib 3 | 4 | func _init() -> void: 5 | output_port_for_preview = 0 6 | 7 | func _get_name() -> String: 8 | return "PseudoRandomNoise" 9 | 10 | func _get_category() -> String: 11 | return "Procedural/Noise" 12 | 13 | func _get_description() -> String: 14 | return "Generates a pseudo random noise based on input seed." 15 | 16 | func _get_return_icon_type() -> PortType: 17 | return PORT_TYPE_SCALAR 18 | 19 | func _get_input_port_count() -> int: 20 | return 1 21 | 22 | func _get_input_port_name(port: int) -> String: 23 | return "seed" 24 | 25 | func _get_input_port_type(port: int) -> PortType: 26 | return PORT_TYPE_SCALAR 27 | 28 | func _get_input_port_default_value(port: int) -> Variant: 29 | match port: 30 | 0: 31 | return 0.0 32 | _: 33 | return null 34 | 35 | func _get_output_port_count() -> int: 36 | return 1 37 | 38 | func _get_output_port_name(port: int) -> String: 39 | return "output" 40 | 41 | func _get_output_port_type(port: int) -> PortType: 42 | return PORT_TYPE_SCALAR 43 | 44 | func _get_global_code(mode: Shader.Mode) -> String: 45 | return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version] 46 | 47 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 48 | return output_vars[0] + " = pseudo_random_noise(UV, %s);" % input_vars[0] 49 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Procedural/Noise/SimpleNoise.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeProceduralSimpleNoise extends ShaderLib 3 | 4 | func _init() -> void: 5 | output_port_for_preview = 0 6 | 7 | func _get_name() -> String: 8 | return "SimpleNoise" 9 | 10 | func _get_category() -> String: 11 | return "Procedural/Noise" 12 | 13 | func _get_description() -> String: 14 | return "Generates a simplex, or value noise based on input UV." 15 | 16 | func _get_return_icon_type() -> VisualShaderNode.PortType: 17 | return PORT_TYPE_SCALAR 18 | 19 | func _get_input_port_count() -> int: 20 | return 3 21 | 22 | func _get_input_port_name(port: int) -> String: 23 | match port: 24 | 0: 25 | return "uv" 26 | 1: 27 | return "scale" 28 | _: 29 | return "octaves" 30 | 31 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 32 | match port: 33 | 0: 34 | return PORT_TYPE_VECTOR_2D 35 | 1: 36 | return PORT_TYPE_SCALAR 37 | _: 38 | return PORT_TYPE_SCALAR_INT 39 | 40 | func _get_input_port_default_value(port: int) -> Variant: 41 | match port: 42 | 1: 43 | return 10.0 44 | 2: 45 | return 6 46 | _: 47 | return null 48 | 49 | func _get_output_port_count() -> int: 50 | return 1 51 | 52 | func _get_output_port_name(port: int) -> String: 53 | return "output" 54 | 55 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 56 | return PORT_TYPE_SCALAR 57 | 58 | func _get_global_code(mode: Shader.Mode) -> String: 59 | return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version] 60 | 61 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 62 | var uv: String = "UV" 63 | 64 | if input_vars[0]: 65 | uv = input_vars[0] 66 | 67 | var scale: String = input_vars[1] 68 | var octaves: String = input_vars[2] 69 | 70 | return output_vars[0] + " = simple_noise(%s, %s, %s);" % [uv, scale, octaves] 71 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Procedural/Noise/Voronoi.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeProceduralVoronoi extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "Voronoi" 6 | 7 | func _get_category() -> String: 8 | return "Procedural/Noise" 9 | 10 | func _get_description() -> String: 11 | return "Generates a Voronoi or Worley noise based on input UV." 12 | 13 | func _get_return_icon_type() -> VisualShaderNode.PortType: 14 | return PORT_TYPE_SCALAR 15 | 16 | func _get_input_port_count() -> int: 17 | var distance_index: int = get_option_index(0) 18 | match distance_index: 19 | 2: 20 | return 4 21 | _: 22 | return 3 23 | 24 | func _get_input_port_name(port: int) -> String: 25 | var distance_index: int = get_option_index(0) 26 | match distance_index: 27 | 2: 28 | match port: 29 | 0: 30 | return "uv" 31 | 1: 32 | return "cell density" 33 | 2: 34 | return "angle offset" 35 | _: 36 | return "chebyshev power" 37 | _: 38 | match port: 39 | 0: 40 | return "uv" 41 | 1: 42 | return "cell density" 43 | _: 44 | return "angle offset" 45 | 46 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 47 | match port: 48 | 0: 49 | return PORT_TYPE_VECTOR_2D 50 | _: 51 | return PORT_TYPE_SCALAR 52 | 53 | func _get_input_port_default_value(port: int) -> Variant: 54 | var distance_index: int = get_option_index(0) 55 | match distance_index: 56 | 2: 57 | match port: 58 | 1: 59 | return 5.0 60 | 2: 61 | return 2.0 62 | 3: 63 | return 5.0 64 | _: 65 | return null 66 | _: 67 | match port: 68 | 1: 69 | return 5.0 70 | 2: 71 | return 2.0 72 | _: 73 | return null 74 | 75 | func _get_output_port_count() -> int: 76 | return 2 77 | 78 | func _get_output_port_name(port: int) -> String: 79 | match port: 80 | 0: 81 | return "output" 82 | _: 83 | return "cells" 84 | 85 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 86 | return PORT_TYPE_SCALAR 87 | 88 | func _get_property_count() -> int: 89 | return 1 90 | 91 | func _get_property_name(index: int) -> String: 92 | return "Distance" 93 | 94 | func _get_property_default_index(index: int) -> int: 95 | return 0 96 | 97 | func _get_property_options(index: int) -> PackedStringArray: 98 | return ["Euclidean", "Manhattan", "Chebyshev"] 99 | 100 | func _get_global_code(mode: Shader.Mode) -> String: 101 | return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version] 102 | 103 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 104 | var uv: String = "UV" 105 | 106 | if input_vars[0]: 107 | uv = input_vars[0] 108 | 109 | var distance_index: int = get_option_index(0) 110 | 111 | var cell_density: String = input_vars[1] 112 | var angle_offset: String = input_vars[2] 113 | 114 | var output: String = output_vars[0] 115 | var cells: String = output_vars[1] 116 | 117 | match distance_index: 118 | 1: 119 | return "%s = voronoi_noise_manhattan(%s, %s, %s, %s);" % [output, uv, cell_density, angle_offset, cells] 120 | 2: 121 | var chebyshev_power: String = input_vars[3] 122 | return "%s = voronoi_noise_chebyshev(%s, %s, %s, %s, %s);" % [output, uv, cell_density, angle_offset, chebyshev_power, cells] 123 | _: 124 | return "%s = voronoi_noise_euclidean(%s, %s, %s, %s);" % [output, uv, cell_density, angle_offset, cells] 125 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Procedural/Procedural.gdshaderinc: -------------------------------------------------------------------------------- 1 | #include "res://addons/ShaderLib_v2_2_4/Maths/Maths.gdshaderinc" 2 | 3 | vec3 checker_board(vec2 uv, vec3 color_a, vec3 color_b, vec2 frequency) { 4 | uv = (uv.xy + 0.5) * frequency; 5 | vec4 derivatives = vec4(dFdx(uv), dFdy(uv)); 6 | vec2 duv_length = sqrt(vec2(dot(derivatives.xz, derivatives.xz), dot(derivatives.yw, derivatives.yw))); 7 | float width = 1.0; 8 | vec2 distance3 = 4.0 * abs(fract(uv + 0.25) - 0.5) - width; 9 | vec2 scale = 0.35 / duv_length.xy; 10 | float frequency_limiter = sqrt(clamp(1.1f - max(duv_length.x, duv_length.y), 0.0, 1.0)); 11 | vec2 vector_alpha = clamp(distance3 * scale.xy, -1.0, 1.0); 12 | float alpha = clamp(0.5f + 0.5f * vector_alpha.x * vector_alpha.y * frequency_limiter, 0.0, 1.0); 13 | return mix(color_b, color_a, alpha); 14 | } 15 | 16 | vec2 koch_fractal_direction(float angle) { 17 | return vec2(sin(angle), cos(angle)); 18 | } 19 | 20 | float koch_fractal(vec2 uv, float outline, int iteration, float shape_width, float shape_height, out vec2 koch_uv) { 21 | float tiling = 3.0; 22 | vec2 center = uv - vec2(.5); 23 | shape_width = .85 * (shape_width / 1.); 24 | shape_height = .85 * (shape_height / 1.); 25 | center.x /= shape_width; 26 | center.y /= shape_height; 27 | 28 | center.x = abs(center.x); 29 | center.y += tan(.833 * PI) * .5; 30 | vec2 dir = koch_fractal_direction(.833 * PI); 31 | float dist = dot(center - vec2(tiling / (2. * tiling), 0), dir); 32 | center -= dir * max(0, dist) * 2.0; 33 | 34 | dir = koch_fractal_direction(.6667 * PI); 35 | float scale = 1.0; 36 | center.x += .5; 37 | for(int i = 0; i < iteration; i++){ 38 | center *= tiling; 39 | scale *= tiling; 40 | center.x -= .5 * tiling; 41 | 42 | center.x = abs(center.x); 43 | center.x -= .5; 44 | center -= dir * min(0.0, dot(center, dir)) * 2.0; 45 | } 46 | 47 | dist = length(center - vec2(clamp(center.x, -1.0, 1.0), 0)); 48 | dist += step(outline / 100.0, dist / scale); 49 | koch_uv = abs(center); 50 | return 1.0 - dist; 51 | } 52 | 53 | vec2 gradient_modulo(vec2 divident, vec2 divisor) { 54 | vec2 positive_divident = mod(divident, divisor) + divisor; 55 | return mod(positive_divident, divisor); 56 | } 57 | 58 | vec2 gradient_random(vec2 uv) { 59 | uv = vec2(dot(uv, vec2(127.1,311.7)), dot(uv, vec2(269.5,183.3))); 60 | return -1.0 + 2.0 * fract(sin(uv) * 43758.5453123); 61 | } 62 | 63 | float gradient_noise(vec2 uv, float scale) { 64 | uv = uv * float(scale); 65 | vec2 period = vec2(30.0, 60.0); 66 | vec2 cells_minimum = floor(uv); 67 | vec2 cells_maximum = ceil(uv); 68 | vec2 uv_fract = fract(uv); 69 | cells_minimum = gradient_modulo(cells_minimum, period); 70 | cells_maximum = gradient_modulo(cells_maximum, period); 71 | vec2 blur = smoothstep(0.0, 1.0, uv_fract); 72 | vec2 lowerLeftDirection = gradient_random(vec2(cells_minimum.x, cells_minimum.y)); 73 | vec2 lowerRightDirection = gradient_random(vec2(cells_maximum.x, cells_minimum.y)); 74 | vec2 upperLeftDirection = gradient_random(vec2(cells_minimum.x, cells_maximum.y)); 75 | vec2 upperRightDirection = gradient_random(vec2(cells_maximum.x, cells_maximum.y)); 76 | vec2 fraction = fract(uv); 77 | float mix_one = mix(dot(lowerLeftDirection, fraction - vec2(0, 0)), dot(lowerRightDirection, fraction - vec2(1, 0)), blur.x); 78 | float mix_two = mix(dot(upperLeftDirection, fraction - vec2(0, 1)), dot(upperRightDirection, fraction - vec2(1, 1)), blur.x); 79 | return mix(mix_one, mix_two, blur.y) * 0.8 + 0.5; 80 | } 81 | 82 | float gyroid_noise(vec2 uv, float scale, vec2 ratio, float height, float thickness) { 83 | scale *= 10.; 84 | thickness = clamp(thickness, 0., 1.); 85 | vec3 vector = vec3(uv, height); 86 | vector *= scale; 87 | return abs(dot(sin(vector * ratio.x), cos(vector.zxy * ratio.y))) - thickness; 88 | } 89 | 90 | float pseudo_random_noise(vec2 uv, float seed) { 91 | return fract(sin(dot(uv.xy + seed, vec2(12.9898,78.233))) * 43758.5453123); 92 | } 93 | 94 | float simple_noise_random(vec2 point) { 95 | return fract(sin(point.x * 100. + point.y * 654.125) * 55647.8745); 96 | } 97 | 98 | float value_noise(vec2 uv) { 99 | vec2 grid_uv = fract(uv); 100 | vec2 grid_id = floor(uv); 101 | grid_uv = grid_uv * grid_uv * (3. - 2. * grid_uv); 102 | 103 | float bottom_left = simple_noise_random(grid_id); 104 | float bottom_right = simple_noise_random(grid_id + vec2(1, 0)); 105 | float bottom = mix(bottom_left, bottom_right, grid_uv.x); 106 | 107 | float top_left = simple_noise_random(grid_id + vec2(0, 1)); 108 | float top_right = simple_noise_random(grid_id + vec2(1, 1)); 109 | float top = mix(top_left, top_right, grid_uv.x); 110 | 111 | return mix(bottom, top, grid_uv.y); 112 | } 113 | 114 | float simple_noise(vec2 uv, float scale, int octaves) { 115 | octaves = clamp(octaves, 1, 6); 116 | float noise = value_noise(uv * scale); 117 | float amplitude = 1.; 118 | 119 | for(int i = 1; i < octaves; i++) { 120 | scale *= 2.; 121 | amplitude /= 2.; 122 | noise += value_noise(uv * scale) * amplitude; 123 | } 124 | 125 | return noise / 2.; 126 | } 127 | 128 | vec2 voronoi_random_vector(vec2 p) { 129 | mat2 matrix = mat2(vec2(15.27, 47.63), vec2(99.41, 89.98)); 130 | return fract(sin(p * matrix) * 46839.32); 131 | } 132 | 133 | float voronoi_noise_euclidean(vec2 uv, float cell_density, float angle_offset, out float cells){ 134 | vec2 grid_uv = fract(uv * cell_density); 135 | vec2 grid_id = floor(uv * cell_density); 136 | vec2 cell_id = vec2(0); 137 | float min_dist = 100.; 138 | 139 | for(float y = -1.; y <= 1.; y++) { 140 | for(float x = -1.; x <= 1.; x++) { 141 | vec2 offset = vec2(x, y); 142 | vec2 n = voronoi_random_vector(grid_id + offset); 143 | vec2 p = offset + vec2(sin(n.x + angle_offset) * .5 + .5, cos(n.y + angle_offset) * .5 + .5); 144 | float d = min_dist; 145 | d = distance(grid_uv, p); 146 | if(d < min_dist) { 147 | min_dist = d; 148 | cell_id = voronoi_random_vector(grid_id + offset); 149 | } 150 | } 151 | } 152 | 153 | cells = cell_id.y; 154 | return min_dist; 155 | } 156 | 157 | float voronoi_noise_manhattan(vec2 uv, float cell_density, float angle_offset, out float cells){ 158 | vec2 grid_uv = fract(uv * cell_density); 159 | vec2 grid_id = floor(uv * cell_density); 160 | vec2 cell_id = vec2(0); 161 | float min_dist = 100.; 162 | 163 | for(float y = -1.; y <= 1.; y++) { 164 | for(float x = -1.; x <= 1.; x++) { 165 | vec2 offset = vec2(x, y); 166 | vec2 n = voronoi_random_vector(grid_id + offset); 167 | vec2 p = offset + vec2(sin(n.x + angle_offset) * .5 + .5, cos(n.y + angle_offset) * .5 + .5); 168 | float d = min_dist; 169 | d = manhattan_distance_2d(grid_uv, p); 170 | 171 | if(d < min_dist) { 172 | min_dist = d; 173 | cell_id = voronoi_random_vector(grid_id + offset); 174 | } 175 | } 176 | } 177 | 178 | cells = cell_id.y; 179 | return min_dist; 180 | } 181 | 182 | float voronoi_noise_chebyshev(vec2 uv, float cell_density, float angle_offset, float chebyshev_power, out float cells){ 183 | vec2 grid_uv = fract(uv * cell_density); 184 | vec2 grid_id = floor(uv * cell_density); 185 | vec2 cell_id = vec2(0); 186 | float min_dist = 100.; 187 | 188 | for(float y = -1.; y <= 1.; y++) { 189 | for(float x = -1.; x <= 1.; x++) { 190 | vec2 offset = vec2(x, y); 191 | vec2 n = voronoi_random_vector(grid_id + offset); 192 | vec2 p = offset + vec2(sin(n.x + angle_offset) * .5 + .5, cos(n.y + angle_offset) * .5 + .5); 193 | float d = min_dist; 194 | d = chebyshev_distance_2d(grid_uv, p, chebyshev_power); 195 | 196 | if(d < min_dist) { 197 | min_dist = d; 198 | cell_id = voronoi_random_vector(grid_id + offset); 199 | } 200 | } 201 | } 202 | 203 | cells = cell_id.y; 204 | return min_dist; 205 | } 206 | 207 | float ellipse_shape(vec2 uv, float width, float height) { 208 | float dist = length((uv * 2.0 - 1.0) / vec2(width, height)); 209 | return clamp((1.0 - dist) / fwidth(dist), 0.0, 1.0); 210 | } 211 | 212 | float polygon_shape(vec2 uv, int sides, float width, float height) { 213 | float a_width = width * cos(PI / float(sides)); 214 | float a_height = height * cos(PI / float(sides)); 215 | uv = (uv * 2.0 - 1.0) / vec2(a_width, a_height); 216 | uv.y *= -1.0; 217 | float polar_coords = atan(uv.x, uv.y); 218 | float radius = 2.0 * PI / float(sides); 219 | float dist = cos(floor(0.5 + polar_coords / radius) * radius - polar_coords) * length(uv); 220 | return clamp((1.0 - dist) / fwidth(dist), 0.0, 1.0); 221 | } 222 | 223 | float rectangle_shape(vec2 uv, float width, float height) { 224 | vec2 dist = abs(uv * 2.0 - 1.0) - vec2(width, height); 225 | dist = 1.0 - dist / fwidth(dist); 226 | return clamp(min(dist.x, dist.y), 0.0, 1.0); 227 | } 228 | 229 | float rounded_polygon_shape(vec2 uv, float width, float height, float sides, float roundness){ 230 | uv = uv * 2.0 + vec2(-1.0); 231 | roundness /= 10.0; 232 | float epsilon = 1e-6; 233 | uv.x = uv.x / ( width + ((width > -epsilon && width < epsilon) ? 1.0 : 0.0 * epsilon)); 234 | uv.y = uv.y / ( height + ((height > -epsilon && height < epsilon) ? 1.0 : 0.0 * epsilon)); 235 | roundness = clamp(roundness, 1e-6, 1.0); 236 | float i_sides = floor( abs( sides ) ); 237 | float full_angle = 2.0 * PI / i_sides; 238 | float half_angle = full_angle / 2.; 239 | float diagonal = 1.0 / cos( half_angle ); 240 | float chamfer_angle = roundness * half_angle; 241 | float remaining_angle = half_angle - chamfer_angle; 242 | float ratio = tan(remaining_angle) / tan(half_angle); 243 | vec2 chamfer_center = vec2(cos(half_angle) , sin(half_angle))* ratio * diagonal; 244 | 245 | float dist_a = length(chamfer_center); 246 | float dist_b = 1.0 - chamfer_center.x; 247 | float uv_scale = diagonal; 248 | uv *= uv_scale; 249 | vec2 polar_uv = vec2(atan(uv.y, uv.x), length(uv)); 250 | 251 | polar_uv.x += PI / 2.0 + TAU; 252 | polar_uv.x = mod(polar_uv.x + half_angle, full_angle ); 253 | polar_uv.x = abs(polar_uv.x - half_angle); 254 | uv = vec2(cos(polar_uv.x), sin(polar_uv.x)) * polar_uv.y; 255 | float angle_ratio = 1.0 - (polar_uv.x- remaining_angle) / chamfer_angle; 256 | float dist_c = sqrt(dist_a * dist_a + dist_b * dist_b - 2.0 * dist_a * dist_b * cos(PI - half_angle * angle_ratio)); 257 | float output = uv.x; 258 | float chamfer_zone = (half_angle - polar_uv.x) < chamfer_angle ? 1.0 : 0.0; 259 | output = mix(uv.x, polar_uv.y / dist_c, chamfer_zone); 260 | output = clamp((1.0 - output) / fwidth(output), 0.0, 1.0); 261 | return output; 262 | } 263 | 264 | float rounded_rectangle_shape(vec2 uv, float width, float height, float radius){ 265 | radius /= 10.0; 266 | radius = max(min(min(abs(radius * 2.0), abs(width)), abs(height)), 1e-5); 267 | uv = abs(uv * 2.0 - 1.0) - vec2(width, height) + radius; 268 | float dist = length(max(vec2(0.0), uv)) / radius; 269 | return clamp((1.0 - dist) / fwidth(dist), 0.0, 1.0); 270 | } 271 | 272 | vec3 heigth_to_normal(sampler2D height_map, vec2 uv, float bump_strength) { 273 | float pixel_width = .002; 274 | float height = texture(height_map, uv).r; 275 | float r = height - texture(height_map, uv + vec2(pixel_width, 0)).r; 276 | float l = height - texture(height_map, uv - vec2(pixel_width, 0)).r; 277 | float u = height - texture(height_map, uv + vec2(0, pixel_width)).r; 278 | float d = height - texture(height_map, uv - vec2(0, pixel_width)).r; 279 | float h = (r - l) / pixel_width; 280 | float v = (u - d) / pixel_width; 281 | vec3 n = vec3(h, v, 1.); 282 | n.x = n.x * (pixel_width * bump_strength * .5) + .5; 283 | n.y = n.y * (pixel_width * bump_strength * .5) + .5; 284 | return normalize(n); 285 | } -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Procedural/Shapes/Ellipse.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeProceduralEllipse extends ShaderLib 3 | 4 | func _init() -> void: 5 | output_port_for_preview = 0 6 | 7 | func _get_name() -> String: 8 | return "Ellipse" 9 | 10 | func _get_category() -> String: 11 | return "Procedural/Shapes" 12 | 13 | func _get_description() -> String: 14 | return "Generates an ellipse shape based on input UV at the size specified by inputs width and height." 15 | 16 | func _get_return_icon_type() -> VisualShaderNode.PortType: 17 | return PORT_TYPE_SCALAR 18 | 19 | func _get_input_port_count() -> int: 20 | return 3 21 | 22 | func _get_input_port_name(port: int) -> String: 23 | match port: 24 | 0: 25 | return "uv" 26 | 1: 27 | return "width" 28 | 2: 29 | return "height" 30 | return "" 31 | 32 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 33 | match port: 34 | 0: 35 | return PORT_TYPE_VECTOR_2D 36 | 1, 2: 37 | return PORT_TYPE_SCALAR 38 | return PORT_TYPE_SCALAR 39 | 40 | func _get_input_port_default_value(port: int) -> Variant: 41 | match port: 42 | 1, 2: 43 | return 0.5 44 | _: 45 | return null 46 | 47 | func _get_output_port_count() -> int: 48 | return 1 49 | 50 | func _get_output_port_name(port: int) -> String: 51 | return "output" 52 | 53 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 54 | return PORT_TYPE_SCALAR 55 | 56 | func _get_global_code(mode: Shader.Mode) -> String: 57 | return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version] 58 | 59 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 60 | var uv: String = "UV" 61 | 62 | if input_vars[0]: 63 | uv = input_vars[0] 64 | 65 | var width: String = input_vars[1] 66 | var height: String = input_vars[2] 67 | 68 | return output_vars[0] + " = ellipse_shape(%s, %s, %s);" % [uv, width, height] 69 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Procedural/Shapes/Polygon.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeProceduralPolygon extends ShaderLib 3 | 4 | func _init() -> void: 5 | output_port_for_preview = 0 6 | 7 | func _get_name() -> String: 8 | return "Polygon" 9 | 10 | func _get_category() -> String: 11 | return "Procedural/Shapes" 12 | 13 | func _get_description() -> String: 14 | return "Generates a regular polygon shape based on input UV at the size specified by inputs width and height. The polygon's amount of sides is determined by input sides." 15 | 16 | func _get_return_icon_type() -> VisualShaderNode.PortType: 17 | return PORT_TYPE_SCALAR 18 | 19 | func _get_input_port_count() -> int: 20 | return 4 21 | 22 | func _get_input_port_name(port: int) -> String: 23 | match port: 24 | 0: 25 | return "uv" 26 | 1: 27 | return "sides" 28 | 2: 29 | return "width" 30 | 3: 31 | return "height" 32 | return "" 33 | 34 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 35 | match port: 36 | 0: 37 | return PORT_TYPE_VECTOR_2D 38 | 1: 39 | return PORT_TYPE_SCALAR_INT 40 | 2, 3: 41 | return PORT_TYPE_SCALAR 42 | return PORT_TYPE_SCALAR 43 | 44 | func _get_input_port_default_value(port: int) -> Variant: 45 | match port: 46 | 1: 47 | return 3 48 | 2, 3: 49 | return 0.5 50 | _: 51 | return null 52 | 53 | func _get_output_port_count() -> int: 54 | return 1 55 | 56 | func _get_output_port_name(port: int) -> String: 57 | return "output" 58 | 59 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 60 | return PORT_TYPE_SCALAR 61 | 62 | func _get_global_code(mode: Shader.Mode) -> String: 63 | return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version] 64 | 65 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 66 | var uv: String = "UV" 67 | 68 | if input_vars[0]: 69 | uv = input_vars[0] 70 | 71 | var sides: String = input_vars[1] 72 | var width: String = input_vars[2] 73 | var height: String = input_vars[3] 74 | 75 | return output_vars[0] + " = polygon_shape(%s, %s, %s, %s);" % [uv, sides, width, height] 76 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Procedural/Shapes/Rectangle.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeProceduralRectangle extends ShaderLib 3 | 4 | func _init() -> void: 5 | output_port_for_preview = 0 6 | 7 | func _get_name() -> String: 8 | return "Rectangle" 9 | 10 | func _get_category() -> String: 11 | return "Procedural/Shapes" 12 | 13 | func _get_description() -> String: 14 | return "Generates a rectangle shape based on input UV at the size specified by inputs width and height." 15 | 16 | func _get_return_icon_type() -> VisualShaderNode.PortType: 17 | return PORT_TYPE_SCALAR 18 | 19 | func _get_input_port_count() -> int: 20 | return 3 21 | 22 | func _get_input_port_name(port: int) -> String: 23 | match port: 24 | 0: 25 | return "uv" 26 | 1: 27 | return "width" 28 | 2: 29 | return "height" 30 | return "" 31 | 32 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 33 | match port: 34 | 0: 35 | return PORT_TYPE_VECTOR_2D 36 | 1, 2: 37 | return PORT_TYPE_SCALAR 38 | return PORT_TYPE_SCALAR 39 | 40 | func _get_input_port_default_value(port: int) -> Variant: 41 | match port: 42 | 1, 2: 43 | return 0.5 44 | _: 45 | return null 46 | 47 | func _get_output_port_count() -> int: 48 | return 1 49 | 50 | func _get_output_port_name(port: int) -> String: 51 | return "output" 52 | 53 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 54 | return PORT_TYPE_SCALAR 55 | 56 | func _get_global_code(mode: Shader.Mode) -> String: 57 | return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version] 58 | 59 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 60 | var uv: String = "UV" 61 | 62 | if input_vars[0]: 63 | uv = input_vars[0] 64 | 65 | var width: String = input_vars[1] 66 | var height: String = input_vars[2] 67 | 68 | return output_vars[0] + " = rectangle_shape(%s, %s, %s);" % [uv, width, height] 69 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Procedural/Shapes/RoundedPolygon.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeProceduralRoundedPolygon extends ShaderLib 3 | 4 | func _init() -> void: 5 | output_port_for_preview = 0 6 | 7 | func _get_name() -> String: 8 | return "RoundedPolygon" 9 | 10 | func _get_category() -> String: 11 | return "Procedural/Shapes" 12 | 13 | func _get_description() -> String: 14 | return "Generates a rounded polygon shape based on input UV at the size specified by inputs width and height. The input sides specifies the number of sides, and the input roundness defines the roundness of each corner." 15 | 16 | func _get_return_icon_type() -> VisualShaderNode.PortType: 17 | return PORT_TYPE_SCALAR 18 | 19 | func _get_input_port_count() -> int: 20 | return 5 21 | 22 | func _get_input_port_name(port: int) -> String: 23 | match port: 24 | 0: 25 | return "uv" 26 | 1: 27 | return "width" 28 | 2: 29 | return "height" 30 | 3: 31 | return "sides" 32 | 4: 33 | return "roundness" 34 | return "" 35 | 36 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 37 | match port: 38 | 0: 39 | return PORT_TYPE_VECTOR_2D 40 | _: 41 | return PORT_TYPE_SCALAR 42 | 43 | func _get_input_port_default_value(port: int) -> Variant: 44 | match port: 45 | 1, 2: 46 | return 0.5 47 | 3: 48 | return 3 49 | 4: 50 | return 1.0 51 | _: 52 | return null 53 | 54 | func _get_output_port_count() -> int: 55 | return 1 56 | 57 | func _get_output_port_name(port: int) -> String: 58 | return "output" 59 | 60 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 61 | return PORT_TYPE_SCALAR 62 | 63 | func _get_global_code(mode: Shader.Mode) -> String: 64 | return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version] 65 | 66 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 67 | var uv: String = "UV" 68 | 69 | if input_vars[0]: 70 | uv = input_vars[0] 71 | 72 | var width: String = input_vars[1] 73 | var height: String = input_vars[2] 74 | var sides: String = input_vars[3] 75 | var roundness: String = input_vars[4] 76 | 77 | return output_vars[0] + " = rounded_polygon_shape(%s, %s, %s, float(%s), %s);" % [uv, width, height, sides, roundness] 78 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/Procedural/Shapes/RoundedRectangle.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeProceduralRoundedRectangle extends ShaderLib 3 | 4 | func _init() -> void: 5 | output_port_for_preview = 0 6 | 7 | func _get_name() -> String: 8 | return "RoundedRectangle" 9 | 10 | func _get_category() -> String: 11 | return "Procedural/Shapes" 12 | 13 | func _get_description() -> String: 14 | return "Generates a rounded rectangle shape based on input UV at the size specified by inputs width and height. The radius of each corner is defined by input radius." 15 | 16 | func _get_return_icon_type() -> VisualShaderNode.PortType: 17 | return PORT_TYPE_SCALAR 18 | 19 | func _get_input_port_count() -> int: 20 | return 4 21 | 22 | func _get_input_port_name(port: int) -> String: 23 | match port: 24 | 0: 25 | return "uv" 26 | 1: 27 | return "width" 28 | 2: 29 | return "height" 30 | 3: 31 | return "radius" 32 | return "" 33 | 34 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 35 | match port: 36 | 0: 37 | return PORT_TYPE_VECTOR_2D 38 | 1, 2, 3: 39 | return PORT_TYPE_SCALAR 40 | return PORT_TYPE_SCALAR 41 | 42 | func _get_input_port_default_value(port: int) -> Variant: 43 | match port: 44 | 1, 2: 45 | return 0.5 46 | 3: 47 | return 1.0 48 | _: 49 | return null 50 | 51 | func _get_output_port_count() -> int: 52 | return 1 53 | 54 | func _get_output_port_name(port: int) -> String: 55 | return "output" 56 | 57 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 58 | return PORT_TYPE_SCALAR 59 | 60 | func _get_global_code(mode: Shader.Mode) -> String: 61 | return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version] 62 | 63 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 64 | var uv: String = "UV" 65 | 66 | if input_vars[0]: 67 | uv = input_vars[0] 68 | 69 | var width: String = input_vars[1] 70 | var height: String = input_vars[2] 71 | var radius: String = input_vars[3] 72 | 73 | return output_vars[0] + " = rounded_rectangle_shape(%s, %s, %s, %s);" % [uv, width, height, radius] 74 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/RayMarching/RayMarch.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeRayMarch extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "RayMarch" 6 | 7 | func _get_category() -> String: 8 | return "RayMarching" 9 | 10 | func _get_description() -> String: 11 | return "A simple ray marcher for primitive shapes." 12 | 13 | func _get_return_icon_type() -> PortType: 14 | return PORT_TYPE_SCALAR 15 | 16 | func _get_input_port_count() -> int: 17 | var sdf_index: int = get_option_index(0) 18 | match sdf_index: 19 | 2, 3, 4: 20 | return 9 21 | _: 22 | return 8 23 | 24 | func _get_input_port_name(port: int) -> String: 25 | var sdf_index: int = get_option_index(0) 26 | match sdf_index: 27 | 0, 1: 28 | match port: 29 | 0: 30 | return "ray origin" 31 | 1: 32 | return "ray direction" 33 | 2: 34 | return "max steps" 35 | 3: 36 | return "max distance" 37 | 4: 38 | return "distance threshold" 39 | 5: 40 | return "cube pos" if sdf_index == 0 else "sphere pos" 41 | 6: 42 | return "cube eulers" if sdf_index == 0 else "sphere eulers" 43 | _: 44 | return "cube scale" if sdf_index == 0 else "sphere scale" 45 | 2, 3: 46 | match port: 47 | 0: 48 | return "ray origin" 49 | 1: 50 | return "ray direction" 51 | 2: 52 | return "max steps" 53 | 3: 54 | return "max distance" 55 | 4: 56 | return "distance threshold" 57 | 5: 58 | return "capsule pos" if sdf_index == 2 else "cylinder pos" 59 | 6: 60 | return "capsule eulers" if sdf_index == 2 else "cylinder eulers" 61 | 7: 62 | return "capsule height" if sdf_index == 2 else "cylinder height" 63 | _: 64 | return "capsule radius" if sdf_index == 2 else "cylinder radius" 65 | _: 66 | match port: 67 | 0: 68 | return "ray origin" 69 | 1: 70 | return "ray direction" 71 | 2: 72 | return "max steps" 73 | 3: 74 | return "max distance" 75 | 4: 76 | return "distance threshold" 77 | 5: 78 | return "torus pos" 79 | 6: 80 | return "torus eulers" 81 | 7: 82 | return "torus small radius" 83 | _: 84 | return "torus big radius" 85 | 86 | func _get_input_port_type(port: int) -> PortType: 87 | var sdf_index: int = get_option_index(0) 88 | match sdf_index: 89 | 0, 1: 90 | match port: 91 | 0, 1, 5, 6, 7: 92 | return PORT_TYPE_VECTOR_3D 93 | 2: 94 | return PORT_TYPE_SCALAR_INT 95 | _: 96 | return PORT_TYPE_SCALAR 97 | 2, 3: 98 | match port: 99 | 0, 1, 5, 6: 100 | return PORT_TYPE_VECTOR_3D 101 | 2: 102 | return PORT_TYPE_SCALAR_INT 103 | _: 104 | return PORT_TYPE_SCALAR 105 | _: 106 | match port: 107 | 0, 1, 5, 6: 108 | return PORT_TYPE_VECTOR_3D 109 | 2: 110 | return PORT_TYPE_SCALAR_INT 111 | _: 112 | return PORT_TYPE_SCALAR 113 | 114 | func _get_input_port_default_value(port: int) -> Variant: 115 | var sdf_index: int = get_option_index(0) 116 | match sdf_index: 117 | 0, 1: 118 | match port: 119 | 0, 5, 6: 120 | return Vector3(0, 0, 0) 121 | 1: 122 | return Vector3(0 ,0 ,-1) 123 | 2: 124 | return 15 125 | 3: 126 | return 15.0 127 | 7: 128 | return Vector3(0.3, 0.3, 0.3) 129 | _: 130 | return 1e-2 131 | 2, 3: 132 | match port: 133 | 0, 5, 6: 134 | return Vector3(0, 0, 0) 135 | 1: 136 | return Vector3(0 ,0 ,-1) 137 | 2: 138 | return 15 139 | 3: 140 | return 15.0 141 | 4: 142 | return 1e-2 143 | 7: 144 | return .5 if sdf_index == 2 else 1.0 145 | _: 146 | return .3 147 | _: 148 | match port: 149 | 0, 5, 6: 150 | return Vector3(0, 0, 0) 151 | 1: 152 | return Vector3(0 ,0 ,-1) 153 | 2: 154 | return 15 155 | 3: 156 | return 15.0 157 | 4: 158 | return 1e-2 159 | 7: 160 | return 0.1 161 | _: 162 | return 0.4 163 | 164 | func _get_property_count() -> int: 165 | return 1 166 | 167 | func _get_property_default_index(index: int) -> int: 168 | return 0 169 | 170 | func _get_property_name(index: int) -> String: 171 | return "SDF" 172 | 173 | func _get_property_options(index: int) -> PackedStringArray: 174 | return ["SDBox", "SDSphere", "SDCapsule", "SDCylinder", "SDTorus"] 175 | 176 | func _get_output_port_count() -> int: 177 | return 1 178 | 179 | func _get_output_port_name(port: int) -> String: 180 | return "distance" 181 | 182 | func _get_output_port_type(port: int) -> PortType: 183 | return PORT_TYPE_SCALAR 184 | 185 | func _get_global_code(mode: Shader.Mode) -> String: 186 | return "#include \"res://addons/ShaderLib_%s/RayMarching/SignedDistanceFunctions.gdshaderinc\"" % [version] 187 | 188 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 189 | var sdf_index: int = get_option_index(0) 190 | var ray_origin: String = input_vars[0] 191 | var ray_direction: String = input_vars[1] 192 | var max_steps: String = input_vars[2] 193 | var max_dist: String = input_vars[3] 194 | var dist_threshold: String = input_vars[4] 195 | 196 | match sdf_index: 197 | 0: 198 | var cube_pos: String = input_vars[5] 199 | var eulers: String = input_vars[6] 200 | var size: String = input_vars[7] 201 | return output_vars[0] + " = ray_march_sd_box(%s, %s, %s, %s, %s, %s, %s, %s);" % [ray_origin, ray_direction, max_steps, max_dist, dist_threshold, cube_pos, eulers, size] 202 | 1: 203 | var sphere_pos: String = input_vars[5] 204 | var eulers: String = input_vars[6] 205 | var scale: String = input_vars[7] 206 | return output_vars[0] + " = ray_march_sd_sphere(%s, %s, %s, %s, %s, %s, %s, %s);" % [ray_origin, ray_direction, max_steps, max_dist, dist_threshold, sphere_pos, eulers, scale] 207 | 2: 208 | var capsule_pos: String = input_vars[5] 209 | var capsule_eulers: String = input_vars[6] 210 | var capsule_height: String = input_vars[7] 211 | var capsule_radius: String = input_vars[8] 212 | return output_vars[0] + " = ray_march_sd_capsule(%s, %s, %s, %s, %s, %s, %s, %s, %s);" % [ray_origin, ray_direction, max_steps, max_dist, dist_threshold, capsule_pos, capsule_height, capsule_radius, capsule_eulers] 213 | 3: 214 | var cylinder_pos: String = input_vars[5] 215 | var cylinder_eulers: String = input_vars[6] 216 | var cylinder_height: String = input_vars[7] 217 | var cylinder_radius: String = input_vars[8] 218 | return output_vars[0] + " = ray_march_sd_cylinder(%s, %s, %s, %s, %s, %s, %s, %s, %s);" % [ray_origin, ray_direction, max_steps, max_dist, dist_threshold, cylinder_pos, cylinder_height, cylinder_radius, cylinder_eulers] 219 | _: 220 | var torus_pos: String = input_vars[5] 221 | var eulers: String = input_vars[6] 222 | var small_radius: String = input_vars[7] 223 | var big_radius: String = input_vars[8] 224 | return output_vars[0] + " = ray_march_sd_torus(%s, %s, %s, %s, %s, %s, %s, %s, %s);" % [ray_origin, ray_direction, max_steps, max_dist, dist_threshold, torus_pos, eulers, small_radius, big_radius] 225 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/RayMarching/RayMarchCustomTemplate.gdshaderinc: -------------------------------------------------------------------------------- 1 | // For in depth ray marching or sphere tracing info check out the playlist 2 | // https://www.youtube.com/watch?v=68G3V5Yr8FY&list=PLaE0_uENxXqvzte-A0Ux2pav0zrUrTJ1V 3 | 4 | float sdf_custom(vec3 p) { 5 | // Basic example of Sphere SDF with radius of .3 6 | // Put your custom logic here 7 | float radius = .3; 8 | return length(p) - radius; 9 | } 10 | 11 | float ray_march_custom(vec3 ray_origin, vec3 ray_dir, int max_steps, float max_dist, float dist_threshold) { 12 | ray_dir = normalize(ray_dir); 13 | dist_threshold = abs(dist_threshold); 14 | float dist_from_origin = 0.; 15 | float dist_to_surface; 16 | for(int i = 0; i < max_steps; i++) { 17 | vec3 point = ray_origin + dist_from_origin * ray_dir; 18 | dist_to_surface = sdf_custom(point); 19 | dist_from_origin += dist_to_surface; 20 | if(dist_to_surface < dist_threshold || dist_to_surface > max_dist) 21 | break; 22 | } 23 | return dist_from_origin; 24 | } -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/RayMarching/SignedDistanceFunctions.gdshaderinc: -------------------------------------------------------------------------------- 1 | mat2 rm_rotation(float angle) { 2 | angle = -angle * (3.1415926 / 180.); 3 | return mat2( 4 | vec2(cos(angle), -sin(angle)), 5 | vec2(sin(angle), cos(angle)) 6 | ); 7 | } 8 | 9 | float sd_box(vec3 point, vec3 size, vec3 eulers) { 10 | point.yz *= rm_rotation(eulers.x); 11 | point.xy *= rm_rotation(eulers.z); 12 | point.xz *= rm_rotation(-eulers.y); 13 | vec3 box_distances = abs(point) - size; 14 | float external_dist = length(max(box_distances, 0)); 15 | float internal_dist = min(max(box_distances.x, max(box_distances.y, box_distances.z)), 0); 16 | return external_dist + internal_dist; 17 | } 18 | 19 | float ray_march_sd_box(vec3 ray_origin, vec3 ray_dir, int max_steps, float max_dist, float dist_threshold, vec3 cube_pos, vec3 eulers, vec3 size) { 20 | ray_dir = normalize(ray_dir); 21 | dist_threshold = abs(dist_threshold); 22 | float dist_from_origin = 0.; 23 | float dist_to_surface; 24 | for(int i = 0; i < max_steps; i++) { 25 | vec3 point = ray_origin + dist_from_origin * ray_dir; 26 | dist_to_surface = sd_box(point - cube_pos, size, eulers); 27 | dist_from_origin += dist_to_surface; 28 | if(dist_to_surface < dist_threshold || dist_to_surface > max_dist) 29 | break; 30 | } 31 | return dist_from_origin; 32 | } 33 | 34 | float sd_capsule(vec3 point, vec3 capsule_pos, float height, float radius, vec3 eulers) { 35 | vec3 orientation = vec3(0, 1, 0); 36 | orientation.yz *= rm_rotation(eulers.x); 37 | orientation.xy *= rm_rotation(eulers.z); 38 | orientation.xz *= rm_rotation(-eulers.y); 39 | 40 | vec3 top_point = point + orientation * (height * .5); 41 | vec3 bottom_point = point - orientation * (height * .5); 42 | 43 | vec3 height_vector = bottom_point - top_point; 44 | vec3 top_distance = capsule_pos - top_point; 45 | 46 | float t = dot(height_vector, top_distance) / dot(height_vector, height_vector); 47 | t = clamp(t, 0., 1.); 48 | vec3 hit_point = top_point + t * height_vector; 49 | 50 | return length(capsule_pos - hit_point) - radius; 51 | } 52 | 53 | float ray_march_sd_capsule(vec3 ray_origin, vec3 ray_dir, int max_steps, float max_dist, float dist_threshold, vec3 capsule_pos, float capsule_height, float capsule_radius, vec3 eulers) { 54 | ray_dir = normalize(ray_dir); 55 | dist_threshold = abs(dist_threshold); 56 | float dist_from_origin = 0.; 57 | float dist_to_surface; 58 | for(int i = 0; i < max_steps; i++) { 59 | vec3 point = ray_origin + dist_from_origin * ray_dir; 60 | dist_to_surface = sd_capsule(point, capsule_pos, capsule_height, capsule_radius, eulers); 61 | dist_from_origin += dist_to_surface; 62 | if(dist_to_surface < dist_threshold || dist_to_surface > max_dist) 63 | break; 64 | } 65 | return dist_from_origin; 66 | } 67 | 68 | float sd_cylinder(vec3 point, vec3 cylinder_pos, float height, float radius, vec3 eulers) { 69 | vec3 orientation = vec3(0, 1, 0); 70 | orientation.yz *= rm_rotation(eulers.x); 71 | orientation.xy *= rm_rotation(eulers.z); 72 | orientation.xz *= rm_rotation(-eulers.y); 73 | 74 | vec3 top_point = point + orientation * (height * .5); 75 | vec3 bottom_point = point - orientation * (height * .5); 76 | 77 | vec3 height_vector = bottom_point - top_point; 78 | vec3 top_distance = cylinder_pos - top_point; 79 | 80 | float t = dot(height_vector, top_distance) / dot(height_vector, height_vector); 81 | vec3 hit_point = top_point + t * height_vector; 82 | 83 | float x = length(cylinder_pos - hit_point) - radius; 84 | float y = (abs(t - .5) - .5) * length(height_vector); 85 | float e = length(max(vec2(x, y), 0)); 86 | float i = min(max(x, y), 0.); 87 | 88 | return e + i; 89 | } 90 | 91 | float ray_march_sd_cylinder(vec3 ray_origin, vec3 ray_dir, int max_steps, float max_dist, float dist_threshold, vec3 cylinder_pos, float cylinder_height, float cylinder_radius, vec3 eulers) { 92 | ray_dir = normalize(ray_dir); 93 | dist_threshold = abs(dist_threshold); 94 | float dist_from_origin = 0.; 95 | float dist_to_surface; 96 | for(int i = 0; i < max_steps; i++) { 97 | vec3 point = ray_origin + dist_from_origin * ray_dir; 98 | dist_to_surface = sd_cylinder(point, cylinder_pos, cylinder_height, cylinder_radius, eulers); 99 | dist_from_origin += dist_to_surface; 100 | if(dist_to_surface < dist_threshold || dist_to_surface > max_dist) 101 | break; 102 | } 103 | return dist_from_origin; 104 | } 105 | 106 | float sd_sphere(vec3 point, vec3 eulers, vec3 scale) { 107 | float radius = 1.; 108 | point.yz *= rm_rotation(eulers.x); 109 | point.xy *= rm_rotation(eulers.z); 110 | point.xz *= rm_rotation(-eulers.y); 111 | point /= scale; 112 | return (length(point) - radius) * min(scale.x, min(scale.y, scale.z)); 113 | } 114 | 115 | float ray_march_sd_sphere(vec3 ray_origin, vec3 ray_dir, int max_steps, float max_dist, float dist_threshold, vec3 sphere_pos, vec3 eulers, vec3 scale) { 116 | ray_dir = normalize(ray_dir); 117 | dist_threshold = abs(dist_threshold); 118 | float dist_from_origin = 0.; 119 | float dist_to_surface; 120 | for(int i = 0; i < max_steps; i++) { 121 | vec3 point = ray_origin + dist_from_origin * ray_dir; 122 | dist_to_surface = sd_sphere(point - sphere_pos, eulers, scale); 123 | dist_from_origin += dist_to_surface; 124 | if(dist_to_surface < dist_threshold || dist_to_surface > max_dist) 125 | break; 126 | } 127 | return dist_from_origin; 128 | } 129 | 130 | float sd_torus(vec3 point, float small_radius, float big_radius, vec3 eulers) { 131 | point.yz *= rm_rotation(eulers.x); 132 | point.xy *= rm_rotation(eulers.z); 133 | point.xz *= rm_rotation(-eulers.y); 134 | return length(vec2(length(point.xz) - big_radius, point.y)) - small_radius; 135 | } 136 | 137 | float ray_march_sd_torus(vec3 ray_origin, vec3 ray_dir, int max_steps, float max_dist, float dist_threshold, vec3 torus_pos, vec3 eulers, float small_radius, float big_radius) { 138 | ray_dir = normalize(ray_dir); 139 | dist_threshold = abs(dist_threshold); 140 | float dist_from_origin = 0.; 141 | float dist_to_surface; 142 | for(int i = 0; i < max_steps; i++) { 143 | vec3 point = ray_origin + dist_from_origin * ray_dir; 144 | dist_to_surface = sd_torus(point - torus_pos, small_radius, big_radius, eulers); 145 | dist_from_origin += dist_to_surface; 146 | if(dist_to_surface < dist_threshold || dist_to_surface > max_dist) 147 | break; 148 | } 149 | return dist_from_origin; 150 | } -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/ShaderLib.gd: -------------------------------------------------------------------------------- 1 | class_name ShaderLib extends VisualShaderNodeCustom 2 | 3 | var version: String = "v2_2_4" 4 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/UV/FlipbookUV.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeUVFlipbook extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "Flipbook" 6 | 7 | func _get_category() -> String: 8 | return "UV" 9 | 10 | func _get_description() -> String: 11 | return "Creates a flipbook, or texture sheet animation, of the UVs supplied to input UV." 12 | 13 | func _get_return_icon_type() -> VisualShaderNode.PortType: 14 | return PORT_TYPE_VECTOR_2D 15 | 16 | func _get_input_port_count() -> int: 17 | return 4 18 | 19 | func _get_input_port_name(port: int) -> String: 20 | match port: 21 | 0: 22 | return "uv" 23 | 1: 24 | return "rows" 25 | 2: 26 | return "columns" 27 | 3: 28 | return "anim speed" 29 | return "" 30 | 31 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 32 | match port: 33 | 0: 34 | return PORT_TYPE_VECTOR_2D 35 | 1, 2: 36 | return PORT_TYPE_SCALAR_INT 37 | 3: 38 | return PORT_TYPE_SCALAR 39 | return PORT_TYPE_SCALAR 40 | 41 | func _get_input_port_default_value(port: int) -> Variant: 42 | match port: 43 | 1, 2: 44 | return 1 45 | 3: 46 | return 0.1 47 | _: 48 | return null 49 | 50 | func _get_output_port_count() -> int: 51 | return 1 52 | 53 | func _get_output_port_name(port: int) -> String: 54 | return "uv" 55 | 56 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 57 | return PORT_TYPE_VECTOR_2D 58 | 59 | func _get_global_code(mode: Shader.Mode) -> String: 60 | return "#include \"res://addons/ShaderLib_%s/UV/UV.gdshaderinc\"" % [version] 61 | 62 | func _is_available(mode: Shader.Mode, type: VisualShader.Type) -> bool: 63 | match mode: 64 | 0, 1: 65 | return true 66 | _: 67 | return false 68 | 69 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 70 | var uv: String 71 | 72 | match mode: 73 | 0, 1: 74 | uv = "UV" 75 | _: 76 | uv = "vec2(0.0)" 77 | 78 | if input_vars[0]: 79 | uv = input_vars[0] 80 | 81 | var rows: String = input_vars[1] 82 | var columns: String = input_vars[2] 83 | var anim_speed: String = input_vars[3] 84 | 85 | return output_vars[0] + " = flipbook_uv(%s, %s, %s, %s);" % [uv, rows, columns, anim_speed] 86 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/UV/ParallaxMappingUV.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeUVParallaxMapping extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "ParallaxMapping" 6 | 7 | func _get_category() -> String: 8 | return "UV" 9 | 10 | func _get_description() -> String: 11 | return "The Parallax Mapping node lets you create a parallax effect that displaces a Material's UVs to create the illusion of depth inside a Material." 12 | 13 | func _get_return_icon_type() -> VisualShaderNode.PortType: 14 | return PORT_TYPE_VECTOR_2D 15 | 16 | func _get_input_port_count() -> int: 17 | return 2 18 | 19 | func _get_input_port_name(port: int) -> String: 20 | match port: 21 | 0: 22 | return "heightMap" 23 | 1: 24 | return "amplitude" 25 | return "" 26 | 27 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 28 | match port: 29 | 0: 30 | return PORT_TYPE_SAMPLER 31 | _: 32 | return PORT_TYPE_SCALAR 33 | 34 | func _get_input_port_default_value(port: int) -> Variant: 35 | match port: 36 | 1: 37 | return 1.0 38 | _: 39 | return null 40 | 41 | func _get_output_port_count() -> int: 42 | return 1 43 | 44 | func _get_output_port_name(port: int) -> String: 45 | return "uv" 46 | 47 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 48 | return PORT_TYPE_VECTOR_2D 49 | 50 | func _is_available(mode: Shader.Mode, type: VisualShader.Type) -> bool: 51 | match mode: 52 | 0, 1: 53 | return true 54 | _: 55 | return false 56 | 57 | func _get_global_code(mode: Shader.Mode) -> String: 58 | return "#include \"res://addons/ShaderLib_%s/UV/UV.gdshaderinc\"" % [version] 59 | 60 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 61 | var height_map: String = input_vars[0] 62 | var amplitude: String = input_vars[1] 63 | if !height_map: 64 | return output_vars[0] + " = UV;" 65 | return output_vars[0] + " = parallax_mapping_uv(%s, -%s, UV, TANGENT, NORMAL, BINORMAL, VIEW);" % [height_map, amplitude]; 66 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/UV/RadialShearUV.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeUVRadialShear extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "RadialShear" 6 | 7 | func _get_category() -> String: 8 | return "UV" 9 | 10 | func _get_description() -> String: 11 | return "Applies a radial shear warping effect similar to a wave to the value of input UV." 12 | 13 | func _get_return_icon_type() -> VisualShaderNode.PortType: 14 | return PORT_TYPE_VECTOR_2D 15 | 16 | func _get_input_port_count() -> int: 17 | return 4 18 | 19 | func _get_input_port_name(port: int) -> String: 20 | match port: 21 | 0: 22 | return "uv" 23 | 1: 24 | return "center" 25 | 2: 26 | return "strength" 27 | 3: 28 | return "offset" 29 | return "" 30 | 31 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 32 | match port: 33 | 0, 1, 3: 34 | return PORT_TYPE_VECTOR_2D 35 | 2: 36 | return PORT_TYPE_SCALAR 37 | return PORT_TYPE_SCALAR 38 | 39 | func _get_input_port_default_value(port: int) -> Variant: 40 | match port: 41 | 1: 42 | return Vector2(0.5, 0.5) 43 | 2: 44 | return 10.0 45 | 3: 46 | return Vector2(0.0, 0.0) 47 | _: 48 | return null 49 | 50 | func _get_output_port_count() -> int: 51 | return 1 52 | 53 | func _get_output_port_name(port: int) -> String: 54 | return "uv" 55 | 56 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 57 | return PORT_TYPE_VECTOR_2D 58 | 59 | func _get_global_code(mode: Shader.Mode) -> String: 60 | return "#include \"res://addons/ShaderLib_%s/UV/UV.gdshaderinc\"" % [version] 61 | 62 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 63 | var uv: String 64 | 65 | match mode: 66 | 0, 1: 67 | uv = "UV" 68 | _: 69 | uv = "vec2(0.0)" 70 | 71 | if input_vars[0]: 72 | uv = input_vars[0] 73 | 74 | var center: String = input_vars[1] 75 | var strength: String = input_vars[2] 76 | var offset: String = input_vars[3] 77 | return output_vars[0] + " = radial_shear_uv(%s, %s, %s, %s);" % [uv, center, strength, offset]; 78 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/UV/RotateUV.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeUVRotate extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "Rotate" 6 | 7 | func _get_category() -> String: 8 | return "UV" 9 | 10 | func _get_description() -> String: 11 | return "Rotates value of input UV around a reference point defined by input center by the amount of input rotation." 12 | 13 | func _get_return_icon_type() -> VisualShaderNode.PortType: 14 | return PORT_TYPE_VECTOR_2D 15 | 16 | func _get_input_port_count() -> int: 17 | return 3 18 | 19 | func _get_input_port_name(port: int) -> String: 20 | match port: 21 | 0: 22 | return "uv" 23 | 1: 24 | return "center" 25 | 2: 26 | return "rotation" 27 | return "" 28 | 29 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 30 | match port: 31 | 0, 1: 32 | return PORT_TYPE_VECTOR_2D 33 | 2: 34 | return PORT_TYPE_SCALAR 35 | return PORT_TYPE_SCALAR 36 | 37 | func _get_input_port_default_value(port: int) -> Variant: 38 | match port: 39 | 1: 40 | return Vector2(0.5, 0.5) 41 | 2: 42 | return 0.0 43 | _: 44 | return null 45 | 46 | func _get_output_port_count() -> int: 47 | return 1 48 | 49 | func _get_output_port_name(port: int) -> String: 50 | return "uv" 51 | 52 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 53 | return PORT_TYPE_VECTOR_2D 54 | 55 | func _get_property_count() -> int: 56 | return 1 57 | 58 | func _get_property_default_index(index: int) -> int: 59 | return 0 60 | 61 | func _get_property_name(index: int) -> String: 62 | return "Units" 63 | 64 | func _get_property_options(index: int) -> PackedStringArray: 65 | return ["Degrees", "Radians"] 66 | 67 | func _get_global_code(mode: Shader.Mode) -> String: 68 | return "#include \"res://addons/ShaderLib_%s/UV/UV.gdshaderinc\"" % [version] 69 | 70 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 71 | var uv: String 72 | 73 | match mode: 74 | 0, 1: 75 | uv = "UV" 76 | _: 77 | uv = "vec2(0.0)" 78 | 79 | if input_vars[0]: 80 | uv = input_vars[0] 81 | 82 | var center: String = input_vars[1] 83 | var rotation: String = input_vars[2] 84 | var use_degrees: String = "true" if get_option_index(0) == 0 else "false" 85 | 86 | return output_vars[0] + " = rotate_uv(%s, %s, %s, %s);" % [uv, center, rotation, use_degrees] 87 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/UV/SpherizeUV.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeUVSpherize extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "Spherize" 6 | 7 | func _get_category() -> String: 8 | return "UV" 9 | 10 | func _get_description() -> String: 11 | return "Applies a spherical warping effect similar to a fisheye camera lens to the value of input UV." 12 | 13 | func _get_return_icon_type() -> VisualShaderNode.PortType: 14 | return PORT_TYPE_VECTOR_2D 15 | 16 | func _get_input_port_count() -> int: 17 | return 4 18 | 19 | func _get_input_port_name(port: int) -> String: 20 | match port: 21 | 0: 22 | return "uv" 23 | 1: 24 | return "center" 25 | 2: 26 | return "strength" 27 | 3: 28 | return "offset" 29 | return "" 30 | 31 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 32 | match port: 33 | 0, 1, 3: 34 | return PORT_TYPE_VECTOR_2D 35 | 2: 36 | return PORT_TYPE_SCALAR 37 | return PORT_TYPE_SCALAR 38 | 39 | func _get_input_port_default_value(port: int) -> Variant: 40 | match port: 41 | 1: 42 | return Vector2(0.5, 0.5) 43 | 2: 44 | return 10.0 45 | 3: 46 | return Vector2(0.0, 0.0) 47 | _: 48 | return null 49 | 50 | func _get_output_port_count() -> int: 51 | return 1 52 | 53 | func _get_output_port_name(port: int) -> String: 54 | return "uv" 55 | 56 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 57 | return PORT_TYPE_VECTOR_2D 58 | 59 | func _get_global_code(mode: Shader.Mode) -> String: 60 | return "#include \"res://addons/ShaderLib_%s/UV/UV.gdshaderinc\"" % [version] 61 | 62 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 63 | var uv: String 64 | 65 | match mode: 66 | 0, 1: 67 | uv = "UV" 68 | _: 69 | uv = "vec2(0.0)" 70 | 71 | if input_vars[0]: 72 | uv = input_vars[0] 73 | 74 | var center: String = input_vars[1] 75 | var strength: String = input_vars[2] 76 | var offset: String = input_vars[3] 77 | 78 | return output_vars[0] + " = spherize_uv(%s, %s, %s, %s);" % [uv, center, strength, offset] 79 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/UV/SwirlUV.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeUVSwirl extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "Swirl" 6 | 7 | func _get_category() -> String: 8 | return "UV" 9 | 10 | func _get_description() -> String: 11 | return "Applies a swirl warping effect similar to a black hole to the value of input UV." 12 | 13 | func _get_return_icon_type() -> VisualShaderNode.PortType: 14 | return PORT_TYPE_VECTOR_2D 15 | 16 | func _get_input_port_count() -> int: 17 | return 4 18 | 19 | func _get_input_port_name(port: int) -> String: 20 | match port: 21 | 0: 22 | return "uv" 23 | 1: 24 | return "center" 25 | 2: 26 | return "strength" 27 | 3: 28 | return "offset" 29 | return "" 30 | 31 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 32 | match port: 33 | 0, 1, 3: 34 | return PORT_TYPE_VECTOR_2D 35 | 2: 36 | return PORT_TYPE_SCALAR 37 | return PORT_TYPE_SCALAR 38 | 39 | func _get_input_port_default_value(port: int) -> Variant: 40 | match port: 41 | 1: 42 | return Vector2(0.5, 0.5) 43 | 2: 44 | return 10.0 45 | 3: 46 | return Vector2(0.0, 0.0) 47 | _: 48 | return null 49 | 50 | func _get_output_port_count() -> int: 51 | return 1 52 | 53 | func _get_output_port_name(port: int) -> String: 54 | return "uv" 55 | 56 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 57 | return PORT_TYPE_VECTOR_2D 58 | 59 | func _get_global_code(mode: Shader.Mode) -> String: 60 | return "#include \"res://addons/ShaderLib_%s/UV/UV.gdshaderinc\"" % [version] 61 | 62 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 63 | var uv: String 64 | 65 | match mode: 66 | 0, 1: 67 | uv = "UV" 68 | _: 69 | uv = "vec2(0.0)" 70 | 71 | if input_vars[0]: 72 | uv = input_vars[0] 73 | 74 | var center: String = input_vars[1] 75 | var strength: String = input_vars[2] 76 | var offset: String = input_vars[3] 77 | 78 | return output_vars[0] + " = swirl_uv(%s, %s, %s, %s);" % [uv, center, strength, offset] 79 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/UV/TilingAndOffsetUV.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeUVTilingAndOffset extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "TilingAndOffset" 6 | 7 | func _get_category() -> String: 8 | return "UV" 9 | 10 | func _get_description() -> String: 11 | return "Tiles and offsets the value of input UV by the inputs Tiling and Offset respectively. This is commonly used for detail maps and scrolling textures over TIME." 12 | 13 | func _get_return_icon_type() -> VisualShaderNode.PortType: 14 | return PORT_TYPE_VECTOR_2D 15 | 16 | func _get_input_port_count() -> int: 17 | return 3 18 | 19 | func _get_input_port_name(port: int) -> String: 20 | match port: 21 | 0: 22 | return "uv" 23 | 1: 24 | return "tiling" 25 | 2: 26 | return "offset" 27 | return "" 28 | 29 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 30 | match port: 31 | 0, 1, 2: 32 | return PORT_TYPE_VECTOR_2D 33 | return PORT_TYPE_SCALAR 34 | 35 | func _get_input_port_default_value(port: int) -> Variant: 36 | match port: 37 | 1: 38 | return Vector2(1.0, 1.0) 39 | 2: 40 | return Vector2(0.0, 0.0) 41 | _: 42 | return null 43 | 44 | func _get_output_port_count() -> int: 45 | return 1 46 | 47 | func _get_output_port_name(port: int) -> String: 48 | return "uv" 49 | 50 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 51 | return PORT_TYPE_VECTOR_2D 52 | 53 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 54 | var uv: String 55 | 56 | match mode: 57 | 0, 1: 58 | uv = "UV" 59 | _: 60 | uv = "vec2(0.0)" 61 | 62 | if input_vars[0]: 63 | uv = input_vars[0] 64 | 65 | var tiling: String = input_vars[1] 66 | var offset: String = input_vars[2] 67 | 68 | return output_vars[0] + " = %s * %s + %s;" % [uv, tiling, offset] 69 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/UV/TwirlUV.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeUVTwirl extends ShaderLib 3 | 4 | func _get_name() -> String: 5 | return "Twirl" 6 | 7 | func _get_category() -> String: 8 | return "UV" 9 | 10 | func _get_description() -> String: 11 | return "Applies a twirl warping effect similar to a black hole to the value of input UV." 12 | 13 | func _get_return_icon_type() -> VisualShaderNode.PortType: 14 | return PORT_TYPE_VECTOR_2D 15 | 16 | func _get_input_port_count() -> int: 17 | return 4 18 | 19 | func _get_input_port_name(port: int) -> String: 20 | match port: 21 | 0: 22 | return "uv" 23 | 1: 24 | return "center" 25 | 2: 26 | return "strength" 27 | 3: 28 | return "offset" 29 | return "" 30 | 31 | func _get_input_port_type(port: int) -> VisualShaderNode.PortType: 32 | match port: 33 | 0, 1, 3: 34 | return PORT_TYPE_VECTOR_2D 35 | 2: 36 | return PORT_TYPE_SCALAR 37 | return PORT_TYPE_SCALAR 38 | 39 | func _get_input_port_default_value(port: int) -> Variant: 40 | match port: 41 | 1: 42 | return Vector2(0.5, 0.5) 43 | 2: 44 | return 10.0 45 | 3: 46 | return Vector2(0.0, 0.0) 47 | _: 48 | return null 49 | 50 | func _get_output_port_count() -> int: 51 | return 1 52 | 53 | func _get_output_port_name(port: int) -> String: 54 | return "uv" 55 | 56 | func _get_output_port_type(port: int) -> VisualShaderNode.PortType: 57 | return PORT_TYPE_VECTOR_2D 58 | 59 | func _get_global_code(mode: Shader.Mode) -> String: 60 | return "#include \"res://addons/ShaderLib_%s/UV/UV.gdshaderinc\"" % [version] 61 | 62 | func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: 63 | var uv: String 64 | 65 | match mode: 66 | 0, 1: 67 | uv = "UV" 68 | _: 69 | uv = "vec2(0.0)" 70 | 71 | if input_vars[0]: 72 | uv = input_vars[0] 73 | 74 | var center: String = input_vars[1] 75 | var strength: String = input_vars[2] 76 | var offset: String = input_vars[3] 77 | 78 | return output_vars[0] + " = twirl_uv(%s, %s, %s, %s);" % [uv, center, strength, offset] 79 | -------------------------------------------------------------------------------- /addons/ShaderLib_v2_2_4/UV/UV.gdshaderinc: -------------------------------------------------------------------------------- 1 | vec2 flipbook_uv(vec2 uv, int rows, int columns, float anim_speed) { 2 | int start_frame = 1; 3 | int end_frame = rows * columns; 4 | start_frame += int(fract(TIME * anim_speed) * float(end_frame)); 5 | float frame = float(clamp(start_frame, 0, end_frame)); 6 | vec2 off_per_frame = vec2((1.0 / float(columns)), (1.0 / float(rows))); 7 | vec2 sprite_size = vec2(uv.x / float(columns), uv.y / float(rows)); 8 | vec2 current_sprite = vec2(0.0, 1.0 - off_per_frame.y); 9 | current_sprite.x += frame * off_per_frame.x; 10 | float row_index; 11 | current_sprite.y -= 1.0 - (row_index * off_per_frame.y); 12 | current_sprite.x -= row_index * float(columns) * off_per_frame.x; 13 | vec2 sprite_uv = (sprite_size + current_sprite); 14 | return sprite_uv; 15 | } 16 | 17 | vec2 parallax_mapping_uv_offset_1_step(float height, float amplitude, vec3 view_dir_tangent) { 18 | height = height * amplitude - amplitude / 2.0; 19 | vec3 vector = view_dir_tangent; 20 | vector.y += 0.42; 21 | return height * (vector.xz / vector.y); 22 | } 23 | 24 | vec2 parallax_mapping_uv(sampler2D height, float amplitude, vec2 uv, vec3 tangent, vec3 normal, vec3 binormal, vec3 view) { 25 | float depth = amplitude / 10.0; 26 | mat3 tangent_matrix = mat3(tangent, normal, -binormal); // VIEW TO TANGENT SPACE 27 | vec3 view_tangent = transpose(tangent_matrix) * view; 28 | float parallaxHeight = texture(height, uv).r; 29 | vec2 parallaxOffset = parallax_mapping_uv_offset_1_step(parallaxHeight, depth, view_tangent); 30 | return parallaxOffset + uv; 31 | } 32 | 33 | vec2 radial_shear_uv(vec2 uv, vec2 center, float strength, vec2 offset) { 34 | vec2 delta = uv - center; 35 | float delta2 = dot(delta.xy, delta.xy); 36 | vec2 delta_offset = vec2(delta2 * strength); 37 | return uv + vec2(delta.y, -delta.x) * delta_offset + offset; 38 | } 39 | 40 | mat2 rotation_mat2(float angle) { 41 | return mat2( 42 | vec2(cos(angle), -sin(angle)), 43 | vec2(sin(angle), cos(angle)) 44 | ); 45 | } 46 | 47 | vec2 rotate_uv(vec2 uv, vec2 center, float rotation, bool use_degrees) { 48 | float angle = rotation; 49 | if(use_degrees){ 50 | angle = rotation * (3.1415926/180.0); 51 | } 52 | vec2 delta = uv - center; 53 | delta = rotation_mat2(angle) * delta; 54 | return delta + center; 55 | } 56 | 57 | vec2 spherize_uv(vec2 uv, vec2 center, float strength, vec2 offset) { 58 | vec2 delta = uv - center; 59 | float delta2 = dot(delta.xy, delta.xy); 60 | float delta4 = delta2 * delta2; 61 | vec2 delta_offset = vec2(delta4 * strength); 62 | return uv + delta * delta_offset + offset; 63 | } 64 | 65 | vec2 swirl_uv(vec2 uv, vec2 center, float strength, vec2 offset) { 66 | vec2 delta = uv - center; 67 | float angle = strength * max(pow(1. - length(delta), 3), 0); 68 | delta = rotation_mat2(angle) * delta; 69 | return delta + center + offset; 70 | } 71 | 72 | vec2 twirl_uv(vec2 uv, vec2 center, float strength, vec2 offset) { 73 | vec2 delta = uv - center; 74 | float angle = strength * length(delta); 75 | delta = rotation_mat2(angle) * delta; 76 | return delta + center + offset; 77 | } --------------------------------------------------------------------------------