Improvements on alpha stippling

This commit is contained in:
Rodolphe Houdas 2023-01-11 09:05:14 +00:00
parent 0c5e0aca68
commit 0f1ba4a6e2
5 changed files with 86 additions and 21 deletions

View File

@ -3,5 +3,7 @@
[ext_resource type="Shader" path="res://shaders/AlphaStippling.gdshader" id="1_c3b51"]
[resource]
render_priority = 0
render_priority = 3
shader = ExtResource("1_c3b51")
shader_parameter/max_distance = null
shader_parameter/min_distance = null

View File

@ -0,0 +1,18 @@
[gd_resource type="ShaderMaterial" load_steps=5 format=3 uid="uid://dovtliytbew0m"]
[ext_resource type="Material" uid="uid://dych1ros5vlo0" path="res://materials/AlphaStippling.tres" id="1_q5qkg"]
[ext_resource type="Shader" path="res://shaders/soap.gdshader" id="2_dufay"]
[ext_resource type="Texture2D" uid="uid://2i2g7306xmrh" path="res://textures/Soap.png" id="3_x3r58"]
[ext_resource type="Texture2D" uid="uid://dxcmick7pytlf" path="res://noise.tres" id="4_wrx6j"]
[resource]
render_priority = 0
next_pass = ExtResource("1_q5qkg")
shader = ExtResource("2_dufay")
shader_parameter/thickness = 500.0
shader_parameter/alpha = 0.35
shader_parameter/metallic = 1.0
shader_parameter/roughness = 0.6
shader_parameter/gravity_strength = 350.0
shader_parameter/gradient = ExtResource("3_x3r58")
shader_parameter/noise = ExtResource("4_wrx6j")

View File

@ -1,7 +1,9 @@
[gd_scene load_steps=7 format=3 uid="uid://j55y525enak6"]
[gd_scene load_steps=9 format=3 uid="uid://j55y525enak6"]
[ext_resource type="Script" path="res://FreeLookCamera.gd" id="1_5u6fq"]
[ext_resource type="Material" uid="uid://dovtliytbew0m" path="res://materials/soap_plus_alphastippling.tres" id="2_2n3rb"]
[ext_resource type="Material" uid="uid://dych1ros5vlo0" path="res://materials/AlphaStippling.tres" id="2_nry4q"]
[ext_resource type="Script" path="res://scripts/SinMove.gd" id="3_lbskv"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_4og27"]
sky_top_color = Color(0.411765, 0.372549, 0.811765, 1)
@ -16,10 +18,7 @@ sky_material = SubResource("ProceduralSkyMaterial_4og27")
background_mode = 2
sky = SubResource("Sky_ih2eo")
[sub_resource type="BoxMesh" id="BoxMesh_4sjiu"]
subdivide_width = 100
subdivide_height = 100
subdivide_depth = 100
[sub_resource type="SphereMesh" id="SphereMesh_sr0y4"]
[node name="AlphaStippling" type="Node3D"]
@ -30,29 +29,49 @@ environment = SubResource("Environment_g4rrm")
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)
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, 0)
script = ExtResource("1_5u6fq")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
material_override = ExtResource("2_nry4q")
mesh = SubResource("BoxMesh_4sjiu")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.68653, 0, 0)
material_override = ExtResource("2_2n3rb")
mesh = SubResource("SphereMesh_sr0y4")
surface_material_override/0 = ExtResource("2_nry4q")
script = ExtResource("3_lbskv")
speed = 0.1
[node name="MeshInstance3D2" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1.35595)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.99634, 0, 1.35595)
material_override = ExtResource("2_nry4q")
mesh = SubResource("BoxMesh_4sjiu")
mesh = SubResource("SphereMesh_sr0y4")
surface_material_override/0 = ExtResource("2_nry4q")
script = ExtResource("3_lbskv")
phase = 0.628
speed = 0.1
[node name="MeshInstance3D3" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 2.58446)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.54308, 0, 2.58446)
material_override = ExtResource("2_nry4q")
mesh = SubResource("BoxMesh_4sjiu")
mesh = SubResource("SphereMesh_sr0y4")
surface_material_override/0 = ExtResource("2_nry4q")
script = ExtResource("3_lbskv")
phase = 1.257
speed = 0.1
[node name="MeshInstance3D4" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3.81592)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.501123, 0, 3.81592)
material_override = ExtResource("2_nry4q")
mesh = SubResource("BoxMesh_4sjiu")
mesh = SubResource("SphereMesh_sr0y4")
surface_material_override/0 = ExtResource("2_nry4q")
script = ExtResource("3_lbskv")
phase = 1.885
speed = 0.1
[node name="MeshInstance3D5" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 5.04877)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.68653, 0, 5.04877)
material_override = ExtResource("2_nry4q")
mesh = SubResource("BoxMesh_4sjiu")
mesh = SubResource("SphereMesh_sr0y4")
surface_material_override/0 = ExtResource("2_nry4q")
script = ExtResource("3_lbskv")
phase = 3.14159
speed = 0.1

20
scripts/SinMove.gd Normal file
View File

@ -0,0 +1,20 @@
@tool
extends Node
var total_time : float = 0
@export_range(0, PI) var phase : float = 0
@export_range(0, 5) var speed : float = 1.0
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
total_time += delta
var sig : float = sin((total_time * speed) + phase) * 2
self.position.x = sig

View File

@ -1,4 +1,8 @@
shader_type spatial;
render_mode depth_prepass_alpha;
uniform float max_distance = 2.0;
uniform float min_distance = 1.0;
void fragment() {
mat4 thresholdMatrix = mat4(
@ -8,17 +12,19 @@ void fragment() {
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);
if (dist < max_distance) {
int x = int(FRAGCOORD.x * 0.5);
int y = int(FRAGCOORD.y * 0.5);
float threshold = float(thresholdMatrix[x % 4][y % 4]) / 17.0;
//ALBEDO.r = threshold;
if (dist - threshold < 1.0) {
if (dist - threshold < 0.5) {
discard;
}
}
//ALBEDO = vec3(dist - 1.0);
//ALBEDO = COLOR.rgb;
//ALPHA = COLOR.a;
}