2023-10-07 22:18:20 -04:00
|
|
|
#include "/lib/settings.glsl"
|
2024-05-02 12:43:30 -04:00
|
|
|
|
|
|
|
#ifdef IS_LPV_ENABLED
|
|
|
|
#extension GL_EXT_shader_image_load_store: enable
|
|
|
|
#endif
|
|
|
|
|
2023-10-07 22:18:20 -04:00
|
|
|
#include "/lib/res_params.glsl"
|
|
|
|
|
2023-04-16 16:18:26 -04:00
|
|
|
varying vec4 lmtexcoord;
|
|
|
|
varying vec4 color;
|
|
|
|
|
2024-02-05 16:04:37 -05:00
|
|
|
#ifdef LINES
|
|
|
|
flat varying int SELECTION_BOX;
|
|
|
|
#endif
|
|
|
|
|
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-08-03 00:23:29 -04:00
|
|
|
|
2023-10-07 22:18:20 -04:00
|
|
|
flat varying vec3 WsunVec;
|
|
|
|
|
|
|
|
flat varying vec3 averageSkyCol_Clouds;
|
|
|
|
flat varying vec4 lightCol;
|
|
|
|
#endif
|
2023-04-16 16:18:26 -04:00
|
|
|
|
2024-03-01 22:48:09 -05:00
|
|
|
uniform int isEyeInWater;
|
|
|
|
|
2023-10-07 22:18:20 -04:00
|
|
|
uniform sampler2D texture;
|
|
|
|
uniform sampler2D noisetex;
|
2023-08-03 00:23:29 -04:00
|
|
|
uniform sampler2D colortex4;
|
|
|
|
|
2024-05-04 16:33:11 -04:00
|
|
|
#ifdef IS_LPV_ENABLED
|
|
|
|
uniform sampler3D texLpv1;
|
|
|
|
uniform sampler3D texLpv2;
|
|
|
|
#endif
|
|
|
|
|
2023-08-03 00:23:29 -04:00
|
|
|
|
2023-04-16 16:18:26 -04:00
|
|
|
uniform mat4 gbufferProjectionInverse;
|
|
|
|
uniform mat4 gbufferModelViewInverse;
|
|
|
|
uniform mat4 gbufferModelView;
|
|
|
|
uniform mat4 shadowModelView;
|
|
|
|
uniform mat4 shadowProjection;
|
|
|
|
uniform vec3 cameraPosition;
|
|
|
|
|
2023-08-03 00:23:29 -04:00
|
|
|
uniform float frameTimeCounter;
|
2023-10-14 23:34:52 -04:00
|
|
|
#include "/lib/Shadow_Params.glsl"
|
2023-04-16 16:18:26 -04:00
|
|
|
|
2023-08-03 00:23:29 -04:00
|
|
|
uniform vec2 texelSize;
|
|
|
|
|
|
|
|
uniform ivec2 eyeBrightnessSmooth;
|
|
|
|
uniform float rainStrength;
|
2023-10-30 16:07:38 -04:00
|
|
|
flat varying float HELD_ITEM_BRIGHTNESS;
|
2023-04-16 16:18:26 -04:00
|
|
|
|
2023-10-07 22:18:20 -04:00
|
|
|
#ifndef OVERWORLD_SHADER
|
|
|
|
uniform float nightVision;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef OVERWORLD_SHADER
|
|
|
|
#define CLOUDSHADOWSONLY
|
|
|
|
#include "/lib/volumetricClouds.glsl"
|
|
|
|
#endif
|
|
|
|
|
2024-05-02 12:43:30 -04:00
|
|
|
#ifdef IS_LPV_ENABLED
|
|
|
|
uniform int frameCounter;
|
|
|
|
|
|
|
|
#include "/lib/hsv.glsl"
|
|
|
|
#include "/lib/lpv_common.glsl"
|
|
|
|
#include "/lib/lpv_render.glsl"
|
|
|
|
#endif
|
|
|
|
|
2023-04-16 16:18:26 -04:00
|
|
|
#include "/lib/diffuse_lighting.glsl"
|
2023-08-03 00:23:29 -04:00
|
|
|
#include "/lib/sky_gradient.glsl"
|
2023-04-16 16:18:26 -04:00
|
|
|
|
|
|
|
vec3 toLinear(vec3 sRGB){
|
|
|
|
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
|
|
|
|
|
|
|
|
vec3 toScreenSpace(vec3 p) {
|
|
|
|
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
|
|
|
|
vec3 p3 = p * 2. - 1.;
|
|
|
|
vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
|
|
|
|
return fragposition.xyz / fragposition.w;
|
|
|
|
}
|
|
|
|
|
|
|
|
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.);
|
|
|
|
|
2023-10-07 22:18:20 -04:00
|
|
|
//Mie phase function
|
|
|
|
float phaseg(float x, float g){
|
|
|
|
float gg = g * g;
|
|
|
|
return (gg * -0.25 + 0.25) * pow(-2.0 * (g * x) + (gg + 1.0), -1.5) / 3.14;
|
2023-04-16 16:18:26 -04:00
|
|
|
}
|
|
|
|
|
2024-03-30 23:20:34 -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;
|
|
|
|
}
|
|
|
|
float encodeVec2(float x,float y){
|
|
|
|
return encodeVec2(vec2(x,y));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-16 16:18:26 -04:00
|
|
|
//////////////////////////////VOID MAIN//////////////////////////////
|
|
|
|
//////////////////////////////VOID MAIN//////////////////////////////
|
|
|
|
//////////////////////////////VOID MAIN//////////////////////////////
|
|
|
|
//////////////////////////////VOID MAIN//////////////////////////////
|
|
|
|
//////////////////////////////VOID MAIN//////////////////////////////
|
2023-10-07 22:18:20 -04:00
|
|
|
|
2024-03-30 23:20:34 -04:00
|
|
|
#ifdef DAMAGE_BLOCK_EFFECT
|
|
|
|
/* RENDERTARGETS:11 */
|
|
|
|
#else
|
|
|
|
/* DRAWBUFFERS:29 */
|
|
|
|
#endif
|
2023-10-07 22:18:20 -04:00
|
|
|
|
2023-04-16 16:18:26 -04:00
|
|
|
void main() {
|
2024-02-05 16:04:37 -05:00
|
|
|
|
|
|
|
#ifdef LINES
|
|
|
|
#ifndef SELECT_BOX
|
|
|
|
if(SELECTION_BOX > 0) discard;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2023-10-07 22:18:20 -04:00
|
|
|
vec2 tempOffset = offsets[framemod8];
|
|
|
|
vec3 viewPos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0));
|
|
|
|
vec3 feetPlayerPos = mat3(gbufferModelViewInverse) * viewPos;
|
|
|
|
vec3 feetPlayerPos_normalized = normalize(feetPlayerPos);
|
2023-04-16 16:18:26 -04:00
|
|
|
|
2023-10-07 22:18:20 -04:00
|
|
|
vec4 TEXTURE = texture2D(texture, lmtexcoord.xy)*color;
|
2024-03-30 23:20:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-04-16 16:18:26 -04:00
|
|
|
|
2023-10-07 22:18:20 -04:00
|
|
|
vec3 Albedo = toLinear(TEXTURE.rgb);
|
|
|
|
|
|
|
|
vec2 lightmap = lmtexcoord.zw;
|
|
|
|
|
|
|
|
#ifndef OVERWORLD_SHADER
|
|
|
|
lightmap.y = 1.0;
|
|
|
|
#endif
|
2023-10-30 16:07:38 -04:00
|
|
|
|
|
|
|
#ifdef Hand_Held_lights
|
2024-01-11 14:43:16 -05:00
|
|
|
lightmap.x = max(lightmap.x, HELD_ITEM_BRIGHTNESS * clamp( pow(max(1.0-length(viewPos)/HANDHELD_LIGHT_RANGE,0.0),1.5),0.0,1.0));
|
2023-10-30 16:07:38 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-07 22:18:20 -04:00
|
|
|
#ifdef WEATHER
|
|
|
|
gl_FragData[1].a = TEXTURE.a; // for bloomy rain and stuff
|
|
|
|
#endif
|
2023-04-16 16:18:26 -04:00
|
|
|
|
|
|
|
|
2023-10-07 22:18:20 -04:00
|
|
|
#ifndef WEATHER
|
|
|
|
#ifndef LINES
|
|
|
|
gl_FragData[0].a = TEXTURE.a;
|
|
|
|
#else
|
|
|
|
gl_FragData[0].a = 1.0;
|
|
|
|
#endif
|
2023-12-21 15:21:15 -05:00
|
|
|
#ifndef BLOOMY_PARTICLES
|
|
|
|
gl_FragData[1].a = 0.0; // for bloomy rain and stuff
|
|
|
|
#endif
|
2023-12-22 16:19:44 -05:00
|
|
|
|
2023-10-07 22:18:20 -04:00
|
|
|
vec3 Direct_lighting = vec3(0.0);
|
|
|
|
vec3 Indirect_lighting = vec3(0.0);
|
2024-03-01 22:48:09 -05:00
|
|
|
|
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);
|
|
|
|
|
2023-10-07 22:18:20 -04:00
|
|
|
vec3 Torch_Color = vec3(TORCH_R,TORCH_G,TORCH_B);
|
|
|
|
|
2023-10-30 16:07:38 -04:00
|
|
|
|
|
|
|
if(lightmap.x >= 0.9) Torch_Color *= LIT_PARTICLE_BRIGHTNESS;
|
2023-10-07 22:18:20 -04:00
|
|
|
|
|
|
|
#ifdef OVERWORLD_SHADER
|
2024-03-20 21:44:25 -04:00
|
|
|
vec3 Shadows = vec3(1.0);
|
2023-10-07 22:18:20 -04:00
|
|
|
|
|
|
|
vec3 feetPlayerPos_shadow = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
|
|
|
|
vec3 projectedShadowPosition = mat3(shadowModelView) * feetPlayerPos_shadow + shadowModelView[3].xyz;
|
|
|
|
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
|
|
|
|
|
|
|
|
//apply distortion
|
2024-02-05 16:04:37 -05:00
|
|
|
#ifdef DISTORT_SHADOWMAP
|
|
|
|
float distortFactor = calcDistort(projectedShadowPosition.xy);
|
|
|
|
projectedShadowPosition.xy *= distortFactor;
|
|
|
|
#else
|
|
|
|
float distortFactor = 1.0;
|
|
|
|
#endif
|
2023-10-07 22:18:20 -04:00
|
|
|
|
|
|
|
//do shadows only if on shadow map
|
|
|
|
if (abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution){
|
2024-03-20 21:44:25 -04:00
|
|
|
Shadows = vec3(0.0);
|
2023-10-07 22:18:20 -04:00
|
|
|
|
|
|
|
projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5);
|
|
|
|
|
2024-03-20 21:44:25 -04:00
|
|
|
#ifdef TRANSLUCENT_COLORED_SHADOWS
|
|
|
|
float opaqueShadow = shadow2D(shadowtex0, projectedShadowPosition).x;
|
|
|
|
Shadows += vec3(opaqueShadow);
|
|
|
|
|
|
|
|
if(shadow2D(shadowtex1, projectedShadowPosition).x > projectedShadowPosition.z){
|
|
|
|
vec4 translucentShadow = texture2D(shadowcolor0, projectedShadowPosition.xy);
|
|
|
|
if(translucentShadow.a < 0.9) Shadows += normalize(translucentShadow.rgb+0.0001) * (1.0-opaqueShadow);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
Shadows = vec3(shadow2D(shadow, projectedShadowPosition).x);
|
|
|
|
#endif
|
2023-10-07 22:18:20 -04:00
|
|
|
}
|
2023-08-03 00:23:29 -04:00
|
|
|
|
2023-10-07 22:18:20 -04:00
|
|
|
float cloudShadow = GetCloudShadow(feetPlayerPos);
|
|
|
|
|
|
|
|
Direct_lighting = (lightCol.rgb/80.0) * Shadows * cloudShadow;
|
2023-10-10 23:02:00 -04:00
|
|
|
|
2023-10-07 22:18:20 -04:00
|
|
|
|
|
|
|
#ifndef LINES
|
|
|
|
Direct_lighting *= phaseg(clamp(dot(feetPlayerPos_normalized, WsunVec),0.0,1.0), 0.65)*2 + 0.5;
|
|
|
|
#endif
|
|
|
|
|
2024-03-01 22:48:09 -05:00
|
|
|
vec3 AmbientLightColor = (averageSkyCol_Clouds / 30.0) * 3.0;
|
2023-08-03 00:23:29 -04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NETHER_SHADER
|
2024-03-22 22:58:19 -04:00
|
|
|
// vec3 AmbientLightColor = skyCloudsFromTexLOD2(vec3( 0, 1, 0), colortex4, 6).rgb / 15;
|
|
|
|
vec3 AmbientLightColor = vec3(0.1);
|
2023-10-18 17:43:29 -04:00
|
|
|
#endif
|
2023-04-16 16:18:26 -04:00
|
|
|
|
2023-10-18 17:43:29 -04:00
|
|
|
#ifdef END_SHADER
|
|
|
|
vec3 AmbientLightColor = vec3(1.0);
|
2023-08-03 00:23:29 -04:00
|
|
|
#endif
|
2023-10-07 22:18:20 -04:00
|
|
|
|
2024-05-02 12:43:30 -04:00
|
|
|
Indirect_lighting = DoAmbientLightColor(feetPlayerPos, AmbientLightColor,MinimumLightColor, Torch_Color, clamp(lightmap.xy,0,1));
|
2023-10-18 17:43:29 -04:00
|
|
|
|
2023-10-20 21:33:13 -04:00
|
|
|
#ifdef LINES
|
2023-10-07 22:18:20 -04:00
|
|
|
gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * toLinear(color.rgb);
|
2023-10-20 21:33:13 -04:00
|
|
|
#else
|
|
|
|
gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * Albedo;
|
2023-10-07 22:18:20 -04:00
|
|
|
#endif
|
2024-03-30 23:20:34 -04:00
|
|
|
|
|
|
|
#ifdef DAMAGE_BLOCK_EFFECT
|
|
|
|
|
|
|
|
gl_FragData[0] = vec4(0.0, encodeVec2(TEXTURE.rg), encodeVec2(vec2(TEXTURE.b,0.0)), TEXTURE.a);
|
|
|
|
#endif
|
2023-10-07 22:18:20 -04:00
|
|
|
|
|
|
|
// distance fade targeting the world border...
|
|
|
|
if(TEXTURE.a < 0.7 && TEXTURE.a > 0.2) gl_FragData[0] *= clamp(1.0 - length(feetPlayerPos) / 100.0 ,0.0,1.0);
|
|
|
|
#endif
|
2023-04-16 16:18:26 -04:00
|
|
|
}
|