<?xml version="1.0" encoding="utf-8"?>
<!--
	GrainShader
	Shader to animate a dynamic grainplane
	
	Author: Manuel Leithner - SFM-Modding
	Date:	19.05.2011
	
	Copyright 2011 - SFM-Modding
	free for noncommerical-usage
-->
<CustomShader version="1.0" classRequirement="">
    <LodLevel startDistance="0">
        <Parameters>
			<Parameter name="c1" target="In.mat.c1" type="float4" />
			<Parameter name="c2" target="In.mat.c2" type="float4" />
			<Parameter name="c3" target="In.mat.c3" type="float4" />
			<Parameter name="c4" target="In.mat.c4" type="float4" />
			<Parameter name="c5" target="In.mat.c5" type="float4" />
			<Parameter name="c6" target="In.mat.c6" type="float4" />
			<Parameter name="c7" target="In.mat.c7" type="float4" />
			<Parameter name="c8" target="In.mat.c8" type="float4" />
        </Parameters>
        <CodeInjections>
			<CodeInjection position="MATERIALINFO">
<![CDATA[
uniform float4 c1;
uniform float4 c2;
uniform float4 c3;
uniform float4 c4;
uniform float4 c5;
uniform float4 c6;
uniform float4 c7;
uniform float4 c8;
]]>
			</CodeInjection>
        	<CodeInjection position="GET_POSITION_VS">
<![CDATA[

	int index = (int) In.texCoords[1].y;
	float3 nearestPos = float3(In.position.x, In.position.y, In.position.z);
	
	if(index == 1)
	{
		nearestPos = float3(In.mat.c1.x, In.mat.c1.y, In.mat.c1.z);
	}
	if(index == 2)
	{
		nearestPos = float3(In.mat.c2.x, In.mat.c2.y, In.mat.c2.z);
	}
	if(index == 3)
	{
		nearestPos = float3(In.mat.c3.x, In.mat.c3.y, In.mat.c3.z);
	}
	if(index == 4)
	{
		nearestPos = float3(In.mat.c4.x, In.mat.c4.y, In.mat.c4.z);
	}
	if(index == 5)
	{
		nearestPos = float3(In.mat.c5.x, In.mat.c5.y, In.mat.c5.z);
	}
	if(index == 6)
	{
		nearestPos = float3(In.mat.c6.x, In.mat.c6.y, In.mat.c6.z);
	}
	if(index == 7)
	{
		nearestPos = float3(In.mat.c7.x, In.mat.c7.y, In.mat.c7.z);
	}
	if(index == 8)
	{
		nearestPos = float3(In.mat.c8.x, In.mat.c8.y, In.mat.c8.z);
	}	

	return float4(nearestPos.x , In.position.y, nearestPos.z, In.position.w);
]]>
	        	</CodeInjection>	
        	</CodeInjections>
    </LodLevel>
</CustomShader>