
vertex_program PlasticVP_medCG cg
{
	source materials/programs/plastic_med.cgfx
	profiles vs_1_1
	entry_point plastic_vp_simple
}
fragment_program PlasticFP_medCG cg
{
	source materials/programs/plastic_med.cgfx
	entry_point plastic_fp_simple
	profiles ps_2_0
}
vertex_program PlasticVP_gbuffer_medCG cg
{
	source materials/programs/plastic_med.cgfx
	profiles vs_1_1
	entry_point plastic_vp_simple
	
	compile_arguments -DGBUFFER
}
fragment_program PlasticFP_gbuffer_medCG cg
{
	source materials/programs/plastic_med.cgfx
	entry_point plastic_fp_simple
	profiles ps_2_x
	
	compile_arguments -DGBUFFER
}
vertex_program PlasticVP_highCG cg
{
	source materials/programs/plastic_high.cgfx
	profiles vs_1_1
	entry_point plastic_vp_precise
}
fragment_program PlasticFP_highCG cg
{
	source materials/programs/plastic_high.cgfx
	entry_point plastic_fp_precise
	profiles ps_2_x
}
vertex_program PlasticVP_high_gbufferCG cg
{
	source materials/programs/plastic_high_gbuffer.cgfx
	profiles vs_1_1
	entry_point plastic_vp_precise
}
fragment_program PlasticFP_high_gbufferCG cg
{
	source materials/programs/plastic_high_gbuffer.cgfx
	entry_point plastic_fp_precise
	profiles ps_2_x
}

// GLSL programs
vertex_program PlasticVP_medGLSL glsl
{
	source materials/programs/glsl/vert/plastic_simple.vert
	preprocessor_defines GLSL=1,GLSL_VERT=1,ENABLE_STUDS=1,SIMPLE=1
	
}
fragment_program PlasticFP_medGLSL glsl
{
	source materials/programs/glsl/frag/plastic_simple.frag
	preprocessor_defines GLSL=1,GLSL_FRAG=1,ENABLE_STUDS=1,SIMPLE=1
	default_params
	{
		param_named StudsSamp int 0
	}
}
vertex_program PlasticVP_gbuffer_medGLSL glsl
{
	source materials/programs/glsl/vert/plastic_simple.vert
	preprocessor_defines GLSL=1,GBUFFER=1,GLSL_VERT=1,ENABLE_STUDS=1,SIMPLE=1	
}
fragment_program PlasticFP_gbuffer_medGLSL glsl
{
	source materials/programs/glsl/frag/plastic_simple.frag
	preprocessor_defines GLSL=1,GBUFFER=1,GLSL_FRAG=1,ENABLE_STUDS=1,SIMPLE=1	
	default_params
	{
		param_named StudsSamp int 0
	}
}
vertex_program PlasticVP_highGLSL glsl
{
	source materials/programs/glsl/vert/plastic_precise.vert
	preprocessor_defines GLSL=1,GLSL_VERT=1,ENABLE_STUDS=1,ENABLE_REFLECTIONS=1,ENABLE_FRESNEL=1,PRECISE=1
}
fragment_program PlasticFP_highGLSL glsl
{
	source materials/programs/glsl/frag/plastic_precise.frag
	preprocessor_defines GLSL=1,GLSL_FRAG=1,ENABLE_STUDS=1,ENABLE_REFLECTIONS=1,ENABLE_FRESNEL=1,PRECISE=1
	
	default_params
	{
		param_named StudsSamp int 0
		param_named EnvSamp int 1
	}
}
vertex_program PlasticVP_high_gbufferGLSL glsl
{
	source materials/programs/glsl/vert/plastic_precise.vert
	preprocessor_defines GLSL=1,GBUFFER=1,GLSL_VERT=1,ENABLE_STUDS=1,ENABLE_REFLECTIONS=1,ENABLE_FRESNEL=1,PRECISE=1	
}
fragment_program PlasticFP_high_gbufferGLSL glsl
{
	source materials/programs/glsl/frag/plastic_precise.frag
	preprocessor_defines GLSL=1,GBUFFER=1,GLSL_FRAG=1,ENABLE_STUDS=1,ENABLE_REFLECTIONS=1,ENABLE_FRESNEL=1,PRECISE=1
	
	default_params
	{
		param_named StudsSamp int 0
		param_named EnvSamp int 1
	}
}

// unified programs
vertex_program PlasticVP_med unified
{
	delegate PlasticVP_medCG
	delegate PlasticVP_medGLSL
}
fragment_program PlasticFP_med unified
{
	delegate PlasticFP_medCG
	delegate PlasticFP_medGLSL	
}
vertex_program PlasticVP_gbuffer_med unified
{
	delegate PlasticVP_gbuffer_medCG
	delegate PlasticVP_gbuffer_medGLSL	
}
fragment_program PlasticFP_gbuffer_med unified
{
	delegate PlasticFP_gbuffer_medCG
	delegate PlasticFP_gbuffer_medGLSL	
}
vertex_program PlasticVP_high unified
{
	delegate PlasticVP_highCG
	delegate PlasticVP_highGLSL
}
fragment_program PlasticFP_high unified
{
	delegate PlasticFP_highCG
	delegate PlasticFP_highGLSL
}
vertex_program PlasticVP_high_gbuffer unified
{
	delegate PlasticVP_high_gbufferCG
	delegate PlasticVP_high_gbufferGLSL
}
fragment_program PlasticFP_high_gbuffer unified
{
	delegate PlasticFP_high_gbufferCG
	delegate PlasticFP_high_gbufferGLSL
}


//todo: need a med and high quality studless once we decide to go with high fidelidty plastic.
material PlasticStudless
{
	technique
	{
		pass
		{
			ambient vertexcolour
			diffuse vertexcolour
			specular 0.9 0.9 0.9 50
		}
	}
}

material PlasticStudlessTransparent : PlasticStudless
{
	technique
	{
		pass
		{
			scene_blend alpha_blend
			depth_write off
		}
	}
}


material PlasticStuds_Low : PlasticStudless
{
	technique
	{
		pass
		{
			texture_unit
			{
				texture_alias StudsAlways
				tex_coord_set 0
				texture textures/SurfacesAlpha.png
		        colour_op alpha_blend
				//ignore alpha from SurfaceAlpha.png. Use fixed alpha. VERY IMPORTANT FOR OFF-SCREEN RENDERING!
		        alpha_op_ex source1 src_manual src_manual 1 1 1
		        filtering trilinear
			}
		}
	}
}

material Plastic_Low : PlasticStudless
{
	technique
	{
		pass
		{
			texture_unit
			{
				texture_alias Studs
				tex_coord_set 0
				texture textures/SurfacesAlpha.png
		        colour_op alpha_blend
				//ignore alpha from SurfaceAlpha.png. Use fixed alpha. VERY IMPORTANT FOR OFF-SCREEN RENDERING!
		        alpha_op_ex source1 src_manual src_manual 1 1 1
		        filtering trilinear
			}
		}
	}
}

material PlasticStuds_Med : PlasticStudless
{
	technique
	{
		pass
		{
			max_lights 2
			
			vertex_program_ref PlasticVP_med
			{
				param_named_auto WorldITXf inverse_transpose_world_matrix
				param_named_auto WorldXf world_matrix
				param_named_auto ViewIXf inverse_view_matrix
				param_named_auto WvpXf worldviewproj_matrix
				param_named_auto WvXf worldview_matrix
				param_named_auto AmbiColor ambient_light_colour
				param_named_auto Lamp0Pos light_position 0
				param_named_auto Lamp1Pos light_position 1
				param_named_auto Lamp0Color light_diffuse_colour 0
				param_named_auto Lamp1Color light_diffuse_colour 1
			}

			fragment_program_ref PlasticFP_med
			{
				param_named_auto Lamp0Color light_diffuse_colour 0
				param_named Ks float  0.75
				param_named SpecExpon float  81
				param_named_auto FogColour fog_colour
				param_named_auto FogParams fog_params
			}
			
			texture_unit
			{
				//texture_alias StudsAlways
				texture_alias StudsSamp
				tex_coord_set 0
				texture textures/SurfacesAlpha.png
		       		filtering trilinear
			}
		}
	}
	
	technique
	{
		scheme MRT
		pass
		{
			max_lights 2
			
			vertex_program_ref PlasticVP_gbuffer_med
			{
				param_named_auto WorldITXf inverse_transpose_world_matrix
				param_named_auto WorldXf world_matrix
				param_named_auto WvXf worldview_matrix
				param_named_auto ViewIXf inverse_view_matrix
				param_named_auto WvpXf worldviewproj_matrix
				param_named_auto AmbiColor ambient_light_colour
				param_named_auto Lamp0Pos light_position 0
				param_named_auto Lamp1Pos light_position 1
				param_named_auto Lamp0Color light_diffuse_colour 0
				param_named_auto Lamp1Color light_diffuse_colour 1
			}

			fragment_program_ref PlasticFP_gbuffer_med
			{
				param_named_auto Lamp0Color light_diffuse_colour 0
				param_named Ks float  0.75
				param_named SpecExpon float  81
				param_named_auto FogColour fog_colour
				param_named_auto FogParams fog_params
			}
			
			texture_unit
			{
				//texture_alias StudsAlways
				texture_alias StudsSamp
				tex_coord_set 0
				texture textures/SurfacesAlpha.png
		       		filtering trilinear
			}
		}
	}
}

material Plastic_Med : PlasticStudless
{
	technique
	{
		pass
		{
			max_lights 2
			
			vertex_program_ref PlasticVP_med
			{
				param_named_auto WorldITXf inverse_transpose_world_matrix
				param_named_auto WorldXf world_matrix
				param_named_auto ViewIXf inverse_view_matrix
				param_named_auto WvpXf worldviewproj_matrix
				param_named_auto AmbiColor ambient_light_colour
				param_named_auto Lamp0Pos light_position 0
				param_named_auto Lamp1Pos light_position 1
				param_named_auto Lamp0Color light_diffuse_colour 0
				param_named_auto Lamp1Color light_diffuse_colour 1
			}

			fragment_program_ref PlasticFP_med
			{
				param_named_auto Lamp0Color light_diffuse_colour 0
				param_named Ks float  0.75
				param_named SpecExpon float  81
				param_named_auto FogColour fog_colour
				param_named_auto FogParams fog_params
			}
			
			texture_unit
			{
				texture_alias Studs
				tex_coord_set 0
				texture textures/SurfacesAlpha.png
		        filtering trilinear
			}
		}
	}
	
	technique
	{
		scheme MRT
		pass
		{
			max_lights 2
			
			vertex_program_ref PlasticVP_gbuffer_med
			{
				param_named_auto WorldITXf inverse_transpose_world_matrix
				param_named_auto WorldXf world_matrix
				param_named_auto ViewIXf inverse_view_matrix
				param_named_auto WvpXf worldviewproj_matrix
				param_named_auto WvXf worldview_matrix
				param_named_auto AmbiColor ambient_light_colour
				param_named_auto Lamp0Pos light_position 0
				param_named_auto Lamp1Pos light_position 1
				param_named_auto Lamp0Color light_diffuse_colour 0
				param_named_auto Lamp1Color light_diffuse_colour 1
			}

			fragment_program_ref PlasticFP_gbuffer_med
			{
				param_named_auto Lamp0Color light_diffuse_colour 0
				param_named Ks float  0.75
				param_named SpecExpon float  81
				param_named_auto FogColour fog_colour
				param_named_auto FogParams fog_params
			}
			
			texture_unit
			{
				texture_alias Studs
				tex_coord_set 0
				texture textures/SurfacesAlpha.png
		        filtering trilinear
			}
		}
	}
}

material PlasticStuds_High : PlasticStudless
{
	technique
	{
		lod_index 0
		pass
		{
			max_lights 2
			
			vertex_program_ref PlasticVP_high
			{
				param_named_auto WorldITXf inverse_transpose_world_matrix
				param_named_auto WorldXf world_matrix
				param_named_auto WvXf worldview_matrix
				param_named_auto ViewIXf inverse_view_matrix
				param_named_auto WvpXf worldviewproj_matrix
				param_named_auto Lamp0Pos light_position 0
				param_named_auto Lamp1Pos light_position 1
			}

			fragment_program_ref PlasticFP_high
			{
				param_named Ks float  0.75
				param_named SpecExpon float  81

				param_named_auto AmbiColor ambient_light_colour
				param_named_auto Lamp0Color light_diffuse_colour 0
				param_named_auto Lamp1Color light_diffuse_colour 1

				// lerp Kr and FresnelMin towards 1,1 according to sqrt of reflection parameter (since they are multiplied)
				// to emulate legacy style reflection paramter. reflection parameter expected to be [0..1] range.
				// if you change these, remember to change matching hard-coded parameters in-engine (look for Kr and FresnelMin)
				param_named Kr float 0.45
				param_named FresnelMin float 0.05
				param_named FresnelExp float 3.55
				param_named_auto FogColour fog_colour
				param_named_auto FogParams fog_params
			}
			
			texture_unit
			{
				texture_alias StudsAlways
				tex_coord_set 0
				texture textures/SurfacesAlpha.png
		        filtering trilinear
			}
			
			texture_unit
			{
				texture_alias SkyBox
				tex_coord_set 1
				texture textures/penv.dds cubic
		        filtering trilinear
			}
		}
	}

	technique
	{
		scheme MRT
		lod_index 0
		pass
		{
			max_lights 2
			
			vertex_program_ref PlasticVP_high_gbuffer
			{
				param_named_auto WorldITXf inverse_transpose_world_matrix
				param_named_auto WorldXf world_matrix
				param_named_auto ViewIXf inverse_view_matrix
				param_named_auto WvpXf worldviewproj_matrix
				param_named_auto WvXf worldview_matrix
				param_named_auto Lamp0Pos light_position 0
				param_named_auto Lamp1Pos light_position 1
			}

			fragment_program_ref PlasticFP_high_gbuffer
			{
				param_named Ks float  0.75
				param_named SpecExpon float  81

				param_named_auto AmbiColor ambient_light_colour
				param_named_auto Lamp0Color light_diffuse_colour 0
				param_named_auto Lamp1Color light_diffuse_colour 1

				// lerp Kr and FresnelMin towards 1,1 according to sqrt of reflection parameter (since they are multiplied)
				// to emulate legacy style reflection paramter. reflection parameter expected to be [0..1] range.
				// if you change these, remember to change matching hard-coded parameters in-engine (look for Kr and FresnelMin)
				param_named Kr float 0.45
				param_named FresnelMin float 0.05
				param_named FresnelExp float 3.55
				param_named_auto FogColour fog_colour
				param_named_auto FogParams fog_params
			}
			
			texture_unit
			{
				texture_alias StudsAlways
				tex_coord_set 0
				texture textures/SurfacesAlpha.png
		        filtering trilinear
			}
			
			texture_unit
			{
				texture_alias SkyBox
				tex_coord_set 1
				texture textures/penv.dds cubic
		        filtering trilinear
			}
		}
	}

}

material Plastic_High : PlasticStudless
{
	technique
	{
		lod_index 0
		pass
		{
			max_lights 2
			
			vertex_program_ref PlasticVP_high
			{
				param_named_auto WorldITXf inverse_transpose_world_matrix
				param_named_auto WorldXf world_matrix
				param_named_auto WvXf worldview_matrix
				param_named_auto ViewIXf inverse_view_matrix
				param_named_auto WvpXf worldviewproj_matrix
				param_named_auto Lamp0Pos light_position 0
				param_named_auto Lamp1Pos light_position 1
			}

			fragment_program_ref PlasticFP_high
			{
				param_named Ks float  0.75
				param_named SpecExpon float  81

				param_named_auto AmbiColor ambient_light_colour
				param_named_auto Lamp0Color light_diffuse_colour 0
				param_named_auto Lamp1Color light_diffuse_colour 1

				// lerp Kr and FresnelMin towards 1,1 according to sqrt of reflection parameter (since they are multiplied)
				// to emulate legacy style reflection paramter. reflection parameter expected to be [0..1] range.
				// if you change these, remember to change matching hard-coded parameters in-engine (look for Kr and FresnelMin)
				param_named Kr float 0.45
				param_named FresnelMin float 0.05
				param_named FresnelExp float 3.55
				param_named_auto FogColour fog_colour
				param_named_auto FogParams fog_params
			}
			
			texture_unit
			{
				texture_alias Studs
				tex_coord_set 0
				texture textures/SurfacesAlpha.png
		        filtering trilinear
			}
			
			texture_unit
			{
				texture_alias SkyBox
				tex_coord_set 1
				texture textures/penv.dds cubic
		        filtering trilinear
			}
		}
	}
	 
	technique
	{
		scheme MRT
		lod_index 0
		pass
		{
			max_lights 2
			
			vertex_program_ref PlasticVP_high_gbuffer
			{
				param_named_auto WorldITXf inverse_transpose_world_matrix
				param_named_auto WorldXf world_matrix
				param_named_auto ViewIXf inverse_view_matrix
				param_named_auto WvpXf worldviewproj_matrix
				param_named_auto WvXf worldview_matrix
				param_named_auto Lamp0Pos light_position 0
				param_named_auto Lamp1Pos light_position 1
			}

			fragment_program_ref PlasticFP_high_gbuffer
			{
				param_named Ks float  0.75
				param_named SpecExpon float  81

				param_named_auto AmbiColor ambient_light_colour
				param_named_auto Lamp0Color light_diffuse_colour 0
				param_named_auto Lamp1Color light_diffuse_colour 1

				// lerp Kr and FresnelMin towards 1,1 according to sqrt of reflection parameter (since they are multiplied)
				// to emulate legacy style reflection paramter. reflection parameter expected to be [0..1] range.
				// if you change these, remember to change matching hard-coded parameters in-engine (look for Kr and FresnelMin)
				param_named Kr float 0.45
				param_named FresnelMin float 0.05
				param_named FresnelExp float 3.55
				param_named_auto FogColour fog_colour
				param_named_auto FogParams fog_params
			}
			
			texture_unit
			{
				texture_alias Studs
				tex_coord_set 0
				texture textures/SurfacesAlpha.png
		        filtering trilinear
			}
			
			texture_unit
			{
				texture_alias SkyBox
				tex_coord_set 1
				texture textures/penv.dds cubic
		        filtering trilinear
			}
		}
	}

}
material PlasticTransparent_Low : Plastic_Low
{
	technique
	{
		pass
		{
			scene_blend alpha_blend
			depth_write off

			texture_unit
			{
				//ignore alpha from SurfaceAlpha.png. Use alpha from vertices.
		        alpha_op_ex source1 src_diffuse src_texture
			}
		}
	}
}

material PlasticStudsTransparent_Low : PlasticStuds_Low
{
	technique
	{
		pass
		{
			scene_blend alpha_blend
			depth_write off

			texture_unit
			{
				//ignore alpha from SurfaceAlpha.png. Use alpha from vertices.
		        alpha_op_ex source1 src_diffuse src_texture
			}
		}
	}
}


material PlasticTransparent_Med : Plastic_Med
{
	technique
	{
		pass
		{
			scene_blend alpha_blend
			depth_write off
		}
	}
}
material PlasticStudsTransparent_Med : PlasticStuds_Med
{
	technique
	{
		pass
		{
			scene_blend alpha_blend
			depth_write off
		}
	}
}
material PlasticTransparent_High : Plastic_High
{
	technique
	{
		pass
		{
			scene_blend alpha_blend
			depth_write off
		}
	}
}
material PlasticStudsTransparent_High : PlasticStuds_High
{
	technique
	{
		pass
		{
			scene_blend alpha_blend
			depth_write off
		}
	}
}

