Added water shader

This commit is contained in:
Eduard Urbach 2024-02-08 23:46:03 +01:00
parent d36de18b3c
commit 03d271e87c
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
6 changed files with 118 additions and 7 deletions

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=25 format=3 uid="uid://b40y7iuskv1ar"]
[gd_scene load_steps=26 format=3 uid="uid://b40y7iuskv1ar"]
[ext_resource type="Script" path="res://Main.gd" id="1_cw3ws"]
[ext_resource type="Script" path="res://network/Client.gd" id="2_8hxcx"]
@ -18,9 +18,10 @@
[ext_resource type="PackedScene" uid="uid://cb2t7bvvf3gwh" path="res://enemy/slime/Slime.tscn" id="15_hgl78"]
[ext_resource type="Script" path="res://world/PlayerManager.gd" id="16_dp6bj"]
[ext_resource type="PackedScene" uid="uid://dagn5bf7ou3sd" path="res://ui/UI.tscn" id="17_43qhq"]
[ext_resource type="Material" uid="uid://bdsblfaxbipaa" path="res://world/grass/grass_material.tres" id="18_tja64"]
[ext_resource type="Material" uid="uid://bdsblfaxbipaa" path="res://world/grass/GrassMaterial.tres" id="18_tja64"]
[ext_resource type="Script" path="res://camera/Camera.gd" id="18_wogcj"]
[ext_resource type="MultiMesh" uid="uid://dog5aq5n2q025" path="res://assets/grass/grass.multimesh" id="19_ae26a"]
[ext_resource type="PackedScene" uid="uid://cm0rho6adv2p7" path="res://world/water/Water.tscn" id="20_bmo3k"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_he5c5"]
diffuse_mode = 3
@ -137,6 +138,11 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 7.00829, 1.28057, -1.95247)
[node name="Slime3" parent="World/Enemies" instance=ExtResource("15_hgl78")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8.53558, 1.28057, -0.306177)
[node name="Grass" type="MultiMeshInstance3D" parent="World"]
material_override = ExtResource("18_tja64")
cast_shadow = 0
multimesh = ExtResource("19_ae26a")
[node name="Floor" type="MeshInstance3D" parent="World"]
mesh = SubResource("PlaneMesh_lb6xk")
@ -146,10 +152,38 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.5, 0)
[node name="CollisionShape3D" type="CollisionShape3D" parent="World/Floor/StaticBody3D"]
shape = SubResource("BoxShape3D_yg2lt")
[node name="Grass" type="MultiMeshInstance3D" parent="World"]
material_override = ExtResource("18_tja64")
cast_shadow = 0
multimesh = ExtResource("19_ae26a")
[node name="Ocean" type="Node3D" parent="World"]
[node name="Water" parent="World/Ocean" instance=ExtResource("20_bmo3k")]
skeleton = NodePath("../..")
[node name="Water2" parent="World/Ocean" instance=ExtResource("20_bmo3k")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 25, 0, 25)
skeleton = NodePath("../..")
[node name="Water3" parent="World/Ocean" instance=ExtResource("20_bmo3k")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 25)
skeleton = NodePath("../..")
[node name="Water4" parent="World/Ocean" instance=ExtResource("20_bmo3k")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -25, 0, 25)
skeleton = NodePath("../..")
[node name="Water5" parent="World/Ocean" instance=ExtResource("20_bmo3k")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -25, 0, 0)
skeleton = NodePath("../..")
[node name="Water6" parent="World/Ocean" instance=ExtResource("20_bmo3k")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -25, 0, -25)
skeleton = NodePath("../..")
[node name="Water7" parent="World/Ocean" instance=ExtResource("20_bmo3k")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -25)
skeleton = NodePath("../..")
[node name="Water8" parent="World/Ocean" instance=ExtResource("20_bmo3k")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 25, 0, -25)
skeleton = NodePath("../..")
[node name="Players" type="Node3D" parent="."]
unique_name_in_owner = true

View File

@ -1,6 +1,6 @@
[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://bdsblfaxbipaa"]
[ext_resource type="Shader" path="res://world/grass/grass_shader.gdshader" id="1_7qi6v"]
[ext_resource type="Shader" path="res://world/grass/Grass.gdshader" id="1_7qi6v"]
[resource]
render_priority = 0

View File

@ -0,0 +1,36 @@
shader_type spatial;
render_mode cull_disabled;
render_mode specular_toon;
// render_mode wireframe;
uniform vec3 color : source_color = vec3(0.055, 0.286, 0.62);
uniform vec3 fresnel_color : source_color = vec3(0.141, 0.447, 0.902);
uniform float fresnel_reduction = 5.0;
uniform float roughness : hint_range(0.0, 1.0) = 0.02;
uniform sampler2D height_map;
uniform sampler2D normal_map;
uniform float height_scale = 0.0;
uniform float noise_scale = 0.5;
varying vec2 noise_position;
float get_fresnel(float power, vec3 normal, vec3 view) {
return pow((1.0 - clamp(dot(normalize(normal), normalize(view)), 0.0, 1.0)), power);
}
void vertex() {
noise_position = VERTEX.xz * noise_scale + 0.5;
float height = texture(height_map, noise_position).x - 0.5;
VERTEX.y += height * height_scale;
}
void fragment() {
// NORMAL_MAP = texture(normal_map, UV).rgb;
NORMAL_MAP = texture(normal_map, noise_position).xyz;
float fresnel = get_fresnel(fresnel_reduction, NORMAL, VIEW);
RIM = 0.2;
METALLIC = 0.0;
ROUGHNESS = roughness * fresnel;
ALBEDO = mix(color, fresnel_color, fresnel);
}

View File

@ -0,0 +1,30 @@
[gd_resource type="ShaderMaterial" load_steps=6 format=3 uid="uid://c6kk0k4jvuh4q"]
[ext_resource type="Shader" path="res://world/water/Water.gdshader" id="1_uj7oj"]
[sub_resource type="FastNoiseLite" id="FastNoiseLite_f06x4"]
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_7t3c8"]
noise = SubResource("FastNoiseLite_f06x4")
[sub_resource type="FastNoiseLite" id="FastNoiseLite_d0hd3"]
noise_type = 3
fractal_type = 2
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_rcc52"]
seamless = true
as_normal_map = true
bump_strength = 1.5
noise = SubResource("FastNoiseLite_d0hd3")
[resource]
render_priority = 0
shader = ExtResource("1_uj7oj")
shader_parameter/color = Color(0.054902, 0.286275, 0.619608, 1)
shader_parameter/fresnel_color = Color(0.141176, 0.447059, 0.901961, 1)
shader_parameter/fresnel_reduction = 5.0
shader_parameter/roughness = 0.02
shader_parameter/height_scale = 0.0
shader_parameter/noise_scale = 0.5
shader_parameter/height_map = SubResource("NoiseTexture2D_7t3c8")
shader_parameter/normal_map = SubResource("NoiseTexture2D_rcc52")

View File

@ -0,0 +1,11 @@
[gd_scene load_steps=3 format=3 uid="uid://cm0rho6adv2p7"]
[ext_resource type="Material" uid="uid://c6kk0k4jvuh4q" path="res://world/water/Water.tres" id="1_yiqgh"]
[sub_resource type="PlaneMesh" id="PlaneMesh_cybb0"]
material = ExtResource("1_yiqgh")
size = Vector2(25, 25)
[node name="Water" type="MeshInstance3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 25, 0, 0)
mesh = SubResource("PlaneMesh_cybb0")