From 19847bd56c4e1d42db111c8be5820ffd95c0b007 Mon Sep 17 00:00:00 2001 From: Victor Turgeon Date: Sun, 11 Jun 2023 10:44:54 -0400 Subject: [PATCH] some environnement and water stuff --- README.md | 1 + levels/test_level.tscn | 46 ++++++++++++++++++++++++++++++++++++-- shaders/water.gdshader | 33 +++++++++++++++++++++++++++ shaders/water_plane.tscn | 48 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 shaders/water.gdshader create mode 100644 shaders/water_plane.tscn diff --git a/README.md b/README.md index fff324d..950177d 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ # Sources ## Tutorials - https://www.youtube.com/watch?v=VjuyfBaryu8 +- https://www.youtube.com/watch?v=7L6ZUYj1hs8 ## 3d Assets - https://ace-spectre.itch.io/ps1-heavy-and-light-weapons-pack diff --git a/levels/test_level.tscn b/levels/test_level.tscn index 8fd55fa..99dac84 100644 --- a/levels/test_level.tscn +++ b/levels/test_level.tscn @@ -1,7 +1,35 @@ -[gd_scene load_steps=3 format=3 uid="uid://cbs0x36e3ranm"] +[gd_scene load_steps=6 format=3 uid="uid://cbs0x36e3ranm"] [ext_resource type="MeshLibrary" uid="uid://dwo1m72yajrb1" path="res://assets/tilesets/tileset.tres" id="1_l447d"] [ext_resource type="PackedScene" uid="uid://b5gb5paiupum" path="res://player/player.tscn" id="2_ojnju"] +[ext_resource type="PackedScene" uid="uid://c2casdi4d2o3j" path="res://shaders/water_plane.tscn" id="3_ga7wg"] + +[sub_resource type="Environment" id="Environment_i4emf"] +ambient_light_source = 3 +ambient_light_color = Color(0.54902, 0.815686, 0.964706, 1) +ssao_radius = 11.01 +sdfgi_enabled = true +sdfgi_use_occlusion = true +sdfgi_bounce_feedback = 0.56 +glow_intensity = 1.69 +fog_enabled = true +fog_light_color = Color(0.294118, 0.439216, 0.411765, 1) +fog_light_energy = 0.8 +fog_density = 0.005 +fog_height = -1.0 +fog_height_density = 0.5 +volumetric_fog_enabled = true +volumetric_fog_density = 0.005 +volumetric_fog_albedo = Color(0.780392, 0.996078, 1, 1) +volumetric_fog_emission = Color(0.360784, 0.290196, 0.0862745, 1) +volumetric_fog_anisotropy = 0.05 +volumetric_fog_detail_spread = 1.68179 +adjustment_enabled = true +adjustment_brightness = 1.1 +adjustment_contrast = 1.25 +adjustment_saturation = 0.8 + +[sub_resource type="CameraAttributesPhysical" id="CameraAttributesPhysical_rja1c"] [node name="test_level" type="Node3D"] @@ -16,5 +44,19 @@ data = { metadata/_editor_floor_ = Vector3(0, 0, 0) [node name="player" parent="." instance=ExtResource("2_ojnju")] -transform = Transform3D(1, 0, 0, 0, 0.388867, 0.921294, 0, -0.921294, 0.388867, -1.19974, 40.1006, 13.3341) +transform = Transform3D(1, 0, 0, 0, 0.494109, 0.8694, 0, -0.8694, 0.494109, -3.70665, 40.1006, 20.9216) current = true + +[node name="water_plane" parent="." instance=ExtResource("3_ga7wg")] +transform = Transform3D(227.061, 0, -196.07, 0, 300, 0, 196.07, 0, 227.061, 0, 0.257405, 0) + +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] +transform = Transform3D(0.175911, -0.891337, 0.41782, 0.878449, 0.333691, 0.34202, -0.444278, 0.306869, 0.841694, 0, 3.35555, 0) +light_energy = 2.1 +light_indirect_energy = 0.863 +light_volumetric_fog_energy = 1.74 +light_angular_distance = 5.2 + +[node name="WorldEnvironment" type="WorldEnvironment" parent="."] +environment = SubResource("Environment_i4emf") +camera_attributes = SubResource("CameraAttributesPhysical_rja1c") diff --git a/shaders/water.gdshader b/shaders/water.gdshader new file mode 100644 index 0000000..91d4c35 --- /dev/null +++ b/shaders/water.gdshader @@ -0,0 +1,33 @@ +shader_type spatial; + +uniform vec3 albedo : source_color; +uniform vec3 albedo2 : source_color; +uniform float metallic : hint_range(0.0,1.0) = 0; +uniform float roughness : hint_range(0.0,1.0)=0.02; +uniform sampler2D texture_normal; +uniform sampler2D texture_normal2; +uniform sampler2D texture_image; +uniform vec2 wave_direction = vec2(2.0,0.0); +uniform vec2 wave_direction2 = vec2(0.0,1.0); +uniform float time_scale : hint_range(0.0, 0.2, 0.005) = 0.005; + +float fresnel(float amount, vec3 normal, vec3 view){ + return pow((1.0 - clamp(dot(normalize(normal), normalize(view)),0.0,1.0)),amount); +} + +void fragment() { + vec2 time = (TIME * wave_direction) * time_scale; + vec2 time2 = (TIME * wave_direction2) * time_scale; + + vec3 normal_blend = mix(texture(texture_normal, UV + time).rgb, texture(texture_normal2, UV + time2).rgb, 0.5); + + float fresnel = fresnel(5.0, NORMAL, VIEW); + vec3 surface_color = mix(albedo, albedo2, fresnel); + vec3 surface_texture = mix(surface_color, texture(texture_image, UV + time).rgb, 0.2); + + ALBEDO = surface_texture; + METALLIC = metallic; + ROUGHNESS = roughness; + NORMAL_MAP = normal_blend; + ALPHA = 0.8; +} diff --git a/shaders/water_plane.tscn b/shaders/water_plane.tscn new file mode 100644 index 0000000..9d8feb9 --- /dev/null +++ b/shaders/water_plane.tscn @@ -0,0 +1,48 @@ +[gd_scene load_steps=9 format=3 uid="uid://c2casdi4d2o3j"] + +[ext_resource type="Shader" path="res://shaders/water.gdshader" id="1_yfj5n"] +[ext_resource type="Texture2D" uid="uid://bsw8l5crn3aid" path="res://assets/textures/water.png" id="2_83coh"] + +[sub_resource type="QuadMesh" id="QuadMesh_x322w"] +subdivide_width = 200 +subdivide_depth = 200 +orientation = 1 + +[sub_resource type="FastNoiseLite" id="FastNoiseLite_ido7w"] +noise_type = 3 +fractal_type = 2 + +[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_ntr7e"] +seamless = true +as_normal_map = true +bump_strength = 1.5 +noise = SubResource("FastNoiseLite_ido7w") + +[sub_resource type="FastNoiseLite" id="FastNoiseLite_bfpu3"] +noise_type = 3 +seed = 69 +fractal_type = 2 + +[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_wvpl0"] +seamless = true +as_normal_map = true +bump_strength = 1.5 +noise = SubResource("FastNoiseLite_bfpu3") + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_yma05"] +render_priority = 0 +shader = ExtResource("1_yfj5n") +shader_parameter/albedo = Color(0.101961, 0.0509804, 0.431373, 1) +shader_parameter/albedo2 = Color(0.658824, 0.905882, 0.929412, 1) +shader_parameter/metallic = 0.0 +shader_parameter/roughness = 0.02 +shader_parameter/wave_direction = Vector2(2, 0) +shader_parameter/wave_direction2 = Vector2(0, 1) +shader_parameter/time_scale = 0.025 +shader_parameter/texture_normal = SubResource("NoiseTexture2D_ntr7e") +shader_parameter/texture_normal2 = SubResource("NoiseTexture2D_wvpl0") +shader_parameter/texture_image = ExtResource("2_83coh") + +[node name="water_plane" type="MeshInstance3D"] +mesh = SubResource("QuadMesh_x322w") +surface_material_override/0 = SubResource("ShaderMaterial_yma05")