From ba93e0d3f59b84e70433132ab60e562b7a7834bd Mon Sep 17 00:00:00 2001 From: Sara Date: Tue, 16 Jun 2026 15:48:04 +0200 Subject: [PATCH] feat: more player shader --- project/assets/character/player/player.tscn | 2 ++ .../assets/character/player/skin_shader.tres | 29 +++++++--------- .../character/shaders/player_skin.gdshader | 29 ++++++++++++---- .../assets/materials/kaleidoscope_mosaic.tres | 33 +++++++++++-------- .../kaleidoscope_mosaic_albedo.png.import | 2 +- .../kaleidoscope_mosaic_heightmap.png | 4 +-- .../materials/kaleidoscope_mosaic_normal.png | 4 +-- .../materials/stone_block_albedo.png.import | 2 +- project/data/player_noise_mask.tres | 14 ++++++++ project/levels/appartments.tscn | 2 +- project/objects/player.tscn | 1 + 11 files changed, 77 insertions(+), 45 deletions(-) create mode 100644 project/data/player_noise_mask.tres diff --git a/project/assets/character/player/player.tscn b/project/assets/character/player/player.tscn index 4332296e..173f7443 100644 --- a/project/assets/character/player/player.tscn +++ b/project/assets/character/player/player.tscn @@ -9,8 +9,10 @@ transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 0, 0, 0) [node name="BlankCharacterMesh" parent="HumanArmature/Skeleton3D" parent_id_path=PackedInt32Array(1295955268) index="0" unique_id=1294452068] +transform = Transform3D(0.99992746, 0, 0, 0, 0.99992746, 0, 0, 0, 0.99992746, 0, 0, 0) layers = 3 material_override = ExtResource("2_0o6ap") +instance_shader_parameters/health = 0.6790000322525 [node name="Eyes" parent="HumanArmature/Skeleton3D" parent_id_path=PackedInt32Array(1295955268) index="4" unique_id=332871592] layers = 3 diff --git a/project/assets/character/player/skin_shader.tres b/project/assets/character/player/skin_shader.tres index 8017a35d..95c7a9e8 100644 --- a/project/assets/character/player/skin_shader.tres +++ b/project/assets/character/player/skin_shader.tres @@ -1,35 +1,30 @@ [gd_resource type="ShaderMaterial" format=3 uid="uid://dmfij86pa2ce4"] [ext_resource type="Shader" uid="uid://briad1jwmkdw2" path="res://assets/character/shaders/player_skin.gdshader" id="1_6rrkd"] +[ext_resource type="Texture2D" uid="uid://clm4tvbemlk7a" path="res://data/player_noise_mask.tres" id="2_mlgwu"] [ext_resource type="Texture2D" uid="uid://cufv10vyjbn0x" path="res://assets/character/player/player_skin.png" id="2_thik8"] [ext_resource type="Texture2D" uid="uid://34f1swwafqoa" path="res://assets/materials/kaleidoscope_mosaic_emission.png" id="3_i1ahx"] [ext_resource type="Texture2D" uid="uid://b0yi45ldkax5s" path="res://assets/materials/kaleidoscope_mosaic_heightmap.png" id="4_i1ahx"] [ext_resource type="Texture2D" uid="uid://dwskfat6ut10d" path="res://assets/materials/kaleidoscope_mosaic_normal.png" id="4_thik8"] -[sub_resource type="FastNoiseLite" id="FastNoiseLite_thik8"] -noise_type = 0 -frequency = 0.007 -offset = Vector3(-151.31, 0, 0) -fractal_octaves = 3 -fractal_lacunarity = 2.4 -fractal_gain = -0.432 -fractal_weighted_strength = 0.36 - -[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_i1ahx"] -noise = SubResource("FastNoiseLite_thik8") -invert = true +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_i1ahx"] +cull_mode = 1 +shading_mode = 0 +albedo_color = Color(0, 0, 0, 1) +grow = true +grow_amount = 0.007 [resource] render_priority = 0 +next_pass = SubResource("StandardMaterial3D_i1ahx") shader = ExtResource("1_6rrkd") -shader_parameter/alpha_texture = SubResource("NoiseTexture2D_i1ahx") -shader_parameter/health = 0.3510000166725 +shader_parameter/mask_texture = ExtResource("2_mlgwu") shader_parameter/top_layer_albedo = ExtResource("2_thik8") shader_parameter/under_layer_albedo = ExtResource("3_i1ahx") shader_parameter/under_layer_normal = ExtResource("4_thik8") shader_parameter/under_layer_depth = ExtResource("4_i1ahx") shader_parameter/under_layer_scale = 11.561 -shader_parameter/under_layer_depth_scale = 0.349 -shader_parameter/max_depth_layers = 128.0 -shader_parameter/min_depth_layers = 32.0 +shader_parameter/under_layer_depth_scale = 0.081 +shader_parameter/max_depth_layers = 500.0 +shader_parameter/min_depth_layers = 100.0 shader_parameter/under_emission_strength = 0.052 diff --git a/project/assets/character/shaders/player_skin.gdshader b/project/assets/character/shaders/player_skin.gdshader index 6d169538..61c240a8 100644 --- a/project/assets/character/shaders/player_skin.gdshader +++ b/project/assets/character/shaders/player_skin.gdshader @@ -1,37 +1,52 @@ shader_type spatial; render_mode diffuse_toon, specular_disabled; -uniform sampler2D alpha_texture : hint_default_white, filter_linear; -uniform float health : hint_range(0.0, 1.0) = 1.0; +uniform sampler2D mask_texture : hint_default_white, filter_linear; // mask to add irregularity to revealed crystals +instance uniform float health : hint_range(0.0, 1.0) = .4; // amount of hidden under layer (0=fully revealed, 1=fully hidden) group_uniforms TopLayer; -uniform sampler2D top_layer_albedo : source_color, hint_default_black, filter_linear_mipmap_anisotropic; +uniform sampler2D top_layer_albedo : source_color, hint_default_black, filter_linear_mipmap_anisotropic; // top layer only has albedo colour, all others maps are constant/unchanged group_uniforms UnderLayer; +// basic maps albedo + normal uniform sampler2D under_layer_albedo : source_color, hint_default_white, filter_linear_mipmap_anisotropic; uniform sampler2D under_layer_normal : hint_normal; +// depth map uniform sampler2D under_layer_depth : hint_default_white, filter_linear_mipmap_anisotropic; +// uv scale for under layer uniform float under_layer_scale = 1.0; +// depth factor uniform float under_layer_depth_scale = 1.0; +// depth layer counts uniform float max_depth_layers = 128.0; uniform float min_depth_layers = 8.0; +// under layer emission multiplier uniform float under_emission_strength = 0.5; +// convert model space to tangent space varying mat3 tangent_matrix; +// converts texture UV to parallax depth UV vec2 uv_to_parallax(vec2 uv, vec3 view_direction, sampler2D depth_map, float depth_factor) { - vec2 penetration = view_direction.xy * -depth_factor; + // total amount of UV shift from 0.0 to 1.0 depth + vec2 uv_total_shift = view_direction.xy * -depth_factor; + // number of layers to check for this fragment, based on view depth float layer_count = mix(min_depth_layers, max_depth_layers, max(dot(vec3(0.0, 0.0, 1.0), view_direction), 0.0)); + // amount of space between layers as a percentage of total depth float layer_separation = 1.0 / layer_count; - vec2 uv_layer_shift = penetration / layer_count; + // amount each layer is shifted due to the angle + vec2 uv_layer_shift = uv_total_shift / layer_count; + // starting at the top, find the first layer that intersects the view angle vec2 uv_iterator = uv; float layer_depth_iterator = 0.0; float depth_iterator = 1.0 - (texture(depth_map, uv).r); + // ... by iterating until the depth of this layer peeks _above_ the view depth while(layer_depth_iterator < depth_iterator) { - uv_iterator -= uv_layer_shift; + uv_iterator -= uv_layer_shift; // adjusting the UV according to view angle each time depth_iterator = 1.0 - (texture(depth_map, uv_iterator).r); layer_depth_iterator += layer_separation; } + // vec2 steep_parallax_uv = uv_iterator; float steep_parallax_depth = depth_iterator - layer_depth_iterator; float depth_distance = texture(depth_map, steep_parallax_uv).r - layer_depth_iterator + layer_separation; @@ -48,7 +63,7 @@ void fragment() { vec2 under_uv_parallax = uv_to_parallax(under_uv, normalize(normalize(-VERTEX) * tangent_matrix), under_layer_depth, under_layer_depth_scale); vec4 top_layer_sample = texture(top_layer_albedo, UV); vec4 under_layer_sample = texture(under_layer_albedo, under_uv_parallax); - float alpha = clamp(step(0.0, health - texture(alpha_texture, UV).r * texture(under_layer_depth, under_uv_parallax).r) * top_layer_sample.a, 0.0, 1.0); + float alpha = clamp(step(0.0, health - texture(mask_texture, UV).r * texture(under_layer_depth, under_uv_parallax).r) * top_layer_sample.a, 0.0, 1.0); if (alpha < 1.0 && (under_uv_parallax.x / under_layer_scale > 1.0 || under_uv_parallax.x / under_layer_scale < 0.0 || under_uv_parallax.y / under_layer_scale > 1.0 || under_uv_parallax.y / under_layer_scale < 0.0)) { discard; } diff --git a/project/assets/materials/kaleidoscope_mosaic.tres b/project/assets/materials/kaleidoscope_mosaic.tres index 7b9bfa8f..dc1126df 100644 --- a/project/assets/materials/kaleidoscope_mosaic.tres +++ b/project/assets/materials/kaleidoscope_mosaic.tres @@ -1,22 +1,27 @@ -[gd_resource type="StandardMaterial3D" format=3 uid="uid://dui8cejorbv0l"] - -[ext_resource type="Texture2D" uid="uid://ddaso2y8ooove" path="res://assets/materials/kaleidoscope_mosaic_albedo.png" id="1"] -[ext_resource type="Texture2D" uid="uid://dwskfat6ut10d" path="res://assets/materials/kaleidoscope_mosaic_normal.png" id="3"] -[ext_resource type="Texture2D" uid="uid://b0yi45ldkax5s" path="res://assets/materials/kaleidoscope_mosaic_heightmap.png" id="4"] -[ext_resource type="Texture2D" uid="uid://34f1swwafqoa" path="res://assets/materials/kaleidoscope_mosaic_emission.png" id="5"] - +[gd_resource type="StandardMaterial3D" load_steps=5 format=2] +[ext_resource path="kaleidoscope_mosaic_albedo.png" type="Texture" id=1] +[ext_resource path="kaleidoscope_mosaic_normal.png" type="Texture" id=3] +[ext_resource path="kaleidoscope_mosaic_heightmap.png" type="Texture" id=4] +[ext_resource path="kaleidoscope_mosaic_emission.png" type="Texture" id=5] [resource] -albedo_texture = ExtResource("1") +albedo_color = Color(1.0, 1.0, 1.0, 1.0) +albedo_texture = ExtResource( 1 ) metallic = 1.0 roughness = 0.19 -emission_enabled = true -emission_energy_multiplier = 0.03 -emission_texture = ExtResource("5") normal_enabled = true -normal_texture = ExtResource("3") +normal_scale = 1.0 +normal_texture = ExtResource( 3 ) +emission_enabled = true +emission = Color( 0, 0, 0, 1 ) +emission_energy = 0.03 +emission_operator = 0 +emission_texture = ExtResource( 5 ) heightmap_enabled = true -heightmap_scale = 25.0 +heightmap_scale = 7.0 heightmap_deep_parallax = true heightmap_min_layers = 8 heightmap_max_layers = 32 -heightmap_texture = ExtResource("4") +heightmap_texture = ExtResource( 4 ) + + + diff --git a/project/assets/materials/kaleidoscope_mosaic_albedo.png.import b/project/assets/materials/kaleidoscope_mosaic_albedo.png.import index 2faa46a6..b38c4d7b 100644 --- a/project/assets/materials/kaleidoscope_mosaic_albedo.png.import +++ b/project/assets/materials/kaleidoscope_mosaic_albedo.png.import @@ -22,7 +22,7 @@ compress/lossy_quality=0.7 compress/uastc_level=0 compress/rdo_quality_loss=0.0 compress/hdr_compression=1 -compress/normal_map=1 +compress/normal_map=2 compress/channel_pack=0 mipmaps/generate=true mipmaps/limit=-1 diff --git a/project/assets/materials/kaleidoscope_mosaic_heightmap.png b/project/assets/materials/kaleidoscope_mosaic_heightmap.png index 37ff3035..d7690f90 100644 --- a/project/assets/materials/kaleidoscope_mosaic_heightmap.png +++ b/project/assets/materials/kaleidoscope_mosaic_heightmap.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3d4477efd7f766794fb9cc5eeb66cab675703b1e997af460a5125dfcc13833e0 -size 459976 +oid sha256:ae5e09e269deab1ead88dd1423efa3283a44f9f9fa2dde150c61a884080e5e13 +size 690214 diff --git a/project/assets/materials/kaleidoscope_mosaic_normal.png b/project/assets/materials/kaleidoscope_mosaic_normal.png index f646a0a3..2b7dbe6e 100644 --- a/project/assets/materials/kaleidoscope_mosaic_normal.png +++ b/project/assets/materials/kaleidoscope_mosaic_normal.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:97bac14517971358465655e3e43ec048c7bdea3dd66ce0d6ac67879b496304a8 -size 1620775 +oid sha256:f561885a0026af64dd50fcaa6ec220f2f3d9b009212c2b2773ca8e96a7d050b1 +size 1755378 diff --git a/project/assets/materials/stone_block_albedo.png.import b/project/assets/materials/stone_block_albedo.png.import index 571786f7..679329ac 100644 --- a/project/assets/materials/stone_block_albedo.png.import +++ b/project/assets/materials/stone_block_albedo.png.import @@ -22,7 +22,7 @@ compress/lossy_quality=0.7 compress/uastc_level=0 compress/rdo_quality_loss=0.0 compress/hdr_compression=1 -compress/normal_map=1 +compress/normal_map=2 compress/channel_pack=0 mipmaps/generate=true mipmaps/limit=-1 diff --git a/project/data/player_noise_mask.tres b/project/data/player_noise_mask.tres new file mode 100644 index 00000000..a6b5cc01 --- /dev/null +++ b/project/data/player_noise_mask.tres @@ -0,0 +1,14 @@ +[gd_resource type="NoiseTexture2D" format=3 uid="uid://clm4tvbemlk7a"] + +[sub_resource type="Gradient" id="Gradient_7f35t"] +offsets = PackedFloat32Array(0.7650961, 0.88510245) +colors = PackedColorArray(1, 1, 1, 1, 0, 0, 0, 1) + +[sub_resource type="FastNoiseLite" id="FastNoiseLite_i1ahx"] +frequency = 0.0559 + +[resource] +width = 128 +height = 128 +noise = SubResource("FastNoiseLite_i1ahx") +color_ramp = SubResource("Gradient_7f35t") diff --git a/project/levels/appartments.tscn b/project/levels/appartments.tscn index f5b2a8c7..66ecacda 100644 --- a/project/levels/appartments.tscn +++ b/project/levels/appartments.tscn @@ -1916,7 +1916,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3, 0) transform = Transform3D(-4.371139e-08, 0, -1, 0, 1, 0, 1, 0, -4.371139e-08, 0.07438529, 0.0057001114, -3.970789) [node name="AppartmentFascade3" parent="TowerC/AppartmentBuildingStory12" unique_id=707801204 instance=ExtResource("4_eefle")] -transform = Transform3D(-4.371139e-08, 0, -1, 0, 1, 0, 1, 0, -4.371139e-08, 0.074384816, 0.0057001114, 4.0292115) +transform = Transform3D(-4.371139e-08, 0, -1, 0, 1, 0, 1, 0, -4.371139e-08, 0.07438469, 0.0057001114, 4.029211) [node name="stairs" parent="TowerC" unique_id=1879869667 instance=ExtResource("12_nrvdc")] transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 1, 3, 11) diff --git a/project/objects/player.tscn b/project/objects/player.tscn index 55312947..e8c78fa2 100644 --- a/project/objects/player.tscn +++ b/project/objects/player.tscn @@ -68,6 +68,7 @@ animation = &"wallrun_right" [sub_resource type="AnimationNodeBlend2" id="AnimationNodeBlend2_eqqp1"] [sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_uxov2"] +graph_offset = Vector2(-363.57355, -446.2923) nodes/output/position = Vector2(1140, 140) nodes/ClimbUpClip/node = SubResource("AnimationNodeAnimation_vqq2l") nodes/ClimbUpClip/position = Vector2(480, 480)