Skip to content

Commit

Permalink
Add wireframe shader and use it for a new target info view
Browse files Browse the repository at this point in the history
  • Loading branch information
jspahrsummers committed Jul 3, 2024
1 parent cdf8ba6 commit 3161c06
Show file tree
Hide file tree
Showing 17 changed files with 393 additions and 6 deletions.
1 change: 1 addition & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ SOFTWARE.
- dropdown
- radar
- radio
- target_info

---

Expand Down
30 changes: 30 additions & 0 deletions fx/wireframe.gdshader
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
shader_type spatial;

render_mode unshaded, wireframe;

uniform vec4 wireframe_color : source_color = vec4(0.0, 0.0, 0.0, 1.0);
uniform float wireframe_thickness : hint_range(0.0, 10.0) = 1.0;
uniform float wireframe_smoothness : hint_range(0.0, 10.0) = 1.0;

varying vec3 barycentric_coords;

void vertex() {
// Calculate barycentric coordinates
float base = float(VERTEX_ID % 3);
barycentric_coords = vec3(0.0);
barycentric_coords[int(base)] = 1.0;
}

void fragment() {
// Calculate the minimum distance to an edge
vec3 deltas = fwidth(barycentric_coords);
vec3 smoothing = deltas * wireframe_smoothness;
vec3 thickness = deltas * wireframe_thickness;

vec3 barycentric = smoothstep(thickness, thickness + smoothing, barycentric_coords);
float min_distance = min(min(barycentric.x, barycentric.y), barycentric.z);

// Mix the wireframe color with transparency based on the distance
ALBEDO = wireframe_color.rgb;
ALPHA = 1.0 - min_distance;
}
Binary file added gui/hud/images/target_info/bar_empty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions gui/hud/images/target_info/bar_empty.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://cwdmvrqg25666"
path="res://.godot/imported/bar_empty.png-b104e5c09f9d9231156ca764a29a557a.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://gui/hud/images/target_info/bar_empty.png"
dest_files=["res://.godot/imported/bar_empty.png-b104e5c09f9d9231156ca764a29a557a.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
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
Binary file added gui/hud/images/target_info/heading_border.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions gui/hud/images/target_info/heading_border.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://dcg5m8doqdfc"
path="res://.godot/imported/heading_border.png-c966ae8439c2daa80140c98ef2f97888.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://gui/hud/images/target_info/heading_border.png"
dest_files=["res://.godot/imported/heading_border.png-c966ae8439c2daa80140c98ef2f97888.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
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
Binary file added gui/hud/images/target_info/hull_fill.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions gui/hud/images/target_info/hull_fill.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://e8r1y25pox5u"
path="res://.godot/imported/hull_fill.png-555f5f5b083a2023ff49c2a7584268d1.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://gui/hud/images/target_info/hull_fill.png"
dest_files=["res://.godot/imported/hull_fill.png-555f5f5b083a2023ff49c2a7584268d1.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
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
Binary file added gui/hud/images/target_info/shields_fill.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions gui/hud/images/target_info/shields_fill.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bsf3tqgocto7h"
path="res://.godot/imported/shields_fill.png-9eebbd928584a892ac05d44c6835b499.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://gui/hud/images/target_info/shields_fill.png"
dest_files=["res://.godot/imported/shields_fill.png-9eebbd928584a892ac05d44c6835b499.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
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
Binary file added gui/hud/images/target_info/target_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions gui/hud/images/target_info/target_bg.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://s173r8o180gv"
path="res://.godot/imported/target_bg.png-b5cf7ada0150f7b982841beebedcfc7e.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://gui/hud/images/target_info/target_bg.png"
dest_files=["res://.godot/imported/target_bg.png-b5cf7ada0150f7b982841beebedcfc7e.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=false
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
36 changes: 36 additions & 0 deletions gui/hud/target_fill_bar.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
extends Control
class_name TargetFillBar

@export var max_value: float:
get:
return self._max_value
set(value):
self._max_value = value
self._update()

@export var value: float:
get:
return self._value
set(value):
self._value = value
self._update()

@export var fill_rect: NinePatchRect

@export var max_width: float
@export var min_width: float

var _max_value: float
var _value: float

func _ready() -> void:
self._update()

func _update() -> void:
if self.fill_rect == null:
return

var percentage := 0.0 if is_zero_approx(self.max_value) else clampf(self.value / self.max_value, 0.0, 1.0)

self.fill_rect.visible = not is_zero_approx(percentage)
self.fill_rect.size.x = (self.max_width - self.min_width) * percentage + self.min_width
42 changes: 42 additions & 0 deletions gui/hud/target_fill_bar.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[gd_scene load_steps=4 format=3 uid="uid://bpav2va7o5qt4"]

[ext_resource type="Script" path="res://gui/hud/target_fill_bar.gd" id="1_q2o4q"]
[ext_resource type="Texture2D" uid="uid://cwdmvrqg25666" path="res://gui/hud/images/target_info/bar_empty.png" id="1_slxrs"]
[ext_resource type="Texture2D" uid="uid://e8r1y25pox5u" path="res://gui/hud/images/target_info/hull_fill.png" id="2_gshbn"]

[node name="TargetFillBar" type="Control" node_paths=PackedStringArray("fill_rect")]
custom_minimum_size = Vector2(100, 11)
layout_mode = 3
anchors_preset = 0
mouse_filter = 1
script = ExtResource("1_q2o4q")
max_value = 10.0
value = 7.0
fill_rect = NodePath("NinePatchRect")
max_width = 184.0
min_width = 16.0

[node name="Background" type="TextureRect" parent="."]
custom_minimum_size = Vector2(100, 11)
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
texture = ExtResource("1_slxrs")
expand_mode = 1

[node name="NinePatchRect" type="NinePatchRect" parent="."]
layout_mode = 0
offset_left = -7.0
offset_top = -6.0
offset_right = 107.0
offset_bottom = 17.0
texture = ExtResource("2_gshbn")
region_rect = Rect2(2.08165e-12, 2.08165e-12, 278, 23)
patch_margin_left = 8
patch_margin_top = 8
patch_margin_right = 8
patch_margin_bottom = 8
34 changes: 34 additions & 0 deletions gui/hud/target_view.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[gd_scene load_steps=5 format=3 uid="uid://boit6owlfi3h"]

[ext_resource type="ArrayMesh" uid="uid://c2y60nf8m25ka" path="res://ships/frigate03/frigate03_mesh.tres" id="1_a2vil"]
[ext_resource type="Shader" path="res://fx/wireframe.gdshader" id="2_uts7q"]

[sub_resource type="ShaderMaterial" id="ShaderMaterial_yvqgq"]
render_priority = 0
shader = ExtResource("2_uts7q")
shader_parameter/wireframe_color = Color(0.65098, 0.831373, 1, 1)
shader_parameter/wireframe_thickness = 1.0
shader_parameter/wireframe_smoothness = 1.0

[sub_resource type="Environment" id="Environment_n1lj7"]
ambient_light_color = Color(1, 1, 1, 1)
reflected_light_source = 1

[node name="TargetView" type="Node3D"]

[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(-0.866023, -0.433016, 0.250001, 0, 0.499998, 0.866027, -0.500003, 0.749999, -0.43301, 0, 0, 0)
shadow_enabled = true

[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
mesh = ExtResource("1_a2vil")
surface_material_override/0 = SubResource("ShaderMaterial_yvqgq")

[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(0.707107, 0.5, -0.5, 2.4663e-16, 0.707107, 0.707107, 0.707107, -0.5, 0.5, -2, 2, 2)
current = true
near = 1.0
far = 10.0

[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_n1lj7")
Loading

0 comments on commit 3161c06

Please sign in to comment.