Add radial charger

This commit is contained in:
Spencer Killen 2023-11-11 14:56:43 -07:00
parent 1744e6a727
commit 8891190a31
Signed by: sjkillen
GPG Key ID: 3AF3117BA6FBB75B
11 changed files with 111 additions and 9 deletions

BIN
blends/small_room.blend (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -4,6 +4,7 @@ extends Node3D
@export var initial_target: Node3D @export var initial_target: Node3D
var target: Targetable = null var target: Targetable = null
@export var sensitivity := 0.01 @export var sensitivity := 0.01
@export var charge_time := 3
func _ready(): func _ready():
set_target(initial_target) set_target(initial_target)
@ -11,12 +12,23 @@ func _ready():
func _input(event): func _input(event):
if event is InputEventMouseMotion: if event is InputEventMouseMotion:
rotate_view(event.relative*sensitivity) rotate_view(event.relative*sensitivity)
if event.is_action("charge"):
charge(event.get_action_strength("charge"))
func _process(_delta): func _process(_delta):
transform.origin = target.global_position transform.origin = target.global_position
camera.global_position = %camera_spot.global_position camera.global_position = %camera_spot.global_position
camera.look_at(target.global_position) camera.look_at(target.global_position)
var charge_tween: Tween = null
func charge(amount: float):
if charge_tween != null:
charge_tween.kill()
if amount == 0.0:
%radial_ui.set_charge(0.0)
return
charge_tween = create_tween()
charge_tween.tween_method(%radial_ui.set_charge, 0.0, 1.0, charge_time)
func rotate_view(amount: Vector2): func rotate_view(amount: Vector2):
rotate_y(-amount.x) rotate_y(-amount.x)
%rotate_helper.rotate_z(amount.y) %rotate_helper.rotate_z(amount.y)

View File

@ -1,6 +1,7 @@
[gd_scene load_steps=2 format=3 uid="uid://drmb4sitb74fx"] [gd_scene load_steps=3 format=3 uid="uid://drmb4sitb74fx"]
[ext_resource type="Script" path="res://control_scheme/controller.gd" id="1_h3pjb"] [ext_resource type="Script" path="res://control_scheme/controller.gd" id="1_h3pjb"]
[ext_resource type="PackedScene" uid="uid://p2n48c8st55d" path="res://control_scheme/radial_ui.tscn" id="2_qidcb"]
[node name="controller" type="Node3D"] [node name="controller" type="Node3D"]
top_level = true top_level = true
@ -12,3 +13,6 @@ unique_name_in_owner = true
[node name="camera_spot" type="Marker3D" parent="rotate_helper"] [node name="camera_spot" type="Marker3D" parent="rotate_helper"]
unique_name_in_owner = true unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0)
[node name="radial_ui" parent="." instance=ExtResource("2_qidcb")]
unique_name_in_owner = true

View File

@ -28,9 +28,9 @@ func change_all_materials(mesh: MeshInstance3D):
layer0.next_pass = layer1 layer0.next_pass = layer1
layer1.next_pass = layer2 layer1.next_pass = layer2
layer0.render_priority = 0 layer0.render_priority = 10
layer1.render_priority = 1 layer1.render_priority = 20
layer2.render_priority = 2 layer2.render_priority = 30

View File

@ -0,0 +1,8 @@
extends Node3D
func _ready():
set_charge(0.0)
func set_charge(amount: float):
var mat: ShaderMaterial = $MeshInstance3D.get_active_material(0)
mat.set_shader_parameter("charge", amount)

View File

@ -0,0 +1,39 @@
// NOTE: Shader automatically converted from Godot Engine 4.1.3.stable.mono's StandardMaterial3D.
shader_type spatial;
render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_disabled,unshaded,shadows_disabled,ambient_light_disabled, depth_test_disabled;
uniform float grow;
uniform sampler2D colors : source_color, repeat_disable;
uniform float charge = 1.0;
#include "res://shaders/noise.gdshaderinc"
void vertex() {
// Billboarding
MODELVIEW_MATRIX = VIEW_MATRIX * mat4(INV_VIEW_MATRIX[0], INV_VIEW_MATRIX[1], INV_VIEW_MATRIX[2], MODEL_MATRIX[3]);
MODELVIEW_NORMAL_MATRIX = mat3(MODELVIEW_MATRIX);
VERTEX+=NORMAL*grow;
float speed = pow(2.0, ((charge+.4)*5.0));
float dy = sin(speed*.7) * 0.005;
float dx = sin(speed) * 0.005;
VERTEX.y += dy;
VERTEX.x += dx;
}
void fragment() {
float where = distance(UV, vec2(0.5))*2.0;
if (where >= charge) {
discard;
}
vec2 buv = floor(UV * 350.0);
int bx = int(buv.x);
int by = int(buv.y);
int amount = 2;
if ((bx % amount == 0) || (by % amount == 0)) {
discard;
}
ALBEDO = texture(colors, vec2(where)).rgb;
}

View File

@ -0,0 +1,13 @@
[gd_scene load_steps=4 format=3 uid="uid://p2n48c8st55d"]
[ext_resource type="Script" path="res://control_scheme/radial_ui.gd" id="1_0qwj1"]
[ext_resource type="Material" uid="uid://cybyibjbyyok1" path="res://control_scheme/radial_ui_material.tres" id="2_go05o"]
[sub_resource type="QuadMesh" id="QuadMesh_sogra"]
[node name="radial_ui" type="Node3D"]
script = ExtResource("1_0qwj1")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
material_override = ExtResource("2_go05o")
mesh = SubResource("QuadMesh_sogra")

View File

@ -0,0 +1,18 @@
[gd_resource type="ShaderMaterial" load_steps=4 format=3 uid="uid://cybyibjbyyok1"]
[ext_resource type="Shader" path="res://control_scheme/radial_ui.gdshader" id="1_hmfvm"]
[sub_resource type="Gradient" id="Gradient_l7u12"]
interpolation_mode = 1
offsets = PackedFloat32Array(0.00328947, 0.347039, 0.506579, 0.694079, 0.848684)
colors = PackedColorArray(0.266667, 0.215686, 0.258824, 1, 0.517647, 0.423529, 0.356863, 1, 0.807843, 0.627451, 0.494118, 1, 0.929412, 0.85098, 0.639216, 1, 0.886275, 0.909804, 0.752941, 1)
[sub_resource type="GradientTexture1D" id="GradientTexture1D_8vk7x"]
gradient = SubResource("Gradient_l7u12")
[resource]
render_priority = 5
shader = ExtResource("1_hmfvm")
shader_parameter/grow = 0.01
shader_parameter/charge = 0.0
shader_parameter/colors = SubResource("GradientTexture1D_8vk7x")

View File

@ -25,3 +25,11 @@ project/assembly_name="Hurrmmm"
[filesystem] [filesystem]
import/blender/enabled=false import/blender/enabled=false
[input]
charge={
"deadzone": 0.0,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
]
}