shader_type spatial;
render_mode unshaded;


uniform sampler2D albedo: hint_default_black, source_color;

varying float pixel_distance;

void vertex() {
	// Calculate the world-space distance between the pixel and camera.
	// Pass the distance to the fragment shader using a varying attribute.
	vec3 world_position = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
	vec3 camera_position = (INV_VIEW_MATRIX * vec4(0.0, 0.0, 0.0, 1.0)).xyz;

	pixel_distance = distance(world_position, camera_position);
}

void fragment() {
	// The portal color is simply the screen-space color of the exit camera render target.
	// This is because the exit camera views the exit portal from the perspective of the player watching
	// the entrance portal, meaning the exit portal will occupy the same screen-space as the entrance portal.
	vec3 portal_color = texture(albedo, SCREEN_UV).rgb;

	ALBEDO = portal_color;
}
