target tracer transparency

godot-4.2
John Montagu, the 4th Earl of Sandvich 2023-09-10 09:37:12 -07:00
parent 456236afdb
commit 59d2def8a9
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
5 changed files with 60 additions and 42 deletions

View File

@ -71,7 +71,15 @@ public sealed partial class Player : Character
{ {
base._Process(delta); base._Process(delta);
_targetTracer.Rotation = DesiredTarget.Angle(); float angle = DesiredTarget.Angle();
float deltaTheta = Mathf.Abs(_targetTracer.Rotation - angle);
_targetTracer.Rotation = angle;
// must turn > pi / 4 radians per second to increase intensity
_targetTracer.Intensity = Mathf.Min(_targetTracer.Intensity +
deltaTheta, 1);
_targetTracer.Intensity = Mathf.Max(_targetTracer.Intensity -
Mathf.Pi / 4 * (float)delta, 0);
GD.Print(_targetTracer.Intensity);
} }
public override void _Input(InputEvent @event) public override void _Input(InputEvent @event)

View File

@ -245,9 +245,9 @@ tracks/2/keys = {
"values": [false] "values": [false]
} }
[sub_resource type="Animation" id="Animation_3w3u1"] [sub_resource type="Animation" id="Animation_audkv"]
resource_name = "sword" resource_name = "heal"
length = 0.3 loop_mode = 1
tracks/0/type = "value" tracks/0/type = "value"
tracks/0/imported = false tracks/0/imported = false
tracks/0/enabled = true tracks/0/enabled = true
@ -255,10 +255,22 @@ tracks/0/path = NodePath("%Sprites/Node2D/Character:frame")
tracks/0/interp = 1 tracks/0/interp = 1
tracks/0/loop_wrap = true tracks/0/loop_wrap = true
tracks/0/keys = { tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1, 0.2), "times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1, 1, 1), "transitions": PackedFloat32Array(1),
"update": 1, "update": 1,
"values": [12, 13, 14] "values": [35]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("%Effects/HealParticles:emitting")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [true]
} }
[sub_resource type="Animation" id="Animation_60iyy"] [sub_resource type="Animation" id="Animation_60iyy"]
@ -277,22 +289,6 @@ tracks/0/keys = {
"values": [false] "values": [false]
} }
[sub_resource type="Animation" id="Animation_6twa8"]
resource_name = "heal_start"
length = 0.25
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("%Sprites/Node2D/Character:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [35]
}
[sub_resource type="Animation" id="Animation_dyfl4"] [sub_resource type="Animation" id="Animation_dyfl4"]
resource_name = "heal_end" resource_name = "heal_end"
length = 0.001 length = 0.001
@ -321,9 +317,9 @@ tracks/1/keys = {
"values": [true] "values": [true]
} }
[sub_resource type="Animation" id="Animation_audkv"] [sub_resource type="Animation" id="Animation_6twa8"]
resource_name = "heal" resource_name = "heal_start"
loop_mode = 1 length = 0.25
tracks/0/type = "value" tracks/0/type = "value"
tracks/0/imported = false tracks/0/imported = false
tracks/0/enabled = true tracks/0/enabled = true
@ -336,17 +332,21 @@ tracks/0/keys = {
"update": 1, "update": 1,
"values": [35] "values": [35]
} }
tracks/1/type = "value"
tracks/1/imported = false [sub_resource type="Animation" id="Animation_3w3u1"]
tracks/1/enabled = true resource_name = "sword"
tracks/1/path = NodePath("%Effects/HealParticles:emitting") length = 0.3
tracks/1/interp = 1 tracks/0/type = "value"
tracks/1/loop_wrap = true tracks/0/imported = false
tracks/1/keys = { tracks/0/enabled = true
"times": PackedFloat32Array(0), tracks/0/path = NodePath("%Sprites/Node2D/Character:frame")
"transitions": PackedFloat32Array(1), tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1, 0.2),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 1, "update": 1,
"values": [true] "values": [12, 13, 14]
} }
[sub_resource type="AnimationLibrary" id="AnimationLibrary_73mj7"] [sub_resource type="AnimationLibrary" id="AnimationLibrary_73mj7"]

View File

@ -1,8 +1,11 @@
shader_type canvas_item; shader_type canvas_item;
render_mode blend_mix;
uniform float speed = 16; uniform float speed = 16;
uniform vec2 direction = vec2(1, 0); uniform vec2 direction = vec2(1, 0);
uniform vec4 tint_color : source_color;
void fragment() { void fragment() {
COLOR = texture(TEXTURE, UV - direction * TIME * speed); vec4 color = texture(TEXTURE, UV - direction * TIME * speed);
COLOR = color * tint_color;
} }

View File

@ -4,12 +4,17 @@ public partial class TargetTracer : Node2D
{ {
private Line2D _line; private Line2D _line;
private float Intensity private float _intensity = 127;
public float Intensity
{ {
get => SelfModulate.A; get => _intensity;
set set
{ {
SelfModulate = new Color(SelfModulate, value); var color = new Color(Colors.White, value);
(Material as ShaderMaterial)
.SetShaderParameter("tint_color", color);
_intensity = value;
} }
} }

View File

@ -3,10 +3,11 @@
[ext_resource type="Shader" path="res://Shaders/Scrolling.gdshader" id="1_1y0lt"] [ext_resource type="Shader" path="res://Shaders/Scrolling.gdshader" id="1_1y0lt"]
[ext_resource type="Script" path="res://UI/TargetTracer.cs" id="1_mtnfa"] [ext_resource type="Script" path="res://UI/TargetTracer.cs" id="1_mtnfa"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_hcccp"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_46g0j"]
shader = ExtResource("1_1y0lt") shader = ExtResource("1_1y0lt")
shader_parameter/speed = 1.0 shader_parameter/speed = 1.0
shader_parameter/direction = Vector2(1, 0) shader_parameter/direction = Vector2(1, 0)
shader_parameter/tint_color = Color(1, 1, 1, 1)
[sub_resource type="Gradient" id="Gradient_0wna6"] [sub_resource type="Gradient" id="Gradient_0wna6"]
interpolation_mode = 1 interpolation_mode = 1
@ -19,12 +20,13 @@ width = 2
height = 1 height = 1
[node name="TargetTracer" type="Node2D"] [node name="TargetTracer" type="Node2D"]
material = SubResource("ShaderMaterial_46g0j")
script = ExtResource("1_mtnfa") script = ExtResource("1_mtnfa")
[node name="Line2D" type="Line2D" parent="."] [node name="Line2D" type="Line2D" parent="."]
z_index = 31 z_index = 31
texture_repeat = 2 texture_repeat = 2
material = SubResource("ShaderMaterial_hcccp") use_parent_material = true
scale = Vector2(1, 0.5) scale = Vector2(1, 0.5)
points = PackedVector2Array(0, 0, 32, 0) points = PackedVector2Array(0, 0, 32, 0)
width = 2.0 width = 2.0