// declare the vertex shader (CG for the language)
vertex_program PSSM/shadow_caster_vsCg 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_psCg 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
	{
	}
}

// declare the vertex shader (GLSL ES for the language)
vertex_program PSSM/shadow_caster_vsGLSLES glsles
{
	// source file
	source pssmCasterVp.glsles
	// will run on GLSL ES
	profiles glsles

	default_params
	{
		param_named_auto worldViewProjMatrix 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 (GLSL ES for the language)
fragment_program PSSM/shadow_caster_psGLSLES glsles
{
	// source file
	source pssmCasterFp.glsles
	// will run on GLSL ES
	profiles glsles

	default_params
	{
	}
}

// declare the vertex shader (GLSL for the language)
vertex_program PSSM/shadow_caster_vsGLSL glsl
{
	// source file
	source pssmCasterVp.glsl
	// will run on GLSL 1.50
	syntax glsl150

	default_params
	{
		param_named_auto worldViewProjMatrix 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 (GLSL for the language)
fragment_program PSSM/shadow_caster_psGLSL glsl
{
	// source file
	source pssmCasterFp.glsl
	// will run on GLSL 1.50
	syntax glsl150

	default_params
	{
	}
}

vertex_program PSSM/shadow_caster_vs unified
{
	delegate PSSM/shadow_caster_vsGLSL
	delegate PSSM/shadow_caster_vsGLSLES
	delegate PSSM/shadow_caster_vsCg
}

fragment_program PSSM/shadow_caster_ps unified
{
	delegate PSSM/shadow_caster_psGLSL
	delegate PSSM/shadow_caster_psGLSLES
	delegate PSSM/shadow_caster_psCg
}

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_vsCg 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_psCg 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
	}
}

vertex_program PSSM/shadow_receiver_vsGLSLES glsles
{
	source pssmReceiverVp.glsles
	profiles glsles

	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_psGLSLES glsles
{
	source pssmReceiverFp.glsles
	profiles glsles

	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
	}
}

vertex_program PSSM/shadow_receiver_vsGLSL glsl
{
	source pssmReceiverVp.glsl
	syntax glsl150

	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_psGLSLES glsl
{
	source pssmReceiverFp.glsl
	syntax glsl150

	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
	}
}

vertex_program PSSM/shadow_receiver_vs unified
{
	delegate PSSM/shadow_receiver_vsGLSL
	delegate PSSM/shadow_receiver_vsGLSLES
	delegate PSSM/shadow_receiver_vsCg
}

fragment_program PSSM/shadow_receiver_ps unified
{
	delegate PSSM/shadow_receiver_psGLSL
	delegate PSSM/shadow_receiver_psGLSLES
	delegate PSSM/shadow_receiver_psCg
}

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
}

