/* Class150_Sub3 - Decompiled by JODE
 * Visit http://jode.sourceforge.net/
 */
import jaggl.OpenGL;

public class Class150_Sub3 extends Class150 {
	Class151 aClass151_10237;
	static final String aString10238 = "varying vec3 wvVertex;\nvarying float waterDepth;\nuniform vec3 sunDir;\nuniform vec4 sunColour;\nuniform float sunExponent;\nuniform vec2 waveIntensity;\nuniform float waveExponent;\nuniform float breakWaterDepth;\nuniform float breakWaterOffset;\nuniform sampler3D normalSampler;\nuniform samplerCube envMapSampler;\nvoid main() {\nvec4 wnNormal = texture3D(normalSampler, gl_TexCoord[0].xyz).rbga;\nwnNormal.xyz = 2.0*wnNormal.xyz-1.0;\nvec3 wnVector = normalize(wvVertex);\nvec3 wnReflection = reflect(wnVector, wnNormal.xyz);\nvec3 envColour = textureCube(envMapSampler, wnReflection).rgb;\nvec4 specularColour = sunColour*pow(clamp(-dot(sunDir, wnReflection), 0.0, 1.0), sunExponent);\nfloat shoreFactor = clamp(waterDepth/breakWaterDepth-breakWaterOffset*wnNormal.w, 0.0, 1.0);\nfloat waveFactor = pow(1.0-shoreFactor, waveExponent)-0.5;\nwaveFactor = -4.0*waveFactor*waveFactor+1.0;\nfloat ndote = dot(wnVector, wnNormal.xyz);\nfloat fresnel = pow(1.0-abs(ndote), 1.0);\nvec4 surfaceColour = mix(vec4(envColour, fresnel*shoreFactor), (waveIntensity.x*wnNormal.wwww)+waveIntensity.y, waveFactor)+specularColour*shoreFactor;\ngl_FragColor = vec4(mix(surfaceColour.rgb, gl_Fog.color.rgb, gl_FogFragCoord), surfaceColour.a);\n}\n";
	Class157 aClass157_10239;
	boolean aBool10240 = false;
	boolean aBool10241 = false;
	static final String aString10242 = "uniform float time;\nuniform float scale;\nvarying vec3 wvVertex;\nvarying float waterDepth;\nvoid main() {\nwaterDepth = gl_MultiTexCoord0.z;\nvec4 ecVertex = gl_ModelViewMatrix*gl_Vertex;\nwvVertex.x = dot(gl_NormalMatrix[0], ecVertex.xyz);\nwvVertex.y = dot(gl_NormalMatrix[1], ecVertex.xyz);\nwvVertex.z = dot(gl_NormalMatrix[2], ecVertex.xyz);\ngl_TexCoord[0].x = dot(gl_TextureMatrix[0][0], gl_MultiTexCoord0)*scale;\ngl_TexCoord[0].y = dot(gl_TextureMatrix[0][1], gl_MultiTexCoord0)*scale;\ngl_TexCoord[0].z = time;\ngl_TexCoord[0].w = 1.0;\ngl_FogFragCoord = clamp((ecVertex.z-gl_Fog.start)*gl_Fog.scale, 0.0, 1.0);\ngl_Position = ftransform();\n}\n";

	void method3400(Class145 class145, int i) {
		if (!((Class150_Sub3) this).aBool10240) {
			((Class150_Sub3) this).aClass84_Sub3_1836.method15440(class145);
			((Class150_Sub3) this).aClass84_Sub3_1836.method15467(i);
		}
	}

	boolean method3395() {
		return ((Class150_Sub3) this).aBool10241;
	}

	void method3399(int i, int i_0_) {
		if (((Class150_Sub3) this).aBool10240) {
			int i_1_ = 1 << (i & 0x3);
			float f = (float) (1 << (i >> 3 & 0x7)) / 32.0F;
			int i_2_ = i_0_ & 0xffff;
			float f_3_ = (float) (i_0_ >> 16 & 0x3) / 8.0F;
			float f_4_ = (float) (i_0_ >> 19 & 0xf) / 16.0F;
			float f_5_ = (float) (i_0_ >> 23 & 0xf) / 16.0F;
			int i_6_ = i_0_ >> 27 & 0xf;
			int i_7_ = (((Class157) ((Class150_Sub3) this).aClass157_10239).anInt1879);
			OpenGL.glUniform1f(OpenGL.glGetUniformLocation(i_7_, "time"), (float) (i_1_ * ((Class84_Sub3) (((Class150_Sub3) this).aClass84_Sub3_1836)).anInt9327 % 40000) / 40000.0F);
			OpenGL.glUniform1f(OpenGL.glGetUniformLocation(i_7_, "scale"), f);
			OpenGL.glUniform1f(OpenGL.glGetUniformLocation(i_7_, "breakWaterDepth"), (float) i_2_);
			OpenGL.glUniform1f(OpenGL.glGetUniformLocation(i_7_, "breakWaterOffset"), f_3_);
			OpenGL.glUniform2f(OpenGL.glGetUniformLocation(i_7_, "waveIntensity"), f_5_, f_4_);
			OpenGL.glUniform1f(OpenGL.glGetUniformLocation(i_7_, "waveExponent"), (float) i_6_);
		}
	}

	boolean method3394() {
		return ((Class150_Sub3) this).aBool10241;
	}

	void method3398() {
		if (((Class150_Sub3) this).aBool10240) {
			((Class150_Sub3) this).aClass84_Sub3_1836.method15439(1);
			((Class150_Sub3) this).aClass84_Sub3_1836.method15440(null);
			((Class150_Sub3) this).aClass84_Sub3_1836.method15439(0);
			((Class150_Sub3) this).aClass84_Sub3_1836.method15440(null);
			OpenGL.glUseProgram(0);
			((Class150_Sub3) this).aBool10240 = false;
		}
	}

	void method3401(boolean bool) {
		/* empty */
	}

	void method3406(boolean bool) {
		/* empty */
	}

	Class150_Sub3(Class84_Sub3 class84_sub3, Class151 class151) {
		super(class84_sub3);
		((Class150_Sub3) this).aClass151_10237 = class151;
		if ((((Class151) ((Class150_Sub3) this).aClass151_10237).aClass145_Sub3_1840) != null && (((Class84_Sub3) ((Class150_Sub3) this).aClass84_Sub3_1836).aBool9467) && (((Class84_Sub3) ((Class150_Sub3) this).aClass84_Sub3_1836).aBool9368)) {
			Class142 class142 = (Class142.method3296(((Class150_Sub3) this).aClass84_Sub3_1836, 35633, "uniform float time;\nuniform float scale;\nvarying vec3 wvVertex;\nvarying float waterDepth;\nvoid main() {\nwaterDepth = gl_MultiTexCoord0.z;\nvec4 ecVertex = gl_ModelViewMatrix*gl_Vertex;\nwvVertex.x = dot(gl_NormalMatrix[0], ecVertex.xyz);\nwvVertex.y = dot(gl_NormalMatrix[1], ecVertex.xyz);\nwvVertex.z = dot(gl_NormalMatrix[2], ecVertex.xyz);\ngl_TexCoord[0].x = dot(gl_TextureMatrix[0][0], gl_MultiTexCoord0)*scale;\ngl_TexCoord[0].y = dot(gl_TextureMatrix[0][1], gl_MultiTexCoord0)*scale;\ngl_TexCoord[0].z = time;\ngl_TexCoord[0].w = 1.0;\ngl_FogFragCoord = clamp((ecVertex.z-gl_Fog.start)*gl_Fog.scale, 0.0, 1.0);\ngl_Position = ftransform();\n}\n"));
			Class142 class142_8_ = (Class142.method3296(((Class150_Sub3) this).aClass84_Sub3_1836, 35632, "varying vec3 wvVertex;\nvarying float waterDepth;\nuniform vec3 sunDir;\nuniform vec4 sunColour;\nuniform float sunExponent;\nuniform vec2 waveIntensity;\nuniform float waveExponent;\nuniform float breakWaterDepth;\nuniform float breakWaterOffset;\nuniform sampler3D normalSampler;\nuniform samplerCube envMapSampler;\nvoid main() {\nvec4 wnNormal = texture3D(normalSampler, gl_TexCoord[0].xyz).rbga;\nwnNormal.xyz = 2.0*wnNormal.xyz-1.0;\nvec3 wnVector = normalize(wvVertex);\nvec3 wnReflection = reflect(wnVector, wnNormal.xyz);\nvec3 envColour = textureCube(envMapSampler, wnReflection).rgb;\nvec4 specularColour = sunColour*pow(clamp(-dot(sunDir, wnReflection), 0.0, 1.0), sunExponent);\nfloat shoreFactor = clamp(waterDepth/breakWaterDepth-breakWaterOffset*wnNormal.w, 0.0, 1.0);\nfloat waveFactor = pow(1.0-shoreFactor, waveExponent)-0.5;\nwaveFactor = -4.0*waveFactor*waveFactor+1.0;\nfloat ndote = dot(wnVector, wnNormal.xyz);\nfloat fresnel = pow(1.0-abs(ndote), 1.0);\nvec4 surfaceColour = mix(vec4(envColour, fresnel*shoreFactor), (waveIntensity.x*wnNormal.wwww)+waveIntensity.y, waveFactor)+specularColour*shoreFactor;\ngl_FragColor = vec4(mix(surfaceColour.rgb, gl_Fog.color.rgb, gl_FogFragCoord), surfaceColour.a);\n}\n"));
			((Class150_Sub3) this).aClass157_10239 = Class157.method3457((((Class150_Sub3) this).aClass84_Sub3_1836), new Class142[] { class142, class142_8_ });
			((Class150_Sub3) this).aBool10241 = ((Class150_Sub3) this).aClass157_10239 != null;
		}
	}

	boolean method3402() {
		return ((Class150_Sub3) this).aBool10241;
	}

	boolean method3403() {
		return ((Class150_Sub3) this).aBool10241;
	}

	void method3410(boolean bool) {
		Class145_Sub1 class145_sub1 = ((Class150_Sub3) this).aClass84_Sub3_1836.method15401();
		if (((Class150_Sub3) this).aBool10241 && class145_sub1 != null) {
			float f = (1.0F + (1.0F - Math.abs(((Class84_Sub3) (((Class150_Sub3) this).aClass84_Sub3_1836)).aFloatArray9314[1])) * 2.0F);
			((Class150_Sub3) this).aClass84_Sub3_1836.method15439(1);
			((Class150_Sub3) this).aClass84_Sub3_1836.method15440(class145_sub1);
			((Class150_Sub3) this).aClass84_Sub3_1836.method15439(0);
			((Class150_Sub3) this).aClass84_Sub3_1836.method15440(((Class151) ((Class150_Sub3) this).aClass151_10237).aClass145_Sub3_1840);
			int i = (((Class157) ((Class150_Sub3) this).aClass157_10239).anInt1879);
			OpenGL.glUseProgram(i);
			OpenGL.glUniform1i(OpenGL.glGetUniformLocation(i, "normalSampler"), 0);
			OpenGL.glUniform1i(OpenGL.glGetUniformLocation(i, "envMapSampler"), 1);
			OpenGL.glUniform3f(OpenGL.glGetUniformLocation(i, "sunDir"), -(((Class84_Sub3) ((Class150_Sub3) this).aClass84_Sub3_1836).aFloatArray9314[0]), -(((Class84_Sub3) ((Class150_Sub3) this).aClass84_Sub3_1836).aFloatArray9314[1]), -(((Class84_Sub3) ((Class150_Sub3) this).aClass84_Sub3_1836).aFloatArray9314[2]));
			OpenGL.glUniform4f(OpenGL.glGetUniformLocation(i, "sunColour"), (((Class84_Sub3) ((Class150_Sub3) this).aClass84_Sub3_1836).aFloat9465) * f, (((Class84_Sub3) ((Class150_Sub3) this).aClass84_Sub3_1836).aFloat9411) * f, (((Class84_Sub3) ((Class150_Sub3) this).aClass84_Sub3_1836).aFloat9370) * f, 1.0F);
			OpenGL.glUniform1f(OpenGL.glGetUniformLocation(i, "sunExponent"), 64.0F + Math.abs(((Class84_Sub3) (((Class150_Sub3) this).aClass84_Sub3_1836)).aFloatArray9314[1]) * 928.0F);
			((Class150_Sub3) this).aBool10240 = true;
		}
	}

	void method3405(boolean bool) {
		/* empty */
	}

	void method3404(boolean bool) {
		Class145_Sub1 class145_sub1 = ((Class150_Sub3) this).aClass84_Sub3_1836.method15401();
		if (((Class150_Sub3) this).aBool10241 && class145_sub1 != null) {
			float f = (1.0F + (1.0F - Math.abs(((Class84_Sub3) (((Class150_Sub3) this).aClass84_Sub3_1836)).aFloatArray9314[1])) * 2.0F);
			((Class150_Sub3) this).aClass84_Sub3_1836.method15439(1);
			((Class150_Sub3) this).aClass84_Sub3_1836.method15440(class145_sub1);
			((Class150_Sub3) this).aClass84_Sub3_1836.method15439(0);
			((Class150_Sub3) this).aClass84_Sub3_1836.method15440(((Class151) ((Class150_Sub3) this).aClass151_10237).aClass145_Sub3_1840);
			int i = (((Class157) ((Class150_Sub3) this).aClass157_10239).anInt1879);
			OpenGL.glUseProgram(i);
			OpenGL.glUniform1i(OpenGL.glGetUniformLocation(i, "normalSampler"), 0);
			OpenGL.glUniform1i(OpenGL.glGetUniformLocation(i, "envMapSampler"), 1);
			OpenGL.glUniform3f(OpenGL.glGetUniformLocation(i, "sunDir"), -(((Class84_Sub3) ((Class150_Sub3) this).aClass84_Sub3_1836).aFloatArray9314[0]), -(((Class84_Sub3) ((Class150_Sub3) this).aClass84_Sub3_1836).aFloatArray9314[1]), -(((Class84_Sub3) ((Class150_Sub3) this).aClass84_Sub3_1836).aFloatArray9314[2]));
			OpenGL.glUniform4f(OpenGL.glGetUniformLocation(i, "sunColour"), (((Class84_Sub3) ((Class150_Sub3) this).aClass84_Sub3_1836).aFloat9465) * f, (((Class84_Sub3) ((Class150_Sub3) this).aClass84_Sub3_1836).aFloat9411) * f, (((Class84_Sub3) ((Class150_Sub3) this).aClass84_Sub3_1836).aFloat9370) * f, 1.0F);
			OpenGL.glUniform1f(OpenGL.glGetUniformLocation(i, "sunExponent"), 64.0F + Math.abs(((Class84_Sub3) (((Class150_Sub3) this).aClass84_Sub3_1836)).aFloatArray9314[1]) * 928.0F);
			((Class150_Sub3) this).aBool10240 = true;
		}
	}

	void method3397(boolean bool) {
		/* empty */
	}

	void method3408() {
		if (((Class150_Sub3) this).aBool10240) {
			((Class150_Sub3) this).aClass84_Sub3_1836.method15439(1);
			((Class150_Sub3) this).aClass84_Sub3_1836.method15440(null);
			((Class150_Sub3) this).aClass84_Sub3_1836.method15439(0);
			((Class150_Sub3) this).aClass84_Sub3_1836.method15440(null);
			OpenGL.glUseProgram(0);
			((Class150_Sub3) this).aBool10240 = false;
		}
	}

	void method3409() {
		if (((Class150_Sub3) this).aBool10240) {
			((Class150_Sub3) this).aClass84_Sub3_1836.method15439(1);
			((Class150_Sub3) this).aClass84_Sub3_1836.method15440(null);
			((Class150_Sub3) this).aClass84_Sub3_1836.method15439(0);
			((Class150_Sub3) this).aClass84_Sub3_1836.method15440(null);
			OpenGL.glUseProgram(0);
			((Class150_Sub3) this).aBool10240 = false;
		}
	}

	void method3411(int i, int i_9_) {
		if (((Class150_Sub3) this).aBool10240) {
			int i_10_ = 1 << (i & 0x3);
			float f = (float) (1 << (i >> 3 & 0x7)) / 32.0F;
			int i_11_ = i_9_ & 0xffff;
			float f_12_ = (float) (i_9_ >> 16 & 0x3) / 8.0F;
			float f_13_ = (float) (i_9_ >> 19 & 0xf) / 16.0F;
			float f_14_ = (float) (i_9_ >> 23 & 0xf) / 16.0F;
			int i_15_ = i_9_ >> 27 & 0xf;
			int i_16_ = (((Class157) ((Class150_Sub3) this).aClass157_10239).anInt1879);
			OpenGL.glUniform1f(OpenGL.glGetUniformLocation(i_16_, "time"), (float) (i_10_ * ((Class84_Sub3) (((Class150_Sub3) this).aClass84_Sub3_1836)).anInt9327 % 40000) / 40000.0F);
			OpenGL.glUniform1f(OpenGL.glGetUniformLocation(i_16_, "scale"), f);
			OpenGL.glUniform1f(OpenGL.glGetUniformLocation(i_16_, "breakWaterDepth"), (float) i_11_);
			OpenGL.glUniform1f(OpenGL.glGetUniformLocation(i_16_, "breakWaterOffset"), f_12_);
			OpenGL.glUniform2f(OpenGL.glGetUniformLocation(i_16_, "waveIntensity"), f_14_, f_13_);
			OpenGL.glUniform1f(OpenGL.glGetUniformLocation(i_16_, "waveExponent"), (float) i_15_);
		}
	}

	void method3396(int i, int i_17_) {
		if (((Class150_Sub3) this).aBool10240) {
			int i_18_ = 1 << (i & 0x3);
			float f = (float) (1 << (i >> 3 & 0x7)) / 32.0F;
			int i_19_ = i_17_ & 0xffff;
			float f_20_ = (float) (i_17_ >> 16 & 0x3) / 8.0F;
			float f_21_ = (float) (i_17_ >> 19 & 0xf) / 16.0F;
			float f_22_ = (float) (i_17_ >> 23 & 0xf) / 16.0F;
			int i_23_ = i_17_ >> 27 & 0xf;
			int i_24_ = (((Class157) ((Class150_Sub3) this).aClass157_10239).anInt1879);
			OpenGL.glUniform1f(OpenGL.glGetUniformLocation(i_24_, "time"), (float) (i_18_ * ((Class84_Sub3) (((Class150_Sub3) this).aClass84_Sub3_1836)).anInt9327 % 40000) / 40000.0F);
			OpenGL.glUniform1f(OpenGL.glGetUniformLocation(i_24_, "scale"), f);
			OpenGL.glUniform1f(OpenGL.glGetUniformLocation(i_24_, "breakWaterDepth"), (float) i_19_);
			OpenGL.glUniform1f(OpenGL.glGetUniformLocation(i_24_, "breakWaterOffset"), f_20_);
			OpenGL.glUniform2f(OpenGL.glGetUniformLocation(i_24_, "waveIntensity"), f_22_, f_21_);
			OpenGL.glUniform1f(OpenGL.glGetUniformLocation(i_24_, "waveExponent"), (float) i_23_);
		}
	}

	void method3407(Class145 class145, int i) {
		if (!((Class150_Sub3) this).aBool10240) {
			((Class150_Sub3) this).aClass84_Sub3_1836.method15440(class145);
			((Class150_Sub3) this).aClass84_Sub3_1836.method15467(i);
		}
	}
}
