compositor_node Tutorial_ReconstructPosFromDepthNode
{
	in 0 rt_renderwindow
	
	//Inform that we want to use a depth texture, the format and pool ID must match
	//We don't read the depth buffer directly from rt_renderwindow because OpenGL doesn't support it.
	//(D3D11 does though, and will work)
	texture rt0 target_width target_height PF_R8G8B8 depth_texture depth_format PF_D32_FLOAT depth_pool 2

	//The depthTexture will be a "view" to rt0's depth because it has the exact same parameters
	//(PF_D32_FLOAT, pool ID = 2; rt0 was asked to use a depth_texture)
	//
	//Note that other RTTs may share the same depth buffer if they have the same parameters as well due
	//to depth buffer sharing (depth_pool 65534 is a special pool where sharing is disabled so each RTT gets
	//its own depth buffer/texture; depth textures are by default placed there so we need to explicitly set
	//it to 2).
	texture depthTexture target_width target_height PF_D32_FLOAT depth_pool 2
	
	//This depthTexture will be a copy of the original. We can read from 'depthTexture' directly, however
	//on a lot of HW reading from the depth texture means it needs to be decompressed. If you later
	//need to keep rendering using the same depth buffer (something very common in most use cases
	//for this technique) you will pay the performance price for using a decompressed buffer.
	//See section '4.1.4.2 Depth Textures' of the manual for an explanation.
	texture depthTextureCopy target_width target_height PF_D32_FLOAT

	target rt0
	{
		pass clear
		{
			colour_value 0.2 0.4 0.6 1
		}

		pass render_scene
		{
			overlays	off
		}
	}
	
	target rt_renderwindow
	{
		pass clear
		{
			colour_value 1 0 0 0
			buffers			colour
			discard_only	true
		}
		
		pass depth_copy
		{
			//When alias_on_copy_failure is on, if the copy fails (i.e. hardware doesn't support it)
			//then 'depthTextureCopy' will internally point to the same buffer as depthTexture.
			//For a lot of cases this is harmless and a nice fallback.
			alias_on_copy_failure	on
			in		depthTexture
			out		depthTextureCopy
		}
		
		pass render_quad
		{
			material ReconstructPosFromDepth
	    	input 0 depthTextureCopy

			quad_normals	camera_far_corners_view_space
		}
		
		pass render_scene
		{
			lod_update_list	off

			//Render Overlays
			overlays	on
			rq_first	254
			rq_last		255
		}
	}
}

workspace Tutorial_ReconstructPosFromDepthWorkspace
{
	connect_output Tutorial_ReconstructPosFromDepthNode 0
}
