LOTS of fixes, changes, improvements. changes made is bloated because of a skill issue.

FIXED AND IMPROVED translucent rendering. FIXED random stuff from rendering over the hand. FIXED hand shading. FIXED blue horses. FIXED translucent lighting on the hand. FIXED translucent lighting on entities. IMPROVED colored shadows. IMPROVED SSAO application to the scene. IMPROVED subsurface scattering and give it more settings. IMPROVED bloom. ADD AgX tonemap and make it default.
This commit is contained in:
Xonk
2024-05-04 21:08:24 -04:00
parent 343a68c816
commit 25a2284a60
70 changed files with 4096 additions and 1510 deletions

View File

@ -109,8 +109,12 @@ void main() {
vec3 normals = viewToWorld(normals_and_materials.xyz);
float materials = normals_and_materials.a;
vec2 PackLightmaps = lightmapCoords;
PackLightmaps.y *= 1.05;
PackLightmaps = min(max(PackLightmaps - 0.001*blueNoise(),0.0)*1.002,1.0);
vec4 data1 = clamp( encode(normals.xyz, vec2(lightmapCoords)), 0.0, 1.0);
vec4 data1 = clamp( encode(normals.xyz, PackLightmaps), 0.0, 1.0);
// alpha is material masks, set it to 0.65 to make a DH LODs mask.
vec4 Albedo = vec4(gcolor.rgb, 1.0);

View File

@ -68,7 +68,7 @@ void main() {
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
lightmapCoords = gl_MultiTexCoord1.xy * 0.975; // is this even correct? lol'
lightmapCoords = gl_MultiTexCoord1.xy; // is this even correct? lol'
gcolor = gl_Color;
pos = gl_ModelViewMatrix * gl_Vertex;

View File

@ -11,9 +11,10 @@ uniform sampler2D noisetex;
const bool shadowHardwareFiltering = true;
uniform sampler2DShadow shadow;
#ifdef DISTANT_HORIZONS
uniform sampler2D dhDepthTex;
// uniform sampler2D dhDepthTex0;
uniform sampler2D dhDepthTex1;
#endif
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
@ -110,10 +111,8 @@ uniform int isEyeInWater;
uniform float rainStrength;
#include "/lib/volumetricClouds.glsl"
vec3 GGX (vec3 n, vec3 v, vec3 l, float r, vec3 F0) {
r = pow(r,2.5);
// r*=r;
float GGX(vec3 n, vec3 v, vec3 l, float r, float f0) {
r = max(pow(r,2.5), 0.0001);
vec3 h = l + v;
float hn = inversesqrt(dot(h, h));
@ -125,11 +124,13 @@ vec3 GGX (vec3 n, vec3 v, vec3 l, float r, vec3 F0) {
float denom = dotNHsq * r - dotNHsq + 1.;
float D = r / (3.141592653589793 * denom * denom);
vec3 F = 0.2 + (1. - F0) * exp2((-5.55473*dotLH-6.98316)*dotLH);
float F = f0 + (1. - f0) * exp2((-5.55473*dotLH-6.98316)*dotLH);
float k2 = .25 * r;
return dotNL * D * F / (dotLH*dotLH*(1.0-k2)+k2);
}
uniform int framemod8;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
@ -226,143 +227,190 @@ uniform float near;
float ld(float dist) {
return (2.0 * near) / (far + near - dist * (far - near));
}
vec3 applyBump(mat3 tbnMatrix, vec3 bump, float puddle_values){
float bumpmult = puddle_values;
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
//
return normalize(bump*tbnMatrix);
}
varying vec4 tangent;
/* RENDERTARGETS:2,7 */
void main() {
if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 ) {
bool iswater = isWater > 0;
float material = 0.7;
if(iswater) material = 1.0;
vec3 normals = normals_and_materials.xyz;
vec3 playerPos = mat3(gbufferModelViewInverse) * pos.xyz;
vec3 viewPos = pos.xyz;
vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
float transition = exp(-25* pow(clamp(1.0 - length(playerPos)/(far-8),0.0,1.0),2));
#ifdef DH_OVERDRAW_PREVENTION
if(length(playerPos) < max(far-16*4,16) ){ discard; return;}
#endif
if(iswater){
vec3 posxz = playerPos+cameraPosition;
vec3 waterHeightmap = normalize(getWaveNormal(posxz, true));
float bumpmult = WATER_WAVE_STRENGTH;
waterHeightmap = waterHeightmap * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
waterHeightmap = normalize(waterHeightmap);
vec3 bump = normalize(getWaveNormal(posxz, true));
// vec2 TangentNormal = waterHeightmap.xy*0.5+0.5;
// gl_FragData[2] = vec4(encodeVec2(TangentNormal), encodeVec2(vec2(1.0)), encodeVec2(vec2(1.0)), 1.0);
float bumpmult = 10.0 * WATER_WAVE_STRENGTH;
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
if(normals.y > 0.0) normals = vec3(waterHeightmap.x,normals.y,waterHeightmap.y);
normals.xz = bump.xy;
}
normals = worldToView(normals);
vec3 Albedo = toLinear(gcolor.rgb);
gl_FragData[0] = vec4(Albedo, gcolor.a);
vec4 COLORTEST = gl_FragData[0];
gl_FragData[0] = gcolor;
// float UnchangedAlpha = gl_FragData[0].a;
#ifndef Vanilla_like_water
if(iswater){
Albedo = vec3(0.0);
gl_FragData[0].a = 1.0/255.0;
}
#ifdef WhiteWorld
gl_FragData[0].rgb = vec3(0.5);
gl_FragData[0].a = 1.0;
#endif
vec3 Albedo = toLinear(gl_FragData[0].rgb);
#ifndef WhiteWorld
#ifndef Vanilla_like_water
if (iswater){
Albedo = vec3(0.0);
gl_FragData[0].a = 1.0/255.0;
}
#endif
#endif
// diffuse
vec3 Direct_lighting = lightCol.rgb/80.0;
vec3 Indirect_lighting = vec3(0.0);
// vec3 MinimumLightColor = vec3(1.0);
// if(isEyeInWater == 1) MinimumLightColor = vec3(10.0);
vec3 Direct_lighting = vec3(0.0);
float NdotL = max(dot(normals, WsunVec2), 0.0f);
Direct_lighting *= NdotL;
#ifdef CLOUDS_SHADOWS
Direct_lighting *= GetCloudShadow(playerPos);
#endif
#ifdef OVERWORLD_SHADER
vec3 DirectLightColor = lightCol.rgb/80.0;
float NdotL = clamp(dot(normals, normalize(WsunVec2)),0.0,1.0);
NdotL = clamp((-15 + NdotL*255.0) / 240.0 ,0.0,1.0);
#ifdef DISTANT_HORIZONS_SHADOWMAP
float Shadows = 1.0;
vec3 feetPlayerPos_shadow = mat3(gbufferModelViewInverse) * pos.xyz + gbufferModelViewInverse[3].xyz;
vec3 projectedShadowPosition = mat3(shadowModelView) * feetPlayerPos_shadow + shadowModelView[3].xyz;
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
#ifdef DISTANT_HORIZONS_SHADOWMAP
vec3 feetPlayerPos_shadow = mat3(gbufferModelViewInverse) * pos.xyz + gbufferModelViewInverse[3].xyz;
//apply distortion
#ifdef DISTORT_SHADOWMAP
float distortFactor = calcDistort(projectedShadowPosition.xy);
projectedShadowPosition.xy *= distortFactor;
#else
float distortFactor = 1.0;
#endif
vec3 projectedShadowPosition = mat3(shadowModelView) * feetPlayerPos_shadow + shadowModelView[3].xyz;
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
float smallbias = -0.0035;
//apply distortion
#ifdef DISTORT_SHADOWMAP
float distortFactor = calcDistort(projectedShadowPosition.xy);
projectedShadowPosition.xy *= distortFactor;
#else
float distortFactor = 1.0;
#endif
bool ShadowBounds = abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.z) < 6.0;
if(ShadowBounds){
Shadows = 0.0;
projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5);
float smallbias = -0.0035;
Shadows = shadow2D(shadow, projectedShadowPosition + vec3(0.0,0.0, smallbias)).x;
}
Direct_lighting *= Shadows;
#endif
bool ShadowBounds = abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.z) < 6.0;
if(ShadowBounds){
Shadows = 0.0;
projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5);
vec3 Indirect_lighting = averageSkyCol_Clouds/30.0;
gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * Albedo;
// specular
vec3 reflectedVector = reflect(normalize(pos.xyz), normals);
float normalDotEye = dot(normals, normalize(pos.xyz));
float fresnel = pow(clamp(1.0 + normalDotEye, 0.0, 1.0),5.0);
fresnel = mix(0.02, 1.0, fresnel);
#ifdef SNELLS_WINDOW
if(isEyeInWater == 1) fresnel = pow(clamp(1.5 + normalDotEye,0.0,1.0), 25.0);
#endif
#ifdef WATER_REFLECTIONS
vec4 ssReflections = vec4(0);
#ifdef SCREENSPACE_REFLECTIONS
vec3 rtPos = rayTrace(reflectedVector, pos.xyz, interleaved_gradientNoise(), fresnel, false);
if (rtPos.z < 1.){
vec3 previousPosition = mat3(gbufferModelViewInverse) * DH_toScreenSpace(rtPos) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition;
previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz;
previousPosition.xy = projMAD(dhPreviousProjection, previousPosition).xy / -previousPosition.z * 0.5 + 0.5;
if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0) {
ssReflections.a = 1.0;
ssReflections.rgb = texture2D(colortex5, previousPosition.xy).rgb;
}
}
Shadows = shadow2D(shadow, projectedShadowPosition + vec3(0.0,0.0, smallbias)).x;
}
#endif
#ifdef CLOUDS_SHADOWS
Shadows *= pow(GetCloudShadow(playerPos),3);
#endif
vec3 skyReflection = skyCloudsFromTex(mat3(gbufferModelViewInverse) * reflectedVector, colortex4).rgb / 30.0 ;
skyReflection = mix(skyReflection, ssReflections.rgb, ssReflections.a);
Direct_lighting = DirectLightColor * NdotL * Shadows;
vec3 sunReflection = Direct_lighting * GGX(normals, -normalize(pos.xyz), WsunVec2, 0.05, vec3(0.02)) * (1-ssReflections.a) ;
vec3 AmbientLightColor = averageSkyCol_Clouds/30.0;
gl_FragData[0].rgb = mix(gl_FragData[0].rgb, skyReflection, fresnel) + sunReflection ;
gl_FragData[0].a = mix(gl_FragData[0].a, 1.0, fresnel);
#endif
vec3 ambientcoefs = normals_and_materials.xyz / dot(abs(normals_and_materials.xyz), vec3(1.0));
float SkylightDir = ambientcoefs.y*1.5;
float material = 1.0;
#ifdef DH_OVERDRAW_PREVENTION
float distancefade = min(max(1.0 - length(pos.xz)/max(far-16.0,0.0),0.0)*2.0,1.0);
gl_FragData[0].a = mix(gl_FragData[0].a, 0.0, distancefade);
material = distancefade < 1.0 ? 1.0 : 0.0;
float skylight = max(pow(viewToWorld(normals_and_materials.xyz).y*0.5+0.5,0.1) + SkylightDir, 0.2);
AmbientLightColor *= skylight;
#endif
if(texture2D(depthtex1, gl_FragCoord.xy*texelSize).x < 1.0){
Indirect_lighting = AmbientLightColor;
vec3 FinalColor = (Indirect_lighting + Direct_lighting) * Albedo;
// specular
#ifdef WATER_REFLECTIONS
vec3 Reflections_Final = vec3(0.0);
vec4 Reflections = vec4(0.0);
vec3 BackgroundReflection = FinalColor;
vec3 SunReflection = vec3(0.0);
float roughness = 0.035;
float f0 = 0.02;
// float f0 = 0.9;
vec3 reflectedVector = reflect(normalize(viewPos), normals);
float normalDotEye = dot(normals, normalize(viewPos));
float fresnel = pow(clamp(1.0 + normalDotEye, 0.0, 1.0),5.0);
fresnel = mix(f0, 1.0, fresnel);
#ifdef SNELLS_WINDOW
if(isEyeInWater == 1) fresnel = pow(clamp(1.5 + normalDotEye,0.0,1.0), 25.0);
#endif
#ifdef SCREENSPACE_REFLECTIONS
vec3 rtPos = rayTrace(reflectedVector, viewPos, interleaved_gradientNoise(), fresnel, false);
if (rtPos.z < 1.){
vec3 previousPosition = mat3(gbufferModelViewInverse) * DH_toScreenSpace(rtPos) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition;
previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz;
previousPosition.xy = projMAD(dhPreviousProjection, previousPosition).xy / -previousPosition.z * 0.5 + 0.5;
if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0) {
Reflections.a = 1.0;
Reflections.rgb = texture2D(colortex5, previousPosition.xy).rgb;
}
}
#endif
#ifdef WATER_BACKGROUND_SPECULAR
BackgroundReflection = skyCloudsFromTex(mat3(gbufferModelViewInverse) * reflectedVector, colortex4).rgb / 30.0;
#endif
#ifdef WATER_SUN_SPECULAR
SunReflection = Direct_lighting * GGX(normalize(normals), -normalize(viewPos), normalize(WsunVec2), roughness, f0) * (1.0 - Reflections.a);
#endif
Reflections_Final = mix(BackgroundReflection, Reflections.rgb, Reflections.a) * fresnel;
Reflections_Final += SunReflection;
//correct alpha channel with fresnel
float alpha0 = gl_FragData[0].a;
gl_FragData[0].a = -gl_FragData[0].a * fresnel + gl_FragData[0].a + fresnel;
// prevent reflections from being darkened by buffer blending
gl_FragData[0].rgb = clamp(FinalColor / gl_FragData[0].a*alpha0*(1.0-fresnel) * 0.1 + Reflections_Final / gl_FragData[0].a * 0.1,0.0,65100.0);
if (gl_FragData[0].r > 65000.) gl_FragData[0].rgba = vec4(0.0);
#else
gl_FragData[0].rgb = FinalColor*0.1;
#endif
#ifdef DH_OVERDRAW_PREVENTION
float distancefade = min(max(1.0 - length(playerPos)/max(far-16*4,16),0.0)*5,1.0);
if(texture2D(depthtex1, gl_FragCoord.xy*texelSize).x < 1.0 || distancefade > 0.0){
gl_FragData[0].a = 0.0;
material = 0.0;
}
#endif
#if DEBUG_VIEW == debug_DH_WATER_BLENDING
if(gl_FragCoord.x*texelSize.x > 0.53) gl_FragData[0] = vec4(0.0);

View File

@ -1,8 +1,14 @@
#include "/lib/settings.glsl"
#ifdef IS_LPV_ENABLED
#extension GL_EXT_shader_image_load_store: enable
#endif
#include "/lib/res_params.glsl"
varying vec4 lmtexcoord;
varying vec4 color;
flat varying float exposure;
#ifdef LINES
flat varying int SELECTION_BOX;
@ -29,6 +35,10 @@ uniform int isEyeInWater;
uniform sampler2D texture;
uniform sampler2D noisetex;
uniform sampler2D colortex4;
#ifdef IS_LPV_ENABLED
uniform sampler3D texLpv1;
uniform sampler3D texLpv2;
#endif
uniform mat4 gbufferProjectionInverse;
@ -56,6 +66,14 @@ flat varying float HELD_ITEM_BRIGHTNESS;
#include "/lib/volumetricClouds.glsl"
#endif
#ifdef IS_LPV_ENABLED
uniform int frameCounter;
#include "/lib/hsv.glsl"
#include "/lib/lpv_common.glsl"
#include "/lib/lpv_render.glsl"
#endif
#include "/lib/diffuse_lighting.glsl"
#include "/lib/sky_gradient.glsl"
@ -100,6 +118,135 @@ float encodeVec2(float x,float y){
}
// #undef BASIC_SHADOW_FILTER
#ifdef OVERWORLD_SHADER
float ComputeShadowMap(inout vec3 directLightColor, vec3 playerPos, float maxDistFade){
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);
#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);
// get opaque shadow data to get opaque data from translucent shadows.
float opaqueShadow = shadow2D(shadowtex0, projectedShadowPosition).x;
shadowmap += max(opaqueShadow, shadowDepthDiff);
// 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 TRANSLUCENT_COLORED_SHADOWS
// tint the lightsource color with the translucent shadow color
directLightColor *= mix(vec3(1.0), translucentTint.rgb, maxDistFade);
#endif
return mix(1.0, shadowmap, maxDistFade);
}
#endif
#if defined DAMAGE_BLOCK_EFFECT && defined POM
#extension GL_ARB_shader_texture_lod : enable
mat3 inverseMatrix(mat3 m) {
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
float b01 = a22 * a11 - a12 * a21;
float b11 = -a22 * a10 + a12 * a20;
float b21 = a21 * a10 - a11 * a20;
float det = a00 * b01 + a01 * b11 + a02 * b21;
return mat3(b01, (-a22 * a01 + a02 * a21), (a12 * a01 - a02 * a11),
b11, (a22 * a00 - a02 * a20), (-a12 * a00 + a02 * a10),
b21, (-a21 * a00 + a01 * a20), (a11 * a00 - a01 * a10)) / det;
}
const float MAX_OCCLUSION_DISTANCE = MAX_DIST;
const float MIX_OCCLUSION_DISTANCE = MAX_DIST*0.9;
const int MAX_OCCLUSION_POINTS = MAX_ITERATIONS;
varying vec4 vtexcoordam; // .st for add, .pq for mul
varying vec4 vtexcoord;
vec2 dcdx = dFdx(vtexcoord.st*vtexcoordam.pq)*exp2(Texture_MipMap_Bias);
vec2 dcdy = dFdy(vtexcoord.st*vtexcoordam.pq)*exp2(Texture_MipMap_Bias);
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
uniform mat4 gbufferProjection;
vec3 toClipSpace3(vec3 viewSpacePosition) {
return projMAD(gbufferProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
}
flat varying vec3 WsunVec2;
const float mincoord = 1.0/4096.0;
const float maxcoord = 1.0-mincoord;
uniform sampler2D normals;
varying vec4 tangent;
varying vec4 normalMat;
vec4 readNormal(in vec2 coord)
{
return texture2DGradARB(normals,fract(coord)*vtexcoordam.pq+vtexcoordam.st,dcdx,dcdy);
}
vec4 readTexture(in vec2 coord)
{
return texture2DGradARB(texture,fract(coord)*vtexcoordam.pq+vtexcoordam.st,dcdx,dcdy);
}
#endif
uniform float near;
// uniform float far;
float ld(float dist) {
return (2.0 * near) / (far + near - dist * (far - near));
}
vec3 texture2D_POMSwitch(
sampler2D sampler,
vec2 lightmapCoord,
vec4 dcdxdcdy
){
return texture2DGradARB(sampler, lightmapCoord, dcdxdcdy.xy, dcdxdcdy.zw).rgb;
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
@ -114,6 +261,73 @@ float encodeVec2(float x,float y){
void main() {
#ifdef DAMAGE_BLOCK_EFFECT
vec2 adjustedTexCoord = lmtexcoord.xy;
#ifdef POM
vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize/RENDER_SCALE,1.0)-vec3(0.0));
vec3 worldpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz + cameraPosition;
vec3 normal = normalMat.xyz;
vec3 tangent2 = normalize(cross(tangent.rgb,normal)*tangent.w);
mat3 tbnMatrix = mat3(tangent.x, tangent2.x, normal.x,
tangent.y, tangent2.y, normal.y,
tangent.z, tangent2.z, normal.z);
adjustedTexCoord = fract(vtexcoord.st)*vtexcoordam.pq+vtexcoordam.st;
vec3 viewVector = normalize(tbnMatrix*fragpos);
float dist = length(fragpos);
float maxdist = MAX_OCCLUSION_DISTANCE;
// float depth = gl_FragCoord.z;
if (dist < maxdist) {
float depthmap = readNormal(vtexcoord.st).a;
float used_POM_DEPTH = 1.0;
if ( viewVector.z < 0.0 && depthmap < 0.9999 && depthmap > 0.00001) {
#ifdef Adaptive_Step_length
vec3 interval = (viewVector.xyz /-viewVector.z/MAX_OCCLUSION_POINTS * POM_DEPTH) * clamp(1.0-pow(depthmap,2),0.1,1.0);
used_POM_DEPTH = 1.0;
#else
vec3 interval = viewVector.xyz/-viewVector.z/ MAX_OCCLUSION_POINTS*POM_DEPTH;
#endif
vec3 coord = vec3(vtexcoord.st, 1.0);
coord += interval * used_POM_DEPTH;
float sumVec = 0.5;
for (int loopCount = 0; (loopCount < MAX_OCCLUSION_POINTS) && (1.0 - POM_DEPTH + POM_DEPTH * readNormal(coord.st).a ) < coord.p && coord.p >= 0.0; ++loopCount) {
coord = coord + interval * used_POM_DEPTH;
sumVec += used_POM_DEPTH;
}
if (coord.t < mincoord) {
if (readTexture(vec2(coord.s,mincoord)).a == 0.0) {
coord.t = mincoord;
discard;
}
}
adjustedTexCoord = mix(fract(coord.st)*vtexcoordam.pq+vtexcoordam.st, adjustedTexCoord, max(dist-MIX_OCCLUSION_DISTANCE,0.0)/(MAX_OCCLUSION_DISTANCE-MIX_OCCLUSION_DISTANCE));
// vec3 truePos = fragpos + sumVec*inverseMatrix(tbnMatrix)*interval;
// depth = toClipSpace3(truePos).z;
}
}
vec3 Albedo = toLinear(texture2D_POMSwitch(texture, adjustedTexCoord.xy, vec4(dcdx,dcdy)));
#else
vec3 Albedo = toLinear(texture2D(texture, adjustedTexCoord.xy).rgb);
#endif
gl_FragData[0] = vec4(encodeVec2(vec2(0.5)), encodeVec2(Albedo.rg), encodeVec2(vec2(Albedo.b,0.02)), 1.0);
#endif
#if !defined DAMAGE_BLOCK_EFFECT
#ifdef LINES
#ifndef SELECT_BOX
if(SELECTION_BOX > 0) discard;
@ -127,8 +341,9 @@ void main() {
vec4 TEXTURE = texture2D(texture, lmtexcoord.xy)*color;
#ifdef WhiteWorld
TEXTURE.rgb = vec3(0.5);
#endif
vec3 Albedo = toLinear(TEXTURE.rgb);
@ -142,104 +357,77 @@ void main() {
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));
#endif
#ifdef WEATHER
gl_FragData[1].a = TEXTURE.a; // for bloomy rain and stuff
#endif
#ifndef WEATHER
#ifndef LINES
gl_FragData[0].a = TEXTURE.a;
#else
gl_FragData[0].a = 1.0;
#endif
#ifndef BLOOMY_PARTICLES
gl_FragData[1].a = 0.0; // for bloomy rain and stuff
#endif
vec3 Direct_lighting = vec3(0.0);
vec3 Indirect_lighting = vec3(0.0);
vec3 MinimumLightColor = vec3(1.0);
if(isEyeInWater == 1) MinimumLightColor = vec3(10.0);
vec3 Torch_Color = vec3(TORCH_R,TORCH_G,TORCH_B);
if(lightmap.x >= 0.9) Torch_Color *= LIT_PARTICLE_BRIGHTNESS;
#ifdef OVERWORLD_SHADER
vec3 Shadows = vec3(1.0);
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
#ifdef DISTORT_SHADOWMAP
float distortFactor = calcDistort(projectedShadowPosition.xy);
projectedShadowPosition.xy *= distortFactor;
#else
float distortFactor = 1.0;
#endif
//do shadows only if on shadow map
if (abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution){
Shadows = vec3(0.0);
projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5);
#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
}
float cloudShadow = GetCloudShadow(feetPlayerPos);
Direct_lighting = (lightCol.rgb/80.0) * Shadows * cloudShadow;
#ifndef WEATHER
#ifndef LINES
Direct_lighting *= phaseg(clamp(dot(feetPlayerPos_normalized, WsunVec),0.0,1.0), 0.65)*2 + 0.5;
gl_FragData[0].a = TEXTURE.a;
#else
gl_FragData[0].a = 1.0;
#endif
#ifndef BLOOMY_PARTICLES
gl_FragData[1].a = 0.0; // for bloomy rain and stuff
#endif
vec3 AmbientLightColor = (averageSkyCol_Clouds / 30.0) * 3.0;
vec3 Direct_lighting = vec3(0.0);
vec3 directLightColor = vec3(0.0);
vec3 Indirect_lighting = vec3(0.0);
vec3 AmbientLightColor = vec3(0.0);
vec3 Torch_Color = vec3(TORCH_R,TORCH_G,TORCH_B);
vec3 MinimumLightColor = vec3(1.0);
if(isEyeInWater == 1) MinimumLightColor = vec3(10.0);
if(lightmap.x >= 0.9) Torch_Color *= LIT_PARTICLE_BRIGHTNESS;
#ifdef OVERWORLD_SHADER
directLightColor = lightCol.rgb/80.0;
float Shadows = 1.0;
vec3 shadowPlayerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
float shadowMapFalloff = smoothstep(0.0, 1.0, min(max(1.0 - length(shadowPlayerPos) / (shadowDistance+16),0.0)*5.0,1.0));
float shadowMapFalloff2 = smoothstep(0.0, 1.0, min(max(1.0 - length(shadowPlayerPos) / (shadowDistance+11),0.0)*5.0,1.0));
float LM_shadowMapFallback = min(max(lightmap.y-0.8, 0.0) * 25,1.0);
Shadows = ComputeShadowMap(directLightColor, shadowPlayerPos, shadowMapFalloff);
Shadows = mix(LM_shadowMapFallback, Shadows, shadowMapFalloff2);
float cloudShadow = GetCloudShadow(feetPlayerPos);
Direct_lighting = directLightColor * Shadows * cloudShadow;
#ifndef LINES
Direct_lighting *= phaseg(clamp(dot(feetPlayerPos_normalized, WsunVec),0.0,1.0), 0.65)*2 + 0.5;
#endif
AmbientLightColor = averageSkyCol_Clouds / 30.0;
AmbientLightColor *= 2.5;
#endif
#ifdef IS_LPV_ENABLED
vec3 lpvPos = GetLpvPosition(feetPlayerPos);
#else
const vec3 lpvPos = vec3(0.0);
#endif
Indirect_lighting = DoAmbientLightColor(lpvPos, AmbientLightColor, MinimumLightColor, Torch_Color, clamp(lightmap.xy,0,1), exposure);
#ifdef LINES
gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * toLinear(color.rgb);
#else
gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * Albedo;
#endif
// 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);
gl_FragData[0].rgb *= 0.1;
#endif
#ifdef NETHER_SHADER
// vec3 AmbientLightColor = skyCloudsFromTexLOD2(vec3( 0, 1, 0), colortex4, 6).rgb / 15;
vec3 AmbientLightColor = vec3(0.1);
#endif
#ifdef END_SHADER
vec3 AmbientLightColor = vec3(1.0);
#endif
Indirect_lighting = DoAmbientLightColor(AmbientLightColor,MinimumLightColor, Torch_Color, clamp(lightmap.xy,0,1));
#ifdef LINES
gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * toLinear(color.rgb);
#else
gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * Albedo;
#endif
#ifdef DAMAGE_BLOCK_EFFECT
gl_FragData[0] = vec4(0.0, encodeVec2(TEXTURE.rg), encodeVec2(vec2(TEXTURE.b,0.0)), TEXTURE.a);
#endif
// 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
}

View File

@ -1,5 +1,6 @@
#include "/lib/settings.glsl"
#include "/lib/res_params.glsl"
#include "/lib/items.glsl"
/*
!! DO NOT REMOVE !!
@ -10,6 +11,9 @@ Read the terms of modification and sharing before changing something below pleas
varying vec4 lmtexcoord;
varying vec4 color;
uniform sampler2D colortex4;
flat varying float exposure;
#ifdef LINES
flat varying int SELECTION_BOX;
@ -19,11 +23,9 @@ varying vec4 color;
flat varying vec3 averageSkyCol_Clouds;
flat varying vec4 lightCol;
flat varying vec3 WsunVec;
uniform sampler2D colortex4;
#endif
uniform vec3 sunPosition;
uniform float sunElevation;
@ -52,7 +54,22 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
vec4 toClipSpace3(vec3 viewSpacePosition) {
return vec4(projMAD(gl_ProjectionMatrix, viewSpacePosition),-viewSpacePosition.z);
}
}
#ifdef DAMAGE_BLOCK_EFFECT
varying vec4 vtexcoordam; // .st for add, .pq for mul
varying vec4 vtexcoord;
attribute vec4 mc_midTexCoord;
varying vec4 tangent;
attribute vec4 at_tangent;
varying vec4 normalMat;
flat varying vec3 WsunVec2;
#endif
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
@ -61,15 +78,30 @@ vec4 toClipSpace3(vec3 viewSpacePosition) {
void main() {
#ifdef DAMAGE_BLOCK_EFFECT
WsunVec2 = (float(sunElevation > 1e-5)*2.0 - 1.0)*normalize(mat3(gbufferModelViewInverse) * sunPosition);
#endif
lmtexcoord.xy = (gl_MultiTexCoord0).xy;
vec2 lmcoord = gl_MultiTexCoord1.xy / 240.0; // is this even correct? lol'
lmtexcoord.zw = lmcoord;
#ifdef DAMAGE_BLOCK_EFFECT
vec2 midcoord = (gl_TextureMatrix[0] * mc_midTexCoord).st;
vec2 texcoordminusmid = lmtexcoord.xy-midcoord;
vtexcoordam.pq = abs(texcoordminusmid)*2;
vtexcoordam.st = min(lmtexcoord.xy,midcoord-texcoordminusmid);
vtexcoord.xy = sign(texcoordminusmid)*0.5+0.5;
tangent = vec4(normalize(gl_NormalMatrix * at_tangent.rgb), at_tangent.w);
normalMat = vec4(normalize(gl_NormalMatrix * gl_Normal), 1.0);
#endif
HELD_ITEM_BRIGHTNESS = 0.0;
#ifdef Hand_Held_lights
if(heldItemId == 100 || heldItemId2 == 100) HELD_ITEM_BRIGHTNESS = 0.9;
if(heldItemId == ITEM_LIGHT_SOURCES || heldItemId2 == ITEM_LIGHT_SOURCES) HELD_ITEM_BRIGHTNESS = 0.9;
#endif
@ -94,6 +126,8 @@ void main() {
color = gl_Color;
exposure = texelFetch2D(colortex4,ivec2(10,37),0).r;
// color.rgb = worldpos;
#ifdef LINES
@ -110,6 +144,7 @@ void main() {
WsunVec = lightCol.a * normalize(mat3(gbufferModelViewInverse) * sunPosition);
#endif
#ifndef WEATHER
#ifdef TAA_UPSCALING
gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w;

View File

@ -280,12 +280,10 @@ vec4 texture2D_POMSwitch(
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
varying vec3 pos;
#ifdef HAND
/* RENDERTARGETS: 1,7,8,15,2 */
#if defined HAND || defined ENTITIES
/* RENDERTARGETS:1,7,8,15,2 */
#else
/* RENDERTARGETS: 1,7,8,15 */
/* RENDERTARGETS:1,7,8,15 */
#endif
void main() {
@ -312,19 +310,9 @@ void main() {
vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0));
vec3 worldpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz + cameraPosition;
// #if defined DH_OVERDRAW_PREVENTION && defined DISTANT_HORIZONS
// // overdraw prevention
// if(clamp(1.0-length(pos.xyz)/max(far - 16.0 * sqrt(interleaved_gradientNoise_temporal()),0.0),0.0,1.0) <= 0.0 ){
// discard;
// return;
// }
// #endif
float torchlightmap = lmtexcoord.z;
#ifdef Hand_Held_lights
if(HELD_ITEM_BRIGHTNESS > 0.0) torchlightmap = max(torchlightmap, HELD_ITEM_BRIGHTNESS * clamp( pow(max(1.0-length(fragpos)/HANDHELD_LIGHT_RANGE,0.0),1.5),0.0,1.0));
#ifdef HAND
@ -365,7 +353,7 @@ void main() {
float used_POM_DEPTH = 1.0;
if ( viewVector.z < 0.0 && depthmap < 0.9999 && depthmap > 0.00001) {
float noise = blueNoise();
// float noise = blueNoise();
#ifdef Adaptive_Step_length
vec3 interval = (viewVector.xyz /-viewVector.z/MAX_OCCLUSION_POINTS * POM_DEPTH) * clamp(1.0-pow(depthmap,2),0.1,1.0);
used_POM_DEPTH = 1.0;
@ -374,9 +362,9 @@ void main() {
#endif
vec3 coord = vec3(vtexcoord.st , 1.0);
coord += interval * noise * used_POM_DEPTH;
coord += interval * used_POM_DEPTH;
float sumVec = noise;
float sumVec = 0.5;
for (int loopCount = 0; (loopCount < MAX_OCCLUSION_POINTS) && (1.0 - POM_DEPTH + POM_DEPTH * readNormal(coord.st).a ) < coord.p && coord.p >= 0.0; ++loopCount) {
coord = coord + interval * used_POM_DEPTH;
sumVec += used_POM_DEPTH;
@ -392,13 +380,11 @@ void main() {
adjustedTexCoord = mix(fract(coord.st)*vtexcoordam.pq+vtexcoordam.st, adjustedTexCoord, max(dist-MIX_OCCLUSION_DISTANCE,0.0)/(MAX_OCCLUSION_DISTANCE-MIX_OCCLUSION_DISTANCE));
vec3 truePos = fragpos + sumVec*inverseMatrix(tbnMatrix)*interval;
// #ifdef Depth_Write_POM
gl_FragDepth = toClipSpace3(truePos).z;
// #endif
gl_FragDepth = toClipSpace3(truePos).z;
}
}
#endif
if(!ifPOM) adjustedTexCoord = lmtexcoord.xy;
@ -408,7 +394,6 @@ void main() {
float textureLOD = bias();
vec4 Albedo = texture2D_POMSwitch(texture, adjustedTexCoord.xy, vec4(dcdx,dcdy), ifPOM, textureLOD) * color;
#if defined HAND
if (Albedo.a < 0.1) discard;
#endif
@ -427,22 +412,26 @@ void main() {
#ifdef AEROCHROME_MODE
float gray = dot(Albedo.rgb, vec3(0.2, 1.0, 0.07));
if(blockID == 10001 || blockID == 10003 || blockID == 10004 || blockID == 10006 || blockID == 10009) {
// IR Reflective (Pink-red)
if (
blockID == BLOCK_AMETHYST_BUD_MEDIUM || blockID == BLOCK_AMETHYST_BUD_LARGE || blockID == BLOCK_AMETHYST_CLUSTER ||
blockID == BLOCK_SSS_STRONG || blockID == BLOCK_SSS_WEAK ||
blockID >= 10 && blockId < 80
) {
// IR Reflective (Pink-red)
Albedo.rgb = mix(vec3(gray), aerochrome_color, 0.7);
}
else if(blockID == 10008) {
else if(blockID == BLOCK_GRASS) {
// Special handling for grass block
float strength = 1.0 - color.b;
Albedo.rgb = mix(Albedo.rgb, aerochrome_color, strength);
}
#ifdef AEROCHROME_WOOL_ENABLED
else if(blockID == 200) {
else if(blockID == BLOCK_SSS_WEAK_2) {
// Wool
Albedo.rgb = mix(Albedo.rgb, aerochrome_color, 0.3);
}
#endif
else if(blockID == 8 || blockID == 10002)
else if(blockID == BLOCK_WATER || (blockID >= 300 && blockID < 400))
{
// IR Absorbsive? Dark.
Albedo.rgb = mix(Albedo.rgb, vec3(0.01, 0.08, 0.15), 0.5);
@ -458,10 +447,14 @@ void main() {
if (Albedo.a > 0.1){
Albedo.a = 0.75;
gl_FragData[4].a = 0.0;
} else Albedo.a = 1.0;
} else {
Albedo.a = 1.0;
}
#endif
#ifdef ENTITIES
gl_FragData[4].a = 0.0;
#endif
//////////////////////////////// ////////////////////////////////
//////////////////////////////// NORMAL ////////////////////////////////
@ -479,15 +472,14 @@ void main() {
NormalTex.xy = NormalTex.xy * 2.0-1.0;
NormalTex.z = sqrt(max(1.0 - dot(NormalTex.xy, NormalTex.xy), 0.0));
#if defined HEIGTHMAP_DEPTH_OFFSET && !defined HAND
gl_FragDepth = gl_FragCoord.z;
vec3 truePos = fragpos;
truePos.z -= Heightmap * POM_DEPTH * (1.0 + ld(truePos.z));
// #if defined HEIGTHMAP_DEPTH_OFFSET && !defined HAND
// gl_FragDepth = gl_FragCoord.z;
// vec3 truePos = fragpos;
// truePos.z -= Heightmap * POM_DEPTH * (1.0 + ld(truePos.z));
gl_FragDepth = toClipSpace3(truePos).z;
#endif
// gl_FragDepth = toClipSpace3(truePos).z;
// #endif
normal = applyBump(tbnMatrix, NormalTex.xyz, mix(1.0,1-Puddle_shape,rainfall) );
// normal = applyBump(tbnMatrix, NormalTex.xyz, 0.0);
#endif
@ -568,10 +560,6 @@ void main() {
// apply noise to lightmaps to reduce banding.
vec2 PackLightmaps = vec2(torchlightmap, lmtexcoord.w);
#if !defined ENTITIES && !defined HAND
// PackLightmaps = clamp(PackLightmaps*blueNoise()*0.05 + PackLightmaps,0.0,1.0);
#endif
vec4 data1 = clamp( encode(viewToWorld(normal), PackLightmaps), 0.0, 1.0);
// gl_FragData[0] = vec4(.0);
gl_FragData[0] = vec4(encodeVec2(Albedo.x,data1.x), encodeVec2(Albedo.y,data1.y), encodeVec2(Albedo.z,data1.z), encodeVec2(data1.w,Albedo.w));

View File

@ -2,6 +2,9 @@
#include "/lib/settings.glsl"
#include "/lib/res_params.glsl"
#include "/lib/bokeh.glsl"
#include "/lib/blocks.glsl"
#include "/lib/entities.glsl"
#include "/lib/items.glsl"
/*
!! DO NOT REMOVE !!
@ -182,26 +185,18 @@ float luma(vec3 color) {
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
varying vec3 pos;
void main() {
gl_Position = ftransform();
vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
pos = position;
/////// ----- COLOR STUFF ----- ///////
color = gl_Color;
VanillaAO = 1.0 - clamp(color.a,0,1);
if (color.a < 0.3) color.a = 1.0; // fix vanilla ao on some custom block models.
/////// ----- RANDOM STUFF ----- ///////
// gl_TextureMatrix[0] for animated things like charged creepers
lmtexcoord.xy = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
@ -214,7 +209,8 @@ void main() {
vtexcoord.xy = sign(texcoordminusmid)*0.5+0.5;
// #endif
vec2 lmcoord = gl_MultiTexCoord1.xy / 255.0; // is this even correct? lol'
vec2 lmcoord = gl_MultiTexCoord1.xy / 240.0;
lmtexcoord.zw = lmcoord;
@ -229,17 +225,16 @@ void main() {
blockID = mc_Entity.x;
// velocity = at_velocity;
if(mc_Entity.x == 10009) normalMat.a = 0.60;
if(mc_Entity.x == BLOCK_GROUND_WAVING_VERTICAL || mc_Entity.x == BLOCK_GRASS_SHORT) normalMat.a = 0.60;
PORTAL = 0;
SIGN = 0;
#ifdef WORLD
// disallow POM to work on signs.
if(blockEntityId == 2200) SIGN = 1;
if(blockEntityId == BLOCK_SIGN) SIGN = 1;
if(blockEntityId == 2100) PORTAL = 1;
if(blockEntityId == BLOCK_END_PORTAL) PORTAL = 1;
#endif
NameTags = 0;
@ -247,71 +242,79 @@ void main() {
#ifdef ENTITIES
// disallow POM to work on item frames.
if(entityId == 2300) SIGN = 1;
if(entityId == ENTITY_ITEM_FRAME) SIGN = 1;
// try and single out nametag text and then discard nametag background
// if( dot(gl_Color.rgb, vec3(1.0/3.0)) < 1.0) NameTags = 1;
// if(gl_Color.a < 1.0) NameTags = 1;
// if(gl_Color.a >= 0.24 && gl_Color.a <= 0.25 ) gl_Position = vec4(10,10,10,1);
if(entityId == 1100 || entityId == 1200 || entityId == 2468) normalMat.a = 0.45;
if(entityId == ENTITY_SSS_MEDIUM || entityId == ENTITY_SSS_WEAK || entityId == ENTITY_PLAYER || entityId == 2468) normalMat.a = 0.45;
#endif
if(mc_Entity.x == 10003) normalMat.a = 0.55;
if(mc_Entity.x == BLOCK_AIR_WAVING) normalMat.a = 0.55;
/////// ----- EMISSIVE STUFF ----- ///////
EMISSIVE = 0.0;
LIGHTNING = 0;
EMISSIVE = 0.0;
LIGHTNING = 0;
// if(NameTags > 0) EMISSIVE = 0.9;
// normal block lightsources
if(mc_Entity.x == 10005) EMISSIVE = 0.5;
if(mc_Entity.x >= 100 && mc_Entity.x < 300) EMISSIVE = 0.5;
// special cases light lightning and beacon beams...
#ifdef ENTITIES
if(entityId == 12345){
if(entityId == ENTITY_LIGHTNING){
LIGHTNING = 1;
normalMat.a = 0.50;
}
#endif
/////// ----- SSS STUFF ----- ///////
SSSAMOUNT = 0.0;
SSSAMOUNT = 0.0;
HELD_ITEM_BRIGHTNESS = 0.0;
#ifdef Hand_Held_lights
if(heldItemId == 100 || heldItemId2 == 100) HELD_ITEM_BRIGHTNESS = 0.9;
if(heldItemId == ITEM_LIGHT_SOURCES || heldItemId2 == ITEM_LIGHT_SOURCES) HELD_ITEM_BRIGHTNESS = 0.9;
#endif
#ifdef WORLD
/////// ----- SSS ON BLOCKS ----- ///////
// strong
if(mc_Entity.x == 10001 || mc_Entity.x == 10003 || mc_Entity.x == 10004 || mc_Entity.x == 10009) SSSAMOUNT = 1.0;
if (
mc_Entity.x == BLOCK_GROUND_WAVING || mc_Entity.x == BLOCK_GROUND_WAVING_VERTICAL || mc_Entity.x == BLOCK_AIR_WAVING ||
mc_Entity.x == BLOCK_GRASS_SHORT || mc_Entity.x == BLOCK_GRASS_TALL_UPPER || mc_Entity.x == BLOCK_GRASS_TALL_LOWER ||
mc_Entity.x == BLOCK_SSS_STRONG || mc_Entity.x == BLOCK_SAPLING
) {
SSSAMOUNT = 1.0;
}
// medium
if(mc_Entity.x == 10006 || mc_Entity.x == 200) SSSAMOUNT = 0.75;
if (
mc_Entity.x == BLOCK_SSS_WEAK || mc_Entity.x == BLOCK_SSS_WEAK_2 ||
mc_Entity.x == BLOCK_AMETHYST_BUD_MEDIUM || mc_Entity.x == BLOCK_AMETHYST_BUD_LARGE || mc_Entity.x == BLOCK_AMETHYST_CLUSTER ||
mc_Entity.x == BLOCK_BAMBOO || mc_Entity.x == BLOCK_SAPLING || mc_Entity.x == BLOCK_VINE
) {
SSSAMOUNT = 0.75;
}
// low
#ifdef MISC_BLOCK_SSS
if(mc_Entity.x == 10007 || mc_Entity.x == 10008) SSSAMOUNT = 0.5; // weird SSS on blocks like grass and stuff
if(mc_Entity.x == BLOCK_SSS_WEIRD || mc_Entity.x == BLOCK_GRASS) SSSAMOUNT = 0.5; // weird SSS on blocks like grass and stuff
#endif
#ifdef ENTITIES
#ifdef MOB_SSS
/////// ----- SSS ON MOBS----- ///////
// strong
if(entityId == 1100) SSSAMOUNT = 0.75;
if(entityId == ENTITY_SSS_MEDIUM) SSSAMOUNT = 0.75;
// medium
// low
if(entityId == 1200) SSSAMOUNT = 0.3;
if(entityId == ENTITY_SSS_WEAK || entityId == ENTITY_PLAYER) SSSAMOUNT = 0.3;
#endif
#endif
@ -320,7 +323,7 @@ void main() {
// strong
// medium
if(blockEntityId == 10010) SSSAMOUNT = 0.4;
if(blockEntityId == BLOCK_SSS_WEAK_3) SSSAMOUNT = 0.4;
// low
@ -330,21 +333,25 @@ void main() {
#ifdef WAVY_PLANTS
bool istopv = gl_MultiTexCoord0.t < mc_midTexCoord.t;
if ((mc_Entity.x == 10001 || mc_Entity.x == 10009) && istopv && abs(position.z) < 64.0) {
vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz + cameraPosition;
if (
(
mc_Entity.x == BLOCK_GROUND_WAVING || mc_Entity.x == BLOCK_GROUND_WAVING_VERTICAL ||
mc_Entity.x == BLOCK_GRASS_SHORT || mc_Entity.x == BLOCK_GRASS_TALL_UPPER ||
mc_Entity.x == BLOCK_SAPLING
) && istopv && abs(position.z) < 64.0
) {
vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz + cameraPosition;
worldpos.xyz += calcMovePlants(worldpos.xyz)*lmtexcoord.w - cameraPosition;
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
}
if (mc_Entity.x == 10003 && abs(position.z) < 64.0) {
if (mc_Entity.x == BLOCK_AIR_WAVING && abs(position.z) < 64.0) {
vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz + cameraPosition;
worldpos.xyz += calcMoveLeaves(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))*lmtexcoord.w - cameraPosition;
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
}
#endif
gl_Position = toClipSpace3(position);
#endif
#if defined Seasons && defined WORLD && !defined ENTITIES && !defined BLOCKENTITIES && !defined HAND

View File

@ -1,8 +1,14 @@
#include "/lib/settings.glsl"
#ifdef IS_LPV_ENABLED
#extension GL_EXT_shader_image_load_store: enable
#endif
#include "/lib/res_params.glsl"
varying vec4 lmtexcoord;
varying vec4 color;
uniform vec4 entityColor;
#ifdef OVERWORLD_SHADER
const bool shadowHardwareFiltering = true;
@ -21,14 +27,7 @@ varying vec4 color;
flat varying vec4 lightCol;
#endif
#ifdef BLOCKENTITIES
#undef WATER_REFLECTIONS
#endif
#ifdef ENTITIES
#undef WATER_BACKGROUND_SPECULAR
#undef SCREENSPACE_REFLECTIONS
#endif
flat varying float HELD_ITEM_BRIGHTNESS;
@ -36,21 +35,31 @@ const bool colortex4MipmapEnabled = true;
uniform sampler2D noisetex;
uniform sampler2D depthtex1;
uniform sampler2D depthtex0;
#ifdef DISTANT_HORIZONS
uniform sampler2D dhDepthTex1;
#endif
uniform sampler2D colortex7;
uniform sampler2D colortex12;
uniform sampler2D colortex14;
uniform sampler2D colortex5;
uniform sampler2D colortex6;
uniform sampler2D texture;
uniform sampler2D specular;
uniform sampler2D normals;
#ifdef IS_LPV_ENABLED
uniform sampler3D texLpv1;
uniform sampler3D texLpv2;
#endif
varying vec4 tangent;
varying vec4 normalMat;
varying vec3 binormal;
varying vec3 flatnormal;
flat varying float exposure;
uniform vec3 sunVec;
@ -97,27 +106,29 @@ uniform vec3 nsunColor;
#include "/lib/end_fog.glsl"
#endif
#include "/lib/diffuse_lighting.glsl"
#ifdef IS_LPV_ENABLED
#include "/lib/hsv.glsl"
#include "/lib/lpv_common.glsl"
#include "/lib/lpv_render.glsl"
#endif
#include "/lib/diffuse_lighting.glsl"
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
float R2_dither(){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter) ;
float interleaved_gradientNoise_temporal(){
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+frameTimeCounter*51.9521);
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy + (frameCounter%40000);
// vec2 coord = gl_FragCoord.xy + frameTimeCounter;
// vec2 coord = gl_FragCoord.xy;
float noise = fract( 52.9829189 * fract( (coord.x * 0.06711056) + (coord.y * 0.00583715)) );
return noise ;
}
float interleaved_gradientNoise(float temporal){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)+temporal);
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
float R2_dither(){
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
}
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
@ -134,35 +145,26 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
#define PW_DEPTH 1.0 //[0.5 1.0 1.5 2.0 2.5 3.0]
#define PW_POINTS 1 //[2 4 6 8 16 32]
#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]
varying vec3 viewVector;
vec3 getParallaxDisplacement(vec3 posxz) {
vec3 parallaxPos = posxz;
vec2 vec = viewVector.xy * (1.0 / float(PW_POINTS)) * 22.0;
float waterHeight = getWaterHeightmap(posxz.xz);
parallaxPos.xz += waterHeight * vec;
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;
return parallaxPos;
}
// vec3 getParallaxDisplacement(vec3 posxz,float bumpmult,vec3 viewVec) {
// vec3 parallaxPos = posxz;
// vec2 vec = viewVector.xy * (1.0 / float(PW_POINTS)) * 22.0 * PW_DEPTH;
// float waterHeight = getWaterHeightmap(posxz.xz) ;
// parallaxPos.xz += waterHeight * vec;
// return parallaxPos;
// }
vec3 applyBump(mat3 tbnMatrix, vec3 bump, float puddle_values){
float bumpmult = 1;
float bumpmult = puddle_values;
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
//
return normalize(bump*tbnMatrix);
}
@ -259,12 +261,8 @@ vec3 rayTrace(vec3 dir, vec3 position,float dither, float fresnel, bool inwater)
// decode depth buffer
// float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0);
#ifdef HAND
vec2 testthing = spos.xy*texelSize; // fix for ssr on hand
#else
vec2 testthing = spos.xy/texelSize/4.0;
#endif
float sp = sqrt((texelFetch2D(colortex4,ivec2(testthing),0).a)/65000.0);
float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4.0),0).a/65000.0);
sp = invLinZ(sp);
if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ)) return vec3(spos.xy/RENDER_SCALE,sp);
@ -283,8 +281,8 @@ vec3 rayTrace(vec3 dir, vec3 position,float dither, float fresnel, bool inwater)
return vec3(1.1);
}
vec3 GGX (vec3 n, vec3 v, vec3 l, float r, vec3 F0) {
r = pow(r,2.5);
float GGX(vec3 n, vec3 v, vec3 l, float r, float f0) {
r = max(pow(r,2.5), 0.0001);
vec3 h = l + v;
float hn = inversesqrt(dot(h, h));
@ -294,94 +292,202 @@ vec3 GGX (vec3 n, vec3 v, vec3 l, float r, vec3 F0) {
float dotNL = clamp(dot(n,l),0.,1.);
float dotNHsq = dotNH*dotNH;
float denom = dotNHsq * r - dotNHsq + 1.0;
float denom = dotNHsq * r - dotNHsq + 1.;
float D = r / (3.141592653589793 * denom * denom);
vec3 F = 0.2 + (1. - F0) * exp2((-5.55473*dotLH-6.98316)*dotLH);
float F = f0 + (1. - f0) * exp2((-5.55473*dotLH-6.98316)*dotLH);
float k2 = .25 * r;
return dotNL * D * F / (dotLH*dotLH*(1.0-k2)+k2);
}
uniform float dhFarPlane;
#include "/lib/DistantHorizons_projections.glsl"
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
float darkSpecularHighlight(vec3 playerPos, vec3 normal, float roughness, float f0){
roughness = max(pow(1.0 - roughness, 2.0),0.002);
float distanceFalloff = clamp( exp(-7.0 * (length(playerPos) / 16.0)) ,0.0,1.0);
float NdotP = clamp(1.0 + dot(normal, normalize(playerPos)),0.0,1.0);
// #undef BASIC_SHADOW_FILTER
float specularHighlight = exp( -(1.0 / roughness) * NdotP ) * f0;
#ifdef OVERWORLD_SHADER
float ComputeShadowMap(inout vec3 directLightColor, vec3 playerPos, float maxDistFade, float noise){
return specularHighlight * distanceFalloff;
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++){
vec2 offsetS = tapLocation_simple(i, 7, 9, noise) *0.5;
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);
// get opaque shadow data to get opaque data from translucent shadows.
float opaqueShadow = shadow2D(shadowtex0, projectedShadowPosition).x;
shadowmap += max(opaqueShadow, shadowDepthDiff);
// 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;
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
uniform vec4 entityColor;
/* RENDERTARGETS:2,7,11,14 */
void main() {
if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 ) {
vec3 FragCoord = gl_FragCoord.xyz;
#ifdef HAND
convertHandDepth(FragCoord.z);
#endif
vec2 tempOffset = offsets[framemod8];
vec3 viewPos = toScreenSpace(FragCoord*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5, 0.0));
vec3 feetPlayerPos = mat3(gbufferModelViewInverse) * viewPos;
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 + gbufferModelViewInverse[3].xyz;
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// MATERIAL MASKS ////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
float MATERIALS = normalMat.w;
////////////////////////////////
//////////////////////////////// ALBEDO
////////////////////////////////
// 1.0 = water mask
// 0.9 = entity mask
// 0.8 = reflective entities
// 0.7 = reflective blocks
// 0.1 = hand mask
#ifdef HAND
MATERIALS = 0.1;
#endif
// 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;
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// ALBEDO /////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
gl_FragData[0] = texture2D(texture, lmtexcoord.xy, Texture_MipMap_Bias) * color;
vec3 Albedo = toLinear(gl_FragData[0].rgb);
float UnchangedAlpha = gl_FragData[0].a;
float iswater = normalMat.w;
#ifdef HAND
iswater = 0.1;
#ifdef WhiteWorld
gl_FragData[0].rgb = vec3(0.5);
gl_FragData[0].a = 1.0;
#endif
#ifdef Vanilla_like_water
if (iswater > 0.95){
Albedo *= sqrt(luma(Albedo));
// Albedo = toLinear( gl_FragData[0].rgb * sqrt(luma(gl_FragData[0].rgb)));
}
#else
if (iswater > 0.95){
Albedo = vec3(0.0);
gl_FragData[0].a = 1.0/255.0;
}
vec3 Albedo = toLinear(gl_FragData[0].rgb);
#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
#endif
#ifdef ENTITIES
Albedo.rgb = mix(Albedo.rgb, entityColor.rgb, clamp(entityColor.a*1.5,0,1));
#endif
vec4 COLORTEST = vec4(Albedo, UnchangedAlpha);
vec4 GLASS_TINT_COLORS = vec4(Albedo, UnchangedAlpha);
#ifdef BIOME_TINT_WATER
if (iswater > 0.95) COLORTEST.rgb = color.rgb;
if (isWater) GLASS_TINT_COLORS.rgb = toLinear(color.rgb);
#endif
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// NORMALS ///////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////
//////////////////////////////// NORMAL
////////////////////////////////
vec3 normal = normalMat.xyz;
vec3 normal = normalMat.xyz; // in viewSpace
vec3 worldSpaceNormal = viewToWorld(normal).xyz;
vec2 TangentNormal = vec2(0); // for refractions
vec3 tangent2 = normalize(cross(tangent.rgb,normal)*tangent.w);
@ -389,40 +495,44 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
tangent.y, tangent2.y, normal.y,
tangent.z, tangent2.z, normal.z);
vec4 NormalTex = texture2D(normals, lmtexcoord.xy, Texture_MipMap_Bias).rgba;
vec3 NormalTex = vec3(texture2D(normals, lmtexcoord.xy, Texture_MipMap_Bias).xy,0.0);
NormalTex.xy = NormalTex.xy*2.0-1.0;
NormalTex.z = clamp(sqrt(1.0 - dot(NormalTex.xy, NormalTex.xy)),0.0,1.0) ;
// tangent space normals for refraction
TangentNormal = NormalTex.xy*0.5+0.5;
normal = applyBump(tbnMatrix, NormalTex.xyz, 1.0);
#ifndef HAND
if (iswater > 0.95){
vec3 posxz = feetPlayerPos + cameraPosition;
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.
if(abs(worldSpaceNormal.y) < 0.9995) posxz.xz -= (posxz.y + frameTimeCounter*3 * WATER_WAVE_SPEED) * normalize(worldSpaceNormal.xz) ;
float bumpmult = 1.0;
posxz.xyz = getParallaxDisplacement(posxz) ;
posxz.xyz = getParallaxDisplacement(posxz);
vec3 bump = normalize(getWaveNormal(posxz, false));
TangentNormal = (bump.xy/3.0)*0.5+0.5; // tangent space normals for refraction
float bumpmult = 10.0 * WATER_WAVE_STRENGTH;
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
normal = normalize(bump * tbnMatrix);
NormalTex.xyz = bump;
// tangent space normals for refraction
TangentNormal = (bump.xy/3.0)*0.5+0.5;
}
#endif
gl_FragData[2] = vec4(encodeVec2(TangentNormal), encodeVec2(COLORTEST.rg), encodeVec2(COLORTEST.ba), UnchangedAlpha);
normal = applyBump(tbnMatrix, NormalTex.xyz, 1.0);
vec3 WS_normal = viewToWorld(normal);
////////////////////////////////
//////////////////////////////// DIFFUSE LIGHTING
////////////////////////////////
gl_FragData[2] = vec4(encodeVec2(TangentNormal), encodeVec2(GLASS_TINT_COLORS.rg), encodeVec2(GLASS_TINT_COLORS.ba), 1.0);
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// DIFFUSE LIGHTING //////////////////////////////
////////////////////////////////////////////////////////////////////////////////
vec2 lightmap = lmtexcoord.zw;
// lightmap.y = 1.0;
#ifndef OVERWORLD_SHADER
lightmap.y = 1.0;
@ -435,127 +545,62 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
vec3 Indirect_lighting = vec3(0.0);
vec3 MinimumLightColor = vec3(1.0);
if(isEyeInWater == 1) MinimumLightColor = vec3(10.0);
vec3 Direct_lighting = vec3(0.0);
#ifdef OVERWORLD_SHADER
vec3 DirectLightColor = lightCol.rgb/80.0;
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);
vec3 Shadows = vec3(0.0);
bool inShadowmapBounds = false;
float Shadows = 1.0;
vec3 feetPlayerPos_shadow = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
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));
// mat4 Custom_ViewMatrix = BuildShadowViewMatrix(LightDir);
// vec3 projectedShadowPosition = mat3(Custom_ViewMatrix) * feetPlayerPos_shadow + Custom_ViewMatrix[3].xyz;
vec3 projectedShadowPosition = mat3(shadowModelView) * feetPlayerPos_shadow + shadowModelView[3].xyz;
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
float LM_shadowMapFallback = min(max(lightmap.y-0.8, 0.0) * 25,1.0);
//apply distortion
#ifdef DISTORT_SHADOWMAP
float distortFactor = calcDistort(projectedShadowPosition.xy);
projectedShadowPosition.xy *= distortFactor;
#else
float distortFactor = 1.0;
#endif
bool ShadowBounds = false;
if(shadowDistanceRenderMul > 0.0) ShadowBounds = length(feetPlayerPos_shadow) < max(shadowDistance - 20,0.0);
if(shadowDistanceRenderMul < 0.0) ShadowBounds = abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.z) < 6.0;
vec3 shadowPlayerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
// sample shadows only if on shadow map
if(ShadowBounds){
if (NdotL > 0.0){
Shadows = vec3(0.0);
projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5);
Shadows = ComputeShadowMap(DirectLightColor, shadowPlayerPos, shadowMapFalloff, blueNoise());
#ifndef HAND
#ifdef BASIC_SHADOW_FILTER
const float threshMul = max(2048.0/shadowMapResolution*shadowDistance/128.0,0.95);
float distortThresh = (sqrt(1.0-NdotL*NdotL)/NdotL+0.7)/distortFactor;
float diffthresh = distortThresh/6000.0*threshMul;
Shadows = mix(LM_shadowMapFallback, Shadows, shadowMapFalloff2);
float rdMul = 4.0/shadowMapResolution;
float noise = blueNoise();
Shadows *= pow(GetCloudShadow(feetPlayerPos),3);
int SampleCount = 7;
for(int i = 0; i < SampleCount; i++){
vec2 offsetS = tapLocation_simple(i, 7, 9, noise) * 0.5;
float weight = 1.0+(i+noise)*rdMul/9.0*shadowMapResolution;
#ifdef TRANSLUCENT_COLORED_SHADOWS
vec3 shadowProjOffsets = projectedShadowPosition + vec3(rdMul*offsetS, -diffthresh*weight);
float opaqueShadow = shadow2D(shadowtex0, shadowProjOffsets).x;
Shadows += vec3(opaqueShadow/SampleCount);
if(shadow2D(shadowtex1, shadowProjOffsets).x > shadowProjOffsets.z){
vec4 translucentShadow = texture2D(shadowcolor0, shadowProjOffsets.xy);
if(translucentShadow.a < 0.9) Shadows += (normalize(translucentShadow.rgb+0.0001) * clamp(1.0-opaqueShadow,0.0,1.0)) / SampleCount;
}
#else
Shadows += vec3(shadow2D(shadow, projectedShadowPosition + vec3(rdMul*offsetS, -diffthresh*weight)).x / SampleCount);
#endif
}
#else
#ifdef TRANSLUCENT_COLORED_SHADOWS
projectedShadowPosition -= vec3(0.0,0.0,0.0001);
Shadows = vec3(shadow2D(shadowtex0, projectedShadowPosition ).x);
if(shadow2D(shadowtex1, projectedShadowPosition).x > projectedShadowPosition.z){
vec4 shadowLightColor = texture2D(shadowcolor0, projectedShadowPosition.xy);
if(shadowLightColor.a < 0.9) Shadows += normalize(shadowLightColor.rgb+0.0001);
}
#else
Shadows = vec3(shadow2D(shadow, projectedShadowPosition - vec3(0.0,0.0,0.0001)).x);
#endif
#endif
#else
Shadows = vec3(shadow2D(shadow, projectedShadowPosition - vec3(0.0,0.0,0.0005)).x);
#endif
}
inShadowmapBounds = true;
}
if(!inShadowmapBounds) Shadows = vec3(1.0);
Shadows *= GetCloudShadow(feetPlayerPos);
Direct_lighting = (lightCol.rgb/80.0) * NdotL * Shadows;
Direct_lighting = DirectLightColor * NdotL * Shadows;
vec3 AmbientLightColor = averageSkyCol_Clouds/30.0;
vec3 ambientcoefs = WS_normal / dot(abs(WS_normal), vec3(1));
// vec3 ambientcoefs = slopednormal / dot(abs(slopednormal), vec3(1.0));
// float SkylightDir = ambientcoefs.y*1.5;
// if(isGrass) SkylightDir = 1.25;
// float skylight = max(pow(viewToWorld(FlatNormals).y*0.5+0.5,0.1) + SkylightDir, 0.2 + (1.0-lightmap.y)*0.8) ;
vec3 ambientcoefs = worldSpaceNormal / dot(abs(worldSpaceNormal), vec3(1.0));
float SkylightDir = ambientcoefs.y*1.5;
float skylight = max(pow(viewToWorld(flatnormal).y*0.5+0.5,0.1) + SkylightDir, 0.25);
float skylight = max(pow(viewToWorld(flatnormal).y*0.5+0.5,0.1) + SkylightDir, 0.2);
AmbientLightColor *= skylight;
#endif
#ifdef NETHER_SHADER
// vec3 AmbientLightColor = skyCloudsFromTexLOD2(WS_normal, colortex4, 6).rgb / 15.0;
// vec3 AmbientLightColor = skyCloudsFromTexLOD2(worldSpaceNormal, colortex4, 6).rgb / 15.0;
// vec3 up = skyCloudsFromTexLOD2(vec3( 0, 1, 0), colortex4, 6).rgb/ 30.0;
// vec3 down = skyCloudsFromTexLOD2(vec3( 0,-1, 0), colortex4, 6).rgb/ 30.0;
// up *= pow( max( WS_normal.y, 0), 2);
// down *= pow( max(-WS_normal.y, 0), 2);
// up *= pow( max( worldSpaceNormal.y, 0), 2);
// down *= pow( max(-worldSpaceNormal.y, 0), 2);
// AmbientLightColor += up + down;
vec3 AmbientLightColor = vec3(0.1);
#endif
#ifdef END_SHADER
float vortexBounds = clamp(vortexBoundRange - length(feetPlayerPos+cameraPosition), 0.0,1.0);
vec3 lightPos = LightSourcePosition(feetPlayerPos+cameraPosition, cameraPosition,vortexBounds);
@ -563,56 +608,91 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
float lightningflash = texelFetch2D(colortex4,ivec2(1,1),0).x/150.0;
vec3 lightColors = LightSourceColors(vortexBounds, lightningflash);
float NdotL = clamp(dot(WS_normal, normalize(-lightPos))*0.5+0.5,0.0,1.0);
float NdotL = clamp(dot(worldSpaceNormal, normalize(-lightPos))*0.5+0.5,0.0,1.0);
NdotL *= NdotL;
Direct_lighting = lightColors * endFogPhase(lightPos) * NdotL;
vec3 AmbientLightColor = vec3(0.5,0.75,1.0) * 0.9 + 0.1;
AmbientLightColor *= clamp(1.5 + dot(WS_normal, normalize(feetPlayerPos))*0.5,0,2);
#endif
Indirect_lighting = DoAmbientLightColor(AmbientLightColor, MinimumLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.xy);
#ifdef ENTITIES
Albedo.rgb = mix(Albedo.rgb, entityColor.rgb, clamp(entityColor.a*1.5,0,1));
AmbientLightColor *= clamp(1.5 + dot(worldSpaceNormal, normalize(feetPlayerPos))*0.5,0,2);
#endif
#ifdef IS_LPV_ENABLED
vec3 lpvPos = GetLpvPosition(feetPlayerPos);
#ifdef LPV_NORMAL_OFFSET
lpvPos += -0.5*worldSpaceNormal + viewToWorld(normal);
#else
lpvPos += 0.5*worldSpaceNormal;
#endif
#else
const vec3 lpvPos = vec3(0.0);
#endif
Indirect_lighting = DoAmbientLightColor(lpvPos, AmbientLightColor, MinimumLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.xy, exposure);
vec3 FinalColor = (Indirect_lighting + Direct_lighting) * Albedo;
// #ifdef Glass_Tint
// FinalColor *= min(pow(gl_FragData[0].a,2.0),1.0);
// #endif
////////////////////////////////
//////////////////////////////// SPECULAR
////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// SPECULAR LIGHTING /////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#ifdef DAMAGE_BLOCK_EFFECT
#undef WATER_REFLECTIONS
#endif
// #ifdef ENTITIES
// #undef WATER_BACKGROUND_SPECULAR
// #endif
#ifndef OVERWORLD_SHADER
#undef WATER_SUN_SPECULAR
#endif
#ifdef WATER_REFLECTIONS
vec2 SpecularTex = texture2D(specular, lmtexcoord.xy, Texture_MipMap_Bias).rg;
SpecularTex = (iswater > 0.0 && iswater < 0.9) && SpecularTex.r > 0.0 && SpecularTex.g < 0.9 ? SpecularTex : vec2(1.0,0.02);
float roughness = max(pow(1.0-SpecularTex.r,2.0),0.05);
float f0 = SpecularTex.g;
// if nothing is chosen, no smoothness and no reflectance
vec2 specularValues = vec2(1.0, 0.0);
// roughness = 0.1;
// f0 = 0.1;
// hardcode specular values for select blocks like glass, water, and slime
if(isReflective) specularValues = vec2(1.0, 0.02);
// detect if the specular texture is used, if it is, overwrite hardcoded values
if(SpecularTex.r > 0.0 && SpecularTex.g <= 1.0) specularValues = SpecularTex;
float roughness = pow(1.0-specularValues.r,2.0);
float f0 = isReflective ? max(specularValues.g, 0.02) : specularValues.g;
#ifdef HAND
f0 = max(specularValues.g, 0.02);
#endif
// specularValues = SpecularTex;
// f0 = 0.9;
// roughness = 0.0;
vec3 Metals = f0 > 229.5/255.0 ? normalize(Albedo+1e-7) * (dot(Albedo,vec3(0.21, 0.72, 0.07)) * 0.7 + 0.3) : vec3(1.0);
// make sure zero alpha is not forced to be full alpha by fresnel on items with funny normal padding
if(UnchangedAlpha <= 0.0 && !isReflective) f0 = 0.0;
if (f0 > 0.0){
if(isReflective) f0 = max(f0, 0.02);
if (iswater > 0.0 && gl_FragData[0].a < 0.9999999){
vec3 Reflections_Final = vec3(0.0);
vec4 Reflections = vec4(0.0);
vec3 SkyReflection = vec3(0.0);
vec3 BackgroundReflection = FinalColor;
vec3 SunReflection = vec3(0.0);
float indoors = clamp((lightmap.y-0.6)*5.0, 0.0,1.0);
vec3 reflectedVector = reflect(normalize(viewPos), normal);
float indoors = pow(1.0-pow(1.0-min(max(lightmap.y-0.6,0.0)*3.0,1.0),0.5),2.0);
vec3 reflectedVector = reflect(normalize(viewPos), normal);
float normalDotEye = dot(normal, normalize(viewPos));
float fresnel = pow(clamp(1.0 + normalDotEye, 0.0, 1.0),5.0);
#ifdef SNELLS_WINDOW
@ -622,90 +702,80 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
fresnel = mix(f0, 1.0, fresnel);
vec3 Metals = f0 > 229.5/255.0 ? normalize(Albedo+1e-7) * (dot(Albedo,vec3(0.21, 0.72, 0.07)) * 0.7 + 0.3) : vec3(1.0);
// Sun, Sky, and screen-space reflections
#ifdef OVERWORLD_SHADER
#ifdef WATER_SUN_SPECULAR
SunReflection = Direct_lighting * GGX(normal, -normalize(viewPos), WsunVec*mat3(gbufferModelViewInverse), roughness, vec3(f0)) ;
SunReflection = Direct_lighting * GGX(normal, -normalize(viewPos), WsunVec*mat3(gbufferModelViewInverse), max(roughness,0.035), f0) * Metals;
#endif
#ifdef WATER_BACKGROUND_SPECULAR
if(isEyeInWater == 0) SkyReflection = skyCloudsFromTex(mat3(gbufferModelViewInverse) * reflectedVector, colortex4).rgb / 30.0 ;
if(isEyeInWater == 0 && !isReflectiveEntity) BackgroundReflection = skyCloudsFromTex(mat3(gbufferModelViewInverse) * reflectedVector, colortex4).rgb / 30.0 * Metals;
#endif
if(isEyeInWater == 1 && isWater) BackgroundReflection.rgb = exp(-8.0 * vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B)) * clamp(WsunVec.y*lightCol.a,0,1);
#else
#ifdef WATER_BACKGROUND_SPECULAR
if(isEyeInWater == 0) SkyReflection = skyCloudsFromTexLOD2(mat3(gbufferModelViewInverse) * reflectedVector, colortex4, 0).rgb / 30.0 ;
if(isEyeInWater == 0) BackgroundReflection = skyCloudsFromTexLOD2(mat3(gbufferModelViewInverse) * reflectedVector, colortex4, 0).rgb / 30.0 * Metals;
#endif
#endif
#ifdef SCREENSPACE_REFLECTIONS
if(iswater > 0.0){
vec3 rtPos = rayTrace(reflectedVector, viewPos.xyz, interleaved_gradientNoise(), fresnel, isEyeInWater == 1);
if (rtPos.z < 1.){
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rtPos) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition;
previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz;
previousPosition.xy = projMAD(gbufferPreviousProjection, previousPosition).xy / -previousPosition.z * 0.5 + 0.5;
if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0) {
Reflections.a = 1.0;
Reflections.rgb = texture2D(colortex5,previousPosition.xy).rgb ;
}
vec3 rtPos = rayTrace(reflectedVector, viewPos.xyz, interleaved_gradientNoise_temporal(), fresnel, isEyeInWater == 1);
if (rtPos.z < 1.){
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rtPos) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition;
previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz;
previousPosition.xy = projMAD(gbufferPreviousProjection, previousPosition).xy / -previousPosition.z * 0.5 + 0.5;
if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0) {
Reflections.a = 1.0;
Reflections.rgb = texture2D(colortex5,previousPosition.xy).rgb * Metals;
}
}
#endif
#ifdef OVERWORLD_SHADER
if(isEyeInWater == 1 && iswater > 0.9){
SkyReflection.rgb = exp(-8.0 * vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B)) * clamp(WsunVec.y*lightCol.a,0,1);
}
// if(iswater > 0.9) SkyReflection.rgb = mix(vec3(CaveFogColor_R, CaveFogColor_G, CaveFogColor_B)*0.1, SkyReflection.rgb*indoors, clamp(pow(eyeBrightnessSmooth.y/240. + lightmap.y,2.0),0.0,1.0));
#endif
float visibilityFactor = clamp(exp2((pow(roughness,3.0) / f0) * -4),0,1);
#ifdef ENTITIES
Reflections_Final = FinalColor;
#else
Reflections_Final = mix(SkyReflection*indoors, Reflections.rgb, Reflections.a);
Reflections_Final = mix(FinalColor, Reflections_Final * Metals, fresnel);
#endif
Reflections_Final += SunReflection * Metals;
Reflections_Final = mix(mix(FinalColor, BackgroundReflection, indoors), Reflections.rgb, Reflections.a) * fresnel * visibilityFactor;
Reflections_Final += SunReflection;
// Reflections_Final += vec3(CaveFogColor_R, CaveFogColor_G, CaveFogColor_B)*0.1 * darkSpecularHighlight(feetPlayerPos, viewToWorld(normal), 0.9, 0.1);
gl_FragData[0].rgb = Reflections_Final ;
#ifndef ENTITIES
//correct alpha channel with fresnel
gl_FragData[0].a = mix(gl_FragData[0].a, 1.0, fresnel);
#endif
//correct alpha channel with fresnel
float alpha0 = gl_FragData[0].a;
gl_FragData[0].a = -gl_FragData[0].a * fresnel + gl_FragData[0].a + fresnel;
// prevent reflections from being darkened by buffer blending
gl_FragData[0].rgb = clamp(FinalColor / gl_FragData[0].a*alpha0*(1.0-fresnel) * 0.1 + Reflections_Final / gl_FragData[0].a * 0.1,0.0,65100.0);
if (gl_FragData[0].r > 65000.) gl_FragData[0].rgba = vec4(0.0);
} else {
gl_FragData[0].rgb = FinalColor;
gl_FragData[0].rgb = FinalColor*0.1;
}
#else
gl_FragData[0].rgb = FinalColor;
gl_FragData[0].rgb = FinalColor*0.1;
#endif
// gl_FragData[0].rgb = vec3(1) * (texelFetch2D(depthtex0,ivec2(gl_FragCoord.xy),0).x - texelFetch2D(dhDepthTex1,ivec2(gl_FragCoord.xy),0).x);
#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;
#if defined DISTANT_HORIZONS && defined DH_OVERDRAW_PREVENTION
gl_FragData[0].a = mix(gl_FragData[0].a, 0.0, 1.0-min(max(1.0 - length(feetPlayerPos.xz)/max(far,0.0),0.0)*2.0,1.0) );
if(WATER) gl_FragData[0].a = 0.0;
#endif
#ifndef HAND
gl_FragData[1] = vec4(Albedo, iswater);
gl_FragData[1] = vec4(Albedo, MATERIALS);
#endif
#if DEBUG_VIEW == debug_DH_WATER_BLENDING
if(gl_FragCoord.x*texelSize.x < 0.47) gl_FragData[0] = vec4(0.0);
#endif
#if DEBUG_VIEW == debug_NORMALS
gl_FragData[0].rgb = normal.xyz * 0.1 * vec3(0,0,1);
#endif
#if DEBUG_VIEW == debug_INDIRECT
gl_FragData[0].rgb = Indirect_lighting* 0.1;
#endif
#if DEBUG_VIEW == debug_DIRECT
gl_FragData[0].rgb = Direct_lighting * 0.1;
#endif
gl_FragData[3].a = lmtexcoord.w;
gl_FragData[3].a = encodeVec2(lightmap);
}
}

View File

@ -1,6 +1,7 @@
#include "/lib/settings.glsl"
#include "/lib/res_params.glsl"
#include "/lib/bokeh.glsl"
#include "/lib/items.glsl"
uniform float frameTimeCounter;
#include "/lib/Shadow_Params.glsl"
@ -15,6 +16,9 @@ Read the terms of modification and sharing before changing something below pleas
varying vec4 lmtexcoord;
varying vec4 color;
uniform sampler2D colortex4;
flat varying float exposure;
#ifdef OVERWORLD_SHADER
flat varying vec3 averageSkyCol_Clouds;
flat varying vec4 lightCol;
@ -34,7 +38,6 @@ flat varying int glass;
attribute vec4 at_tangent;
attribute vec4 mc_Entity;
uniform sampler2D colortex4;
uniform vec3 sunPosition;
uniform float sunElevation;
@ -72,7 +75,6 @@ vec4 toClipSpace3(vec3 viewSpacePosition) {
return vec4(projMAD(gl_ProjectionMatrix, viewSpacePosition),-viewSpacePosition.z);
}
varying vec4 pos;
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
@ -81,36 +83,44 @@ varying vec4 pos;
void main() {
lmtexcoord.xy = (gl_MultiTexCoord0).xy;
vec2 lmcoord = gl_MultiTexCoord1.xy / 240.0; // is this even correct? lol
// lmtexcoord.xy = (gl_MultiTexCoord0).xy;
lmtexcoord.xy = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
vec2 lmcoord = gl_MultiTexCoord1.xy / 240.0;
lmtexcoord.zw = lmcoord;
vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
gl_Position = toClipSpace3(position);
pos = vec4(position,1);
HELD_ITEM_BRIGHTNESS = 0.0;
#ifdef Hand_Held_lights
if(heldItemId == 100 || heldItemId2 == 100) HELD_ITEM_BRIGHTNESS = 0.9;
if(heldItemId == ITEM_LIGHT_SOURCES || heldItemId2 == ITEM_LIGHT_SOURCES) HELD_ITEM_BRIGHTNESS = 0.9;
#endif
// 1.0 = water mask
// 0.9 = entity mask
// 0.8 = reflective entities
// 0.7 = reflective blocks
float mat = 0.0;
// water mask
if(mc_Entity.x == 8.0) {
mat = 1.0;
gl_Position.z -= 1e-4;
}
if (mc_Entity.x == 10002) mat = 0.2;
if (mc_Entity.x == 72) mat = 0.5;
// translucent entities
#if defined ENTITIES || defined BLOCKENTITIES
mat = 0.1;
mat = 0.9;
if (entityId == 1403) mat = 0.8;
#endif
// translucent blocks
if (mc_Entity.x >= 301 && mc_Entity.x <= 321) mat = 0.7;
tangent = vec4(normalize(gl_NormalMatrix *at_tangent.rgb),at_tangent.w);
@ -131,6 +141,7 @@ void main() {
color = vec4(gl_Color.rgb, 1.0);
exposure = texelFetch2D(colortex4,ivec2(10,37),0).r;
#ifdef OVERWORLD_SHADER
lightCol.rgb = texelFetch2D(colortex4,ivec2(6,37),0).rgb;
@ -142,8 +153,6 @@ void main() {
// WsunVec = normalize(LightDir);
#endif
#ifdef TAA_UPSCALING
gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w;
#endif

View File

@ -1,10 +1,19 @@
#include "/lib/settings.glsl"
varying vec4 color;
varying vec2 texcoord;
uniform sampler2D texture;
uniform sampler2D normals;
uniform sampler2D noisetex;
flat varying float exposure;
varying vec4 tangent;
varying vec4 normalMat;
attribute vec4 at_tangent;
uniform float frameTimeCounter;
//faster and actually more precise than pow 2.2
vec3 toLinear(vec3 sRGB){
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
@ -28,42 +37,51 @@ float encodeVec2(float x,float y){
return encodeVec2(vec2(x,y));
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
#if defined SPIDER_EYES || defined BEACON_BEAM || defined GLOWING
/* DRAWBUFFERS:1 */
#endif
uniform mat4 gbufferModelViewInverse;
#ifdef ENCHANT_GLINT
/* DRAWBUFFERS:2 */
#endif
vec3 viewToWorld(vec3 viewPos) {
vec4 pos;
pos.xyz = viewPos;
pos.w = 0.0;
pos = gbufferModelViewInverse * pos;
return pos.xyz;
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
/* DRAWBUFFERS:2 */
void main() {
vec4 Albedo = texture2D(texture, texcoord);
Albedo.rgb = toLinear(Albedo.rgb);
#if defined SPIDER_EYES || defined BEACON_BEAM || defined GLOWING
vec4 data1 = vec4(1.0); float materialMask = 1.0;
#if defined SPIDER_EYES || defined GLOWING
if(Albedo.a < 0.1) discard;
Albedo.rgb *= color.a;
#endif
if(Albedo.a < 0.102) { discard; return; }
float minimumBrightness = 0.5;
#ifdef BEACON_BEAM
Albedo.rgb = Albedo.rgb * color.rgb;
materialMask = 0.75;
minimumBrightness = 10.0;
#endif
gl_FragData[0] = vec4(encodeVec2(Albedo.x,data1.x), encodeVec2(Albedo.y,data1.y), encodeVec2(Albedo.z,data1.z), encodeVec2(data1.w, materialMask));
float autoBrightnessAdjust = mix(minimumBrightness, 100.0, clamp(exp(-10.0*exposure),0.0,1.0));
vec3 emissiveColor = Albedo.rgb * color.a * autoBrightnessAdjust;
gl_FragData[0] = vec4(emissiveColor*0.1, Albedo.a * sqrt(color.a));
#endif
#ifdef ENCHANT_GLINT
vec3 GlintColor = toLinear(Albedo.rgb * color.rgb) / clamp(exposure,0.01,1.0);
float autoBrightnessAdjust = mix(0.1, 100.0, clamp(exp(-10.0*exposure),0.0,1.0));
gl_FragData[0] = vec4(GlintColor , Albedo.a * 0.1);
vec3 GlintColor = Albedo.rgb * autoBrightnessAdjust * Emissive_Brightness;
gl_FragData[0] = vec4(GlintColor*0.1, dot(Albedo.rgb,vec3(0.333)) * Albedo.a );
#endif
}

View File

@ -11,6 +11,11 @@ Read the terms of modification and sharing before changing something below pleas
varying vec4 color;
varying vec2 texcoord;
varying vec4 tangent;
varying vec4 normalMat;
attribute vec4 at_tangent;
uniform vec2 texelSize;
uniform int framemod8;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
@ -40,13 +45,9 @@ flat varying float exposure;
void main() {
color = gl_Color;
#ifdef ENCHANT_GLINT
texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).st;
#else
texcoord = (gl_MultiTexCoord0).xy;
#endif
texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).st;
#if defined ENCHANT_GLINT || defined SPIDER_EYES
#if defined ENCHANT_GLINT || defined SPIDER_EYES || defined BEACON_BEAM
exposure = texelFetch2D(colortex4,ivec2(10,37),0).r;
vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
@ -60,6 +61,11 @@ void main() {
if(gl_Color.a < 1.0) gl_Position = vec4(10,10,10,0);
#endif
#ifdef ENCHANT_GLINT
tangent = vec4(normalize(gl_NormalMatrix * at_tangent.rgb), at_tangent.w);
normalMat = vec4(normalize(gl_NormalMatrix * gl_Normal), 1.0);
#endif
#ifdef TAA_UPSCALING
gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w;

View File

@ -6,14 +6,19 @@ flat varying vec2 TAA_Offset;
#include "/lib/res_params.glsl"
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
#ifdef DISTANT_HORIZONS
uniform sampler2D dhDepthTex;
uniform sampler2D dhDepthTex1;
#endif
uniform sampler2D colortex1;
uniform sampler2D colortex3; // Noise
uniform sampler2D colortex6; // Noise
uniform sampler2D colortex8; // Noise
uniform sampler2D colortex14; // Noise
uniform sampler2D colortex12; // Noise
uniform sampler2D colortex15; // Noise
uniform sampler2D shadow;
@ -31,14 +36,22 @@ uniform vec2 texelSize;
uniform float frameTimeCounter;
uniform float rainStrength;
uniform int frameCounter;
uniform mat4 gbufferProjection;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferModelView;
uniform vec3 cameraPosition;
uniform mat4 gbufferProjection;
uniform mat4 gbufferProjectionInverse;
uniform vec3 previousCameraPosition;
uniform mat4 gbufferPreviousProjection;
uniform mat4 gbufferPreviousModelView;
uniform mat4 shadowModelView;
uniform mat4 shadowProjection;
uniform vec3 cameraPosition;
uniform float viewWidth;
uniform float aspectRatio;
uniform float viewHeight;
@ -117,11 +130,11 @@ float interleaved_gradientNoise(){
// return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+ 1.0/1.6180339887 * frameCounter);
// }
float R2_dither(){
#ifdef TAA
// #ifdef TAA
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
#else
vec2 coord = gl_FragCoord.xy;
#endif
// #else
// vec2 coord = gl_FragCoord.xy;
// #endif
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
}
@ -242,12 +255,13 @@ vec2 SSAO(
#endif
vec2 acc = -(TAA_Offset*(texelSize/2.0))*RENDER_SCALE ;
vec2 BLUENOISE = blueNoise(gl_FragCoord.xy).rg;
int n = 0;
for (int i = 0; i < samples; i++) {
vec2 sampleOffset = SpiralSample(i, 7, 8, noise) * clamp(0.05 + i*0.095, 0.0,0.3) * mulfov2;
vec2 sampleOffset = SpiralSample(i, 7, 8, noise) * mulfov2 * clamp(0.05 + i*0.095, 0.0,0.3) ;
ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight*aspectRatio)*RENDER_SCALE);
@ -300,13 +314,56 @@ float encodeVec2(vec2 a){
float encodeVec2(float x,float y){
return encodeVec2(vec2(x,y));
}
// #include "/lib/indirect_lighting_effects.glsl"
#ifdef DENOISE_SSS_AND_SSAO
/* RENDERTARGETS:3,14,12*/
#else
/* RENDERTARGETS:3*/
#endif
vec3 toClipSpace3Prev(vec3 viewSpacePosition) {
return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
}
vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth, bool hand)
{
vec2 du = vec2(texelSize.x*2., 0.0);
vec2 dv = vec2(0.0, texelSize.y*2.);
vec3 dtl = vec3(texcoord,0.) + vec3(-texelSize, texture2D(depth, texcoord - dv - du).x);
vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture2D(depth, texcoord - dv + du).x);
vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture2D(depth, texcoord).x);
vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture2D(depth, texcoord + dv - du).x);
vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture2D(depth, texcoord + dv + du).x);
if(hand){
convertHandDepth(dtl.z);
convertHandDepth(dtr.z);
convertHandDepth(dmc.z);
convertHandDepth(dbl.z);
convertHandDepth(dbr.z);
}
vec3 dmin = dmc;
dmin = dmin.z > dtr.z ? dtr : dmin;
dmin = dmin.z > dtl.z ? dtl : dmin;
dmin = dmin.z > dbl.z ? dbl : dmin;
dmin = dmin.z > dbr.z ? dbr : dmin;
#ifdef TAA_UPSCALING
dmin.xy = dmin.xy/RENDER_SCALE;
#endif
return dmin;
}
float ld(float dist) {
return (2.0 * near) / (far + near - dist * (far - near));
}
float sampleDepth(sampler2D depthTex, vec2 texcoord, bool hand){
// return texture2D(depthTex, texcoord).r;
return convertHandDepth_2(texture2D(depthTex, texcoord).r, hand);
}
/* RENDERTARGETS:3,14,12*/
void main() {
@ -315,10 +372,16 @@ void main() {
vec2 texcoord = gl_FragCoord.xy*texelSize;
float z = texture2D(depthtex1,texcoord).x;
#ifdef DISTANT_HORIZONS
float DH_depth1 = texture2D(dhDepthTex1,texcoord).x;
float swappedDepth = z >= 1.0 ? DH_depth1 : z;
#else
float DH_depth1 = 1.0;
float swappedDepth = z;
#endif
vec4 SHADOWDATA = vec4(0.0);
vec4 data = texture2D(colortex1,texcoord);
vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y));
@ -327,6 +390,7 @@ void main() {
vec2 lightmap = dataUnpacked1.yz;
gl_FragData[1] = vec4(0.0,0.0,0.0, texture2D(colortex14,texcoord).a );
// bool lightningBolt = abs(dataUnpacked1.w-0.5) <0.01;
@ -338,11 +402,12 @@ void main() {
// bool blocklights = abs(dataUnpacked1.w-0.8) <0.01;
if(hand) convertHandDepth(z);
if(hand){
convertHandDepth(z);
}
vec3 viewPos = toScreenSpace_DH(texcoord/RENDER_SCALE - TAA_Offset*texelSize*0.5, z, DH_depth1);
gl_FragData[1] = vec4(0.0,0.0,0.0,texture2D(colortex14,texcoord).a);
#if defined DENOISE_SSS_AND_SSAO && indirect_effect == 1
float depth = z;
@ -366,15 +431,22 @@ void main() {
gl_FragData[2] = vec4(vec3(0.0), 65000.0);
vec3 FlatNormals = texture2D(colortex15,texcoord).rgb * 2.0 - 1.0;
vec3 FlatNormals = texture2D(colortex15,texcoord).rgb * 2.0 - 1.0;
if(z >= 1.0){
FlatNormals = worldToView(normal);
}
gl_FragData[1].xy = SSAO(viewPos, FlatNormals, hand, isLeaf, noise);
vec2 SSAO_SSS = SSAO(viewPos, FlatNormals, hand, isLeaf, noise);
if(swappedDepth >= 1.0) SSAO_SSS = vec2(1.0,0.0);
gl_FragData[1].xy = SSAO_SSS;
#else
vec2 SSAO_SSS = vec2(1.0,0.0);
#endif
#ifdef OVERWORLD_SHADER
float SpecularTex = texture2D(colortex8,texcoord).z;
float LabSSS = clamp((-64.0 + SpecularTex * 255.0) / 191.0 ,0.0,1.0);
@ -385,31 +457,25 @@ void main() {
float minshadowfilt = Min_Shadow_Filter_Radius;
float maxshadowfilt = Max_Shadow_Filter_Radius;
if(lightmap.y < 0.1 && !entities){
// minshadowfilt *= vanillAO;
maxshadowfilt = mix(minshadowfilt, maxshadowfilt, vanillAO);
}
// if(lightmap.y < 0.1 && !entities){
// maxshadowfilt = mix(minshadowfilt, maxshadowfilt, vanillAO);
// }
#ifndef Variable_Penumbra_Shadows
if (LabSSS > 0.0 && NdotL < 0.001) minshadowfilt += 50;
#ifdef BASIC_SHADOW_FILTER
if (LabSSS > 0.0 && NdotL < 0.001){
minshadowfilt = 50;
// maxshadowfilt = 50;
}
#endif
if (z < 1.0){
gl_FragData[0] = vec4(minshadowfilt, 0.1, 0.0, 0.0);
gl_FragData[0].a = 0;
// vec3 viewPos = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z));
#ifdef Variable_Penumbra_Shadows
if (LabSSS > -1) {
vec3 feetPlayerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
vec3 projectedShadowPosition = mat3(shadowModelView) * feetPlayerPos + shadowModelView[3].xyz;
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
@ -420,8 +486,9 @@ void main() {
#else
float distortFactor = 1.0;
#endif
//do shadows only if on shadow map
if (abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.z) < 6.0 || length(feetPlayerPos) < far){
// if (abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.z) < 6.0 || length(feetPlayerPos) < far){
const float threshMul = max(2048.0/shadowMapResolution*shadowDistance/128.0,0.95);
float distortThresh = (sqrt(1.0-NdotL*NdotL)/NdotL+0.7)/distortFactor;
float diffthresh = distortThresh/6000.0*threshMul;
@ -435,24 +502,23 @@ void main() {
float diffthreshM = diffthresh*mult*d0*k/20.;
float avgDepth = 0.0;
vec2 BLUENOISE = blueNoise(gl_FragCoord.xy).rg;
for(int i = 0; i < VPS_Search_Samples; i++){
vec2 offsetS = SpiralSample(i, 7, 8, noise) * 0.5;
float weight = 3.0 + (i+noise) *rdMul/SHADOW_FILTER_SAMPLE_COUNT*shadowMapResolution*distortFactor/2.7;
// float d = texelFetch2D( shadow, ivec2((projectedShadowPosition.xy+offsetS*rdMul)*shadowMapResolution),0).x;
float d = texelFetch2D(shadowtex1, ivec2((projectedShadowPosition.xy+offsetS*rdMul)*shadowMapResolution),0).x;
float d = texelFetch2D(shadow, ivec2((projectedShadowPosition.xy+offsetS*rdMul)*shadowMapResolution),0).x;
float b = smoothstep(weight*diffthresh/2.0, weight*diffthresh, projectedShadowPosition.z - d);
blockerCount += b;
#ifdef DISTANT_HORIZONS_SHADOWMAP
avgDepth += max(projectedShadowPosition.z - d, 0.0)*10000.0;
#else
avgDepth += max(projectedShadowPosition.z - d, 0.0)*1000.0;
#endif
avgBlockerDepth += d * b;
}
@ -464,7 +530,7 @@ void main() {
float ssample = max(projectedShadowPosition.z - avgBlockerDepth,0.0)*1500.0;
gl_FragData[0].r = clamp(ssample, scales.x, scales.y)/(scales.y)*(mult-minshadowfilt)+minshadowfilt;
}
}
// }
}
#endif
}

File diff suppressed because it is too large Load Diff

View File

@ -6,10 +6,12 @@
#endif
flat varying vec3 WsunVec;
// flat varying vec3 unsigned_WsunVec;
flat varying vec3 unsigned_WsunVec;
flat varying vec3 averageSkyCol_Clouds;
flat varying vec4 lightCol;
flat varying float exposure;
flat varying vec2 TAA_Offset;
flat varying vec3 zMults;
uniform sampler2D colortex4;
@ -53,8 +55,9 @@ void main() {
averageSkyCol_Clouds = texelFetch2D(colortex4,ivec2(0,37),0).rgb;
WsunVec = lightCol.a*normalize(mat3(gbufferModelViewInverse) * sunPosition);
// unsigned_WsunVec = normalize(mat3(gbufferModelViewInverse) * sunPosition);
unsigned_WsunVec = normalize(mat3(gbufferModelViewInverse) * sunPosition);
exposure = texelFetch2D(colortex4,ivec2(10,37),0).r;
#ifdef TAA
TAA_Offset = offsets[framemod8];

View File

@ -1,3 +1,5 @@
#include "/lib/settings.glsl"
uniform sampler2D colortex3;
uniform sampler2D colortex6;
@ -79,24 +81,33 @@ vec4 texture2D_bicubic(sampler2D tex, vec2 uv)
void main() {
/* DRAWBUFFERS:3 */
vec2 resScale = vec2(1920.,1080.)/max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.));
vec2 texcoord = ((gl_FragCoord.xy)*2.+0.5)*texelSize;
vec3 bloom = texture2D_bicubic(colortex3,texcoord/2.0).rgb; //1/4 res
vec2 texcoord = ((gl_FragCoord.xy)*2.0 + 0.5)*texelSize;
bloom += texture2D_bicubic(colortex6,texcoord/4.).rgb; //1/8 res
#ifdef OLD_BLOOM
vec3 bloom = texture2D_bicubic(colortex3,texcoord/2.).rgb; //1/4 res
bloom += texture2D_bicubic(colortex6,texcoord/4.).rgb; //1/8 res
bloom += texture2D_bicubic(colortex6,texcoord/8.+vec2(0.25*resScale.x+2.5*texelSize.x,.0)).rgb; //1/16 res
bloom += texture2D_bicubic(colortex6,texcoord/16.+vec2(0.375*resScale.x+4.5*texelSize.x,.0)).rgb; //1/32 res
bloom += texture2D_bicubic(colortex6,texcoord/32.+vec2(0.4375*resScale.x+6.5*texelSize.x,.0)).rgb; //1/64 res
bloom += texture2D_bicubic(colortex6,texcoord/64.+vec2(0.46875*resScale.x+8.5*texelSize.x,.0)).rgb; //1/128 res
bloom += texture2D_bicubic(colortex6,texcoord/128.+vec2(0.484375*resScale.x+10.5*texelSize.x,.0)).rgb; //1/256 res
bloom += texture2D_bicubic(colortex6,texcoord/8.+vec2(0.25*resScale.x+2.5*texelSize.x,.0)).rgb; //1/16 res
gl_FragData[0].rgb = bloom * 2.0;
#else
bloom += texture2D_bicubic(colortex6,texcoord/16.+vec2(0.375*resScale.x+4.5*texelSize.x,.0)).rgb; //1/32 res
float weights[7] = float[]( 1.0, 1.0/2.0, 1.0/3.0, 1.0/5.5, 1.0/8.0, 1.0/10.0, 1.0/12.0 );
// float weights[7] = float[]( 0.7, pow(0.5,2), pow(0.5,3), pow(0.5,4), pow(0.5,5), pow(0.5,6), pow(0.5,7) );
bloom += texture2D_bicubic(colortex6,texcoord/32.+vec2(0.4375*resScale.x+6.5*texelSize.x,.0)).rgb*1.0; //1/64 res
vec3 bloom = texture2D_bicubic(colortex3,texcoord/2.).rgb * weights[0]; //1/4 res
bloom += texture2D_bicubic(colortex6,texcoord/4.).rgb * weights[1]; //1/8 res
bloom += texture2D_bicubic(colortex6,texcoord/8.+vec2(0.25*resScale.x+2.5*texelSize.x,.0)).rgb * weights[2]; //1/16 res
bloom += texture2D_bicubic(colortex6,texcoord/16.+vec2(0.375*resScale.x+4.5*texelSize.x,.0)).rgb * weights[3]; //1/32 res
bloom += texture2D_bicubic(colortex6,texcoord/32.+vec2(0.4375*resScale.x+6.5*texelSize.x,.0)).rgb * weights[4]; //1/64 res
bloom += texture2D_bicubic(colortex6,texcoord/64.+vec2(0.46875*resScale.x+8.5*texelSize.x,.0)).rgb * weights[5]; //1/128 res
bloom += texture2D_bicubic(colortex6,texcoord/128.+vec2(0.484375*resScale.x+10.5*texelSize.x,.0)).rgb * weights[6]; //1/256 res
bloom += texture2D_bicubic(colortex6,texcoord/64.+vec2(0.46875*resScale.x+8.5*texelSize.x,.0)).rgb*1.0; //1/128 res
bloom += texture2D_bicubic(colortex6,texcoord/128.+vec2(0.484375*resScale.x+10.5*texelSize.x,.0)).rgb*1.0; //1/256 res
//bloom = texture2D_bicubic(colortex6,texcoord).rgb*6.; //1/8 res
gl_FragData[0].rgb = bloom*2.;
gl_FragData[0].rgb = bloom * 3.0;
#endif
gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.);
}

View File

@ -67,57 +67,39 @@ float ld(float depth) {
// uniform float viewHeight;
// uniform sampler2D depthtex0;
#ifdef DISTANT_HORIZONS
uniform sampler2D dhDepthTex;
#endif
uniform float dhNearPlane;
uniform float dhFarPlane;
// uniform mat4 gbufferProjectionInverse;
uniform mat4 dhProjectionInverse;
vec3 getViewPos() {
ivec2 uv = ivec2(gl_FragCoord.xy);
vec2 viewSize = vec2(viewWidth, viewHeight);
vec2 texcoord = gl_FragCoord.xy / viewSize;
vec4 viewPos = vec4(0.0);
float depth = texelFetch(depthtex0, uv, 0).r;
if (depth < 1.0) {
vec4 ndcPos = vec4(texcoord, depth, 1.0) * 2.0 - 1.0;
viewPos = gbufferProjectionInverse * ndcPos;
viewPos.xyz /= viewPos.w;
} else {
depth = texelFetch(dhDepthTex, ivec2(gl_FragCoord.xy), 0).r;
vec4 ndcPos = vec4(texcoord, depth, 1.0) * 2.0 - 1.0;
viewPos = dhProjectionInverse * ndcPos;
viewPos.xyz /= viewPos.w;
}
return viewPos.xyz;
}
vec3 ACESFilm2(vec3 x){
// float a = 2.51f;
// float b = 0.03f;
// float c = 2.43f;
// float d = 0.59f;
// float e = 0.14f;
float a = 2.51f; // brightests
float b = 0.53f; // lower midtones
float c = 2.43f; // upper midtones
float d = 0.59f; // upper midtones
float e = 0.54f; // lowest tones
return clamp((x*(a*x+b))/(x*(c*x+d)+e),0.0,1.0);
}
float linearizeDepthFast(const in float depth, const in float near, const in float far) {
return (near * far) / (depth * (near - far) + far);
}
float bloomWeight(){
float weights[7] = float[]( 1.0, 1.0/2.0, 1.0/3.0, 1.0/5.5, 1.0/8.0, 1.0/10.0, 1.0/12.0 );
// float weights[7] = float[]( 0.7, pow(0.5,2), pow(0.5,3), pow(0.5,4), pow(0.5,5), pow(0.5,6), pow(0.5,7) );
float result = 0.0;
for ( int i = 0; i < 7; i++) {
result += weights[i];
}
return result;
}
#define linear_to_srgb(x) (pow(x, vec3(1.0/2.2)))
void main() {
/* DRAWBUFFERS:7 */
float vignette = (1.5-dot(texcoord-0.5,texcoord-0.5)*2.);
@ -157,15 +139,15 @@ void main() {
vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.));
#ifdef OLD_BLOOM
vec3 bloom = texture2D(colortex3,texcoord/clampedRes*vec2(1920.,1080.)*BLOOM_QUALITY).rgb / 2.0 / 7.0;
float lightScat = clamp((BLOOM_STRENGTH+3) * 0.05 * pow(exposure.a, 0.2) ,0.0,1.0) * vignette;
#else
vec3 bloom = texture2D(colortex3,texcoord/clampedRes*vec2(1920.,1080.)*BLOOM_QUALITY).rgb / 3.0 / bloomWeight();
float lightScat = clamp(BLOOM_STRENGTH * 0.5 * pow(exposure.a, 0.2) ,0.0,1.0) * vignette;
#endif
vec3 bloom = (texture2D(colortex3,texcoord/clampedRes*vec2(1920.,1080.)*BLOOM_QUALITY).rgb)/2./7.0;
// vec3 bloom = texture2D(colortex3, texcoord/clampedRes*vec2(1920.,1080.)*BLOOM_QUALITY).rgb / 2.0 / 7.0;
float lightScat = clamp(BLOOM_STRENGTH * 0.05 * pow(exposure.a, 0.2) ,0.0,1.0)*vignette;
float VL_abs = texture2D(colortex7,texcoord*RENDER_SCALE).r;
float VL_abs = texture2D(colortex7, texcoord*RENDER_SCALE).r;
#ifdef AUTO_EXPOSURE
float purkinje = clamp(exposure.a*exposure.a,0.0,1.0) * clamp(rodExposureDepth.x/(1.0+rodExposureDepth.x)*Purkinje_strength,0,1);
@ -174,8 +156,10 @@ void main() {
#endif
VL_abs = clamp((1.0-VL_abs)*BLOOMY_FOG*0.75*(1.0+rainStrength) * (1.0-purkinje*0.3),0.0,1.0)*clamp(1.0-pow(cdist(texcoord.xy),15.0),0.0,1.0);
col = (mix(col, bloom, VL_abs) + bloom * lightScat) * exposure.rgb;
// if(hideGUI > 0) col = bloom * lightScat* exposure.rgb;
float lum = dot(col, vec3(0.15,0.3,0.55));
float lum2 = dot(col, vec3(0.85,0.7,0.45));
@ -184,12 +168,6 @@ void main() {
col = mix(lum * vec3(Purkinje_R, Purkinje_G, Purkinje_B) * Purkinje_Multiplier, col, rodCurve);
// gl_FragColor = vec4(getViewPos() * 0.001,1.0);
// gl_FragColor.rgb = linear_to_srgb(gl_FragColor.rgb);
#ifndef USE_ACES_COLORSPACE_APPROXIMATION
col = LinearTosRGB(TONEMAP(col));
#else

View File

@ -7,8 +7,11 @@ flat varying vec3 averageSkyCol_Clouds;
uniform sampler2D noisetex;
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
#ifdef DISTANT_HORIZONS
uniform sampler2D dhDepthTex;
uniform sampler2D dhDepthTex1;
#endif
uniform sampler2D colortex2;
uniform sampler2D colortex3;
@ -366,7 +369,11 @@ void main() {
#endif
float z = texture2D(depthtex1,tc).x;
float DH_z = texture2D(dhDepthTex1,tc).x;
#ifdef DISTANT_HORIZONS
float DH_z = texture2D(dhDepthTex1,tc).x;
#else
float DH_z = 0.0;
#endif
vec3 viewPos1 = toScreenSpace_DH(tc/RENDER_SCALE, z, DH_z);
vec3 viewPos0 = toScreenSpace_DH(tc/RENDER_SCALE, z0, DH_z0);
@ -418,4 +425,6 @@ void main() {
gl_FragData[0] = clamp(vec4(vl,1.0),0.000001,65000.);
}
// gl_FragData[0] = clamp(vec4(vl,1.0),0.000001,65000.);
}

View File

@ -8,9 +8,11 @@ flat varying vec3 skyGroundColor;
uniform sampler2D noisetex;
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
#ifdef DISTANT_HORIZONS
uniform sampler2D dhDepthTex;
uniform sampler2D dhDepthTex1;
#endif
uniform sampler2D colortex0;
uniform sampler2D colortex1;
@ -197,23 +199,24 @@ void applyContrast(inout vec3 color, float contrast){
color = ((color - 0.5) * max(contrast, 0.0)) + 0.5;
}
void ApplyDistortion(inout vec2 Texcoord, vec2 TangentNormals, float lineardistance, bool isEntity){
void ApplyDistortion(inout vec2 Texcoord, vec2 TangentNormals, float lineardistance, bool isTranslucentEntity){
vec2 UnalteredTexcoord = Texcoord;
float refractionStrength = isEntity ? 0.5 : 1.0;
float refractionStrength = isTranslucentEntity ? 0.25 : 1.0 ;
// Texcoord = abs(Texcoord + (TangentNormals * clamp((ld(depths.x) - ld(depths.y)) * 0.5,0.0,0.15)) * RENDER_SCALE * refractionStrength );
Texcoord = abs(Texcoord + (TangentNormals * mix(0.01, 0.1, pow(clamp(1.0-lineardistance/(32*4),0.0,1.0),2))) * RENDER_SCALE * refractionStrength );
float DistortedAlpha = decodeVec2(texture2D(colortex11,Texcoord).b).g;
// float DistortedAlpha = decodeVec2(texelFetch2D(colortex11,ivec2(Texcoord/texelSize),0).b).g;
// float DistortedAlpha = texelFetch2D(colortex2,ivec2(Texcoord/texelSize),0).a;
if(DistortedAlpha < 0.1) Texcoord = UnalteredTexcoord; // remove distortion on non-translucents
Texcoord = mix(Texcoord, UnalteredTexcoord, min(max(0.1-DistortedAlpha,0.0) * 1000.0,1.0)); // remove distortion on non-translucents
}
uniform float dhRenderDistance;
uniform int dhRenderDistance;
uniform float eyeAltitude;
void main() {
/* DRAWBUFFERS:73 */
@ -257,25 +260,27 @@ void main() {
float lightleakfixfast = clamp(eyeBrightness.y/240.,0.0,1.0);
////// --------------- UNPACK TRANSLUCENT GBUFFERS --------------- //////
vec3 data = texture2D(colortex11,texcoord).rgb;
vec4 data = texture2D(colortex11,texcoord).rgba;
vec4 unpack0 = vec4(decodeVec2(data.r),decodeVec2(data.g)) ;
vec4 unpack1 = vec4(decodeVec2(data.b),0,0) ;
vec4 albedo = vec4(unpack0.ba,unpack1.rg);
vec2 tangentNormals = unpack0.xy*2.0-1.0;
if(albedo.a < 0.01) tangentNormals = vec2(0.0);
vec4 TranslucentShader = texture2D(colortex2, texcoord);
////// --------------- UNPACK MISC --------------- //////
float trpData = texture2D(colortex7, texcoord).a;
////// --------------- MASKS/BOOLEANS --------------- //////
bool iswater = trpData > 0.99;
bool isTranslucentEntity = abs(trpData-0.1) < 0.01;
float translucentAlpha = trpData;
// 1.0 = water mask
// 0.9 = entity mask
// 0.8 = reflective entities
// 0.7 = reflective blocks
float translucentMasks = texture2D(colortex7, texcoord).a;
bool isWater = translucentMasks > 0.99;
bool isReflectiveEntity = abs(translucentMasks - 0.8) < 0.01;
bool isReflective = abs(translucentMasks - 0.7) < 0.01 || isWater || isReflectiveEntity;
bool isEntity = abs(translucentMasks - 0.9) < 0.01 || isReflectiveEntity;
////// --------------- get volumetrics
@ -293,26 +298,29 @@ void main() {
////// --------------- distort texcoords as a refraction effect
vec2 refractedCoord = texcoord;
#ifdef Refraction
ApplyDistortion(refractedCoord, tangentNormals, linearDistance, isTranslucentEntity);
ApplyDistortion(refractedCoord, tangentNormals, linearDistance, isEntity);
#endif
////// --------------- MAIN COLOR BUFFER
vec3 color = texture2D(colortex3, refractedCoord).rgb;
// apply block breaking effect.
if(albedo.a > 0.01 && !isWater && TranslucentShader.a <= 0.0) color = mix(color*6.0, color, luma(albedo.rgb)) * albedo.rgb;
////// --------------- BLEND TRANSLUCENT GBUFFERS
//////////// and do border fog on opaque and translucents
#if defined BorderFog
#ifdef DISTANT_HORIZONS
float fog = 1.0 - pow(1.0-pow(1.0-min(max(1.0 - linearDistance_cylinder / dhFarPlane,0.0)*3.0,1.0),2.0),2.0);
float fog = smoothstep(1.0, 0.0, min(max(1.0 - linearDistance_cylinder / dhRenderDistance,0.0)*3.0,1.0) );
#else
float fog = 1.0 - pow(1.0-pow(1.0-min(max(1.0 - linearDistance_cylinder / far,0.0)*5.0,1.0),2.0),2.0);
float fog = smoothstep(1.0, 0.0, min(max(1.0 - linearDistance_cylinder / far,0.0)*3.0,1.0) );
#endif
fog *= exp(-10.0 * pow(clamp(np3.y,0.0,1.0)*4.0,2.0));
if(swappedDepth >= 1.0 || isEyeInWater != 0) fog = 0.0;
if(lightleakfixfast < 1.0) fog *= lightleakfix;
@ -320,27 +328,24 @@ void main() {
#ifdef SKY_GROUND
vec3 borderFogColor = skyGroundColor;
#else
vec3 borderFogColor = skyFromTex(np3, colortex4)/30.0;
vec3 borderFogColor = skyFromTex(np3, colortex4)/30.0;
#endif
color.rgb = mix(color.rgb, borderFogColor, fog);
#else
float fog = 0.0;
#endif
if (albedo.a > 0.0 || TranslucentShader.a > 0.0){
if (TranslucentShader.a > 0.0){
#ifdef Glass_Tint
if(!iswater && TranslucentShader.a > 0.0) color *= normalize(albedo.rgb+0.0001)*0.9+0.1;
if(!isWater) color *= mix(normalize(albedo.rgb+0.0001)*0.9+0.1, vec3(1.0), max(fog, min(max(0.1-albedo.a,0.0) * 1000.0,1.0))) ;
#endif
// block breaking effect.
if(!iswater && TranslucentShader.a <= 0.0) color *= albedo.rgb;
color = color*(1.0-TranslucentShader.a) + TranslucentShader.rgb;
#ifdef BorderFog
color.rgb = mix(color.rgb, borderFogColor, fog);
TranslucentShader = mix(TranslucentShader, vec4(0.0), fog);
#endif
color = color*(1.0-TranslucentShader.a) + TranslucentShader.rgb*10.0;
}
////// --------------- VARIOUS FOG EFFECTS (behind volumetric fog)
@ -361,7 +366,7 @@ void main() {
BiomeFogColor(cavefogCol);
#endif
color.rgb = mix(color.rgb, cavefogCol, cavefog * (1-lightleakfix));
color.rgb = mix(color.rgb, cavefogCol, cavefog * lightleakfix);
}
#endif
@ -442,13 +447,13 @@ void main() {
vl.a = 1.0;
}
#endif
// color.rgb = vec3(1) * sqrt(texture2D(colortex12,texcoord).a/65000.0);
gl_FragData[0].r = bloomyFogMult; // pass fog alpha so bloom can do bloomy fog
gl_FragData[1].rgb = clamp(color.rgb, 0.0,68000.0);
// gl_FragData[1].rgb = vec3(1.0) * ld( (data.a > 0.0 ? data.a : texture2D(depthtex0, texcoord).x ) ) ;
// gl_FragData[1].rgb = gl_FragData[1].rgb * (1.0-TranslucentShader.a) + TranslucentShader.rgb*10.0;
// gl_FragData[1].rgb = 1-(texcoord.x > 0.5 ? vec3(TranslucentShader.a) : vec3(data.a));
// gl_FragData[1].rgb = vec3(1) * sqrt(texelFetch2D(colortex12,ivec2(gl_FragCoord.xy),0).a/65000.0);
// gl_FragData[1].rgb = vl.rgb;
}

View File

@ -16,7 +16,7 @@ const int colortex11Format = RGBA16; // unchanged translucents albedo, alpha
const int colortex12Format = RGBA16F; // DISTANT HORIZONS + VANILLA MIXED DEPTHs
const int colortex13Format = RGBA16F; // low res VL (composite5->composite15)
const int colortex14Format = RGBA8; // rg = SSAO and SS-SSS. a = skylightmap for translucents.
const int colortex14Format = RGBA16; // rg = SSAO and SS-SSS. a = skylightmap for translucents.
const int colortex15Format = RGBA8; // flat normals and vanilla AO
*/
@ -59,6 +59,7 @@ uniform sampler2D colortex5;
uniform sampler2D colortex6;
uniform sampler2D colortex10;
uniform sampler2D colortex12;
uniform sampler2D colortex14;
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
@ -249,13 +250,20 @@ vec3 closestToCamera5taps_DH(vec2 texcoord, sampler2D depth, sampler2D dhDepth,
}
#ifdef DISTANT_HORIZONS
uniform sampler2D dhDepthTex;
#endif
uniform float near;
uniform float far;
uniform float dhFarPlane;
uniform float dhNearPlane;
#include "/lib/DistantHorizons_projections.glsl"
float ld(float dist) {
return (2.0 * near) / (far + near - dist * (far - near));
}
float DH_ld(float dist) {
return (2.0 * dhNearPlane) / (dhFarPlane + dhNearPlane - dist * (dhFarPlane - dhNearPlane));
}
@ -332,7 +340,7 @@ vec4 TAA_hq(bool hand){
//use velocity from the nearest texel from camera in a 3x3 box in order to improve edge quality in motion
#ifdef CLOSEST_VELOCITY
#ifdef DISTANT_HORIZONS
vec3 closestToCamera = closestToCamera5taps_DH(adjTC, depthtex0, dhDepthTex, depthCheck, hand);
vec3 closestToCamera = closestToCamera5taps_DH(adjTC, depthtex0, dhDepthTex, depthCheck, hand);
#else
vec3 closestToCamera = closestToCamera5taps(adjTC,depthtex0, hand);
#endif
@ -384,16 +392,20 @@ vec4 TAA_hq(bool hand){
#endif
#ifndef SCREENSHOT_MODE
vec3 albedoPrev = max(FastCatmulRom(colortex5, previousPosition.xy,vec4(texelSize, 1.0/texelSize), 0.75).xyz, 0.0);
vec3 finalcAcc = clamp(albedoPrev, cMin, cMax);
//Increases blending factor when far from AABB and in motion, reduces ghosting
float isclamped = distance(albedoPrev,finalcAcc)/luma(albedoPrev) * 0.5;
float movementRejection = (0.12+isclamped)*clamp(length(velocity/texelSize),0.0,1.0);
if(hand) movementRejection *= 5.0;
float depthDiff = texture2D(colortex14, previousPosition.xy).a;
// movementRejection = mix( 0.0, 1.0, depthDiff);
if(hand) movementRejection *= 5.0;
//Blend current pixel with clamped history, apply fast tonemap beforehand to reduce flickering
vec4 supersampled = vec4(invTonemap(mix(tonemap(finalcAcc), tonemap(albedoCurrent0), clamp(BLEND_FACTOR + movementRejection, 0.0,1.0))), 1.0);
@ -422,15 +434,16 @@ void main() {
gl_FragData[0].a = 1.0;
#ifdef TAA
float dataUnpacked = decodeVec2(texture2D(colortex1,texcoord).w).y;
bool hand = abs(dataUnpacked-0.75) < 0.01 && texture2D(depthtex1,texcoord).x < 1.0;
vec4 color = TAA_hq(hand);
#if DEBUG_VIEW == debug_TEMPORAL_REPROJECTION
color.rgb = texture2D(colortex3, texcoord).rgb;
#endif
#ifdef SCREENSHOT_MODE
gl_FragData[0] = clamp(color, 0.0, 65000.0);
#else

View File

@ -383,6 +383,7 @@ vec3 temp = texelFetch2D(colortex4,ivec2(gl_FragCoord.xy),0).rgb;
vec3 curr = gl_FragData[0].rgb*150.;
if(accumuteSpeed < 1.0) mixhistory = 1.0;
gl_FragData[0].rgb = clamp(mix(temp, curr, mixhistory),0.0,65000.);

View File

@ -142,7 +142,7 @@ void main() {
// maximum control of color and luminance
vec3 minimumlight = vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.003 + nightVision);
averageSkyCol_Clouds = max( normalize(averageSkyCol_Clouds) * min(luma(averageSkyCol_Clouds) * 3.0,3.0), minimumlight);
averageSkyCol_Clouds = max( normalize(averageSkyCol_Clouds) * min(luma(averageSkyCol_Clouds) * 3.0,2.5), minimumlight);
averageSkyCol = max(averageSkyCol * PLANET_GROUND_BRIGHTNESS, minimumlight);
////////////////////////////////////////

View File

@ -7,9 +7,10 @@ uniform vec2 texelSize;
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
#ifdef DISTANT_HORIZONS
uniform sampler2D dhDepthTex;
uniform sampler2D dhDepthTex1;
#endif
uniform float near;
uniform float far;
@ -44,7 +45,9 @@ void main() {
#ifdef DISTANT_HORIZONS
float QuarterResDepth = texelFetch2D(dhDepthTex, ivec2(gl_FragCoord.xy*4), 0).x;
if(newTex >= 1.0) newTex = QuarterResDepth;
if(newTex >= 1.0) newTex = sqrt(QuarterResDepth);// + 0.0001;
gl_FragData[1].a = DH_ld(QuarterResDepth)*DH_ld(QuarterResDepth)*65000.0;
#endif
if (newTex < 1.0)
@ -52,28 +55,27 @@ void main() {
else
gl_FragData[0] = vec4(oldTex, 2.0);
float depth = texelFetch2D(depthtex1, ivec2(gl_FragCoord.xy*4), 0).x;
#ifdef DISTANT_HORIZONS
float _near = near;
float _far = far*4.0;
if (depth >= 1.0) {
depth = texelFetch2D(dhDepthTex1, ivec2(gl_FragCoord.xy*4), 0).x;
_near = dhNearPlane;
_far = dhFarPlane;
}
depth = linearizeDepthFast(depth, _near, _far);
depth = depth / dhFarPlane;
#endif
if(depth < 1.0)
gl_FragData[1] = vec4(vec3(0.0), depth * depth * 65000.0);
else
gl_FragData[1] = vec4(vec3(0.0), 65000.0);
#ifdef DISTANT_HORIZONS
gl_FragData[1].a = DH_ld(QuarterResDepth)*DH_ld(QuarterResDepth)*65000.0;
#endif
// float depth = texelFetch2D(depthtex1, ivec2(gl_FragCoord.xy*4), 0).x;
// #ifdef DISTANT_HORIZONS
// float _near = near;
// float _far = far*4.0;
// if (depth >= 1.0) {
// depth = texelFetch2D(dhDepthTex1, ivec2(gl_FragCoord.xy*4), 0).x;
// _near = dhNearPlane;
// _far = dhFarPlane;
// }
// depth = linearizeDepthFast(depth, _near, _far);
// depth = depth / dhFarPlane;
// #endif
// if(depth < 1.0)
// gl_FragData[1] = vec4(vec3(0.0), depth * depth * 65000.0);
// else
// gl_FragData[1] = vec4(vec3(0.0), 65000.0);
}

View File

@ -16,7 +16,10 @@ flat varying float tempOffsets;
// uniform float far;
uniform float near;
uniform sampler2D depthtex0;
#ifdef DISTANT_HORIZONS
uniform sampler2D dhDepthTex;
#endif
// uniform sampler2D colortex4;
uniform sampler2D noisetex;
@ -111,8 +114,6 @@ void main() {
// gl_FragData[0] = vec4(0.0,0.0,0.0,1.0);
gl_FragData[0] = VolumetricClouds;
#else
gl_FragData[0] = vec4(0.0,0.0,0.0,1.0);
#endif

View File

@ -3,6 +3,8 @@
varying vec2 texcoord;
uniform sampler2D colortex7;
uniform sampler2D colortex14;
uniform sampler2D depthtex0;
uniform vec2 texelSize;
uniform float frameTimeCounter;
@ -17,6 +19,7 @@ uniform sampler2D shadowtex1;
#include "/lib/res_params.glsl"
#include "/lib/gameplay_effects.glsl"
uniform int hideGUI;
vec4 SampleTextureCatmullRom(sampler2D tex, vec2 uv, vec2 texSize )
{
@ -90,7 +93,7 @@ vec3 toneCurve(vec3 color){
vec3 colorGrading(vec3 color) {
float grade_luma = dot(color, vec3(1.0 / 3.0));
float shadows_amount = saturate(-6.0 * grade_luma + 2.75);
float shadows_amount = saturate(-6.0 * grade_luma + 2.75);
float mids_amount = saturate(-abs(6.0 * grade_luma - 3.0) + 1.25);
float highlights_amount = saturate(6.0 * grade_luma - 3.25);
@ -101,31 +104,13 @@ vec3 colorGrading(vec3 color) {
return saturate(graded_shadows * shadows_amount + graded_mids * mids_amount + graded_highlights * highlights_amount);
}
// #ifdef HURT_AND_DEATH_EFFECT
// uniform float hurt;
// uniform float dying;
// uniform float dead;
// void PlayerDamagedEffect(inout vec3 outColor){
// if(dying > 0){
// float vignette2 = clamp(1.0 - exp(-(sin(frameTimeCounter*7)*15+50) * dot(texcoord-0.5,texcoord-0.5)),0.0,1.0);
// outColor = mix(outColor, vec3(0.0), min(dying,1.0)*vignette2);
// outColor = mix(outColor, vec3(0.0), dead);
// }else{
// float vignette = clamp(1.0 - exp(-5 * dot(texcoord-0.5,texcoord-0.5)),0.0,1.0);
// outColor = mix(outColor, vec3(0.3,0.0,0.0), vignette*sqrt(hurt));
// }
// }
// #endif
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
uniform int hideGUI;
void main() {
#ifdef BICUBIC_UPSCALING
vec3 col = SampleTextureCatmullRom(colortex7,texcoord,1.0/texelSize).rgb;
@ -168,12 +153,19 @@ void main() {
applyContrast(FINAL_COLOR, CONTRAST); // for fun
applyGameplayEffects_FRAGMENT(FINAL_COLOR, texcoord); // for making the fun, more fun
applyGameplayEffects_FRAGMENT(FINAL_COLOR, texcoord, interleaved_gradientNoise()); // for making the fun, more fun
// float reprojectedBuffer = texture2D(colortex14, texcoord).a;
// gl_FragColor.rgb = vec3(1.0) * reprojectedBuffer;
gl_FragColor.rgb = FINAL_COLOR;
#if DEBUG_VIEW == debug_SHADOWMAP
if(texcoord.x < 0.25 && texcoord.y < 0.5) gl_FragColor.rgb = texture2D(shadowcolor0, (texcoord * vec2(2.0, 1.0) * 2 - vec2(0.0, 0.0)) ).rgb * vec3(1.0);
if(texcoord.x < 0.25 && texcoord.y < 0.5) gl_FragColor.rgb = texture2D(shadowcolor0, (texcoord * vec2(2.0, 1.0) * 2 - vec2(0.0, 0.0)) ).rgb;
#endif
}

View File

@ -3,12 +3,15 @@
flat varying vec4 lightCol;
flat varying vec3 averageSkyCol;
flat varying vec3 averageSkyCol_Clouds;
flat varying float exposure;
uniform sampler2D noisetex;
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
#ifdef DISTANT_HORIZONS
uniform sampler2D dhDepthTex;
uniform sampler2D dhDepthTex1;
#endif
uniform sampler2D colortex2;
uniform sampler2D colortex3;
@ -198,7 +201,7 @@ vec4 waterVolumetrics_test( vec3 rayStart, vec3 rayEnd, float estEndDepth, float
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
ambient = max(ambient* (normalize(wpos).y*0.3+0.7),0.0);
ambient = max(ambient * (normalize(wpos).y*0.3+0.7),0.0);
float expFactor = 11.0;
for (int i=0;i<spCount;i++) {
@ -244,7 +247,7 @@ vec4 waterVolumetrics_test( vec3 rayStart, vec3 rayEnd, float estEndDepth, float
vec3 ambientMul = exp(-estEndDepth * d * waterCoefs );
vec3 Directlight = ((lightSource * sh) * phase * sunMul) ;
vec3 Indirectlight = max(ambient * ambientMul, vec3(0.01,0.2,0.4) * ambientMul * 0.05) ;
vec3 Indirectlight = max(ambient * ambientMul, vec3(0.01,0.2,0.4) * ambientMul * 0.03) ;
vec3 light = (Indirectlight + Directlight) * scatterCoef;
@ -254,6 +257,11 @@ vec4 waterVolumetrics_test( vec3 rayStart, vec3 rayEnd, float estEndDepth, float
// inColor += vL;
return vec4( vL, dot(newabsorbance,vec3(0.335)));
}
vec2 decodeVec2(float a){
const vec2 constant1 = 65535. / vec2( 256., 65536.);
const float constant2 = 256. / 255.;
return fract( a * constant1 ) * constant2 ;
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
@ -282,8 +290,12 @@ void main() {
#endif
float z = texture2D(depthtex1,tc).x;
float DH_z = texture2D(dhDepthTex1,tc).x;
#ifdef DISTANT_HORIZONS
float DH_z = texture2D(dhDepthTex1,tc).x;
#else
float DH_z = 0.0;
#endif
vec3 viewPos1 = toScreenSpace_DH(tc/RENDER_SCALE, z, DH_z);
vec3 viewPos0 = toScreenSpace_DH(tc/RENDER_SCALE, z0, DH_z0);
@ -291,7 +303,8 @@ void main() {
vec3 playerPos = normalize(mat3(gbufferModelViewInverse) * viewPos1);
// vec3 lightningColor = (lightningEffect / 3) * (max(eyeBrightnessSmooth.y,0)/240.);
float dirtAmount = Dirt_Amount + 0.05;
float dirtAmount = Dirt_Amount + 0.1;
// float dirtAmount = Dirt_Amount + 0.01;
vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B);
vec3 totEpsilon = dirtEpsilon*dirtAmount + waterEpsilon;
@ -305,16 +318,22 @@ void main() {
///////////////// BEHIND OF TRANSLUCENTS /////////////////
//////////////////////////////////////////////////////////
// gl_FragData[0] = vec4(0,0,0,1);
if(texture2D(colortex2, tc).a > 0.0 || iswater){
#ifdef OVERWORLD_SHADER
float lightmap = texture2D(colortex14,tc).a;
if(z >= 1.0) lightmap = 1.0;
vec2 lightmap = decodeVec2(texture2D(colortex14, tc).a);
if(z >= 1.0) lightmap.y = 0.99;
#else
float lightmap = 1.0;
vec2 lightmap = decodeVec2(texture2D(colortex14, tc).a);
lightmap.y = 1.0;
#endif
indirectLightColor_dynamic = indirectLightColor_dynamic * ambient_brightness * pow(1.0-pow(1.0-lightmap.y,0.5),3.0) ;
float TorchBrightness_autoAdjust = mix(1.0, 30.0, clamp(exp(-10.0*exposure),0.0,1.0)) ;
// indirectLightColor_dynamic += vec3(TORCH_R,TORCH_G,TORCH_B) * TorchBrightness_autoAdjust * pow(1.0-sqrt(1.0-clamp(lightmap.x,0.0,1.0)),2.0) * 2.0;
float Vdiff = distance(viewPos1, viewPos0) * 2.0;
float VdotU = playerPos.y;
float estimatedDepth = Vdiff * abs(VdotU) ; //assuming water plane
@ -326,7 +345,7 @@ void main() {
#endif
vec4 underwaterVlFog = vec4(0,0,0,1);
if(iswater) underwaterVlFog = waterVolumetrics_test(viewPos0, viewPos1, estimatedDepth, estimatedSunDepth, Vdiff, noise_1, totEpsilon, scatterCoef, indirectLightColor_dynamic * max(lightmap,0.0), directLightColor, dot(normalize(viewPos1), normalize(sunVec*lightCol.a)) );
if(iswater) underwaterVlFog = waterVolumetrics_test(viewPos0, viewPos1, estimatedDepth, estimatedSunDepth, Vdiff, noise_1, totEpsilon, scatterCoef, indirectLightColor_dynamic, directLightColor, dot(normalize(viewPos1), normalize(sunVec*lightCol.a)) );
vec4 fogFinal = vec4(underwaterVlFog.rgb * VolumetricFog2.a + VolumetricFog2.rgb, VolumetricFog2.a * underwaterVlFog.a);

View File

@ -12,6 +12,7 @@ flat varying vec3 refractedSunVec;
flat varying float tempOffsets;
uniform sampler2D colortex4;
flat varying float exposure;
uniform float sunElevation;
uniform vec2 texelSize;
@ -53,13 +54,13 @@ void main() {
#ifdef NETHER_SHADER
lightCol.rgb = vec3(0.0);
averageSkyCol = vec3(0.0);
averageSkyCol_Clouds = vec3(2.0, 1.0, 0.5) * 10.0;
averageSkyCol_Clouds = vec3(2.0, 1.0, 0.5) * 5.0;
#endif
#ifdef END_SHADER
lightCol.rgb = vec3(0.0);
averageSkyCol = vec3(0.0);
averageSkyCol_Clouds = vec3(5.0);
averageSkyCol_Clouds = vec3(15);
#endif
@ -68,4 +69,6 @@ void main() {
// WsunVec = normalize(LightDir);
refractedSunVec = refract(WsunVec, -vec3(0.0,1.0,0.0), 1.0/1.33333);
exposure = texelFetch2D(colortex4,ivec2(10,37),0).r;
}

View File

@ -0,0 +1,967 @@
layout (local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
const ivec3 workGroups = ivec3(6, 6, 1);
#ifdef IS_LPV_ENABLED
#include "/lib/blocks.glsl"
#include "/lib/lpv_blocks.glsl"
const vec3 LightColor_Amethyst = vec3(0.464, 0.227, 0.788);
const vec3 LightColor_Candles = vec3(1.0, 0.4, 0.1);
const vec3 LightColor_CopperBulb = vec3(1.0);
const vec3 LightColor_LightBlock = vec3(1.0);
const vec3 LightColor_RedstoneTorch = vec3(0.939, 0.305, 0.164);
const vec3 LightColor_SeaPickle = vec3(0.283, 0.394, 0.212);
#ifdef LPV_COLORED_CANDLES
const vec3 LightColor_Candles_Black = vec3(0.200);
const vec3 LightColor_Candles_Blue = vec3(0.000, 0.259, 1.000);
const vec3 LightColor_Candles_Brown = vec3(0.459, 0.263, 0.149);
const vec3 LightColor_Candles_Cyan = vec3(0.000, 0.839, 0.839);
const vec3 LightColor_Candles_Gray = vec3(0.329, 0.357, 0.388);
const vec3 LightColor_Candles_Green = vec3(0.263, 0.451, 0.000);
const vec3 LightColor_Candles_LightBlue = vec3(0.153, 0.686, 1.000);
const vec3 LightColor_Candles_LightGray = vec3(0.631, 0.627, 0.624);
const vec3 LightColor_Candles_Lime = vec3(0.439, 0.890, 0.000);
const vec3 LightColor_Candles_Magenta = vec3(0.757, 0.098, 0.812);
const vec3 LightColor_Candles_Orange = vec3(1.000, 0.459, 0.000);
const vec3 LightColor_Candles_Pink = vec3(1.000, 0.553, 0.718);
const vec3 LightColor_Candles_Purple = vec3(0.569, 0.000, 1.000);
const vec3 LightColor_Candles_Red = vec3(0.859, 0.000, 0.000);
const vec3 LightColor_Candles_White = vec3(1.000);
const vec3 LightColor_Candles_Yellow = vec3(1.000, 0.878, 0.000);
#endif
uint BuildLpvMask(const in uint north, const in uint east, const in uint south, const in uint west, const in uint up, const in uint down) {
return east | (west << 1) | (down << 2) | (up << 3) | (south << 4) | (north << 5);
}
#endif
void main() {
#ifdef IS_LPV_ENABLED
uint blockId = uint(gl_GlobalInvocationID.x + gl_GlobalInvocationID.y * 32);
if (blockId >= 2000) return;
vec3 lightColor = vec3(0.0);
float lightRange = 0.0;
float mixWeight = 0.0;
uint mixMask = 0xFFFF;
vec3 tintColor = vec3(1.0);
switch (blockId) {
case BLOCK_WATER:
mixWeight = 0.8;
break;
case BLOCK_BAMBOO:
mixWeight = 0.8;
break;
case BLOCK_GRASS_SHORT:
case BLOCK_GRASS_TALL_UPPER:
case BLOCK_GRASS_TALL_LOWER:
mixWeight = 0.85;
break;
case BLOCK_GROUND_WAVING:
case BLOCK_GROUND_WAVING_VERTICAL:
case BLOCK_AIR_WAVING:
mixWeight = 0.9;
break;
case BLOCK_SAPLING:
mixWeight = 0.9;
break;
// lightsources
case BLOCK_AMETHYST_BUD_LARGE:
lightColor = LightColor_Amethyst;
lightRange = 4.0;
mixWeight = 0.6;
break;
case BLOCK_AMETHYST_BUD_MEDIUM:
lightColor = LightColor_Amethyst;
lightRange = 2.0;
mixWeight = 0.8;
break;
case BLOCK_AMETHYST_CLUSTER:
lightColor = LightColor_Amethyst;
lightRange = 5.0;
mixWeight = 0.4;
break;
case BLOCK_BEACON:
lightColor = vec3(1.0);
lightRange = 15.0;
break;
case BLOCK_BREWING_STAND:
lightColor = vec3(0.636, 0.509, 0.179);
lightRange = 1.0;
mixWeight = 0.8;
break;
#ifdef LPV_COLORED_CANDLES
case BLOCK_CANDLES_PLAIN_LIT_1:
lightColor = LightColor_Candles;
lightRange = 3.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_PLAIN_LIT_2:
lightColor = LightColor_Candles;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_PLAIN_LIT_3:
lightColor = LightColor_Candles;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_PLAIN_LIT_4:
lightColor = LightColor_Candles;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_BLACK_LIT_1:
lightColor = LightColor_Candles_Black;
lightRange = 3.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_BLACK_LIT_2:
lightColor = LightColor_Candles_Black;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_BLACK_LIT_3:
lightColor = LightColor_Candles_Black;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_BLACK_LIT_4:
lightColor = LightColor_Candles_Black;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_BLUE_LIT_1:
lightColor = LightColor_Candles_Blue;
lightRange = 3.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_BLUE_LIT_2:
lightColor = LightColor_Candles_Blue;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_BLUE_LIT_3:
lightColor = LightColor_Candles_Blue;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_BLUE_LIT_4:
lightColor = LightColor_Candles_Blue;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_BROWN_LIT_1:
lightColor = LightColor_Candles_Brown;
lightRange = 3.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_BROWN_LIT_2:
lightColor = LightColor_Candles_Brown;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_BROWN_LIT_3:
lightColor = LightColor_Candles_Brown;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_BROWN_LIT_4:
lightColor = LightColor_Candles_Brown;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_CYAN_LIT_1:
lightColor = LightColor_Candles_Cyan;
lightRange = 3.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_CYAN_LIT_2:
lightColor = LightColor_Candles_Cyan;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_CYAN_LIT_3:
lightColor = LightColor_Candles_Cyan;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_CYAN_LIT_4:
lightColor = LightColor_Candles_Cyan;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_GRAY_LIT_1:
lightColor = LightColor_Candles_Gray;
lightRange = 3.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_GRAY_LIT_2:
lightColor = LightColor_Candles_Gray;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_GRAY_LIT_3:
lightColor = LightColor_Candles_Gray;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_GRAY_LIT_4:
lightColor = LightColor_Candles_Gray;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_GREEN_LIT_1:
lightColor = LightColor_Candles_Green;
lightRange = 3.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_GREEN_LIT_2:
lightColor = LightColor_Candles_Green;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_GREEN_LIT_3:
lightColor = LightColor_Candles_Green;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_GREEN_LIT_4:
lightColor = LightColor_Candles_Green;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIGHT_BLUE_LIT_1:
lightColor = LightColor_Candles_LightBlue;
lightRange = 3.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIGHT_BLUE_LIT_2:
lightColor = LightColor_Candles_LightBlue;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIGHT_BLUE_LIT_3:
lightColor = LightColor_Candles_LightBlue;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIGHT_BLUE_LIT_4:
lightColor = LightColor_Candles_LightBlue;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIGHT_GRAY_LIT_1:
lightColor = LightColor_Candles_LightGray;
lightRange = 3.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIGHT_GRAY_LIT_2:
lightColor = LightColor_Candles_LightGray;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIGHT_GRAY_LIT_3:
lightColor = LightColor_Candles_LightGray;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIGHT_GRAY_LIT_4:
lightColor = LightColor_Candles_LightGray;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIME_LIT_1:
lightColor = LightColor_Candles_Lime;
lightRange = 3.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIME_LIT_2:
lightColor = LightColor_Candles_Lime;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIME_LIT_3:
lightColor = LightColor_Candles_Lime;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIME_LIT_4:
lightColor = LightColor_Candles_Lime;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_MAGENTA_LIT_1:
lightColor = LightColor_Candles_Magenta;
lightRange = 3.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_MAGENTA_LIT_2:
lightColor = LightColor_Candles_Magenta;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_MAGENTA_LIT_3:
lightColor = LightColor_Candles_Magenta;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_MAGENTA_LIT_4:
lightColor = LightColor_Candles_Magenta;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_ORANGE_LIT_1:
lightColor = LightColor_Candles_Orange;
lightRange = 3.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_ORANGE_LIT_2:
lightColor = LightColor_Candles_Orange;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_ORANGE_LIT_3:
lightColor = LightColor_Candles_Orange;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_ORANGE_LIT_4:
lightColor = LightColor_Candles_Orange;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_PINK_LIT_1:
lightColor = LightColor_Candles_Pink;
lightRange = 3.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_PINK_LIT_2:
lightColor = LightColor_Candles_Pink;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_PINK_LIT_3:
lightColor = LightColor_Candles_Pink;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_PINK_LIT_4:
lightColor = LightColor_Candles_Pink;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_PURPLE_LIT_1:
lightColor = LightColor_Candles_Purple;
lightRange = 3.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_PURPLE_LIT_2:
lightColor = LightColor_Candles_Purple;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_PURPLE_LIT_3:
lightColor = LightColor_Candles_Purple;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_PURPLE_LIT_4:
lightColor = LightColor_Candles_Purple;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_RED_LIT_1:
lightColor = LightColor_Candles_Red;
lightRange = 3.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_RED_LIT_2:
lightColor = LightColor_Candles_Red;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_RED_LIT_3:
lightColor = LightColor_Candles_Red;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_RED_LIT_4:
lightColor = LightColor_Candles_Red;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_WHITE_LIT_1:
lightColor = LightColor_Candles_White;
lightRange = 3.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_WHITE_LIT_2:
lightColor = LightColor_Candles_White;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_WHITE_LIT_3:
lightColor = LightColor_Candles_White;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_WHITE_LIT_4:
lightColor = LightColor_Candles_White;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_YELLOW_LIT_1:
lightColor = LightColor_Candles_Yellow;
lightRange = 3.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_YELLOW_LIT_2:
lightColor = LightColor_Candles_Yellow;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_YELLOW_LIT_3:
lightColor = LightColor_Candles_Yellow;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_YELLOW_LIT_4:
lightColor = LightColor_Candles_Yellow;
lightRange = 12.0;
mixWeight = 1.0;
break;
#else
case BLOCK_CANDLES_LIT_1:
lightColor = LightColor_Candles;
lightRange = 3.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIT_2:
lightColor = LightColor_Candles;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIT_3:
lightColor = LightColor_Candles;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIT_4:
lightColor = LightColor_Candles;
lightRange = 12.0;
mixWeight = 1.0;
break;
#endif
case BLOCK_CAVE_VINE_BERRIES:
lightColor = vec3(0.651, 0.369, 0.157);
lightRange = 14.0;
mixWeight = 1.0;
break;
#ifdef LPV_REDSTONE_LIGHTS
case BLOCK_COMPARATOR_LIT:
lightColor = LightColor_RedstoneTorch;
lightRange = 4.0;
break;
#endif
case BLOCK_COPPER_BULB_LIT:
lightColor = LightColor_CopperBulb;
lightRange = 15.0;
break;
case BLOCK_COPPER_BULB_EXPOSED_LIT:
lightColor = LightColor_CopperBulb;
lightRange = 12.0;
break;
case BLOCK_COPPER_BULB_OXIDIZED_LIT:
lightColor = LightColor_CopperBulb;
lightRange = 4.0;
break;
case BLOCK_COPPER_BULB_WEATHERED_LIT:
lightColor = LightColor_CopperBulb;
lightRange = 8.0;
break;
case BLOCK_CONDUIT:
lightColor = vec3(1.0);
lightRange = 15.0;
break;
case BLOCK_CRYING_OBSIDIAN:
lightColor = vec3(0.390, 0.065, 0.646);
lightRange = 10.0;
break;
case BLOCK_END_GATEWAY:
lightColor = vec3(1.0);
lightRange = 15.0;
break;
case BLOCK_END_ROD:
lightColor = vec3(0.957, 0.929, 0.875);
lightRange = 14.0;
break;
case BLOCK_FIRE:
lightColor = vec3(0.864, 0.598, 0.348);
lightRange = 15.0;
mixWeight = 1.0;
break;
case BLOCK_FROGLIGHT_OCHRE:
lightColor = vec3(0.768, 0.648, 0.108);
lightRange = 15.0;
break;
case BLOCK_FROGLIGHT_PEARLESCENT:
lightColor = vec3(0.737, 0.435, 0.658);
lightRange = 15.0;
break;
case BLOCK_FROGLIGHT_VERDANT:
lightColor = vec3(0.463, 0.763, 0.409);
lightRange = 15.0;
break;
case BLOCK_GLOW_LICHEN:
lightColor = vec3(0.092, 0.217, 0.126);
lightRange = 7.0;
break;
case BLOCK_GLOWSTONE:
lightColor = vec3(0.747, 0.594, 0.326);
lightRange = 15.0;
break;
case BLOCK_JACK_O_LANTERN:
lightColor = vec3(0.864, 0.598, 0.348);
lightRange = 15.0;
break;
case BLOCK_LANTERN:
lightColor = vec3(0.839, 0.541, 0.2);
lightRange = 15.0;
mixWeight = 0.8;
break;
case BLOCK_LAVA:
lightColor = vec3(0.659, 0.302, 0.106);
lightRange = 15.0;
break;
case BLOCK_LIGHT_1:
lightColor = LightColor_LightBlock;
lightRange = 1;
mixWeight = 1.0;
break;
case BLOCK_LIGHT_2:
lightColor = LightColor_LightBlock;
lightRange = 2;
mixWeight = 1.0;
break;
case BLOCK_LIGHT_3:
lightColor = LightColor_LightBlock;
lightRange = 3;
mixWeight = 1.0;
break;
case BLOCK_LIGHT_4:
lightColor = LightColor_LightBlock;
lightRange = 4;
mixWeight = 1.0;
break;
case BLOCK_LIGHT_5:
lightColor = LightColor_LightBlock;
lightRange = 5;
mixWeight = 1.0;
break;
case BLOCK_LIGHT_6:
lightColor = LightColor_LightBlock;
lightRange = 6;
mixWeight = 1.0;
break;
case BLOCK_LIGHT_7:
lightColor = LightColor_LightBlock;
lightRange = 7;
mixWeight = 1.0;
break;
case BLOCK_LIGHT_8:
lightColor = LightColor_LightBlock;
lightRange = 8;
mixWeight = 1.0;
break;
case BLOCK_LIGHT_9:
lightColor = LightColor_LightBlock;
lightRange = 9;
mixWeight = 1.0;
break;
case BLOCK_LIGHT_10:
lightColor = LightColor_LightBlock;
lightRange = 10;
mixWeight = 1.0;
break;
case BLOCK_LIGHT_11:
lightColor = LightColor_LightBlock;
lightRange = 11;
mixWeight = 1.0;
break;
case BLOCK_LIGHT_12:
lightColor = LightColor_LightBlock;
lightRange = 12;
mixWeight = 1.0;
break;
case BLOCK_LIGHT_13:
lightColor = LightColor_LightBlock;
lightRange = 13;
mixWeight = 1.0;
break;
case BLOCK_LIGHT_14:
lightColor = LightColor_LightBlock;
lightRange = 14;
mixWeight = 1.0;
break;
case BLOCK_LIGHT_15:
lightColor = LightColor_LightBlock;
lightRange = 15;
mixWeight = 1.0;
break;
case BLOCK_MAGMA:
lightColor = vec3(0.747, 0.323, 0.110);
lightRange = 3.0;
break;
case BLOCK_REDSTONE_LAMP_LIT:
lightColor = vec3(0.953, 0.796, 0.496);
lightRange = 15.0;
break;
case BLOCK_REDSTONE_TORCH_LIT:
lightColor = LightColor_RedstoneTorch;
lightRange = 7.0;
break;
#ifdef LPV_REDSTONE_LIGHTS
case BLOCK_REDSTONE_WIRE_1:
lightColor = LightColor_RedstoneTorch;
lightRange = 0.5;
break;
case BLOCK_REDSTONE_WIRE_2:
lightColor = LightColor_RedstoneTorch;
lightRange = 1.0;
break;
case BLOCK_REDSTONE_WIRE_3:
lightColor = LightColor_RedstoneTorch;
lightRange = 1.5;
break;
case BLOCK_REDSTONE_WIRE_4:
lightColor = LightColor_RedstoneTorch;
lightRange = 2.0;
break;
case BLOCK_REDSTONE_WIRE_5:
lightColor = LightColor_RedstoneTorch;
lightRange = 2.5;
break;
case BLOCK_REDSTONE_WIRE_6:
lightColor = LightColor_RedstoneTorch;
lightRange = 3.0;
break;
case BLOCK_REDSTONE_WIRE_7:
lightColor = LightColor_RedstoneTorch;
lightRange = 3.5;
break;
case BLOCK_REDSTONE_WIRE_8:
lightColor = LightColor_RedstoneTorch;
lightRange = 4.0;
break;
case BLOCK_REDSTONE_WIRE_9:
lightColor = LightColor_RedstoneTorch;
lightRange = 4.5;
break;
case BLOCK_REDSTONE_WIRE_10:
lightColor = LightColor_RedstoneTorch;
lightRange = 5.0;
break;
case BLOCK_REDSTONE_WIRE_11:
lightColor = LightColor_RedstoneTorch;
lightRange = 5.5;
break;
case BLOCK_REDSTONE_WIRE_12:
lightColor = LightColor_RedstoneTorch;
lightRange = 6.0;
break;
case BLOCK_REDSTONE_WIRE_13:
lightColor = LightColor_RedstoneTorch;
lightRange = 6.5;
break;
case BLOCK_REDSTONE_WIRE_14:
lightColor = LightColor_RedstoneTorch;
lightRange = 7.0;
break;
case BLOCK_REDSTONE_WIRE_15:
lightColor = LightColor_RedstoneTorch;
lightRange = 7.5;
break;
case BLOCK_REPEATER_LIT:
lightColor = LightColor_RedstoneTorch;
lightRange = 4.0;
break;
#endif
case BLOCK_RESPAWN_ANCHOR_4:
lightColor = vec3(1.0, 0.2, 1.0);
lightRange = 15.0;
break;
case BLOCK_SCULK_SENSOR_ACTIVE:
lightColor = vec3(0.1, 0.4, 1.0);
lightRange = 1.0;
break;
case BLOCK_SEA_PICKLE_WET_1:
lightColor = LightColor_SeaPickle;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_SEA_PICKLE_WET_2:
lightColor = LightColor_SeaPickle;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_SEA_PICKLE_WET_3:
lightColor = LightColor_SeaPickle;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_SEA_PICKLE_WET_4:
lightColor = LightColor_SeaPickle;
lightRange = 15.0;
mixWeight = 1.0;
break;
case BLOCK_SEA_LANTERN:
lightColor = vec3(0.553, 0.748, 0.859);
lightRange = 15.0;
break;
case BLOCK_SHROOMLIGHT:
lightColor = vec3(0.848, 0.469, 0.205);
lightRange = 15.0;
break;
case BLOCK_SMOKER_LIT:
lightColor = vec3(0.8, 0.7, 0.1);
lightRange = 13.0;
break;
case BLOCK_SOUL_FIRE:
lightColor = vec3(0.1, 0.6, 1.0);
lightRange = 10.0;
mixWeight = 1.0;
break;
case BLOCK_SOUL_LANTERN:
case BLOCK_SOUL_TORCH:
lightColor = vec3(0.1, 0.6, 1.0);
lightRange = 10.0;
mixWeight = 0.8;
break;
case BLOCK_TORCH:
lightColor = vec3(1.0, 0.6, 0.1);
lightRange = 14.0;
mixWeight = 0.8;
break;
// reflective translucents / glass
case BLOCK_HONEY:
tintColor = vec3(0.984, 0.733, 0.251);
mixWeight = 1.0;
break;
case BLOCK_NETHER_PORTAL:
lightColor = vec3(0.502, 0.165, 0.831);
tintColor = vec3(0.502, 0.165, 0.831);
lightRange = 11.0;
mixWeight = 1.0;
break;
case BLOCK_SLIME:
tintColor = vec3(0.408, 0.725, 0.329);
mixWeight = 1.0;
break;
case BLOCK_GLASS_BLACK:
tintColor = vec3(0.3);
mixWeight = 1.0;
break;
case BLOCK_GLASS_BLUE:
tintColor = vec3(0.1, 0.1, 0.98);
mixWeight = 1.0;
break;
case BLOCK_GLASS_BROWN:
tintColor = vec3(0.566, 0.388, 0.148);
mixWeight = 1.0;
break;
case BLOCK_GLASS_CYAN:
tintColor = vec3(0.082, 0.533, 0.763);
mixWeight = 1.0;
break;
case BLOCK_GLASS_GRAY:
tintColor = vec3(0.4, 0.4, 0.4);
mixWeight = 1.0;
break;
case BLOCK_GLASS_GREEN:
tintColor = vec3(0.125, 0.808, 0.081);
mixWeight = 1.0;
break;
case BLOCK_GLASS_LIGHT_BLUE:
tintColor = vec3(0.320, 0.685, 0.955);
mixWeight = 1.0;
break;
case BLOCK_GLASS_LIGHT_GRAY:
tintColor = vec3(0.7);
mixWeight = 1.0;
break;
case BLOCK_GLASS_LIME:
tintColor = vec3(0.633, 0.924, 0.124);
mixWeight = 1.0;
break;
case BLOCK_GLASS_MAGENTA:
tintColor = vec3(0.698, 0.298, 0.847);
mixWeight = 1.0;
break;
case BLOCK_GLASS_ORANGE:
tintColor = vec3(0.919, 0.586, 0.185);
mixWeight = 1.0;
break;
case BLOCK_GLASS_PINK:
tintColor = vec3(0.949, 0.274, 0.497);
mixWeight = 1.0;
break;
case BLOCK_GLASS_PURPLE:
tintColor = vec3(0.578, 0.170, 0.904);
mixWeight = 1.0;
break;
case BLOCK_GLASS_RED:
tintColor = vec3(0.999, 0.188, 0.188);
mixWeight = 1.0;
break;
case BLOCK_GLASS_WHITE:
tintColor = vec3(0.96, 0.96, 0.96);
mixWeight = 1.0;
break;
case BLOCK_GLASS_YELLOW:
tintColor = vec3(0.965, 0.965, 0.123);
mixWeight = 1.0;
break;
// LPV shapes
case BLOCK_BUTTON:
mixWeight = 0.9;
break;
case BLOCK_CANDLE:
mixWeight = 1.0;
break;
case BLOCK_CARPET:
mixMask = BuildLpvMask(1u, 1u, 1u, 1u, 1u, 0u);
mixWeight = 0.9;
break;
case BLOCK_CHAIN:
mixWeight = 1.0;
break;
case BLOCK_DOOR_N:
mixMask = BuildLpvMask(0u, 1u, 1u, 1u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_DOOR_E:
mixMask = BuildLpvMask(1u, 0u, 1u, 1u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_DOOR_S:
mixMask = BuildLpvMask(1u, 1u, 0u, 1u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_DOOR_W:
mixMask = BuildLpvMask(1u, 1u, 1u, 0u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_FENCE:
case BLOCK_FENCE_GATE:
mixWeight = 0.7;
break;
case BLOCK_FLOWER_POT:
mixWeight = 0.7;
break;
case BLOCK_IRON_BARS:
mixWeight = 0.6;
break;
case BLOCK_LADDER:
mixWeight = 0.7;
break;
case BLOCK_LEVER:
mixWeight = 0.8;
break;
case BLOCK_PRESSURE_PLATE:
mixMask = BuildLpvMask(1u, 1u, 1u, 1u, 1u, 0u);
mixWeight = 0.9;
break;
case BLOCK_SLAB_TOP:
mixMask = BuildLpvMask(1u, 1u, 1u, 1u, 0u, 1u);
mixWeight = 0.5;
break;
case BLOCK_SLAB_BOTTOM:
mixMask = BuildLpvMask(1u, 1u, 1u, 1u, 1u, 0u);
mixWeight = 0.5;
break;
case BLOCK_TRAPDOOR_BOTTOM:
mixMask = BuildLpvMask(1u, 1u, 1u, 1u, 1u, 0u);
mixWeight = 0.8;
break;
case BLOCK_TRAPDOOR_TOP:
mixMask = BuildLpvMask(1u, 1u, 1u, 1u, 0u, 1u);
mixWeight = 0.8;
break;
case BLOCK_TRAPDOOR_N:
mixMask = BuildLpvMask(0u, 1u, 1u, 1u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_TRAPDOOR_E:
mixMask = BuildLpvMask(1u, 0u, 1u, 1u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_TRAPDOOR_S:
mixMask = BuildLpvMask(1u, 1u, 0u, 1u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_TRAPDOOR_W:
mixMask = BuildLpvMask(1u, 1u, 1u, 0u, 1u, 1u);
mixWeight = 0.8;
break;
// Misc
case BLOCK_SIGN:
mixWeight = 0.9;
break;
}
// hack to increase light (if set)
if (lightRange > 0.0) lightRange += 1.0;
LpvBlockData block;
block.ColorRange = packUnorm4x8(vec4(lightColor, lightRange/255.0));
block.MaskWeight = BuildBlockLpvData(mixMask, mixWeight);
block.Tint = packUnorm4x8(vec4(tintColor, 0.0));
LpvBlockMap[blockId] = block;
#endif
}

View File

@ -0,0 +1,160 @@
#define RENDER_SHADOWCOMP
layout (local_size_x = 8, local_size_y = 8, local_size_z = 8) in;
#if LPV_SIZE == 8
const ivec3 workGroups = ivec3(32, 32, 32);
#elif LPV_SIZE == 7
const ivec3 workGroups = ivec3(16, 16, 16);
#elif LPV_SIZE == 6
const ivec3 workGroups = ivec3(8, 8, 8);
#endif
#ifdef IS_LPV_ENABLED
shared vec4 lpvSharedData[10*10*10];
shared uint voxelSharedData[10*10*10];
const vec2 LpvBlockSkyFalloff = vec2(0.96, 0.96);
const ivec3 lpvFlatten = ivec3(1, 10, 100);
#define EPSILON 1e-6
uniform int frameCounter;
uniform vec3 cameraPosition;
uniform vec3 previousCameraPosition;
#include "/lib/hsv.glsl"
#include "/lib/util.glsl"
#include "/lib/blocks.glsl"
#include "/lib/lpv_common.glsl"
#include "/lib/lpv_blocks.glsl"
#include "/lib/lpv_buffer.glsl"
#include "/lib/voxel_common.glsl"
int sumOf(ivec3 vec) {return vec.x + vec.y + vec.z;}
vec3 Lpv_RgbToHsv(const in vec3 lightColor, const in float lightRange) {
vec3 lightValue = RgbToHsv(lightColor);
lightValue.b = lightRange / LpvBlockSkyRange.x;
return lightValue;
}
vec4 GetLpvValue(in ivec3 texCoord) {
if (clamp(texCoord, ivec3(0), ivec3(LpvSize) - 1) != texCoord) return vec4(0.0);
vec4 lpvSample = (frameCounter % 2) == 0
? imageLoad(imgLpv2, texCoord)
: imageLoad(imgLpv1, texCoord);
lpvSample.ba = exp2(lpvSample.ba * LpvBlockSkyRange) - 1.0;
lpvSample.rgb = HsvToRgb(lpvSample.rgb);
return lpvSample;
}
int getSharedIndex(ivec3 pos) {
return sumOf(pos * lpvFlatten);
}
vec4 sampleShared(ivec3 pos, int mask_index) {
int shared_index = getSharedIndex(pos + 1);
float mixWeight = 1.0;
uint mixMask = 0xFFFF;
uint blockId = voxelSharedData[shared_index];
if (blockId > 0 && blockId != BLOCK_EMPTY)
ParseBlockLpvData(LpvBlockMap[blockId].MaskWeight, mixMask, mixWeight);
return lpvSharedData[shared_index] * ((mixMask >> mask_index) & 1u);// * mixWeight;
}
vec4 mixNeighbours(const in ivec3 fragCoord, const in uint mask) {
vec4 nX1 = sampleShared(fragCoord + ivec3(-1, 0, 0), 1) * ((mask ) & 1u);
vec4 nX2 = sampleShared(fragCoord + ivec3( 1, 0, 0), 0) * ((mask >> 1) & 1u);
vec4 nY1 = sampleShared(fragCoord + ivec3( 0, -1, 0), 3) * ((mask >> 2) & 1u);
vec4 nY2 = sampleShared(fragCoord + ivec3( 0, 1, 0), 2) * ((mask >> 3) & 1u);
vec4 nZ1 = sampleShared(fragCoord + ivec3( 0, 0, -1), 5) * ((mask >> 4) & 1u);
vec4 nZ2 = sampleShared(fragCoord + ivec3( 0, 0, 1), 4) * ((mask >> 5) & 1u);
const vec4 avgFalloff = (1.0/6.0) * LpvBlockSkyFalloff.xxxy;
return (nX1 + nX2 + nY1 + nY2 + nZ1 + nZ2) * avgFalloff;
}
uint GetVoxelBlock(const in ivec3 voxelPos) {
if (clamp(voxelPos, ivec3(0), ivec3(VoxelSize3-1u)) != voxelPos)
return BLOCK_EMPTY;
return imageLoad(imgVoxelMask, voxelPos).r;
}
void PopulateSharedIndex(const in ivec3 imgCoordOffset, const in ivec3 workGroupOffset, const in uint i) {
ivec3 pos = workGroupOffset + ivec3(i / lpvFlatten) % 10;
lpvSharedData[i] = GetLpvValue(imgCoordOffset + pos);
voxelSharedData[i] = GetVoxelBlock(pos);
}
#endif
////////////////////////////// VOID MAIN //////////////////////////////
void main() {
#ifdef IS_LPV_ENABLED
uvec3 chunkPos = gl_WorkGroupID * gl_WorkGroupSize;
if (any(greaterThanEqual(chunkPos, LpvSize3))) return;
uint i = uint(gl_LocalInvocationIndex) * 2u;
if (i < 1000u) {
ivec3 imgCoordOffset = ivec3(floor(cameraPosition) - floor(previousCameraPosition));
ivec3 workGroupOffset = ivec3(gl_WorkGroupID * gl_WorkGroupSize) - 1;
PopulateSharedIndex(imgCoordOffset, workGroupOffset, i);
PopulateSharedIndex(imgCoordOffset, workGroupOffset, i + 1u);
}
barrier();
ivec3 imgCoord = ivec3(gl_GlobalInvocationID);
if (any(greaterThanEqual(imgCoord, LpvSize3))) return;
uint blockId = voxelSharedData[getSharedIndex(ivec3(gl_LocalInvocationID) + 1)];
vec4 lightValue = vec4(0.0);
vec3 tintColor = vec3(1.0);
float mixWeight = 1.0;
uint mixMask = 0xFFFF;
if (blockId > 0u) {
mixWeight = 0.0;
ParseBlockLpvData(LpvBlockMap[blockId].MaskWeight, mixMask, mixWeight);
uint tintData = LpvBlockMap[blockId].Tint;
tintColor = unpackUnorm4x8(tintData).rgb;
}
if (mixWeight > EPSILON) {
vec4 lightMixed = mixNeighbours(ivec3(gl_LocalInvocationID), mixMask);
lightMixed.rgb *= srgbToLinear(tintColor) * mixWeight;
lightValue += lightMixed;
}
lightValue.rgb = RgbToHsv(lightValue.rgb);
lightValue.ba = log2(lightValue.ba + 1.0) / LpvBlockSkyRange;
if (blockId > 0u) {
vec4 lightColorRange = unpackUnorm4x8(LpvBlockMap[blockId].ColorRange);
float lightRange = lightColorRange.a * 255.0;
if (lightRange > EPSILON) {
vec3 lightColor = srgbToLinear(lightColorRange.rgb);
lightValue.rgb = Lpv_RgbToHsv(lightColor, lightRange);
}
}
if (frameCounter % 2 == 0)
imageStore(imgLpv1, imgCoord, lightValue);
else
imageStore(imgLpv2, imgCoord, lightValue);
#endif
}