// declare the vertex shader (CG for the language)
vertex_program PSSM/shadow_caster_vs cg
{
	// source file
	source pssm.cg
	// will run on vertex shader 1.1+
	profiles vs_1_1 arbvp1
	// entry function
	entry_point shadow_caster_vs

	default_params
	{
		param_named_auto wvpMat worldviewproj_matrix
		// this is the scene's depth range
		//param_named_auto depthRange			scene_depth_range
		//param_named_auto optimalAdustFactor	custom 0
	}
}

// declare the fragment shader (CG for the language)
fragment_program PSSM/shadow_caster_ps cg
{
	// source file
	source pssm.cg
	// will run on pixel shader 2.0+
	profiles ps_2_0 arbfp1
	// entry function
	entry_point shadow_caster_ps

	default_params
	{
	}
}

material PSSM/shadow_caster
{
	technique
	{
		// all this will do is write depth and depth˛ to red and green
		pass
		{
			vertex_program_ref PSSM/shadow_caster_vs
			{
			}

			fragment_program_ref PSSM/shadow_caster_ps
			{
			}
		}
	}
}



vertex_program PSSM/shadow_receiver_vs cg
{
	source pssm.cg
	profiles vs_1_1 arbvp1
	entry_point shadow_receiver_vs

	default_params
	{
		param_named_auto lightPosition				light_position_object_space 0
		param_named_auto eyePosition				camera_position_object_space
		param_named_auto worldViewProjMatrix		worldviewproj_matrix
		param_named_auto texWorldViewProjMatrix0	texture_worldviewproj_matrix 0
		param_named_auto texWorldViewProjMatrix1	texture_worldviewproj_matrix 1
		param_named_auto texWorldViewProjMatrix2	texture_worldviewproj_matrix 2
		//param_named_auto depthRange0				shadow_scene_depth_range 0
		//param_named_auto depthRange1				shadow_scene_depth_range 1
		//param_named_auto depthRange2				shadow_scene_depth_range 2
	}
}

fragment_program PSSM/shadow_receiver_ps cg
{
	source pssm.cg
	profiles ps_2_x arbfp1
	entry_point shadow_receiver_ps

	default_params
	{
		param_named_auto lightDiffuse		derived_light_diffuse_colour 0
		param_named_auto lightSpecular		derived_light_specular_colour 0
		param_named_auto ambient			derived_ambient_light_colour 
		param_named_auto invShadowMapSize0	inverse_texture_size 0
		param_named_auto invShadowMapSize1	inverse_texture_size 1
		param_named_auto invShadowMapSize2	inverse_texture_size 2
		//param_named pssmSplitPoints MANUAL
	}
}


abstract material PSSM/base_receiver
{
	technique
	{
		pass
		{
			ambient 1 1 1 1
			diffuse 1 1 1 1

			vertex_program_ref PSSM/shadow_receiver_vs {}
			fragment_program_ref PSSM/shadow_receiver_ps {}

			texture_unit shadow_tex0
			{
				content_type shadow
				tex_address_mode clamp
			}
			texture_unit shadow_tex1
			{
				content_type shadow
				tex_address_mode clamp
			}
			texture_unit shadow_tex2
			{
				content_type shadow
				tex_address_mode clamp
			}

			texture_unit diffuse_tex
			{
				texture $diffuse
			}
		}
	}
}

material PSSM/Plane : PSSM/base_receiver
{
	set $diffuse BumpyMetal.jpg
}

material PSSM/Knot : PSSM/base_receiver
{
	set $diffuse MtlPlat2.jpg
}

