uniform sampler2D texture0;
uniform sampler2D texture1;
varying float distanceAcross;
uniform vec2 windPosition;
uniform vec4 variables;	// x = narrow strength, y = narrow exponent, z = wide strenth, w = wide exponent.
void main()
{
	mat2 rotation = mat2(0.996, -0.087, 0.087, 0.996); //Rotation by five degrees to avoid obvious texture tiling on horizontal or vertical lasers.
	//Simple passthrough, outputs interpolated vertex colours.
	vec4 slowSample = texture2D(texture0, ((gl_TexCoord[0].xy * 0.15) * rotation) + windPosition * -0.2);
	vec4 fastSample = texture2D(texture0, ((gl_TexCoord[0].xy * 0.15) * rotation) + windPosition * 0.1);
	vec4 textureColour = vec4 (slowSample.r, fastSample.g, 0.0, 1.0);
	
	vec4 patternVals = texture2D(texture1, vec2((gl_TexCoord[0].z + windPosition.x) * 0.15, 0.5)) * gl_Color;
	float patternStrength = clamp(patternVals.x + patternVals.y + patternVals.z, 0.0, 1.0);
	
	
	
	float fromLaser, fromLaserSquared;
	float intensity = textureColour.r;
	//textureColour.xyz = 1.0 - textureColour.xyz;
	gl_FragColor = vec4(gl_Color.r + 0.2, gl_Color.g + 0.2, gl_Color.b + 0.2, 1.0);// * textureColour.r;
	//gl_FragColor.xyz = textureColour.xyz;
	
	fromLaser = abs(1.0 - (distanceAcross * 2.0));
	
	fromLaser = pow (fromLaser * fromLaser + (1.0 - gl_Color.a) * (1.0 - gl_Color.a), 0.5);
	
	
	gl_FragColor.a = variables.x * pow(1.01 - fromLaser, variables.y) * patternStrength;
	gl_FragColor.a += variables.z * pow(1.0 - fromLaser, variables.w) * (1.0 - (1.0 - patternStrength) * 0.5);
	
	gl_FragColor.a *= textureColour.r;
	float particleness = 3.0 * pow(1.0 - fromLaser, variables.w) * textureColour.g;
	gl_FragColor.rgb += (vec3(particleness, particleness, particleness) * 0.3);
	gl_FragColor.a += particleness;
	
	
	//gl_FragColor.a = 1;
	
	
	
	//pow(1.0 - fromLaser, 3.0);
	
	//gl_FragColor = vec4(gl_TexCoord[0].xy, 0.0, 1.0);
	//gl_FragColor.a = 1.0;
}