Files
minecraft-pt/shaders/Lib/Programs/Gbuffers/Water_FS.glsl
T

51 lines
1.6 KiB
GLSL

// MinecraftPT — Water Fragment Shader
// Writes the water GBuffer with waves, caustics data
#include "/Lib/Settings.glsl"
#include "/Lib/Utilities.glsl"
in vec2 texcoord;
in vec3 worldPos;
in vec3 worldNormal;
in vec3 vertexNormal;
in vec4 color;
in vec2 lightmap;
layout(location = 0) out vec4 colortex0Out; // albedo + emissive
layout(location = 1) out vec4 colortex1Out; // normals
layout(location = 2) out vec4 colortex2Out; // spec + matID
layout(location = 3) out vec4 colortex3Out; // lightmap
layout(location = 4) out vec4 colortex4Out; // translucent albedo + alpha
layout(location = 5) out vec4 colortex5Out; // translucent normal + matID
#include "/Lib/IndividualFunctions/WaterWaves.glsl"
void main(){
vec4 albedo = texture(tex, texcoord) * color;
// Water surface height / waves
vec3 wPos = worldPos;
#ifdef WAVE_PARALLAX
vec3 waveNormal = GetWaveNormal(wPos, lightmap.y);
#else
vec3 waveNormal = GetWaveNormal(wPos, lightmap.y);
#endif
// Water color — deep water tint
vec3 waterColor = mix(vec3(0.05, 0.15, 0.2), vec3(0.1, 0.3, 0.4), wetness * 0.5);
// Water lightmap
vec2 lm = lightmap;
lm.y = SkyLightmapCurve(lightmap.y);
// Water is translucent
colortex0Out = vec4(waterColor, 0.0);
colortex1Out = vec4(EncodeNormal(waveNormal), EncodeNormal(vertexNormal));
colortex2Out = vec4(0.0, 0.018, 0.0, 1.0 / 255.0); // matID = MATID_WATER
colortex3Out = vec4(lm, 1.0, 1.0);
// Translucent buffer: water albedo is mostly transparent, we store depth tint
colortex4Out = vec4(waterColor, 0.6);
colortex5Out = vec4(EncodeNormal(waveNormal), 1.0 / 255.0, 0.0);
}