diff --git a/materials/tilables/water.material b/materials/tilables/water.material new file mode 100644 index 0000000..d816f51 --- /dev/null +++ b/materials/tilables/water.material @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:278af24434d59557b6fd8c38eb292a03bbe6f9e26349dcec426c575184bb48f9 +size 726 diff --git a/materials/tilables/water_fountain.material b/materials/tilables/water_fountain.material new file mode 100644 index 0000000..5059021 --- /dev/null +++ b/materials/tilables/water_fountain.material @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0c08c15da91a79537cad53a446d8b3c80e8d941a0dc2f85538304391cff4c69f +size 735 diff --git a/meshes/props/fountain_suzanha/Fountain_suzanha.tscn b/meshes/props/fountain_suzanha/Fountain_suzanha.tscn index 743a4aa..6b6c4a2 100644 --- a/meshes/props/fountain_suzanha/Fountain_suzanha.tscn +++ b/meshes/props/fountain_suzanha/Fountain_suzanha.tscn @@ -1,9 +1,12 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://meshes/props/fountain_suzanha/foutain_suzanha.escn" type="PackedScene" id=1] [ext_resource path="res://materials/tilables/suzahna_bricks.tres" type="Material" id=2] [ext_resource path="res://materials/tilables/suzahna_bricks_wide.tres" type="Material" id=3] [ext_resource path="res://materials/tilables/suzahna_base.tres" type="Material" id=4] +[ext_resource path="res://materials/tilables/water_fountain.material" type="Material" id=5] + +[sub_resource type="PlaneMesh" id=1] [node name="Fountain_suzanha" index="0" instance=ExtResource( 1 )] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.47228, 0 ) @@ -17,3 +20,7 @@ material/0 = ExtResource( 3 ) [node name="Fountain_suzanha_waterhole" parent="." index="2"] material/0 = ExtResource( 4 ) +[node name="water" type="MeshInstance" parent="." index="3"] +transform = Transform( 1.86, 0, 0, 0, 1, 0, 0, 0, 0.77, 0.0789185, 0.304244, 0 ) +mesh = SubResource( 1 ) +material/0 = ExtResource( 5 ) diff --git a/previewer/previewer.gd b/previewer/previewer.gd index 32db8cb..1a242c5 100644 --- a/previewer/previewer.gd +++ b/previewer/previewer.gd @@ -33,7 +33,7 @@ func _process( delta ): iTime+=delta iFrame+=1 - if (Engine.is_editor_hint() and $sky/viewport/sprite.editor_playing) or !Engine.is_editor_hint(): + if (Engine.is_editor_hint() and $sky/viewport/sprite.editor_clouds_playing) or !Engine.is_editor_hint(): emit_signal("time_frame_changed", iTime, iFrame) if Input.is_action_pressed("move_up"): diff --git a/previewer/previewer.tscn b/previewer/previewer.tscn index 0973eea..9105213 100644 --- a/previewer/previewer.tscn +++ b/previewer/previewer.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=22 format=2] +[gd_scene load_steps=24 format=2] [ext_resource path="res://previewer/previewer.gd" type="Script" id=1] [ext_resource path="res://shaders/sky.shader" type="Shader" id=2] @@ -6,11 +6,12 @@ [ext_resource path="res://previewer/dummy/dummy.tscn" type="PackedScene" id=4] [ext_resource path="res://textures/tilables/basic_texture_1024.png" type="Texture" id=5] [ext_resource path="res://meshes/decors/rocks/cliff_001.tscn" type="PackedScene" id=6] -[ext_resource path="res://meshes/props/pendo_teddy/pendo_teddy.tscn" type="PackedScene" id=7] -[ext_resource path="res://meshes/props/travel_box/container.tscn" type="PackedScene" id=8] -[ext_resource path="res://meshes/props/reference_box/reference_box.tscn" type="PackedScene" id=9] -[ext_resource path="res://meshes/props/fountain_suzanha/Fountain_suzanha.tscn" type="PackedScene" id=10] -[ext_resource path="res://previewer/settings.tscn" type="PackedScene" id=11] +[ext_resource path="res://materials/tilables/water.material" type="Material" id=7] +[ext_resource path="res://meshes/props/pendo_teddy/pendo_teddy.tscn" type="PackedScene" id=8] +[ext_resource path="res://meshes/props/travel_box/container.tscn" type="PackedScene" id=9] +[ext_resource path="res://meshes/props/reference_box/reference_box.tscn" type="PackedScene" id=10] +[ext_resource path="res://meshes/props/fountain_suzanha/Fountain_suzanha.tscn" type="PackedScene" id=11] +[ext_resource path="res://previewer/settings.tscn" type="PackedScene" id=12] [sub_resource type="OpenSimplexNoise" id=1] period = 8.0 @@ -23,8 +24,8 @@ noise = SubResource( 1 ) [sub_resource type="ShaderMaterial" id=3] shader = ExtResource( 2 ) -shader_param/iTime = 15.5758 -shader_param/iFrame = 1014 +shader_param/iTime = 452.999 +shader_param/iFrame = 20840 shader_param/COVERAGE = 0.5 shader_param/THICKNESS = 25.0 shader_param/ABSORPTION = 1.031 @@ -32,7 +33,7 @@ shader_param/STEPS = 25 shader_param/earth_radius_km = 6371.0 shader_param/atmo_radius_km = 6471.0 shader_param/cam_height_m = 1.8 -shader_param/sun_pos = Vector3( -11.462, 50, 85.8407 ) +shader_param/sun_pos = Vector3( -6.85618, 85.5364, 51.347 ) shader_param/sun_intensity = 42.0 shader_param/rayleigh_coeff = Vector3( 5.5, 13, 22.4 ) shader_param/mie_coeff = 21.0 @@ -68,7 +69,9 @@ uv1_scale = Vector3( 122, 122, 122 ) [sub_resource type="PlaneMesh" id=9] material = SubResource( 8 ) -[sub_resource type="GIProbeData" id=10] +[sub_resource type="PlaneMesh" id=10] + +[sub_resource type="GIProbeData" id=11] bounds = AABB( -63.192, -25, -76.323, 126.384, 50, 152.646 ) cell_size = 1.19255 to_cell_xform = Transform( 0.838542, 0, 0, 0, 0.838542, 0, 0, 0, 0.838542, 52.9891, 20.9635, 64 ) @@ -92,8 +95,8 @@ material = SubResource( 3 ) texture = SubResource( 4 ) centered = false script = ExtResource( 3 ) -editor_playing = true -sun_position = Vector3( -11.462, 50, 85.8407 ) +directional_light_node_path = NodePath("../../../light_system/directional_light") +sun_position = Vector3( -6.85618, 85.5364, 51.347 ) [node name="world_environment" type="WorldEnvironment" parent="."] environment = SubResource( 7 ) @@ -112,49 +115,54 @@ moss_height = 15.0 moss_fade = 2.5 moss_depth_min = 0.73 +[node name="water" type="MeshInstance" parent="terrain"] +transform = Transform( 22.72, 0, 0, 0, 1, 0, 0, 0, 18.77, -27.5637, 0.428694, -26.1742 ) +mesh = SubResource( 10 ) +material/0 = ExtResource( 7 ) + [node name="props" type="Spatial" parent="."] -[node name="pendo_teddy" parent="props" instance=ExtResource( 7 )] +[node name="pendo_teddy" parent="props" instance=ExtResource( 8 )] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -3 ) -[node name="container" parent="props" instance=ExtResource( 8 )] +[node name="container" parent="props" instance=ExtResource( 9 )] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -5 ) color = Color( 0.145098, 0.0980392, 0.713726, 1 ) lid_angle = 45.0 -[node name="container_2" parent="props" instance=ExtResource( 8 )] +[node name="container_2" parent="props" instance=ExtResource( 9 )] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1.24144, 0, -5 ) color = Color( 0.491686, 0.159256, 0.832031, 1 ) lid_angle = 90.0 -[node name="container_3" parent="props" instance=ExtResource( 8 )] +[node name="container_3" parent="props" instance=ExtResource( 9 )] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -2.6614, 0, -5 ) color = Color( 0.360784, 1, 0, 1 ) lid_angle = 12.0 -[node name="container_4" parent="props" instance=ExtResource( 8 )] +[node name="container_4" parent="props" instance=ExtResource( 9 )] transform = Transform( 0.457191, 0, 0.889369, 0, 1, 0, -0.889369, 0, 0.457191, -3.94754, 4.76837e-07, -4.27729 ) color = Color( 0.972549, 0.196078, 0.0431373, 1 ) lid_angle = 0.0 -[node name="reference_box" parent="props" instance=ExtResource( 9 )] +[node name="reference_box" parent="props" instance=ExtResource( 10 )] -[node name="Fountain_suzanha" parent="props" instance=ExtResource( 10 )] +[node name="Fountain_suzanha" parent="props" instance=ExtResource( 11 )] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 5, 0.472, -5 ) [node name="light_system" type="Spatial" parent="."] [node name="directional_light" type="DirectionalLight" parent="light_system"] -transform = Transform( 0.991203, 0.0661759, -0.11462, 0, 0.866025, 0.5, 0.132352, -0.495601, 0.858407, -11.462, 50, 85.8407 ) -light_energy = 0.333333 +transform = Transform( 0.991203, 0.113209, -0.0685618, 0, 0.518027, 0.855364, 0.132352, -0.84784, 0.51347, -6.85618, 85.5364, 51.347 ) +light_energy = 0.653333 shadow_enabled = true [node name="gi_probe" type="GIProbe" parent="light_system"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 21.7307, 0 ) extents = Vector3( 63.192, 25, 76.323 ) -data = SubResource( 10 ) +data = SubResource( 11 ) -[node name="settings" parent="." instance=ExtResource( 11 )] +[node name="settings" parent="." instance=ExtResource( 12 )] visible = true margin_left = -475.0 margin_top = -243.0 diff --git a/previewer/sky.gd b/previewer/sky.gd index 54cb55b..03ce753 100644 --- a/previewer/sky.gd +++ b/previewer/sky.gd @@ -1,11 +1,14 @@ tool extends Sprite -export(bool) var editor_playing = false +export(bool) var editor_clouds_playing = false +export(float, 0.0, 24.0) var day_time_hours = 12.0 setget set_day_time_hours + +export(NodePath) var directional_light_node_path func _ready(): if !Engine.is_editor_hint(): - editor_playing = true + editor_clouds_playing = true func _on_previewer_time_frame_changed(time, frame): self.material.set("shader_param/iTime", time) @@ -48,3 +51,7 @@ func set_time_of_day(hours, directional_light, horizontal_angle = 0.0): # and update our sky set_sun_position(sun_position) + +func set_day_time_hours(hours): + if directional_light_node_path: + set_time_of_day(hours, get_node(directional_light_node_path), 25.0) diff --git a/shaders/water.shader b/shaders/water.shader new file mode 100644 index 0000000..7e2f59b --- /dev/null +++ b/shaders/water.shader @@ -0,0 +1,183 @@ +/* +Realistic Water Shader for GODOT 3.1.1 + +Copyright (c) 2019 UnionBytes, Achim Menzel (alias AiYori) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this +software and associated documentation files (the "Software"), to deal in the Software +without restriction, including without limitation the rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +OR OTHER DEALINGS IN THE SOFTWARE. + +-- UnionBytes +-- YouTube: +*/ + + +// For this shader min. GODOT 3.1.1 is required, because 3.1 has a depth buffer bug! +shader_type spatial; +render_mode cull_back,diffuse_burley,specular_schlick_ggx, blend_mix; + + +// Wave settings: +uniform float wave_speed = 0.5; // Speed scale for the waves +uniform vec4 wave_a = vec4(1.0, 1.0, 0.35, 3.0); // xy = Direction, z = Steepness, w = Length +uniform vec4 wave_b = vec4(1.0, 0.6, 0.30, 1.55); // xy = Direction, z = Steepness, w = Length +uniform vec4 wave_c = vec4(1.0, 1.3, 0.25, 0.9); // xy = Direction, z = Steepness, w = Length + +// Surface settings: +uniform vec2 sampler_scale = vec2(0.25, 0.25); // Scale for the sampler +uniform vec2 sampler_direction= vec2(0.05, 0.04); // Direction and speed for the sampler offset + +uniform sampler2D uv_sampler : hint_aniso; // UV motion sampler for shifting the normalmap +uniform vec2 uv_sampler_scale = vec2(0.25, 0.25); // UV sampler scale +uniform float uv_sampler_strength = 0.04; // UV shifting strength + +uniform sampler2D normalmap_a_sampler : hint_normal; // Normalmap sampler A +uniform sampler2D normalmap_b_sampler : hint_normal; // Normalmap sampler B + +uniform sampler2D foam_sampler : hint_black; // Foam sampler +uniform float foam_level = 0.5; // Foam level -> distance from the object (0.0 - 0.5) + +// Volume settings: +uniform float refraction = 0.075; // Refraction of the water + +uniform vec4 color_deep : hint_color; // Color for deep places in the water, medium to dark blue +uniform vec4 color_shallow : hint_color; // Color for lower places in the water, bright blue - green +uniform float beers_law = 2.0; // Beers law value, regulates the blending size to the deep water level +uniform float depth_offset = -0.75; // Offset for the blending + +// Projector for the water caustics: +uniform mat4 projector; // Projector matrix, mostly the matric of the sun / directlight +uniform sampler2DArray caustic_sampler : hint_black; // Caustic sampler, (Texture array with 16 Textures for the animation) + + +// Vertex -> Fragment: +varying float vertex_height; // Height of the water surface +varying vec3 vertex_normal; // Vertex normal -> Needed for refraction calculation +varying vec3 vertex_binormal; // Vertex binormal -> Needed for refraction calculation +varying vec3 vertex_tangent; // Vertex tangent -> Needed for refraction calculation + +varying mat4 inv_mvp; // Inverse ModelViewProjection matrix -> Needed for caustic projection + + +// Wave function: +vec4 wave(vec4 parameter, vec2 position, float time, inout vec3 tangent, inout vec3 binormal) +{ + float wave_steepness = parameter.z; + float wave_length = parameter.w; + + float k = 2.0 * 3.14159265359 / wave_length; + float c = sqrt(9.8 / k); + vec2 d = normalize(parameter.xy); + float f = k * (dot(d, position) - c * time); + float a = wave_steepness / k; + + tangent += normalize(vec3(1.0-d.x * d.x * (wave_steepness * sin(f)), d.x * (wave_steepness * cos(f)), -d.x * d.y * (wave_steepness * sin(f)))); + binormal += normalize(vec3(-d.x * d.y * (wave_steepness * sin(f)), d.y * (wave_steepness * cos(f)), 1.0-d.y * d.y * (wave_steepness * sin(f)))); + + return vec4(d.x * (a * cos(f)), a * sin(f) * 0.25, d.y * (a * cos(f)), 0.0); +} + + +// Vertex shader: +void vertex() +{ + float time = TIME * wave_speed; + + vec4 vertex = vec4(VERTEX, 1.0); + vec3 vertex_position = (WORLD_MATRIX * vertex).xyz; + + vertex_tangent = vec3(0.0, 0.0, 0.0); + vertex_binormal = vec3(0.0, 0.0, 0.0); + + vertex += wave(wave_a, vertex_position.xz, time, vertex_tangent, vertex_binormal); + vertex += wave(wave_b, vertex_position.xz, time, vertex_tangent, vertex_binormal); + vertex += wave(wave_c, vertex_position.xz, time, vertex_tangent, vertex_binormal); + + vertex_position = vertex.xyz; + + vertex_height = (PROJECTION_MATRIX * MODELVIEW_MATRIX * vertex).z; + + TANGENT = vertex_tangent; + BINORMAL = vertex_binormal; + vertex_normal = normalize(cross(vertex_binormal, vertex_tangent)); + NORMAL = vertex_normal; + + UV = vertex.xz * sampler_scale; + + VERTEX = vertex.xyz; + + inv_mvp = inverse(PROJECTION_MATRIX * MODELVIEW_MATRIX); +} + + +// Fragment shader: +void fragment() +{ + // Calculation of the UV with the UV motion sampler + vec2 uv_offset = sampler_direction * TIME; + vec2 uv_sampler_uv = UV * uv_sampler_scale + uv_offset; + vec2 uv_sampler_uv_offset = uv_sampler_strength * texture(uv_sampler, uv_sampler_uv).rg * 2.0 - 1.0; + vec2 uv = UV + uv_sampler_uv_offset; + + // Normalmap: + vec3 normalmap = texture(normalmap_a_sampler, uv - uv_offset*2.0).rgb * 0.75; // 75 % sampler A + normalmap += texture(normalmap_b_sampler, uv + uv_offset).rgb * 0.25; // 25 % sampler B + + // Refraction UV: + vec3 ref_normalmap = normalmap * 2.0 - 1.0; + ref_normalmap = normalize(vertex_tangent*ref_normalmap.x + vertex_binormal*ref_normalmap.y + vertex_normal*ref_normalmap.z); + vec2 ref_uv = SCREEN_UV + (ref_normalmap.xy * refraction) / vertex_height; + + // Ground depth: + float depth_raw = texture(DEPTH_TEXTURE, ref_uv).r * 2.0 - 1.0; + float depth = PROJECTION_MATRIX[3][2] / (depth_raw + PROJECTION_MATRIX[2][2]); + + float depth_blend = exp((depth+VERTEX.z + depth_offset) * -beers_law); + depth_blend = clamp(1.0-depth_blend, 0.0, 1.0); + float depth_blend_pow = clamp(pow(depth_blend, 2.5), 0.0, 1.0); + + // Ground color: + vec3 screen_color = textureLod(SCREEN_TEXTURE, ref_uv, depth_blend_pow * 2.5).rgb; + + vec3 dye_color = mix(color_shallow.rgb, color_deep.rgb, depth_blend_pow); + vec3 color = mix(screen_color*dye_color, dye_color*0.25, depth_blend_pow*0.5); + + // Caustic screen projection + vec4 caustic_screenPos = vec4(ref_uv*2.0-1.0, depth_raw, 1.0); + vec4 caustic_localPos = inv_mvp * caustic_screenPos; + caustic_localPos = vec4(caustic_localPos.xyz/caustic_localPos.w, caustic_localPos.w); + + vec2 caustic_Uv = caustic_localPos.xz / vec2(1024.0) + 0.5; + vec4 caustic_color = texture(caustic_sampler, vec3(caustic_Uv*300.0, mod(TIME*14.0, 16.0))); + + color *= 1.0 + pow(caustic_color.r, 1.50) * (1.0-depth_blend) * 6.0; + + // Foam: + if(depth + VERTEX.z < foam_level && depth > vertex_height-0.1) + { + float foam_noise = clamp(pow(texture(foam_sampler, (uv*4.0) - uv_offset).r, 10.0)*40.0, 0.0, 0.2); + float foam_mix = clamp(pow((1.0-(depth + VERTEX.z) + foam_noise), 8.0) * foam_noise * 0.4, 0.0, 1.0); + color = mix(color, vec3(1.0), foam_mix); + } + + // Set all values: + ALBEDO = color; + METALLIC = 0.1; + ROUGHNESS = 0.2; + SPECULAR = 0.2 + depth_blend_pow * 0.4; + NORMALMAP = normalmap; + NORMALMAP_DEPTH = 1.25; +} diff --git a/textures/tilables/water/Caustic.png b/textures/tilables/water/Caustic.png new file mode 100644 index 0000000..e1cf7db Binary files /dev/null and b/textures/tilables/water/Caustic.png differ diff --git a/textures/tilables/water/Foam.png b/textures/tilables/water/Foam.png new file mode 100644 index 0000000..a499223 Binary files /dev/null and b/textures/tilables/water/Foam.png differ diff --git a/textures/tilables/water/Water_N_A.png b/textures/tilables/water/Water_N_A.png new file mode 100644 index 0000000..e4f59af Binary files /dev/null and b/textures/tilables/water/Water_N_A.png differ diff --git a/textures/tilables/water/Water_N_B.png b/textures/tilables/water/Water_N_B.png new file mode 100644 index 0000000..2c64fbd Binary files /dev/null and b/textures/tilables/water/Water_N_B.png differ diff --git a/textures/tilables/water/Water_UV.png b/textures/tilables/water/Water_UV.png new file mode 100644 index 0000000..74ad47a Binary files /dev/null and b/textures/tilables/water/Water_UV.png differ