aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Gone2Daly <71726742+Gone2Daly@users.noreply.github.com>2023-04-15 01:13:52 +0200
committer Gone2Daly <71726742+Gone2Daly@users.noreply.github.com>2023-04-15 01:13:52 +0200
commit8e4eedf5e25237c514bd19d2a6c42ad9e00ec1a6 (patch)
tree4da70d8887d32d4c3e03fb039f66f5488304bcbb
parent5ed64dd74b9d3dcdb884cf8f5668e5a9d7423901 (diff)
First try at 3d map3d-terrain
-rw-r--r--game/art/terrain/Basemap.pngbin0 -> 594760 bytes
-rw-r--r--game/art/terrain/Basemap.png.import35
-rw-r--r--game/art/terrain/Height.pngbin0 -> 1073803 bytes
-rw-r--r--game/art/terrain/Height.png.import35
-rw-r--r--game/src/GameSession/GameSession.tscn23
-rw-r--r--game/src/GameSession/MapView.gd2
-rw-r--r--game/src/GameSession/MapView.tscn23
-rw-r--r--game/src/GameSession/TerrainMap.gdshader14
-rw-r--r--game/src/GameSession/Water/Water.gdshader82
-rw-r--r--game/src/GameSession/Water/Water.tres34
-rw-r--r--game/src/GameSession/Water/WaterPlane.tscn12
-rw-r--r--game/src/GameSession/Water/WaterPlaneNormal.tres13
m---------godot-cpp0
13 files changed, 267 insertions, 6 deletions
diff --git a/game/art/terrain/Basemap.png b/game/art/terrain/Basemap.png
new file mode 100644
index 0000000..fb536f7
--- /dev/null
+++ b/game/art/terrain/Basemap.png
Binary files differ
diff --git a/game/art/terrain/Basemap.png.import b/game/art/terrain/Basemap.png.import
new file mode 100644
index 0000000..b299d62
--- /dev/null
+++ b/game/art/terrain/Basemap.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://dw3sykhcyw2v7"
+path.s3tc="res://.godot/imported/Basemap.png-d53ade5aa5c4b8ccee40e0cc43bf0fda.s3tc.ctex"
+metadata={
+"imported_formats": ["s3tc_bptc"],
+"vram_texture": true
+}
+
+[deps]
+
+source_file="res://art/terrain/Basemap.png"
+dest_files=["res://.godot/imported/Basemap.png-d53ade5aa5c4b8ccee40e0cc43bf0fda.s3tc.ctex"]
+
+[params]
+
+compress/mode=2
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=true
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=0
diff --git a/game/art/terrain/Height.png b/game/art/terrain/Height.png
new file mode 100644
index 0000000..798318b
--- /dev/null
+++ b/game/art/terrain/Height.png
Binary files differ
diff --git a/game/art/terrain/Height.png.import b/game/art/terrain/Height.png.import
new file mode 100644
index 0000000..ff68906
--- /dev/null
+++ b/game/art/terrain/Height.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://bds8jrlnde3mm"
+path.s3tc="res://.godot/imported/Height.png-2ea003a31795ddcac3a7f74d638eb139.s3tc.ctex"
+metadata={
+"imported_formats": ["s3tc_bptc"],
+"vram_texture": true
+}
+
+[deps]
+
+source_file="res://art/terrain/Height.png"
+dest_files=["res://.godot/imported/Height.png-2ea003a31795ddcac3a7f74d638eb139.s3tc.ctex"]
+
+[params]
+
+compress/mode=2
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=true
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=0
diff --git a/game/src/GameSession/GameSession.tscn b/game/src/GameSession/GameSession.tscn
index e270f8a..5e2cc3b 100644
--- a/game/src/GameSession/GameSession.tscn
+++ b/game/src/GameSession/GameSession.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=6 format=3 uid="uid://bgnupcshe1m7r"]
+[gd_scene load_steps=10 format=3 uid="uid://bgnupcshe1m7r"]
[ext_resource type="Script" path="res://src/GameSession/GameSession.gd" id="1_eklvp"]
[ext_resource type="PackedScene" uid="uid://g524p8lr574w" path="res://src/GameSession/MapControlPanel.tscn" id="3_afh6d"]
@@ -6,11 +6,32 @@
[ext_resource type="PackedScene" uid="uid://dkehmdnuxih2r" path="res://src/GameSession/MapView.tscn" id="4_xkg5j"]
[ext_resource type="PackedScene" uid="uid://byq323jbel48u" path="res://src/GameSession/ProvinceOverviewPanel.tscn" id="5_osjnn"]
+[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_8qaci"]
+
+[sub_resource type="Sky" id="Sky_w8b4m"]
+sky_material = SubResource("ProceduralSkyMaterial_8qaci")
+
+[sub_resource type="Environment" id="Environment_wam0l"]
+background_mode = 2
+sky = SubResource("Sky_w8b4m")
+tonemap_mode = 3
+sdfgi_enabled = true
+sdfgi_use_occlusion = true
+fog_enabled = true
+fog_light_color = Color(0.466667, 0.541176, 0.607843, 1)
+
+[sub_resource type="CameraAttributesPractical" id="CameraAttributesPractical_foqwj"]
+dof_blur_far_distance = 8192.0
+
[node name="GameSession" type="Node" node_paths=PackedStringArray("_game_session_menu")]
editor_description = "SS-102, UI-546"
script = ExtResource("1_eklvp")
_game_session_menu = NodePath("GameSessionMenu")
+[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
+environment = SubResource("Environment_wam0l")
+camera_attributes = SubResource("CameraAttributesPractical_foqwj")
+
[node name="MapView" parent="." instance=ExtResource("4_xkg5j")]
[node name="GameSessionMenu" parent="." instance=ExtResource("3_bvmqh")]
diff --git a/game/src/GameSession/MapView.gd b/game/src/GameSession/MapView.gd
index 54d8df8..857365b 100644
--- a/game/src/GameSession/MapView.gd
+++ b/game/src/GameSession/MapView.gd
@@ -254,4 +254,4 @@ func _on_minimap_clicked(pos_clicked : Vector2):
pos_clicked *= _map_mesh_dims
_camera.position.x = pos_clicked.x
_camera.position.z = pos_clicked.y
- _clamp_over_map() \ No newline at end of file
+ _clamp_over_map()
diff --git a/game/src/GameSession/MapView.tscn b/game/src/GameSession/MapView.tscn
index 93fc162..40b43de 100644
--- a/game/src/GameSession/MapView.tscn
+++ b/game/src/GameSession/MapView.tscn
@@ -1,17 +1,30 @@
-[gd_scene load_steps=6 format=3 uid="uid://dkehmdnuxih2r"]
+[gd_scene load_steps=10 format=3 uid="uid://dkehmdnuxih2r"]
[ext_resource type="Script" path="res://src/GameSession/MapView.gd" id="1_exccw"]
[ext_resource type="Shader" path="res://src/GameSession/TerrainMap.gdshader" id="1_upocn"]
-[ext_resource type="Texture2D" uid="uid://cmw0pvjthnn8c" path="res://art/terrain/terrain.png" id="3_l8pnf"]
+[ext_resource type="Texture2D" uid="uid://dw3sykhcyw2v7" path="res://art/terrain/Basemap.png" id="3_tw3yw"]
+[ext_resource type="Texture2D" uid="uid://bds8jrlnde3mm" path="res://art/terrain/Height.png" id="4_2d2pi"]
+[ext_resource type="Texture2D" uid="uid://cmw0pvjthnn8c" path="res://art/terrain/terrain.png" id="4_eahcr"]
+[ext_resource type="PackedScene" uid="uid://b35mxcc3d74di" path="res://src/GameSession/Water/WaterPlane.tscn" id="6_b5h2h"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_tayeg"]
render_priority = 0
shader = ExtResource("1_upocn")
shader_parameter/hover_index = null
shader_parameter/selected_index = null
-shader_parameter/terrain_tex = ExtResource("3_l8pnf")
+shader_parameter/height_ratio = 0.014
+shader_parameter/base_ratio = 0.01
+shader_parameter/terrain_tex = ExtResource("4_eahcr")
+shader_parameter/basemap = ExtResource("3_tw3yw")
+shader_parameter/heightmap = ExtResource("4_2d2pi")
[sub_resource type="MapMesh" id="MapMesh_3gtsd"]
+subdivide_width = 1500
+subdivide_depth = 750
+
+[sub_resource type="QuadMesh" id="QuadMesh_f5kgg"]
+size = Vector2(40, 10)
+orientation = 1
[node name="MapView" type="Node3D" node_paths=PackedStringArray("_camera", "_map_mesh_instance")]
editor_description = "SS-73"
@@ -27,3 +40,7 @@ editor_description = "FS-343"
transform = Transform3D(10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0)
material_override = SubResource("ShaderMaterial_tayeg")
mesh = SubResource("MapMesh_3gtsd")
+
+[node name="Water" parent="." instance=ExtResource("6_b5h2h")]
+transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.08, 0)
+mesh = SubResource("QuadMesh_f5kgg")
diff --git a/game/src/GameSession/TerrainMap.gdshader b/game/src/GameSession/TerrainMap.gdshader
index 7aca0f9..05031a8 100644
--- a/game/src/GameSession/TerrainMap.gdshader
+++ b/game/src/GameSession/TerrainMap.gdshader
@@ -13,6 +13,13 @@ uniform uint hover_index;
// Index of the currently selected province
uniform uint selected_index;
+uniform sampler2D basemap;
+uniform sampler2D heightmap;
+uniform float height_ratio: hint_range(0.0, 1.0, 0.002) = .005;
+uniform float base_ratio: hint_range(0.0, 1.0, 0.002) = .001;
+
+
+
uvec2 vec2_to_uvec2(vec2 v) {
return uvec2(v * 255.0);
}
@@ -40,6 +47,11 @@ void fragment() {
vec3 terrain_colour = texture(terrain_tex, UV).rgb;
vec3 province_colour = texelFetch(province_colour_tex, ivec2(prov_idx_split), 0).rgb;
-
+ ANISOTROPY = 1.0;
ALBEDO = mix(terrain_colour, province_colour, mix_val);
}
+
+void vertex() {
+ VERTEX.y += texture(basemap, UV).r * base_ratio;
+ VERTEX.y += texture(heightmap, UV).r * height_ratio;
+}
diff --git a/game/src/GameSession/Water/Water.gdshader b/game/src/GameSession/Water/Water.gdshader
new file mode 100644
index 0000000..b8c2d5f
--- /dev/null
+++ b/game/src/GameSession/Water/Water.gdshader
@@ -0,0 +1,82 @@
+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 wave;
+uniform sampler2D texture_normal;
+uniform sampler2D texture_normal2;
+uniform sampler2D DEPTH_TEXTURE : hint_depth_texture, filter_linear_mipmap;
+uniform sampler2D SCREEN_TEXTURE : hint_depth_texture, filter_linear_mipmap;
+uniform vec2 wave_direction = vec2(2.0,0.0); // Direction of wave 1
+uniform vec2 wave_direction2 = vec2(0.0,1.0); // Direction of wave 2
+uniform float time_scale : hint_range(0.0, 0.2, 0.005) = 0.025; // Rate of movement multiplied by TIME
+uniform float noise_scale = 10.0;
+uniform float height_scale = 0.15;
+
+uniform vec4 color_deep : source_color; // Deep depth color
+uniform vec4 color_shallow : source_color; // Shallow depth color
+uniform float beers_law = 2.0; // Beer's law application
+uniform float depth_offset = -0.75; // Offset
+
+uniform float edge_scale = 0.1;
+uniform float near = 1.0;
+uniform float far = 100.0;
+uniform vec3 edge_color : source_color;
+
+// Varying variables
+varying float height;
+varying vec3 world_pos;
+
+float fresnel(float amount, vec3 normal, vec3 view)
+{
+ return pow((1.0 - clamp(dot(normalize(normal), normalize(view)), 0.0, 1.0 )), amount);
+}
+float edge(float depth){
+ depth = 2.0 * depth - 1.0;
+ return near * far / (far + depth * (near - far));
+}
+
+void vertex() {
+ world_pos = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
+ height = texture(wave, world_pos.xz / noise_scale + TIME * time_scale).r;
+ VERTEX.y += height * height_scale;
+}
+
+void fragment() {
+ // Depth variables and calc
+ float depth_texture = texture(DEPTH_TEXTURE, SCREEN_UV).r * 2.0 - 1.0;
+ float depth = PROJECTION_MATRIX[3][2] / (depth_texture + 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_power = clamp(pow(depth_blend, 2.5), 0.0, 1.0);
+
+ // Retrieving depth color and applying the deep and shallow colors
+ vec3 screen_color = textureLod(SCREEN_TEXTURE, SCREEN_UV, depth_blend_power * 2.5).rgb;
+ vec3 depth_color = mix(color_shallow.rgb, color_deep.rgb, depth_blend_power);
+ vec3 color = mix(screen_color * depth_color, depth_color * 0.25, depth_blend_power * 0.5);
+
+ // Getting edge depth calc
+ float z_depth = edge(texture(DEPTH_TEXTURE, SCREEN_UV).x);
+ float z_pos = edge(FRAGCOORD.z);
+ float z_dif = z_depth - z_pos;
+
+ // Time calculations for wave (normal map) movement
+ vec2 time = (TIME * wave_direction) * time_scale; // Movement rate of first wave
+ vec2 time2 = (TIME * wave_direction2) * time_scale; // Movement rate of second wave
+
+ // Blend normal maps into one
+ vec3 normal_blend = mix(texture(texture_normal,world_pos.xz + time).rgb, texture(texture_normal2,world_pos.xz + time2).rgb, 0.5);
+
+ // Calculate Fresnel
+ float fresnel = fresnel(5.0, NORMAL, VIEW);
+ vec3 surface_color = mix(albedo, albedo2, fresnel); // Interpolate albedo values by frensel
+
+ vec3 depth_color_adj = mix(edge_color, color, step(edge_scale, z_dif));
+
+ ALBEDO = clamp(surface_color + depth_color_adj,vec3(0.0),vec3(1.0));
+ METALLIC = metallic;
+ ROUGHNESS = roughness;
+ NORMAL_MAP = normal_blend;
+} \ No newline at end of file
diff --git a/game/src/GameSession/Water/Water.tres b/game/src/GameSession/Water/Water.tres
new file mode 100644
index 0000000..0d5d912
--- /dev/null
+++ b/game/src/GameSession/Water/Water.tres
@@ -0,0 +1,34 @@
+[gd_resource type="ShaderMaterial" load_steps=5 format=3 uid="uid://c3mh5p2w5s8g7"]
+
+[ext_resource type="Shader" path="res://src/GameSession/Water/Water.gdshader" id="1_gectt"]
+[ext_resource type="Texture2D" uid="uid://gq8n64t6y4go" path="res://src/GameSession/Water/WaterPlaneNormal.tres" id="2_24cl4"]
+
+[sub_resource type="FastNoiseLite" id="FastNoiseLite_aggf3"]
+
+[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_qniod"]
+seamless = true
+noise = SubResource("FastNoiseLite_aggf3")
+
+[resource]
+render_priority = 0
+shader = ExtResource("1_gectt")
+shader_parameter/albedo = Color(0.0627451, 0.298039, 0.431373, 1)
+shader_parameter/albedo2 = Color(0.105882, 0.352941, 0.764706, 1)
+shader_parameter/metallic = 1.0
+shader_parameter/roughness = 0.08
+shader_parameter/wave_direction = Vector2(2, 0)
+shader_parameter/wave_direction2 = Vector2(0, 1)
+shader_parameter/time_scale = 0.01
+shader_parameter/noise_scale = 100.0
+shader_parameter/height_scale = 0.03
+shader_parameter/color_deep = Color(0.105882, 0.294118, 0.329412, 1)
+shader_parameter/color_shallow = Color(0, 0.552941, 0.65098, 1)
+shader_parameter/beers_law = 2.0
+shader_parameter/depth_offset = -0.75
+shader_parameter/edge_scale = 0.1
+shader_parameter/near = 1.0
+shader_parameter/far = 100.0
+shader_parameter/edge_color = Color(0, 0.321569, 0.431373, 1)
+shader_parameter/wave = SubResource("NoiseTexture2D_qniod")
+shader_parameter/texture_normal = ExtResource("2_24cl4")
+shader_parameter/texture_normal2 = ExtResource("2_24cl4")
diff --git a/game/src/GameSession/Water/WaterPlane.tscn b/game/src/GameSession/Water/WaterPlane.tscn
new file mode 100644
index 0000000..35bb64c
--- /dev/null
+++ b/game/src/GameSession/Water/WaterPlane.tscn
@@ -0,0 +1,12 @@
+[gd_scene load_steps=3 format=3 uid="uid://b35mxcc3d74di"]
+
+[ext_resource type="Material" uid="uid://c3mh5p2w5s8g7" path="res://src/GameSession/Water/Water.tres" id="1_ij8tq"]
+
+[sub_resource type="PlaneMesh" id="PlaneMesh_4hfu7"]
+size = Vector2(40, 10)
+
+[node name="Water" type="MeshInstance3D"]
+transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00229871, 0.00877783, 0)
+cast_shadow = 0
+mesh = SubResource("PlaneMesh_4hfu7")
+surface_material_override/0 = ExtResource("1_ij8tq")
diff --git a/game/src/GameSession/Water/WaterPlaneNormal.tres b/game/src/GameSession/Water/WaterPlaneNormal.tres
new file mode 100644
index 0000000..5223e98
--- /dev/null
+++ b/game/src/GameSession/Water/WaterPlaneNormal.tres
@@ -0,0 +1,13 @@
+[gd_resource type="NoiseTexture2D" load_steps=2 format=3 uid="uid://gq8n64t6y4go"]
+
+[sub_resource type="FastNoiseLite" id="FastNoiseLite_0fbhj"]
+noise_type = 3
+seed = 2
+frequency = 0.011
+fractal_type = 2
+
+[resource]
+seamless = true
+as_normal_map = true
+bump_strength = 1.5
+noise = SubResource("FastNoiseLite_0fbhj")
diff --git a/godot-cpp b/godot-cpp
-Subproject 7fb46e9ea1571b1364ab049b2088e9b302ff798
+Subproject 4d3afc0ad0c5445831418830a33c6adb3e0a9aa