diff --git a/assets/interfaces/debug_window/debug_window.gd b/assets/interfaces/debug_window/debug_window.gd new file mode 100644 index 0000000..4c0bd4a --- /dev/null +++ b/assets/interfaces/debug_window/debug_window.gd @@ -0,0 +1,12 @@ +extends WindowDialog + +signal time_of_day_changed( value ) +signal mist_level_changed( value ) + + +func _on_time_of_day_value_changed(value): + emit_signal( "time_of_day_changed", value ) + + +func _on_mist_level_value_changed(value): + emit_signal( "mist_level_changed", value ) diff --git a/assets/interfaces/debug_window/debug_window.tscn b/assets/interfaces/debug_window/debug_window.tscn new file mode 100644 index 0000000..ac30d9a --- /dev/null +++ b/assets/interfaces/debug_window/debug_window.tscn @@ -0,0 +1,88 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://assets/interfaces/debug_window/debug_window.gd" type="Script" id=1] + +[node name="debug_window" type="WindowDialog"] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_right = -1232.0 +margin_bottom = -719.0 +rect_min_size = Vector2( 256, 256 ) +popup_exclusive = true +window_title = "Debug/Tests" +resizable = true +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="v_box_container" type="VBoxContainer" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="sky_label" type="Label" parent="v_box_container"] +margin_right = 256.0 +margin_bottom = 14.0 +text = "Sky:" + +[node name="sky_box" type="VBoxContainer" parent="v_box_container"] +margin_top = 18.0 +margin_right = 256.0 +margin_bottom = 34.0 + +[node name="time_of_day" type="HBoxContainer" parent="v_box_container/sky_box"] +margin_right = 256.0 +margin_bottom = 16.0 + +[node name="label" type="Label" parent="v_box_container/sky_box/time_of_day"] +margin_left = 52.0 +margin_top = 1.0 +margin_right = 126.0 +margin_bottom = 15.0 +size_flags_horizontal = 10 +text = "Time of day" + +[node name="value" type="HSlider" parent="v_box_container/sky_box/time_of_day"] +margin_left = 130.0 +margin_right = 256.0 +margin_bottom = 16.0 +size_flags_horizontal = 3 +max_value = 24.0 +step = 0.1 +value = 12.0 + +[node name="mist_label" type="Label" parent="v_box_container"] +margin_top = 38.0 +margin_right = 256.0 +margin_bottom = 52.0 +text = "Mist:" + +[node name="mist_box" type="VBoxContainer" parent="v_box_container"] +margin_top = 56.0 +margin_right = 256.0 +margin_bottom = 72.0 + +[node name="mist_level" type="HBoxContainer" parent="v_box_container/mist_box"] +margin_right = 256.0 +margin_bottom = 16.0 + +[node name="label" type="Label" parent="v_box_container/mist_box/mist_level"] +margin_left = 63.0 +margin_top = 1.0 +margin_right = 126.0 +margin_bottom = 15.0 +size_flags_horizontal = 10 +text = "Mist level" + +[node name="value" type="HSlider" parent="v_box_container/mist_box/mist_level"] +margin_left = 130.0 +margin_right = 256.0 +margin_bottom = 16.0 +size_flags_horizontal = 3 +max_value = 1.0 +step = 0.1 +[connection signal="value_changed" from="v_box_container/sky_box/time_of_day/value" to="." method="_on_time_of_day_value_changed"] +[connection signal="value_changed" from="v_box_container/mist_box/mist_level/value" to="." method="_on_mist_level_value_changed"] diff --git a/assets/mist/mist.shader b/assets/mist/mist.shader new file mode 100644 index 0000000..3e7ce7b --- /dev/null +++ b/assets/mist/mist.shader @@ -0,0 +1,43 @@ +shader_type spatial; +render_mode unshaded, cull_disabled, blend_mix; + +uniform float mist_level = 0.0; +uniform vec4 mist_color : hint_color = vec4( 1.0, 0.0, 1.0, 1.0 ); +uniform float mist_height = 0.0; +uniform float mist_distance = 25.0; + +varying mat4 CAMERA; + +void vertex() +{ + POSITION = vec4(VERTEX, 1.0); + CAMERA = CAMERA_MATRIX; +} + +void fragment() +{ + float depth = texture(DEPTH_TEXTURE, SCREEN_UV).x; + vec3 ndc = vec3(SCREEN_UV, depth) * 2.0 - 1.0; + + vec4 view = INV_PROJECTION_MATRIX * vec4(ndc, 1.0); + view.xyz /= view.w; + float linear_depth = -view.z; + + vec4 world = CAMERA * INV_PROJECTION_MATRIX * vec4(ndc, 1.0); + vec3 world_position = world.xyz / world.w; + + if ( linear_depth*mist_level <= mist_distance ) + { + ALBEDO = vec3( 1.0, 0.0, 1.0 ) * mist_level; + ALPHA = (linear_depth*mist_level)/mist_distance; + } + else + { + ALBEDO = vec3( 1.0, 0.0, 1.0 ); + ALPHA = 1.0; + } +// if ( world_position.y > 0.2 && world_position.y >= mist_height ) +// { +// ALPHA *= mist_height/world_position.y; +// } +} \ No newline at end of file diff --git a/scenes/game/game.gd b/scenes/game/game.gd index 8f19ad3..33dcd8a 100644 --- a/scenes/game/game.gd +++ b/scenes/game/game.gd @@ -5,8 +5,9 @@ var player_rotation_speed = 0.1 var heightmap = null -#func _ready(): -# +func _ready(): + if ProjectSettings.get_setting("khanat/debug_mode"): + $debug_window.popup() # self.heightmap = Image.new() # self.heightmap.load( "res://assets/decors/terrains/dunes_heightmap.png" ) # @@ -32,26 +33,15 @@ func _input( event ): $creatures/player.move( movment ) -func _process( delta ): - pass -# if self.heightmap: -# self.heightmap.lock() -# print( $creatures/player.translation ) -# print( $creatures/player/model.translation ) -# print( $creatures/player/model/ra.translation ) -# var pixel = self.heightmap.get_pixel( $creatures/player/model/ra.translation.x*2048.0, $creatures/player/model/ra.translation.z*2048.0 ) - -# var pixel = self.heightmap.get_pixel( 512, 512 ) -# self.heightmap.unlock() -# print ( pixel ) -# var movment = Vector3( 0.0, 0.0, 0.0 ) -# $creatures/player/model/ra.translation.y = pixel.r*10.0 -# movment.y = pixel.r - $creatures/player/model/ra.translation.y -# -# $creatures/player.move( movment ) -# print( movment ) - func load_player( filename ): $creatures/player.load_creature( filename ) + + +func _on_debug_window_time_of_day_changed(value): + $sky/viewport/sky.set_day_time_hours(( value )) + + +func _on_debug_window_mist_level_changed(value): + $mist_fx.get_surface_material( 0 ).set_shader_param( "mist_level", value ) diff --git a/scenes/game/game.tscn b/scenes/game/game.tscn index b5b6168..a69b23a 100644 --- a/scenes/game/game.tscn +++ b/scenes/game/game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=14 format=2] +[gd_scene load_steps=18 format=2] [ext_resource path="res://scenes/player/player.tscn" type="PackedScene" id=1] [ext_resource path="res://scenes/decors/terrains/dunes/dunes.tscn" type="PackedScene" id=2] @@ -6,6 +6,8 @@ [ext_resource path="res://scenes/decors/vegets/tree_001.tscn" type="PackedScene" id=4] [ext_resource path="res://assets/sky/sky.shader" type="Shader" id=5] [ext_resource path="res://scenes/game/sky.gd" type="Script" id=6] +[ext_resource path="res://assets/mist/mist.shader" type="Shader" id=7] +[ext_resource path="res://assets/interfaces/debug_window/debug_window.tscn" type="PackedScene" id=8] [sub_resource type="OpenSimplexNoise" id=1] period = 8.0 @@ -20,8 +22,8 @@ noise = SubResource( 1 ) [sub_resource type="ShaderMaterial" id=5] resource_local_to_scene = true shader = ExtResource( 5 ) -shader_param/iTime = 6392.37 -shader_param/iFrame = 208147 +shader_param/iTime = 169.046 +shader_param/iFrame = 6399 shader_param/COVERAGE = 0.5 shader_param/THICKNESS = 25.0 shader_param/ABSORPTION = 1.031 @@ -29,7 +31,7 @@ shader_param/STEPS = 50 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( -1.15706e-06, 100, 8.66537e-06 ) +shader_param/sun_pos = Vector3( -9.32094, -70.9947, 69.806 ) shader_param/sun_intensity = 42.0 shader_param/rayleigh_coeff = Vector3( 5.5, 13, 22.4 ) shader_param/mie_coeff = 21.0 @@ -56,6 +58,20 @@ background_mode = 2 background_sky = SubResource( 3 ) background_energy = 0.1 ambient_light_energy = 3.82 +fog_color = Color( 0.247059, 0.00784314, 0.592157, 1 ) +fog_sun_color = Color( 0.898039, 0.529412, 1, 1 ) +fog_depth_begin = 5.0 +fog_transmit_enabled = true + +[sub_resource type="QuadMesh" id=8] +size = Vector2( 2, 2 ) + +[sub_resource type="ShaderMaterial" id=10] +shader = ExtResource( 7 ) +shader_param/mist_level = 0.0 +shader_param/mist_color = Color( 1, 0, 1, 1 ) +shader_param/mist_height = 0.0 +shader_param/mist_distance = 25.0 [node name="game" type="Spatial"] script = ExtResource( 3 ) @@ -72,9 +88,14 @@ texture = SubResource( 6 ) offset = Vector2( 640, 360 ) script = ExtResource( 6 ) editor_clouds_playing = true -day_time_hours = 14.0283 -directional_light_node_path = NodePath("../../../directional_light") -sun_position = Vector3( -1.15706e-06, 100, 8.66537e-06 ) +day_time_hours = 21.0154 +directional_light_node_path = NodePath("../../sun") +sun_position = Vector3( -9.32094, -70.9947, 69.806 ) + +[node name="sun" type="DirectionalLight" parent="sky"] +transform = Transform( 0.991203, -0.0939627, -0.0932094, 0, 0.704255, -0.709947, 0.132352, 0.703701, 0.69806, -9.32094, -70.9947, 69.806 ) +light_energy = 0.0 +shadow_enabled = true [node name="world_environment" type="WorldEnvironment" parent="."] environment = SubResource( 7 ) @@ -92,7 +113,12 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -11.2768, 8, 13.9512 ) [node name="player" parent="creatures" instance=ExtResource( 1 )] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 14.7098, 0 ) -[node name="directional_light" type="DirectionalLight" parent="."] -transform = Transform( 0.991203, 0.132352, -1.15706e-08, 0, 8.74228e-08, 1, 0.132352, -0.991203, 8.66537e-08, -1.15706e-06, 100, 8.66537e-06 ) -light_energy = 1.0 -shadow_enabled = true +[node name="mist_fx" type="MeshInstance" parent="."] +cast_shadow = 0 +extra_cull_margin = 16384.0 +mesh = SubResource( 8 ) +material/0 = SubResource( 10 ) + +[node name="debug_window" parent="." instance=ExtResource( 8 )] +[connection signal="mist_level_changed" from="debug_window" to="." method="_on_debug_window_mist_level_changed"] +[connection signal="time_of_day_changed" from="debug_window" to="." method="_on_debug_window_time_of_day_changed"] diff --git a/scenes/game/sky.gd b/scenes/game/sky.gd index 1fa210b..b1ebda5 100644 --- a/scenes/game/sky.gd +++ b/scenes/game/sky.gd @@ -23,9 +23,9 @@ func _process( delta ): self.material.set("shader_param/iTime", iTime) self.material.set("shader_param/iFrame", iFrame) - self.set_day_time_hours( self.day_time_hours + delta ) - if day_time_hours >= 24: - self.set_day_time_hours( 0 ) +# self.set_day_time_hours( self.day_time_hours + delta ) +# if day_time_hours >= 24: +# self.set_day_time_hours( 0 ) func cov_scb(value):