very starty setup
This commit is contained in:
30
root.gd
Normal file
30
root.gd
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
extends Node2D
|
||||||
|
|
||||||
|
@onready var sim_viewport := $SubViewport
|
||||||
|
@onready var display_sprite := $Sprite2D
|
||||||
|
|
||||||
|
var tex_a: Texture2D
|
||||||
|
var tex_b: Texture2D
|
||||||
|
var swap = false
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
# Create textures
|
||||||
|
tex_a = ImageTexture.create_from_image(
|
||||||
|
Image.create(sim_viewport.size.x, sim_viewport.size.y, false, Image.FORMAT_RGBAF)
|
||||||
|
)
|
||||||
|
tex_b = tex_a.duplicate()
|
||||||
|
|
||||||
|
# Assign one texture to the simulation shader as input
|
||||||
|
$SubViewport/ColorRect.material.set("shader_parameter/trail_tex", tex_a)
|
||||||
|
display_sprite.texture = tex_a
|
||||||
|
|
||||||
|
func _process(_delta):
|
||||||
|
# Swap textures each frame
|
||||||
|
swap = !swap
|
||||||
|
var src = tex_a if swap else tex_b
|
||||||
|
var dst = tex_b if swap else tex_a
|
||||||
|
|
||||||
|
# Assign src as input and dst as render target
|
||||||
|
$SubViewport/ColorRect.material.set("shader_parameter/trail_tex", src)
|
||||||
|
sim_viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS
|
||||||
|
display_sprite.texture = dst
|
||||||
1
root.gd.uid
Normal file
1
root.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://d1bbllvcal2uw
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
shader_type canvas_item;
|
shader_type canvas_item;
|
||||||
|
|
||||||
|
uniform sampler2D trail_tex;
|
||||||
|
|
||||||
uniform float sensor_distance = 2.0;
|
uniform float sensor_distance = 2.0;
|
||||||
uniform float sensor_angle = 15.0;
|
uniform float sensor_angle = 15.0;
|
||||||
uniform float rotation_angle = 23.0;
|
uniform float rotation_angle = 23.0;
|
||||||
@@ -7,10 +9,11 @@ uniform float move_distance = 2.67;
|
|||||||
uniform float decay_factor = 0.75;
|
uniform float decay_factor = 0.75;
|
||||||
|
|
||||||
void fragment() {
|
void fragment() {
|
||||||
COLOR = vec4(0.05, 0.05, 0.05, 1.0);
|
vec2 uv = UV;
|
||||||
}
|
// Read current trail value
|
||||||
|
vec4 trail = texture(trail_tex, uv);
|
||||||
//void light() {
|
// Apply decay
|
||||||
// // Called for every pixel for every light affecting the CanvasItem.
|
trail *= decay_factor;
|
||||||
// // Uncomment to replace the default light processing function with this one.
|
|
||||||
//}
|
COLOR = trail;
|
||||||
|
}
|
||||||
28
root.tscn
28
root.tscn
@@ -1,6 +1,15 @@
|
|||||||
[gd_scene load_steps=4 format=3 uid="uid://bf4ohdg0sfl8l"]
|
[gd_scene load_steps=5 format=3 uid="uid://bf4ohdg0sfl8l"]
|
||||||
|
|
||||||
[ext_resource type="Shader" uid="uid://b3wu436nky225" path="res://root.gdshader" id="1_pq8q7"]
|
[ext_resource type="Shader" uid="uid://b3wu436nky225" path="res://root.gdshader" id="1_pq8q7"]
|
||||||
|
[ext_resource type="Script" uid="uid://d1bbllvcal2uw" path="res://root.gd" id="1_pyidc"]
|
||||||
|
|
||||||
|
[sub_resource type="ShaderMaterial" id="ShaderMaterial_pq8q7"]
|
||||||
|
shader = ExtResource("1_pq8q7")
|
||||||
|
shader_parameter/sensor_distance = 2.0
|
||||||
|
shader_parameter/sensor_angle = 15.0
|
||||||
|
shader_parameter/rotation_angle = 23.0
|
||||||
|
shader_parameter/move_distance = 2.67
|
||||||
|
shader_parameter/decay_factor = 0.75
|
||||||
|
|
||||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_pyidc"]
|
[sub_resource type="ShaderMaterial" id="ShaderMaterial_pyidc"]
|
||||||
shader = ExtResource("1_pq8q7")
|
shader = ExtResource("1_pq8q7")
|
||||||
@@ -10,12 +19,15 @@ shader_parameter/rotation_angle = 23.0
|
|||||||
shader_parameter/move_distance = 2.67
|
shader_parameter/move_distance = 2.67
|
||||||
shader_parameter/decay_factor = 0.75
|
shader_parameter/decay_factor = 0.75
|
||||||
|
|
||||||
[sub_resource type="QuadMesh" id="QuadMesh_vvh5c"]
|
|
||||||
material = SubResource("ShaderMaterial_pyidc")
|
|
||||||
size = Vector2(1152, 648)
|
|
||||||
|
|
||||||
[node name="Node2D" type="Node2D"]
|
[node name="Node2D" type="Node2D"]
|
||||||
|
script = ExtResource("1_pyidc")
|
||||||
|
|
||||||
[node name="MeshInstance2D" type="MeshInstance2D" parent="."]
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
position = Vector2(576, 324)
|
material = SubResource("ShaderMaterial_pq8q7")
|
||||||
mesh = SubResource("QuadMesh_vvh5c")
|
|
||||||
|
[node name="SubViewport" type="SubViewport" parent="."]
|
||||||
|
|
||||||
|
[node name="ColorRect" type="ColorRect" parent="SubViewport"]
|
||||||
|
material = SubResource("ShaderMaterial_pyidc")
|
||||||
|
offset_right = 40.0
|
||||||
|
offset_bottom = 40.0
|
||||||
|
|||||||
Reference in New Issue
Block a user