#version 120

uniform float ticks;
uniform int worldTime;

uniform int fogMode;
uniform int lightmapEnabled;
uniform int texture2DEnabled;
uniform int blendFunc;
uniform vec4 overrideColor;
uniform int renderMode; //0 = default, 1 = item effect, 2 = item effect backwards

uniform vec4 fractal0TexCoords;
varying vec2 texFractal0Coords;

uniform float alcohol;
uniform float weed;
uniform float redshrooms;
uniform float brownshrooms;
uniform float tobacco;
uniform float cocaine;

uniform vec3 playerPos;

varying vec3 normalVector;

uniform int glLightEnabled;
uniform float glLightAmbient;
uniform vec3 glLightPos0;
uniform vec2 glLightStrength0;
uniform vec3 glLightPos1;
uniform vec2 glLightStrength1;

void main()
{    
	gl_Position = ftransform();
    
    normalVector = gl_Normal.xyz;
    if (normalVector.x == 0.0 && normalVector.y == 0.0 && normalVector.z == 0.0)
    {
        normalVector = vec3(0.0, 1.0, 0.0);
    }

    gl_TexCoord[0] = gl_MultiTexCoord0;
    if (renderMode == 1)
    {
        gl_TexCoord[0] = gl_TexCoord[0] * 0.125;
        gl_TexCoord[0] += mod(ticks, 100.0) / 100.0;
    }
    if (renderMode == 2)
    {
        gl_TexCoord[0] = gl_TexCoord[0] * 0.125;
        gl_TexCoord[0] -= mod(ticks, 123.0) / 123.0;
    }
    
	gl_TexCoord[1] = gl_MultiTexCoord1;
    
	if (brownshrooms > 0.0)
    {
        texFractal0Coords = vec2(mix(fractal0TexCoords[0], fractal0TexCoords[2], (mod(gl_Vertex[0] + gl_Vertex[1], 4.0)) / 4.0), mix(fractal0TexCoords[1], fractal0TexCoords[3], (mod(gl_Vertex[2] + gl_Vertex[1], 4.0)) / 4.0));
    }

    gl_FrontColor = gl_Color;
        
    vec3 vVertex = vec3(gl_ModelViewMatrix * gl_Vertex);
	gl_FogFragCoord = length(vVertex);
    
    if (redshrooms > 0.0)
    {        
        float w1 = 8.0;
        
        gl_Position[1] += sin((gl_Vertex[0] + ticks / 5.0) / w1 * 3.14159 * 2.0) * sin((gl_Vertex[2] + ticks / 5.0) / w1 * 3.14159 * 2.0) * redshrooms * 1.5;
        gl_Position[1] -= sin((playerPos.x + ticks / 5.0) / w1 * 3.14159 * 2.0) * sin((playerPos.z + ticks / 5.0) / w1 * 3.14159 * 2.0) * redshrooms * 1.5;

        float w2 = 16.0;

        gl_Position[1] += sin((gl_Vertex[0] + ticks / 8.0) / w2 * 3.14159 * 2.0) * sin((gl_Vertex[2]) / w2 * 3.14159 * 2.0) * redshrooms * 3.0;
        gl_Position[1] -= sin((playerPos.x + ticks / 8.0) / w2 * 3.14159 * 2.0) * sin((playerPos.z) / w2 * 3.14159 * 2.0) * redshrooms * 3.0;
        
        gl_Position[0] = mix(gl_Position[0], gl_Position[0] * (1.0 + gl_FogFragCoord / 20.0), redshrooms);
        gl_Position[1] = mix(gl_Position[1], gl_Position[1] * (1.0 + gl_FogFragCoord / 20.0), redshrooms);
    }
    if(brownshrooms > 0.0)
    {
        float w1 = 8.0;

        gl_Position[0] += sin((gl_Vertex[1] + ticks / 8.0) / w1 * 3.14159 * 2.0) * sin((gl_Vertex[2] + ticks / 5.0) / w1 * 3.14159 * 2.0) * brownshrooms * 1.5;

        if(gl_FogFragCoord > 5.0) gl_Position[1] += (sin(gl_FogFragCoord / 8.0 * 3.14159 * 2.0) + 1.0) * brownshrooms * (gl_FogFragCoord - 5.0) / 8.0;
    }
}
