struct v2f_vertex_lit {
    vec2 uv;
    vec4 diff;
    vec4 spec;
};
struct v2f_img {
    vec4 pos;
    vec2 uv;
};
struct appdata_img {
    vec4 vertex;
    vec2 texcoord;
};
struct v2f {
    vec4 pos;
    float fog;
    vec4 uv;
    vec4 color;
};
struct appdata_tree {
    vec4 vertex;
    vec4 tangent;
    vec3 normal;
    vec4 color;
    vec4 texcoord;
};
uniform float _AO;
uniform vec4 _Color;
uniform vec4 _Scale;
uniform float _SquashAmount;
uniform vec4 _SquashPlaneNormal;
uniform mat4 _TerrainEngineBendTree;
uniform vec4 _TerrainTreeLightColors[4];
uniform vec3 _TerrainTreeLightDirections[4];



vec4 Squash( in vec4 pos );
void TerrainAnimateTree( inout vec4 pos, in float alpha );
v2f vert( in appdata_tree v );
vec4 Squash( in vec4 pos ) {
    vec3 projectedVertex;
    vec3 planePoint;
    vec3 planeNormal;
    projectedVertex = pos.xyz ;
    planePoint = vec3( 0.000000, _SquashPlaneNormal.w , 0.000000);
    planeNormal = _SquashPlaneNormal.xyz ;
    projectedVertex += (dot( planeNormal, (planePoint - vec3( pos))) * planeNormal);
    pos = vec4( mix( projectedVertex, pos.xyz , vec3( _SquashAmount)), 1.00000);
    return pos;
}
void TerrainAnimateTree( inout vec4 pos, in float alpha ) {
    vec3 bent;
    pos.xyz  *= _Scale.xyz ;
    bent = ( _TerrainEngineBendTree * vec4( pos.xyz , 0.000000) ).xyz ;
    pos.xyz  = mix( pos.xyz , bent, vec3( alpha));
    pos = Squash( pos);
}
v2f vert( in appdata_tree v ) {
    vec3 viewpos;
    v2f o;
    vec4 lightDir;
    vec4 lightColor;
    int i = 0;
    float atten = 1.00000;
    float occ;
    TerrainAnimateTree( v.vertex, v.color.w );
    viewpos = vec3( ( gl_ModelViewMatrix * v.vertex ));
    o.pos = ( gl_ModelViewProjectionMatrix * v.vertex );
    o.fog = o.pos.z ;
    o.uv = v.texcoord;
    lightDir.w  = _AO;
    lightColor = gl_LightModel.ambient;
    for ( ; (i < 4); ( i++ )) {
        lightDir.xyz  = _TerrainTreeLightDirections[ i ];
        occ = dot( lightDir.xyz , v.normal);
        occ = max( 0.000000, occ);
        occ *= atten;
        lightColor += (_TerrainTreeLightColors[ i ] * occ);
    }
    lightColor.w  = 1.00000;
    o.color = (lightColor * _Color);
    o.color.w  = 1.00000;
    return o;
}
attribute vec4 TANGENT;
varying vec4 xlv_FOG;
void main() {
    v2f xl_retval;
    appdata_tree xlt_v;
    xlt_v.vertex = vec4( gl_Vertex);
    xlt_v.tangent = vec4( TANGENT);
    xlt_v.normal = vec3( gl_Normal);
    xlt_v.color = vec4( gl_Color);
    xlt_v.texcoord = vec4( gl_MultiTexCoord0);
    xl_retval = vert( xlt_v);
    gl_Position = vec4( xl_retval.pos);
    xlv_FOG = vec4( xl_retval.fog, 0.0, 0.0, 0.0);
    gl_TexCoord[0] = vec4( xl_retval.uv);
    gl_FrontColor = vec4( xl_retval.color);
}
