
vertex_program RustVPCG cg
{
	source materials/programs/rust.cgfx
	profiles vs_1_1
	entry_point NoiseVS
}
fragment_program RustFPCG cg
{
	source materials/programs/rust.cgfx
	entry_point mainPSStuds
	profiles ps_2_x

}
vertex_program RustVP_gbufferCG cg
{
	source materials/programs/rust.cgfx
	profiles vs_1_1
	entry_point NoiseVS
	
	compile_arguments -DGBUFFER
}
fragment_program RustFP_gbufferCG cg
{
	source materials/programs/rust.cgfx
	entry_point mainPSStuds
	profiles ps_2_x
	
	compile_arguments -DGBUFFER
}

// GLSL programs
vertex_program RustVPGLSL glsl
{
	source materials/programs/glsl/vert/noise.vert
	preprocessor_defines GLSL=1,GLSL_VERT=1

}
fragment_program RustFPGLSL glsl
{
	source materials/programs/glsl/frag/rust.frag
	preprocessor_defines GLSL=1,GLSL_FRAG=1
	default_params
	{
		param_named StudsSamp int 0
		param_named NoiseSamp int 1
		param_named RustSamp int 2
		param_named NormalSamp int 3
	}
}
vertex_program RustVP_gbufferGLSL glsl
{
	source materials/programs/glsl/vert/noise.vert
	preprocessor_defines GLSL=1,GLSL_VERT=1,GBUFFER=1

}
fragment_program RustFP_gbufferGLSL glsl
{
	source materials/programs/glsl/frag/rust.frag
	preprocessor_defines GLSL=1,GLSL_FRAG=1,GBUFFER=1
	default_params
	{
		param_named StudsSamp int 0
		param_named NoiseSamp int 1
		param_named RustSamp int 2
		param_named NormalSamp int 3
	}
}

// Unified programs
vertex_program RustVP unified
{
	delegate RustVPCG
	delegate RustVPGLSL

}
fragment_program RustFP unified
{
	delegate RustFPCG
	delegate RustFPGLSL
}
vertex_program RustVP_gbuffer unified
{
	delegate RustVP_gbufferCG
	delegate RustVP_gbufferGLSL

}
fragment_program RustFP_gbuffer unified
{
	delegate RustFP_gbufferCG
	delegate RustFP_gbufferGLSL
}

material Rust_Low
{
	technique lod1
	{
		pass
		{
			// set ambient and diffuse colors to Lerp(WoodColor1, WoodColor2, MixedColorRatio)
			// set specular to Lerp(Ks1, Ks2, MixedColorRatio) SpecExpo
			
			ambient vertexcolour
			diffuse vertexcolour
			specular 0.12 0.12 0.12 70
			// mimic current wood shader limitation
			max_lights 2
		
			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 Rust_Med 
{
	technique LegacyFF_lod0
	{
		lod_index 0
		pass
		{
			ambient vertexcolour
			diffuse vertexcolour
			specular 0.12 0.12 0.12 70
			// mimic current rust shader limitation
			max_lights 2
			
			
			texture_unit
			{
				tex_coord_set 1
				texture textures/rust_combined.png
		        filtering trilinear
				colour_op alpha_blend
		        //Rotate(37)*Scale(0.0625)
		        transform 0.05 0.0376 0 0	-0.0376 0.05 0 0	0 0 0 0.0625		0 0 0 1
		         filtering trilinear
			}
			
			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 Rust_High : Rust_Low
{ 
	lod_distances 320.0 

	technique Procedural_lod0
	{
		lod_index 0

		pass
		{
			max_lights 2
			
			vertex_program_ref RustVP
			{
				param_named_auto Lamp0Pos light_position 0
				param_named_auto Lamp1Pos light_position 1
				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 WorldXf world_matrix
				param_named_auto WvXf worldview_matrix
				param_named NormMapScale float  0.15
				param_named Transform3DNoiseCoordinates float 1
				param_named FadeDistance float 200
			}

			fragment_program_ref RustFP
			{
				param_named_auto AmbiColor ambient_light_colour
				param_named_auto Lamp0Color light_diffuse_colour 0
				param_named_auto Lamp1Color light_diffuse_colour 1
				param_named Contrast float3  0.1 0.1 0.1
				param_named Ks float  0.12
				param_named SpecExpon float  70
				param_named NoiseScale float3  0.02083 0.0693 0.2083
				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
			{
				tex_coord_set 1
				texture textures/noiseL8_32x32x32.dds 3d
		        filtering trilinear
			}
			texture_unit
			{
				tex_coord_set 2
				texture textures/RustGradient.png
		        filtering trilinear
		        tex_address_mode clamp
			}
			texture_unit
			{
				tex_coord_set 3
				texture textures/Sand_Normal.dds
		        filtering trilinear
			}

		}
		
	}

	technique
	{
		lod_index 0
		
		scheme MRT

		pass
		{
			max_lights 2
			
			vertex_program_ref RustVP_gbuffer
			{
				param_named_auto Lamp0Pos light_position 0
				param_named_auto Lamp1Pos light_position 1
				param_named_auto WorldITXf inverse_transpose_world_matrix
				param_named_auto ViewIXf inverse_view_matrix
				param_named_auto WvpXf worldviewproj_matrix
				param_named_auto WorldXf world_matrix
				param_named_auto WvXf worldview_matrix
				param_named NormMapScale float  0.15
				param_named Transform3DNoiseCoordinates float 1
				param_named FadeDistance float 200
			}

			fragment_program_ref RustFP_gbuffer
			{
				param_named_auto AmbiColor ambient_light_colour
				param_named_auto Lamp0Color light_diffuse_colour 0
				param_named_auto Lamp1Color light_diffuse_colour 1
				param_named Contrast float3  0.1 0.1 0.1
				param_named Ks float  0.12
				param_named SpecExpon float  70
				param_named NoiseScale float3  0.02083 0.0693 0.2083
				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
			{
				tex_coord_set 1
				texture textures/noiseL8_32x32x32.dds 3d
		        filtering trilinear
		        tex_address_mode wrap wrap wrap
			}
			texture_unit
			{
				tex_coord_set 2
				texture textures/RustGradient.png
		        filtering trilinear
		        tex_address_mode clamp
			}
			texture_unit
			{
				tex_coord_set 3
				texture textures/Sand_Normal.dds
		        filtering trilinear
			}

		}
		
	}
		
	technique lod1
	{
		lod_index 1
	}
}


