extends Node

## Fixes the tonemapping being applied twice when looking through a portal.
##
## It copies the original environment (sky and stuff) and just puts in a noop
## tonemapping (linear with exposure 1).

@export var base: WorldEnvironment

func _ready() -> void:
	var adapted_env: Environment = base.environment.duplicate(false)
	adapted_env.tonemap_mode = Environment.TONE_MAPPER_LINEAR
	# exposure is the only thing the linear tonemapper takes into account
	adapted_env.tonemap_exposure = 1
	
	for p in get_tree().get_nodes_in_group("portals"):
		if p is Portal:
			p.exit_environment = adapted_env
			
