update shader and test tscn

This commit is contained in:
Nitwel 2024-04-21 23:45:09 +02:00
parent 4fe0f1e4c9
commit cc69cafd98
3 changed files with 37 additions and 22 deletions

View File

@ -1,12 +1,18 @@
shader_type spatial;
render_mode unshaded, cull_disabled;
uniform vec4 color : source_color = vec4(1.0, 1.0, 1.0, 1.0);
uniform vec4 border_color : source_color = vec4(1.0, 1.0, 1.0, 1.0);
uniform vec2 size = vec2(1.0, 1.0);
uniform float border_size = 0.1;
uniform float border_size: hint_range(0.0, 0.5) = 0.1;
uniform float border_fade_in: hint_range(0.0, 10.0) = 0.0;
uniform float border_fade_out: hint_range(0.0, 10.0) = 0.0;
uniform float corner_radius = 0.0;
uniform float grain_amount : hint_range(0.0, 1.0) = 0.05;
float rectangle(vec2 position) {
vec2 component_wise_edge_distance = abs(position) - (vec2(0.5, 0.5) * size + corner_radius * (size - 1.0));
float outsideDistance = length(max(component_wise_edge_distance, 0));
@ -15,19 +21,31 @@ float rectangle(vec2 position) {
}
void fragment() {
ALBEDO = color.xyz;
ALBEDO = border_color.xyz;
ALPHA = 0.0;
float border_scale = 1.0 + 2.0 * corner_radius;
float d = rectangle((UV - 0.5) * size * border_scale);
float border_width = (border_size + border_fade_in + border_fade_out) * border_scale;
if (d >= corner_radius - border_width && d <= corner_radius) {
// Inside
float rel_d = (d - corner_radius + border_width) / border_width;
ALPHA = min((rel_d / (border_fade_in * border_scale / border_width)), (1.0 - (rel_d)) / (border_fade_out * border_scale / border_width));
float alpha = min((rel_d / (border_fade_in * border_scale / border_width)), (1.0 - (rel_d)) / (border_fade_out * border_scale / border_width));
if (d < corner_radius - (border_size + border_fade_out) * border_scale) {
ALBEDO = mix(color, border_color, alpha).xyz;
ALPHA = mix(color.w, border_color.w, alpha);
} else {
// Outside
ALPHA = 0.0;
ALBEDO = border_color.xyz;
ALPHA = mix(0.0, border_color.w, alpha);
}
} else if (d < corner_radius - border_width ) {
ALBEDO = color.xyz;
ALPHA = color.w;
}
float noise = (fract(sin(dot(UV, vec2(12.9898, 78.233))) * 43758.5453) - 0.5) * 2.0;
// Add noise to the original color
ALBEDO += noise * grain_amount;
}

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ca6bc1d679f5e116431fb17104d1bcb1083ca0b5e834c20bd5008dbaa7c3b79a
size 413

View File

@ -1,25 +1,15 @@
[gd_scene load_steps=8 format=3 uid="uid://dclceqjqfxekx"]
[gd_scene load_steps=7 format=3 uid="uid://dclceqjqfxekx"]
[ext_resource type="Script" path="res://content/ui/test.gd" id="1_jevji"]
[ext_resource type="Shader" path="res://content/ui/glass.gdshader" id="1_p0dkh"]
[ext_resource type="Material" uid="uid://dy5bbwaceset8" path="res://content/ui/test.material" id="2_fswvt"]
[ext_resource type="PackedScene" uid="uid://pk5k1q8bx0rj" path="res://content/ui/components/slider/slider.tscn" id="3_f40pk"]
[ext_resource type="Script" path="res://content/functions/movable.gd" id="4_qjv7o"]
[sub_resource type="BoxShape3D" id="BoxShape3D_ptbst"]
size = Vector3(2, 1, 0.1)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_xoqnh"]
render_priority = 0
shader = ExtResource("1_p0dkh")
shader_parameter/color = Color(1, 1, 1, 1)
shader_parameter/size = Vector2(2, 1)
shader_parameter/border_size = 0.04
shader_parameter/border_fade_in = 0.07
shader_parameter/border_fade_out = 0.0
shader_parameter/corner_radius = 3.435
[sub_resource type="QuadMesh" id="QuadMesh_4253w"]
size = Vector2(2, 1)
size = Vector2(0.8, 0.5)
[node name="Test" type="Node3D"]
script = ExtResource("1_jevji")
@ -28,10 +18,11 @@ script = ExtResource("1_jevji")
[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.07)
visible = false
shape = SubResource("BoxShape3D_ptbst")
[node name="MeshInstance3D" type="MeshInstance3D" parent="StaticBody3D"]
material_override = SubResource("ShaderMaterial_xoqnh")
material_override = ExtResource("2_fswvt")
mesh = SubResource("QuadMesh_4253w")
skeleton = NodePath("../..")
@ -53,20 +44,23 @@ label_unit = "h"
[node name="Slider3" parent="StaticBody3D" instance=ExtResource("3_f40pk")]
transform = Transform3D(-4.37114e-08, 4.37114e-08, 1, 1, 1.91069e-15, 4.37114e-08, 0, 1, -4.37114e-08, 0.179572, 0, 0)
max = 0.5
show_label = true
label_unit = "s"
[node name="Slider4" parent="StaticBody3D" instance=ExtResource("3_f40pk")]
transform = Transform3D(-4.37114e-08, 4.37114e-08, 1, 1, 1.91069e-15, 4.37114e-08, 0, 1, -4.37114e-08, 0.277398, 0, 0)
max = 10.0
show_label = true
label_unit = "c"
[node name="Slider5" parent="StaticBody3D" instance=ExtResource("3_f40pk")]
transform = Transform3D(-4.37114e-08, 4.37114e-08, 1, 1, 1.91069e-15, 4.37114e-08, 0, 1, -4.37114e-08, 0.368523, 0, 0)
max = 0.5
[node name="Slider6" parent="StaticBody3D" instance=ExtResource("3_f40pk")]
transform = Transform3D(-4.37114e-08, 4.37114e-08, 1, 1, 1.91069e-15, 4.37114e-08, 0, 1, -4.37114e-08, 0.458309, 0, 0)
max = 0.5
value = 0.0
[node name="Movable" type="Node" parent="StaticBody3D"]
script = ExtResource("4_qjv7o")