<?xml version="1.0" encoding="iso-8859-1"?>

<CustomShader version="1.0" classRequirement="">
    <LodLevel startDistance="0">
        <Parameters>
            <!--Parameter name="bumpSpeedScale" target="In.mat.bumpSpeedScale" type="float3" /-->
            <Parameter name="alphaBoostStartEndMax" target="In.mat.alphaBoostStartEndMax" type="float3" />
        </Parameters>
        <CodeInjections>
            <CodeInjection position="NUM_TEXCOORDS">
<![CDATA[
#if defined(SPECULAR)
#undef SPECULAR
#endif
#if (defined(AMBIENT) || defined(DIFFUSE) || defined(SPECULAR))
#define FOLIAGE_COLOR_OUTPUT
#endif
]]>
            </CodeInjection>
            <CodeInjection position="CONFIG_DEFINES">
<![CDATA[
#if defined(_NO_TANGENTSPACE_LIGHT) && (NUM_DIRECTIONAL_LIGHTS > 0) && defined(DIFFUSE)
#define VERTEX_DIRLIGHT_LIGHTING
#endif
]]>
            </CodeInjection>
            <CodeInjection position="GET_TEXCOORDS_VS">
<![CDATA[
// convert from short to 0-1 range
return In.texCoords[texCoordSet]/32767.0;
]]>
            </CodeInjection>
            <CodeInjection position="GET_NORMAL_VS">
<![CDATA[
#ifdef FOLIAGE_COLOR_OUTPUT
    // we use blendIndices to store normal, since normal attribute does not support UBYTE4 type
    return normalize(In.blendIndices.xyz/127.5 - 1.0);
#endif
]]>
            </CodeInjection>
            <CodeInjection position="NEED_FS_NORMAL">
<![CDATA[
//#if defined(_NEED_FS_NORMAL)
//#undef _NEED_FS_NORMAL
//#endif
]]>
            </CodeInjection>
            <CodeInjection position="MATERIALINFO">
<![CDATA[
#if defined(FOLIAGE_COLOR_OUTPUT)
    //uniform float4 bumpSpeedScale;
#endif
uniform float4 alphaBoostStartEndMax;
]]>
            </CodeInjection>
            <CodeInjection position="GET_POSITION_VS">
<![CDATA[
float frequency = 0.3;
float3 direction = float3(1,0,0)*0.1;
float offset = sin(In.time.y + In.position.x*In.position.y * frequency)*In.texCoords[0].y/32767.0;
return float4(In.position.xyz + direction * offset, 1.0);
]]>
            </CodeInjection>
            <CodeInjection position="VS_OUTPUT">
<![CDATA[
float alphaScale;
#ifdef VERTEX_DIRLIGHT_LIGHTING
    float3 dirVertexLighting[NUM_DIRECTIONAL_LIGHTS];
#endif
]]>
            </CodeInjection>
            <CodeInjection position="VS_END">
<![CDATA[
Out.alphaScale = 1 + saturate((length(viewDir)-In.mat.alphaBoostStartEndMax.x)/(In.mat.alphaBoostStartEndMax.y-In.mat.alphaBoostStartEndMax.x))*In.mat.alphaBoostStartEndMax.z;
#ifdef VERTEX_DIRLIGHT_LIGHTING
    for (int i=0; i < NUM_DIRECTIONAL_LIGHTS; i++) {
        float NdotL = saturate(dot(-In.lights.dirLightDirections[i].xyz, worldNormal.xyz));
        Out.dirVertexLighting[i].xyz = NdotL*In.lights.diffuseColors[i].xyz;
    }
#endif
]]>
            </CodeInjection>
            <CodeInjection position="POST_ALBEDO_FS">
<![CDATA[
albedo.w *= In.vs.alphaScale;
]]>
            </CodeInjection>
            <CodeInjection position="DIFFUSE_LIGHTING_DIR_FS">
<![CDATA[
#ifdef VERTEX_DIRLIGHT_LIGHTING
return In.vs.dirVertexLighting[dirLightI].xyz*atten;
#endif
]]>
            </CodeInjection>
        </CodeInjections>
    </LodLevel>
    <LodLevel startDistance="45">
        <Parameters>
            <!--Parameter name="bumpSpeedScale" target="In.mat.bumpSpeedScale" type="float3" /-->
        </Parameters>
        <CodeInjections>
            <CodeInjection position="NUM_TEXCOORDS">
<![CDATA[
#if defined(SPECULAR)
#undef SPECULAR
#endif
#if (defined(AMBIENT) || defined(DIFFUSE) || defined(SPECULAR))
#define FOLIAGE_COLOR_OUTPUT
#endif
#undef ALPHA_TESTED
]]>
            </CodeInjection>
            <CodeInjection position="CONFIG_DEFINES">
<![CDATA[
#if defined(_NO_TANGENTSPACE_LIGHT) && (NUM_DIRECTIONAL_LIGHTS > 0) && defined(DIFFUSE)
#define VERTEX_DIRLIGHT_LIGHTING
#endif
]]>
            </CodeInjection>
            <CodeInjection position="GET_TEXCOORDS_VS">
<![CDATA[
// convert from short to 0-1 range
return In.texCoords[texCoordSet]/32767.0;
]]>
            </CodeInjection>
            <CodeInjection position="GET_NORMAL_VS">
<![CDATA[
#ifdef FOLIAGE_COLOR_OUTPUT
    // we use blendIndices to store normal, since normal attribute does not support UBYTE4 type
    return In.blendIndices.xyz/127.5 - 1.0;
#endif
]]>
            </CodeInjection>
            <CodeInjection position="NEED_FS_NORMAL">
<![CDATA[
//#if defined(_NEED_FS_NORMAL)
//#undef _NEED_FS_NORMAL
//#endif
]]>
            </CodeInjection>
            <CodeInjection position="MATERIALINFO">
<![CDATA[
#if defined(FOLIAGE_COLOR_OUTPUT)
    //uniform float4 bumpSpeedScale;
#endif
]]>
            </CodeInjection>
            <CodeInjection position="VS_OUTPUT">
<![CDATA[
#ifdef VERTEX_DIRLIGHT_LIGHTING
    float3 dirVertexLighting[NUM_DIRECTIONAL_LIGHTS];
#endif
]]>
            </CodeInjection>
            <CodeInjection position="VS_END">
<![CDATA[
#ifdef VERTEX_DIRLIGHT_LIGHTING
    for (int i=0; i < NUM_DIRECTIONAL_LIGHTS; i++) {
        float NdotL = saturate(dot(-In.lights.dirLightDirections[i].xyz, worldNormal.xyz));
        Out.dirVertexLighting[i].xyz = NdotL*In.lights.diffuseColors[i].xyz;
    }
#endif
]]>
            </CodeInjection>
            <CodeInjection position="POST_ALBEDO_FS">
<![CDATA[
albedo.w = 1.0;
]]>
            </CodeInjection>
            <CodeInjection position="DIFFUSE_LIGHTING_DIR_FS">
<![CDATA[
#ifdef VERTEX_DIRLIGHT_LIGHTING
return In.vs.dirVertexLighting[dirLightI].xyz*atten;
#endif
]]>
            </CodeInjection>
        </CodeInjections>
    </LodLevel>
</CustomShader>
