Complementary Reimagined r5.1.1 - Ocean Physics Support

Created Diff never expires
9 removals
Words removed27
Total words1304
Words removed (%)2.07
459 lines
206 additions
Words added934
Total words2211
Words added (%)42.24
656 lines
////////////////////////////////////////
////////////////////////////////////////
// Complementary Reimagined by EminGT //
// Complementary Reimagined by EminGT //
////////////////////////////////////////
////////////////////////////////////////


//Common//
//Common//
#include "/lib/common.glsl"
#include "/lib/common.glsl"


const int PHYSICS_ITERATIONS_OFFSET = 13;
const float PHYSICS_DRAG_MULT = 0.048;
const float PHYSICS_XZ_SCALE = 0.035;
const float PHYSICS_TIME_MULTIPLICATOR = 0.45;
const float PHYSICS_W_DETAIL = 0.75;
const float PHYSICS_FREQUENCY = 6.0;
const float PHYSICS_SPEED = 2.0;
const float PHYSICS_WEIGHT = 0.8;
const float PHYSICS_FREQUENCY_MULT = 1.18;
const float PHYSICS_SPEED_MULT = 1.07;
const float PHYSICS_ITER_INC = 12.0;
const float PHYSICS_NORMAL_STRENGTH = 1.4;

uniform int physics_iterationsNormal;
uniform vec2 physics_waveOffset;
uniform ivec2 physics_textureOffset;
uniform float physics_gameTime;
uniform float physics_globalTime;
uniform float physics_oceanHeight;
uniform float physics_oceanWaveHorizontalScale;
uniform vec3 physics_modelOffset;
uniform float physics_rippleRange;
uniform float physics_foamAmount;
uniform float physics_foamOpacity;
uniform sampler2D physics_waviness;
uniform sampler2D physics_ripples;
uniform sampler3D physics_foam;
uniform sampler2D physics_lightmap;

float physics_waveHeight(vec2 position, int iterations, float factor, float time) {
position = (position - physics_waveOffset) * PHYSICS_XZ_SCALE * physics_oceanWaveHorizontalScale;
float iter = 0.0;
float frequency = PHYSICS_FREQUENCY;
float speed = PHYSICS_SPEED;
float weight = 1.0;
float height = 0.0;
float waveSum = 0.0;
float modifiedTime = time * PHYSICS_TIME_MULTIPLICATOR;
for (int i = 0; i < iterations; i++) {
vec2 direction = vec2(sin(iter), cos(iter));
float x = dot(direction, position) * frequency + modifiedTime * speed;
float wave = exp(sin(x) - 1.0);
float result = wave * cos(x);
vec2 force = result * weight * direction;
position -= force * PHYSICS_DRAG_MULT;
height += wave * weight;
iter += PHYSICS_ITER_INC;
waveSum += weight;
weight *= PHYSICS_WEIGHT;
frequency *= PHYSICS_FREQUENCY_MULT;
speed *= PHYSICS_SPEED_MULT;
}
return height / waveSum * physics_oceanHeight * factor - physics_oceanHeight * factor * 0.5;
}

vec2 physics_waveDirection(vec2 position, int iterations, float time) {
position = (position - physics_waveOffset) * PHYSICS_XZ_SCALE * physics_oceanWaveHorizontalScale;
float iter = 0.0;
float frequency = PHYSICS_FREQUENCY;
float speed = PHYSICS_SPEED;
float weight = 1.0;
float waveSum = 0.0;
float modifiedTime = time * PHYSICS_TIME_MULTIPLICATOR;
vec2 dx = vec2(0.0);
for (int i = 0; i < iterations; i++) {
vec2 direction = vec2(sin(iter), cos(iter));
float x = dot(direction, position) * frequency + modifiedTime * speed;
float wave = exp(sin(x) - 1.0);
float result = wave * cos(x);
vec2 force = result * weight * direction;
dx += force / pow(weight, PHYSICS_W_DETAIL);
position -= force * PHYSICS_DRAG_MULT;
iter += PHYSICS_ITER_INC;
waveSum += weight;
weight *= PHYSICS_WEIGHT;
frequency *= PHYSICS_FREQUENCY_MULT;
speed *= PHYSICS_SPEED_MULT;
}
return vec2(dx / pow(waveSum, 1.0 - PHYSICS_W_DETAIL));
}

vec3 physics_waveNormal(const in vec2 position, const in vec2 direction, const in float factor, const in float time) {
float oceanHeightFactor = physics_oceanHeight / 13.0;
float totalFactor = oceanHeightFactor * factor;
vec3 waveNormal = normalize(vec3(direction.x * totalFactor, PHYSICS_NORMAL_STRENGTH, direction.y * totalFactor));
vec2 eyePosition = position + physics_modelOffset.xz;
vec2 rippleFetch = (eyePosition + vec2(physics_rippleRange)) / (physics_rippleRange * 2.0);
vec2 rippleTexelSize = vec2(2.0 / textureSize(physics_ripples, 0).x, 0.0);
float left = texture(physics_ripples, rippleFetch - rippleTexelSize.xy).r;
float right = texture(physics_ripples, rippleFetch + rippleTexelSize.xy).r;
float top = texture(physics_ripples, rippleFetch - rippleTexelSize.yx).r;
float bottom = texture(physics_ripples, rippleFetch + rippleTexelSize.yx).r;
float totalEffect = left + right + top + bottom;
float normalx = left - right;
float normalz = top - bottom;
vec3 rippleNormal = normalize(vec3(normalx, 1.0, normalz));
return normalize(mix(waveNormal, rippleNormal, pow(totalEffect, 0.5)));
}

struct WavePixelData {
vec2 direction;
vec2 worldPos;
vec3 normal;
float foam;
float height;
};

WavePixelData physics_wavePixel(const in vec2 position, const in float factor, const in float iterations, const in float time) {
vec2 wavePos = (position.xy - physics_waveOffset) * PHYSICS_XZ_SCALE * physics_oceanWaveHorizontalScale;
float iter = 0.0;
float frequency = PHYSICS_FREQUENCY;
float speed = PHYSICS_SPEED;
float weight = 1.0;
float height = 0.0;
float waveSum = 0.0;
float modifiedTime = time * PHYSICS_TIME_MULTIPLICATOR;
vec2 dx = vec2(0.0);
for (int i = 0; i < iterations; i++) {
vec2 direction = vec2(sin(iter), cos(iter));
float x = dot(direction, wavePos) * frequency + modifiedTime * speed;
float wave = exp(sin(x) - 1.0);
float result = wave * cos(x);
vec2 force = result * weight * direction;
dx += force / pow(weight, PHYSICS_W_DETAIL);
wavePos -= force * PHYSICS_DRAG_MULT;
height += wave * weight;
iter += PHYSICS_ITER_INC;
waveSum += weight;
weight *= PHYSICS_WEIGHT;
frequency *= PHYSICS_FREQUENCY_MULT;
speed *= PHYSICS_SPEED_MULT;
}
WavePixelData data;
data.direction = -vec2(dx / pow(waveSum, 1.0 - PHYSICS_W_DETAIL));
data.worldPos = wavePos / physics_oceanWaveHorizontalScale / PHYSICS_XZ_SCALE;
data.height = height / waveSum * physics_oceanHeight * factor - physics_oceanHeight * factor * 0.5;
data.normal = physics_waveNormal(position, data.direction, factor, time);

float waveAmplitude = data.height * pow(max(data.normal.y, 0.0), 4.0);
vec2 waterUV = mix(position - physics_waveOffset, data.worldPos, clamp(factor * 2.0, 0.2, 1.0));
vec2 s1 = textureLod(physics_foam, vec3(waterUV * 0.26, physics_globalTime / 360.0), 0).rg;
vec2 s2 = textureLod(physics_foam, vec3(waterUV * 0.02, physics_globalTime / 360.0 + 0.5), 0).rg;
vec2 s3 = textureLod(physics_foam, vec3(waterUV * 0.1, physics_globalTime / 360.0 + 1.0), 0).rg;
float waterSurfaceNoise = s1.r * s2.r * s3.r * 2.8 * physics_foamAmount;
waveAmplitude = clamp(waveAmplitude * 1.2, 0.0, 1.0);
waterSurfaceNoise = (1.0 - waveAmplitude) * waterSurfaceNoise + waveAmplitude * physics_foamAmount;
float worleyNoise = 0.2 + 0.8 * s1.g * (1.0 - s2.g);
float waterFoamMinSmooth = 0.45;
float waterFoamMaxSmooth = 2.0;
waterSurfaceNoise = smoothstep(waterFoamMinSmooth, 1.0, waterSurfaceNoise) * worleyNoise;
data.foam = clamp(waterFoamMaxSmooth * waterSurfaceNoise * physics_foamOpacity, 0.0, 1.0);
if (!gl_FrontFacing) {
data.normal = -data.normal;
}
return data;
}




//////////Fragment Shader//////////Fragment Shader//////////Fragment Shader//////////
//////////Fragment Shader//////////Fragment Shader//////////Fragment Shader//////////
#ifdef FRAGMENT_SHADER
#ifdef FRAGMENT_SHADER


flat in int mat;
flat in int mat;


in vec2 texCoord;
in vec2 texCoord;
in vec2 lmCoord;
in vec2 lmCoord;


flat in vec3 upVec, sunVec, northVec, eastVec;
flat in vec3 upVec, sunVec, northVec, eastVec;
in vec3 normal;
in vec3 normal;
in vec3 viewVector;
in vec3 viewVector;
in vec3 physics_localPosition;
in vec3 physics_foamColor;
in float physics_localWaviness;
WavePixelData physics_waveData;


in vec4 glColor;
in vec4 glColor;


#if WATER_STYLE >= 2 || RAIN_PUDDLES >= 1 && WATER_STYLE == 1 && WATER_QUALITY >= 2 || defined GENERATED_NORMALS || defined CUSTOM_PBR
#if WATER_STYLE >= 2 || RAIN_PUDDLES >= 1 && WATER_STYLE == 1 && WATER_QUALITY >= 2 || defined GENERATED_NORMALS || defined CUSTOM_PBR
flat in vec3 binormal, tangent;
flat in vec3 binormal, tangent;
#endif
#endif


#if WATER_STYLE >= 2 || defined FANCY_NETHERPORTAL || defined GENERATED_NORMALS || defined POM
#if WATER_STYLE >= 2 || defined FANCY_NETHERPORTAL || defined GENERATED_NORMALS || defined POM
in vec2 signMidCoordPos;
in vec2 signMidCoordPos;
flat in vec2 absMidCoordPos;
flat in vec2 absMidCoordPos;
#endif
#endif


#ifdef POM
#ifdef POM
in vec4 vTexCoordAM;
in vec4 vTexCoordAM;
#endif
#endif


//Uniforms//
//Uniforms//
uniform int isEyeInWater;
uniform int isEyeInWater;
uniform int frameCounter;
uniform int frameCounter;
uniform int heldItemId;
uniform int heldItemId;
uniform int heldItemId2;
uniform int heldItemId2;


uniform float near;
uniform float near;
uniform float far;
uniform float far;
uniform float nightVision;
uniform float nightVision;
uniform float blindness;
uniform float blindness;
uniform float darknessFactor;
uniform float darknessFactor;
uniform float frameTimeCounter;
uniform float frameTimeCounter;


uniform ivec2 eyeBrightness;
uniform ivec2 eyeBrightness;


uniform vec3 skyColor;
uniform vec3 skyColor;
uniform vec3 cameraPosition;
uniform vec3 cameraPosition;


uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferModelViewInverse;
uniform mat4 shadowModelView;
uniform mat4 shadowModelView;
uniform mat4 shadowProjection;
uniform mat4 shadowProjection;
uniform float viewWidth;
uniform float viewWidth;
uniform float viewHeight;
uniform float viewHeight;
uniform float aspectRatio;
uniform float aspectRatio;


uniform sampler2D tex;
uniform sampler2D tex;
uniform sampler2D noisetex;
uniform sampler2D noisetex;


#if WATER_STYLE >= 2 || defined CLOUDS_REIMAGINED && defined CLOUD_SHADOWS || WATER_REFLECT_QUALITY >= 1 && defined SKY_EFFECT_REFLECTION && defined VL_CLOUDS_ACTIVE
#if WATER_STYLE >= 2 || defined CLOUDS_REIMAGINED && defined CLOUD_SHADOWS || WATER_REFLECT_QUALITY >= 1 && defined SKY_EFFECT_REFLECTION && defined VL_CLOUDS_ACTIVE
uniform sampler2D gaux4;
uniform sampler2D gaux4;
#endif
#endif


#ifdef VL_CLOUDS_ACTIVE
#ifdef VL_CLOUDS_ACTIVE
uniform sampler2D gaux1;
uniform sampler2D gaux1;
#endif
#endif


#if WATER_QUALITY >= 2 || WATER_REFLECT_QUALITY >= 1
#if WATER_QUALITY >= 2 || WATER_REFLECT_QUALITY >= 1
uniform sampler2D depthtex1;
uniform sampler2D depthtex1;
#endif
#endif


#if WATER_REFLECT_QUALITY >= 1 || defined FANCY_NETHERPORTAL
#if WATER_REFLECT_QUALITY >= 1 || defined FANCY_NETHERPORTAL
uniform mat4 gbufferProjection;
uniform mat4 gbufferProjection;
#endif
#endif


#if WATER_REFLECT_QUALITY >= 1
#if WATER_REFLECT_QUALITY >= 1
uniform sampler2D gaux2;
uniform sampler2D gaux2;
#endif
#endif


#if RAIN_PUDDLES >= 1
#if RAIN_PUDDLES >= 1
#if RAIN_PUDDLES < 3
#if RAIN_PUDDLES < 3
uniform float inRainy;
uniform float inRainy;
#else
#else
float inRainy = 1.0;
float inRainy = 1.0;
#endif
#endif
#endif
#endif


#if defined GENERATED_NORMALS || defined COATED_TEXTURES || defined POM || WATER_STYLE >= 2
#if defined GENERATED_NORMALS || defined COATED_TEXTURES || defined POM || WATER_STYLE >= 2
uniform ivec2 atlasSize;
uniform ivec2 atlasSize;
#endif
#endif


#ifdef CUSTOM_PBR
#ifdef CUSTOM_PBR
uniform sampler2D normals;
uniform sampler2D normals;
uniform sampler2D specular;
uniform sampler2D specular;
#endif
#endif


#if WATER_REFLECT_QUALITY >= 1 && defined SKY_EFFECT_REFLECTION && AURORA_STYLE > 0
#if WATER_REFLECT_QUALITY >= 1 && defined SKY_EFFECT_REFLECTION && AURORA_STYLE > 0
uniform float inSnowy;
uniform float inSnowy;


#ifndef UNIFORM_MOONPHASE
#ifndef UNIFORM_MOONPHASE
#define UNIFORM_MOONPHASE
#define UNIFORM_MOONPHASE
uniform int moonPhase;
uniform int moonPhase;
#endif
#endif
#endif
#endif


//Pipeline Constants//
//Pipeline Constants//


//Common Variables//
//Common Variables//
float NdotU = dot(normal, upVec);
float NdotU = dot(normal, upVec);
float NdotUmax0 = max(NdotU, 0.0);
float NdotUmax0 = max(NdotU, 0.0);
float SdotU = dot(sunVec, upVec);
float SdotU = dot(sunVec, upVec);
float sunFactor = SdotU < 0.0 ? clamp(SdotU + 0.375, 0.0, 0.75) / 0.75 : clamp(SdotU + 0.03125, 0.0, 0.0625) / 0.0625;
float sunFactor = SdotU < 0.0 ? clamp(SdotU + 0.375, 0.0, 0.75) / 0.75 : clamp(SdotU + 0.03125, 0.0, 0.0625) / 0.0625;
float sunVisibility = clamp(SdotU + 0.0625, 0.0, 0.125) / 0.125;
float sunVisibility = clamp(SdotU + 0.0625, 0.0, 0.125) / 0.125;
float sunVisibility2 = sunVisibility * sunVisibility;
float sunVisibility2 = sunVisibility * sunVisibility;
float shadowTimeVar1 = abs(sunVisibility - 0.5) * 2.0;
float shadowTimeVar1 = abs(sunVisibility - 0.5) * 2.0;
float shadowTimeVar2 = shadowTimeVar1 * shadowTimeVar1;
float shadowTimeVar2 = shadowTimeVar1 * shadowTimeVar1;
float shadowTime = shadowTimeVar2 * shadowTimeVar2;
float shadowTime = shadowTimeVar2 * shadowTimeVar2;


#ifdef OVERWORLD
#ifdef OVERWORLD
vec3 lightVec = sunVec * ((timeAngle < 0.5325 || timeAngle > 0.9675) ? 1.0 : -1.0);
vec3 lightVec = sunVec * ((timeAngle < 0.5325 || timeAngle > 0.9675) ? 1.0 : -1.0);
#else
#else
vec3 lightVec = sunVec;
vec3 lightVec = sunVec;
#endif
#endif


#if WATER_STYLE >= 2 || RAIN_PUDDLES >= 1 && WATER_STYLE == 1 && WATER_QUALITY >= 2 || defined GENERATED_NORMALS || defined CUSTOM_PBR
#if WATER_STYLE >= 2 || RAIN_PUDDLES >= 1 && WATER_STYLE == 1 && WATER_QUALITY >= 2 || defined GENERATED_NORMALS || defined CUSTOM_PBR
mat3 tbnMatrix = mat3(
mat3 tbnMatrix = mat3(
tangent.x, binormal.x, normal.x,
tangent.x, binormal.x, normal.x,
tangent.y, binormal.y, normal.y,
tangent.y, binormal.y, normal.y,
tangent.z, binormal.z, normal.z
tangent.z, binormal.z, normal.z
);
);
#endif
#endif


//Common Functions//
//Common Functions//
float GetLinearDepth(float depth) {
float GetLinearDepth(float depth) {
return (2.0 * near) / (far + near - depth * (far - near));
return (2.0 * near) / (far + near - depth * (far - near));
}
}


//Includes//
//Includes//
#include "/lib/util/dither.glsl"
#include "/lib/util/dither.glsl"
#include "/lib/util/spaceConversion.glsl"
#include "/lib/util/spaceConversion.glsl"
#include "/lib/lighting/mainLighting.glsl"
#include "/lib/lighting/mainLighting.glsl"
#include "/lib/atmospherics/fog/mainFog.glsl"
#include "/lib/atmospherics/fog/mainFog.glsl"


#ifdef OVERWORLD
#ifdef OVERWORLD
#include "/lib/atmospherics/sky.glsl"
#include "/lib/atmospherics/sky.glsl"
#endif
#endif


#if WATER_REFLECT_QUALITY >= 1
#if WATER_REFLECT_QUALITY >= 1
#if defined SKY_EFFECT_REFLECTION && defined OVERWORLD
#if defined SKY_EFFECT_REFLECTION && defined OVERWORLD
#if AURORA_STYLE > 0
#if AURORA_STYLE > 0
#include "/lib/atmospherics/auroraBorealis.glsl"
#include "/lib/atmospherics/auroraBorealis.glsl"
#endif
#endif


#ifdef NIGHT_NEBULA
#ifdef NIGHT_NEBULA
#include "/lib/atmospherics/nightNebula.glsl"
#include "/lib/atmospherics/nightNebula.glsl"
#else
#else
#include "/lib/atmospherics/stars.glsl"
#include "/lib/atmospherics/stars.glsl"
#endif
#endif


#ifdef VL_CLOUDS_ACTIVE
#ifdef VL_CLOUDS_ACTIVE
#include "/lib/atmospherics/clouds/mainClouds.glsl"
#include "/lib/atmospherics/clouds/mainClouds.glsl"
#endif
#endif
#endif
#endif


#include "/lib/materials/materialMethods/reflections.glsl"
#include "/lib/materials/materialMethods/reflections.glsl"
#endif
#endif


#ifdef TAA
#ifdef TAA
#include "/lib/antialiasing/jitter.glsl"
#include "/lib/antialiasing/jitter.glsl"
#endif
#endif


#if defined GENERATED_NORMALS || defined COATED_TEXTURES || WATER_STYLE >= 2
#if defined GENERATED_NORMALS || defined COATED_TEXTURES || WATER_STYLE >= 2
#include "/lib/util/miplevel.glsl"
#include "/lib/util/miplevel.glsl"
#endif
#endif


#ifdef GENERATED_NORMALS
#ifdef GENERATED_NORMALS
#include "/lib/materials/materialMethods/generatedNormals.glsl"
#include "/lib/materials/materialMethods/generatedNormals.glsl"
#endif
#endif


#ifdef CUSTOM_PBR
#ifdef CUSTOM_PBR
#include "/lib/materials/materialHandling/customMaterials.glsl"
#include "/lib/materials/materialHandling/customMaterials.glsl"
#endif
#endif


#ifdef ATM_COLOR_MULTS
#ifdef ATM_COLOR_MULTS
#include "/lib/colors/colorMultipliers.glsl"
#include "/lib/colors/colorMultipliers.glsl"
#endif
#endif
#ifdef MOON_PHASE_INF_ATMOSPHERE
#ifdef MOON_PHASE_INF_ATMOSPHERE
#include "/lib/colors/moonPhaseInfluence.glsl"
#include "/lib/colors/moonPhaseInfluence.glsl"
#endif
#endif


#ifdef COLOR_CODED_PROGRAMS
#ifdef COLOR_CODED_PROGRAMS
#include "/lib/misc/colorCodedPrograms.glsl"
#include "/lib/misc/colorCodedPrograms.glsl"
#endif
#endif


//Program//
//Program//
void main() {
void main() {
physics_waveData = physics_wavePixel(physics_localPosition.xz, physics_localWaviness, physics_iterationsNormal, physics_gameTime);
vec3 physics_normal = normalize(gl_NormalMatrix * physics_waveData.normal);
if (!gl_FrontFacing) {
physics_waveData.normal = -physics_waveData.normal;
}
vec4 colorP = texture2D(tex, texCoord);
vec4 colorP = texture2D(tex, texCoord);
vec4 color = colorP * vec4(glColor.rgb, 1.0);
vec4 color = colorP * vec4(glColor.rgb, 1.0);


vec2 screenCoord = gl_FragCoord.xy / vec2(viewWidth, viewHeight);
vec2 screenCoord = gl_FragCoord.xy / vec2(viewWidth, viewHeight);
vec3 screenPos = vec3(screenCoord, gl_FragCoord.z);
vec3 screenPos = vec3(screenCoord, gl_FragCoord.z);
#ifdef TAA
#ifdef TAA
vec3 viewPos = ScreenToView(vec3(TAAJitter(screenPos.xy, -0.5), screenPos.z));
vec3 viewPos = ScreenToView(vec3(TAAJitter(screenPos.xy, -0.5), screenPos.z));
#else
#else
vec3 viewPos = ScreenToView(screenPos);
vec3 viewPos = ScreenToView(screenPos);
#endif
#endif
float lViewPos = length(viewPos);
float lViewPos = length(viewPos);


float dither = Bayer64(gl_FragCoord.xy);
float dither = Bayer64(gl_FragCoord.xy);
#ifdef TAA
#ifdef TAA
dither = fract(dither + 1.61803398875 * mod(float(frameCounter), 3600.0));
dither = fract(dither + 1.61803398875 * mod(float(frameCounter), 3600.0));
#endif
#endif


#ifdef LIGHT_COLOR_MULTS
#ifdef LIGHT_COLOR_MULTS
lightColorMult = GetLightColorMult();
lightColorMult = GetLightColorMult();
#endif
#endif
#ifdef ATM_COLOR_MULTS
#ifdef ATM_COLOR_MULTS
atmColorMult = GetAtmColorMult();
atmColorMult = GetAtmColorMult();
sqrtAtmColorMult = sqrt(atmColorMult);
sqrtAtmColorMult = sqrt(atmColorMult);
#endif
#endif


#ifdef VL_CLOUDS_ACTIVE
#ifdef VL_CLOUDS_ACTIVE
float cloudLinearDepth = texelFetch(gaux1, texelCoord, 0).r;
float cloudLinearDepth = texelFetch(gaux1, texelCoord, 0).r;


if (pow2(cloudLinearDepth + OSIEBCA * dither) * far < min(lViewPos, far)) discard;
if (pow2(cloudLinearDepth + OSIEBCA * dither) * far < min(lViewPos, far)) discard;
#endif
#endif


#if WATER_QUALITY >= 3
#if WATER_QUALITY >= 3
float materialMask = 0.0;
float materialMask = 0.0;
#endif
#endif


vec3 nViewPos = normalize(viewPos);
vec3 nViewPos = normalize(viewPos);
vec3 playerPos = ViewToPlayer(viewPos);
vec3 playerPos = ViewToPlayer(viewPos);
float VdotU = dot(nViewPos, upVec);
float VdotU = dot(nViewPos, upVec);
float VdotS = dot(nViewPos, sunVec);
float VdotS = dot(nViewPos, sunVec);
float VdotN = dot(nViewPos, normal);
float VdotN = dot(nViewPos, normal);


// Materials
// Materials
vec4 translucentMult = vec4(1.0);
vec4 translucentMult = vec4(1.0);
bool noSmoothLighting = false, noDirectionalShading = false, translucentMultCalculated = false;
bool noSmoothLighting = false, noDirectionalShading = false, translucentMultCalculated = false;
#ifdef GENERATED_NORMALS
#ifdef GENERATED_NORMALS
bool noGeneratedNormals = false;
bool noGeneratedNormals = false;
#endif
#endif
int subsurfaceMode = 0;
int subsurfaceMode = 0;
float smoothnessG = 0.0, highlightMult = 1.0, reflectMult = 0.0, emission = 0.0;
float smoothnessG = 0.0, highlightMult = 1.0, reflectMult = 0.0, emission = 0.0;
vec2 lmCoordM = lmCoord;
vec2 lmCoordM = lmCoord;
vec3 normalM = VdotN > 0.0 ? -normal : normal; // Inverted Iris Water Normal Workaround
vec3 normalM = physics_normal;
vec3 geoNormal = normalM;
vec3 geoNormal = normalM;
vec3 shadowMult = vec3(1.0);
vec3 shadowMult = vec3(1.0);
float fresnel = clamp(1.0 + dot(normalM, nViewPos), 0.0, 1.0);
float fresnel = clamp(1.0 + dot(normalM, nViewPos), 0.0, 1.0);
#ifdef IPBR
#ifdef IPBR
#include "/lib/materials/materialHandling/translucentMaterials.glsl"
#include "/lib/materials/materialHandling/translucentMaterials.glsl"


#ifdef GENERATED_NORMALS
#ifdef GENERATED_NORMALS
if (!noGeneratedNormals) GenerateNormals(normalM, colorP.rgb * colorP.a * 1.5);
if (!noGeneratedNormals) GenerateNormals(normalM, colorP.rgb * colorP.a * 1.5);
#endif
#endif
#else
#else
#ifdef CUSTOM_PBR
#ifdef CUSTOM_PBR
float smoothnessD, materialMaskPh;
float smoothnessD, materialMaskPh;
GetCustomMaterials(color, normalM, lmCoordM, NdotU, shadowMult, smoothnessG, smoothnessD, highlightMult, emission, materialMaskPh, viewPos, lViewPos);
// I haven't implemented PBR for the custom ocean shader, this is just for education purposes
//GetCustomMaterials(color, normalM, lmCoordM, NdotU, shadowMult, smoothnessG, smoothnessD, highlightMult, emission, materialMaskPh, viewPos, lViewPos);
reflectMult = smoothnessD;
reflectMult = smoothnessD;
#endif
#endif


if (mat == 31000) { // Water
if (mat == 31000) { // Water
#include "/lib/materials/specificMaterials/translucents/water.glsl"
#include "/lib/materials/specificMaterials/translucents/water.glsl"
} else if (mat == 30020) { // Nether Portal
} else if (mat == 30020) { // Nether Portal
#ifdef FANCY_NETHERPORTAL
#ifdef FANCY_NETHERPORTAL
#include "/lib/materials/specificMaterials/translucents/netherPortal.glsl"
#include "/lib/materials/specificMaterials/translucents/netherPortal.glsl"
#endif
#endif
}
}
#endif
#endif


// Blending
// Blending
if (!translucentMultCalculated)
if (!translucentMultCalculated)
translucentMult = vec4(mix(vec3(0.666), color.rgb * (1.0 - pow2(pow2(color.a))), color.a), 1.0);
translucentMult = vec4(mix(vec3(0.666), color.rgb * (1.0 - pow2(pow2(color.a))), color.a), 1.0);


translucentMult.rgb = mix(translucentMult.rgb, vec3(1.0), min1(pow2(pow2(lViewPos / far))));
translucentMult.rgb = mix(translucentMult.rgb, vec3(1.0), min1(pow2(pow2(lViewPos / far))));


// Lighting
// Lighting
DoLighting(color, shadowMult, playerPos, viewPos, lViewPos, normalM, lmCoordM,
DoLighting(color, shadowMult, playerPos, viewPos, lViewPos, normalM, lmCoordM,
noSmoothLighting, noDirectionalShading, false, false,
noSmoothLighting, noDirectionalShading, false, false,
subsurfaceMode, smoothnessG, highlightMult, emission);
subsurfaceMode, smoothnessG, highlightMult, emission);


// Reflections
// Reflections
#if WATER_REFLECT_QUALITY >= 1
#if WATER_REFLECT_QUALITY >= 1
#ifdef LIGHT_COLOR_MULTS
#ifdef LIGHT_COLOR_MULTS
highlightColor *= lightColorMult;
highlightColor *= lightColorMult;
#endif
#endif
#ifdef MOON_PHASE_INF_REFLECTION
#ifdef MOON_PHASE_INF_REFLECTION
highlightColor *= pow2(moonPhaseInfluence);
highlightColor *= pow2(moonPhaseInfluence);
#endif
#endif


float fresnelM = (pow3(fresnel) * 0.85 + 0.15) * reflectMult;
float fresnelM = (pow3(fresnel) * 0.85 + 0.15) * reflectMult;


float skyLightFactor = pow2(max(lmCoordM.y - 0.7, 0.0) * 3.33333);
float skyLightFactor = pow2(max(lmCoordM.y - 0.7, 0.0) * 3.33333);
#if defined REALTIME_SHADOWS && WATER_REFLECT_QUALITY >= 2 && WATER_QUALITY >= 2
#if defined REALTIME_SHADOWS && WATER_REFLECT_QUALITY >= 2 && WATER_QUALITY >= 2
skyLightFactor = max(skyLightFactor, min1(dot(shadowMult, shadowMult)));
skyLightFactor = max(skyLightFactor, min1(dot(shadowMult, shadowMult)));
#endif
#endif


vec4 reflection = GetReflection(normalM, viewPos.xyz, nViewPos, playerPos, lViewPos, -1.0,
vec4 reflection = GetReflection(normalM, viewPos.xyz, nViewPos, playerPos, lViewPos, -1.0,
depthtex1, dither, skyLightFactor, fresnel,
depthtex1, dither, skyLightFactor, fresnel,
smoothnessG, geoNormal, color.rgb, shadowMult, highlightMult);
smoothnessG, geoNormal, color.rgb, shadowMult, highlightMult);


color.rgb = mix(color.rgb, reflection.rgb, fresnelM);
color.rgb = mix(color.rgb, reflection.rgb, fresnelM);
#endif
#endif
////
////


#ifdef COLOR_CODED_PROGRAMS
#ifdef COLOR_CODED_PROGRAMS
ColorCodeProgram(color);
ColorCodeProgram(color);
#endif
#endif


float sky = 0.0;
float sky = 0.0;
DoFog(color.rgb, sky, lViewPos, playerPos, VdotU, VdotS, dither);
DoFog(color.rgb, sky, lViewPos, playerPos, VdotU, VdotS, dither);
color.a *= 1.0 - sky;
color.a *= 1.0 - sky;


#ifndef LIGHT_COLORING
#ifndef LIGHT_COLORING
/* DRAWBUFFERS:03 */
/* DRAWBUFFERS:03 */
#else
#else
/* DRAWBUFFERS:08 */
/* DRAWBUFFERS:08 */
#endif
#endif
gl_FragData[0] = color;
gl_FragData[0] = color;
gl_FragData[1] = vec4(1.0 - translucentMult.rgb, translucentMult.a);
gl_FragData[1] = vec4(1.0 - translucentMult.rgb, translucentMult.a);


#if WATER_QUALITY >= 3
#if WATER_QUALITY >= 3
#ifndef LIGHT_COLORING
#ifndef LIGHT_COLORING
/* DRAWBUFFERS:031 */
/* DRAWBUFFERS:031 */
#else
#else
/* DRAWBUFFERS:081 */
/* DRAWBUFFERS:081 */
#endif
#endif
gl_FragData[2] = vec4(0.0, materialMask, 0.0, 1.0);
gl_FragData[2] = vec4(0.0, materialMask, 0.0, 1.0);
#endif
#endif
gl_FragData[0] = mix(gl_FragData[0], vec4(physics_foamColor, 1.0), physics_waveData.foam);
}
}


#endif
#endif


//////////Vertex Shader//////////Vertex Shader//////////Vertex Shader//////////
//////////Vertex Shader//////////Vertex Shader//////////Vertex Shader//////////
#ifdef VERTEX_SHADER
#ifdef VERTEX_SHADER


out vec3 physics_localPosition;
out vec3 physics_foamColor;
out float physics_localWaviness;

flat out int mat;
flat out int mat;


out vec2 texCoord;
out vec2 texCoord;
out vec2 lmCoord;
out vec2 lmCoord;


flat out vec3 upVec, sunVec, northVec, eastVec;
flat out vec3 upVec, sunVec, northVec, eastVec;
out vec3 normal;
out vec3 normal;
out vec3 viewVector;
out vec3 viewVector;


out vec4 glColor;
out vec4 glColor;


#if WATER_STYLE >= 2 || RAIN_PUDDLES >= 1 && WATER_STYLE == 1 && WATER_QUALITY >= 2 || defined GENERATED_NORMALS || defined CUSTOM_PBR
#if WATER_STYLE >= 2 || RAIN_PUDDLES >= 1 && WATER_STYLE == 1 && WATER_QUALITY >= 2 || defined GENERATED_NORMALS || defined CUSTOM_PBR
flat out vec3 binormal, tangent;
flat out vec3 binormal, tangent;
#endif
#endif


#if WATER_STYLE >= 2 || defined FANCY_NETHERPORTAL || defined GENERATED_NORMALS || defined POM
#if WATER_STYLE >= 2 || defined FANCY_NETHERPORTAL || defined GENERATED_NORMALS || defined POM
out vec2 signMidCoordPos;
out vec2 signMidCoordPos;
flat out vec2 absMidCoordPos;
flat out vec2 absMidCoordPos;
#endif
#endif


#ifdef POM
#ifdef POM
out vec4 vTexCoordAM;
out vec4 vTexCoordAM;
#endif
#endif


//Uniforms//
//Uniforms//
#ifdef TAA
#ifdef TAA
uniform float viewWidth, viewHeight;
uniform float viewWidth, viewHeight;
#endif
#endif


#ifdef WAVING_WATER_VERTEX
#ifdef WAVING_WATER_VERTEX
uniform float frameTimeCounter;
uniform float frameTimeCounter;


uniform vec3 cameraPosition;
uniform vec3 cameraPosition;


uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferModelViewInverse;
#endif
#endif


//Attributes//
//Attributes//
attribute vec4 mc_Entity;
attribute vec4 mc_Entity;
attribute vec4 mc_midTexCoord;
attribute vec4 mc_midTexCoord;
attribute vec4 at_tangent;
attribute vec4 at_tangent;


//Common Variables//
//Common Variables//
#if WATER_STYLE >= 2 || RAIN_PUDDLES >= 1 && WATER_STYLE == 1 && WATER_QUALITY >= 2 || defined GENERATED_NORMALS || defined CUSTOM_PBR
#if WATER_STYLE >= 2 || RAIN_PUDDLES >= 1 && WATER_STYLE == 1 && WATER_QUALITY >= 2 || defined GENERATED_NORMALS || defined CUSTOM_PBR
#else
#else
vec3 binormal;
vec3 binormal;
vec3 tangent;
vec3 tangent;
#endif
#endif


//Common Functions//
//Common Functions//


//Includes//
//Includes//
#ifdef TAA
#ifdef TAA
#include "/lib/antialiasing/jitter.glsl"
#include "/lib/antialiasing/jitter.glsl"
#endif
#endif


#ifdef WAVING_WATER_VERTEX
#ifdef WAVING_WATER_VERTEX
#include "/lib/materials/materialMethods/wavingBlocks.glsl"
#include "/lib/materials/materialMethods/wavingBlocks.glsl"
#endif
#endif


//Program//
//Program//
void main() {
void main() {
texCoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
texCoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
lmCoord = GetLightMapCoordinates();
lmCoord = GetLightMapCoordinates();
physics_foamColor = textureLod(physics_lightmap, (mat4(vec4(0.00390625, 0.0, 0.0, 0.0), vec4(0.0, 0.00390625, 0.0, 0.0), vec4(0.0, 0.0, 0.00390625, 0.0), vec4(0.03125, 0.03125, 0.03125, 1.0)) * gl_MultiTexCoord1).xy, 0).rgb;
physics_localWaviness = texelFetch(physics_waviness, ivec2(gl_Vertex.xz) - physics_textureOffset, 0).r;
vec4 physics_finalPosition = vec4(gl_Vertex.x, gl_Vertex.y + physics_waveHeight(gl_Vertex.xz, PHYSICS_ITERATIONS_OFFSET, physics_localWaviness, physics_gameTime), gl_Vertex.z, gl_Vertex.w);
physics_localPosition = physics_finalPosition.xyz;


glColor = gl_Color;
glColor = gl_Color;


mat = int(mc_Entity.x + 0.5);
mat = int(mc_Entity.x + 0.5);


normal = normalize(gl_NormalMatrix * gl_Normal);
normal = normalize(gl_NormalMatrix * gl_Normal);
upVec = normalize(gbufferModelView[1].xyz);
upVec = normalize(gbufferModelView[1].xyz);
eastVec = normalize(gbufferModelView[0].xyz);
eastVec = normalize(gbufferModelView[0].xyz);
northVec = normalize(gbufferModelView[2].xyz);
northVec = normalize(gbufferModelView[2].xyz);
sunVec = GetSunVector();
sunVec = GetSunVector();


binormal = normalize(gl_NormalMatrix * cross(at_tangent.xyz, gl_Normal.xyz) * at_tangent.w);
binormal = normalize(gl_NormalMatrix * cross(at_tangent.xyz, gl_Normal.xyz) * at_tangent.w);
tangent = normalize(gl_NormalMatrix * at_tangent.xyz);
tangent = normalize(gl_NormalMatrix * at_tangent.xyz);


mat3 tbnMatrix = mat3(
mat3 tbnMatrix = mat3(1.0);
tangent.x, binormal.x, normal.x,
tangent.y, binormal.y, normal.y,
tangent.z, binormal.z, normal.z
);


viewVector = tbnMatrix * (gl_ModelViewMatrix * gl_Vertex).xyz;
viewVector = tbnMatrix * (gl_ModelViewMatrix * physics_finalPosition).xyz;


#if WATER_STYLE >= 2 || defined FANCY_NETHERPORTAL || defined GENERATED_NORMALS || defined POM
#if WATER_STYLE >= 2 || defined FANCY_NETHERPORTAL || defined GENERATED_NORMALS || defined POM
vec2 midCoord = (gl_TextureMatrix[0] * mc_midTexCoord).st;
vec2 midCoord = (gl_TextureMatrix[0] * mc_midTexCoord).st;
vec2 texMinMidCoord = texCoord - midCoord;
vec2 texMinMidCoord = texCoord - midCoord;
signMidCoordPos = sign(texMinMidCoord);
signMidCoordPos = sign(texMinMidCoord);
absMidCoordPos = abs(texMinMidCoord);
absMidCoordPos = abs(texMinMidCoord);


#ifdef POM
#ifdef POM
vTexCoordAM.zw = abs(texMinMidCoord) * 2;
vTexCoordAM.zw = abs(texMinMidCoord) * 2;
vTexCoordAM.xy = min(texCoord, midCoord - texMinMidCoord);
vTexCoordAM.xy = min(texCoord, midCoord - texMinMidCoord);
#endif
#endif
#endif
#endif


#ifdef WAVING_WATER_VERTEX
#ifdef WAVING_WATER_VERTEX
vec4 position = gbufferModelViewInverse * gl_ModelViewMatrix * gl_Vertex;
vec4 position = gbufferModelViewInverse * gl_ModelViewMatrix * physics_finalPosition;


DoWave(position.xyz, mat);
DoWave(position.xyz, mat);


gl_Position = gl_ProjectionMatrix * gbufferModelView * position;
gl_Position = gl_ProjectionMatrix * gbufferModelView * position;
#else
#else
gl_Position = ftransform();
gl_Position = ftransform();
#endif
#endif


#ifdef TAA
#ifdef TAA
gl_Position.xy = TAAJitter(gl_Position.xy, gl_Position.w);
gl_Position.xy = TAAJitter(gl_Position.xy, gl_Position.w);
#endif
#endif


gl_Position.z -= 0.0001;
gl_Position.z -= 0.0001;
}
}


#endif
#endif