DashBoomColorClash/scenes/World.gd

44 lines
1.4 KiB
GDScript
Raw Normal View History

2024-01-26 21:07:19 +01:00
extends Node3D
@onready var camera: Camera3D = $Camera3D
2024-01-27 00:05:04 +01:00
@onready var level: Node3D = $Level
@onready var world_coloring_viewport: SubViewport = $WorldColoringViewport
2024-01-27 01:41:29 +01:00
@onready var player1: CharacterBody3D = $Player1
@onready var player2: CharacterBody3D = $Player2
2024-01-26 21:07:19 +01:00
var camera_offset: Vector3;
2024-01-27 00:05:04 +01:00
var world_coloring_material: ShaderMaterial
2024-01-26 21:07:19 +01:00
# Called when the node enters the scene tree for the first time.
func _ready():
camera_offset = camera.global_position - player1.global_position
2024-01-27 00:05:04 +01:00
world_coloring_material = load("res://materials/WorldColoringMaterialPass.tres")
world_coloring_material.set_shader_parameter("world_color_texture", world_coloring_viewport.get_texture())
2024-01-27 00:05:04 +01:00
apply_world_coloring_recursive(level)
2024-01-26 21:07:19 +01:00
# Called every frame. 'delta' is the elapsed time since the previous frame.
2024-01-27 00:05:04 +01:00
func _process(_delta):
2024-01-26 21:07:19 +01:00
camera.global_position = player1.global_position + camera_offset
pass
2024-01-27 00:05:04 +01:00
func _physics_process(_delta):
world_coloring_material.set_shader_parameter("world_color_texture", world_coloring_viewport.get_texture())
2024-01-27 00:05:04 +01:00
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