Add some cool shaders

This commit is contained in:
Nikolai Rodionov 2025-02-04 13:18:53 +01:00
parent 3560bebbcc
commit 63951803a2
Signed by: allanger
GPG Key ID: 09F8B434D0FDD99B
4 changed files with 98 additions and 33 deletions

View File

@ -1,6 +1,7 @@
[gd_scene load_steps=20 format=4 uid="uid://ddwrs0so7swxn"]
[gd_scene load_steps=22 format=4 uid="uid://ddwrs0so7swxn"]
[ext_resource type="Script" path="res://scenes/characters/character_wrapper.gd" id="1_k4p2i"]
[ext_resource type="Shader" path="res://shaders/test.gdshader" id="2_1fm51"]
[ext_resource type="Script" path="res://scenes/characters/hit_detected.gd" id="2_oqdj0"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_su866"]
@ -229,6 +230,10 @@ bind/64/name = &"mixamorig_RightToe_End"
bind/64/bone = -1
bind/64/pose = Transform3D(-99.9742, -1.79969, 1.38647, 1.41798, -1.75007, 99.9746, -1.77497, 99.9685, 1.77515, -9.59363, -21.1414, -3.65246)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_d0e4k"]
render_priority = 0
shader = ExtResource("2_1fm51")
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ow6gq"]
resource_name = "Alpha_Body_MAT"
cull_mode = 2
@ -2790,13 +2795,15 @@ bones/64/scale = Vector3(1, 1, 1)
[node name="Alpha_Joints" type="MeshInstance3D" parent="model/Body/Skeleton3D"]
mesh = SubResource("ArrayMesh_5dlpb")
skin = SubResource("Skin_rvj8b")
surface_material_override/0 = SubResource("ShaderMaterial_d0e4k")
[node name="Alpha_Surface" type="MeshInstance3D" parent="model/Body/Skeleton3D"]
mesh = SubResource("ArrayMesh_7ywky")
skin = SubResource("Skin_rvj8b")
surface_material_override/0 = SubResource("ShaderMaterial_d0e4k")
[node name="HeadAttachment" type="BoneAttachment3D" parent="model/Body/Skeleton3D"]
transform = Transform3D(1, -8.72661e-05, -2.03588e-07, 2.03586e-07, -2.60935e-08, 1, -8.72661e-05, -1, -2.60935e-08, -0.00445369, -0.340739, -160.075)
transform = Transform3D(1, -8.72661e-05, -2.03595e-07, 2.03593e-07, -1.86429e-08, 1, -8.72661e-05, -1, -1.86429e-08, -0.00445369, -0.340739, -160.075)
bone_name = "mixamorig_Head"
bone_idx = 5
@ -2827,7 +2834,7 @@ body_part = "Torso"
shape = SubResource("CapsuleShape3D_tr87i")
[node name="RightHipAttachment" type="BoneAttachment3D" parent="model/Body/Skeleton3D"]
transform = Transform3D(-0.999982, -0.00602634, -7.76412e-05, -1.30228e-06, -0.0126665, 0.99992, -0.00602684, 0.999902, 0.0126663, -9.12448, -0.0553331, -93.1355)
transform = Transform3D(-0.999982, -0.00602634, -7.76412e-05, -1.30229e-06, -0.0126665, 0.99992, -0.00602684, 0.999902, 0.0126663, -9.12448, -0.0553331, -93.1355)
bone_name = "mixamorig_RightUpLeg"
bone_idx = 60
@ -2858,7 +2865,7 @@ body_part = "Right Leg"
shape = SubResource("CapsuleShape3D_h5mrs")
[node name="RightFootAttachment" type="BoneAttachment3D" parent="model/Body/Skeleton3D"]
transform = Transform3D(-0.99866, -0.0237603, 0.0459726, -5.97443e-07, 0.88837, 0.459128, -0.0517497, 0.458513, -0.88718, -9.12446, -2.63009, -10.4922)
transform = Transform3D(-0.99866, -0.0237603, 0.0459725, -5.66943e-07, 0.888369, 0.459129, -0.0517496, 0.458514, -0.887179, -9.12446, -2.63009, -10.4922)
bone_name = "mixamorig_RightFoot"
bone_idx = 62
@ -2873,7 +2880,7 @@ body_part = "Right Foot"
shape = SubResource("BoxShape3D_1pj41")
[node name="RightArmAttachment" type="BoneAttachment3D" parent="model/Body/Skeleton3D"]
transform = Transform3D(1.85437e-06, -1, -6.98492e-07, 1, 1.92268e-06, -2.95534e-07, 3.52825e-07, -6.57514e-07, 1, -18.7638, -6.1714, -143.565)
transform = Transform3D(1.88417e-06, -1, -6.42613e-07, 1, 1.95263e-06, -3.02052e-07, 2.49216e-07, -5.60656e-07, 1, -18.7638, -6.1714, -143.565)
bone_name = "mixamorig_RightArm"
bone_idx = 32
@ -2888,7 +2895,7 @@ body_part = "Right Arm"
shape = SubResource("CapsuleShape3D_56i6t")
[node name="RightForearmAttachment" type="BoneAttachment3D" parent="model/Body/Skeleton3D"]
transform = Transform3D(1.80121e-06, -1, -3.08638e-07, 1, 1.86951e-06, -1.07555e-07, 1.64845e-07, -2.6766e-07, 1, -46.1685, -6.17135, -143.565)
transform = Transform3D(1.83101e-06, -1, -2.52758e-07, 1, 1.89947e-06, -1.14072e-07, 6.12353e-08, -1.70802e-07, 1, -46.1685, -6.17135, -143.565)
bone_name = "mixamorig_RightForeArm"
bone_idx = 33
@ -2903,7 +2910,7 @@ body_part = "Right Forearm"
shape = SubResource("CapsuleShape3D_1sjun")
[node name="RightPalmAttachment" type="BoneAttachment3D" parent="model/Body/Skeleton3D"]
transform = Transform3D(2.03487e-06, -1, -7.82122e-07, 1, 2.10317e-06, -4.60422e-07, 5.17713e-07, -7.41144e-07, 1, -73.783, -6.17128, -143.565)
transform = Transform3D(2.06467e-06, -1, -7.26243e-07, 1, 2.13313e-06, -4.66939e-07, 4.14103e-07, -6.44286e-07, 1, -73.783, -6.17128, -143.565)
bone_name = "mixamorig_RightHand"
bone_idx = 34
@ -2919,7 +2926,7 @@ transform = Transform3D(1, -4.54747e-13, -5.68434e-14, 0, 1, 2.94416e-14, 0, -8.
shape = SubResource("SphereShape3D_eryh8")
[node name="LeftHipAttachment" type="BoneAttachment3D" parent="model/Body/Skeleton3D"]
transform = Transform3D(-0.999982, 0.00602684, 7.59335e-05, -4.90119e-07, -0.0126795, 0.99992, 0.00602732, 0.999901, 0.0126793, 9.12442, -0.0553195, -93.1355)
transform = Transform3D(-0.999982, 0.00602684, 7.59335e-05, -4.90116e-07, -0.0126795, 0.99992, 0.00602731, 0.999901, 0.0126793, 9.12442, -0.0553195, -93.1355)
bone_name = "mixamorig_LeftUpLeg"
bone_idx = 55
@ -2935,7 +2942,7 @@ transform = Transform3D(0.997222, -0.0744854, -0.000943551, 0.0744854, 0.997222,
shape = SubResource("CapsuleShape3D_xyxrh")
[node name="LeftLegAttachment" type="BoneAttachment3D" parent="model/Body/Skeleton3D"]
transform = Transform3D(-0.999983, -0.00581159, -0.000285655, -9.44594e-07, -0.0489312, 0.998802, -0.0058186, 0.998785, 0.0489303, 9.36911, -0.570101, -52.5401)
transform = Transform3D(-0.999983, -0.00581159, -0.000285655, -9.44579e-07, -0.0489312, 0.998802, -0.0058186, 0.998785, 0.0489303, 9.36911, -0.570101, -52.5401)
bone_name = "mixamorig_LeftLeg"
bone_idx = 56
@ -2965,7 +2972,7 @@ body_part = "Left Foot"
shape = SubResource("BoxShape3D_1pj41")
[node name="LeftArmAttachment" type="BoneAttachment3D" parent="model/Body/Skeleton3D"]
transform = Transform3D(-3.4824e-06, 1, 1.33924e-06, -1, -3.41376e-06, 4.89861e-07, 5.22362e-07, -1.30571e-06, 1, 18.7578, -6.17146, -143.565)
transform = Transform3D(-3.4526e-06, 1, 1.33924e-06, -1, -3.3838e-06, 4.83343e-07, 5.16076e-07, -1.30385e-06, 1, 18.7578, -6.17146, -143.565)
bone_name = "mixamorig_LeftArm"
bone_idx = 8
@ -2980,7 +2987,7 @@ body_part = "Left Arm"
shape = SubResource("CapsuleShape3D_56i6t")
[node name="LeftForearmAttachment" type="BoneAttachment3D" parent="model/Body/Skeleton3D"]
transform = Transform3D(-3.49777e-06, 1, 1.58986e-07, -1, -3.42913e-06, 6.22795e-07, 6.55292e-07, -1.25458e-07, 1, 46.1625, -6.17155, -143.566)
transform = Transform3D(-3.46797e-06, 1, 1.58986e-07, -1, -3.39917e-06, 6.16277e-07, 6.49006e-07, -1.23596e-07, 1, 46.1625, -6.17155, -143.566)
bone_name = "mixamorig_LeftForeArm"
bone_idx = 9
@ -2995,7 +3002,7 @@ body_part = "Left Forearm"
shape = SubResource("CapsuleShape3D_1sjun")
[node name="LeftPalmAttachment" type="BoneAttachment3D" parent="model/Body/Skeleton3D"]
transform = Transform3D(-3.38808e-06, 1, -1.37357e-06, -1, -3.31944e-06, 3.93894e-07, 4.26386e-07, 1.40709e-06, 1, 73.777, -6.17164, -143.566)
transform = Transform3D(-3.35828e-06, 1, -1.37357e-06, -1, -3.28948e-06, 3.87377e-07, 4.201e-07, 1.40896e-06, 1, 73.777, -6.17164, -143.566)
bone_name = "mixamorig_LeftHand"
bone_idx = 10

File diff suppressed because one or more lines are too long

View File

@ -1,23 +1,25 @@
shader_type spatial;
render_mode cull_front, unshaded;
@shader_type spatial;
@render_mode unshaded;
uniform vec4 outline_color : source_color;
uniform float outline_width = 1.0;
void vertex() {
vec4 clip_position = PROJECTION_MATRIX * (MODELVIEW_MATRIX * vec4(VERTEX, 1.0));
vec3 clip_normal = mat3(PROJECTION_MATRIX) * (mat3(MODELVIEW_MATRIX) * NORMAL);
vec2 offset = normalize(clip_normal.xy) / VIEWPORT_SIZE * clip_position.w * outline_width * 2.0;
clip_position.xy += offset;
POSITION = clip_position;
}
@uniform sampler2D albedo_texture;
@uniform vec3 light_color = vec3(1.0, 1.0, 1.0);
@uniform float outline_width = 0.05;
@uniform vec3 outline_color = vec3(0.0, 0.0, 0.0);
void fragment() {
ALBEDO = outline_color.rgb;
if (outline_color.a < 1.0) {
ALPHA = outline_color.a;
}
}
// Fake directional light
vec3 light_dir = normalize(vec3(0.5, 1.0, -0.5));
vec3 norm = normalize(NORMAL);
float intensity = dot(norm, light_dir);
// Cel shading - Quantized lighting steps
float shade = step(0.1, intensity) * 0.3 +
step(0.3, intensity) * 0.4 +
step(0.6, intensity) * 0.3;
// Sample texture and apply shading
vec4 tex_color = texture(albedo_texture, UV);
vec3 final_color = tex_color.rgb * shade * light_color;
ALBEDO = final_color;
}

36
shaders/test.gdshader Normal file
View File

@ -0,0 +1,36 @@
shader_type spatial;
render_mode unshaded;
uniform vec4 light_color : source_color = vec4(1.0, 1.0, 1.0, 1.0);
uniform sampler2D albedo_texture;
uniform float outline_width = 0.05; // Thickness of outline
uniform vec4 outline_color : source_color = vec4(0.0, 0.0, 0.0, 1.0);
void vertex() {
// Expanding vertices along normals for outlines (inverted hull technique)
if (OUTLINE_PASS) {
VERTEX += NORMAL * outline_width;
}
}
void fragment() {
vec3 light_dir = normalize(vec3(0.5, 1.0, -0.5)); // Fake directional light
vec3 norm = normalize(NORMAL);
float intensity = dot(norm, light_dir);
// Cel shading (quantized lighting levels)
float shade = smoothstep(0.1, 0.3, intensity) * 0.5 +
smoothstep(0.3, 0.6, intensity) * 0.3 +
smoothstep(0.6, 1.0, intensity) * 0.2;
// Sample texture and apply shading
vec4 tex_color = texture(albedo_texture, UV);
vec3 final_color = tex_color.rgb * shade * light_color.rgb;
// Outline pass
if (OUTLINE_PASS) {
final_color = outline_color.rgb;
}
ALBEDO = final_color;
}