Skip to content

Commit

Permalink
Merge pull request #452 from Malcolmnixon/teleport-beam
Browse files Browse the repository at this point in the history
Backport teleport beam options from master into 3.x maintenance branch.
  • Loading branch information
BastiaanOlij authored Apr 18, 2023
2 parents c2febeb + 43f4a76 commit 19e6a45
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 14 deletions.
40 changes: 39 additions & 1 deletion assets/meshes/teleport/teleport.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ export (String, FILE, '*.tscn') var scene : String
export var title: Texture setget _set_title

## Can Teleporter be used
export var active := true
export var active : bool = true setget _set_active

## Is teleport beam visible if inactive
export var inactive_beam_visible: bool = false setget _set_inactive_beam_visible

## The beam color in active state
export var active_beam_color: Color = Color("#2b40f8") setget _set_active_beam_color

## The beam color in inactive state
export var inactive_beam_color: Color = Color("#ad0400") setget _set_inactive_beam_color


# Scene base to trigger loading
Expand All @@ -22,6 +31,7 @@ onready var _scene_base: XRToolsSceneBase = get_node(scene_base)

func _ready():
_update_title()
_update_teleport()


# Called when the player enters the teleport area
Expand Down Expand Up @@ -59,3 +69,31 @@ func _update_title():
if title:
var material: ShaderMaterial = $TeleportBody/Top.get_active_material(1)
material.set_shader_param("Title", title)

func _set_active(value):
active = value
if is_inside_tree():
_update_teleport()

func _set_active_beam_color(value):
active_beam_color = value
if is_inside_tree():
_update_teleport()

func _set_inactive_beam_color(value):
inactive_beam_color = value
if is_inside_tree():
_update_teleport()

func _set_inactive_beam_visible(value):
inactive_beam_visible = value
if is_inside_tree():
_update_teleport()

func _update_teleport():
if active:
$TeleportArea/Cylinder.get_surface_material(0).set_shader_param("beam_color", active_beam_color)
$TeleportArea/Cylinder.visible = true
else:
$TeleportArea/Cylinder.get_surface_material(0).set_shader_param("beam_color", inactive_beam_color)
$TeleportArea/Cylinder.visible = inactive_beam_visible
29 changes: 17 additions & 12 deletions assets/meshes/teleport/teleport_area_shader.tres
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
output_port_for_preview = 0
function = 17

[sub_resource type="VisualShaderNodeColorConstant" id=13]
constant = Color( 0.169944, 0.249712, 0.97294, 1 )

[sub_resource type="VisualShaderNodeInput" id=14]
input_name = "time"

Expand Down Expand Up @@ -43,10 +40,16 @@ default_input_values = [ 0, 1.0, 1, 0.4, 2, 0.0 ]
output_port_for_preview = 0
operator = 7

[sub_resource type="VisualShaderNodeColorUniform" id=35]
uniform_name = "beam_color"
default_value_enabled = true
default_value = Color( 0.168627, 0.25098, 0.972549, 1 )

[sub_resource type="VisualShader" id=22]
code = "shader_type spatial;
render_mode blend_add, cull_disabled, specular_schlick_ggx, unshaded;
render_mode blend_add, cull_disabled, specular_schlick_ggx, async_visible, unshaded;

uniform vec4 beam_color : hint_color = vec4(0.168627, 0.250980, 0.972549, 1.000000);



Expand All @@ -56,9 +59,9 @@ void vertex() {
}

void fragment() {
// Color:19
vec3 n_out19p0 = vec3(0.169944, 0.249712, 0.972940);
float n_out19p1 = 1.000000;
// ColorUniform:53
vec3 n_out53p0 = beam_color.rgb;
float n_out53p1 = beam_color.a;

// Input:2
float n_out2p0 = TIME;
Expand Down Expand Up @@ -98,7 +101,7 @@ void fragment() {
float n_out49p0 = n_out52p0 * n_in49p1;

// VectorOp:40
vec3 n_out40p0 = n_out19p0 * vec3(n_out49p0);
vec3 n_out40p0 = n_out53p0 * vec3(n_out49p0);

// Output:0
ALBEDO = n_out40p0;
Expand All @@ -111,7 +114,7 @@ void light() {

}
"
graph_offset = Vector2( 736.672, -32.0883 )
graph_offset = Vector2( -194.801, -246.485 )
modes/blend = 1
modes/cull = 2
flags/unshaded = true
Expand All @@ -122,8 +125,6 @@ nodes/fragment/5/node = SubResource( 21 )
nodes/fragment/5/position = Vector2( -360, 160 )
nodes/fragment/12/node = SubResource( 8 )
nodes/fragment/12/position = Vector2( 340, 60 )
nodes/fragment/19/node = SubResource( 13 )
nodes/fragment/19/position = Vector2( 1365, -84 )
nodes/fragment/25/node = SubResource( 19 )
nodes/fragment/25/position = Vector2( -140, -20 )
nodes/fragment/26/node = SubResource( 23 )
Expand All @@ -140,7 +141,11 @@ nodes/fragment/51/node = SubResource( 33 )
nodes/fragment/51/position = Vector2( 640, 140 )
nodes/fragment/52/node = SubResource( 34 )
nodes/fragment/52/position = Vector2( 980, 40 )
nodes/fragment/connections = PoolIntArray( 2, 0, 25, 0, 5, 0, 26, 0, 25, 0, 27, 0, 26, 0, 27, 1, 27, 0, 12, 0, 49, 0, 0, 1, 40, 0, 0, 0, 49, 0, 40, 1, 19, 0, 40, 0, 12, 0, 50, 2, 12, 0, 51, 2, 50, 0, 52, 0, 51, 0, 52, 1, 52, 0, 49, 0 )
nodes/fragment/53/node = SubResource( 35 )
nodes/fragment/53/position = Vector2( 1200, -220 )
nodes/fragment/connections = PoolIntArray( 2, 0, 25, 0, 5, 0, 26, 0, 25, 0, 27, 0, 26, 0, 27, 1, 27, 0, 12, 0, 49, 0, 0, 1, 40, 0, 0, 0, 49, 0, 40, 1, 12, 0, 50, 2, 12, 0, 51, 2, 50, 0, 52, 0, 51, 0, 52, 1, 52, 0, 49, 0, 53, 0, 40, 0 )

[resource]
resource_local_to_scene = true
shader = SubResource( 22 )
shader_param/beam_color = Color( 0.168627, 0.25098, 0.972549, 1 )
1 change: 0 additions & 1 deletion scenes/main_menu/main_menu_level.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ func _update_demo_positions() -> void:
var count = 0
var visible_children := []
for teleporter in $Demos.get_children():
teleporter.active = teleporter.visible
teleporter.set_collision_disabled(!teleporter.visible)
if teleporter.visible:
count += 1
Expand Down

0 comments on commit 19e6a45

Please sign in to comment.