diff --git a/app/content/system/house/mini/mini_wall_shader.gdshader b/app/content/system/house/mini/mini_wall_shader.gdshader index b11c4e6..7ae17f2 100644 --- a/app/content/system/house/mini/mini_wall_shader.gdshader +++ b/app/content/system/house/mini/mini_wall_shader.gdshader @@ -1,11 +1,14 @@ shader_type spatial; -render_mode blend_mix, depth_draw_opaque, cull_disabled, diffuse_lambert, specular_schlick_ggx, unshaded; +render_mode blend_mix, depth_draw_opaque, cull_disabled, diffuse_burley, specular_schlick_ggx, shadows_disabled; uniform vec4 data[100]; uniform int data_size: hint_range(0, 100, 1); uniform float alpha: hint_range(0.0, 1.0, 0.1) = 0.3; uniform sampler2D color_gradient; +uniform float roughness : hint_range(0.0, 1.0) = 0.15; +uniform vec4 edge_color : source_color = vec4(0.0, 0.0, 0.0, 1.0); + varying vec3 color; float simple_weight(int index, vec3 world_pos, float p) { @@ -17,6 +20,12 @@ float sphere_weight(int index, vec3 world_pos, float r) { return pow(max(0, r - dist) / (r * dist), 2); } +float SchlickFresnel(float u) { + float m = 1.0 - u; + float m2 = m * m; + return m2 * m2 * m; +} + void vertex() { color = vec3(1.0, 1.0, 1.0); @@ -60,4 +69,14 @@ void vertex() { void fragment() { ALBEDO = vec3(color.xyz); ALPHA = alpha; + + float VdotN = dot(VIEW, NORMAL); + float fresnel = clamp(SchlickFresnel(VdotN), 0.0, 1.0); + + // apply glass look + float a = mix(0.001, 1.0, ALPHA); + ALPHA = mix(fresnel * edge_color.a, 1.0, a); + ALBEDO = mix(edge_color.rgb * edge_color.a, ALBEDO, a); + ROUGHNESS = roughness; + SPECULAR = 0.5 * inversesqrt(ALPHA); } diff --git a/app/content/ui/glass.gdshader b/app/content/ui/glass.gdshader index d0bf6b2..455ebb5 100644 --- a/app/content/ui/glass.gdshader +++ b/app/content/ui/glass.gdshader @@ -1,6 +1,6 @@ shader_type spatial; -render_mode unshaded, cull_disabled; +render_mode diffuse_burley, specular_schlick_ggx, blend_mix, cull_disabled, shadows_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); @@ -10,6 +10,9 @@ 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 roughness : hint_range(0.0, 1.0) = 0.15; +uniform vec4 edge_color : source_color = vec4(0.0, 0.0, 0.0, 1.0); + uniform float grain_amount : hint_range(0.0, 1.0) = 0.05; @@ -20,7 +23,17 @@ float rectangle(vec2 position) { return outsideDistance + insideDistance; } +float SchlickFresnel(float u) { + float m = 1.0 - u; + float m2 = m * m; + return m2 * m2 * m; +} + void fragment() { + + float VdotN = dot(VIEW, NORMAL); + float fresnel = clamp(SchlickFresnel(VdotN), 0.0, 1.0); + ALBEDO = border_color.xyz; ALPHA = 0.0; float border_scale = 1.0 + 2.0 * corner_radius; @@ -42,6 +55,13 @@ void fragment() { ALPHA = color.w; } + float a = mix(0.001, 1.0, ALPHA); + ALPHA = mix(fresnel * edge_color.a, 1.0, a); + ALBEDO = mix(edge_color.rgb * edge_color.a, ALBEDO.rgb, a); + + ROUGHNESS = roughness; + SPECULAR = 0.5 * inversesqrt(ALPHA); + float noise = (fract(sin(dot(UV, vec2(12.9898, 78.233))) * 43758.5453) - 0.5) * 2.0; // Add noise to the original color diff --git a/app/content/ui/glass2.gdshader b/app/content/ui/glass2.gdshader new file mode 100644 index 0000000..b12dd58 --- /dev/null +++ b/app/content/ui/glass2.gdshader @@ -0,0 +1,46 @@ +shader_type spatial; +render_mode diffuse_burley, specular_schlick_ggx, blend_mix; + +group_uniforms albedo; +uniform vec4 albedo : source_color = vec4(1.0, 1.0, 1.0, 0.0); +uniform sampler2D albedo_texture : source_color, hint_default_white; + +group_uniforms roughness; +uniform float roughness : hint_range(0.0, 1.0) = 0.15; +uniform sampler2D roughness_texture : hint_roughness_r; + +group_uniforms normal; +uniform float normal_strength : hint_range(-16.0, 16.0) = 1.0; +uniform sampler2D normal_map : hint_normal; + +group_uniforms misc; +uniform vec4 edge_color : source_color = vec4(0.0, 0.0, 0.0, 1.0); + +float SchlickFresnel(float u) { + float m = 1.0 - u; + float m2 = m * m; + return m2 * m2 * m; +} + +void fragment() { + // calculate fresnel values + float VdotN = dot(VIEW, NORMAL); + float fresnel = clamp(SchlickFresnel(VdotN), 0.0, 1.0); + + // sample and mix textures + vec4 _albedo = texture(albedo_texture, UV) * albedo; + float _roughness = texture(roughness_texture, UV).r * roughness; + + // apply glass look + float a = mix(0.001, 1.0, _albedo.a); + ALPHA = mix(fresnel * edge_color.a, 1.0, a); + ALBEDO = mix(edge_color.rgb * edge_color.a, _albedo.rgb, a); + + ROUGHNESS = _roughness; + NORMAL_MAP = texture(normal_map, UV).xyz; + NORMAL_MAP_DEPTH = normal_strength; + + // function to compensate specular for alpha blend + // 0.5 * ALPHA^-0.5 + SPECULAR = 0.5 * inversesqrt(ALPHA); +} \ No newline at end of file diff --git a/app/content/ui/test.material b/app/content/ui/test.material index baf74a1..53681ab 100644 --- a/app/content/ui/test.material +++ b/app/content/ui/test.material @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ca6bc1d679f5e116431fb17104d1bcb1083ca0b5e834c20bd5008dbaa7c3b79a -size 413 +oid sha256:6041f48bfc2a4bc4c88096265fb3baf46881eec9a244104378c98a6c5e0dbb9a +size 442 diff --git a/app/content/ui/test.tscn b/app/content/ui/test.tscn index 51d143e..c13bcd6 100644 --- a/app/content/ui/test.tscn +++ b/app/content/ui/test.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=7 format=3 uid="uid://dclceqjqfxekx"] +[gd_scene load_steps=10 format=3 uid="uid://dclceqjqfxekx"] [ext_resource type="Script" path="res://content/ui/test.gd" id="1_jevji"] [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"] +[ext_resource type="Shader" path="res://content/ui/glass2.gdshader" id="5_yedor"] [sub_resource type="BoxShape3D" id="BoxShape3D_ptbst"] size = Vector3(2, 1, 0.1) @@ -11,9 +12,24 @@ size = Vector3(2, 1, 0.1) [sub_resource type="QuadMesh" id="QuadMesh_4253w"] size = Vector2(0.8, 0.5) +[sub_resource type="ShaderMaterial" id="ShaderMaterial_tiql8"] +render_priority = 0 +shader = ExtResource("5_yedor") +shader_parameter/albedo = Color(1, 1, 1, 0.388235) +shader_parameter/roughness = 0.15 +shader_parameter/normal_strength = 1.0 +shader_parameter/edge_color = Color(0, 0, 0, 1) + +[sub_resource type="QuadMesh" id="QuadMesh_g82c4"] +size = Vector2(1, 0.5) + [node name="Test" type="Node3D"] script = ExtResource("1_jevji") +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] +transform = Transform3D(-0.866023, -0.433016, 0.250001, 0.470665, -0.53724, 0.699892, -0.168754, 0.723789, 0.669068, 0.677175, 0.464924, 0.836006) +shadow_enabled = true + [node name="StaticBody3D" type="StaticBody3D" parent="."] [node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D"] @@ -64,3 +80,10 @@ value = 0.0 [node name="Movable" type="Node" parent="StaticBody3D"] script = ExtResource("4_qjv7o") + +[node name="MeshInstance3D3" type="MeshInstance3D" parent="StaticBody3D"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.0121959) +visible = false +material_override = SubResource("ShaderMaterial_tiql8") +mesh = SubResource("QuadMesh_g82c4") +skeleton = NodePath("../..")