Add Alpha stippling shader

This commit is contained in:
Rodolphe Houdas 2023-01-10 17:53:51 +00:00
parent 26c3e70aa5
commit 0c5e0aca68
3 changed files with 89 additions and 0 deletions

View file

@ -0,0 +1,7 @@
[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://dych1ros5vlo0"]
[ext_resource type="Shader" path="res://shaders/AlphaStippling.gdshader" id="1_c3b51"]
[resource]
render_priority = 0
shader = ExtResource("1_c3b51")

View file

@ -0,0 +1,58 @@
[gd_scene load_steps=7 format=3 uid="uid://j55y525enak6"]
[ext_resource type="Script" path="res://FreeLookCamera.gd" id="1_5u6fq"]
[ext_resource type="Material" uid="uid://dych1ros5vlo0" path="res://materials/AlphaStippling.tres" id="2_nry4q"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_4og27"]
sky_top_color = Color(0.411765, 0.372549, 0.811765, 1)
sky_horizon_color = Color(0.811765, 0.588235, 0.584314, 1)
ground_bottom_color = Color(0.25098, 0.121569, 0.215686, 1)
ground_horizon_color = Color(0.796078, 0.580392, 0.701961, 1)
[sub_resource type="Sky" id="Sky_ih2eo"]
sky_material = SubResource("ProceduralSkyMaterial_4og27")
[sub_resource type="Environment" id="Environment_g4rrm"]
background_mode = 2
sky = SubResource("Sky_ih2eo")
[sub_resource type="BoxMesh" id="BoxMesh_4sjiu"]
subdivide_width = 100
subdivide_height = 100
subdivide_depth = 100
[node name="AlphaStippling" type="Node3D"]
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_g4rrm")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.459177, 0.888345, 0, -0.888345, 0.459177, 0, 2.002, 1.79264)
[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.128473, 0, 0)
script = ExtResource("1_5u6fq")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
material_override = ExtResource("2_nry4q")
mesh = SubResource("BoxMesh_4sjiu")
[node name="MeshInstance3D2" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1.35595)
material_override = ExtResource("2_nry4q")
mesh = SubResource("BoxMesh_4sjiu")
[node name="MeshInstance3D3" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 2.58446)
material_override = ExtResource("2_nry4q")
mesh = SubResource("BoxMesh_4sjiu")
[node name="MeshInstance3D4" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3.81592)
material_override = ExtResource("2_nry4q")
mesh = SubResource("BoxMesh_4sjiu")
[node name="MeshInstance3D5" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 5.04877)
material_override = ExtResource("2_nry4q")
mesh = SubResource("BoxMesh_4sjiu")

View file

@ -0,0 +1,24 @@
shader_type spatial;
void fragment() {
mat4 thresholdMatrix = mat4(
vec4(1, 9, 3, 11),
vec4(13, 5, 15, 7),
vec4(4, 12, 2, 10),
vec4(16, 8, 14, 6)
);
float dist = length(NODE_POSITION_WORLD - CAMERA_POSITION_WORLD);
if (dist < 2.0) {
int x = int(FRAGCOORD.x);
int y = int(FRAGCOORD.y);
float threshold = float(thresholdMatrix[x % 4][y % 4]) / 17.0;
//ALBEDO.r = threshold;
if (dist - threshold < 1.0) {
discard;
}
}
//ALBEDO = vec3(dist - 1.0);
}