DashBoomColorClash/scenes/World.gd

44 lines
1.4 KiB
GDScript

extends Node3D
@onready var camera: Camera3D = $Camera3D
@onready var level: Node3D = $Level
@onready var world_coloring_viewport: SubViewport = $WorldColoringViewport
@onready var player1: CharacterBody3D = $Player1
@onready var player2: CharacterBody3D = $Player2
var camera_offset: Vector3;
var world_coloring_material: ShaderMaterial
# Called when the node enters the scene tree for the first time.
func _ready():
camera_offset = camera.global_position - player1.global_position
world_coloring_material = load("res://materials/WorldColoringMaterialPass.tres")
world_coloring_material.set_shader_parameter("world_color_texture", world_coloring_viewport.get_texture())
apply_world_coloring_recursive(level)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
camera.global_position = player1.global_position + camera_offset
pass
func _physics_process(_delta):
world_coloring_material.set_shader_parameter("world_color_texture", world_coloring_viewport.get_texture())
func apply_world_coloring_recursive (node):
for child in node.get_children():
var mesh_instance := child as MeshInstance3D
if mesh_instance:
assign_world_coloring_pass(mesh_instance)
apply_world_coloring_recursive(child)
func assign_world_coloring_pass(mesh_instance: MeshInstance3D) -> void:
var material = mesh_instance.get_active_material(0)
if not material:
return
material.next_pass = world_coloring_material