add v1.541 (Extreme)

This commit is contained in:
2025-11-18 08:49:24 +01:00
commit f2788f598f
105 changed files with 10844 additions and 0 deletions

View File

@@ -0,0 +1,291 @@
#version 120
/* DRAWBUFFERS:34 */
#define gbuffers_shadows
#define composite0
#define composite2
#define lightingColors
#include "/shaders.settings"
#ifdef HandLight
uniform int heldBlockLightValue;
uniform int heldBlockLightValue2;
#endif
varying vec2 texcoord;
varying vec3 sunVec;
varying vec3 upVec;
varying vec3 sunlight;
varying float tr;
varying float sunVisibility;
varying float moonVisibility;
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
uniform sampler2D colortex0;
uniform sampler2D colortex1;
uniform sampler2D colortex2;
uniform sampler2D composite;
uniform mat4 gbufferProjectionInverse;
uniform int isEyeInWater;
uniform float aspectRatio;
uniform float near;
uniform float far;
uniform float viewWidth;
uniform float viewHeight;
uniform float rainStrength;
uniform float nightVision;
uniform float screenBrightness;
float comp = 1.0-near/far/far; //distance above that are considered as sky
const vec2 check_offsets[25] = vec2[25](vec2(-0.4894566f,-0.3586783f),
vec2(-0.1717194f,0.6272162f),
vec2(-0.4709477f,-0.01774091f),
vec2(-0.9910634f,0.03831699f),
vec2(-0.2101292f,0.2034733f),
vec2(-0.7889516f,-0.5671548f),
vec2(-0.1037751f,-0.1583221f),
vec2(-0.5728408f,0.3416965f),
vec2(-0.1863332f,0.5697952f),
vec2(0.3561834f,0.007138769f),
vec2(0.2868255f,-0.5463203f),
vec2(-0.4640967f,-0.8804076f),
vec2(0.1969438f,0.6236954f),
vec2(0.6999109f,0.6357007f),
vec2(-0.3462536f,0.8966291f),
vec2(0.172607f,0.2832828f),
vec2(0.4149241f,0.8816f),
vec2(0.136898f,-0.9716249f),
vec2(-0.6272043f,0.6721309f),
vec2(-0.8974028f,0.4271871f),
vec2(0.5551881f,0.324069f),
vec2(0.9487136f,0.2605085f),
vec2(0.7140148f,-0.312601f),
vec2(0.0440252f,0.9363738f),
vec2(0.620311f,-0.6673451f)
);
vec3 decode (vec2 enc){
vec2 fenc = enc*4-2;
float f = dot(fenc,fenc);
float g = sqrt(1-f/4.0);
vec3 n;
n.xy = fenc*g;
n.z = 1-f/2;
return n;
}
vec3 YCoCg2RGB(vec3 c){
c.y-=0.5;
c.z-=0.5;
return vec3(c.r+c.g-c.b, c.r + c.b, c.r - c.g - c.b);
}
#ifdef Celshading
float edepth(vec2 coord) {
return texture2D(depthtex1,coord).x;
}
vec3 celshade(vec3 clrr) {
//edge detect
float dtresh = 1.0/(far-near) / (5000.0*Celradius);
vec4 dc = vec4(edepth(texcoord.xy));
vec3 border = vec3(1.0/viewWidth, 1.0/viewHeight, 0.0)*Celborder;
vec4 sa = vec4(edepth(texcoord.xy + vec2(-border.x,-border.y)),
edepth(texcoord.xy + vec2(border.x,-border.y)),
edepth(texcoord.xy + vec2(-border.x,border.z)),
edepth(texcoord.xy + vec2(border.z,border.y)));
//opposite side samples
vec4 sb = vec4(edepth(texcoord.xy + vec2(border.x,border.y)),
edepth(texcoord.xy + vec2(-border.x,border.y)),
edepth(texcoord.xy + vec2(border.x,border.z)),
edepth(texcoord.xy + vec2(border.z,-border.y)));
vec4 dd = abs(2.0* dc - sa - sb) - dtresh;
dd = step(dd.xyzw, vec4(0.0));
float e = clamp(dot(dd,vec4(0.25f)),0.0,1.0);
return clrr*e;
}
#endif
#ifdef TAA
vec2 texelSize = vec2(1.0/viewWidth,1.0/viewHeight);
uniform int framemod8;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
vec2(-3,-5.)/8.,
vec2(-5.,5.)/8.,
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
#endif
vec3 toScreenSpace(vec3 p) {
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
vec3 p3 = p * 2.0 - 1.0;
vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
return fragposition.xyz / fragposition.w;
}
#ifdef SSDO
uniform float frameTimeCounter;
//modified version of Yuriy O'Donnell's SSDO (License MIT -> https://github.com/kayru/dssdo)
float calcSSDO(vec3 fragpos, vec3 normal){
float finalAO = 0.0;
float radius = 0.05 / (fragpos.z);
const float attenuation_angle_threshold = 0.1;
const int num_samples = 16;
const float ao_weight = 1.0;
#ifdef TAA
float noise = fract(0.75487765 * gl_FragCoord.x + 0.56984026 * gl_FragCoord.y);
noise = fract(frameTimeCounter * 2.0 + noise);
#else
float noise = 1.0;
#endif
for( int i=0; i<num_samples; ++i ){
vec2 texOffset = pow(length(check_offsets[i].xy),0.5)*radius*vec2(1.0,aspectRatio)*normalize(check_offsets[i].xy);
vec2 newTC = texcoord+texOffset*noise;
#ifdef TAA
vec3 t0 = toScreenSpace(vec3(newTC-offsets[framemod8]*texelSize*0.5, texture2D(depthtex1, newTC).x));
#else
vec3 t0 = toScreenSpace(vec3(newTC, texture2D(depthtex1, newTC).x));
#endif
vec3 center_to_sample = t0.xyz - fragpos.xyz;
float dist = length(center_to_sample);
vec3 center_to_sample_normalized = center_to_sample / dist;
float attenuation = 1.0-clamp(dist/6.0,0.0,1.0);
float dp = dot(normal, center_to_sample_normalized);
attenuation = sqrt(max(dp,0.0))*attenuation*attenuation * step(attenuation_angle_threshold, dp);
finalAO += attenuation * (ao_weight / num_samples);
}
return finalAO;
}
#endif
vec2 decodeVec2(float a){
const vec2 constant1 = 65535. / vec2( 256., 65536.);
const float constant2 = 256. / 255.;
return fract( a * constant1 ) * constant2 ;
}
uniform mat4 gbufferModelViewInverse;
void main() {
//Setup depth
float depth0 = texture2D(depthtex0, texcoord).x; //everything
float depth1 = texture2D(depthtex1, texcoord).x; //transparency
bool sky = (depth1 >= 1.0);
vec4 albedo = texture2D(colortex0,texcoord);
vec3 normal = decode(texture2D(colortex1, texcoord).xy);
vec2 lightmap = texture2D(colortex1, texcoord.xy).zw;
bool translucent = albedo.b > 0.69 && albedo.b < 0.71;
bool emissive = albedo.b > 0.59 && albedo.b < 0.61;
vec3 color = vec3(albedo.rg,0.0);
vec2 a0 = texture2D(colortex0,texcoord + vec2(1.0/viewWidth,0.0)).rg;
vec2 a1 = texture2D(colortex0,texcoord - vec2(1.0/viewWidth,0.0)).rg;
vec2 a2 = texture2D(colortex0,texcoord + vec2(0.0,1.0/viewHeight)).rg;
vec2 a3 = texture2D(colortex0,texcoord - vec2(0.0,1.0/viewHeight)).rg;
vec4 lumas = vec4(a0.x,a1.x,a2.x,a3.x);
vec4 chromas = vec4(a0.y,a1.y,a2.y,a3.y);
vec4 w = 1.0-step(0.1176, abs(lumas - color.x));
float W = dot(w,vec4(1.0));
w.x = (W==0.0)? 1.0:w.x; W = (W==0.0)? 1.0:W;
bool pattern = (mod(gl_FragCoord.x,2.0)==mod(gl_FragCoord.y,2.0));
color.b= dot(w,chromas)/W;
color.rgb = (pattern)?color.rbg:color.rgb;
color.rgb = YCoCg2RGB(color.rgb);
color = pow(color,vec3(2.2));
if (!sky){
//Water and Ice
vec3 Wnormal = texture2D(colortex2,texcoord).xyz;
bool iswater = Wnormal.z < 0.2499 && dot(Wnormal,Wnormal) > 0.0;
bool isice = Wnormal.z > 0.2499 && Wnormal.z < 0.4999 && dot(Wnormal,Wnormal) > 0.0;
bool isnsun = (iswater||isice) || ((!iswater||!isice) && isEyeInWater == 1);
/*--------------------------------------------------------------------------------------*/
#ifdef TAA
vec2 newTC = gl_FragCoord.xy*texelSize;
vec3 TAAfragpos = toScreenSpace(vec3(newTC-offsets[framemod8]*texelSize*0.5, texture2D(depthtex1, newTC).x));
#else
vec3 TAAfragpos = toScreenSpace(vec3(texcoord,depth1)); //was depth0 before, might cause issues
#endif
#ifdef Whiteworld
color += vec3(1.5);
#endif
#ifdef Celshading
color = celshade(color);
#endif
float ao = 1.0;
#ifdef SSDO
float occlusion = calcSSDO(TAAfragpos, normal);
if(!iswater)ao = pow(1.0-occlusion, ao_strength);
#endif
//Emissive blocks lighting and colors
#ifdef HandLight
bool underwaterlava = (isEyeInWater == 1.0 || isEyeInWater == 2.0);
if(!underwaterlava) lightmap.x = max(lightmap.x, max(max(float(heldBlockLightValue), float(heldBlockLightValue2)) - 1.0 - length(TAAfragpos), 0.0) / 15.0);
#endif
float torch_lightmap = 16.0-min(15.0,(lightmap.x-0.5/16.0)*16.0*16.0/15.0);
float fallof1 = clamp(1.0 - pow(torch_lightmap/16.0,4.0),0.0,1.0);
torch_lightmap = fallof1*fallof1/(torch_lightmap*torch_lightmap+1.0);
float c_emitted = dot((color.rgb),vec3(1.0,0.6,0.4))/2.0;
float emitted = emissive? clamp(c_emitted*c_emitted,0.0,1.0)*torch_lightmap : 0.0;
vec3 emissiveLightC = vec3(emissive_R,emissive_G,emissive_B);
/*------------------------------------------------------------------------------------------*/
//Lighting and colors
float NdotL = dot(normal,sunVec);
float NdotU = dot(normal,upVec);
const vec3 moonlight = vec3(0.5, 0.9, 1.8) * Moonlight;
vec2 visibility = vec2(sunVisibility,moonVisibility);
float skyL = max(lightmap.y-2./16.0,0.0)*1.14285714286;
float SkyL2 = skyL*skyL;
float skyc2 = mix(1.0,SkyL2,skyL);
vec4 bounced = vec4(NdotL,NdotL,NdotL,NdotU) * vec4(-0.14*skyL*skyL,0.33,0.7,0.1) + vec4(0.6,0.66,0.7,0.25);
bounced *= vec4(skyc2,skyc2,visibility.x-tr*visibility.x,0.8);
vec3 sun_ambient = bounced.w * (vec3(0.1, 0.5, 1.1)*2.4+rainStrength*2.3*vec3(0.05,-0.33,-0.9))+ 1.6*sunlight*(sqrt(bounced.w)*bounced.x*2.4 + bounced.z)*(1.0-rainStrength*0.99);
vec3 moon_ambient = (moonlight*0.7 + moonlight*bounced.y)*4.0;
vec3 amb1 = (sun_ambient*visibility.x + moon_ambient*visibility.y)*SkyL2*(0.03*0.65+tr*0.17*0.65);
float finalminlight = (nightVision > 0.01)? 0.15 : (minlight+0.006)+(screenBrightness*0.0125); //add nightvision support but make sure minlight is still adjustable.
vec3 ambientC = ao*amb1 + emissiveLightC*(emitted*15.*color + torch_lightmap*ao)*0.66 + ao*finalminlight*min(skyL+6/16.,9/16.)*normalize(amb1+0.0001);
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
color *= (ambientC*(isnsun?1.0/(SkyL2*skyL*0.5+0.5):1.0)*1.4)*0.63;
}
//Draw skytexture from gbuffers_skytextured
if (sky)color = pow(texture2D(composite, texcoord.xy).rgb,vec3(2.2));
gl_FragData[0] = vec4(0.0); //used by custom skycolor, godrays and VL not needed in end dimension
gl_FragData[1] = vec4(pow(color/257.0,vec3(0.454)), 1.0);
}

View File

@@ -0,0 +1,55 @@
#version 120
#define lightingColors
#include "/shaders.settings"
varying vec2 texcoord;
varying vec3 sunVec;
varying vec3 upVec;
varying vec3 sunlight;
varying float tr;
varying float sunVisibility;
varying float moonVisibility;
uniform vec3 sunPosition;
uniform vec3 upPosition;
uniform int worldTime;
const vec3 ToD[7] = vec3[7]( vec3(0.58597,0.16,0.005),
vec3(0.58597,0.31,0.08),
vec3(0.58597,0.45,0.16),
vec3(0.58597,0.5,0.35),
vec3(0.58597,0.5,0.36),
vec3(0.58597,0.5,0.37),
vec3(0.58597,0.5,0.38));
void main() {
//Position
gl_Position = ftransform();
texcoord = (gl_MultiTexCoord0).xy;
/*--------------------------------*/
//Sun/moon pos
sunVec = normalize(sunPosition);
upVec = vec3(0.0, 1.0, 0.0); //fix for loading shaderpacks in nether and end, optifine bug.
float SdotU = dot(sunVec,upVec);
sunVisibility = pow(clamp(SdotU+0.15,0.0,0.15)/0.15,4.0);
moonVisibility = pow(clamp(-SdotU+0.15,0.0,0.15)/0.15,4.0);
/*--------------------------------*/
//reduced the sun color to a 7 array
float hour = max(mod(worldTime/1000.0+2.0,24.0)-2.0,0.0); //-0.1
float cmpH = max(-abs(floor(hour)-6.0)+6.0,0.0); //12
float cmpH1 = max(-abs(floor(hour)-5.0)+6.0,0.0); //1
vec3 temp = ToD[int(cmpH)];
vec3 temp2 = ToD[int(cmpH1)];
sunlight = mix(temp,temp2,fract(hour));
sunlight.rgb += vec3(r_multiplier,g_multiplier,b_multiplier); //allows lighting colors to be tweaked.
sunlight.rgb *= light_brightness; //brightness needs to be adjusted if we tweak lighting colors.
vec2 trCalc = min(abs(worldTime-vec2(23000.0,12700.0)),750.0);
tr = max(min(trCalc.x,trCalc.y)/375.0-1.0,0.0);
}

View File

@@ -0,0 +1,287 @@
#version 120
#extension GL_ARB_shader_texture_lod : enable
const bool gaux1MipmapEnabled = true;
/* DRAWBUFFERS:3 */
#define composite2
#define composite1
#define lightingColors
#include "/shaders.settings"
varying vec2 texcoord;
uniform sampler2D composite;
uniform sampler2D gaux1;
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
uniform sampler2D colortex0;
uniform sampler2D colortex1;
uniform sampler2D colortex2;
uniform sampler2D gdepth;
uniform sampler2D noisetex;
uniform sampler2D gaux3;
uniform sampler2D gaux2;
uniform vec3 cameraPosition;
uniform mat4 gbufferProjection;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferModelViewInverse;
uniform int isEyeInWater;
uniform float near;
uniform float far;
uniform float screenBrightness;
uniform float frameTimeCounter;
uniform float blindness;
#if MC_VERSION >= 11900
uniform float darknessFactor;
uniform float darknessLightFactor;
#endif
/*------------------------------------------*/
float comp = 1.0-near/far/far;
#if defined waterRefl || defined iceRefl
const int maxf = 3; //number of refinements
const float ref = 0.11; //refinement multiplier
const float inc = 3.0; //increasement factor at each step
vec3 nvec3(vec4 pos) {
return pos.xyz/pos.w;
}
vec4 nvec4(vec3 pos) {
return vec4(pos.xyz, 1.0);
}
float cdist(vec2 coord) {
return max(abs(coord.s-0.5),abs(coord.t-0.5))*2.0;
}
vec4 raytrace(vec3 fragpos, vec3 skycolor, vec3 rvector) {
vec4 color = vec4(0.0);
vec3 start = fragpos;
rvector *= 1.2;
fragpos += rvector;
vec3 tvector = rvector;
int sr = 0;
for(int i=0;i<25;i++){
vec3 pos = nvec3(gbufferProjection * nvec4(fragpos)) * 0.5 + 0.5;
if(pos.x < 0 || pos.x > 1 || pos.y < 0 || pos.y > 1 || pos.z < 0 || pos.z > 1.0) break;
vec3 fragpos0 = vec3(pos.st, texture2D(depthtex1, pos.st).r);
fragpos0 = nvec3(gbufferProjectionInverse * nvec4(fragpos0 * 2.0 - 1.0));
float err = distance(fragpos,fragpos0);
if(err < pow(length(rvector),1.175)){ //if(err < pow(length(rvector)*1.85,1.15)){ <- old, adjusted error check to reduce banding issues/glitches
sr++;
if(sr >= maxf){
bool land = texture2D(depthtex1, pos.st).r < comp;
color = pow(texture2DLod(gaux1, pos.st, 1),vec4(2.2))*257.0;
if (isEyeInWater == 0) color.rgb = land ? mix(color.rgb,skycolor,0.5) : skycolor; //reflections color, blend it with fake sky color.
color.a = clamp(1.0 - pow(cdist(pos.st), 20.0), 0.0, 1.0);
break;
}
tvector -= rvector;
rvector *= ref;
}
rvector *= inc;
tvector += rvector;
fragpos = start + tvector;
}
return color;
}
#endif
#ifdef Refraction
mat2 rmatrix(float rad){
return mat2(vec2(cos(rad), -sin(rad)), vec2(sin(rad), cos(rad)));
}
float calcWaves(vec2 coord){
vec2 movement = abs(vec2(0.0, -frameTimeCounter * 0.5));
coord *= 0.4;
vec2 coord0 = coord * rmatrix(1.0) - movement * 4.5;
coord0.y *= 3.0;
vec2 coord1 = coord * rmatrix(0.5) - movement * 1.5;
coord1.y *= 3.0;
vec2 coord2 = coord * frameTimeCounter * 0.02;
coord0 *= waveSize;
coord1 *= (waveSize-0.5); //create an offset for smaller waves
float wave = texture2D(noisetex,coord0 * 0.005).x * 10.0; //big waves
wave -= texture2D(noisetex,coord1 * 0.010416).x * 7.0; //small waves
wave += 1.0-sqrt(texture2D(noisetex,coord2 * 0.0416).x * 6.5) * 1.33; //noise texture
wave *= 0.0157;
return wave;
}
vec2 calcBump(vec2 coord){
const vec2 deltaPos = vec2(0.25, 0.0);
float h0 = calcWaves(coord);
float h1 = calcWaves(coord + deltaPos.xy);
float h2 = calcWaves(coord - deltaPos.xy);
float h3 = calcWaves(coord + deltaPos.yx);
float h4 = calcWaves(coord - deltaPos.yx);
float xDelta = ((h1-h0)+(h0-h2));
float yDelta = ((h3-h0)+(h0-h4));
return vec2(xDelta,yDelta)*0.05;
}
#endif
vec3 decode (vec2 enc){
vec2 fenc = enc*4-2;
float f = dot(fenc,fenc);
float g = sqrt(1-f/4.0);
vec3 n;
n.xy = fenc*g;
n.z = 1-f/2;
return n;
}
void main() {
vec3 c = pow(texture2D(gaux1,texcoord).xyz,vec3(2.2))*257.;
//Depth and fragpos
float depth0 = texture2D(depthtex0, texcoord).x;
vec4 fragpos0 = gbufferProjectionInverse * (vec4(texcoord, depth0, 1.0) * 2.0 - 1.0);
fragpos0 /= fragpos0.w;
vec3 normalfragpos0 = normalize(fragpos0.xyz);
float depth1 = texture2D(depthtex1, texcoord).x;
vec4 fragpos1 = gbufferProjectionInverse * (vec4(texcoord, depth1, 1.0) * 2.0 - 1.0);
fragpos1 /= fragpos1.w;
vec3 normalfragpos1 = normalize(fragpos1.xyz);
/*--------------------------------------------------------------------------------------------*/
vec4 trp = texture2D(gaux3,texcoord.xy);
bool transparency = dot(trp.xyz,trp.xyz) > 0.000001;
#ifdef Refraction
if (texture2D(colortex2, texcoord).z < 0.2499 && dot(texture2D(colortex2,texcoord).xyz,texture2D(colortex2,texcoord).xyz) > 0.0 || isEyeInWater == 1.0) { //reflective water
vec2 wpos = (gbufferModelViewInverse*fragpos0).xz+cameraPosition.xz;
vec2 refraction = texcoord.xy + calcBump(wpos);
c = pow(texture2D(gaux1, refraction).xyz, vec3(2.2))*257.0;
//remove underwater tint, not needed in end
}
#endif
//Draw fog
vec3 fogC = vec3(0.001, 0.0, 0.002);
//float fogF = calcFog(fragpos0.xyz);
//Render before transparency
float mats = texture2D(colortex0,texcoord).b;
bool isMetallic = mats > 0.39 && mats < 0.41;
bool isPolished = mats > 0.49 && mats < 0.51;
#ifndef polishedRefl
isPolished = false;
#endif
#ifndef metallicRefl
isMetallic = false;
#endif
#if defined metallicRefl || defined polishedRefl
if (isMetallic || isPolished) {
vec3 relfNormal = decode(texture2D(colortex1,texcoord).xy);
vec3 reflectedVector = reflect(normalfragpos0, relfNormal);
float normalDotEye = dot(relfNormal, normalfragpos0);
float fresnel = pow(clamp(1.0 + normalDotEye,0.0,1.0), 4.0);
fresnel = mix(0.09,1.0,fresnel); //F0
vec3 sky_c = fogC*metallicSky;
vec4 reflection = raytrace(fragpos0.xyz, sky_c, reflectedVector);
reflection.rgb = mix(sky_c, reflection.rgb, reflection.a)*0.5;
c = mix(c,reflection.rgb,fresnel*metalStrength);
}
#endif
if (transparency) {
vec3 normal = texture2D(colortex2,texcoord).xyz;
float sky = normal.z;
bool reflectiveWater = sky < 0.2499 && dot(normal,normal) > 0.0;
bool reflectiveIce = sky > 0.2499 && sky < 0.4999 && dot(normal,normal) > 0.0;
bool iswater = sky < 0.2499;
bool isice = sky > 0.2499 && sky < 0.4999;
if (iswater) sky *= 4.0;
if (isice) sky = (sky - 0.25)*4.0;
if (!iswater && !isice) sky = (sky - 0.5)*4.0;
sky = clamp(sky*1.2-2./16.0*1.2,0.,1.0);
sky *= sky;
normal = decode(normal.xy);
normal = normalize(normal);
//draw fog for transparency
float iswater2 = float(iswater);
//c = mix(c, fogC, 1.0-exp(-length(fragpos1.xyz)*(0.0075+(screenBrightness*0.001))));
if(depth1 < comp)c = mix(fogC, c, exp(-exp2(length(fragpos1.xyz) / far * 16.0 - 14.0)));
//Draw transparency
vec3 finalAc = texture2D(gaux2, texcoord.xy).rgb;
float alphaT = clamp(length(trp.rgb)*1.02,0.0,1.0);
c = mix(c,c*(trp.rgb*0.9999+0.0001)*1.732,alphaT)*(1.0-alphaT) + finalAc;
/*-----------------------------------------------------------------------------------------*/
//Reflections
if (reflectiveWater || reflectiveIce) {
vec3 reflectedVector = reflect(normalfragpos1, normal);
vec3 hV= normalize(reflectedVector - normalfragpos1);
float normalDotEye = dot(hV, normalfragpos1);
float F0 = 0.09;
float fresnel = pow(clamp(1.0 + normalDotEye,0.0,1.0), 4.0) ;
fresnel = fresnel+F0*(1.0-fresnel);
vec3 sky_c = fogC*0.5; //Use fogC as our custom sky reflections
#if defined waterRefl || defined iceRefl
vec4 reflection = raytrace(fragpos0.xyz, sky_c, reflectedVector);
#else
vec4 reflection = vec4(0.0);
fresnel *= 0.5;
#endif
reflection.rgb = mix(sky_c, reflection.rgb, reflection.a)*0.5;
#ifdef IceGlassReflections
fresnel *= 0.5*float(isice) + 0.5*iswater2;
#else
fresnel *= 1.0*iswater2;
#endif
c = mix(c,reflection.rgb,fresnel*1.5);
}
}
#ifdef Fog
if(depth0 < comp)c = mix(c, fogC*(1.0-isEyeInWater), 1.0-exp(-length(fragpos0.xyz)*(0.0075+(screenBrightness*0.001)))); //scale with screenbrightness
if(depth0 < comp)c = mix(fogC, c, exp(-exp2(length(fragpos0.xyz) / far * 16.0 - 14.0)));
#endif
#ifdef Underwater_Fog
vec3 ufogC = vec3(0.0, 0.005, 0.0125);
if (isEyeInWater == 1.0) c = mix(c, ufogC, 1.0-exp(-length(fragpos0.xyz)/uFogDensity));
#endif
if (isEyeInWater == 2.0) c = mix(c, vec3(1.0, 0.0125, 0.0), 1.0-exp(-length(fragpos0.xyz))); //lava fog
if(blindness > 0.9) c = mix(c, vec3(0.0), 1.0-exp(-length(fragpos1.xyz)*1.125)); //blindness fog
#if MC_VERSION >= 11900
if(darknessFactor > 0.9) c = mix(c, vec3(0.0), 1.0-exp(-length(fragpos1.xyz)*0.125)) * (1.0-darknessLightFactor*2.0); //Darkness fog, adjust for end.
#endif
c *= 0.142;
gl_FragData[0] = vec4(c,1.0);
}

View File

@@ -0,0 +1,8 @@
#version 120
varying vec2 texcoord;
void main() {
gl_Position = ftransform();
texcoord = (gl_MultiTexCoord0).xy;
}

View File

@@ -0,0 +1,145 @@
#version 120
/* DRAWBUFFERS:7 */
/* Temporal anti-aliasing (TAA) and adaptive sharpening implementation based on Chocapic13, all credits belong to him:
https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/1293898-1-14-chocapic13s-shaders */
#define composite2
#include "/shaders.settings"
varying vec2 texcoord;
uniform sampler2D composite; //everything from composite1
#ifdef TAA
const bool gaux4Clear = false;
uniform sampler2D gaux4; //composite, TAA mixed with everything
uniform sampler2D depthtex0;
/*
uniform sampler2D gcolor;
uniform sampler2D gnormal;
uniform float near;
uniform float far;
*/
uniform float viewWidth;
uniform float viewHeight;
vec2 texelSize = vec2(1.0/viewWidth,1.0/viewHeight);
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferPreviousProjection;
uniform mat4 gbufferPreviousModelView;
uniform vec3 cameraPosition;
uniform vec3 previousCameraPosition;
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
vec3 toClipSpace3Prev(vec3 viewSpacePosition) {
return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
}
vec3 toScreenSpace(vec3 p) {
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
vec3 p3 = p * 2.0 - 1.0;
vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
return fragposition.xyz / fragposition.w;
}
//approximation from SMAA presentation from siggraph 2016
vec3 FastCatmulRom(sampler2D colorTex, vec2 texcoord, vec4 rtMetrics, float sharpenAmount){
vec2 position = rtMetrics.zw * texcoord;
vec2 centerPosition = floor(position - 0.5) + 0.5;
vec2 f = position - centerPosition;
vec2 f2 = f * f;
vec2 f3 = f * f2;
float c = sharpenAmount;
vec2 w0 = -c * f3 + 2.0 * c * f2 - c * f;
vec2 w1 = (2.0 - c) * f3 - (3.0 - c) * f2 + 1.0;
vec2 w2 = -(2.0 - c) * f3 + (3.0 - 2.0 * c) * f2 + c * f;
vec2 w3 = c * f3 - c * f2;
vec2 w12 = w1 + w2;
vec2 tc12 = rtMetrics.xy * (centerPosition + w2 / w12);
vec3 centerColor = texture2D(colorTex, vec2(tc12.x, tc12.y)).rgb;
vec2 tc0 = rtMetrics.xy * (centerPosition - 1.0);
vec2 tc3 = rtMetrics.xy * (centerPosition + 2.0);
vec4 color = vec4(texture2D(colorTex, vec2(tc12.x, tc0.y )).rgb, 1.0) * (w12.x * w0.y ) +
vec4(texture2D(colorTex, vec2(tc0.x, tc12.y)).rgb, 1.0) * (w0.x * w12.y) +
vec4(centerColor, 1.0) * (w12.x * w12.y) +
vec4(texture2D(colorTex, vec2(tc3.x, tc12.y)).rgb, 1.0) * (w3.x * w12.y) +
vec4(texture2D(colorTex, vec2(tc12.x, tc3.y )).rgb, 1.0) * (w12.x * w3.y );
return color.rgb/color.a;
}
vec3 calcTAA(){
//reproject previous frame
float depth0 = texture2D(depthtex0,texcoord).x;
vec3 closestToCamera = vec3(texcoord,depth0);
vec3 fragposition = toScreenSpace(closestToCamera);
fragposition = mat3(gbufferModelViewInverse) * fragposition + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition);
vec3 previousPosition = mat3(gbufferPreviousModelView) * fragposition + gbufferPreviousModelView[3].xyz;
previousPosition = toClipSpace3Prev(previousPosition);
previousPosition.xy = texcoord + (previousPosition.xy - closestToCamera.xy);
//to reduce error propagation caused by interpolation during history resampling, we will introduce back some aliasing in motion
vec2 d = 0.5-abs(fract(previousPosition.xy*vec2(viewWidth,viewHeight)-texcoord*vec2(viewWidth,viewHeight))-0.5);
float rej = dot(d,d)*0.5;
//reject history if off-screen and early exit
if (previousPosition.x < 0.0 || previousPosition.y < 0.0 || previousPosition.x > 1.0 || previousPosition.y > 1.0) return texture2D(composite, texcoord).rgb;
//Samples current frame 3x3 neighboorhood
vec3 albedoCurrent0 = texture2D(composite, texcoord).rgb;
vec3 albedoCurrent1 = texture2D(composite, texcoord + vec2(texelSize.x,texelSize.y)).rgb;
vec3 albedoCurrent2 = texture2D(composite, texcoord + vec2(texelSize.x,-texelSize.y)).rgb;
vec3 albedoCurrent3 = texture2D(composite, texcoord + vec2(-texelSize.x,-texelSize.y)).rgb;
vec3 albedoCurrent4 = texture2D(composite, texcoord + vec2(-texelSize.x,texelSize.y)).rgb;
vec3 albedoCurrent5 = texture2D(composite, texcoord + vec2(0.0,texelSize.y)).rgb;
vec3 albedoCurrent6 = texture2D(composite, texcoord + vec2(0.0,-texelSize.y)).rgb;
vec3 albedoCurrent7 = texture2D(composite, texcoord + vec2(-texelSize.x,0.0)).rgb;
vec3 albedoCurrent8 = texture2D(composite, texcoord + vec2(texelSize.x,0.0)).rgb;
/*
float getmat = texture2D(gcolor,texcoord).b;
bool emissive = getmat > 0.59 && getmat < 0.61;
vec3 normal = texture2D(gnormal,texcoord).xyz;
bool iswater = normal.z < 0.2499 && dot(normal,normal) > 0.0;
if(!iswater && !emissive && depth0 < 1.0-near/far/far){ //don't sharpen emissive blocks, water and sky, clouds
vec3 m1 = (albedoCurrent0 + albedoCurrent1 + albedoCurrent2 + albedoCurrent3 + albedoCurrent4 + albedoCurrent5 + albedoCurrent6 + albedoCurrent7 + albedoCurrent8)/9.0;
vec3 std = abs(albedoCurrent0 - m1) + abs(albedoCurrent1 - m1) + abs(albedoCurrent2 - m1) + abs(albedoCurrent3 - m1) + abs(albedoCurrent3 - m1) +
abs(albedoCurrent4 - m1) + abs(albedoCurrent5 - m1) + abs(albedoCurrent6 - m1) + abs(albedoCurrent7 - m1) + abs(albedoCurrent8 - m1);
float contrast = 1.0 - dot(std,vec3(0.299, 0.587, 0.114))/9.0;
albedoCurrent0 = albedoCurrent0*(1.0+AS_sharpening*contrast)-(albedoCurrent5+albedoCurrent6+albedoCurrent7+albedoCurrent8+(albedoCurrent1 + albedoCurrent2 + albedoCurrent3 + albedoCurrent4)/2.0)/6.0*AS_sharpening*contrast;
}
*/
//Assuming the history color is a blend of the 3x3 neighborhood, we clamp the history to the min and max of each channel in the 3x3 neighborhood
vec3 cMax = max(max(max(albedoCurrent0,albedoCurrent1),albedoCurrent2),max(albedoCurrent3,max(albedoCurrent4,max(albedoCurrent5,max(albedoCurrent6,max(albedoCurrent7,albedoCurrent8))))));
vec3 cMin = min(min(min(albedoCurrent0,albedoCurrent1),albedoCurrent2),min(albedoCurrent3,min(albedoCurrent4,min(albedoCurrent5,min(albedoCurrent6,min(albedoCurrent7,albedoCurrent8))))));
vec3 albedoPrev = FastCatmulRom(gaux4, previousPosition.xy,vec4(texelSize, 1.0/texelSize), 0.82).xyz;
vec3 finalcAcc = clamp(albedoPrev,cMin,cMax);
//increases blending factor if history is far away from aabb, reduces ghosting at the cost of some flickering
float luma = dot(albedoPrev,vec3(0.21, 0.72, 0.07));
float isclamped = distance(albedoPrev,finalcAcc)/luma;
//reduces blending factor if current texel is far from history, reduces flickering
float lumDiff2 = distance(albedoPrev,albedoCurrent0)/luma;
lumDiff2 = 1.0-clamp(lumDiff2*lumDiff2,0.0,1.0)*0.75;
//Blend current pixel with clamped history
return mix(finalcAcc,albedoCurrent0,clamp(0.1*lumDiff2+rej+isclamped+0.01,0.0,1.0));
}
#endif
void main() {
#ifdef TAA
gl_FragData[0] = vec4(calcTAA(), 1.0);
#else
gl_FragData[0] = texture2D(composite, texcoord); //if TAA is disabled just passthrough data from composite0, previous buffer.
#endif
}

View File

@@ -0,0 +1,8 @@
#version 120
varying vec2 texcoord;
void main() {
gl_Position = ftransform();
texcoord = gl_MultiTexCoord0.xy;
}

View File

@@ -0,0 +1,42 @@
#version 120
/* DRAWBUFFERS:6 */
//overwrite buffer 6, final image is buffer 7
//This buffer is scaled down, defined in shaders.properties, it's faster than texcoord scaling
#define Bloom
#define composite3
#include "/shaders.settings"
#ifdef Bloom
varying vec2 texcoord;
uniform sampler2D colortex7; //read buffer 7, TAA+everything
uniform float viewWidth;
uniform float viewHeight;
const bool colortex7MipmapEnabled = true;
#endif
void main() {
#ifdef Bloom
const int nSteps = 25;
const int center = 12; //=nSteps-1 / 2
vec3 blur = vec3(0.0);
float tw = 0.0;
for (int i = 0; i < nSteps; i++) {
float dist = abs(i-float(center))/center;
float weight = (exp(-(dist*dist)/ 0.28));
vec3 bsample = texture2D(colortex7,(texcoord*4.0 + 2.0*vec2(1.0/viewWidth,1.0/viewHeight)*vec2(i-center,0.0))).rgb;
blur += bsample*weight;
tw += weight;
}
blur /= tw;
blur = clamp(blur,0.0,1.0); //fix flashing black square
gl_FragData[0] = vec4(blur, 1.0);
#else
gl_FragData[0] = vec4(0.0);
#endif
}

View File

@@ -0,0 +1,8 @@
#version 120
varying vec2 texcoord;
void main() {
gl_Position = ftransform();
texcoord = gl_MultiTexCoord0.xy;
}

View File

@@ -0,0 +1,50 @@
#version 120
/* DRAWBUFFERS:6 */
//overwrite buffer 6, final image is buffer 7
#define Bloom
#define bloom_strength 0.75
#define composite4
#include "/shaders.settings"
#ifdef Bloom
varying vec2 texcoord;
varying float eyeAdapt;
uniform sampler2D colortex6;
uniform int isEyeInWater;
uniform float rainStrength;
uniform float viewWidth;
uniform float viewHeight;
#endif
void main() {
#ifdef Bloom
const int nSteps = 17;
const int center = 8; //=nSteps-1 / 2
//huge gaussian blur for glare
vec3 blur = vec3(0.0);
float tw = 0.0;
for (int i = 0; i < nSteps; i++) {
float dist = abs(i-float(center))/center;
float weight = (exp(-(dist*dist)/ 0.28));
vec3 bsample = texture2D(colortex6,(texcoord.xy + vec2(1.0/viewWidth,1.0/viewHeight)*vec2(0.0,i-center))).rgb*3.0;
blur += bsample*weight;
tw += weight;
}
blur /= tw;
vec3 glow = blur * bloom_strength;
vec3 overglow = glow*pow(length(glow)*2.0,2.8)*2.0;
vec3 finalColor = (overglow+glow*1.15)*(1+isEyeInWater*10.0+(pow(rainStrength,3.0)*7.0/pow(eyeAdapt,1.0)))*1.2;
gl_FragData[0] = vec4(finalColor, 1.0);
#else
gl_FragData[0] = vec4(0.0);
#endif
}

View File

@@ -0,0 +1,77 @@
#version 120
#define Bloom
#define composite3 //it's composite4 but we don't need the extra define so use 3 instead
#include "/shaders.settings"
#ifdef Bloom
varying vec2 texcoord;
varying float eyeAdapt;
uniform vec3 sunPosition;
uniform vec3 upPosition;
uniform ivec2 eyeBrightnessSmooth;
uniform int worldTime;
uniform float rainStrength;
uniform float frameTimeCounter;
const vec3 ToD[7] = vec3[7]( vec3(0.58597,0.16,0.025),
vec3(0.58597,0.4,0.2),
vec3(0.58597,0.52344,0.24680),
vec3(0.58597,0.55422,0.34),
vec3(0.58597,0.57954,0.38),
vec3(0.58597,0.58,0.40),
vec3(0.58597,0.58,0.40));
float luma(vec3 color) {
return dot(color,vec3(0.299, 0.587, 0.114));
}
#endif
void main() {
gl_Position = ftransform();
#ifdef Bloom
texcoord = (gl_MultiTexCoord0).xy;
//Sun/Moon position
vec3 sunVec = normalize(sunPosition);
vec3 upVec = vec3(0.0, 1.0, 0.0); //fix for loading shaderpacks in nether and end, optifine bug.
float SdotU = dot(sunVec,upVec);
float sunVisibility = pow(clamp(SdotU+0.15,0.0,0.15)/0.15,4.0);
float moonVisibility = pow(clamp(-SdotU+0.15,0.0,0.15)/0.15,4.0);
/*--------------------------------*/
//reduced the sun color to a 7 array
float hour = max(mod(worldTime/1000.0+2.0,24.0)-2.0,0.0); //-0.1
float cmpH = max(-abs(floor(hour)-6.0)+6.0,0.0); //12
float cmpH1 = max(-abs(floor(hour)-5.0)+6.0,0.0); //1
vec3 temp = ToD[int(cmpH)];
vec3 temp2 = ToD[int(cmpH1)];
vec3 sunlight = mix(temp,temp2,fract(hour));
/*--------------------------------*/
//Lighting
float eyebright = max(eyeBrightnessSmooth.y/255.0-0.5/16.0,0.0)*1.03225806452;
float SkyL2 = mix(1.0,eyebright*eyebright,eyebright);
vec2 trCalc = min(abs(worldTime-vec2(23250.0,12700.0)),750.0);
float tr = max(min(trCalc.x,trCalc.y)/375.0-1.0,0.0);
vec4 bounced = vec4(0.5*SkyL2,0.66*SkyL2,0.7,0.3);
vec3 sun_ambient = bounced.w * (vec3(0.25,0.62,1.32)-rainStrength*vec3(0.11,0.32,1.07)) + sunlight*(bounced.x + bounced.z);
const vec3 moonlight = vec3(0.0035, 0.0063, 0.0098);
vec3 avgAmbient =(sun_ambient*sunVisibility + moonlight*moonVisibility)*eyebright*eyebright*(0.05+tr*0.15)*4.7+0.0006;
eyeAdapt = log(clamp(luma(avgAmbient),0.007,80.0))/log(2.6)*0.35;
eyeAdapt = 1.0/pow(2.6,eyeAdapt)*1.75;
#endif
}

278
shaders/world1/final.fsh Normal file
View File

@@ -0,0 +1,278 @@
#version 120
#define final
#include "/shaders.settings"
varying vec2 texcoord;
uniform sampler2D gaux4; //final image
#ifdef Bloom
uniform sampler2D colortex6; //overwritten by bloom
#endif
#if Showbuffer > 0
uniform sampler2D colortex0;
uniform sampler2D colortex1;
uniform sampler2D colortex2;
uniform sampler2D colortex3;
uniform sampler2D gaux1;
uniform sampler2D gaux2;
uniform sampler2D gaux3;
#endif
uniform int isEyeInWater;
uniform float aspectRatio;
uniform float viewWidth;
uniform float viewHeight;
uniform float rainStrength;
uniform float frameTimeCounter;
#if defined Depth_of_Field || defined Motionblur
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
uniform sampler2D depthtex2;
#endif
#ifdef Motionblur
uniform vec3 cameraPosition;
uniform vec3 previousCameraPosition;
uniform mat4 gbufferProjection;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferPreviousProjection;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferPreviousModelView;
#endif
#if defined Depth_of_Field
uniform float near;
uniform float far;
float ld(float depth) {
return (2.0 * near) / (far + near - depth * (far - near));
}
#endif
#ifdef Depth_of_Field
//Dof constant values
const float focal = 0.024;
float aperture = 0.008;
const float sizemult = DoF_Strength;
uniform float centerDepthSmooth;
const float centerDepthHalflife = 2.0f;
//hexagon pattern
const vec2 hex_offsets[60] = vec2[60] ( vec2( 0.2165, 0.1250 ),
vec2( 0.0000, 0.2500 ),
vec2( -0.2165, 0.1250 ),
vec2( -0.2165, -0.1250 ),
vec2( -0.0000, -0.2500 ),
vec2( 0.2165, -0.1250 ),
vec2( 0.4330, 0.2500 ),
vec2( 0.0000, 0.5000 ),
vec2( -0.4330, 0.2500 ),
vec2( -0.4330, -0.2500 ),
vec2( -0.0000, -0.5000 ),
vec2( 0.4330, -0.2500 ),
vec2( 0.6495, 0.3750 ),
vec2( 0.0000, 0.7500 ),
vec2( -0.6495, 0.3750 ),
vec2( -0.6495, -0.3750 ),
vec2( -0.0000, -0.7500 ),
vec2( 0.6495, -0.3750 ),
vec2( 0.8660, 0.5000 ),
vec2( 0.0000, 1.0000 ),
vec2( -0.8660, 0.5000 ),
vec2( -0.8660, -0.5000 ),
vec2( -0.0000, -1.0000 ),
vec2( 0.8660, -0.5000 ),
vec2( 0.2163, 0.3754 ),
vec2( -0.2170, 0.3750 ),
vec2( -0.4333, -0.0004 ),
vec2( -0.2163, -0.3754 ),
vec2( 0.2170, -0.3750 ),
vec2( 0.4333, 0.0004 ),
vec2( 0.4328, 0.5004 ),
vec2( -0.2170, 0.6250 ),
vec2( -0.6498, 0.1246 ),
vec2( -0.4328, -0.5004 ),
vec2( 0.2170, -0.6250 ),
vec2( 0.6498, -0.1246 ),
vec2( 0.6493, 0.6254 ),
vec2( -0.2170, 0.8750 ),
vec2( -0.8663, 0.2496 ),
vec2( -0.6493, -0.6254 ),
vec2( 0.2170, -0.8750 ),
vec2( 0.8663, -0.2496 ),
vec2( 0.2160, 0.6259 ),
vec2( -0.4340, 0.5000 ),
vec2( -0.6500, -0.1259 ),
vec2( -0.2160, -0.6259 ),
vec2( 0.4340, -0.5000 ),
vec2( 0.6500, 0.1259 ),
vec2( 0.4325, 0.7509 ),
vec2( -0.4340, 0.7500 ),
vec2( -0.8665, -0.0009 ),
vec2( -0.4325, -0.7509 ),
vec2( 0.4340, -0.7500 ),
vec2( 0.8665, 0.0009 ),
vec2( 0.2158, 0.8763 ),
vec2( -0.6510, 0.6250 ),
vec2( -0.8668, -0.2513 ),
vec2( -0.2158, -0.8763 ),
vec2( 0.6510, -0.6250 ),
vec2( 0.8668, 0.2513 ));
#endif
vec3 Uncharted2Tonemap(vec3 x) {
x*= Brightness;
float A = 0.28;
float B = 0.29;
float C = 0.10;
float D = 0.2;
float E = 0.025;
float F = 0.35;
return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;
}
#if Showbuffer == 1 || Showbuffer == 2 || Showbuffer == 3
vec3 decode (vec2 enc){
vec2 fenc = enc*4-2;
float f = dot(fenc,fenc);
float g = sqrt(1-f/4.0);
vec3 n;
n.xy = fenc*g;
n.z = 1-f/2;
return n;
}
vec3 YCoCg2RGB(vec3 c){
c.y-=0.5;
c.z-=0.5;
return vec3(c.r+c.g-c.b, c.r + c.b, c.r - c.g - c.b);
}
#endif
void main() {
#if defined Depth_of_Field || defined Motionblur
//Setup depths, do it here because amd drivers suck and texture reads outside of void main or functions are broken, thanks amd
float depth0 = texture2D(depthtex0, texcoord).x;
float depth1 = texture2D(depthtex1, texcoord).x;
float depth2 = texture2D(depthtex2, texcoord).x;
bool hand = (depth0 < depth1) || !(depth0 < depth2);
#endif
float rainlens = 0.0;
vec2 fake_refract = vec2(0.0);
#ifdef Refraction
fake_refract = vec2(sin(frameTimeCounter + texcoord.x*100.0 + texcoord.y*50.0),cos(frameTimeCounter + texcoord.y*100.0 + texcoord.x*50.0));
#endif
vec2 newTC = clamp(texcoord + fake_refract * 0.01 * (rainlens+isEyeInWater*0.2),1.0/vec2(viewWidth,viewHeight),1.0-1.0/vec2(viewWidth,viewHeight));
vec3 color = texture2D(gaux4, newTC.xy).rgb*50.0;
#ifdef Depth_of_Field
if(hand){
float pw = 1.0/ viewWidth;
float z = ld(texture2D(depthtex0, newTC.st).r)*far;
#ifdef smoothDof
float focus = ld(centerDepthSmooth)*far;
#else
float focus = ld(texture2D(depthtex0, vec2(0.5)).r)*far;
#endif
float pcoc = min(abs(aperture * (focal * (z - focus)) / (z * (focus - focal)))*sizemult,pw*15.0);
#ifdef Distance_Blur
float getdist = 1-(exp(-pow(ld(texture2D(depthtex1, newTC.st).r)/Dof_Distance_View*far,4.0-(2.7*rainStrength))*4.0));
pcoc = min(getdist*pw*20.0,pw*20.0);
#endif
vec3 bcolor = vec3(0.0);
for ( int i = 0; i < 60; i++) {
bcolor += texture2D(gaux4, newTC.xy + hex_offsets[i]*pcoc*vec2(1.0,aspectRatio)).rgb;
}
color.rgb = bcolor/61.0*50.0;
}
#endif
#ifdef Motionblur
if(hand){
vec4 currentPosition = vec4(texcoord, depth1, 1.0)*2.0-1.0;
vec4 fragposition = gbufferProjectionInverse * currentPosition;
fragposition = gbufferModelViewInverse * fragposition;
fragposition /= fragposition.w;
fragposition.xyz += cameraPosition;
vec4 previousPosition = fragposition;
previousPosition.xyz -= previousCameraPosition;
previousPosition = gbufferPreviousModelView * previousPosition;
previousPosition = gbufferPreviousProjection * previousPosition;
previousPosition /= previousPosition.w;
vec2 velocity = (currentPosition - previousPosition).st * MB_strength;
vec2 coord = texcoord.st + velocity;
int mb = 1;
for (int i = 0; i < 15; ++i, coord += velocity) {
if (coord.s > 1.0 || coord.t > 1.0 || coord.s < 0.0 || coord.t < 0.0) break;
color += texture2D(gaux4, coord).xyz*50.0;
++mb;
}
color /= mb;
}
#endif
#ifdef Bloom
color.rgb += texture2D(colortex6, texcoord.xy*0.25).rgb; //upscale bloom buffer.
#endif
color.rgb += rainlens*0.01; //draw rainlens
vec3 curr = Uncharted2Tonemap(color*4.7);
color = pow(curr/Uncharted2Tonemap(vec3(15.2)),vec3(1.0/Contrast));
#if Showbuffer == 1
color = vec3(texture2D(colortex0,texcoord).rg,0.0);
vec2 a0 = texture2D(colortex0,texcoord + vec2(1.0/viewWidth,0.0)).rg;
vec2 a1 = texture2D(colortex0,texcoord - vec2(1.0/viewWidth,0.0)).rg;
vec2 a2 = texture2D(colortex0,texcoord + vec2(0.0,1.0/viewHeight)).rg;
vec2 a3 = texture2D(colortex0,texcoord - vec2(0.0,1.0/viewHeight)).rg;
vec4 lumas = vec4(a0.x,a1.x,a2.x,a3.x);
vec4 chromas = vec4(a0.y,a1.y,a2.y,a3.y);
vec4 w = 1.0-step(0.1176, abs(lumas - color.x));
float W = dot(w,vec4(1.0));
w.x = (W==0.0)? 1.0:w.x; W = (W==0.0)? 1.0:W;
bool pattern = (mod(gl_FragCoord.x,2.0)==mod(gl_FragCoord.y,2.0));
color.b= dot(w,chromas)/W;
color.rgb = (pattern)?color.rbg:color.rgb;
color.rgb = YCoCg2RGB(color.rgb);
color = pow(color,vec3(2.2));
#endif
#if Showbuffer == 2
color = decode(texture2D(colortex1, texcoord).xy);
#endif
#if Showbuffer == 25
color = vec3(0.0, texture2D(colortex1, texcoord.xy).zw); //lightmap
#endif
#if Showbuffer == 3
color = decode(texture2D(colortex2, texcoord).xy);
#endif
#if Showbuffer == 35
color = vec3(0.0, texture2D(colortex2, texcoord.xy).zw); //lightmap
#endif
#if Showbuffer == 4
color = texture2D(colortex3, texcoord.xy).rgb * 200.0;
#endif
#if Showbuffer == 5
color = texture2D(gaux1, texcoord.xy).rgb * 25.0;
#endif
#if Showbuffer == 6
color = texture2D(gaux2, texcoord.xy).rgb * 25.0;
#endif
#if Showbuffer == 7
color = texture2D(gaux3, texcoord.xy*0.25).rgb * 25.0;
#endif
#if Showbuffer == 8
color = texture2D(gaux4, texcoord.xy).rgb * 50.0;
#endif
gl_FragColor = vec4(color,1.0);
}

8
shaders/world1/final.vsh Normal file
View File

@@ -0,0 +1,8 @@
#version 120
varying vec2 texcoord;
void main() {
gl_Position = ftransform();
texcoord = (gl_MultiTexCoord0).xy;
}

View File

@@ -0,0 +1,28 @@
#version 120
/* DRAWBUFFERS:5 */
uniform sampler2D texture;
varying vec4 color;
varying vec2 texcoord;
uniform int worldTime;
uniform ivec2 eyeBrightnessSmooth;
uniform float rainStrength;
float night = clamp((worldTime-13000.0)/300.0,0.0,1.0)-clamp((worldTime-22800.0)/200.0,0.0,1.0);
float cavelight = pow(eyeBrightnessSmooth.y / 255.0, 6.0f) * 1.0 + (0.7 + 0.5*night);
void main() {
vec4 albedo = texture2D(texture, texcoord.st)*color;
//Fix minecrafts way of handling enchanted effects and turn it into a somewhat consistent effect across day/night/cave/raining
vec3 lighting = vec3(1.0+ (0.4*rainStrength - 0.4*rainStrength*night));
lighting /= 0.8 - 0.5*night;
lighting /= cavelight;
albedo.rgb = pow(albedo.rgb*0.33, lighting);
gl_FragData[0] = albedo;
}

View File

@@ -0,0 +1,37 @@
#version 120
varying vec4 color;
varying vec2 texcoord;
uniform mat4 gbufferModelView;
uniform mat4 gbufferModelViewInverse;
#define composite2
#include "/shaders.settings"
#ifdef TAA
uniform float viewWidth;
uniform float viewHeight;
vec2 texelSize = vec2(1.0/viewWidth,1.0/viewHeight);
uniform int framemod8;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
vec2(-3,-5.)/8.,
vec2(-5.,5.)/8.,
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
#endif
void main() {
vec4 position = gbufferModelViewInverse * gl_ModelViewMatrix * gl_Vertex;
gl_Position = gl_ProjectionMatrix * gbufferModelView * position;
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
color = gl_Color;
texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).st;
}

View File

@@ -0,0 +1,30 @@
#version 120
/* DRAWBUFFERS:0 */ //01 breaks selection box color but fixes leads
varying vec4 color;
varying vec4 texcoord;
varying vec3 normal;
uniform sampler2D texture;
//encode normal in two channel (xy),torch and material(z) and sky lightmap (w)
vec4 encode (vec3 n){
float p = sqrt(n.z*8+8);
return vec4(n.xy/p + 0.5,texcoord.z,texcoord.w);
}
vec3 RGB2YCoCg(vec3 c){
return vec3( 0.25*c.r+0.5*c.g+0.25*c.b, 0.5*c.r-0.5*c.b +0.5, -0.25*c.r+0.5*c.g-0.25*c.b +0.5);
}
void main() {
vec4 cAlbedo = vec4(RGB2YCoCg(color.rgb),color.a);
bool pattern = (mod(gl_FragCoord.x,2.0)==mod(gl_FragCoord.y,2.0));
cAlbedo.g = (pattern)?cAlbedo.b: cAlbedo.g;
cAlbedo.b = 1.0;
gl_FragData[0] = cAlbedo;
gl_FragData[1] = encode(normal.xyz);
}

View File

@@ -0,0 +1,17 @@
#version 120
varying vec4 color;
varying vec4 texcoord;
varying vec3 normal;
void main() {
gl_Position = ftransform();
color = gl_Color;
texcoord = vec4((gl_MultiTexCoord0).xy,(gl_TextureMatrix[1] * gl_MultiTexCoord1).xy);
normal = normalize(gl_NormalMatrix * gl_Normal);
gl_FogFragCoord = gl_Position.z;
}

View File

@@ -0,0 +1,26 @@
#version 120
/* DRAWBUFFERS:56 */
//Render hand, entities and particles in here, boost and fix enchanted armor effect in gbuffers_armor_glint
#define gbuffers_texturedblock
#include "/shaders.settings"
varying vec4 color;
varying vec2 texcoord;
varying vec3 ambientNdotL;
uniform sampler2D texture;
uniform vec4 entityColor;
void main() {
vec4 albedo = texture2D(texture, texcoord.xy)*color;
#ifdef MobsFlashRed
albedo.rgb = mix(albedo.rgb,entityColor.rgb,entityColor.a);
#endif
vec3 finalColor = pow(albedo.rgb,vec3(2.2)) * ambientNdotL.rgb;
gl_FragData[0] = vec4(finalColor, albedo.a);
gl_FragData[1] = vec4(normalize(albedo.rgb+0.00001), albedo.a);
}

View File

@@ -0,0 +1,105 @@
#version 120
#define composite2
#define gbuffers_texturedblock
#define lightingColors
#include "/shaders.settings"
varying vec4 color;
varying vec2 texcoord;
varying vec3 ambientNdotL;
uniform vec3 sunPosition;
uniform vec3 upPosition;
uniform int worldTime;
uniform float rainStrength;
uniform float nightVision;
uniform float screenBrightness;
const vec3 ToD[7] = vec3[7]( vec3(0.58597,0.15,0.02),
vec3(0.58597,0.35,0.09),
vec3(0.58597,0.5,0.26),
vec3(0.58597,0.5,0.35),
vec3(0.58597,0.5,0.36),
vec3(0.58597,0.5,0.37),
vec3(0.58597,0.5,0.38));
#ifdef TAA
uniform float viewWidth;
uniform float viewHeight;
vec2 texelSize = vec2(1.0/viewWidth,1.0/viewHeight);
uniform int framemod8;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
vec2(-3,-5.)/8.,
vec2(-5.,5.)/8.,
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
#endif
void main() {
//setup basics
color = gl_Color;
gl_Position = ftransform();
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
vec2 lmcoord = (gl_TextureMatrix[1] * gl_MultiTexCoord1).xy;
/*--------------------------------*/
//Emissive blocks lighting in order to fix lighting on particles
float torch_lightmap = 16.0-min(15.,(lmcoord.s-0.5/16.)*16.*16./15);
float fallof1 = clamp(1.0 - pow(torch_lightmap/16.0,4.0),0.0,1.0);
torch_lightmap = fallof1*fallof1/(torch_lightmap*torch_lightmap+1.0);
vec3 emissiveLightC = vec3(emissive_R,emissive_G,emissive_B)*torch_lightmap;
float finalminlight = (nightVision > 0.01)? 0.025 : ((minlight+0.006)+(screenBrightness*0.0125))*0.5;
/*---------------------------------------------------------------------*/
//reduced the sun color to a 7 array
float hour = max(mod(worldTime/1000.0+2.0,24.0)-2.0,0.0); //-0.1
float cmpH = max(-abs(floor(hour)-6.0)+6.0,0.0); //12
float cmpH1 = max(-abs(floor(hour)-5.0)+6.0,0.0); //1
vec3 temp = ToD[int(cmpH)];
vec3 temp2 = ToD[int(cmpH1)];
vec3 sunlight = mix(temp,temp2,fract(hour));
const vec3 rainC = vec3(0.01,0.01,0.01);
sunlight = mix(sunlight,rainC*sunlight,rainStrength);
/*-------------------------------------------------------------------*/
const vec3 moonlight = vec3(0.0024, 0.00432, 0.0078);
vec3 sunVec = normalize(sunPosition);
vec3 upVec = vec3(0.0, 1.0, 0.0); //fix for loading shaderpacks in nether and end, optifine bug.
vec2 visibility = vec2(dot(sunVec,upVec),dot(-sunVec,upVec));
float NdotL = dot(normal,sunVec);
float NdotU = dot(normal,upVec);
vec2 trCalc = min(abs(worldTime-vec2(23250.0,12700.0)),750.0);
float tr = max(min(trCalc.x,trCalc.y)/375.0-1.0,0.0);
visibility = pow(clamp(visibility+0.15,0.0,0.15)/0.15,vec2(4.0));
float skyL = max(lmcoord.t-2./16.0,0.0)*1.14285714286;
float SkyL2 = skyL*skyL;
float skyc2 = mix(1.0,SkyL2,skyL);
vec4 bounced = vec4(NdotL,NdotL,NdotL,NdotU) * vec4(-0.14*skyL*skyL,0.34,0.7,0.1) + vec4(0.6,0.66,0.7,0.25);
bounced *= vec4(skyc2,skyc2,visibility.x-tr*visibility.x,0.8);
vec3 sun_ambient = bounced.w * (vec3(0.1, 0.5, 1.1)+rainStrength*vec3(0.05,-0.27,-0.8))*2.3+ 1.7*sunlight*(sqrt(bounced.w)*bounced.x*2.4 + bounced.z)*(1.0-rainStrength*0.98);
vec3 moon_ambient = (moonlight*0.7 + moonlight*bounced.y)*(1.0-rainStrength*0.95)*2.0;
vec3 amb1 = (sun_ambient*visibility.x + moon_ambient*visibility.y)*SkyL2*(0.03+tr*0.17)*0.65;
ambientNdotL.rgb = amb1 + emissiveLightC + finalminlight;
sunlight = mix(sunlight,moonlight*(1.0-rainStrength*0.9),visibility.y)*tr;
}

View File

@@ -0,0 +1,5 @@
#version 120
void main() {
discard;
}

View File

@@ -0,0 +1,5 @@
#version 120
void main() {
gl_Position = ftransform();
}

View File

@@ -0,0 +1,5 @@
#version 120
void main() {
gl_FragData[0] = vec4(0.0, 0.0, 0.0, 1.0); //fill with zeros to avoid issues, alpha has to be set to 1.0 to fix an optifine issue in 1.17+ causing the sky to be black at certain angles.
}

View File

@@ -0,0 +1,5 @@
#version 120
void main() {
gl_Position = ftransform();
}

View File

@@ -0,0 +1,10 @@
#version 120
/* DRAWBUFFERS:3 */
varying vec4 color;
varying vec2 texcoord;
uniform sampler2D texture;
void main() {
gl_FragData[0] = texture2D(texture,texcoord.xy)*color*0.85;
}

View File

@@ -0,0 +1,14 @@
#version 120
varying vec4 color;
varying vec2 texcoord;
void main() {
texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
color = gl_Color;
gl_Position = ftransform();
}

View File

@@ -0,0 +1,20 @@
#version 120
/* DRAWBUFFERS:56 */
#define gbuffers_texturedblock
#include "/shaders.settings"
varying vec4 color;
varying vec2 texcoord;
varying vec3 ambientNdotL;
uniform sampler2D texture;
void main() {
vec4 albedo = texture2D(texture, texcoord.xy)*color;
vec3 finalColor = pow(albedo.rgb,vec3(2.2)) * ambientNdotL.rgb;
gl_FragData[0] = vec4(finalColor, albedo.a);
gl_FragData[1] = vec4(normalize(albedo.rgb+0.00001), albedo.a);
}

View File

@@ -0,0 +1,64 @@
#version 120
#define composite2
#define gbuffers_texturedblock
#define lightingColors
#include "/shaders.settings"
varying vec4 color;
varying vec2 texcoord;
varying vec3 ambientNdotL;
uniform vec3 sunPosition;
uniform vec3 upPosition;
uniform int worldTime;
uniform float rainStrength;
uniform float nightVision;
const vec3 ToD[7] = vec3[7]( vec3(0.58597,0.15,0.02),
vec3(0.58597,0.35,0.09),
vec3(0.58597,0.5,0.26),
vec3(0.58597,0.5,0.35),
vec3(0.58597,0.5,0.36),
vec3(0.58597,0.5,0.37),
vec3(0.58597,0.5,0.38));
#ifdef TAA
uniform float viewWidth;
uniform float viewHeight;
vec2 texelSize = vec2(1.0/viewWidth,1.0/viewHeight);
uniform int framemod8;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
vec2(-3,-5.)/8.,
vec2(-5.,5.)/8.,
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
#endif
void main() {
//setup basics
color = gl_Color;
gl_Position = ftransform();
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
vec2 lmcoord = (gl_TextureMatrix[1] * gl_MultiTexCoord1).xy;
/*--------------------------------*/
//Emissive blocks lighting
float torch_lightmap = 16.0-min(15.,(lmcoord.s-0.5/16.)*16.*16./15);
float fallof1 = clamp(1.0 - pow(torch_lightmap/16.0,4.0),0.0,1.0);
torch_lightmap = fallof1*fallof1/(torch_lightmap*torch_lightmap+1.0);
//vec3 emissiveLightC = vec3(emissive_R,emissive_G,emissive_B)*torch_lightmap;
vec3 emissiveLightC = vec3(0.5, 0.0, 1.0); //purple eyes
float finalminlight = (nightVision > 0.01)? 0.025 : (minlight+0.006)*10.0; //multiply by 10 to improve eye rendering
ambientNdotL.rgb = emissiveLightC + finalminlight;
}

View File

@@ -0,0 +1,135 @@
#version 120
#extension GL_ARB_shader_texture_lod : enable //This extension must always be enabled to prevent issues with amd linux drivers
/* DRAWBUFFERS:01 */
#define gbuffers_terrain
#include "/shaders.settings"
/* Don't remove me
const int colortex0Format = RGBA16;
const int colortex1Format = RGBA16;
const int colortex2Format = RGBA16; //Entities etc
const int colortex3Format = R11F_G11F_B10F;
const int gaux1Format = RGBA16;
const int gaux2Format = R11F_G11F_B10F;
const int gaux3Format = R11F_G11F_B10F;
const int gaux4Format = R11F_G11F_B10F;
-----------------------------------------*/
varying vec4 color;
varying vec4 texcoord;
varying vec4 normal;
varying vec3 worldpos;
varying vec3 viewVector;
varying mat3 tbnMatrix;
uniform sampler2D texture;
uniform sampler2D noisetex;
//encode normal in two channel (xy),torch and material(z) and sky lightmap (w)
vec4 encode (vec3 n){
return vec4(n.xy*inversesqrt(n.z*8.0+8.0) + 0.5, texcoord.zw);
}
vec3 RGB2YCoCg(vec3 c){
return vec3( 0.25*c.r+0.5*c.g+0.25*c.b, 0.5*c.r-0.5*c.b +0.5, -0.25*c.r+0.5*c.g-0.25*c.b +0.5);
}
vec3 newnormal = normal.xyz;
#if nMap >= 1
varying float block;
bool isblock = block > 0.0 || block < 0.0; //workaround for 1.16 bugs on block entities
uniform sampler2D normals;
varying float dist;
varying vec4 vtexcoordam; // .st for add, .pq for mul
varying vec2 vtexcoord;
mat2 mipmap = mat2(dFdx(vtexcoord.xy*vtexcoordam.pq), dFdy(vtexcoord.xy*vtexcoordam.pq));
vec4 readNormal(in vec2 coord){
return texture2DGradARB(normals,fract(coord)*vtexcoordam.pq+vtexcoordam.st,mipmap[0],mipmap[1]);
}
vec4 calcPOM(vec4 albedo){
vec2 newCoord = vtexcoord.xy*vtexcoordam.pq+vtexcoordam.st;
#if nMap == 2
if (dist < POM_DIST && viewVector.z < 0.0 && readNormal(vtexcoord.xy).a < 1.0){
const float res_stepths = 0.33 * POM_RES;
vec2 pstepth = viewVector.xy * POM_DEPTH / (-viewVector.z * POM_RES);
vec2 coord = vtexcoord.xy;
for (int i= 0; i < res_stepths && (readNormal(coord.xy).a < 1.0-float(i)/POM_RES); ++i) coord += pstepth;
newCoord = fract(coord.xy)*vtexcoordam.pq+vtexcoordam.st;
}
#endif
//vec4 specularity = texture2DGradARB(specular, newCoord, dcdx, dcdy);
vec3 bumpMapping = texture2DGradARB(normals, newCoord, mipmap[0],mipmap[1]).rgb*2.0-1.0;
newnormal = normalize(bumpMapping * tbnMatrix);
return albedo = texture2DGradARB(texture, newCoord, mipmap[0],mipmap[1])*color;
}
#endif
#if defined metallicRefl || defined polishedRefl
float calcNoise(vec2 coord){
return sqrt(texture2D(noisetex, vec2(coord.x*1.25, coord.y*1.95)).x) * 0.45;
}
vec3 calcBump(vec2 coord){
const vec2 deltaPos = vec2(0.25, 0.0);
float h0 = calcNoise(coord);
float h1 = calcNoise(coord + deltaPos.xy);
float h2 = calcNoise(coord - deltaPos.xy);
float h3 = calcNoise(coord + deltaPos.yx);
float h4 = calcNoise(coord - deltaPos.yx);
float xDelta = ((h1-h0)+(h0-h2));
float yDelta = ((h3-h0)+(h0-h4));
return vec3(vec2(xDelta,yDelta)*0.2, 0.8); //z = 1.0-0.5
}
vec3 calcParallax(vec3 pos){
float getnoise = calcNoise(pos.xz);
float height = 1.0;
pos.xz += (getnoise * viewVector.xy) * height;
return pos;
}
#endif
void main() {
vec4 albedo = texture2D(texture, texcoord.xy)*color;
#if nMap >= 1
if(isblock)albedo = calcPOM(albedo);
#endif
#if defined metallicRefl || defined polishedRefl
bool isMetallic = normal.a > 0.39 && normal.a < 0.41;
bool isPolished = normal.a > 0.49 && normal.a < 0.51;
#ifndef polishedRefl
isPolished = false;
#endif
#ifndef metallicRefl
isMetallic = false;
#endif
if(isMetallic || isPolished){
vec3 bumpPos = worldpos;
bumpPos = calcParallax(bumpPos);
vec3 bump = calcBump(bumpPos.xy);
newnormal = normalize(bump * tbnMatrix);
}
#endif
vec4 cAlbedo = vec4(RGB2YCoCg(albedo.rgb),albedo.a);
bool pattern = (mod(gl_FragCoord.x,2.0)==mod(gl_FragCoord.y,2.0));
cAlbedo.g = (pattern)?cAlbedo.b: cAlbedo.g;
cAlbedo.b = normal.a;
gl_FragData[0] = cAlbedo;
gl_FragData[1] = encode(newnormal.xyz);
}

View File

@@ -0,0 +1,280 @@
#version 120
#define composite2
#define gbuffers_terrain
#include "/shaders.settings"
//Moving entities IDs
//See block.properties for mapped ids
#define ENTITY_SMALLGRASS 10031.0
#define ENTITY_LOWERGRASS 10175.0 //lower half only in 1.13+
#define ENTITY_UPPERGRASS 10176.0 //upper half only used in 1.13+
#define ENTITY_SMALLENTS 10059.0
#define ENTITY_LEAVES 10018.0
#define ENTITY_VINES 10106.0
#define ENTITY_LILYPAD 10111.0
#define ENTITY_FIRE 10051.0
#define ENTITY_LAVA 10010.0
#define ENTITY_EMISSIVE 10089.0 //emissive blocks defined in block.properties
#define ENITIY_SOULFIRE 10091.0
#define METALLIC_BLOCK 10080.0 //defined in block.properties
#define POLISHED_BLOCK 10081.0
#define ENTITY_INVERTED_LOWER 10177.0 //hanging_roots
varying vec4 color;
varying vec4 texcoord;
varying vec4 normal;
varying vec3 worldpos;
attribute vec4 mc_Entity;
attribute vec4 mc_midTexCoord;
uniform vec3 cameraPosition;
uniform mat4 gbufferModelView;
uniform mat4 gbufferModelViewInverse;
uniform float frameTimeCounter;
const float PI = 3.1415927;
const float PI48 = 150.796447372;
float pi2wt = (PI48*frameTimeCounter) * animationSpeed;
#if nMap >= 1 || defined metallicRefl || defined polishedRefl
attribute vec4 at_tangent; //xyz = tangent vector, w = handedness, added in 1.7.10
varying float block;
varying float dist;
varying vec3 viewVector;
varying mat3 tbnMatrix;
varying vec4 vtexcoordam; // .st for add, .pq for mul
varying vec2 vtexcoord;
#endif
vec3 calcWave(in vec3 pos, in float fm, in float mm, in float ma, in float f0, in float f1, in float f2, in float f3, in float f4, in float f5) {
vec3 ret;
float magnitude,d0,d1,d2,d3;
magnitude = sin(pi2wt*fm + pos.x*0.5 + pos.z*0.5 + pos.y*0.5) * mm + ma;
d0 = sin(pi2wt*f0);
d1 = sin(pi2wt*f1);
d2 = sin(pi2wt*f2);
ret.x = sin(pi2wt*f3 + d0 + d1 - pos.x + pos.z + pos.y) * magnitude;
ret.z = sin(pi2wt*f4 + d1 + d2 + pos.x - pos.z + pos.y) * magnitude;
ret.y = sin(pi2wt*f5 + d2 + d0 + pos.z + pos.y - pos.y) * magnitude;
return ret;
}
vec3 calcMove(in vec3 pos, in float f0, in float f1, in float f2, in float f3, in float f4, in float f5, in vec3 amp1, in vec3 amp2) {
vec3 move1 = calcWave(pos , 0.0027, 0.0400, 0.0400, 0.0127, 0.0089, 0.0114, 0.0063, 0.0224, 0.0015) * amp1;
vec3 move2 = calcWave(pos+move1, 0.0348, 0.0400, 0.0400, f0, f1, f2, f3, f4, f5) * amp2;
return move1+move2;
}
#ifdef TAA
uniform float viewWidth;
uniform float viewHeight;
vec2 texelSize = vec2(1.0/viewWidth,1.0/viewHeight);
uniform int framemod8;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
vec2(-3,-5.)/8.,
vec2(-5.,5.)/8.,
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
#endif
void main() {
texcoord.xy = (gl_MultiTexCoord0).xy;
texcoord.zw = gl_MultiTexCoord1.xy/255.0;
vec4 position = gbufferModelViewInverse * gl_ModelViewMatrix * gl_Vertex;
worldpos = position.xyz + cameraPosition;
bool istopv = gl_MultiTexCoord0.t < mc_midTexCoord.t;
/*
bool entities = (mc_Entity.x == ENTITY_VINES || mc_Entity.x == ENTITY_SMALLENTS || mc_Entity.x == 10030.0 || mc_Entity.x == 10031.0 || mc_Entity.x == 10115.0 || mc_Entity.x == ENTITY_LILYPAD
|| mc_Entity.x == ENTITY_LAVA || mc_Entity.x == ENTITY_LEAVES || mc_Entity.x == ENTITY_SMALLGRASS || mc_Entity.x == ENTITY_UPPERGRASS || mc_Entity.x == ENTITY_LOWERGRASS);
*/
normal.a = 0.02;
normal.xyz = normalize(gl_NormalMatrix * gl_Normal);
#ifdef Waving_Tallgrass
if (mc_Entity.x == ENTITY_LOWERGRASS && istopv || mc_Entity.x == ENTITY_UPPERGRASS)
position.xyz += calcMove(worldpos.xyz,
0.0041,
0.0070,
0.0044,
0.0038,
0.0240,
0.0000,
vec3(0.8,0.0,0.8),
vec3(0.4,0.0,0.4));
#endif
if (istopv) {
#ifdef Waving_Grass
if ( mc_Entity.x == ENTITY_SMALLGRASS)
position.xyz += calcMove(worldpos.xyz,
0.0041,
0.0070,
0.0044,
0.0038,
0.0063,
0.0000,
vec3(3.0,1.6,3.0),
vec3(0.0,0.0,0.0));
#endif
#ifdef Waving_Entities
if ( mc_Entity.x == ENTITY_SMALLENTS)
position.xyz += calcMove(worldpos.xyz,
0.0041,
0.0070,
0.0044,
0.0038,
0.0240,
0.0000,
vec3(0.8,0.0,0.8),
vec3(0.4,0.0,0.4));
#endif
#ifdef Waving_Fire
if ( mc_Entity.x == ENTITY_FIRE)
position.xyz += calcMove(worldpos.xyz,
0.0105,
0.0096,
0.0087,
0.0063,
0.0097,
0.0156,
vec3(1.2,0.4,1.2),
vec3(0.8,0.8,0.8));
#endif
}
#ifdef Waving_Leaves
if ( mc_Entity.x == ENTITY_LEAVES)
position.xyz += calcMove(worldpos.xyz,
0.0040,
0.0064,
0.0043,
0.0035,
0.0037,
0.0041,
vec3(1.0,0.2,1.0),
vec3(0.5,0.1,0.5));
#endif
#ifdef Waving_Vines
if ( mc_Entity.x == ENTITY_VINES)
position.xyz += calcMove(worldpos.xyz,
0.0040,
0.0064,
0.0043,
0.0035,
0.0037,
0.0041,
vec3(0.5,1.0,0.5),
vec3(0.25,0.5,0.25));
if (mc_Entity.x == ENTITY_INVERTED_LOWER && gl_MultiTexCoord0.t > mc_midTexCoord.t)
position.xyz += calcMove(worldpos.xyz,
0.0041,
0.0070,
0.0044,
0.0038,
0.0240,
0.0000,
vec3(0.8,0.0,0.8),
vec3(0.4,0.0,0.4));
#endif
#ifdef Waving_Lava
if(mc_Entity.x == ENTITY_LAVA){
float fy = fract(worldpos.y + 0.001);
float wave = 0.05 * sin(2 * PI * (frameTimeCounter*0.2 + worldpos.x / 7.0 + worldpos.z / 13.0))
+ 0.05 * sin(2 * PI * (frameTimeCounter*0.15 + worldpos.x / 11.0 + worldpos.z / 5.0));
position.y += clamp(wave, -fy, 1.0-fy)*0.5;
}
#endif
#ifdef Waving_Lilypads
if(mc_Entity.x == ENTITY_LILYPAD){
float fy = fract(worldpos.y + 0.001);
float wave = 0.05 * sin(2 * PI * (frameTimeCounter*0.8 + worldpos.x / 2.5 + worldpos.z / 5.0))
+ 0.05 * sin(2 * PI * (frameTimeCounter*0.6 + worldpos.x / 6.0 + worldpos.z / 12.0));
position.y += clamp(wave, -fy, 1.0-fy)*1.05;
}
#endif
color = gl_Color;
#ifdef Waving_Lanterns
if(mc_Entity.x == 10090.0){
vec3 fxyz = fract(worldpos.xyz + 0.001);
float wave = 0.025 * sin(2 * PI * (frameTimeCounter*0.4 + worldpos.x * 0.5 + worldpos.z * 0.5));
float waveY = 0.05 * cos(frameTimeCounter*2.0 + worldpos.y);
position.x -= clamp(wave, -fxyz.x, 1.0-fxyz.x);
position.y += clamp(waveY*0.25, -fxyz.y, 1.0-fxyz.y)+0.015;
position.z += clamp(wave*0.45, -fxyz.z, 1.0-fxyz.z);
}
#endif
color = gl_Color;
if(mc_Entity.x == METALLIC_BLOCK) normal.a = 0.4;
if(mc_Entity.x == POLISHED_BLOCK) normal.a = 0.5;
//Fix colors on emissive blocks, removed lava as it might cause issues with custom optifine color maps.
if (mc_Entity.x == ENTITY_FIRE
|| mc_Entity.x == ENTITY_EMISSIVE
|| mc_Entity.x == ENITIY_SOULFIRE
|| mc_Entity.x == 10090.0){
normal.a = 0.6;
color = vec4(1.0);
}
if(mc_Entity.x == ENITIY_SOULFIRE || mc_Entity.x == 10090.0) texcoord.z = 0.85;
if(mc_Entity.x == ENTITY_LAVA) normal.a = 0.6;
//Translucent blocks
if (mc_Entity.x == ENTITY_VINES
|| mc_Entity.x == ENTITY_SMALLENTS
|| mc_Entity.x == 20000.0
|| mc_Entity.x == ENTITY_LILYPAD
|| mc_Entity.x == ENTITY_LAVA
|| mc_Entity.x == ENTITY_LEAVES
|| mc_Entity.x == ENTITY_SMALLGRASS
|| mc_Entity.x == ENTITY_UPPERGRASS
|| mc_Entity.x == ENTITY_LOWERGRASS){
normal.a = 0.7;
}
if(mc_Entity.x == 10300.0) color = vec4(1.0); //fix lecterns
gl_Position = gl_ProjectionMatrix * gbufferModelView * position;
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
#if nMap >= 1 || defined metallicRefl || defined polishedRefl
block = mc_Entity.x;
if(mc_Entity.x == ENTITY_EMISSIVE) block = -1.0; //enable bump and parallax mapping for defined ids.
vec2 midcoord = (gl_TextureMatrix[0] * mc_midTexCoord).st;
vec2 texcoordminusmid = texcoord.xy-midcoord;
vtexcoordam.pq = abs(texcoordminusmid)*2;
vtexcoordam.st = min(texcoord.xy ,midcoord-texcoordminusmid);
vtexcoord.xy = sign(texcoordminusmid)*0.5+0.5;
vec3 tangent = normalize(gl_NormalMatrix * at_tangent.xyz);
vec3 binormal = normalize(gl_NormalMatrix * cross(at_tangent.xyz, gl_Normal.xyz) * at_tangent.w);
tbnMatrix = mat3(tangent.x, binormal.x, normal.x,
tangent.y, binormal.y, normal.y,
tangent.z, binormal.z, normal.z);
dist = length(gl_ModelViewMatrix * gl_Vertex);
//viewVector = tbnMatrix * (mat3(gl_ModelViewMatrix) * gl_Vertex.xyz + gl_ModelViewMatrix[3].xyz);
viewVector = tbnMatrix * (gl_ModelViewMatrix * gl_Vertex).xyz;
//viewVector.xy = viewVector.xy / dist * 8.25;
#endif
}

View File

@@ -0,0 +1,26 @@
#version 120
/* DRAWBUFFERS:56 */
//Render hand, entities and particles in here, boost and fix enchanted armor effect in gbuffers_armor_glint
#define gbuffers_texturedblock
#include "/shaders.settings"
varying vec4 color;
varying vec2 texcoord;
varying vec3 ambientNdotL;
uniform sampler2D texture;
uniform vec4 entityColor;
void main() {
vec4 albedo = texture2D(texture, texcoord.xy)*color;
#ifdef MobsFlashRed
albedo.rgb = mix(albedo.rgb,entityColor.rgb,entityColor.a);
#endif
vec3 finalColor = pow(albedo.rgb,vec3(2.2)) * ambientNdotL.rgb;
gl_FragData[0] = vec4(finalColor, albedo.a);
gl_FragData[1] = vec4(normalize(albedo.rgb+0.00001), albedo.a);
}

View File

@@ -0,0 +1,120 @@
#version 120
#define composite2
#define gbuffers_texturedblock
#define lightingColors
#include "/shaders.settings"
varying vec4 color;
varying vec2 texcoord;
varying vec3 ambientNdotL;
uniform vec3 sunPosition;
uniform vec3 upPosition;
uniform int worldTime;
uniform float rainStrength;
uniform float nightVision;
uniform float screenBrightness;
uniform mat4 gbufferModelView;
uniform mat4 gbufferModelViewInverse;
const vec3 ToD[7] = vec3[7]( vec3(0.58597,0.15,0.02),
vec3(0.58597,0.35,0.09),
vec3(0.58597,0.5,0.26),
vec3(0.58597,0.5,0.35),
vec3(0.58597,0.5,0.36),
vec3(0.58597,0.5,0.37),
vec3(0.58597,0.5,0.38));
#ifdef TAA
uniform float viewWidth;
uniform float viewHeight;
vec2 texelSize = vec2(1.0/viewWidth,1.0/viewHeight);
uniform int framemod8;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
vec2(-3,-5.)/8.,
vec2(-5.,5.)/8.,
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
#endif
#ifdef HandLight
uniform int isEyeInWater;
uniform int heldBlockLightValue;
uniform int heldBlockLightValue2;
#endif
void main() {
//setup basics
color = gl_Color;
vec4 position = gbufferModelViewInverse * gl_ModelViewMatrix * gl_Vertex;
gl_Position = gl_ProjectionMatrix * gbufferModelView * position;
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
vec2 lmcoord = (gl_TextureMatrix[1] * gl_MultiTexCoord1).xy;
/*--------------------------------*/
//Emissive blocks lighting in order to fix lighting on particles
#ifdef HandLight
bool underwaterlava = (isEyeInWater == 1.0 || isEyeInWater == 2.0);
if(!underwaterlava) lmcoord.x = max(lmcoord.x, max(max(float(heldBlockLightValue), float(heldBlockLightValue2)) - 1.0 - length(gl_ModelViewMatrix * gl_Vertex), 0.0) / 15.0);
#endif
float torch_lightmap = 16.0-min(15.,(lmcoord.s-0.5/16.)*16.*16./15);
float fallof1 = clamp(1.0 - pow(torch_lightmap/16.0,4.0),0.0,1.0);
torch_lightmap = fallof1*fallof1/(torch_lightmap*torch_lightmap+1.0);
vec3 emissiveLightC = vec3(emissive_R,emissive_G,emissive_B)*torch_lightmap;
float finalminlight = (nightVision > 0.01)? 0.025 : ((minlight+0.006)+(screenBrightness*0.0125))*0.5;
/*---------------------------------------------------------------------*/
//reduced the sun color to a 7 array
float hour = max(mod(worldTime/1000.0+2.0,24.0)-2.0,0.0); //-0.1
float cmpH = max(-abs(floor(hour)-6.0)+6.0,0.0); //12
float cmpH1 = max(-abs(floor(hour)-5.0)+6.0,0.0); //1
vec3 temp = ToD[int(cmpH)];
vec3 temp2 = ToD[int(cmpH1)];
vec3 sunlight = mix(temp,temp2,fract(hour));
const vec3 rainC = vec3(0.01,0.01,0.01);
sunlight = mix(sunlight,rainC*sunlight,rainStrength);
/*-------------------------------------------------------------------*/
const vec3 moonlight = vec3(0.0024, 0.00432, 0.0078);
vec3 sunVec = normalize(sunPosition);
vec3 upVec = vec3(0.0, 1.0, 0.0); //fix for loading shaderpacks in nether and end, optifine bug.
vec2 visibility = vec2(dot(sunVec,upVec),dot(-sunVec,upVec));
float NdotL = dot(normal,sunVec);
float NdotU = dot(normal,upVec);
vec2 trCalc = min(abs(worldTime-vec2(23250.0,12700.0)),750.0);
float tr = max(min(trCalc.x,trCalc.y)/375.0-1.0,0.0);
visibility = pow(clamp(visibility+0.15,0.0,0.15)/0.15,vec2(4.0));
float skyL = max(lmcoord.t-2./16.0,0.0)*1.14285714286;
float SkyL2 = skyL*skyL;
float skyc2 = mix(1.0,SkyL2,skyL);
vec4 bounced = vec4(NdotL,NdotL,NdotL,NdotU) * vec4(-0.14*skyL*skyL,0.34,0.7,0.1) + vec4(0.6,0.66,0.7,0.25);
bounced *= vec4(skyc2,skyc2,visibility.x-tr*visibility.x,0.8);
vec3 sun_ambient = bounced.w * (vec3(0.1, 0.5, 1.1)+rainStrength*vec3(0.05,-0.27,-0.8))*2.3+ 1.7*sunlight*(sqrt(bounced.w)*bounced.x*2.4 + bounced.z)*(1.0-rainStrength*0.98);
vec3 moon_ambient = (moonlight*0.7 + moonlight*bounced.y)*(1.0-rainStrength*0.95)*2.0;
vec3 amb1 = (sun_ambient*visibility.x + moon_ambient*visibility.y)*SkyL2*(0.03+tr*0.17)*0.65;
ambientNdotL.rgb = amb1 + emissiveLightC + finalminlight;
sunlight = mix(sunlight,moonlight*(1.0-rainStrength*0.9),visibility.y)*tr;
}

View File

@@ -0,0 +1,109 @@
#version 120
#define gbuffers_water
#include "/shaders.settings"
varying vec4 color;
varying vec4 ambientNdotL;
varying vec2 texcoord;
varying vec2 lmcoord;
varying vec3 viewVector;
varying vec3 worldpos;
varying mat3 tbnMatrix;
uniform sampler2D noisetex;
uniform sampler2D texture;
uniform float frameTimeCounter;
vec4 encode (vec3 n,float dif){
float p = sqrt(n.z*8+8);
float vis = lmcoord.t;
if (ambientNdotL.a > 0.9) vis = vis * 0.25;
if (ambientNdotL.a > 0.4 && ambientNdotL.a < 0.6) vis = vis*0.25+0.25;
if (ambientNdotL.a < 0.1) vis = vis*0.25+0.5;
return vec4(n.xy/p + 0.5,vis,1.0);
}
mat2 rmatrix(float rad){
return mat2(vec2(cos(rad), -sin(rad)), vec2(sin(rad), cos(rad)));
}
float calcWaves(vec2 coord, float iswater){
vec2 movement = abs(vec2(0.0, -frameTimeCounter * 0.31365*iswater));
coord *= 0.262144;
vec2 coord0 = coord * rmatrix(1.0) - movement * 4.0;
coord0.y *= 3.0;
vec2 coord1 = coord * rmatrix(0.5) - movement * 1.5;
coord1.y *= 3.0;
vec2 coord2 = coord + movement * 0.5;
coord2.y *= 3.0;
float wave = 1.0 - texture2D(noisetex,coord0 * 0.005).x * 10.0; //big waves
wave += texture2D(noisetex,coord1 * 0.010416).x * 7.0; //small waves
wave += sqrt(texture2D(noisetex,coord2 * 0.045).x * 6.5) * 1.33;//noise texture
wave *= 0.0157;
return wave;
}
vec3 calcBump(vec2 coord, float iswater){
const vec2 deltaPos = vec2(0.25, 0.0);
float h0 = calcWaves(coord, iswater);
float h1 = calcWaves(coord + deltaPos.xy, iswater);
float h2 = calcWaves(coord - deltaPos.xy, iswater);
float h3 = calcWaves(coord + deltaPos.yx, iswater);
float h4 = calcWaves(coord - deltaPos.yx, iswater);
float xDelta = ((h1-h0)+(h0-h2));
float yDelta = ((h3-h0)+(h0-h4));
return vec3(vec2(xDelta,yDelta)*0.5, 0.5); //z = 1.0-0.5
}
vec3 calcParallax(vec3 pos, float iswater){
float getwave = calcWaves(pos.xz - pos.y, iswater);
pos.xz += (getwave * viewVector.xy) * waterheight;
return pos;
}
void main() {
float iswater = clamp(ambientNdotL.a*2.0-1.0,0.0,1.0);
vec4 albedo = texture2D(texture, texcoord.xy)*color;
albedo.rgb = pow(albedo.rgb,vec3(2.2));
float texvis = 0.5;
#ifndef watertex
texvis = 0.11;
if(iswater > 0.9)albedo.rgb = vec3(waterCR,waterCG,waterCB);
#endif
//Bump and parallax mapping
vec3 waterpos = worldpos;
#ifdef WaterParallax
waterpos = calcParallax(waterpos, iswater);
#endif
vec3 bump = calcBump(waterpos.xz - waterpos.y, iswater);
vec3 newnormal = normalize(bump * tbnMatrix);
//---
vec3 fColor = albedo.rgb*ambientNdotL.rgb;
float alpha = mix(albedo.a,texvis,iswater);
if(iswater > 0.9)alpha *= waterA;
/* DRAWBUFFERS:526 */
gl_FragData[0] = vec4(fColor,alpha);
gl_FragData[1] = encode(newnormal.xyz, 1.0);
gl_FragData[2] = vec4(normalize(albedo.rgb+0.00001),alpha);
}

View File

@@ -0,0 +1,172 @@
#version 120
#define composite2
#define gbuffers_water
#define lightingColors
#include "/shaders.settings"
varying vec4 color;
varying vec4 ambientNdotL;
varying vec2 texcoord;
varying vec2 lmcoord;
varying vec3 viewVector;
varying vec3 worldpos;
varying mat3 tbnMatrix;
attribute vec4 mc_Entity;
attribute vec4 at_tangent; //xyz = tangent vector, w = handedness, added in 1.7.10
uniform vec3 cameraPosition;
uniform vec3 sunPosition;
uniform vec3 upPosition;
uniform mat4 gbufferModelView;
uniform mat4 gbufferModelViewInverse;
uniform int worldTime;
uniform float rainStrength;
uniform float nightVision;
uniform float screenBrightness;
#ifdef Waving_Water
uniform float frameTimeCounter;
const float PI = 3.1415927;
#endif
const vec3 ToD[7] = vec3[7]( vec3(0.58597,0.16,0.005),
vec3(0.58597,0.31,0.05),
vec3(0.58597,0.45,0.16),
vec3(0.58597,0.5,0.35),
vec3(0.58597,0.5,0.36),
vec3(0.58597,0.5,0.37),
vec3(0.58597,0.5,0.38));
float SunIntensity(float zenithAngleCos, float sunIntensity, float cutoffAngle, float steepness){
return sunIntensity * max(0.0, 1.0 - exp(-((cutoffAngle - acos(zenithAngleCos))/steepness)));
}
float luma(vec3 color) {
return dot(color,vec3(0.299, 0.587, 0.114));
}
#ifdef TAA
uniform float viewWidth;
uniform float viewHeight;
vec2 texelSize = vec2(1.0/viewWidth,1.0/viewHeight);
uniform int framemod8;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
vec2(-3,-5.)/8.,
vec2(-5.,5.)/8.,
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
#endif
void main() {
//pos
vec3 normal = normalize(gl_NormalMatrix * gl_Normal).xyz;
vec3 position = mat3(gbufferModelViewInverse) * (gl_ModelViewMatrix * gl_Vertex).xyz + gbufferModelViewInverse[3].xyz;
worldpos = position.xyz + cameraPosition;
color = gl_Color;
texcoord = (gl_MultiTexCoord0).xy;
lmcoord = (gl_TextureMatrix[1] * gl_MultiTexCoord1).xy;
//Transparency stuff
ambientNdotL.a = 0.0;
float iswater = 1.0; //disable lightmap on water, make light go through instead
if(mc_Entity.x == 10008.0) {
ambientNdotL.a = 1.0;
iswater = 0.0;
#ifdef Waving_Water
float fy = fract(worldpos.y + 0.001);
float wave = 0.05 * sin(2 * PI * (frameTimeCounter*0.8 + worldpos.x / 2.5 + worldpos.z / 5.0))
+ 0.05 * sin(2 * PI * (frameTimeCounter*0.6 + worldpos.x / 6.0 + worldpos.z / 12.0));
position.y += clamp(wave, -fy, 1.0-fy)*waves_amplitude;
#endif
}
if(mc_Entity.x == 10079.0) ambientNdotL.a = 0.5;
//---
gl_Position = gl_ProjectionMatrix * gbufferModelView * vec4(position, 1.0);
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
//ToD
float hour = max(mod(worldTime/1000.0+2.0,24.0)-2.0,0.0); //-0.1
float cmpH = max(-abs(floor(hour)-6.0)+6.0,0.0); //12
float cmpH1 = max(-abs(floor(hour)-5.0)+6.0,0.0); //1
#ifdef MC_GL_VENDOR_ATI
vec3 sunlight = vec3(1.0); //Time of day calculation breaks water on amd drivers 18.8.1, last working driver was 18.6.1, causes heavy flickering. TESTED ON RX460
#else
vec3 sunlight = mix(ToD[int(cmpH)], ToD[int(cmpH1)], fract(hour));
#endif
sunlight.rgb += vec3(r_multiplier,g_multiplier,b_multiplier); //allows lighting colors to be tweaked.
sunlight.rgb *= light_brightness; //brightness needs to be adjusted if we tweak lighting colors.
//---
//lightmap
float torch_lightmap = 16.0-min(15.0,(lmcoord.s-0.5/16.0)*16.0*16.0/15.0);
float fallof1 = clamp(1.0 - pow(torch_lightmap/16.0,4.0),0.0,1.0);
torch_lightmap = fallof1*fallof1/(torch_lightmap*torch_lightmap+1.0);
torch_lightmap *= iswater;
vec3 emissiveLightC = vec3(emissive_R,emissive_G,emissive_B)*torch_lightmap*0.2;
//---
//light bounce
vec3 sunVec = normalize(sunPosition);
vec3 upVec = vec3(0.0, 1.0, 0.0); //fix for loading shaderpacks in nether and end, optifine bug.
vec2 visibility = vec2(dot(sunVec,upVec),dot(-sunVec,upVec));
float cutoffAngle = 1.608;
float steepness = 1.5;
float cosSunUpAngle = dot(sunVec, upVec) * 0.95 + 0.05; //Has a lower offset making it scatter when sun is below the horizon.
float sunE = SunIntensity(cosSunUpAngle, 1000.0, cutoffAngle, steepness); // Get sun intensity based on how high in the sky it is
float NdotL = dot(normal,sunVec);
float NdotU = dot(normal,upVec);
vec2 trCalc = min(abs(worldTime-vec2(23000.0,12700.0)),750.0); //adjust to make day-night switch smoother
float tr = max(min(trCalc.x,trCalc.y)/375.0-1.0,0.0);
visibility = pow(clamp(visibility+0.15,0.0,0.3)/0.3,vec2(4.4));
sunlight = sunlight/luma(sunlight)*sunE*0.0075*0.075*3.*visibility.x;
float skyL = max(lmcoord.t-2./16.0,0.0)*1.14285714286;
float SkyL2 = skyL*skyL;
float skyc2 = mix(1.0,SkyL2,skyL);
vec4 bounced = vec4(NdotL,NdotL,NdotL,NdotU) * vec4(-0.14*skyL*skyL,0.33,0.7,0.1) + vec4(0.6,0.66,0.7,0.25);
bounced *= vec4(skyc2,skyc2,visibility.x-tr*visibility.x,0.8);
vec3 ambientC = mix(vec3(0.3, 0.5, 1.1),vec3(0.08,0.1,0.1),rainStrength)*length(sunlight)*bounced.w;
ambientC += 0.25*sunlight*(bounced.x + bounced.z)*(0.03+tr*0.17)/0.4*(1.0-rainStrength*0.98) + length(sunlight)*0.2*(1.0-rainStrength*0.9);
ambientC += sunlight*(NdotL*0.5+0.45)*visibility.x*(1.0-tr)*(1.0-tr)*4.*(1.0-rainStrength*0.98);
//lighting during night time
const vec3 moonlight = vec3(0.0024, 0.00432, 0.0078);
vec3 moon_ambient = (moonlight*2.0 + moonlight*bounced.y)*(4.0-rainStrength*0.95)*0.2;
vec3 moonC = (moon_ambient*visibility.y)*SkyL2*(0.03*0.65+tr*0.17*0.65);
float finalminlight = (nightVision > 0.01)? 0.075: ((minlight+0.006)+(screenBrightness*0.0125))*0.25;
ambientNdotL.rgb = ambientC*SkyL2*0.3 + moonC + emissiveLightC + finalminlight;
//sunlight = mix(sunlight,moonlight*(1.0-rainStrength*0.9),visibility.y)*tr;
sunlight = mix(sunlight,moonlight*(1.0-rainStrength*0.9),visibility.y); //remove time check to improve day-night transition
//---
vec3 tangent = normalize(gl_NormalMatrix * at_tangent.xyz);
vec3 binormal = normalize(gl_NormalMatrix * cross(at_tangent.xyz, gl_Normal.xyz) * at_tangent.w);
tbnMatrix = mat3(tangent.x, binormal.x, normal.x,
tangent.y, binormal.y, normal.y,
tangent.z, binormal.z, normal.z);
float dist = length(gl_ModelViewMatrix * gl_Vertex);
viewVector = tbnMatrix * (gl_ModelViewMatrix * gl_Vertex).xyz;
viewVector.xy = viewVector.xy / dist * 8.25;
}