Skip to content

Commit

Permalink
IMPROVEMENT: Added viewport to address rendering performance
Browse files Browse the repository at this point in the history
  • Loading branch information
roalyr committed Oct 28, 2021
1 parent 2b83135 commit 7cd14f1
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 87 deletions.
51 changes: 35 additions & 16 deletions Scenes/Main.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=13 format=2]
[gd_scene load_steps=14 format=2]

[ext_resource path="res://Scripts/Main.gd" type="Script" id=1]
[ext_resource path="res://Scenes/UI/Camera_rig.tscn" type="PackedScene" id=2]
Expand All @@ -12,46 +12,65 @@
[ext_resource path="res://Scripts/Signals.gd" type="Script" id=10]
[ext_resource path="res://Default_env.tres" type="Environment" id=11]
[ext_resource path="res://Scripts/Options/Engine.gd" type="Script" id=12]
[ext_resource path="res://Scripts/View.gd" type="Script" id=13]

[node name="Main" type="Spatial"]
[node name="Cont" type="ViewportContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 1
stretch = true
__meta__ = {
"_edit_use_anchors_": false
}

[node name="UI" parent="." instance=ExtResource( 3 )]

[node name="View" type="Viewport" parent="."]
size = Vector2( 1024, 600 )
handle_input_locally = false
render_target_update_mode = 3
script = ExtResource( 13 )
scale_factor = 1.0

[node name="Main" type="Spatial" parent="View"]
script = ExtResource( 1 )

[node name="World" type="WorldEnvironment" parent="."]
[node name="World" type="WorldEnvironment" parent="View/Main"]
environment = ExtResource( 11 )

[node name="Options" type="Node" parent="."]
[node name="Options" type="Node" parent="View/Main"]

[node name="Engine" type="Node" parent="Options"]
[node name="Engine" type="Node" parent="View/Main/Options"]
script = ExtResource( 12 )

[node name="Camera" type="Node" parent="Options"]
[node name="Camera" type="Node" parent="View/Main/Options"]
script = ExtResource( 8 )
camera_far = 60000

[node name="Input" type="Node" parent="."]
[node name="Input" type="Node" parent="View/Main"]
script = ExtResource( 6 )

[node name="Signals" type="Node" parent="Input"]
[node name="Signals" type="Node" parent="View/Main/Input"]
script = ExtResource( 10 )

[node name="State" type="Node" parent="."]
[node name="State" type="Node" parent="View/Main"]

[node name="Player_ship" type="Node" parent="State"]
[node name="Player_ship" type="Node" parent="View/Main/State"]
script = ExtResource( 9 )

[node name="UI" parent="." instance=ExtResource( 3 )]

[node name="Local_space" type="Position3D" parent="."]
[node name="Local_space" type="Position3D" parent="View/Main"]
__meta__ = {
"_edit_group_": true,
"_edit_lock_": true
}

[node name="System_objects" parent="Local_space" instance=ExtResource( 4 )]
[node name="System_objects" parent="View/Main/Local_space" instance=ExtResource( 4 )]

[node name="Player_ship" parent="." instance=ExtResource( 5 )]
[node name="Player_ship" parent="View/Main" instance=ExtResource( 5 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 2500, 0, 0 )
accel_ticks_max = 100

[node name="Camera_rig" parent="Player_ship" instance=ExtResource( 2 )]
[node name="Camera_rig" parent="View/Main/Player_ship" instance=ExtResource( 2 )]
script = ExtResource( 7 )

[connection signal="size_changed" from="View" to="View" method="_on_View_size_changed"]
43 changes: 5 additions & 38 deletions Scenes/UI/UI.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=2]
[gd_scene load_steps=8 format=2]

[ext_resource path="res://Scripts/UI.gd" type="Script" id=1]
[ext_resource path="res://Assets/UI_styles/Button_red/Hover_focus.tres" type="StyleBox" id=2]
Expand All @@ -7,32 +7,9 @@

[sub_resource type="ShaderMaterial" id=1]

[sub_resource type="ShaderMaterial" id=6]
[sub_resource type="ShaderMaterial" id=2]

[sub_resource type="Shader" id=7]
code = "shader_type canvas_item;

uniform float brightness = 1.0;
uniform float contrast = 1.0;
uniform float saturation = 1.0;

void fragment() {
vec3 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;

c.rgb = mix(vec3(0.0), c.rgb, brightness);
c.rgb = mix(vec3(0.5), c.rgb, contrast);
c.rgb = mix(vec3(dot(vec3(1.0), c.rgb) * 0.33333), c.rgb, saturation);

COLOR.rgb = c;
}"

[sub_resource type="ShaderMaterial" id=8]
shader = SubResource( 7 )
shader_param/brightness = 1.415
shader_param/contrast = 1.0
shader_param/saturation = -2.387

[sub_resource type="CanvasItemMaterial" id=4]
[sub_resource type="CanvasItemMaterial" id=3]

[node name="UI" type="CanvasLayer"]
script = ExtResource( 1 )
Expand All @@ -58,8 +35,7 @@ __meta__ = {
}

[node name="_ColorRect" type="ColorRect" parent="Main3D/Debug"]
visible = false
material = SubResource( 6 )
material = SubResource( 2 )
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0.443137, 0.588235, 0.439216, 1 )
Expand Down Expand Up @@ -133,7 +109,6 @@ __meta__ = {
}

[node name="Text_panel" type="Control" parent="Main3D"]
visible = false
anchor_left = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
Expand All @@ -146,7 +121,6 @@ __meta__ = {
}

[node name="_ColorRect" type="ColorRect" parent="Main3D/Text_panel"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0.529412, 0.258824, 0.360784, 1 )
Expand All @@ -170,14 +144,8 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="Filter" type="ColorRect" parent="Main3D"]
visible = false
material = SubResource( 8 )
anchor_right = 1.0
anchor_bottom = 1.0

[node name="Controls" type="Control" parent="."]
material = SubResource( 4 )
material = SubResource( 3 )
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
Expand All @@ -189,7 +157,6 @@ __meta__ = {
}

[node name="ColorRect" type="ColorRect" parent="Controls"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
Expand Down
10 changes: 5 additions & 5 deletions Scripts/Camera_rig.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ var ship_model = Node

func _ready():
# ============================ Initialize nodes ===========================
input = get_node("/root/Main/Input")
cam_opts = get_node("/root/Main/Options/Camera")
player_ship_state = get_node("/root/Main/State/Player_ship")
input = get_node("/root/Cont/View/Main/Input")
cam_opts = get_node("/root/Cont/View/Main/Options/Camera")
player_ship_state = get_node("/root/Cont/View/Main/State/Player_ship")
# TODO: make reference to model universal.
ship = get_parent()
ship_model = get_node("../Ship_model")
signals = get_node("/root/Main/Input/Signals")
ui = get_node("/root/Main/UI")
signals = get_node("/root/Cont/View/Main/Input/Signals")
ui = get_node("/root/Cont/UI")
# ============================ Connect signals ============================
signals.connect("sig_turret_mode_on", self, "is_turret_mode_on")
# =========================================================================
Expand Down
10 changes: 5 additions & 5 deletions Scripts/Input.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ var ui_button_turret = Node

func _ready():
# ============================ Initialize nodes ===========================
camera_rig = get_node("/root/Main/Player_ship/Camera_rig")
player_ship_state = get_node("/root/Main/State/Player_ship")
signals = get_node("/root/Main/Input/Signals")
ui = get_node("/root/Main/UI")
ui_button_turret = get_node("/root/Main/UI/Controls/Button_turret")
camera_rig = get_node("/root/Cont/View/Main/Player_ship/Camera_rig")
player_ship_state = get_node("/root/Cont/View/Main/State/Player_ship")
signals = get_node("/root/Cont/View/Main/Input/Signals")
ui = get_node("/root/Cont/UI")
ui_button_turret = get_node("/root/Cont/UI/Controls/Button_turret")
# ============================ Connect signals ============================
signals.connect("sig_mouse_on_viewport", self, "is_mouse_on_viewport")
signals.connect("sig_viewport_update", self, "is_viewport_update")
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Options/Camera.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var camera = Node

func _ready():
# ============================ Initialize nodes ===========================
camera = get_node("/root/Main/Player_ship/Camera_rig/Camera")
camera = get_node("/root/Cont/View/Main/Player_ship/Camera_rig/Camera")

# Set camera properties.
camera.fov = camera_fov
Expand Down
12 changes: 6 additions & 6 deletions Scripts/Player_ship.gd
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ var player_ship_state = Node
func _ready():
# ============================ Initialize nodes ===========================
engines = get_node("Engines")
engine_opts = get_node("/root/Main/Options/Engine")
input = get_node("/root/Main/Input")
local_space = get_node("/root/Main/Local_space")
ui = get_node("/root/Main/UI")
signals = get_node("/root/Main/Input/Signals")
player_ship_state = get_node("/root/Main/State/Player_ship")
engine_opts = get_node("/root/Cont/View/Main/Options/Engine")
input = get_node("/root/Cont/View/Main/Input")
local_space = get_node("/root/Cont/View/Main/Local_space")
ui = get_node("/root/Cont/UI")
signals = get_node("/root/Cont/View/Main/Input/Signals")
player_ship_state = get_node("/root/Cont/View/Main/State/Player_ship")
# ============================= Connect signals ===========================
signals.connect("sig_accelerate", self, "is_accelerating")
signals.connect("sig_engine_kill", self, "is_engine_kill")
Expand Down
28 changes: 12 additions & 16 deletions Scripts/UI.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@ var text_panel = Node

func _ready():
# ============================ Initialize nodes ===========================
camera_rig = get_node("/root/Main/Player_ship/Camera_rig")
camera_rig = get_node("/root/Cont/View/Main/Player_ship/Camera_rig")
debug = get_node("Main3D/Debug")
input = get_node("/root/Main/Input")
main = get_node("/root/Main")
input = get_node("/root/Cont/View/Main/Input")
main = get_node("/root/Cont/View/Main")
marker = get_node("Main3D/Debug/Marker")
marker2 = get_node("Main3D/Debug/Marker2")
marker3 = get_node("Main3D/Debug/Marker3")
monolith = get_node("/root/Main/Local_space/System_objects/Monolith")
monolith2 = get_node("/root/Main/Local_space/System_objects/Monolith2")
monolith = get_node("/root/Cont/View/Main/Local_space/System_objects/Monolith")
mouse_vector = get_node("Main3D/Debug/Mouse_vector")
signals = get_node("/root/Main/Input/Signals")
signals = get_node("/root/Cont/View/Main/Input/Signals")
text_panel = get_node("Main3D/Text_panel")
# =========================================================================

Expand All @@ -51,19 +50,15 @@ func _process(_delta):
# This should be an iterator over objects within proximity.
var loc = camera_rig.global_transform.origin
var loc2 = monolith.global_transform.origin
var loc3 = monolith2.global_transform.origin

marker.visible = not get_viewport().get_camera().is_position_behind(Vector3(0,0,0))
marker.rect_position = get_viewport().get_camera().unproject_position(Vector3(0,0,0))
marker.text = "Origin: "+str(loc.distance_to(Vector3(0,0,0)))
#marker.visible = not get_viewport().get_camera().is_position_behind(Vector3(0,0,0))
#marker.rect_position = get_viewport().get_camera().unproject_position(Vector3(0,0,0))
#marker.text = "Origin: "+str(loc.distance_to(Vector3(0,0,0)))

marker2.visible = not get_viewport().get_camera().is_position_behind(loc2)
marker2.rect_position = get_viewport().get_camera().unproject_position(loc2)
marker2.text = "Monolith: "+str(loc.distance_to(loc2))
#marker2.visible = not get_viewport().get_camera().is_position_behind(loc2)
#marker2.rect_position = get_viewport().get_camera().unproject_position(loc2)
#marker2.text = "Monolith: "+str(loc.distance_to(loc2))

marker3.visible = not get_viewport().get_camera().is_position_behind(loc3)
marker3.rect_position = get_viewport().get_camera().unproject_position(loc3)
marker3.text = "Monolith2: "+str(loc.distance_to(loc3))
if update_debug_text_on: update_debug_text()

# ================================== Other ====================================
Expand All @@ -80,6 +75,7 @@ func _on_Viewport_main_mouse_entered():
func _on_Viewport_main_mouse_exited():
signals.emit_signal("sig_mouse_on_viewport", false)

# TODO: improve
func _on_Viewport_main_resized():
signals.emit_signal("sig_viewport_update")
viewport_size = OS.window_size
Expand Down
12 changes: 12 additions & 0 deletions Scripts/View.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extends Viewport

export var scale_factor = 0.65

func _ready():
self.get_texture().flags = Texture.FLAG_FILTER
self.size = Vector2(1024, 600)*scale_factor

# TODO: implement ratio setting, factor, size

func _on_View_size_changed():
self.size = Vector2(1024, 600)*scale_factor
4 changes: 4 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ run/main_scene="res://Scenes/Main.tscn"
boot_splash/image="res://Assets/Images/Splash.png"
config/icon="res://Assets/Images/Icon.png"

[display]

window/stretch/aspect="keep"

[editor_plugins]

enabled=PoolStringArray( "res://addons/lod/plugin.cfg" )
Expand Down

0 comments on commit 7cd14f1

Please sign in to comment.