mirror of
https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git
synced 2025-09-19 20:05:57 +08:00
Compare commits
29 Commits
56eaa9e7b1
...
godot-4.2
Author | SHA1 | Date | |
---|---|---|---|
51ee380503 | |||
c1c786f345 | |||
afae2c766e | |||
a98305fa5f | |||
199f4a772a | |||
fb19605155 | |||
85fc207dc0 | |||
d72153b7c4 | |||
21213d657e | |||
1b66431979 | |||
506c677307 | |||
8bac036b66 | |||
009b94277f | |||
e0cd7320e7 | |||
6576785b47 | |||
217bf0a24e | |||
4844686953 | |||
8e9910a8d3 | |||
a4640eed2f | |||
5cc50c533f | |||
571098f3d9 | |||
fae913cea6 | |||
9d7c679c5b | |||
67ec588347 | |||
63acf5d341 | |||
8972c2da37 | |||
5ece7a3bd3 | |||
3fc8d868a6 | |||
32c40f1371 |
13
.github/FUNDING.yml
vendored
Normal file
13
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: DigvijaysinhGohil
|
||||
patreon: DigvijaysinhG
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
@ -1,11 +0,0 @@
|
||||
vec3 node_scale_world(mat4 model_matrix){
|
||||
vec3 _axis_x = model_matrix[0].xyz;
|
||||
vec3 _axis_y = model_matrix[1].xyz;
|
||||
vec3 _axis_z = model_matrix[2].xyz;
|
||||
|
||||
float _scale_x = length(_axis_x);
|
||||
float _scale_y = length(_axis_y);
|
||||
float _scale_z = length(_axis_z);
|
||||
|
||||
return vec3(_scale_x, _scale_y, _scale_z);
|
||||
}
|
@ -1,161 +0,0 @@
|
||||
float chebyshev_distance_2d(vec2 point1, vec2 point2, float power) {
|
||||
vec2 p = abs(point1 - point2);
|
||||
return pow(pow(p.x, power) + pow(p.y, power), 1. / power);
|
||||
}
|
||||
|
||||
float chebyshev_distance_3d(vec3 point1, vec3 point2, float power) {
|
||||
vec3 p = abs(point1 - point2);
|
||||
return pow(pow(p.x, power) + pow(p.y, power) + pow(p.z, power), 1. / power);
|
||||
}
|
||||
|
||||
float manhattan_distance_2d(vec2 point1, vec2 point2) {
|
||||
vec2 d = point1 - point2;
|
||||
return abs(d.x) + abs(d.y);
|
||||
}
|
||||
|
||||
float manhattan_distance_3d(vec3 point1, vec3 point2) {
|
||||
vec3 d = point1 - point2;
|
||||
return abs(d.x) + abs(d.y) + abs(d.z);
|
||||
}
|
||||
|
||||
vec2 project_2d(vec2 a, vec2 b) {
|
||||
return b * (dot(a, b) / dot(b, b));
|
||||
}
|
||||
|
||||
vec3 project_3d(vec3 a, vec3 b) {
|
||||
return b * (dot(a, b) / dot(b, b));
|
||||
}
|
||||
|
||||
vec3 project_on_plane(vec3 vector, vec3 plane_normal) {
|
||||
return vector - (plane_normal * (dot(vector, plane_normal) / dot(plane_normal, plane_normal)));
|
||||
}
|
||||
|
||||
float smoothmin(float a, float b, float t) {
|
||||
float h = clamp(.5 + .5 * (b - a) / t, 0, 1);
|
||||
return mix(b, a, h) - t * h * (1. - h);
|
||||
}
|
||||
|
||||
float smoothmax(float a, float b, float t) {
|
||||
float h = clamp(.5 + .5 * (b - a) / -t, 0, 1);
|
||||
return mix(b, a, h) + t * h * (1. - h);
|
||||
}
|
||||
|
||||
vec3 vector_transform_world_to_local(mat4 model_matrix, vec3 vector){
|
||||
return (inverse(model_matrix) * vec4(vector, 1.0)).xyz;
|
||||
}
|
||||
|
||||
vec3 vector_transform_world_to_view(mat4 view_matrix, vec3 vector){
|
||||
return (view_matrix * vec4(vector, 1.0)).xyz;
|
||||
}
|
||||
|
||||
vec3 vector_transform_world_to_screen(mat4 view_matrix, mat4 projection_matrix, vec3 vector){
|
||||
vec3 vector_view = vector_transform_world_to_view(view_matrix, vector);
|
||||
return (projection_matrix * vec4(vector_view, 1.0)).xyz;
|
||||
}
|
||||
|
||||
vec3 vector_transform_world_to_tangent(mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector){
|
||||
mat3 local_to_tangent_matrix = mat3(tangent, binormal, normal);
|
||||
vec3 vector_local = vector_transform_world_to_local(model_matrix, vector);
|
||||
return local_to_tangent_matrix * vector_local;
|
||||
}
|
||||
|
||||
vec3 vector_transform_local_to_world(mat4 model_matrix, vec3 vector){
|
||||
return (model_matrix * vec4(vector, 1.0)).xyz;
|
||||
}
|
||||
|
||||
vec3 vector_transform_local_to_view(mat4 model_matrix, mat4 view_matrix, vec3 vector){
|
||||
vec3 vector_world = vector_transform_local_to_world(model_matrix, vector);
|
||||
return (view_matrix * vec4(vector_world, 1.0)).xyz;
|
||||
}
|
||||
|
||||
vec3 vector_transform_local_to_screen(mat4 model_matrix, mat4 view_matrix, mat4 projection_matrix, vec3 vector){
|
||||
vec3 vector_view = vector_transform_local_to_view(model_matrix, view_matrix, vector);
|
||||
return (projection_matrix * vec4(vector_view, 1.0)).xyz;
|
||||
}
|
||||
|
||||
vec3 vector_transform_local_to_tangent(vec3 normal, vec3 binormal, vec3 tangent, vec3 vector){
|
||||
mat3 local_to_tangent_matrix = mat3(tangent, binormal, normal);
|
||||
return local_to_tangent_matrix * vector;
|
||||
}
|
||||
|
||||
vec3 vector_transform_view_to_world(mat4 inv_view_matrix, vec3 vector){
|
||||
return (inv_view_matrix * vec4(vector, 1.0)).xyz;;
|
||||
}
|
||||
|
||||
vec3 vector_transform_view_to_local(mat4 inv_view_matrix, mat4 model_matrix, vec3 vector){
|
||||
vec3 vector_world = vector_transform_view_to_world(inv_view_matrix, vector);
|
||||
return vector_transform_world_to_local(model_matrix, vector_world);
|
||||
}
|
||||
|
||||
vec3 vector_transform_view_to_screen(mat4 projection_matrix, vec3 vector){
|
||||
return (projection_matrix * vec4(vector, 1.0)).xyz;
|
||||
}
|
||||
|
||||
vec3 vector_transform_view_to_tangent(mat4 inv_view_matrix, mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector){
|
||||
mat3 local_to_tangent_matrix = mat3(tangent, binormal, normal);
|
||||
vec3 vector_local = vector_transform_view_to_local(inv_view_matrix, model_matrix, vector);
|
||||
return vector_transform_local_to_tangent(normal, binormal, tangent, vector_local);
|
||||
}
|
||||
|
||||
vec3 vector_transform_screen_to_view(mat4 inv_projection_matrix, vec3 vector){
|
||||
return (inv_projection_matrix * vec4(vector, 1.0)).xyz;;
|
||||
}
|
||||
|
||||
vec3 vector_transform_screen_to_local(mat4 inv_projection_matrix, mat4 inv_view_matrix, mat4 model_matrix, vec3 vector){
|
||||
vec3 vector_view = vector_transform_screen_to_view(inv_projection_matrix, vector);
|
||||
return vector_transform_view_to_local(inv_view_matrix, model_matrix, vector_view);
|
||||
}
|
||||
|
||||
vec3 vector_transform_screen_to_world(mat4 inv_projection_matrix, mat4 inv_view_matrix, vec3 vector){
|
||||
vec3 vector_view = vector_transform_screen_to_view(inv_projection_matrix, vector);
|
||||
return vector_transform_view_to_world(inv_view_matrix, vector_view);
|
||||
}
|
||||
|
||||
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){
|
||||
mat3 local_to_tangent_matrix = mat3(tangent, binormal, normal);
|
||||
vec3 vector_local = vector_transform_screen_to_local(inv_projection_matrix, inv_view_matrix, model_matrix, vector);
|
||||
return local_to_tangent_matrix * vector_local;
|
||||
}
|
||||
|
||||
vec3 vector_transform_tangent_to_local(vec3 normal, vec3 binormal, vec3 tangent, vec3 vector){
|
||||
mat3 tangent_to_local_matrix = inverse(mat3(tangent, binormal, normal));
|
||||
return tangent_to_local_matrix * vector;
|
||||
}
|
||||
|
||||
vec3 vector_transform_tangent_to_world(mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector){
|
||||
mat3 tangent_to_local_matrix = inverse(mat3(tangent, binormal, normal));
|
||||
vec3 vector_local = tangent_to_local_matrix * vector;
|
||||
return vector_transform_local_to_world(model_matrix, vector_local);
|
||||
}
|
||||
|
||||
vec3 vector_transform_tangent_to_view(mat4 model_matrix, mat4 view_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector){
|
||||
mat3 tangent_to_local_matrix = inverse(mat3(tangent, binormal, normal));
|
||||
vec3 vector_local = tangent_to_local_matrix * vector;
|
||||
return vector_transform_local_to_view(model_matrix, view_matrix, vector_local);
|
||||
}
|
||||
|
||||
vec3 vector_transform_tangent_to_screen(mat4 model_matrix, mat4 view_matrix, mat4 projection_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector){
|
||||
mat3 tangent_to_local_matrix = inverse(mat3(tangent, binormal, normal));
|
||||
vec3 vector_local = tangent_to_local_matrix * vector;
|
||||
return vector_transform_local_to_screen(model_matrix, view_matrix, projection_matrix, vector_local);
|
||||
}
|
||||
|
||||
vec4 noise_sine_wave(vec4 input, vec2 min_max) {
|
||||
vec4 _sin_in = sin(input);
|
||||
vec4 _sin_in_offset = sin(input + 1.0);
|
||||
vec4 _random_number = fract(sin((_sin_in - _sin_in_offset) * (12.9898 + 78.233))*43758.5453);
|
||||
float _noise = mix(min_max.x, min_max.y, _random_number.x);
|
||||
return _sin_in + vec4(_noise);
|
||||
}
|
||||
|
||||
vec4 sawtooth_wave(vec4 input) {
|
||||
return 2. * (input - floor(.5 + input));
|
||||
}
|
||||
|
||||
vec4 square_wave(vec4 input) {
|
||||
return 1. - 2. * round(fract(input));
|
||||
}
|
||||
|
||||
vec4 triangle_wave(vec4 input) {
|
||||
return 2. * abs(2. * (input - floor(.5 + input))) - 1.;
|
||||
}
|
@ -1,128 +0,0 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeVectorTransform extends VisualShaderNodeCustom
|
||||
|
||||
func _get_name() -> String:
|
||||
return "VectorTransform"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Maths/Vector"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Returns the transformed vector of the input value from one coordinate space to another."
|
||||
|
||||
func _get_return_icon_type() -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_input_port_name(port: int) -> String:
|
||||
return "in"
|
||||
|
||||
func _get_input_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_output_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_output_port_name(port: int) -> String:
|
||||
return "out"
|
||||
|
||||
func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_property_count() -> int:
|
||||
return 2
|
||||
|
||||
func _get_property_default_index(index: int) -> int:
|
||||
match index:
|
||||
0:
|
||||
return 0
|
||||
_:
|
||||
return 1
|
||||
|
||||
func _get_property_name(index: int) -> String:
|
||||
match index:
|
||||
0:
|
||||
return "From"
|
||||
_:
|
||||
return "To"
|
||||
|
||||
func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Local", "World", "View", "Screen", "Tangent"]
|
||||
|
||||
func _is_available(mode: Shader.Mode, type: VisualShader.Type) -> bool:
|
||||
return mode == Shader.MODE_SPATIAL
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var code: String
|
||||
var from_coord_space_index: int = get_option_index(0)
|
||||
var to_coord_space_index: int = get_option_index(1)
|
||||
var input_vector: String = input_vars[0] if input_vars[0] else "vec3(0.0, 0.0, 0.0)"
|
||||
|
||||
match from_coord_space_index:
|
||||
0:
|
||||
match to_coord_space_index:
|
||||
0:
|
||||
code = "%s = %s;" % [output_vars[0], input_vector]
|
||||
1:
|
||||
code = "%s = vector_transform_local_to_world(MODEL_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
2:
|
||||
code = "%s = vector_transform_local_to_view(MODEL_MATRIX, VIEW_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
3:
|
||||
code = "%s = vector_transform_local_to_screen(MODEL_MATRIX, VIEW_MATRIX, PROJECTION_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
4:
|
||||
code = "%s = vector_transform_local_to_tangent(NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
||||
1:
|
||||
match to_coord_space_index:
|
||||
0:
|
||||
code = "%s = vector_transform_world_to_local(MODEL_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
1:
|
||||
code = "%s = %s;" % [output_vars[0], input_vector]
|
||||
2:
|
||||
code = "%s = vector_transform_world_to_view(VIEW_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
3:
|
||||
code = "%s = vector_transform_world_to_screen(VIEW_MATRIX, PROJECTION_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
4:
|
||||
code = "%s = vector_transform_world_to_tangent(MODEL_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
||||
2:
|
||||
match to_coord_space_index:
|
||||
0:
|
||||
code = "%s = vector_transform_view_to_local(INV_VIEW_MATRIX, MODEL_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
1:
|
||||
code = "%s = vector_transform_view_to_world(INV_VIEW_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
2:
|
||||
code = "%s = %s;" % [output_vars[0], input_vector]
|
||||
3:
|
||||
code = "%s = vector_transform_view_to_screen(PROJECTION_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
4:
|
||||
code = "%s = vector_transform_view_to_tangent(INV_VIEW_MATRIX, MODEL_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
||||
3:
|
||||
match to_coord_space_index:
|
||||
0:
|
||||
code = "%s = vector_transform_screen_to_local(INV_PROJECTION_MATRIX, INV_VIEW_MATRIX, MODEL_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
1:
|
||||
code = "%s = vector_transform_screen_to_world(INV_PROJECTION_MATRIX, INV_VIEW_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
2:
|
||||
code = "%s = vector_transform_screen_to_view(INV_PROJECTION_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
3:
|
||||
code = "%s = %s;" % [output_vars[0], input_vector]
|
||||
4:
|
||||
code = "%s = vector_transform_screen_to_tangent(INV_PROJECTION_MATRIX, INV_VIEW_MATRIX, MODEL_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
||||
4:
|
||||
match to_coord_space_index:
|
||||
0:
|
||||
code = "%s = vector_transform_tangent_to_local(NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
||||
1:
|
||||
code = "%s = vector_transform_tangent_to_world(MODEL_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
||||
2:
|
||||
code = "%s = vector_transform_tangent_to_view(MODEL_MATRIX, VIEW_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
||||
3:
|
||||
code = "%s = vector_transform_tangent_to_screen(MODEL_MATRIX, VIEW_MATRIX, PROJECTION_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
||||
4:
|
||||
code = "%s = %s;" % [output_vars[0], input_vector]
|
||||
|
||||
return code
|
@ -1,232 +0,0 @@
|
||||
#include "res://addons/ShaderLib/Maths/Maths.gdshaderinc"
|
||||
|
||||
vec3 checker_board(vec2 uv, vec3 color_a, vec3 color_b, vec2 frequency){
|
||||
uv = (uv.xy + 0.5) * frequency;
|
||||
vec4 _derivatives = vec4(dFdx(uv), dFdy(uv));
|
||||
vec2 _duv_length = sqrt(vec2(dot(_derivatives.xz, _derivatives.xz), dot(_derivatives.yw, _derivatives.yw)));
|
||||
float _width = 1.0;
|
||||
vec2 _distance3 = 4.0 * abs(fract(uv + 0.25) - 0.5) - _width;
|
||||
vec2 _scale = 0.35 / _duv_length.xy;
|
||||
float _frequency_limiter = sqrt(clamp(1.1f - max(_duv_length.x, _duv_length.y), 0.0, 1.0));
|
||||
vec2 _vector_alpha = clamp(_distance3 * _scale.xy, -1.0, 1.0);
|
||||
float _alpha = clamp(0.5f + 0.5f * _vector_alpha.x * _vector_alpha.y * _frequency_limiter, 0.0, 1.0);
|
||||
return mix(color_b, color_a, _alpha);
|
||||
}
|
||||
|
||||
vec2 koch_fractal_direction(float angle){
|
||||
return vec2(sin(angle), cos(angle));
|
||||
}
|
||||
|
||||
float koch_fractal(vec2 uv, float outline, int iteration, float shape_width, float shape_height, out vec2 koch_uv) {
|
||||
float tiling = 3.0;
|
||||
vec2 center = uv - vec2(.5);
|
||||
shape_width = .85 * (shape_width / 1.);
|
||||
shape_height = .85 * (shape_height / 1.);
|
||||
center.x /= shape_width;
|
||||
center.y /= shape_height;
|
||||
|
||||
center.x = abs(center.x);
|
||||
center.y += tan(.833 * PI) * .5;
|
||||
vec2 dir = koch_fractal_direction(.833 * PI);
|
||||
float dist = dot(center - vec2(tiling / (2. * tiling), 0), dir);
|
||||
center -= dir * max(0, dist) * 2.0;
|
||||
|
||||
dir = koch_fractal_direction(.6667 * PI);
|
||||
float scale = 1.0;
|
||||
center.x += .5;
|
||||
for(int i = 0; i < iteration; i++){
|
||||
center *= tiling;
|
||||
scale *= tiling;
|
||||
center.x -= .5 * tiling;
|
||||
|
||||
center.x = abs(center.x);
|
||||
center.x -= .5;
|
||||
center -= dir * min(0.0, dot(center, dir)) * 2.0;
|
||||
}
|
||||
|
||||
dist = length(center - vec2(clamp(center.x, -1.0, 1.0), 0));
|
||||
dist += step(outline / 100.0, dist / scale);
|
||||
koch_uv = abs(center);
|
||||
return 1.0 - dist;
|
||||
}
|
||||
|
||||
vec2 gradient_modulo(vec2 divident, vec2 divisor){
|
||||
vec2 _positive_divident = mod(divident, divisor) + divisor;
|
||||
return mod(_positive_divident, divisor);
|
||||
}
|
||||
|
||||
vec2 gradient_random(vec2 uv){
|
||||
uv = vec2(dot(uv, vec2(127.1,311.7)), dot(uv, vec2(269.5,183.3)));
|
||||
return -1.0 + 2.0 * fract(sin(uv) * 43758.5453123);
|
||||
}
|
||||
|
||||
float gradient_noise(vec2 uv, float scale) {
|
||||
uv = uv * float(scale);
|
||||
vec2 _period = vec2(30.0, 60.0);
|
||||
vec2 _cells_minimum = floor(uv);
|
||||
vec2 _cells_maximum = ceil(uv);
|
||||
vec2 _uv_fract = fract(uv);
|
||||
_cells_minimum = gradient_modulo(_cells_minimum, _period);
|
||||
_cells_maximum = gradient_modulo(_cells_maximum, _period);
|
||||
vec2 _blur = smoothstep(0.0, 1.0, _uv_fract);
|
||||
vec2 _lowerLeftDirection = gradient_random(vec2(_cells_minimum.x, _cells_minimum.y));
|
||||
vec2 _lowerRightDirection = gradient_random(vec2(_cells_maximum.x, _cells_minimum.y));
|
||||
vec2 _upperLeftDirection = gradient_random(vec2(_cells_minimum.x, _cells_maximum.y));
|
||||
vec2 _upperRightDirection = gradient_random(vec2(_cells_maximum.x, _cells_maximum.y));
|
||||
vec2 _fraction = fract(uv);
|
||||
float _mix_one = mix(dot(_lowerLeftDirection, _fraction - vec2(0, 0)), dot(_lowerRightDirection, _fraction - vec2(1, 0)), _blur.x);
|
||||
float _mix_two = mix(dot(_upperLeftDirection, _fraction - vec2(0, 1)), dot(_upperRightDirection, _fraction - vec2(1, 1)), _blur.x);
|
||||
return mix(_mix_one, _mix_two, _blur.y) * 0.8 + 0.5;
|
||||
}
|
||||
|
||||
float gyroid_noise(vec2 uv, float scale, vec2 ratio, float height, float thickness) {
|
||||
scale *= 10.;
|
||||
thickness = clamp(thickness, 0., 1.);
|
||||
vec3 vector = vec3(uv, height);
|
||||
vector *= scale;
|
||||
return abs(dot(sin(vector * ratio.x), cos(vector.zxy * ratio.y))) - thickness;
|
||||
}
|
||||
|
||||
float pseudo_random_noise(vec2 uv, float seed) {
|
||||
return fract(sin(dot(uv.xy + seed, vec2(12.9898,78.233))) * 43758.5453123);
|
||||
}
|
||||
|
||||
float simple_noise_random(vec2 point) {
|
||||
return fract(sin(point.x * 100. + point.y * 654.125) * 55647.8745);
|
||||
}
|
||||
|
||||
float value_noise(vec2 uv) {
|
||||
vec2 grid_uv = fract(uv);
|
||||
vec2 grid_id = floor(uv);
|
||||
grid_uv = grid_uv * grid_uv * (3. - 2. * grid_uv);
|
||||
|
||||
float bottom_left = simple_noise_random(grid_id);
|
||||
float bottom_right = simple_noise_random(grid_id + vec2(1, 0));
|
||||
float bottom = mix(bottom_left, bottom_right, grid_uv.x);
|
||||
|
||||
float top_left = simple_noise_random(grid_id + vec2(0, 1));
|
||||
float top_right = simple_noise_random(grid_id + vec2(1, 1));
|
||||
float top = mix(top_left, top_right, grid_uv.x);
|
||||
|
||||
return mix(bottom, top, grid_uv.y);
|
||||
}
|
||||
|
||||
float simple_noise(vec2 uv, float scale, int octaves) {
|
||||
octaves = clamp(octaves, 1, 6);
|
||||
float noise = value_noise(uv * scale);
|
||||
float amplitude = 1.;
|
||||
|
||||
for(int i = 1; i < octaves; i++) {
|
||||
scale *= 2.;
|
||||
amplitude /= 2.;
|
||||
noise += value_noise(uv * scale) * amplitude;
|
||||
}
|
||||
|
||||
return noise / 2.;
|
||||
}
|
||||
|
||||
vec2 voronoi_random_vector(vec2 p) {
|
||||
mat2 matrix = mat2(vec2(15.27, 47.63), vec2(99.41, 89.98));
|
||||
return fract(sin(p * matrix) * 46839.32);
|
||||
}
|
||||
|
||||
void voronoi_noise(vec2 uv, float cell_density, float angle_offset, int distance_index, float chebyshev_power, out float output, out float cells){
|
||||
vec2 grid_uv = fract(uv * cell_density);
|
||||
vec2 grid_id = floor(uv * cell_density);
|
||||
vec2 cell_id = vec2(0);
|
||||
float min_dist = 100.;
|
||||
|
||||
for(float y = -1.; y <= 1.; y++) {
|
||||
for(float x = -1.; x <= 1.; x++) {
|
||||
vec2 offset = vec2(x, y);
|
||||
vec2 n = voronoi_random_vector(grid_id + offset);
|
||||
vec2 p = offset + vec2(sin(n.x + angle_offset) * .5 + .5, cos(n.y + angle_offset) * .5 + .5);
|
||||
float d = min_dist;
|
||||
|
||||
switch(distance_index){
|
||||
case 1:
|
||||
d = manhattan_distance_2d(grid_uv, p);
|
||||
break;
|
||||
case 2:
|
||||
d = chebyshev_distance_2d(grid_uv, p, chebyshev_power);
|
||||
break;
|
||||
default:
|
||||
d = distance(grid_uv, p);
|
||||
break;
|
||||
}
|
||||
|
||||
if(d < min_dist) {
|
||||
min_dist = d;
|
||||
cell_id = voronoi_random_vector(grid_id + offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
output = min_dist;
|
||||
cells = cell_id.y;
|
||||
}
|
||||
|
||||
float ellipse_shape(vec2 uv, float width, float height){
|
||||
float _distance = length((uv * 2.0 - 1.0) / vec2(width, height));
|
||||
return clamp((1.0 - _distance) / fwidth(_distance), 0.0, 1.0);
|
||||
}
|
||||
|
||||
float polygon_shape(vec2 uv, int sides, float width, float height){
|
||||
float _a_width = width * cos(PI / float(sides));
|
||||
float _a_height = height * cos(PI / float(sides));
|
||||
uv = (uv * 2.0 - 1.0) / vec2(_a_width, _a_height);
|
||||
uv.y *= -1.0;
|
||||
float _polar_coords = atan(uv.x, uv.y);
|
||||
float _radius = 2.0 * PI / float(sides);
|
||||
float _distance = cos(floor(0.5 + _polar_coords / _radius) * _radius - _polar_coords) * length(uv);
|
||||
return clamp((1.0 - _distance) / fwidth(_distance), 0.0, 1.0);
|
||||
}
|
||||
|
||||
float rectangle_shape(vec2 uv, float width, float height){
|
||||
vec2 _distance = abs(uv * 2.0 - 1.0) - vec2(width, height);
|
||||
_distance = 1.0 - _distance / fwidth(_distance);
|
||||
return clamp(min(_distance.x, _distance.y), 0.0, 1.0);
|
||||
}
|
||||
|
||||
float rounded_polygon_shape(vec2 uv, float width, float height, float sides, float roundness){
|
||||
uv = uv * 2.0 + vec2(-1.0);
|
||||
roundness /= 10.0;
|
||||
float _epsilon = 1e-6;
|
||||
uv.x = uv.x / ( width + ((width>-_epsilon && width<_epsilon) ? 1.0 : 0.0 * _epsilon));
|
||||
uv.y = uv.y / ( height + ((height>-_epsilon && height<_epsilon) ? 1.0 : 0.0 * _epsilon));
|
||||
roundness = clamp(roundness, 1e-6, 1.0);
|
||||
float _i_sides = floor( abs( sides ) );
|
||||
float _full_angle = 2.0 * PI / _i_sides;
|
||||
float _half_angle = _full_angle / 2.;
|
||||
float _diagonal = 1.0 / cos( _half_angle );
|
||||
float _chamfer_angle = roundness * _half_angle;
|
||||
float _remaining_angle = _half_angle - _chamfer_angle;
|
||||
float _ratio = tan(_remaining_angle) / tan(_half_angle);
|
||||
vec2 _chamfer_center = vec2(cos(_half_angle) , sin(_half_angle))* _ratio * _diagonal;
|
||||
|
||||
float _dist_a = length(_chamfer_center);
|
||||
float _dist_b = 1.0 - _chamfer_center.x;
|
||||
float _uv_scale = _diagonal;
|
||||
uv *= _uv_scale;
|
||||
vec2 _polar_uv = vec2(atan(uv.y, uv.x), length(uv));
|
||||
|
||||
_polar_uv.x += PI / 2.0 + TAU;
|
||||
_polar_uv.x = mod(_polar_uv.x + _half_angle, _full_angle );
|
||||
_polar_uv.x = abs(_polar_uv.x - _half_angle);
|
||||
uv = vec2(cos(_polar_uv.x), sin(_polar_uv.x)) * _polar_uv.y;
|
||||
float _angle_ratio = 1.0 - (_polar_uv.x-_remaining_angle) / _chamfer_angle;
|
||||
float _dist_c = sqrt(_dist_a * _dist_a + _dist_b * _dist_b - 2.0 * _dist_a *_dist_b * cos(PI - _half_angle * _angle_ratio));
|
||||
float output = uv.x;
|
||||
float _chamfer_zone = (_half_angle - _polar_uv.x) < _chamfer_angle ? 1.0 : 0.0;
|
||||
output = mix(uv.x, _polar_uv.y / _dist_c, _chamfer_zone);
|
||||
output = clamp((1.0 - output) / fwidth(output), 0.0, 1.0);
|
||||
return output;
|
||||
}
|
||||
|
||||
float rounded_rectangle_shape(vec2 uv, float width, float height, float radius){
|
||||
radius /= 10.0;
|
||||
radius = max(min(min(abs(radius * 2.0), abs(width)), abs(height)), 1e-5);
|
||||
uv = abs(uv * 2.0 - 1.0) - vec2(width, height) + radius;
|
||||
float _distance = length(max(vec2(0.0), uv)) / radius;
|
||||
return clamp((1.0 - _distance) / fwidth(_distance), 0.0, 1.0);
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
vec2 flipbook_uv(vec2 uv, int rows, int columns, float anim_speed){
|
||||
int start_frame = 1;
|
||||
int end_frame = rows * columns;
|
||||
start_frame += int(fract(TIME * anim_speed) * float(end_frame));
|
||||
float _frame = float(clamp(start_frame, 0, end_frame));
|
||||
vec2 _off_per_frame = vec2((1.0 / float(columns)), (1.0 / float(rows)));
|
||||
vec2 _sprite_size = vec2(uv.x / float(columns), uv.y / float(rows));
|
||||
vec2 _current_sprite = vec2(0.0, 1.0 - _off_per_frame.y);
|
||||
_current_sprite.x += _frame * _off_per_frame.x;
|
||||
float _row_index;
|
||||
float _mod = modf(_frame / float(columns), _row_index);
|
||||
_current_sprite.y -= 1.0 - (_row_index * _off_per_frame.y);
|
||||
_current_sprite.x -= _row_index * float(columns) * _off_per_frame.x;
|
||||
vec2 _sprite_uv = (_sprite_size + _current_sprite);
|
||||
return _sprite_uv;
|
||||
}
|
||||
|
||||
vec2 parallax_mapping_uv_offset_1_step(float height, float amplitude, vec3 view_dir_tangent)
|
||||
{
|
||||
height = height * amplitude - amplitude / 2.0;
|
||||
vec3 _vector = view_dir_tangent;
|
||||
_vector.y += 0.42;
|
||||
return height * (_vector.xz / _vector.y);
|
||||
}
|
||||
|
||||
vec2 parallax_mapping_uv(sampler2D height, float amplitude, vec2 uv, vec3 tangent, vec3 normal, vec3 binormal, vec3 view)
|
||||
{
|
||||
float depth = amplitude / 10.0;
|
||||
mat3 _tangent_matrix = mat3(tangent, normal, -binormal); // VIEW TO TANGENT SPACE
|
||||
vec3 _view_tangent = transpose(_tangent_matrix) * view;
|
||||
float _parallaxHeight = texture(height, uv).r;
|
||||
vec2 _parallaxOffset = parallax_mapping_uv_offset_1_step(_parallaxHeight, depth, _view_tangent);
|
||||
return _parallaxOffset + uv;
|
||||
}
|
||||
|
||||
vec2 radial_shear_uv(vec2 uv, vec2 center, float strength, vec2 offset){
|
||||
vec2 _delta = uv - center;
|
||||
float _delta2 = dot(_delta.xy, _delta.xy);
|
||||
vec2 _delta_offset = vec2(_delta2 * strength);
|
||||
return uv + vec2(_delta.y, -_delta.x) * _delta_offset + offset;
|
||||
}
|
||||
|
||||
vec2 rotate_uv(vec2 uv, vec2 center, float rotation, bool use_degrees){
|
||||
float _angle = rotation;
|
||||
if(use_degrees){
|
||||
_angle = rotation * (3.1415926/180.0);
|
||||
}
|
||||
mat2 _rotation = mat2(
|
||||
vec2(cos(_angle), -sin(_angle)),
|
||||
vec2(sin(_angle), cos(_angle))
|
||||
);
|
||||
vec2 _delta = uv - center;
|
||||
_delta = _rotation * _delta;
|
||||
return _delta + center;
|
||||
}
|
||||
|
||||
vec2 spherize_uv(vec2 uv, vec2 center, float strength, vec2 offset){
|
||||
vec2 _delta = uv - center;
|
||||
float _delta2 = dot(_delta.xy, _delta.xy);
|
||||
float _delta4 = _delta2 * _delta2;
|
||||
vec2 _delta_offset = vec2(_delta4 * strength);
|
||||
return uv + _delta * _delta_offset + offset;
|
||||
}
|
||||
|
||||
vec2 swirl_uv(vec2 uv, vec2 center, float strength, vec2 offset){
|
||||
vec2 _delta = uv - center;
|
||||
float _angle = strength * max(pow(1. - length(_delta), 3), 0);
|
||||
mat2 _rotation = mat2(
|
||||
vec2(cos(_angle), -sin(_angle)),
|
||||
vec2(sin(_angle), cos(_angle))
|
||||
);
|
||||
_delta = _rotation * _delta;
|
||||
return _delta + center;
|
||||
}
|
||||
|
||||
vec2 twirl_uv(vec2 uv, vec2 center, float strength, vec2 offset){
|
||||
vec2 _delta = uv - center;
|
||||
float _angle = strength * length(_delta);
|
||||
mat2 _rotation = mat2(
|
||||
vec2(cos(_angle), -sin(_angle)),
|
||||
vec2(sin(_angle), cos(_angle))
|
||||
);
|
||||
_delta = _rotation * _delta;
|
||||
return _delta + center;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeAdjustmentContrast extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeAdjustmentContrast extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "Contrast"
|
||||
@ -47,7 +47,7 @@ func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Artistic/Artistic.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Artistic/Artistic.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var input: String = "vec3(1.0)"
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeAdjustmentHue extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeAdjustmentHue extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "Hue"
|
||||
@ -59,7 +59,7 @@ func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Degrees", "Normalize"]
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Artistic/Artistic.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Artistic/Artistic.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var range_index: int = get_option_index(0)
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeAdjustmentReplaceColor extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeAdjustmentReplaceColor extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "ReplaceColor"
|
||||
@ -55,7 +55,7 @@ func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Artistic/Artistic.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Artistic/Artistic.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var input: String = "vec3(1.0)"
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeAdjustmentSaturation extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeAdjustmentSaturation extends ShaderLib
|
||||
|
||||
|
||||
func _get_name() -> String:
|
||||
@ -48,7 +48,7 @@ func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Artistic/Artistic.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Artistic/Artistic.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var input: String = "vec3(1.0)"
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeWhiteBalance extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeWhiteBalance extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "WhiteBalance"
|
||||
@ -49,7 +49,7 @@ func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Artistic/Artistic.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Artistic/Artistic.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var input: String = "vec3(1.0)"
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeMaskColorMask extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeMaskColorMask extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "ColorMask"
|
||||
@ -53,7 +53,7 @@ func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_VECTOR_4D
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Artistic/Artistic.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Artistic/Artistic.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var input: String = "vec3(0.0)"
|
11
addons/ShaderLib_v2_2_4/Geometry/Geometry.gdshaderinc
Normal file
11
addons/ShaderLib_v2_2_4/Geometry/Geometry.gdshaderinc
Normal file
@ -0,0 +1,11 @@
|
||||
vec3 node_scale_world(mat4 model_matrix) {
|
||||
vec3 axis_x = model_matrix[0].xyz;
|
||||
vec3 axis_y = model_matrix[1].xyz;
|
||||
vec3 axis_z = model_matrix[2].xyz;
|
||||
|
||||
float scale_x = length(axis_x);
|
||||
float scale_y = length(axis_y);
|
||||
float scale_z = length(axis_z);
|
||||
|
||||
return vec3(scale_x, scale_y, scale_z);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeGeometryMeshNode extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeGeometryMeshNode extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "MeshNode"
|
||||
@ -42,7 +42,7 @@ func _is_available(mode: Shader.Mode, type: VisualShader.Type) -> bool:
|
||||
return false
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Geometry/Geometry.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Geometry/Geometry.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var code: String
|
61
addons/ShaderLib_v2_2_4/Maths/Maths.gdshaderinc
Normal file
61
addons/ShaderLib_v2_2_4/Maths/Maths.gdshaderinc
Normal file
@ -0,0 +1,61 @@
|
||||
float chebyshev_distance_2d(vec2 point1, vec2 point2, float power) {
|
||||
vec2 p = abs(point1 - point2);
|
||||
return pow(pow(p.x, power) + pow(p.y, power), 1. / power);
|
||||
}
|
||||
|
||||
float chebyshev_distance_3d(vec3 point1, vec3 point2, float power) {
|
||||
vec3 p = abs(point1 - point2);
|
||||
return pow(pow(p.x, power) + pow(p.y, power) + pow(p.z, power), 1. / power);
|
||||
}
|
||||
|
||||
float manhattan_distance_2d(vec2 point1, vec2 point2) {
|
||||
vec2 d = point1 - point2;
|
||||
return abs(d.x) + abs(d.y);
|
||||
}
|
||||
|
||||
float manhattan_distance_3d(vec3 point1, vec3 point2) {
|
||||
vec3 d = point1 - point2;
|
||||
return abs(d.x) + abs(d.y) + abs(d.z);
|
||||
}
|
||||
|
||||
vec2 project_2d(vec2 a, vec2 b) {
|
||||
return b * (dot(a, b) / dot(b, b));
|
||||
}
|
||||
|
||||
vec3 project_3d(vec3 a, vec3 b) {
|
||||
return b * (dot(a, b) / dot(b, b));
|
||||
}
|
||||
|
||||
vec3 project_on_plane(vec3 vector, vec3 plane_normal) {
|
||||
return vector - (plane_normal * (dot(vector, plane_normal) / dot(plane_normal, plane_normal)));
|
||||
}
|
||||
|
||||
float smoothmin(float a, float b, float t) {
|
||||
float h = clamp(.5 + .5 * (b - a) / t, 0, 1);
|
||||
return mix(b, a, h) - t * h * (1. - h);
|
||||
}
|
||||
|
||||
float smoothmax(float a, float b, float t) {
|
||||
float h = clamp(.5 + .5 * (b - a) / -t, 0, 1);
|
||||
return mix(b, a, h) + t * h * (1. - h);
|
||||
}
|
||||
|
||||
vec4 noise_sine_wave(vec4 input, vec2 min_max) {
|
||||
vec4 sin_in = sin(input);
|
||||
vec4 sin_in_offset = sin(input + 1.0);
|
||||
vec4 random_number = fract(sin((sin_in - sin_in_offset) * (12.9898 + 78.233)) * 43758.5453);
|
||||
float noise = mix(min_max.x, min_max.y, random_number.x);
|
||||
return sin_in + vec4(noise);
|
||||
}
|
||||
|
||||
vec4 sawtooth_wave(vec4 input) {
|
||||
return 2. * (input - floor(.5 + input));
|
||||
}
|
||||
|
||||
vec4 square_wave(vec4 input) {
|
||||
return 1. - 2. * round(fract(input));
|
||||
}
|
||||
|
||||
vec4 triangle_wave(vec4 input) {
|
||||
return 2. * abs(2. * (input - floor(.5 + input))) - 1.;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeScalarSmoothMax extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeScalarSmoothMax extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "SmoothMax"
|
||||
@ -45,7 +45,7 @@ func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var a: String = input_vars[0]
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeScalarSmoothMin extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeScalarSmoothMin extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "SmoothMin"
|
||||
@ -45,7 +45,7 @@ func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var a: String = input_vars[0]
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeMathsChebyshevDistance extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeMathsChebyshevDistance extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "ChebyshevDistance"
|
||||
@ -66,7 +66,7 @@ func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Vector2", "Vector3"]
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var point_a: String
|
||||
@ -92,4 +92,3 @@ func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shad
|
||||
return output_vars[0] + " = chebyshev_distance_2d(%s, %s, %s);" % [point_a, point_b, power]
|
||||
_:
|
||||
return output_vars[0] + " = chebyshev_distance_3d(%s, %s, %s);" % [point_a, point_b, power]
|
||||
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeMathsManhattanDistance extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeMathsManhattanDistance extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "ManhattanDistance"
|
||||
@ -53,7 +53,7 @@ func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Vector2", "Vector3"]
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var point_a: String
|
||||
@ -78,4 +78,3 @@ func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shad
|
||||
return output_vars[0] + " = manhattan_distance_2d(%s, %s);" % [point_a, point_b]
|
||||
_:
|
||||
return output_vars[0] + " = manhattan_distance_3d(%s, %s);" % [point_a, point_b]
|
||||
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeVectorProject extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeVectorProject extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "Project"
|
||||
@ -63,7 +63,7 @@ func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Vector2", "Vector3"]
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var vector_a: String = input_vars[0]
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeVectorProjectOnPlane extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeVectorProjectOnPlane extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "ProjectOnPlane"
|
||||
@ -36,7 +36,7 @@ func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var vector_a: String = input_vars[0]
|
153
addons/ShaderLib_v2_2_4/Maths/Vector/VectorTransform.gd
Normal file
153
addons/ShaderLib_v2_2_4/Maths/Vector/VectorTransform.gd
Normal file
@ -0,0 +1,153 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeVectorTransform extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "VectorTransform"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Maths/Vector"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Returns the transformed vector of the input value from one coordinate space to another."
|
||||
|
||||
func _get_return_icon_type() -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_input_port_name(port: int) -> String:
|
||||
return "in"
|
||||
|
||||
func _get_input_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_output_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_output_port_name(port: int) -> String:
|
||||
return "out"
|
||||
|
||||
func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_property_count() -> int:
|
||||
return 3
|
||||
|
||||
func _get_property_default_index(index: int) -> int:
|
||||
match index:
|
||||
0, 1:
|
||||
return 0
|
||||
_:
|
||||
return 1
|
||||
|
||||
func _get_property_name(index: int) -> String:
|
||||
match index:
|
||||
0:
|
||||
return "Vector Type"
|
||||
1:
|
||||
return "From"
|
||||
_:
|
||||
return "To"
|
||||
|
||||
func _get_property_options(index: int) -> PackedStringArray:
|
||||
match index:
|
||||
0:
|
||||
return ["Positional", "Directional"]
|
||||
_:
|
||||
return ["Local", "World", "View", "Clip", "Tangent"]
|
||||
|
||||
func _is_available(mode: Shader.Mode, type: VisualShader.Type) -> bool:
|
||||
return mode == Shader.MODE_SPATIAL
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var code: String
|
||||
var vector_type: int = get_option_index(0)
|
||||
var from_coord_space_index: int = get_option_index(1)
|
||||
var to_coord_space_index: int = get_option_index(2)
|
||||
var input_vector: String = input_vars[0] if input_vars[0] else "vec3(0.0, 0.0, 0.0)"
|
||||
var w_component: String = "1.0" if vector_type == 0 else "0.0"
|
||||
|
||||
match from_coord_space_index:
|
||||
0:
|
||||
match to_coord_space_index:
|
||||
0:
|
||||
code = "%s = %s;" % [output_vars[0], input_vector]
|
||||
1:
|
||||
code = "%s = (MODEL_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||
2:
|
||||
code = "%s = (VIEW_MATRIX * MODEL_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||
3:
|
||||
code = "%s = (PROJECTION_MATRIX * VIEW_MATRIX * MODEL_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||
4:
|
||||
code = """
|
||||
vec3 normal = (inverse(MODEL_MATRIX) * INV_VIEW_MATRIX * vec4(NORMAL, 0.0)).xyz;
|
||||
mat4 local_to_tangent_mat = mat4(vec4(TANGENT, 1.0), vec4(BINORMAL, 1.0), vec4(normal, 1.0), vec4(0.0, 0.0, 0.0, 1.0));
|
||||
"""
|
||||
code += "%s = (local_to_tangent_mat * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||
1:
|
||||
match to_coord_space_index:
|
||||
0:
|
||||
code = "%s = (inverse(MODEL_MATRIX) * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||
1:
|
||||
code = "%s = %s;" % [output_vars[0], input_vector]
|
||||
2:
|
||||
code = "%s = (VIEW_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||
3:
|
||||
code = "%s =(PROJECTION_MATRIX * VIEW_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||
4:
|
||||
code = """
|
||||
vec3 normal = (inverse(MODEL_MATRIX) * INV_VIEW_MATRIX * vec4(NORMAL, 0.0)).xyz;
|
||||
mat4 local_to_tangent_mat = mat4(vec4(TANGENT, 1.0), vec4(BINORMAL, 1.0), vec4(normal, 1.0), vec4(0.0, 0.0, 0.0, 1.0));
|
||||
"""
|
||||
code += "%s = (local_to_tangent_mat * inverse(MODEL_MATRIX) * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||
2:
|
||||
match to_coord_space_index:
|
||||
0:
|
||||
code = "%s = (inverse(MODEL_MATRIX) * INV_VIEW_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||
1:
|
||||
code = "%s = (INV_VIEW_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||
2:
|
||||
code = "%s = %s;" % [output_vars[0], input_vector]
|
||||
3:
|
||||
code = "%s = (PROJECTION_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||
4:
|
||||
code = """
|
||||
vec3 normal = (inverse(MODEL_MATRIX) * INV_VIEW_MATRIX * vec4(NORMAL, 0.0)).xyz;
|
||||
mat4 local_to_tangent_mat = mat4(vec4(TANGENT, 1.0), vec4(BINORMAL, 1.0), vec4(normal, 1.0), vec4(0.0, 0.0, 0.0, 1.0));
|
||||
"""
|
||||
code += "%s = (local_to_tangent_mat * inverse(MODEL_MATRIX) * INV_VIEW_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||
3:
|
||||
match to_coord_space_index:
|
||||
0:
|
||||
code = "%s = (inverse(MODEL_MATRIX) * INV_VIEW_MATRIX * INV_PROJECTION_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||
1:
|
||||
code = "%s = (INV_VIEW_MATRIX * INV_PROJECTION_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||
2:
|
||||
code = "%s = (INV_PROJECTION_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||
3:
|
||||
code = "%s = %s;" % [output_vars[0], input_vector]
|
||||
4:
|
||||
code = """
|
||||
vec3 normal = (inverse(MODEL_MATRIX) * INV_VIEW_MATRIX * vec4(NORMAL, 0.0)).xyz;
|
||||
mat4 local_to_tangent_mat = mat4(vec4(TANGENT, 1.0), vec4(BINORMAL, 1.0), vec4(normal, 1.0), vec4(0.0, 0.0, 0.0, 1.0));
|
||||
"""
|
||||
code += "%s = (local_to_tangent_mat * inverse(MODEL_MATRIX) * INV_VIEW_MATRIX * INV_PROJECTION_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||
4:
|
||||
code = """
|
||||
vec3 normal = (inverse(MODEL_MATRIX) * INV_VIEW_MATRIX * vec4(NORMAL, 0.0)).xyz;
|
||||
mat4 tangent_to_local_mat = inverse(mat4(vec4(TANGENT, 1.0), vec4(BINORMAL, 1.0), vec4(normal, 1.0), vec4(0.0, 0.0, 0.0, 1.0)));
|
||||
"""
|
||||
match to_coord_space_index:
|
||||
0:
|
||||
code += "%s = (tangent_to_local_mat * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||
1:
|
||||
code += "%s = (MODEL_MATRIX * tangent_to_local_mat * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||
2:
|
||||
code += "%s = (VIEW_MATRIX * MODEL_MATRIX * tangent_to_local_mat * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||
3:
|
||||
code += "%s = (PROJECTION_MATRIX * VIEW_MATRIX * MODEL_MATRIX * tangent_to_local_mat * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||
4:
|
||||
code = "%s = %s;" % [output_vars[0], input_vector]
|
||||
|
||||
return code
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeMathsNoiseSineWave extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeMathsNoiseSineWave extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "NoiseSineWave"
|
||||
@ -87,7 +87,7 @@ func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Vector1", "Vector2", "Vector3", "Vector4"]
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var input: String
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeMathsSawtoothWave extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeMathsSawtoothWave extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "SawtoothWave"
|
||||
@ -71,7 +71,7 @@ func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Vector1", "Vector2", "Vector3", "Vector4"]
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var input: String
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeMathsSquareWave extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeMathsSquareWave extends ShaderLib
|
||||
|
||||
|
||||
func _get_name() -> String:
|
||||
@ -72,7 +72,7 @@ func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Vector1", "Vector2", "Vector3", "Vector4"]
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var input: String
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeMathsTriangleWave extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeMathsTriangleWave extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "TriangleWave"
|
||||
@ -70,7 +70,7 @@ func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Vector1", "Vector2", "Vector3", "Vector4"]
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var input: String
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeProceduralCheckerBoard extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeProceduralCheckerBoard extends ShaderLib
|
||||
|
||||
func _init() -> void:
|
||||
output_port_for_preview = 0
|
||||
@ -60,7 +60,7 @@ func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Procedural/Procedural.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var uv: String = "UV"
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeProceduralKochFractal extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeProceduralKochFractal extends ShaderLib
|
||||
|
||||
func _init() -> void:
|
||||
output_port_for_preview = 0
|
||||
@ -68,7 +68,7 @@ func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Procedural/Procedural.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var uv: String = "UV"
|
||||
@ -82,4 +82,3 @@ func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shad
|
||||
var height: String = input_vars[4]
|
||||
|
||||
return output_vars[0] + " = koch_fractal(%s, %s, %s, %s, %s, %s);" % [uv, thickness, iterations, width, height, output_vars[1]]
|
||||
|
65
addons/ShaderLib_v2_2_4/Procedural/HeightToNormal.gd
Normal file
65
addons/ShaderLib_v2_2_4/Procedural/HeightToNormal.gd
Normal file
@ -0,0 +1,65 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeProceduralHeightToNormal extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "HeightToNormal"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Procedural"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Generates a normal map from a height map."
|
||||
|
||||
func _get_return_icon_type() -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 3
|
||||
|
||||
func _get_input_port_name(port: int) -> String:
|
||||
match port:
|
||||
0:
|
||||
return "height map"
|
||||
1:
|
||||
return "uv"
|
||||
2:
|
||||
return "bump strength"
|
||||
return ""
|
||||
|
||||
func _get_input_port_type(port: int) -> PortType:
|
||||
match port:
|
||||
0:
|
||||
return PORT_TYPE_SAMPLER
|
||||
1:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
_:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_input_port_default_value(port: int) -> Variant:
|
||||
match port:
|
||||
2:
|
||||
return 8.0
|
||||
_:
|
||||
return null
|
||||
|
||||
func _get_output_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_output_port_name(port: int) -> String:
|
||||
return "normal"
|
||||
|
||||
func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var uv: String = "UV"
|
||||
if input_vars[1]:
|
||||
uv = input_vars[1]
|
||||
|
||||
var sampler: String = input_vars[0]
|
||||
var bump: String = input_vars[2]
|
||||
|
||||
return output_vars[0] + " = heigth_to_normal(%s, %s, %s);" % [sampler, uv, bump]
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeProceduralGradientNoise extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeProceduralGradientNoise extends ShaderLib
|
||||
|
||||
func _init() -> void:
|
||||
output_port_for_preview = 0
|
||||
@ -52,7 +52,7 @@ func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Procedural/Procedural.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var uv: String = "UV"
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeProceduralGyroidNoise extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeProceduralGyroidNoise extends ShaderLib
|
||||
|
||||
func _init() -> void:
|
||||
output_port_for_preview = 0
|
||||
@ -62,7 +62,7 @@ func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Procedural/Procedural.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var uv: String = "UV"
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodePseudoRandomNoise extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodePseudoRandomNoise extends ShaderLib
|
||||
|
||||
func _init() -> void:
|
||||
output_port_for_preview = 0
|
||||
@ -41,5 +41,8 @@ func _get_output_port_name(port: int) -> String:
|
||||
func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
return output_vars[0] + " = pseudo_random_noise(UV, %s);" % input_vars[0]
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeProceduralSimpleNoise extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeProceduralSimpleNoise extends ShaderLib
|
||||
|
||||
func _init() -> void:
|
||||
output_port_for_preview = 0
|
||||
@ -56,7 +56,7 @@ func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Procedural/Procedural.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var uv: String = "UV"
|
@ -1,8 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeProceduralVoronoi extends VisualShaderNodeCustom
|
||||
|
||||
func _init() -> void:
|
||||
output_port_for_preview = 0
|
||||
class_name VisualShaderNodeProceduralVoronoi extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "Voronoi"
|
||||
@ -63,7 +60,7 @@ func _get_input_port_default_value(port: int) -> Variant:
|
||||
2:
|
||||
return 2.0
|
||||
3:
|
||||
return 2.0
|
||||
return 5.0
|
||||
_:
|
||||
return null
|
||||
_:
|
||||
@ -101,7 +98,7 @@ func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Euclidean", "Manhattan", "Chebyshev"]
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Procedural/Procedural.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var uv: String = "UV"
|
||||
@ -113,13 +110,15 @@ func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shad
|
||||
|
||||
var cell_density: String = input_vars[1]
|
||||
var angle_offset: String = input_vars[2]
|
||||
var chebyshev_power: String = "0."
|
||||
|
||||
if distance_index == 2:
|
||||
if input_vars[3]:
|
||||
chebyshev_power = input_vars[3]
|
||||
|
||||
var output: String = output_vars[0]
|
||||
var cells: String = output_vars[1]
|
||||
|
||||
return "voronoi_noise(%s, %s, %s, %s, %s, %s, %s);" % [uv, cell_density, angle_offset, distance_index, chebyshev_power, output, cells]
|
||||
match distance_index:
|
||||
1:
|
||||
return "%s = voronoi_noise_manhattan(%s, %s, %s, %s);" % [output, uv, cell_density, angle_offset, cells]
|
||||
2:
|
||||
var chebyshev_power: String = input_vars[3]
|
||||
return "%s = voronoi_noise_chebyshev(%s, %s, %s, %s, %s);" % [output, uv, cell_density, angle_offset, chebyshev_power, cells]
|
||||
_:
|
||||
return "%s = voronoi_noise_euclidean(%s, %s, %s, %s);" % [output, uv, cell_density, angle_offset, cells]
|
285
addons/ShaderLib_v2_2_4/Procedural/Procedural.gdshaderinc
Normal file
285
addons/ShaderLib_v2_2_4/Procedural/Procedural.gdshaderinc
Normal file
@ -0,0 +1,285 @@
|
||||
#include "res://addons/ShaderLib_v2_2_4/Maths/Maths.gdshaderinc"
|
||||
|
||||
vec3 checker_board(vec2 uv, vec3 color_a, vec3 color_b, vec2 frequency) {
|
||||
uv = (uv.xy + 0.5) * frequency;
|
||||
vec4 derivatives = vec4(dFdx(uv), dFdy(uv));
|
||||
vec2 duv_length = sqrt(vec2(dot(derivatives.xz, derivatives.xz), dot(derivatives.yw, derivatives.yw)));
|
||||
float width = 1.0;
|
||||
vec2 distance3 = 4.0 * abs(fract(uv + 0.25) - 0.5) - width;
|
||||
vec2 scale = 0.35 / duv_length.xy;
|
||||
float frequency_limiter = sqrt(clamp(1.1f - max(duv_length.x, duv_length.y), 0.0, 1.0));
|
||||
vec2 vector_alpha = clamp(distance3 * scale.xy, -1.0, 1.0);
|
||||
float alpha = clamp(0.5f + 0.5f * vector_alpha.x * vector_alpha.y * frequency_limiter, 0.0, 1.0);
|
||||
return mix(color_b, color_a, alpha);
|
||||
}
|
||||
|
||||
vec2 koch_fractal_direction(float angle) {
|
||||
return vec2(sin(angle), cos(angle));
|
||||
}
|
||||
|
||||
float koch_fractal(vec2 uv, float outline, int iteration, float shape_width, float shape_height, out vec2 koch_uv) {
|
||||
float tiling = 3.0;
|
||||
vec2 center = uv - vec2(.5);
|
||||
shape_width = .85 * (shape_width / 1.);
|
||||
shape_height = .85 * (shape_height / 1.);
|
||||
center.x /= shape_width;
|
||||
center.y /= shape_height;
|
||||
|
||||
center.x = abs(center.x);
|
||||
center.y += tan(.833 * PI) * .5;
|
||||
vec2 dir = koch_fractal_direction(.833 * PI);
|
||||
float dist = dot(center - vec2(tiling / (2. * tiling), 0), dir);
|
||||
center -= dir * max(0, dist) * 2.0;
|
||||
|
||||
dir = koch_fractal_direction(.6667 * PI);
|
||||
float scale = 1.0;
|
||||
center.x += .5;
|
||||
for(int i = 0; i < iteration; i++){
|
||||
center *= tiling;
|
||||
scale *= tiling;
|
||||
center.x -= .5 * tiling;
|
||||
|
||||
center.x = abs(center.x);
|
||||
center.x -= .5;
|
||||
center -= dir * min(0.0, dot(center, dir)) * 2.0;
|
||||
}
|
||||
|
||||
dist = length(center - vec2(clamp(center.x, -1.0, 1.0), 0));
|
||||
dist += step(outline / 100.0, dist / scale);
|
||||
koch_uv = abs(center);
|
||||
return 1.0 - dist;
|
||||
}
|
||||
|
||||
vec2 gradient_modulo(vec2 divident, vec2 divisor) {
|
||||
vec2 positive_divident = mod(divident, divisor) + divisor;
|
||||
return mod(positive_divident, divisor);
|
||||
}
|
||||
|
||||
vec2 gradient_random(vec2 uv) {
|
||||
uv = vec2(dot(uv, vec2(127.1,311.7)), dot(uv, vec2(269.5,183.3)));
|
||||
return -1.0 + 2.0 * fract(sin(uv) * 43758.5453123);
|
||||
}
|
||||
|
||||
float gradient_noise(vec2 uv, float scale) {
|
||||
uv = uv * float(scale);
|
||||
vec2 period = vec2(30.0, 60.0);
|
||||
vec2 cells_minimum = floor(uv);
|
||||
vec2 cells_maximum = ceil(uv);
|
||||
vec2 uv_fract = fract(uv);
|
||||
cells_minimum = gradient_modulo(cells_minimum, period);
|
||||
cells_maximum = gradient_modulo(cells_maximum, period);
|
||||
vec2 blur = smoothstep(0.0, 1.0, uv_fract);
|
||||
vec2 lowerLeftDirection = gradient_random(vec2(cells_minimum.x, cells_minimum.y));
|
||||
vec2 lowerRightDirection = gradient_random(vec2(cells_maximum.x, cells_minimum.y));
|
||||
vec2 upperLeftDirection = gradient_random(vec2(cells_minimum.x, cells_maximum.y));
|
||||
vec2 upperRightDirection = gradient_random(vec2(cells_maximum.x, cells_maximum.y));
|
||||
vec2 fraction = fract(uv);
|
||||
float mix_one = mix(dot(lowerLeftDirection, fraction - vec2(0, 0)), dot(lowerRightDirection, fraction - vec2(1, 0)), blur.x);
|
||||
float mix_two = mix(dot(upperLeftDirection, fraction - vec2(0, 1)), dot(upperRightDirection, fraction - vec2(1, 1)), blur.x);
|
||||
return mix(mix_one, mix_two, blur.y) * 0.8 + 0.5;
|
||||
}
|
||||
|
||||
float gyroid_noise(vec2 uv, float scale, vec2 ratio, float height, float thickness) {
|
||||
scale *= 10.;
|
||||
thickness = clamp(thickness, 0., 1.);
|
||||
vec3 vector = vec3(uv, height);
|
||||
vector *= scale;
|
||||
return abs(dot(sin(vector * ratio.x), cos(vector.zxy * ratio.y))) - thickness;
|
||||
}
|
||||
|
||||
float pseudo_random_noise(vec2 uv, float seed) {
|
||||
return fract(sin(dot(uv.xy + seed, vec2(12.9898,78.233))) * 43758.5453123);
|
||||
}
|
||||
|
||||
float simple_noise_random(vec2 point) {
|
||||
return fract(sin(point.x * 100. + point.y * 654.125) * 55647.8745);
|
||||
}
|
||||
|
||||
float value_noise(vec2 uv) {
|
||||
vec2 grid_uv = fract(uv);
|
||||
vec2 grid_id = floor(uv);
|
||||
grid_uv = grid_uv * grid_uv * (3. - 2. * grid_uv);
|
||||
|
||||
float bottom_left = simple_noise_random(grid_id);
|
||||
float bottom_right = simple_noise_random(grid_id + vec2(1, 0));
|
||||
float bottom = mix(bottom_left, bottom_right, grid_uv.x);
|
||||
|
||||
float top_left = simple_noise_random(grid_id + vec2(0, 1));
|
||||
float top_right = simple_noise_random(grid_id + vec2(1, 1));
|
||||
float top = mix(top_left, top_right, grid_uv.x);
|
||||
|
||||
return mix(bottom, top, grid_uv.y);
|
||||
}
|
||||
|
||||
float simple_noise(vec2 uv, float scale, int octaves) {
|
||||
octaves = clamp(octaves, 1, 6);
|
||||
float noise = value_noise(uv * scale);
|
||||
float amplitude = 1.;
|
||||
|
||||
for(int i = 1; i < octaves; i++) {
|
||||
scale *= 2.;
|
||||
amplitude /= 2.;
|
||||
noise += value_noise(uv * scale) * amplitude;
|
||||
}
|
||||
|
||||
return noise / 2.;
|
||||
}
|
||||
|
||||
vec2 voronoi_random_vector(vec2 p) {
|
||||
mat2 matrix = mat2(vec2(15.27, 47.63), vec2(99.41, 89.98));
|
||||
return fract(sin(p * matrix) * 46839.32);
|
||||
}
|
||||
|
||||
float voronoi_noise_euclidean(vec2 uv, float cell_density, float angle_offset, out float cells){
|
||||
vec2 grid_uv = fract(uv * cell_density);
|
||||
vec2 grid_id = floor(uv * cell_density);
|
||||
vec2 cell_id = vec2(0);
|
||||
float min_dist = 100.;
|
||||
|
||||
for(float y = -1.; y <= 1.; y++) {
|
||||
for(float x = -1.; x <= 1.; x++) {
|
||||
vec2 offset = vec2(x, y);
|
||||
vec2 n = voronoi_random_vector(grid_id + offset);
|
||||
vec2 p = offset + vec2(sin(n.x + angle_offset) * .5 + .5, cos(n.y + angle_offset) * .5 + .5);
|
||||
float d = min_dist;
|
||||
d = distance(grid_uv, p);
|
||||
if(d < min_dist) {
|
||||
min_dist = d;
|
||||
cell_id = voronoi_random_vector(grid_id + offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cells = cell_id.y;
|
||||
return min_dist;
|
||||
}
|
||||
|
||||
float voronoi_noise_manhattan(vec2 uv, float cell_density, float angle_offset, out float cells){
|
||||
vec2 grid_uv = fract(uv * cell_density);
|
||||
vec2 grid_id = floor(uv * cell_density);
|
||||
vec2 cell_id = vec2(0);
|
||||
float min_dist = 100.;
|
||||
|
||||
for(float y = -1.; y <= 1.; y++) {
|
||||
for(float x = -1.; x <= 1.; x++) {
|
||||
vec2 offset = vec2(x, y);
|
||||
vec2 n = voronoi_random_vector(grid_id + offset);
|
||||
vec2 p = offset + vec2(sin(n.x + angle_offset) * .5 + .5, cos(n.y + angle_offset) * .5 + .5);
|
||||
float d = min_dist;
|
||||
d = manhattan_distance_2d(grid_uv, p);
|
||||
|
||||
if(d < min_dist) {
|
||||
min_dist = d;
|
||||
cell_id = voronoi_random_vector(grid_id + offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cells = cell_id.y;
|
||||
return min_dist;
|
||||
}
|
||||
|
||||
float voronoi_noise_chebyshev(vec2 uv, float cell_density, float angle_offset, float chebyshev_power, out float cells){
|
||||
vec2 grid_uv = fract(uv * cell_density);
|
||||
vec2 grid_id = floor(uv * cell_density);
|
||||
vec2 cell_id = vec2(0);
|
||||
float min_dist = 100.;
|
||||
|
||||
for(float y = -1.; y <= 1.; y++) {
|
||||
for(float x = -1.; x <= 1.; x++) {
|
||||
vec2 offset = vec2(x, y);
|
||||
vec2 n = voronoi_random_vector(grid_id + offset);
|
||||
vec2 p = offset + vec2(sin(n.x + angle_offset) * .5 + .5, cos(n.y + angle_offset) * .5 + .5);
|
||||
float d = min_dist;
|
||||
d = chebyshev_distance_2d(grid_uv, p, chebyshev_power);
|
||||
|
||||
if(d < min_dist) {
|
||||
min_dist = d;
|
||||
cell_id = voronoi_random_vector(grid_id + offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cells = cell_id.y;
|
||||
return min_dist;
|
||||
}
|
||||
|
||||
float ellipse_shape(vec2 uv, float width, float height) {
|
||||
float dist = length((uv * 2.0 - 1.0) / vec2(width, height));
|
||||
return clamp((1.0 - dist) / fwidth(dist), 0.0, 1.0);
|
||||
}
|
||||
|
||||
float polygon_shape(vec2 uv, int sides, float width, float height) {
|
||||
float a_width = width * cos(PI / float(sides));
|
||||
float a_height = height * cos(PI / float(sides));
|
||||
uv = (uv * 2.0 - 1.0) / vec2(a_width, a_height);
|
||||
uv.y *= -1.0;
|
||||
float polar_coords = atan(uv.x, uv.y);
|
||||
float radius = 2.0 * PI / float(sides);
|
||||
float dist = cos(floor(0.5 + polar_coords / radius) * radius - polar_coords) * length(uv);
|
||||
return clamp((1.0 - dist) / fwidth(dist), 0.0, 1.0);
|
||||
}
|
||||
|
||||
float rectangle_shape(vec2 uv, float width, float height) {
|
||||
vec2 dist = abs(uv * 2.0 - 1.0) - vec2(width, height);
|
||||
dist = 1.0 - dist / fwidth(dist);
|
||||
return clamp(min(dist.x, dist.y), 0.0, 1.0);
|
||||
}
|
||||
|
||||
float rounded_polygon_shape(vec2 uv, float width, float height, float sides, float roundness){
|
||||
uv = uv * 2.0 + vec2(-1.0);
|
||||
roundness /= 10.0;
|
||||
float epsilon = 1e-6;
|
||||
uv.x = uv.x / ( width + ((width > -epsilon && width < epsilon) ? 1.0 : 0.0 * epsilon));
|
||||
uv.y = uv.y / ( height + ((height > -epsilon && height < epsilon) ? 1.0 : 0.0 * epsilon));
|
||||
roundness = clamp(roundness, 1e-6, 1.0);
|
||||
float i_sides = floor( abs( sides ) );
|
||||
float full_angle = 2.0 * PI / i_sides;
|
||||
float half_angle = full_angle / 2.;
|
||||
float diagonal = 1.0 / cos( half_angle );
|
||||
float chamfer_angle = roundness * half_angle;
|
||||
float remaining_angle = half_angle - chamfer_angle;
|
||||
float ratio = tan(remaining_angle) / tan(half_angle);
|
||||
vec2 chamfer_center = vec2(cos(half_angle) , sin(half_angle))* ratio * diagonal;
|
||||
|
||||
float dist_a = length(chamfer_center);
|
||||
float dist_b = 1.0 - chamfer_center.x;
|
||||
float uv_scale = diagonal;
|
||||
uv *= uv_scale;
|
||||
vec2 polar_uv = vec2(atan(uv.y, uv.x), length(uv));
|
||||
|
||||
polar_uv.x += PI / 2.0 + TAU;
|
||||
polar_uv.x = mod(polar_uv.x + half_angle, full_angle );
|
||||
polar_uv.x = abs(polar_uv.x - half_angle);
|
||||
uv = vec2(cos(polar_uv.x), sin(polar_uv.x)) * polar_uv.y;
|
||||
float angle_ratio = 1.0 - (polar_uv.x- remaining_angle) / chamfer_angle;
|
||||
float dist_c = sqrt(dist_a * dist_a + dist_b * dist_b - 2.0 * dist_a * dist_b * cos(PI - half_angle * angle_ratio));
|
||||
float output = uv.x;
|
||||
float chamfer_zone = (half_angle - polar_uv.x) < chamfer_angle ? 1.0 : 0.0;
|
||||
output = mix(uv.x, polar_uv.y / dist_c, chamfer_zone);
|
||||
output = clamp((1.0 - output) / fwidth(output), 0.0, 1.0);
|
||||
return output;
|
||||
}
|
||||
|
||||
float rounded_rectangle_shape(vec2 uv, float width, float height, float radius){
|
||||
radius /= 10.0;
|
||||
radius = max(min(min(abs(radius * 2.0), abs(width)), abs(height)), 1e-5);
|
||||
uv = abs(uv * 2.0 - 1.0) - vec2(width, height) + radius;
|
||||
float dist = length(max(vec2(0.0), uv)) / radius;
|
||||
return clamp((1.0 - dist) / fwidth(dist), 0.0, 1.0);
|
||||
}
|
||||
|
||||
vec3 heigth_to_normal(sampler2D height_map, vec2 uv, float bump_strength) {
|
||||
float pixel_width = .002;
|
||||
float height = texture(height_map, uv).r;
|
||||
float r = height - texture(height_map, uv + vec2(pixel_width, 0)).r;
|
||||
float l = height - texture(height_map, uv - vec2(pixel_width, 0)).r;
|
||||
float u = height - texture(height_map, uv + vec2(0, pixel_width)).r;
|
||||
float d = height - texture(height_map, uv - vec2(0, pixel_width)).r;
|
||||
float h = (r - l) / pixel_width;
|
||||
float v = (u - d) / pixel_width;
|
||||
vec3 n = vec3(h, v, 1.);
|
||||
n.x = n.x * (pixel_width * bump_strength * .5) + .5;
|
||||
n.y = n.y * (pixel_width * bump_strength * .5) + .5;
|
||||
return normalize(n);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeProceduralEllipse extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeProceduralEllipse extends ShaderLib
|
||||
|
||||
func _init() -> void:
|
||||
output_port_for_preview = 0
|
||||
@ -54,7 +54,7 @@ func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Procedural/Procedural.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var uv: String = "UV"
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeProceduralPolygon extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeProceduralPolygon extends ShaderLib
|
||||
|
||||
func _init() -> void:
|
||||
output_port_for_preview = 0
|
||||
@ -60,7 +60,7 @@ func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Procedural/Procedural.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var uv: String = "UV"
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeProceduralRectangle extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeProceduralRectangle extends ShaderLib
|
||||
|
||||
func _init() -> void:
|
||||
output_port_for_preview = 0
|
||||
@ -54,7 +54,7 @@ func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Procedural/Procedural.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var uv: String = "UV"
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeProceduralRoundedPolygon extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeProceduralRoundedPolygon extends ShaderLib
|
||||
|
||||
func _init() -> void:
|
||||
output_port_for_preview = 0
|
||||
@ -61,7 +61,7 @@ func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Procedural/Procedural.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var uv: String = "UV"
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeProceduralRoundedRectangle extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeProceduralRoundedRectangle extends ShaderLib
|
||||
|
||||
func _init() -> void:
|
||||
output_port_for_preview = 0
|
||||
@ -58,7 +58,7 @@ func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/Procedural/Procedural.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var uv: String = "UV"
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeRayMarch extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeRayMarch extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "RayMarch"
|
||||
@ -183,7 +183,7 @@ func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/RayMarching/SignedDistanceFunctions.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/RayMarching/SignedDistanceFunctions.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var sdf_index: int = get_option_index(0)
|
||||
@ -222,4 +222,3 @@ func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shad
|
||||
var small_radius: String = input_vars[7]
|
||||
var big_radius: String = input_vars[8]
|
||||
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]
|
||||
|
3
addons/ShaderLib_v2_2_4/ShaderLib.gd
Normal file
3
addons/ShaderLib_v2_2_4/ShaderLib.gd
Normal file
@ -0,0 +1,3 @@
|
||||
class_name ShaderLib extends VisualShaderNodeCustom
|
||||
|
||||
var version: String = "v2_2_4"
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeUVFlipbook extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeUVFlipbook extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "Flipbook"
|
||||
@ -57,7 +57,7 @@ func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/UV/UV.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/UV/UV.gdshaderinc\"" % [version]
|
||||
|
||||
func _is_available(mode: Shader.Mode, type: VisualShader.Type) -> bool:
|
||||
match mode:
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeUVParallaxMapping extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeUVParallaxMapping extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "ParallaxMapping"
|
||||
@ -55,7 +55,7 @@ func _is_available(mode: Shader.Mode, type: VisualShader.Type) -> bool:
|
||||
return false
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/UV/UV.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/UV/UV.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var height_map: String = input_vars[0]
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeUVRadialShear extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeUVRadialShear extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "RadialShear"
|
||||
@ -57,7 +57,7 @@ func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/UV/UV.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/UV/UV.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var uv: String
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeUVRotate extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeUVRotate extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "Rotate"
|
||||
@ -65,7 +65,7 @@ func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Degrees", "Radians"]
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/UV/UV.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/UV/UV.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var uv: String
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeUVSpherize extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeUVSpherize extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "Spherize"
|
||||
@ -57,7 +57,7 @@ func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/UV/UV.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/UV/UV.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var uv: String
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeUVSwirl extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeUVSwirl extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "Swirl"
|
||||
@ -57,7 +57,7 @@ func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/UV/UV.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/UV/UV.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var uv: String
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeUVTilingAndOffset extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeUVTilingAndOffset extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "TilingAndOffset"
|
@ -1,5 +1,5 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeUVTwirl extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeUVTwirl extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "Twirl"
|
||||
@ -57,7 +57,7 @@ func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib/UV/UV.gdshaderinc\""
|
||||
return "#include \"res://addons/ShaderLib_%s/UV/UV.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var uv: String
|
77
addons/ShaderLib_v2_2_4/UV/UV.gdshaderinc
Normal file
77
addons/ShaderLib_v2_2_4/UV/UV.gdshaderinc
Normal file
@ -0,0 +1,77 @@
|
||||
vec2 flipbook_uv(vec2 uv, int rows, int columns, float anim_speed) {
|
||||
int start_frame = 1;
|
||||
int end_frame = rows * columns;
|
||||
start_frame += int(fract(TIME * anim_speed) * float(end_frame));
|
||||
float frame = float(clamp(start_frame, 0, end_frame));
|
||||
vec2 off_per_frame = vec2((1.0 / float(columns)), (1.0 / float(rows)));
|
||||
vec2 sprite_size = vec2(uv.x / float(columns), uv.y / float(rows));
|
||||
vec2 current_sprite = vec2(0.0, 1.0 - off_per_frame.y);
|
||||
current_sprite.x += frame * off_per_frame.x;
|
||||
float row_index;
|
||||
current_sprite.y -= 1.0 - (row_index * off_per_frame.y);
|
||||
current_sprite.x -= row_index * float(columns) * off_per_frame.x;
|
||||
vec2 sprite_uv = (sprite_size + current_sprite);
|
||||
return sprite_uv;
|
||||
}
|
||||
|
||||
vec2 parallax_mapping_uv_offset_1_step(float height, float amplitude, vec3 view_dir_tangent) {
|
||||
height = height * amplitude - amplitude / 2.0;
|
||||
vec3 vector = view_dir_tangent;
|
||||
vector.y += 0.42;
|
||||
return height * (vector.xz / vector.y);
|
||||
}
|
||||
|
||||
vec2 parallax_mapping_uv(sampler2D height, float amplitude, vec2 uv, vec3 tangent, vec3 normal, vec3 binormal, vec3 view) {
|
||||
float depth = amplitude / 10.0;
|
||||
mat3 tangent_matrix = mat3(tangent, normal, -binormal); // VIEW TO TANGENT SPACE
|
||||
vec3 view_tangent = transpose(tangent_matrix) * view;
|
||||
float parallaxHeight = texture(height, uv).r;
|
||||
vec2 parallaxOffset = parallax_mapping_uv_offset_1_step(parallaxHeight, depth, view_tangent);
|
||||
return parallaxOffset + uv;
|
||||
}
|
||||
|
||||
vec2 radial_shear_uv(vec2 uv, vec2 center, float strength, vec2 offset) {
|
||||
vec2 delta = uv - center;
|
||||
float delta2 = dot(delta.xy, delta.xy);
|
||||
vec2 delta_offset = vec2(delta2 * strength);
|
||||
return uv + vec2(delta.y, -delta.x) * delta_offset + offset;
|
||||
}
|
||||
|
||||
mat2 rotation_mat2(float angle) {
|
||||
return mat2(
|
||||
vec2(cos(angle), -sin(angle)),
|
||||
vec2(sin(angle), cos(angle))
|
||||
);
|
||||
}
|
||||
|
||||
vec2 rotate_uv(vec2 uv, vec2 center, float rotation, bool use_degrees) {
|
||||
float angle = rotation;
|
||||
if(use_degrees){
|
||||
angle = rotation * (3.1415926/180.0);
|
||||
}
|
||||
vec2 delta = uv - center;
|
||||
delta = rotation_mat2(angle) * delta;
|
||||
return delta + center;
|
||||
}
|
||||
|
||||
vec2 spherize_uv(vec2 uv, vec2 center, float strength, vec2 offset) {
|
||||
vec2 delta = uv - center;
|
||||
float delta2 = dot(delta.xy, delta.xy);
|
||||
float delta4 = delta2 * delta2;
|
||||
vec2 delta_offset = vec2(delta4 * strength);
|
||||
return uv + delta * delta_offset + offset;
|
||||
}
|
||||
|
||||
vec2 swirl_uv(vec2 uv, vec2 center, float strength, vec2 offset) {
|
||||
vec2 delta = uv - center;
|
||||
float angle = strength * max(pow(1. - length(delta), 3), 0);
|
||||
delta = rotation_mat2(angle) * delta;
|
||||
return delta + center + offset;
|
||||
}
|
||||
|
||||
vec2 twirl_uv(vec2 uv, vec2 center, float strength, vec2 offset) {
|
||||
vec2 delta = uv - center;
|
||||
float angle = strength * length(delta);
|
||||
delta = rotation_mat2(angle) * delta;
|
||||
return delta + center + offset;
|
||||
}
|
@ -56,6 +56,7 @@ For example if you want to rotate UV in your **_.gdshader_** file, you can use `
|
||||
<h2>Procedural nodes</h2>
|
||||
|
||||
<h4><a href="/documentation/Nodes/Procedural/CheckerBoard.md"> Checker Board node</a></h4>
|
||||
<h4><a href="/documentation/Nodes/Procedural/HeightToNormal.md"> Height To Normal node</a></h4>
|
||||
|
||||
<h3> Fractals</h3>
|
||||
|
||||
|
@ -10,6 +10,7 @@ Returns the transformed vector of the input value <i><b>in</b></i> from one coor
|
||||
**Controls**
|
||||
|Name|Options|Description|
|
||||
|---|---|---|
|
||||
|Vector type|Positional, Directional|Positional will take into account translation data, Directional won't|
|
||||
|From|Local, World, View, Screen, Tangent|Coordinate space from which you want to transform the input vector|
|
||||
|To|Local, World, View, Screen, Tangent|Coordinate space to which you want to transform the input vector|
|
||||
|
||||
|
29
documentation/Nodes/Procedural/HeightToNormal.md
Normal file
29
documentation/Nodes/Procedural/HeightToNormal.md
Normal file
@ -0,0 +1,29 @@
|
||||
# Height To Normal node
|
||||
Generates a normal map from a height map.
|
||||
<hr>
|
||||
|
||||
**Inputs**
|
||||
|Name|Type|Binding|Description|
|
||||
|---|---|---|---|
|
||||
|height map|sampler2D|none|Height map|
|
||||
|uv|vec2|UV|Input UV value|
|
||||
|bump strength|float|none|Bump strength for the height|
|
||||
|
||||
**Outputs**
|
||||
|Name|Type|Binding|Description|
|
||||
|---|---|---|---|
|
||||
|Normal|vec3|None|Normal map|
|
||||
|
||||
**ShaderInc location**
|
||||
<br>`res://addons/ShaderLib/Procedural/Procedural.gdshaderinc`
|
||||
|
||||
**Method signature**
|
||||
<br>`vec3 heigth_to_normal(sampler2D height_map, vec2 uv, float bump_strength)`
|
||||
|
||||
**Parameters**
|
||||
|Name|Type|Description|
|
||||
|---|---|---|
|
||||
|height_map|sampler2D|Height map|
|
||||
|uv|vec2|Input UV value|
|
||||
|bump_strength|float|Bump strength for the height|
|
||||
___
|
@ -25,7 +25,9 @@ Generates a Voronoi or Worley noise based on input UV. Voronoi noise is generate
|
||||
<br>`res://addons/ShaderLib/Procedural/Procedural.gdshaderinc`
|
||||
|
||||
**Method signature**
|
||||
<br>`void voronoi_noise(vec2 uv, float cell_density, float angle_offset, int distance_index, float chebyshev_power, out float output, out float cells)`
|
||||
<br>`float voronoi_noise_euclidean(vec2 uv, float cell_density, float angle_offset, out float cells)`
|
||||
<br>`float voronoi_noise_manhattan(vec2 uv, float cell_density, float angle_offset, out float cells)`
|
||||
<br>`float voronoi_noise_chebyshev(vec2 uv, float cell_density, float angle_offset, float chebyshev_power, out float cells)`
|
||||
|
||||
**Parameters**
|
||||
|Name|Type|Description|
|
||||
@ -33,8 +35,6 @@ Generates a Voronoi or Worley noise based on input UV. Voronoi noise is generate
|
||||
|uv|vec2|Input UV value|
|
||||
|cell_density|float|Density of generated cells|
|
||||
|angle_offset|float|Offset values for points|
|
||||
|distance_index|int|Distance matrix to use for Voronoi, 0 = Euclidean, 1 = Manhattan, 2 = Chebyshev|
|
||||
|chebyshev_power|float|Power for Chebyshev distance|
|
||||
|output|out float|Output noise value|
|
||||
|cells|out float|Output raw cell data|
|
||||
___
|
@ -12,5 +12,5 @@ config_version=5
|
||||
|
||||
config/name="Godot-shader-lib"
|
||||
config/tags=PackedStringArray("addons")
|
||||
config/features=PackedStringArray("4.2", "Forward Plus")
|
||||
config/features=PackedStringArray("4.3", "Forward Plus")
|
||||
config/icon="res://icons/icon.png"
|
||||
|
Reference in New Issue
Block a user