abstract target cubemap_target
{
	pass clear
	{
		colour_value 0 0 0 1
	}

	pass render_scene
	{
		//Filter stuff that shouldn't be reflected (vampires?)
		visibility_mask		0x00000005
		overlays			off
		camera_cubemap_reorient true
	}

	//Render sky (see TutorialSky_Postprocess)
	pass render_quad
	{
		quad_normals	camera_direction
		material SkyPostprocess
		camera_cubemap_reorient true
	}
}

compositor_node CubemapRendererNode
{
	in 0 cubemap

	target cubemap +X : cubemap_target { }
	target cubemap -X : cubemap_target { }
	target cubemap +Y : cubemap_target { }
	target cubemap -Y : cubemap_target { }
	target cubemap +Z : cubemap_target { }
	target cubemap -Z : cubemap_target
	{
		pass generate_mipmaps
		{
		}
	}
}

compositor_node Tutorial_DynamicCubemapRenderingNode
{
	in 0 rt_renderwindow
	in 1 demo_dynamic_cubemap

	target rt_renderwindow
	{
		pass clear
		{
			colour_value 0 0 0 0 1
		}

		pass render_scene
		{
			//Our materials in this pass will be using this cubemap,
			//so we need to expose it to the pass.
			//Note: Even if it "just works" without exposing, the reason for
			//exposing is to ensure compatibility with Vulkan & D3D12.
			expose demo_dynamic_cubemap

			shadows		Tutorial_DynamicCubemapShadowNode
			overlays	off
			rq_first	0
			rq_last		2
		}

		//Render sky (see TutorialSky_Postprocess)
		pass render_quad
		{
			quad_normals	camera_direction
			material SkyPostprocess
		}

		//Render transparent stuff after sky
		pass render_scene
		{
			overlays	on
			rq_first	2
		}
	}
}

abstract target cubemap_target_shadow
{
	pass clear { colour_value 1 1 1 1 }
	pass render_scene
	{
		camera_cubemap_reorient true
	}
}

compositor_node_shadow Tutorial_DynamicCubemapShadowNode
{
	technique pssm

	texture atlas 2048 7168 PF_D32_FLOAT no_fsaa
	texture tmpCubemap 1024 1024 PF_FLOAT32_R cubemap no_fsaa

	num_splits		3
	pssm_lambda		0.95
	shadow_map 0 atlas uv 0.0 0.000000000000000 1.0 0.285714285714286 light 0 split 0
	shadow_map 1 atlas uv 0.0 0.285714285714286 0.5 0.142857142857143 light 0 split 1
	shadow_map 2 atlas uv 0.5 0.285714285714286 0.5 0.142857142857143 light 0 split 2

	technique focused
	shadow_map 3 atlas uv 0.0 0.428571428571429 1.0 0.285714285714286 light 1
	shadow_map 4 atlas uv 0.0 0.714285714285714 1.0 0.285714285714286 light 2

	target atlas
	{
		pass clear
		{
			colour_value 1 1 1 1
		}
	}

	shadow_map_target_type directional
	{
		shadow_map 0 1 2
		{
			pass render_scene
			{
			}
		}
	}

	shadow_map_target_type directional spot
	{
		shadow_map 3 4
		{
			pass render_scene
			{
			}
		}
	}

	shadow_map_target_type point
	{
		shadow_map_repeat 3 4
		{
			target tmpCubemap +X : cubemap_target_shadow {}
			target tmpCubemap -X : cubemap_target_shadow {}
			target tmpCubemap +Y : cubemap_target_shadow {}
			target tmpCubemap -Y : cubemap_target_shadow {}
			target tmpCubemap +Z : cubemap_target_shadow {}
			target tmpCubemap -Z : cubemap_target_shadow {}

			shadow_map
			{
				pass render_quad
				{
					material Ogre/DPSM/CubeToDpsm
					input 0 tmpCubemap
				}
			}
		}
	}
}

workspace Tutorial_DynamicCubemapWorkspace
{
	//Render Window on channel #0
	connect_external 0 Tutorial_DynamicCubemapRenderingNode 0
	//Cubemap on channel #1
	connect_external 1 Tutorial_DynamicCubemapRenderingNode 1
}
