varying vec2 texcoord;

varying vec3 sunWorldDir, moonWorldDir, lightWorldDir;
varying vec3 sunViewDir, moonViewDir, lightViewDir;

varying float isNoon, isNight, sunRiseSet;

varying mat4 gbufferPreviousProjectionInverse;

#include "/lib/uniform.glsl"
#include "/lib/settings.glsl"
#include "/lib/common/utils.glsl"
#include "/lib/common/position.glsl"

#include "/lib/common/noise.glsl"
#include "/lib/camera/colorToolkit.glsl"
#include "/lib/camera/toneMapping.glsl"
#include "/lib/camera/filter.glsl"


#ifdef FSH

#include "/lib/antialiasing/TAA.glsl"

const bool shadowtex0Mipmap = false;
const bool shadowtex1Mipmap = false;
const bool shadowcolor0Mipmap = false;
const bool shadowcolor1Mipmap = false;

void main() {
	vec3 nowColor = texture(colortex0, texcoord).rgb;
	TAA(nowColor);
	nowColor = max(nowColor, BLACK);

	vec4 CT2 = texelFetch(colortex2, ivec2(gl_FragCoord.xy), 0);
	CT2.rgb = nowColor;

	#ifdef NETHER
		nowColor = pow(nowColor, vec3(1.0)) * 1.5;
	#elif defined END
		nowColor = pow(nowColor, vec3(1.1)) * 1.25;
	#else
		nowColor = nowColor * (1.0 - 0.15 * isNight);

		if(isEyeInWater == 1){
			nowColor.rgb = pow(nowColor.rgb, vec3(UNDERWATER_CONTRAST)) * UNDERWATER_BRI;
		}
	#endif

#ifdef TAA_DEPTH_CONFIDENCE
/* RENDERTARGETS: 0,2,12 */
#else
/* RENDERTARGETS: 0,2 */
#endif
	gl_FragData[0] = vec4(nowColor, 1.0);
	gl_FragData[1] = CT2;
	#ifdef TAA_DEPTH_CONFIDENCE
		gl_FragData[2] = texelFetch(depthtex1, ivec2(gl_FragCoord.xy), 0);
	#endif
}

#endif
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////BY ZYPanDa gjshiwoa////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef VSH

void main() {
	sunViewDir = normalize(sunPosition);
	moonViewDir = normalize(moonPosition);
	lightViewDir = normalize(shadowLightPosition);

	sunWorldDir = normalize(viewPosToWorldPos(vec4(sunPosition, 0.0)).xyz);
    moonWorldDir = normalize(viewPosToWorldPos(vec4(moonPosition, 0.0)).xyz);
    lightWorldDir = normalize(viewPosToWorldPos(vec4(shadowLightPosition, 0.0)).xyz);

	#ifdef END
		sunWorldDir = normalize(vec3(0.0, 1.0, tan(-sunPathRotation * PI / 180.0)));
		moonWorldDir = sunWorldDir;
		lightWorldDir = sunWorldDir;

		sunViewDir = normalize((gbufferModelView * vec4(sunWorldDir, 0.0)).xyz);
		moonViewDir = sunViewDir;
		lightViewDir = sunViewDir;
	#elif defined NETHER
		sunWorldDir = normalize(vec3(0.0, 1.0, 0.0));
		moonWorldDir = sunWorldDir;
		lightWorldDir = sunWorldDir;

		sunViewDir = normalize((gbufferModelView * vec4(sunWorldDir, 0.0)).xyz);
		moonViewDir = sunViewDir;
		lightViewDir = sunViewDir;
	#endif

	isNoon = saturate(dot(sunWorldDir, upWorldDir) * NOON_DURATION);
	isNight = saturate(dot(moonWorldDir, upWorldDir) * NIGHT_DURATION);
	sunRiseSet = saturate(1 - isNoon - isNight);

	gbufferPreviousProjectionInverse = inverse(gbufferPreviousProjection);

	gl_Position = ftransform();
	texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
}

#endif