2023-08-03 17:40:08 -04:00
#include "/lib/settings.glsl"
2024-05-02 12:43:30 -04:00
2024-05-09 18:24:29 -04:00
// #if defined END_SHADER || defined NETHER_SHADER
// #undef IS_LPV_ENABLED
// #endif
2024-05-02 12:43:30 -04:00
#ifdef IS_LPV_ENABLED
#extension GL_EXT_shader_image_load_store: enable
2024-05-06 15:12:52 -04:00
#extension GL_ARB_shading_language_packing: enable
2024-05-02 12:43:30 -04:00
#endif
2023-08-03 17:40:08 -04:00
#include "/lib/res_params.glsl"
2023-04-16 16:18:26 -04:00
varying vec4 lmtexcoord;
varying vec4 color;
2024-05-04 21:36:06 -04:00
uniform vec4 entityColor;
2023-08-02 21:43:18 -04:00
2023-10-07 22:18:20 -04:00
#ifdef OVERWORLD_SHADER
const bool shadowHardwareFiltering = true;
uniform sampler2DShadow shadow;
2024-03-20 21:44:25 -04:00
#ifdef TRANSLUCENT_COLORED_SHADOWS
uniform sampler2D shadowcolor0;
uniform sampler2DShadow shadowtex0;
uniform sampler2DShadow shadowtex1;
#endif
2023-10-07 22:18:20 -04:00
uniform float lightSign;
flat varying vec3 WsunVec;
flat varying vec3 averageSkyCol_Clouds;
flat varying vec4 lightCol;
#endif
2023-08-02 21:43:18 -04:00
2024-01-11 22:19:34 -05:00
2024-01-11 21:38:03 -05:00
2023-10-30 16:07:38 -04:00
flat varying float HELD_ITEM_BRIGHTNESS;
2023-10-10 23:02:00 -04:00
2023-08-03 17:40:08 -04:00
uniform sampler2D noisetex;
uniform sampler2D depthtex1;
2024-02-05 16:04:37 -05:00
uniform sampler2D depthtex0;
2024-05-18 22:58:30 -04:00
2024-05-04 21:36:06 -04:00
#ifdef DISTANT_HORIZONS
2024-05-18 22:58:30 -04:00
uniform sampler2D dhDepthTex1;
2024-05-04 21:36:06 -04:00
#endif
uniform sampler2D colortex7;
2024-02-16 21:28:13 -05:00
uniform sampler2D colortex12;
uniform sampler2D colortex14;
2023-08-03 17:40:08 -04:00
uniform sampler2D colortex5;
2024-05-09 18:24:29 -04:00
uniform sampler2D colortex3;
2024-05-22 00:01:17 -04:00
uniform sampler2D colortex4;
2024-05-04 21:36:06 -04:00
uniform sampler2D colortex6;
2023-08-03 17:40:08 -04:00
uniform sampler2D texture;
uniform sampler2D specular;
2023-08-02 21:43:18 -04:00
uniform sampler2D normals;
2024-05-04 16:33:11 -04:00
#ifdef IS_LPV_ENABLED
2024-05-06 15:12:52 -04:00
uniform usampler1D texBlockData;
2024-05-04 16:33:11 -04:00
uniform sampler3D texLpv1;
uniform sampler3D texLpv2;
#endif
2023-08-03 17:40:08 -04:00
varying vec4 tangent;
2023-04-16 16:18:26 -04:00
varying vec4 normalMat;
varying vec3 binormal;
2023-10-07 22:18:20 -04:00
varying vec3 flatnormal;
2024-06-10 23:26:19 -04:00
#ifdef LARGE_WAVE_DISPLACEMENT
varying vec3 shitnormal;
#endif
2023-08-02 21:43:18 -04:00
2023-04-16 16:18:26 -04:00
2024-05-04 21:36:06 -04:00
flat varying float exposure;
2023-08-02 21:43:18 -04:00
2023-10-07 22:18:20 -04:00
2023-04-16 16:18:26 -04:00
uniform vec3 sunVec;
uniform float near;
2023-10-07 22:18:20 -04:00
// uniform float far;
2023-04-16 16:18:26 -04:00
uniform float sunElevation;
2023-08-03 17:40:08 -04:00
uniform int isEyeInWater;
2023-04-16 16:18:26 -04:00
uniform float rainStrength;
uniform float skyIntensityNight;
uniform float skyIntensity;
2024-03-22 22:11:43 -04:00
uniform ivec2 eyeBrightnessSmooth;
2024-11-15 17:54:18 -05:00
uniform float nightVision;
2023-08-03 17:40:08 -04:00
uniform int frameCounter;
uniform float frameTimeCounter;
uniform vec2 texelSize;
uniform int framemod8;
2024-11-15 17:54:18 -05:00
uniform float viewWidth;
uniform float viewHeight;
2023-08-03 17:40:08 -04:00
2023-04-16 16:18:26 -04:00
uniform mat4 gbufferPreviousModelView;
uniform vec3 previousCameraPosition;
2023-08-03 17:40:08 -04:00
uniform float moonIntensity;
uniform float sunIntensity;
uniform vec3 sunColor;
uniform vec3 nsunColor;
2023-04-16 16:18:26 -04:00
2024-05-18 22:58:30 -04:00
#include "/lib/util.glsl"
2023-08-02 21:43:18 -04:00
#include "/lib/Shadow_Params.glsl"
2023-04-16 16:18:26 -04:00
#include "/lib/color_transforms.glsl"
#include "/lib/projections.glsl"
#include "/lib/sky_gradient.glsl"
#include "/lib/waterBump.glsl"
2024-05-18 22:58:30 -04:00
2023-04-16 16:18:26 -04:00
2023-10-07 22:18:20 -04:00
#ifdef OVERWORLD_SHADER
flat varying float Flashing;
#include "/lib/lightning_stuff.glsl"
2024-11-15 17:54:18 -05:00
#ifdef Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#else
vec4 dailyWeatherParams0 = vec4(CloudLayer0_coverage, CloudLayer1_coverage, CloudLayer2_coverage, 0.0);
vec4 dailyWeatherParams1 = vec4(CloudLayer0_density, CloudLayer1_density, CloudLayer2_density, 0.0);
#endif
2024-05-22 00:01:17 -04:00
#define CLOUDSHADOWSONLY
2023-10-07 22:18:20 -04:00
#include "/lib/volumetricClouds.glsl"
2024-11-15 17:54:18 -05:00
2023-10-07 22:18:20 -04:00
#endif
2023-12-17 22:25:26 -05:00
#ifdef END_SHADER
#include "/lib/end_fog.glsl"
#endif
2024-05-02 12:43:30 -04:00
#ifdef IS_LPV_ENABLED
2024-05-06 11:54:30 -04:00
uniform int heldItemId;
uniform int heldItemId2;
2024-05-02 12:43:30 -04:00
#include "/lib/hsv.glsl"
#include "/lib/lpv_common.glsl"
#include "/lib/lpv_render.glsl"
#endif
2023-10-07 22:18:20 -04:00
#include "/lib/diffuse_lighting.glsl"
2024-05-18 22:58:30 -04:00
2024-05-04 21:36:06 -04:00
float interleaved_gradientNoise_temporal(){
2024-11-15 17:54:18 -05:00
#ifdef TAA
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887 * frameCounter);
#else
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887);
#endif
2023-04-16 16:18:26 -04:00
}
2023-08-02 21:43:18 -04:00
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
2024-05-04 21:36:06 -04:00
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
2023-08-02 21:43:18 -04:00
return noise;
2023-04-16 16:18:26 -04:00
}
2024-05-04 21:36:06 -04:00
float R2_dither(){
2024-11-15 17:54:18 -05:00
vec2 coord = gl_FragCoord.xy ;
#ifdef TAA
coord += + (frameCounter%40000) * 2.0;
#endif
2024-05-04 21:36:06 -04:00
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
}
2024-11-15 17:54:18 -05:00
float blueNoise(){
#ifdef TAA
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
#else
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887);
#endif
}
2023-04-16 16:18:26 -04:00
2024-11-15 17:54:18 -05:00
#include "/lib/TAA_jitter.glsl"
2023-04-16 16:18:26 -04:00
2024-05-04 21:36:06 -04:00
#define PW_DEPTH 1.5 //[0.5 1.0 1.5 2.0 2.5 3.0]
#define PW_POINTS 2 //[2 4 6 8 16 32]
2023-04-16 16:18:26 -04:00
2024-03-01 22:48:09 -05:00
varying vec3 viewVector;
vec3 getParallaxDisplacement(vec3 posxz) {
2023-04-16 16:18:26 -04:00
vec3 parallaxPos = posxz;
2024-05-04 21:36:06 -04:00
vec2 vec = viewVector.xy * (1.0 / float(PW_POINTS)) * 22.0 * PW_DEPTH;
// float waterHeight = (1.0 - (getWaterHeightmap(posxz.xz)*0.5+0.5)) * 2.0 - 1.0;
float waterHeight = getWaterHeightmap(posxz.xz) * 2.0;
parallaxPos.xz -= waterHeight * vec;
2023-04-16 16:18:26 -04:00
return parallaxPos;
}
2023-08-02 21:43:18 -04:00
2024-03-01 22:48:09 -05:00
2023-08-02 21:43:18 -04:00
vec3 applyBump(mat3 tbnMatrix, vec3 bump, float puddle_values){
2024-05-04 21:36:06 -04:00
float bumpmult = puddle_values;
2023-08-02 21:43:18 -04:00
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
2024-05-04 21:36:06 -04:00
//
2023-08-02 21:43:18 -04:00
return normalize(bump*tbnMatrix);
}
2024-05-10 15:36:29 -04:00
vec2 CleanSample(
int samples, float totalSamples, float noise
){
// this will be used to make 1 full rotation of the spiral. the mulitplication is so it does nearly a single rotation, instead of going past where it started
float variance = noise * 0.897;
// for every sample input, it will have variance applied to it.
float variedSamples = float(samples) + variance;
// for every sample, the sample position must change its distance from the origin.
// otherwise, you will just have a circle.
float spiralShape = pow(variedSamples / (totalSamples + variance),0.5);
float shape = 2.26; // this is very important. 2.26 is very specific
float theta = variedSamples * (PI * shape);
float x = cos(theta) * spiralShape;
float y = sin(theta) * spiralShape;
return vec2(x, y);
}
2023-04-16 16:18:26 -04:00
2023-10-07 22:18:20 -04:00
vec3 viewToWorld(vec3 viewPos) {
2023-04-16 16:18:26 -04:00
vec4 pos;
2023-10-07 22:18:20 -04:00
pos.xyz = viewPos;
2023-04-16 16:18:26 -04:00
pos.w = 0.0;
2024-06-23 21:43:15 -04:00
pos = gbufferModelViewInverse * pos ;
2023-04-16 16:18:26 -04:00
return pos.xyz;
}
2023-08-02 21:43:18 -04:00
2023-04-16 16:18:26 -04:00
vec3 worldToView(vec3 worldPos) {
vec4 pos = vec4(worldPos, 0.0);
pos = gbufferModelView * pos;
return pos.xyz;
}
vec4 encode (vec3 n, vec2 lightmaps){
n.xy = n.xy / dot(abs(n), vec3(1.0));
n.xy = n.z <= 0.0 ? (1.0 - abs(n.yx)) * sign(n.xy) : n.xy;
vec2 encn = clamp(n.xy * 0.5 + 0.5,-1.0,1.0);
return vec4(encn,vec2(lightmaps.x,lightmaps.y));
}
2023-08-02 21:43:18 -04:00
//encoding by jodie
float encodeVec2(vec2 a){
const vec2 constant1 = vec2( 1., 256.) / 65535.;
vec2 temp = floor( a * 255. );
return temp.x*constant1.x+temp.y*constant1.y;
2023-04-16 16:18:26 -04:00
}
2023-08-02 21:43:18 -04:00
float encodeVec2(float x,float y){
return encodeVec2(vec2(x,y));
2023-04-16 16:18:26 -04:00
}
2023-08-02 21:43:18 -04:00
float ld(float dist) {
return (2.0 * near) / (far + near - dist * (far - near));
2023-04-16 16:18:26 -04:00
}
2024-02-05 16:04:37 -05:00
uniform float dhFarPlane;
#include "/lib/DistantHorizons_projections.glsl"
2023-08-02 21:43:18 -04:00
2024-03-30 23:20:34 -04:00
2024-05-04 21:36:06 -04:00
// #undef BASIC_SHADOW_FILTER
#ifdef OVERWORLD_SHADER
float ComputeShadowMap(inout vec3 directLightColor, vec3 playerPos, float maxDistFade, float noise){
if(maxDistFade <= 0.0) return 1.0;
// setup shadow projection
vec3 projectedShadowPosition = mat3(shadowModelView) * playerPos + shadowModelView[3].xyz;
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
// un-distort
#ifdef DISTORT_SHADOWMAP
float distortFactor = calcDistort(projectedShadowPosition.xy);
projectedShadowPosition.xy *= distortFactor;
#else
float distortFactor = 1.0;
#endif
// hamburger
projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5);
float shadowmap = 0.0;
vec3 translucentTint = vec3(0.0);
#ifndef HAND
projectedShadowPosition.z -= 0.0001;
#endif
#if defined ENTITIES
projectedShadowPosition.z -= 0.0002;
#endif
#ifdef BASIC_SHADOW_FILTER
int samples = int(SHADOW_FILTER_SAMPLE_COUNT * 0.5);
float rdMul = 14.0*distortFactor*d0*k/shadowMapResolution;
for(int i = 0; i < samples; i++){
2024-05-10 15:36:29 -04:00
vec2 offsetS = CleanSample(i, samples - 1, noise) * 0.3;
2024-05-04 21:36:06 -04:00
projectedShadowPosition.xy += rdMul*offsetS;
#else
int samples = 1;
#endif
#ifdef TRANSLUCENT_COLORED_SHADOWS
// determine when opaque shadows are overlapping translucent shadows by getting the difference of opaque depth and translucent depth
float shadowDepthDiff = pow(clamp((shadow2D(shadowtex1, projectedShadowPosition).x - projectedShadowPosition.z) * 2.0,0.0,1.0),2.0);
2024-03-30 23:20:34 -04:00
2024-05-04 21:36:06 -04:00
// get opaque shadow data to get opaque data from translucent shadows.
float opaqueShadow = shadow2D(shadowtex0, projectedShadowPosition).x;
shadowmap += max(opaqueShadow, shadowDepthDiff);
2024-03-30 23:20:34 -04:00
2024-05-04 21:36:06 -04:00
// get translucent shadow data
vec4 translucentShadow = texture2D(shadowcolor0, projectedShadowPosition.xy);
// this curve simply looked the nicest. it has no other meaning.
float shadowAlpha = pow(1.0 - pow(translucentShadow.a,5.0),0.2);
// normalize the color to remove luminance, and keep the hue. remove all opaque color.
// mulitply shadow alpha to shadow color, but only on surfaces facing the lightsource. this is a tradeoff to protect subsurface scattering's colored shadow tint from shadow bias on the back of the caster.
translucentShadow.rgb = max(normalize(translucentShadow.rgb + 0.0001), max(opaqueShadow, 1.0-shadowAlpha)) * shadowAlpha;
// make it such that full alpha areas that arent in a shadow have a value of 1.0 instead of 0.0
translucentTint += mix(translucentShadow.rgb, vec3(1.0), opaqueShadow*shadowDepthDiff);
#else
shadowmap += shadow2D(shadow, projectedShadowPosition).x;
#endif
#ifdef BASIC_SHADOW_FILTER
}
#endif
#ifdef TRANSLUCENT_COLORED_SHADOWS
// tint the lightsource color with the translucent shadow color
directLightColor *= mix(vec3(1.0), translucentTint.rgb / samples, maxDistFade);
#endif
return mix(1.0, shadowmap / samples, maxDistFade);
}
#endif
void convertHandDepth(inout float depth) {
float ndcDepth = depth * 2.0 - 1.0;
ndcDepth /= MC_HAND_DEPTH;
depth = ndcDepth * 0.5 + 0.5;
2024-03-30 23:20:34 -04:00
}
2024-05-09 18:24:29 -04:00
void Emission(
inout vec3 Lighting,
vec3 Albedo,
float Emission,
float exposure
){
2024-11-15 17:54:18 -05:00
// float autoBrightnessAdjust = mix(5.0, 100.0, clamp(exp(-10.0*exposure),0.0,1.0));
if( Emission < 254.5/255.0) Lighting = mix(Lighting, Albedo * 5.0 * Emissive_Brightness, pow(Emission, Emissive_Curve)); // old method.... idk why
2024-05-09 18:24:29 -04:00
}
2024-07-08 20:12:05 -04:00
uniform vec3 eyePosition;
2024-11-15 17:54:18 -05:00
#define FORWARD_SPECULAR
#define FORWARD_ENVIORNMENT_REFLECTION
#define FORWARD_BACKGROUND_REFLECTION
#define FORWARD_ROUGH_REFLECTION
2024-11-15 20:08:03 -05:00
#ifdef FORWARD_SPECULAR
#endif
#ifdef FORWARD_ENVIORNMENT_REFLECTION
#endif
#ifdef FORWARD_BACKGROUND_REFLECTION
#endif
#ifdef FORWARD_ROUGH_REFLECTION
#endif
2024-11-15 17:54:18 -05:00
#include "/lib/specular.glsl"
2024-05-04 21:36:06 -04:00
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
2024-03-30 23:20:34 -04:00
2023-08-02 21:43:18 -04:00
/* RENDERTARGETS:2,7,11,14 */
2024-05-04 21:36:06 -04:00
2023-04-16 16:18:26 -04:00
void main() {
2023-08-06 16:14:32 -04:00
if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 ) {
2023-10-07 22:18:20 -04:00
2024-05-04 21:36:06 -04:00
vec3 FragCoord = gl_FragCoord.xyz;
#ifdef HAND
convertHandDepth(FragCoord.z);
#endif
2023-08-02 21:43:18 -04:00
vec2 tempOffset = offsets[framemod8];
2024-02-05 16:04:37 -05:00
2024-05-04 21:36:06 -04:00
vec3 viewPos = toScreenSpace(FragCoord*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5, 0.0));
vec3 feetPlayerPos = mat3(gbufferModelViewInverse) * viewPos;
2023-12-17 22:25:26 -05:00
2024-05-04 21:36:06 -04:00
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// MATERIAL MASKS ////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
float MATERIALS = normalMat.w;
// 1.0 = water mask
// 0.9 = entity mask
// 0.8 = reflective entities
// 0.7 = reflective blocks
// 0.1 = hand mask
2023-10-07 22:18:20 -04:00
2024-05-04 21:36:06 -04:00
#ifdef HAND
MATERIALS = 0.1;
#endif
2023-04-16 16:18:26 -04:00
2024-05-04 21:36:06 -04:00
// bool isHand = abs(MATERIALS - 0.1) < 0.01;
bool isWater = MATERIALS > 0.99;
bool isReflectiveEntity = abs(MATERIALS - 0.8) < 0.01;
bool isReflective = abs(MATERIALS - 0.7) < 0.01 || isWater || isReflectiveEntity;
bool isEntity = abs(MATERIALS - 0.9) < 0.01 || isReflectiveEntity;
2024-02-16 21:28:13 -05:00
2024-05-04 21:36:06 -04:00
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// ALBEDO /////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
2024-02-16 21:28:13 -05:00
2023-08-02 21:43:18 -04:00
gl_FragData[0] = texture2D(texture, lmtexcoord.xy, Texture_MipMap_Bias) * color;
2024-02-16 21:28:13 -05:00
2023-08-02 21:43:18 -04:00
float UnchangedAlpha = gl_FragData[0].a;
2024-11-15 17:54:18 -05:00
// gl_FragData[0].a = pow(gl_FragData[0].a,3);
2024-05-04 21:36:06 -04:00
#ifdef WhiteWorld
gl_FragData[0].rgb = vec3(0.5);
gl_FragData[0].a = 1.0;
#endif
2023-04-16 16:18:26 -04:00
2024-05-04 21:36:06 -04:00
vec3 Albedo = toLinear(gl_FragData[0].rgb);
2023-04-16 16:18:26 -04:00
2024-05-04 21:36:06 -04:00
#ifndef WhiteWorld
#ifdef Vanilla_like_water
if (isWater) Albedo *= sqrt(luma(Albedo));
#else
if (isWater){
Albedo = vec3(0.0);
gl_FragData[0].a = 1.0/255.0;
}
#endif
2023-08-02 21:43:18 -04:00
#endif
2023-04-16 16:18:26 -04:00
2024-05-04 21:36:06 -04:00
#ifdef ENTITIES
Albedo.rgb = mix(Albedo.rgb, entityColor.rgb, clamp(entityColor.a*1.5,0,1));
2023-08-02 21:43:18 -04:00
#endif
2023-04-16 16:18:26 -04:00
2024-05-04 21:36:06 -04:00
vec4 GLASS_TINT_COLORS = vec4(Albedo, UnchangedAlpha);
2024-01-11 14:59:43 -05:00
#ifdef BIOME_TINT_WATER
2024-05-04 21:36:06 -04:00
if (isWater) GLASS_TINT_COLORS.rgb = toLinear(color.rgb);
2024-01-11 14:59:43 -05:00
#endif
2023-08-03 17:40:08 -04:00
2024-05-04 21:36:06 -04:00
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// NORMALS ///////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
2023-10-07 22:18:20 -04:00
2024-05-04 21:36:06 -04:00
vec3 normal = normalMat.xyz; // in viewSpace
2024-06-10 23:26:19 -04:00
#ifdef LARGE_WAVE_DISPLACEMENT
if (isWater){
normal = viewToWorld(normal) ;
normal.xz = shitnormal.xy;
normal = worldToView(normal);
}
#endif
2024-05-04 21:36:06 -04:00
vec3 worldSpaceNormal = viewToWorld(normal).xyz;
2023-08-02 21:43:18 -04:00
vec2 TangentNormal = vec2(0); // for refractions
vec3 tangent2 = normalize(cross(tangent.rgb,normal)*tangent.w);
mat3 tbnMatrix = mat3(tangent.x, tangent2.x, normal.x,
2023-10-07 22:18:20 -04:00
tangent.y, tangent2.y, normal.y,
tangent.z, tangent2.z, normal.z);
2023-04-16 16:18:26 -04:00
2024-05-04 21:36:06 -04:00
vec3 NormalTex = vec3(texture2D(normals, lmtexcoord.xy, Texture_MipMap_Bias).xy,0.0);
2023-08-02 21:43:18 -04:00
NormalTex.xy = NormalTex.xy*2.0-1.0;
2024-11-15 17:54:18 -05:00
NormalTex.z = clamp(sqrt(1.0 - dot(NormalTex.xy, NormalTex.xy)),0.0,1.0);
2023-10-07 22:18:20 -04:00
#ifndef HAND
2024-05-04 21:36:06 -04:00
if (isWater){
vec3 posxz = (mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz) + cameraPosition;
// make the waves flow in the direction the water faces, except for perfectly up facing parts.
2024-11-15 17:54:18 -05:00
if(abs(worldSpaceNormal.y) < 0.9995) posxz.xz -= posxz.y + normalize(worldSpaceNormal.xz*10.0) * frameTimeCounter * 3.0 * WATER_WAVE_SPEED;
2024-03-01 22:48:09 -05:00
2024-05-04 21:36:06 -04:00
posxz.xyz = getParallaxDisplacement(posxz);
2024-03-01 22:48:09 -05:00
vec3 bump = normalize(getWaveNormal(posxz, false));
2023-04-16 16:18:26 -04:00
2024-05-04 21:36:06 -04:00
float bumpmult = 10.0 * WATER_WAVE_STRENGTH;
2023-10-07 22:18:20 -04:00
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
2024-05-04 21:36:06 -04:00
NormalTex.xyz = bump;
2023-10-07 22:18:20 -04:00
}
#endif
2023-04-16 16:18:26 -04:00
2024-11-15 17:54:18 -05:00
// tangent space normals for refraction
TangentNormal = NormalTex.xy;
2024-05-04 21:36:06 -04:00
normal = applyBump(tbnMatrix, NormalTex.xyz, 1.0);
2024-11-15 17:54:18 -05:00
// TangentNormal = clamp(TangentNormal + (blueNoise()*2.0-1.0)*0.005,-1.0,1.0);
gl_FragData[2] = vec4(encodeVec2(TangentNormal*0.5+0.5), encodeVec2(GLASS_TINT_COLORS.rg), encodeVec2(GLASS_TINT_COLORS.ba), 1.0);
2023-08-03 17:40:08 -04:00
2024-05-09 18:24:29 -04:00
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// SPECULARS /////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
2024-11-15 17:54:18 -05:00
vec3 SpecularTex = texture2D(specular, lmtexcoord.xy, Texture_MipMap_Bias).rga;
2024-05-04 21:36:06 -04:00
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// DIFFUSE LIGHTING //////////////////////////////
////////////////////////////////////////////////////////////////////////////////
2023-04-16 16:18:26 -04:00
2023-10-07 22:18:20 -04:00
vec2 lightmap = lmtexcoord.zw;
2024-05-04 21:36:06 -04:00
// lightmap.y = 1.0;
2023-10-18 17:43:29 -04:00
2023-10-07 22:18:20 -04:00
#ifndef OVERWORLD_SHADER
lightmap.y = 1.0;
#endif
2023-10-30 16:07:38 -04:00
2024-07-08 20:12:05 -04:00
#if defined Hand_Held_lights && !defined LPV_ENABLED
#ifdef IS_IRIS
vec3 playerCamPos = eyePosition;
#else
vec3 playerCamPos = cameraPosition;
#endif
2024-11-15 17:54:18 -05:00
if(HELD_ITEM_BRIGHTNESS > 0.0){
float pointLight = clamp(1.0-length((feetPlayerPos+cameraPosition)-playerCamPos)/HANDHELD_LIGHT_RANGE,0.0,1.0);
lightmap.x = mix(lightmap.x , HELD_ITEM_BRIGHTNESS, pointLight*pointLight);
}
2023-10-30 16:07:38 -04:00
#endif
2023-10-18 17:43:29 -04:00
2023-08-02 21:43:18 -04:00
vec3 Indirect_lighting = vec3(0.0);
2024-03-22 22:11:43 -04:00
vec3 MinimumLightColor = vec3(1.0);
2024-03-01 22:48:09 -05:00
if(isEyeInWater == 1) MinimumLightColor = vec3(10.0);
2024-05-04 21:36:06 -04:00
2023-10-07 22:18:20 -04:00
vec3 Direct_lighting = vec3(0.0);
#ifdef OVERWORLD_SHADER
2024-11-15 17:54:18 -05:00
vec3 DirectLightColor = lightCol.rgb/2400.0;
2023-10-07 22:18:20 -04:00
float NdotL = clamp(dot(normal, normalize(WsunVec*mat3(gbufferModelViewInverse))),0.0,1.0); NdotL = clamp((-15 + NdotL*255.0) / 240.0 ,0.0,1.0);
2024-05-04 21:36:06 -04:00
float Shadows = 1.0;
2023-10-07 22:18:20 -04:00
2024-05-04 21:36:06 -04:00
float shadowMapFalloff = smoothstep(0.0, 1.0, min(max(1.0 - length(feetPlayerPos) / (shadowDistance+16),0.0)*5.0,1.0));
float shadowMapFalloff2 = smoothstep(0.0, 1.0, min(max(1.0 - length(feetPlayerPos) / shadowDistance,0.0)*5.0,1.0));
2023-10-07 22:18:20 -04:00
2024-05-04 21:36:06 -04:00
float LM_shadowMapFallback = min(max(lightmap.y-0.8, 0.0) * 25,1.0);
2023-10-07 22:18:20 -04:00
2024-05-04 21:36:06 -04:00
vec3 shadowPlayerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
Shadows = ComputeShadowMap(DirectLightColor, shadowPlayerPos, shadowMapFalloff, blueNoise());
2023-10-07 22:18:20 -04:00
2024-05-04 21:36:06 -04:00
Shadows = mix(LM_shadowMapFallback, Shadows, shadowMapFalloff2);
2023-10-07 22:18:20 -04:00
2024-11-15 17:54:18 -05:00
#ifdef CLOUDS_SHADOWS
Shadows *= GetCloudShadow(feetPlayerPos+cameraPosition, WsunVec);
#endif
2023-10-07 22:18:20 -04:00
2024-05-04 21:36:06 -04:00
Direct_lighting = DirectLightColor * NdotL * Shadows;
2023-10-07 22:18:20 -04:00
2024-11-15 17:54:18 -05:00
vec3 AmbientLightColor = averageSkyCol_Clouds/900.0;
2024-05-04 21:36:06 -04:00
vec3 ambientcoefs = worldSpaceNormal / dot(abs(worldSpaceNormal), vec3(1.0));
2023-10-07 22:18:20 -04:00
float SkylightDir = ambientcoefs.y*1.5;
2024-05-04 21:36:06 -04:00
float skylight = max(pow(viewToWorld(flatnormal).y*0.5+0.5,0.1) + SkylightDir, 0.2);
2023-10-23 17:41:30 -04:00
AmbientLightColor *= skylight;
2024-06-23 21:43:15 -04:00
Indirect_lighting = doIndirectLighting(AmbientLightColor, MinimumLightColor, lightmap.y);
2023-10-07 22:18:20 -04:00
#endif
2023-04-16 16:18:26 -04:00
2023-08-03 00:23:29 -04:00
#ifdef NETHER_SHADER
2024-11-15 17:54:18 -05:00
Indirect_lighting = volumetricsFromTex(normalize(worldSpaceNormal), colortex4, 0).rgb / 1200.0 / 1.5;
2023-08-02 21:43:18 -04:00
#endif
2023-04-16 16:18:26 -04:00
2023-08-03 00:23:29 -04:00
#ifdef END_SHADER
2024-11-15 17:54:18 -05:00
// float vortexBounds = clamp(vortexBoundRange - length(feetPlayerPos+cameraPosition), 0.0,1.0);
// vec3 lightPos = LightSourcePosition(feetPlayerPos+cameraPosition, cameraPosition,vortexBounds);
// float lightningflash = texelFetch2D(colortex4,ivec2(1,1),0).x/150.0;
// vec3 lightColors = LightSourceColors(vortexBounds, lightningflash);
// float NdotL = clamp(dot(worldSpaceNormal, normalize(-lightPos))*0.5+0.5,0.0,1.0);
// NdotL *= NdotL;
// Direct_lighting = lightColors * endFogPhase(lightPos) * NdotL;
2023-12-17 22:25:26 -05:00
float vortexBounds = clamp(vortexBoundRange - length(feetPlayerPos+cameraPosition), 0.0,1.0);
vec3 lightPos = LightSourcePosition(feetPlayerPos+cameraPosition, cameraPosition,vortexBounds);
float lightningflash = texelFetch2D(colortex4,ivec2(1,1),0).x/150.0;
vec3 lightColors = LightSourceColors(vortexBounds, lightningflash);
2024-05-04 21:36:06 -04:00
2024-11-15 17:54:18 -05:00
float end_NdotL = clamp(dot(worldSpaceNormal, normalize(-lightPos))*0.5+0.5,0.0,1.0);
end_NdotL *= end_NdotL;
2023-12-17 22:25:26 -05:00
2024-11-15 17:54:18 -05:00
float fogShadow = GetEndFogShadow(feetPlayerPos+cameraPosition, lightPos);
float endPhase = endFogPhase(lightPos);
2023-12-17 22:25:26 -05:00
2024-11-15 17:54:18 -05:00
Direct_lighting += lightColors * endPhase * end_NdotL * fogShadow;
vec3 AmbientLightColor = vec3(0.3,0.6,1.0) ;
2024-06-19 21:44:21 -04:00
2024-06-23 21:43:15 -04:00
Indirect_lighting = AmbientLightColor + 0.7 * AmbientLightColor * dot(worldSpaceNormal, normalize(feetPlayerPos));
2024-11-15 17:54:18 -05:00
Indirect_lighting *= 0.1;
2023-08-02 21:43:18 -04:00
#endif
2024-05-04 21:36:06 -04:00
2024-06-23 21:43:15 -04:00
///////////////////////// BLOCKLIGHT LIGHTING OR LPV LIGHTING OR FLOODFILL COLORED LIGHTING
2024-05-04 21:36:06 -04:00
#ifdef IS_LPV_ENABLED
2024-06-16 23:35:13 -04:00
vec3 normalOffset = vec3(0.0);
if (any(greaterThan(abs(worldSpaceNormal), vec3(1.0e-6))))
normalOffset = 0.5*worldSpaceNormal;
2024-05-04 21:36:06 -04:00
2024-05-04 23:55:14 -04:00
#if LPV_NORMAL_STRENGTH > 0
2024-06-03 12:54:45 -04:00
if (any(greaterThan(abs(normal), vec3(1.0e-6)))) {
vec3 texNormalOffset = -normalOffset + viewToWorld(normal);
normalOffset = mix(normalOffset, texNormalOffset, (LPV_NORMAL_STRENGTH*0.01));
}
2024-05-04 21:36:06 -04:00
#endif
2024-05-04 23:55:14 -04:00
vec3 lpvPos = GetLpvPosition(feetPlayerPos) + normalOffset;
2024-05-04 21:36:06 -04:00
#else
const vec3 lpvPos = vec3(0.0);
2024-03-12 17:16:30 -04:00
#endif
2023-10-18 17:43:29 -04:00
2024-06-23 21:43:15 -04:00
Indirect_lighting += doBlockLightLighting( vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.x, exposure, feetPlayerPos, lpvPos);
2023-04-16 16:18:26 -04:00
2024-05-04 21:36:06 -04:00
vec3 FinalColor = (Indirect_lighting + Direct_lighting) * Albedo;
2024-11-15 17:54:18 -05:00
#if EMISSIVE_TYPE == 2 || EMISSIVE_TYPE == 3
Emission(FinalColor, Albedo, SpecularTex.b, exposure);
#endif
2024-05-04 21:36:06 -04:00
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// SPECULAR LIGHTING /////////////////////////////
////////////////////////////////////////////////////////////////////////////////
2023-08-02 21:43:18 -04:00
2023-10-07 22:18:20 -04:00
#ifdef DAMAGE_BLOCK_EFFECT
2024-11-15 17:54:18 -05:00
#undef FORWARD_SPECULAR
2023-10-07 22:18:20 -04:00
#endif
2024-05-04 21:36:06 -04:00
2024-11-15 17:54:18 -05:00
#ifdef FORWARD_SPECULAR
2024-05-04 21:36:06 -04:00
2024-11-15 17:54:18 -05:00
float harcodedF0 = 0.02;
2023-04-16 16:18:26 -04:00
2024-05-04 21:36:06 -04:00
// if nothing is chosen, no smoothness and no reflectance
vec2 specularValues = vec2(1.0, 0.0);
2024-11-15 17:54:18 -05:00
2024-05-04 21:36:06 -04:00
// hardcode specular values for select blocks like glass, water, and slime
2024-11-15 17:54:18 -05:00
if(isReflective) specularValues = vec2(1.0, harcodedF0);
2024-05-04 21:36:06 -04:00
// detect if the specular texture is used, if it is, overwrite hardcoded values
2024-05-09 18:24:29 -04:00
if(SpecularTex.r > 0.0 && SpecularTex.g <= 1.0) specularValues = SpecularTex.rg;
2024-05-04 21:36:06 -04:00
2024-11-15 17:54:18 -05:00
float f0 = isReflective ? max(specularValues.g, harcodedF0) : specularValues.g;
2024-05-04 21:36:06 -04:00
#ifdef HAND
2024-11-15 17:54:18 -05:00
f0 = max(specularValues.g, harcodedF0);
2024-05-04 21:36:06 -04:00
#endif
2023-10-07 22:18:20 -04:00
2024-11-15 17:54:18 -05:00
float roughness = specularValues.r;
2024-05-04 21:36:06 -04:00
2024-11-15 17:54:18 -05:00
if(UnchangedAlpha <= 0.0 && !isReflective) f0 = 0.0;
2024-05-04 21:36:06 -04:00
2024-11-15 17:54:18 -05:00
if (f0 > 0.0){
if(isReflective) f0 = max(f0, harcodedF0);
float reflectance = 0.0;
2024-05-04 21:36:06 -04:00
2024-11-15 17:54:18 -05:00
#if !defined OVERWORLD_SHADER
vec3 WsunVec = vec3(0.0);
vec3 DirectLightColor = WsunVec;
float Shadows = 0.0;
#endif
2024-01-11 21:38:03 -05:00
2024-11-15 17:54:18 -05:00
vec3 specularReflections = specularReflections(viewPos, normalize(feetPlayerPos), WsunVec, vec3(blueNoise(), vec2(interleaved_gradientNoise_temporal())), viewToWorld(normal), roughness, f0, Albedo, FinalColor*gl_FragData[0].a, DirectLightColor * Shadows, lightmap.y, false, reflectance);
gl_FragData[0].a = gl_FragData[0].a + (1.0-gl_FragData[0].a) * reflectance;
// invert the alpha blending darkening on the color so you can interpolate between diffuse and specular and keep buffer blending
gl_FragData[0].rgb = clamp(specularReflections / gl_FragData[0].a * 0.1,0.0,65000.0);
}else{
gl_FragData[0].rgb = clamp(FinalColor * 0.1,0.0,65000.0);
2023-04-16 16:18:26 -04:00
}
2023-08-02 21:43:18 -04:00
#else
2024-05-04 21:36:06 -04:00
gl_FragData[0].rgb = FinalColor*0.1;
2023-08-02 21:43:18 -04:00
#endif
2024-02-16 21:28:13 -05:00
2024-05-04 21:36:06 -04:00
#if defined DISTANT_HORIZONS && defined DH_OVERDRAW_PREVENTION && !defined HAND
bool WATER = texture2D(colortex7, gl_FragCoord.xy*texelSize).a > 0.0 && length(feetPlayerPos) > far-16*4 && texture2D(depthtex1, gl_FragCoord.xy*texelSize).x >= 1.0;
2024-02-16 21:28:13 -05:00
2024-05-04 21:36:06 -04:00
if(WATER) gl_FragData[0].a = 0.0;
2024-02-16 21:28:13 -05:00
#endif
2023-04-16 16:18:26 -04:00
2023-08-02 21:43:18 -04:00
#ifndef HAND
2024-05-04 21:36:06 -04:00
gl_FragData[1] = vec4(Albedo, MATERIALS);
2023-08-02 21:43:18 -04:00
#endif
2024-02-06 20:04:11 -05:00
#if DEBUG_VIEW == debug_DH_WATER_BLENDING
if(gl_FragCoord.x*texelSize.x < 0.47) gl_FragData[0] = vec4(0.0);
#endif
2024-05-04 21:36:06 -04:00
#if DEBUG_VIEW == debug_NORMALS
2024-11-15 17:54:18 -05:00
gl_FragData[0].rgb = viewToWorld(normalize(normal.xyz)) * 0.1;
gl_FragData[0].a = 1;
2024-05-04 21:36:06 -04:00
#endif
#if DEBUG_VIEW == debug_INDIRECT
2024-11-15 17:54:18 -05:00
gl_FragData[0].rgb = Indirect_lighting * 0.1;
2024-05-04 21:36:06 -04:00
#endif
#if DEBUG_VIEW == debug_DIRECT
gl_FragData[0].rgb = Direct_lighting * 0.1;
#endif
2024-02-05 16:04:37 -05:00
2024-11-15 17:54:18 -05:00
// gl_FragData[3].a = clamp(lightmap.y,0.0,1.0);
gl_FragData[3] = vec4(encodeVec2(lightmap.x, lightmap.y), 1, 1, 1);
2024-05-09 18:24:29 -04:00
2023-04-16 16:18:26 -04:00
}
2023-08-02 21:43:18 -04:00
}