mirror of
https://github.com/X0nk/Bliss-Shader.git
synced 2025-06-22 00:37:35 +08:00
tweaks to subsurface scattering, improve SSS in the distance. make screenspace shadows have consistent step length across all window resolutions. tweak torch lighting (make it slightly brighter and a warmer color). tweak TAA handling of the hand. tweak specular reflection handling of the hand to be slightly more stable. make the shader use moonPosition instead of inverted sunPosition for moon related code. add support for Caelium moon positions. improve water parallax. remove some unused code improve specular handling of translucent entities with inside faces (slimes). add settings for refraction effects. re-enable block breaking effect and glass tint (it was off accidentally lol)
This commit is contained in:
@ -296,9 +296,9 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
vec3 waterNormals = worldSpaceNormals;
|
||||
|
||||
if(iswater && abs(worldSpaceNormals.y) > 0.1){
|
||||
vec3 posxz = playerPos+cameraPosition;
|
||||
|
||||
vec3 bump = normalize(getWaveNormal(posxz, true));
|
||||
vec3 waterPos = (playerPos+cameraPosition).xzy;
|
||||
|
||||
vec3 bump = normalize(getWaveNormal(waterPos, playerPos, true));
|
||||
|
||||
float bumpmult = 10.0 * WATER_WAVE_STRENGTH;
|
||||
|
||||
@ -458,7 +458,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
#if DEBUG_VIEW == debug_DH_WATER_BLENDING
|
||||
if(gl_FragCoord.x*texelSize.x > 0.53) gl_FragData[0] = vec4(0.0);
|
||||
#endif
|
||||
|
||||
|
||||
gl_FragData[1] = vec4(Albedo, material);
|
||||
}
|
||||
}
|
@ -293,7 +293,8 @@ void main() {
|
||||
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
|
||||
mc_Entity.x == BLOCK_SSS_STRONG || mc_Entity.x == BLOCK_SAPLING
|
||||
/*|| (mc_Entity.x >= 410 && mc_Entity.x <= 415) || (mc_Entity.x >= 402 && mc_Entity.x <= 405) THIS IS FOR MCME NEW TREES.*/
|
||||
) {
|
||||
SSSAMOUNT = 1.0;
|
||||
}
|
||||
@ -307,9 +308,10 @@ void main() {
|
||||
) {
|
||||
SSSAMOUNT = 0.5;
|
||||
}
|
||||
|
||||
// low
|
||||
#ifdef MISC_BLOCK_SSS
|
||||
if(mc_Entity.x == BLOCK_SSS_WEIRD || mc_Entity.x == BLOCK_GRASS) 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.25;
|
||||
#endif
|
||||
|
||||
#ifdef ENTITIES
|
||||
|
@ -89,7 +89,6 @@ uniform float skyIntensity;
|
||||
uniform ivec2 eyeBrightnessSmooth;
|
||||
uniform float nightVision;
|
||||
|
||||
|
||||
uniform int frameCounter;
|
||||
uniform float frameTimeCounter;
|
||||
uniform vec2 texelSize;
|
||||
@ -100,7 +99,6 @@ uniform float viewHeight;
|
||||
uniform mat4 gbufferPreviousModelView;
|
||||
uniform vec3 previousCameraPosition;
|
||||
|
||||
|
||||
uniform float moonIntensity;
|
||||
uniform float sunIntensity;
|
||||
uniform vec3 sunColor;
|
||||
@ -115,7 +113,6 @@ uniform float waterEnteredAltitude;
|
||||
#include "/lib/sky_gradient.glsl"
|
||||
#include "/lib/waterBump.glsl"
|
||||
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
flat varying float Flashing;
|
||||
#include "/lib/lightning_stuff.glsl"
|
||||
@ -155,11 +152,13 @@ float interleaved_gradientNoise_temporal(){
|
||||
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887);
|
||||
#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;
|
||||
}
|
||||
|
||||
float R2_dither(){
|
||||
vec2 coord = gl_FragCoord.xy ;
|
||||
|
||||
@ -170,6 +169,7 @@ float R2_dither(){
|
||||
vec2 alpha = vec2(0.75487765, 0.56984026);
|
||||
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
|
||||
}
|
||||
|
||||
float blueNoise(){
|
||||
#ifdef TAA
|
||||
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
|
||||
@ -178,29 +178,23 @@ float blueNoise(){
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#include "/lib/TAA_jitter.glsl"
|
||||
|
||||
|
||||
#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 playerPos) {
|
||||
vec3 getParallaxDisplacement(vec3 waterPos, vec3 playerPos) {
|
||||
|
||||
float waterHeight = getWaterHeightmap(-playerPos.xz) ;
|
||||
float waterHeight = getWaterHeightmap(waterPos.xy) ;
|
||||
waterHeight = exp(-20*sqrt(waterHeight));
|
||||
// waterHeight *= 2.0;
|
||||
// waterHeight *= 5.0;
|
||||
|
||||
vec3 parallaxPos = playerPos;
|
||||
vec3 parallaxPos = waterPos;
|
||||
|
||||
parallaxPos.xz += (viewVector.xy / -viewVector.z) * waterHeight;
|
||||
// parallaxPos.xz -= (viewVec.xy / viewVec.z) * waterHeight * 0.5;
|
||||
parallaxPos.xy += (viewVector.xy / -viewVector.z) * waterHeight;
|
||||
// parallaxPos.xz -= (viewVector.xy / viewVector.z) * waterHeight;
|
||||
|
||||
return parallaxPos;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
@ -244,6 +238,7 @@ vec3 worldToView(vec3 worldPos) {
|
||||
pos = gbufferModelView * pos;
|
||||
return pos.xyz;
|
||||
}
|
||||
|
||||
vec4 encode (vec3 n, vec2 lightmaps){
|
||||
n.xy = n.xy / dot(abs(n), vec3(1.0));
|
||||
n.xy = n.z <= 0.0 ? (1.0 - abs(n.yx)) * sign(n.xy) : n.xy;
|
||||
@ -258,11 +253,11 @@ float encodeVec2(vec2 a){
|
||||
vec2 temp = floor( a * 255. );
|
||||
return temp.x*constant1.x+temp.y*constant1.y;
|
||||
}
|
||||
|
||||
float encodeVec2(float x,float y){
|
||||
return encodeVec2(vec2(x,y));
|
||||
}
|
||||
|
||||
|
||||
float ld(float dist) {
|
||||
return (2.0 * near) / (far + near - dist * (far - near));
|
||||
}
|
||||
@ -397,7 +392,6 @@ uniform vec3 eyePosition;
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
|
||||
|
||||
/* RENDERTARGETS:2,7,11,14 */
|
||||
|
||||
|
||||
@ -426,10 +420,10 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
// 0.9 = entity mask
|
||||
// 0.8 = reflective entities
|
||||
// 0.7 = reflective blocks
|
||||
// 0.1 = hand mask
|
||||
// 0.3 = hand mask
|
||||
|
||||
#ifdef HAND
|
||||
MATERIALS = 0.1;
|
||||
MATERIALS = 0.3;
|
||||
#endif
|
||||
|
||||
// bool isHand = abs(MATERIALS - 0.1) < 0.01;
|
||||
@ -504,13 +498,22 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
|
||||
#ifndef HAND
|
||||
if (isWater){
|
||||
vec3 posxz = (mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz) + cameraPosition;
|
||||
vec3 playerPos = (mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz);
|
||||
vec3 waterPos = playerPos;
|
||||
|
||||
vec3 flowDir = normalize(worldSpaceNormal*10.0) * frameTimeCounter * 2.0 * WATER_WAVE_SPEED;
|
||||
|
||||
vec2 newPos = playerPos.xy + cameraPosition.xy + abs(flowDir.xz);
|
||||
newPos = mix(newPos, playerPos.zy + cameraPosition.zy + abs(flowDir.zx), clamp(abs(worldSpaceNormal.x),0,1));
|
||||
newPos = mix(newPos, playerPos.xz + cameraPosition.xz, clamp(abs(worldSpaceNormal.y),0,1));
|
||||
waterPos.xy = newPos;
|
||||
|
||||
// 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 + normalize(worldSpaceNormal.xz*10.0) * frameTimeCounter * 3.0 * WATER_WAVE_SPEED;
|
||||
// if(abs(worldSpaceNormal.y) < 0.9995) posxz.xz -= posxz.y + normalize(worldSpaceNormal.xz*10.0) * frameTimeCounter * 3.0 * WATER_WAVE_SPEED;
|
||||
|
||||
posxz.xyz = getParallaxDisplacement(posxz);
|
||||
vec3 bump = normalize(getWaveNormal(posxz, false));
|
||||
waterPos.xyz = getParallaxDisplacement(waterPos, playerPos);
|
||||
|
||||
vec3 bump = normalize(getWaveNormal(waterPos, playerPos, false));
|
||||
|
||||
float bumpmult = 10.0 * WATER_WAVE_STRENGTH;
|
||||
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
|
||||
@ -601,12 +604,12 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
|
||||
vec3 AmbientLightColor = averageSkyCol_Clouds/900.0;
|
||||
|
||||
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.2);
|
||||
vec3 indirectNormal = worldSpaceNormal / dot(abs(worldSpaceNormal),vec3(1.0));
|
||||
float SkylightDir = clamp(indirectNormal.y*0.7+0.3,0.0,1.0);
|
||||
|
||||
float skylight = mix(0.2 + 2.3*(1.0-lightmap.y), 2.5, SkylightDir);
|
||||
AmbientLightColor *= skylight;
|
||||
|
||||
|
||||
Indirect_lighting = doIndirectLighting(AmbientLightColor, MinimumLightColor, lightmap.y);
|
||||
#endif
|
||||
|
||||
@ -659,17 +662,6 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
|
||||
vec3 FinalColor = (Indirect_lighting + Direct_lighting) * Albedo;
|
||||
|
||||
// vec4 vlBehingTranslucents = texture2D(colortex13, gl_FragCoord.xy*texelSize * VL_RENDER_RESOLUTION).rgba;
|
||||
|
||||
// vec3 totEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);// dirtEpsilon*dirtAmount + waterEpsilon;
|
||||
// vec3 scatterCoef = Dirt_Amount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
|
||||
|
||||
// vec3 transmittance = exp(-totEpsilon * vlBehingTranslucents.a*50);
|
||||
// FinalColor *= transmittance;
|
||||
|
||||
// FinalColor = FinalColor * vlBehingTranslucents.a +vlBehingTranslucents.rgb ;
|
||||
|
||||
|
||||
#if EMISSIVE_TYPE == 2 || EMISSIVE_TYPE == 3
|
||||
Emission(FinalColor, Albedo, SpecularTex.b, exposure);
|
||||
#endif
|
||||
@ -696,8 +688,11 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
if(SpecularTex.r > 0.0 && SpecularTex.g <= 1.0) specularValues = SpecularTex.rg;
|
||||
|
||||
float f0 = isReflective ? max(specularValues.g, harcodedF0) : specularValues.g;
|
||||
bool isHand = false;
|
||||
|
||||
|
||||
#ifdef HAND
|
||||
isHand = true;
|
||||
f0 = max(specularValues.g, harcodedF0);
|
||||
#endif
|
||||
|
||||
@ -711,13 +706,13 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
float reflectance = 0.0;
|
||||
|
||||
#if !defined OVERWORLD_SHADER
|
||||
|
||||
vec3 WsunVec = vec3(0.0);
|
||||
vec3 DirectLightColor = WsunVec;
|
||||
float Shadows = 0.0;
|
||||
#endif
|
||||
|
||||
vec3 specularReflections = specularReflections(viewPos, normalize(feetPlayerPos), WsunVec, vec3(blueNoise(), vec2(interleaved_gradientNoise_temporal())), viewToWorld(normal), roughness, f0, Albedo, FinalColor*gl_FragData[0].a, DirectLightColor * Shadows, lightmap.y, false, reflectance);
|
||||
|
||||
|
||||
vec3 specularReflections = specularReflections(viewPos, normalize(feetPlayerPos), WsunVec, vec3(blueNoise(), vec2(interleaved_gradientNoise_temporal())), viewToWorld(normal), roughness, f0, Albedo, FinalColor*gl_FragData[0].a, DirectLightColor * Shadows, lightmap.y, isHand, reflectance);
|
||||
|
||||
gl_FragData[0].a = gl_FragData[0].a + (1.0-gl_FragData[0].a) * reflectance;
|
||||
|
||||
@ -731,7 +726,13 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
gl_FragData[0].rgb = FinalColor*0.1;
|
||||
#endif
|
||||
|
||||
|
||||
#if defined ENTITIES
|
||||
// do not allow specular to be very visible in these regions on entities
|
||||
// this helps with specular on slimes, and entities with skin overlays like piglins/players
|
||||
if (!gl_FrontFacing) {
|
||||
gl_FragData[0] = vec4(FinalColor*0.1, UnchangedAlpha);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined DISTANT_HORIZONS && defined DH_OVERDRAW_PREVENTION && !defined HAND
|
||||
#if OVERDRAW_MAX_DISTANCE == 0
|
||||
@ -745,9 +746,8 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
if(WATER) gl_FragData[0].a = 0.0;
|
||||
#endif
|
||||
|
||||
#ifndef HAND
|
||||
gl_FragData[1] = vec4(Albedo, MATERIALS);
|
||||
#endif
|
||||
gl_FragData[1] = vec4(Albedo, MATERIALS);
|
||||
|
||||
#if DEBUG_VIEW == debug_DH_WATER_BLENDING
|
||||
if(gl_FragCoord.x*texelSize.x < 0.47) gl_FragData[0] = vec4(0.0);
|
||||
#endif
|
||||
@ -762,8 +762,6 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
gl_FragData[0].rgb = Direct_lighting * 0.1;
|
||||
#endif
|
||||
|
||||
// gl_FragData[0] = vec4(tbnMatrix * viewPos,1);
|
||||
|
||||
gl_FragData[3] = vec4(encodeVec2(lightmap.x, lightmap.y), 1, 1, 1);
|
||||
|
||||
#if defined ENTITIES && defined IS_IRIS
|
||||
|
@ -55,6 +55,7 @@ attribute vec4 mc_Entity;
|
||||
|
||||
|
||||
uniform vec3 sunPosition;
|
||||
uniform vec3 moonPosition;
|
||||
uniform vec3 cameraPosition;
|
||||
uniform float sunElevation;
|
||||
|
||||
@ -207,8 +208,15 @@ void main() {
|
||||
|
||||
averageSkyCol_Clouds = texelFetch2D(colortex4,ivec2(0,37),0).rgb;
|
||||
|
||||
WsunVec = lightCol.a * normalize(mat3(gbufferModelViewInverse) * sunPosition);
|
||||
// WsunVec = normalize(LightDir);
|
||||
// WsunVec = lightCol.a * normalize(mat3(gbufferModelViewInverse) * sunPosition);
|
||||
|
||||
WsunVec = normalize(mat3(gbufferModelViewInverse) * sunPosition);
|
||||
vec3 moonVec = normalize(mat3(gbufferModelViewInverse) * moonPosition);
|
||||
vec3 WmoonVec = moonVec;
|
||||
if(dot(-moonVec, WsunVec) < 0.9999) WmoonVec = -moonVec;
|
||||
|
||||
WsunVec = mix(WmoonVec, WsunVec, clamp(lightCol.a,0,1));
|
||||
|
||||
|
||||
#if defined Daily_Weather
|
||||
dailyWeatherParams0 = vec4(texelFetch2D(colortex4,ivec2(1,1),0).rgb / 1500.0, 0.0);
|
||||
|
@ -253,7 +253,7 @@ float convertHandDepth_2(in float depth, bool hand) {
|
||||
vec2 SSAO(
|
||||
vec3 viewPos, vec3 normal, vec3 flatnormal, bool hand, bool leaves, float noise
|
||||
){
|
||||
int samples = 14;
|
||||
int samples = 7;
|
||||
float occlusion = 0.0;
|
||||
float sss = 0.0;
|
||||
float THING = 0.0;
|
||||
@ -265,8 +265,6 @@ vec2 SSAO(
|
||||
float distanceScale = hand ? 30.0 : mix(40.0, 10.0, pow(clamp(1.0 - linearViewDistance/50.0,0.0,1.0),2.0));
|
||||
float depthCancelation = (linearViewDistance*linearViewDistance) / distanceScale ;
|
||||
|
||||
// float leaf = leaves ? -0.5 : 0.0;
|
||||
|
||||
int n = 0;
|
||||
for (int i = 0; i < samples; i++) {
|
||||
|
||||
@ -299,141 +297,19 @@ vec2 SSAO(
|
||||
#ifdef OLD_INDIRECT_SSS
|
||||
sss += clamp(-dot(normalize(viewPosDiff), flatnormal),0.0,1.0) * exp(-10*occlusion);
|
||||
#else
|
||||
sss += clamp(-dot(normalize(viewPosDiff), flatnormal) - occlusion/n,0.0,1.0) * 0.25
|
||||
+ min(-normalize(mat3(gbufferModelViewInverse) * viewPosDiff).y - occlusion/n,1.0) * threshHold;
|
||||
// + min(-dot(normalize(mat3(gbufferModelViewInverse) * viewPosDiff),clamp(normalize(WsunVec),-vec3(0.35,1.0,0.35),vec3(0.35,1.0,0.35))) - occlusion/n,1.0) * threshHold;
|
||||
sss += clamp(-dot(normalize(viewPosDiff), flatnormal) - occlusion/n,0.0,1.0) * 0.25 + (normalize(mat3(gbufferModelViewInverse) * -viewPosDiff).y - occlusion/n) * threshHold;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float finaalAO = max(1.0 - occlusion*AO_Strength/n, 0.0);
|
||||
float finalSSS = sss/n;
|
||||
|
||||
return vec2(finaalAO, finalSSS);
|
||||
}
|
||||
|
||||
|
||||
float ScreenSpace_SSS(
|
||||
vec3 viewPos, vec3 normal, bool hand, bool leaves, float noise
|
||||
){
|
||||
int samples = 7;
|
||||
float occlusion = 0.0;
|
||||
float sss = 0.0;
|
||||
|
||||
vec3 normalizedNormals = normalize(normal);
|
||||
vec2 jitterOffsets = TAA_Offset*texelSize*0.5 * RENDER_SCALE - texelSize*0.5;
|
||||
|
||||
// scale the offset radius down as distance increases.
|
||||
float linearViewDistance = length(viewPos);
|
||||
float distanceScale = hand ? 30.0 : mix(40.0, 10.0, pow(clamp(1.0 - linearViewDistance/50.0,0.0,1.0),2.0));
|
||||
|
||||
float leaf = leaves ? -0.5 : 0.0;
|
||||
|
||||
int n = 0;
|
||||
for (int i = 0; i < samples; i++) {
|
||||
|
||||
vec2 offsets = CleanSample(i, samples - 1, noise) / distanceScale;
|
||||
|
||||
ivec2 offsetUV = ivec2(gl_FragCoord.xy + offsets*vec2(viewWidth, viewHeight*aspectRatio)*RENDER_SCALE);
|
||||
|
||||
if (offsetUV.x >= 0 && offsetUV.y >= 0 && offsetUV.x < viewWidth*RENDER_SCALE.x && offsetUV.y < viewHeight*RENDER_SCALE.y ) {
|
||||
|
||||
float sampleDepth = convertHandDepth_2(texelFetch2D(depthtex1, offsetUV, 0).x, hand);
|
||||
|
||||
#ifdef DISTANT_HORIZONS
|
||||
float sampleDHDepth = texelFetch2D(dhDepthTex1, offsetUV, 0).x;
|
||||
vec3 offsetViewPos = toScreenSpace_DH((offsetUV*texelSize - jitterOffsets) * (1.0/RENDER_SCALE), sampleDepth, sampleDHDepth);
|
||||
#else
|
||||
vec3 offsetViewPos = toScreenSpace(vec3((offsetUV*texelSize - jitterOffsets) * (1.0/RENDER_SCALE), sampleDepth));
|
||||
#endif
|
||||
|
||||
vec3 viewPosDiff = offsetViewPos - viewPos;
|
||||
float viewPosDiffSquared = dot(viewPosDiff, viewPosDiff);
|
||||
|
||||
if (viewPosDiffSquared > 1e-5){
|
||||
sss += clamp(leaf - dot(viewPosDiff, normalizedNormals),0.0,1.0);
|
||||
// sss += -(normalize(mat3(gbufferModelViewInverse)*viewPosDiff) + occlusion/n) * threshHold;
|
||||
n += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return max(1.0 - sss/n, 0.0);
|
||||
}
|
||||
|
||||
vec2 spiralSampling(
|
||||
int samples, float totalSamples, float noise
|
||||
){
|
||||
|
||||
// this will be used to make 1 full rotation of the spiral. the mulitplication is so it does nearly a single rotation, instead of going past where it started
|
||||
float variance = noise * 0.897;
|
||||
|
||||
// for every sample input, it will have variance applied to it.
|
||||
float variedSamples = float(samples) + variance;
|
||||
|
||||
// for every sample, the sample position must change its distance from the origin.
|
||||
// otherwise, you will just have a circle.
|
||||
float spiralShape = variedSamples / (totalSamples + variance);
|
||||
|
||||
float shape = 2.26;
|
||||
float theta = variedSamples * (PI * shape);
|
||||
|
||||
float x = cos(theta) * spiralShape;
|
||||
float y = sin(theta) * spiralShape;
|
||||
|
||||
return vec2(x, y);
|
||||
}
|
||||
|
||||
// vec3 getViewPos(in vec2 uv, in float depth, in mat4 inverseProj ){
|
||||
|
||||
// }
|
||||
float getNoise(in vec2 fragCoord){
|
||||
return fract(0.75487765 * fragCoord.x + 0.56984026 * fragCoord.y);
|
||||
}
|
||||
float calculateSSAO(
|
||||
vec2 fragCoord, vec2 uv, vec3 viewPos, vec3 normal, in mat4 inverseProj
|
||||
){
|
||||
// SETTINGS
|
||||
int SAMPLES = 50;
|
||||
float RADIUS = 0.0005;
|
||||
vec2 SCALE_RADIUS = vec2(1280.0, 720.0 * aspectRatio);
|
||||
|
||||
float linearViewDistance = length(viewPos);
|
||||
float distanceScale = mix(40.0, 1.0, pow(clamp(1.0 - linearViewDistance/50.0,0.0,1.0),2.0));
|
||||
float depthCancelation = (linearViewDistance*linearViewDistance) / distanceScale;
|
||||
|
||||
float noise = getNoise(fragCoord);
|
||||
float average = 0.0;
|
||||
float occlusion = 0.0;
|
||||
|
||||
for (int i = 0; i < SAMPLES; i++) {
|
||||
vec2 offsets = (spiralSampling(i, float(SAMPLES - 1), noise) / distanceScale) * RADIUS * SCALE_RADIUS;
|
||||
vec2 offsetUV = uv + offsets;
|
||||
|
||||
if (offsetUV.x >= 0 && offsetUV.y >= 0 && offsetUV.x <= 1.0 && offsetUV.y <= 1.0 ) {
|
||||
float sampleDepth = texture(depthtex0, offsetUV).x;
|
||||
// vec3 offsetViewPos = getViewPos(offsetUV, sampleDepth, inverseProj);
|
||||
vec3 offsetViewPos = toScreenSpace(vec3(offsetUV, sampleDepth));
|
||||
vec3 viewPosDiff = offsetViewPos - viewPos;
|
||||
|
||||
float viewPosDiffSquared = dot(viewPosDiff, viewPosDiff);
|
||||
float threshHold = max(1.0 - viewPosDiffSquared/depthCancelation, 0.0);
|
||||
if (viewPosDiffSquared > 1e-5){
|
||||
occlusion += max(0.0, dot(normalize(viewPosDiff), normal)) * threshHold;
|
||||
average += 1.0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float finalAO = max(1.0 - occlusion / average, 0.0);
|
||||
finalAO = finalAO*finalAO*finalAO*finalAO;
|
||||
return finalAO;
|
||||
}
|
||||
|
||||
vec4 encode (vec3 n, vec2 lightmaps){
|
||||
n.xy = n.xy / dot(abs(n), vec3(1.0));
|
||||
n.xy = n.z <= 0.0 ? (1.0 - abs(n.yx)) * sign(n.xy) : n.xy;
|
||||
@ -448,100 +324,14 @@ float encodeVec2(vec2 a){
|
||||
vec2 temp = floor( a * 255. );
|
||||
return temp.x*constant1.x+temp.y*constant1.y;
|
||||
}
|
||||
|
||||
float encodeVec2(float x,float y){
|
||||
return encodeVec2(vec2(x,y));
|
||||
}
|
||||
|
||||
// #include "/lib/indirect_lighting_effects.glsl"
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
flat varying vec3 zMults;
|
||||
|
||||
vec4 BilateralUpscale_VLFOG(sampler2D tex, sampler2D depth, vec2 coord, float referenceDepth){
|
||||
ivec2 scaling = ivec2(1.0/VL_RENDER_RESOLUTION);
|
||||
ivec2 posDepth = ivec2(coord*VL_RENDER_RESOLUTION) * scaling;
|
||||
ivec2 posColor = ivec2(coord*VL_RENDER_RESOLUTION);
|
||||
ivec2 pos = ivec2(gl_FragCoord.xy*texelSize + 1);
|
||||
|
||||
ivec2 getRadius[5] = ivec2[](
|
||||
ivec2(-1,-1),
|
||||
ivec2( 1, 1),
|
||||
ivec2(-1, 1),
|
||||
ivec2( 1,-1),
|
||||
ivec2( 0, 0)
|
||||
);
|
||||
|
||||
#ifdef DISTANT_HORIZONS
|
||||
float diffThreshold = 0.01;
|
||||
#else
|
||||
float diffThreshold = zMults.x;
|
||||
#endif
|
||||
|
||||
vec4 RESULT = vec4(0.0);
|
||||
float SUM = 0.0;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
||||
ivec2 radius = getRadius[i];
|
||||
|
||||
#ifdef DISTANT_HORIZONS
|
||||
float offsetDepth = sqrt(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling,0).a/65000.0);
|
||||
#else
|
||||
float offsetDepth = ld(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling, 0).r);
|
||||
#endif
|
||||
|
||||
float EDGES = abs(offsetDepth - referenceDepth) < diffThreshold ? 1.0 : 1e-5;
|
||||
|
||||
RESULT += texelFetch2D(tex, posColor + radius + pos, 0) * EDGES;
|
||||
|
||||
SUM += EDGES;
|
||||
}
|
||||
|
||||
return RESULT / SUM;
|
||||
}
|
||||
|
||||
|
||||
#include "/lib/sky_gradient.glsl"
|
||||
|
@ -9,11 +9,9 @@
|
||||
#extension GL_ARB_shading_language_packing: enable
|
||||
#endif
|
||||
|
||||
|
||||
#include "/lib/util.glsl"
|
||||
#include "/lib/res_params.glsl"
|
||||
|
||||
|
||||
#define diagonal3_old(m) vec3((m)[0].x, (m)[1].y, m[2].z)
|
||||
#define projMAD_old(m, v) (diagonal3_old(m) * (v) + (m)[3].xyz)
|
||||
|
||||
@ -32,6 +30,7 @@ uniform float nightVision;
|
||||
|
||||
flat varying vec3 averageSkyCol_Clouds;
|
||||
flat varying vec4 lightCol;
|
||||
flat varying vec3 moonCol;
|
||||
|
||||
#if Sun_specular_Strength != 0
|
||||
#define LIGHTSOURCE_REFLECTION
|
||||
@ -87,16 +86,6 @@ uniform sampler2D colortex15; // flat normals(rgb), vanillaAO(alpha)
|
||||
uniform sampler3D texLpv2;
|
||||
#endif
|
||||
|
||||
|
||||
// uniform mat4 shadowModelView;
|
||||
// uniform mat4 shadowModelViewInverse;
|
||||
// uniform mat4 shadowProjection;
|
||||
// uniform mat4 shadowProjectionInverse;
|
||||
// uniform mat4 gbufferProjection;
|
||||
// uniform mat4 gbufferProjectionInverse;
|
||||
// uniform mat4 gbufferModelView;
|
||||
// uniform mat4 gbufferModelViewInverse;
|
||||
// uniform mat4 gbufferPreviousProjection;
|
||||
uniform mat4 gbufferPreviousModelView;
|
||||
|
||||
// uniform vec3 cameraPosition;
|
||||
@ -129,20 +118,22 @@ uniform ivec2 eyeBrightnessSmooth;
|
||||
uniform vec3 sunVec;
|
||||
flat varying vec3 WsunVec;
|
||||
flat varying vec3 unsigned_WsunVec;
|
||||
flat varying vec3 WmoonVec;
|
||||
flat varying float exposure;
|
||||
|
||||
#ifdef IS_LPV_ENABLED
|
||||
uniform int heldItemId;
|
||||
uniform int heldItemId2;
|
||||
#endif
|
||||
uniform float waterEnteredAltitude;
|
||||
|
||||
uniform float waterEnteredAltitude;
|
||||
|
||||
void convertHandDepth(inout float depth) {
|
||||
float ndcDepth = depth * 2.0 - 1.0;
|
||||
ndcDepth /= MC_HAND_DEPTH;
|
||||
depth = ndcDepth * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
float convertHandDepth_2(in float depth, bool hand) {
|
||||
if(!hand) return depth;
|
||||
|
||||
@ -153,15 +144,6 @@ float convertHandDepth_2(in float depth, bool hand) {
|
||||
|
||||
#include "/lib/projections.glsl"
|
||||
|
||||
// vec3 toScreenSpace(vec3 p) {
|
||||
// vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
|
||||
// vec3 feetPlayerPos = p * 2. - 1.;
|
||||
// vec4 viewPos = iProjDiag * feetPlayerPos.xyzz + gbufferProjectionInverse[3];
|
||||
// return viewPos.xyz / viewPos.w;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
#define TESTTHINGYG
|
||||
|
||||
#include "/lib/color_transforms.glsl"
|
||||
@ -186,7 +168,6 @@ float convertHandDepth_2(in float depth, bool hand) {
|
||||
#define CLOUDS_INTERSECT_TERRAIN
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef IS_LPV_ENABLED
|
||||
#include "/lib/hsv.glsl"
|
||||
#include "/lib/lpv_common.glsl"
|
||||
@ -200,6 +181,7 @@ float ld(float dist) {
|
||||
}
|
||||
|
||||
#include "/lib/sky_gradient.glsl"
|
||||
|
||||
vec3 decode (vec2 encn){
|
||||
vec3 n = vec3(0.0);
|
||||
encn = encn * 2.0 - 1.0;
|
||||
@ -208,17 +190,16 @@ vec3 decode (vec2 encn){
|
||||
n.xy = n.z <= 0.0 ? (1.0 - n.yx) * sign(encn) : encn;
|
||||
return clamp(normalize(n.xyz),-1.0,1.0);
|
||||
}
|
||||
|
||||
vec2 decodeVec2(float a){
|
||||
const vec2 constant1 = 65535. / vec2( 256., 65536.);
|
||||
const float constant2 = 256. / 255.;
|
||||
return fract( a * constant1 ) * constant2 ;
|
||||
}
|
||||
|
||||
|
||||
#include "/lib/end_fog.glsl"
|
||||
|
||||
|
||||
#define DEFERRED_SPECULAR
|
||||
// #define DEFERRED_SPECULAR
|
||||
#define DEFERRED_ENVIORNMENT_REFLECTION
|
||||
#define DEFERRED_BACKGROUND_REFLECTION
|
||||
#define DEFERRED_ROUGH_REFLECTION
|
||||
@ -233,14 +214,12 @@ vec2 decodeVec2(float a){
|
||||
#endif
|
||||
|
||||
#include "/lib/specular.glsl"
|
||||
|
||||
|
||||
|
||||
#include "/lib/DistantHorizons_projections.glsl"
|
||||
|
||||
float DH_ld(float dist) {
|
||||
return (2.0 * dhNearPlane) / (dhFarPlane + dhNearPlane - dist * (dhFarPlane - dhNearPlane));
|
||||
}
|
||||
|
||||
float DH_inv_ld (float lindepth){
|
||||
return -((2.0*dhNearPlane/lindepth)-dhFarPlane-dhNearPlane)/(dhFarPlane-dhNearPlane);
|
||||
}
|
||||
@ -249,20 +228,12 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo
|
||||
return (near * far) / (depth * (near - far) + far);
|
||||
// return (2.0 * near) / (far + near - depth * (far - near));
|
||||
}
|
||||
|
||||
float invertlinearDepthFast(const in float depth, const in float near, const in float far) {
|
||||
return ((2.0*near/depth)-far-near)/(far-near);
|
||||
}
|
||||
|
||||
|
||||
vec3 normVec (vec3 vec){
|
||||
return vec*inversesqrt(dot(vec,vec));
|
||||
}
|
||||
float lengthVec (vec3 vec){
|
||||
return sqrt(dot(vec,vec));
|
||||
}
|
||||
|
||||
// #define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.)
|
||||
|
||||
float triangularize(float dither)
|
||||
{
|
||||
float center = dither*2.0-1.0;
|
||||
@ -276,34 +247,6 @@ vec3 fp10Dither(vec3 color,float dither){
|
||||
return color + dither*exp2(-mantissaBits)*exp2(exponent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// float facos(float sx){
|
||||
// float x = clamp(abs( sx ),0.,1.);
|
||||
// return sqrt( 1. - x ) * ( -0.16882 * x + 1.56734 );
|
||||
// }
|
||||
|
||||
vec2 tapLocation(int sampleNumber,int nb, float nbRot,float jitter,float distort)
|
||||
{
|
||||
float alpha0 = sampleNumber/nb;
|
||||
float alpha = (sampleNumber+jitter)/nb;
|
||||
float angle = jitter*6.28 + alpha * 4.0 * 6.28;
|
||||
|
||||
float sin_v, cos_v;
|
||||
|
||||
sin_v = sin(angle);
|
||||
cos_v = cos(angle);
|
||||
|
||||
return vec2(cos_v, sin_v)*sqrt(alpha);
|
||||
}
|
||||
|
||||
|
||||
vec3 BilateralFiltering(sampler2D tex, sampler2D depth,vec2 coord,float frDepth,float maxZ){
|
||||
vec4 sampled = vec4(texelFetch2D(tex,ivec2(coord),0).rgb,1.0);
|
||||
|
||||
return vec3(sampled.x,sampled.yz/sampled.w);
|
||||
}
|
||||
|
||||
float interleaved_gradientNoise_temporal(){
|
||||
#ifdef TAA
|
||||
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887 * frameCounter);
|
||||
@ -311,11 +254,13 @@ float interleaved_gradientNoise_temporal(){
|
||||
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887);
|
||||
#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;
|
||||
}
|
||||
|
||||
float R2_dither(){
|
||||
vec2 coord = gl_FragCoord.xy ;
|
||||
|
||||
@ -326,6 +271,7 @@ float R2_dither(){
|
||||
vec2 alpha = vec2(0.75487765, 0.56984026);
|
||||
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
|
||||
}
|
||||
|
||||
float R2_dither2(){
|
||||
vec2 coord = gl_FragCoord.xy ;
|
||||
|
||||
@ -336,6 +282,7 @@ float R2_dither2(){
|
||||
vec2 alpha = vec2(0.75487765, 0.56984026);
|
||||
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
|
||||
}
|
||||
|
||||
float blueNoise(){
|
||||
#ifdef TAA
|
||||
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
|
||||
@ -343,45 +290,10 @@ float blueNoise(){
|
||||
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887);
|
||||
#endif
|
||||
}
|
||||
|
||||
vec4 blueNoise(vec2 coord){
|
||||
return texelFetch2D(colortex6, ivec2(coord)%512 , 0) ;
|
||||
}
|
||||
// vec3 toShadowSpaceProjected(vec3 feetPlayerPos){
|
||||
|
||||
// mat4 DH_shadowProjection = DH_shadowProjectionTweak(shadowProjection);
|
||||
|
||||
// feetPlayerPos = mat3(gbufferModelViewInverse) * feetPlayerPos + gbufferModelViewInverse[3].xyz;
|
||||
// feetPlayerPos = mat3(shadowModelView) * feetPlayerPos + shadowModelView[3].xyz;
|
||||
// feetPlayerPos = diagonal3_old(DH_shadowProjection) * feetPlayerPos + DH_shadowProjection[3].xyz;
|
||||
|
||||
// return feetPlayerPos;
|
||||
// }
|
||||
|
||||
vec2 tapLocation(int sampleNumber, float spinAngle,int nb, float nbRot,float r0)
|
||||
{
|
||||
float alpha = (float(sampleNumber*1.0f + r0) * (1.0 / (nb)));
|
||||
float angle = alpha * (nbRot * 6.28) + spinAngle*6.28;
|
||||
|
||||
float ssR = alpha;
|
||||
float sin_v, cos_v;
|
||||
|
||||
sin_v = sin(angle);
|
||||
cos_v = cos(angle);
|
||||
|
||||
return vec2(cos_v, sin_v)*ssR;
|
||||
}
|
||||
vec2 tapLocation_simple(
|
||||
int samples, int totalSamples, float rotation, float rng
|
||||
){
|
||||
const float PI = 3.141592653589793238462643383279502884197169;
|
||||
float alpha = float(samples + rng) * (1.0 / float(totalSamples));
|
||||
float angle = alpha * (rotation * PI);
|
||||
|
||||
float sin_v = sin(angle);
|
||||
float cos_v = cos(angle);
|
||||
|
||||
return vec2(cos_v, sin_v) * sqrt(alpha);
|
||||
}
|
||||
|
||||
vec2 CleanSample(
|
||||
int samples, float totalSamples, float noise
|
||||
@ -405,6 +317,7 @@ vec2 CleanSample(
|
||||
|
||||
return vec2(x, y);
|
||||
}
|
||||
|
||||
vec3 viewToWorld(vec3 viewPos) {
|
||||
vec4 pos;
|
||||
pos.xyz = viewPos;
|
||||
@ -412,11 +325,13 @@ vec3 viewToWorld(vec3 viewPos) {
|
||||
pos = gbufferModelViewInverse * pos;
|
||||
return pos.xyz;
|
||||
}
|
||||
|
||||
vec3 worldToView(vec3 worldPos) {
|
||||
vec4 pos = vec4(worldPos, 0.0);
|
||||
pos = gbufferModelView * pos;
|
||||
return pos.xyz;
|
||||
}
|
||||
|
||||
float swapperlinZ(float depth, float _near, float _far) {
|
||||
return (2.0 * _near) / (_far + _near - depth * (_far - _near));
|
||||
// l = (2*n)/(f+n-d(f-n))
|
||||
@ -434,7 +349,8 @@ vec2 SSRT_Shadows(vec3 viewPos, bool depthCheck, vec3 lightDir, float noise, boo
|
||||
float steps = 16.0;
|
||||
float Shadow = 1.0;
|
||||
float SSS = 0.0;
|
||||
|
||||
// isSSS = true;
|
||||
|
||||
float _near = near; float _far = far*4.0;
|
||||
|
||||
if (depthCheck) {
|
||||
@ -442,26 +358,28 @@ vec2 SSRT_Shadows(vec3 viewPos, bool depthCheck, vec3 lightDir, float noise, boo
|
||||
_far = dhFarPlane;
|
||||
}
|
||||
|
||||
vec3 worldpos = mat3(gbufferModelViewInverse) * viewPos ;
|
||||
float dist = 1.0 + length(worldpos)/(_far/2.0); // step length as distance increases
|
||||
vec3 clipPosition = toClipSpace3_DH(viewPos, depthCheck);
|
||||
|
||||
vec3 clipPosition = toClipSpace3_DH(viewPos, depthCheck);
|
||||
//prevents the ray from going behind the camera
|
||||
float rayLength = ((viewPos.z + lightDir.z * _far*sqrt(3.)) > -_near) ?
|
||||
(-_near -viewPos.z) / lightDir.z : _far*sqrt(3.);
|
||||
|
||||
vec3 direction = toClipSpace3_DH(viewPos + lightDir*rayLength, depthCheck) - clipPosition; //convert to clip space
|
||||
direction.xyz = direction.xyz / max(abs(direction.x)/texelSize.x, abs(direction.y)/texelSize.y); //fixed step size
|
||||
|
||||
float Stepmult = depthCheck ? (isSSS ? 1.0 : 6.0) : (isSSS ? 1.0 : 3.0);
|
||||
|
||||
vec3 rayDir = direction * Stepmult * vec3(RENDER_SCALE,1.0) ;
|
||||
|
||||
vec3 screenPos = clipPosition * vec3(RENDER_SCALE,1.0) + rayDir * noise;
|
||||
direction.xyz = direction.xyz / max(abs(direction.x)/0.0005, abs(direction.y)/0.0005); //fixed step size
|
||||
|
||||
// float Stepmult = depthCheck ? (isSSS ? 1.0 : 3.0) : (isSSS ? 1.0 : 3.0);
|
||||
float Stepmult = isSSS ? 3.0 : 6.0;
|
||||
|
||||
vec3 rayDir = direction * Stepmult * vec3(RENDER_SCALE,1.0);
|
||||
vec3 screenPos = clipPosition * vec3(RENDER_SCALE,1.0) + rayDir*noise - (isSSS ? rayDir*0.9 : vec3(0.0));
|
||||
|
||||
float minZ = screenPos.z;
|
||||
float maxZ = screenPos.z;
|
||||
|
||||
// as distance increases, add larger values to the SSS value. this scales the "density" with distance, as far things should appear denser.
|
||||
float dist = 1.0 + length(mat3(gbufferModelViewInverse) * viewPos) / 500.0;
|
||||
|
||||
for (int i = 0; i < int(steps); i++) {
|
||||
|
||||
float samplePos = convertHandDepth_2(texture2D(depthtex1, screenPos.xy).x, hand);
|
||||
@ -471,13 +389,11 @@ vec2 SSRT_Shadows(vec3 viewPos, bool depthCheck, vec3 lightDir, float noise, boo
|
||||
#endif
|
||||
|
||||
if(samplePos < screenPos.z && (samplePos <= max(minZ,maxZ) && samplePos >= min(minZ,maxZ))){
|
||||
|
||||
vec2 linearZ = vec2(swapperlinZ(screenPos.z, _near, _far), swapperlinZ(samplePos, _near, _far));
|
||||
float calcthreshold = abs(linearZ.x - linearZ.y) / linearZ.x;
|
||||
|
||||
if (calcthreshold < 0.035) Shadow = 0.0;
|
||||
|
||||
SSS += 1.0/steps;
|
||||
SSS += dist;
|
||||
}
|
||||
|
||||
minZ = maxZ - (isSSS ? 1.0 : 0.0001) / swapperlinZ(samplePos, _near, _far);
|
||||
@ -485,9 +401,9 @@ vec2 SSRT_Shadows(vec3 viewPos, bool depthCheck, vec3 lightDir, float noise, boo
|
||||
|
||||
screenPos += rayDir;
|
||||
}
|
||||
return vec2(Shadow, SSS);
|
||||
}
|
||||
|
||||
return vec2(Shadow, SSS / steps);
|
||||
}
|
||||
|
||||
void Emission(
|
||||
inout vec3 Lighting,
|
||||
@ -503,91 +419,6 @@ void Emission(
|
||||
#include "/lib/indirect_lighting_effects.glsl"
|
||||
#include "/lib/PhotonGTAO.glsl"
|
||||
|
||||
vec4 BilateralUpscale(sampler2D tex, sampler2D depth, vec2 coord, float referenceDepth){
|
||||
|
||||
const ivec2 scaling = ivec2(1.0/VL_RENDER_RESOLUTION);
|
||||
ivec2 posDepth = ivec2(coord*VL_RENDER_RESOLUTION) * scaling;
|
||||
ivec2 posColor = ivec2(coord*VL_RENDER_RESOLUTION);
|
||||
|
||||
ivec2 pos = ivec2(gl_FragCoord.xy*texelSize + 1);
|
||||
|
||||
ivec2 getRadius[4] = ivec2[](
|
||||
ivec2(-2,-2),
|
||||
ivec2(-2, 0),
|
||||
ivec2( 0, 0),
|
||||
ivec2( 0,-2)
|
||||
);
|
||||
|
||||
float diffThreshold = zMults.x;
|
||||
|
||||
vec4 RESULT = vec4(0.0);
|
||||
float SUM = 0.0;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
||||
ivec2 radius = getRadius[i];
|
||||
|
||||
float offsetDepth = ld(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling, 0).r);
|
||||
|
||||
float EDGES = abs(offsetDepth - referenceDepth) < diffThreshold ? 1.0 : 1e-5;
|
||||
|
||||
RESULT += texelFetch2D(tex, posColor + radius + pos, 0) * EDGES;
|
||||
|
||||
SUM += EDGES;
|
||||
}
|
||||
// return vec4(0,0,0,1) * SUM;
|
||||
return RESULT / SUM;
|
||||
}
|
||||
|
||||
vec4 BilateralUpscale_DH(sampler2D tex, sampler2D depth, vec2 coord, float referenceDepth){
|
||||
ivec2 scaling = ivec2(1.0/VL_RENDER_RESOLUTION);
|
||||
ivec2 posDepth = ivec2(coord*VL_RENDER_RESOLUTION) * scaling;
|
||||
ivec2 posColor = ivec2(coord*VL_RENDER_RESOLUTION);
|
||||
ivec2 pos = ivec2(gl_FragCoord.xy*texelSize + 1);
|
||||
|
||||
ivec2 getRadius[4] = ivec2[](
|
||||
ivec2(-2,-2),
|
||||
ivec2(-2, 0),
|
||||
ivec2( 0, 0),
|
||||
ivec2( 0,-2)
|
||||
// ivec2(-1,-1),
|
||||
// ivec2( 1, 1),
|
||||
// ivec2(-1, 1),
|
||||
// ivec2( 1,-1)
|
||||
);
|
||||
|
||||
#ifdef DISTANT_HORIZONS
|
||||
float diffThreshold = 0.01;
|
||||
#else
|
||||
float diffThreshold = zMults.x;
|
||||
#endif
|
||||
|
||||
vec4 RESULT = vec4(0.0);
|
||||
float SUM = 0.0;
|
||||
|
||||
RESULT += texelFetch2D(tex, posColor + pos, 0);
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
||||
ivec2 radius = getRadius[i] ;
|
||||
|
||||
#ifdef DISTANT_HORIZONS
|
||||
float offsetDepth = sqrt(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling,0).a/65000.0);
|
||||
#else
|
||||
float offsetDepth = ld(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling, 0).r);
|
||||
#endif
|
||||
|
||||
float EDGES = abs(offsetDepth - referenceDepth) < diffThreshold ? 1.0 : 1e-5;
|
||||
|
||||
RESULT += texelFetch2D(tex, posColor + radius + pos, 0) * EDGES;
|
||||
|
||||
SUM += EDGES;
|
||||
}
|
||||
// return vec4(1) * SUM;
|
||||
return RESULT / SUM;
|
||||
|
||||
}
|
||||
|
||||
void BilateralUpscale_REUSE_Z(sampler2D tex1, sampler2D tex2, sampler2D depth, vec2 coord, float referenceDepth, inout vec2 ambientEffects, inout vec3 filteredShadow, bool hand){
|
||||
ivec2 scaling = ivec2(1.0);
|
||||
ivec2 posDepth = ivec2(coord) * scaling;
|
||||
@ -695,68 +526,8 @@ vec4 BilateralUpscale_VLFOG(sampler2D tex, sampler2D depth, vec2 coord, float re
|
||||
}
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
float ComputeShadowMap(in vec3 projectedShadowPosition, float distortFactor, float noise, float shadowBlockerDepth, float NdotL, float maxDistFade, inout vec3 directLightColor, inout float FUNNYSHADOW, bool isSSS){
|
||||
|
||||
if(maxDistFade <= 0.0) return 1.0;
|
||||
float backface = NdotL <= 0.0 ? 1.0 : 0.0;
|
||||
|
||||
float shadowmap = 0.0;
|
||||
vec3 translucentTint = vec3(0.0);
|
||||
|
||||
#ifdef BASIC_SHADOW_FILTER
|
||||
int samples = SHADOW_FILTER_SAMPLE_COUNT;
|
||||
float rdMul = shadowBlockerDepth*distortFactor*d0*k/shadowMapResolution;
|
||||
|
||||
for(int i = 0; i < samples; i++){
|
||||
// vec2 offsetS = tapLocation_simple(i, 7, 9, noise) * 0.5;
|
||||
vec2 offsetS = CleanSample(i, samples - 1, noise) * 0.3;
|
||||
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*0.6)*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);
|
||||
|
||||
FUNNYSHADOW = shadowAlpha;
|
||||
|
||||
// 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)) * max(shadowAlpha, backface * (1.0 - shadowDepthDiff));
|
||||
|
||||
float translucentMask = 1 - max(shadowDepthDiff-opaqueShadow, 0);
|
||||
// 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 maxDistFade;
|
||||
return shadowmap / samples;
|
||||
// return mix(1.0, shadowmap / samples, maxDistFade);
|
||||
|
||||
}
|
||||
|
||||
|
||||
vec3 ComputeShadowMap_COLOR(in vec3 projectedShadowPosition, float distortFactor, float noise, float shadowBlockerDepth, float NdotL, float maxDistFade, vec3 directLightColor, inout float FUNNYSHADOW, inout vec3 tintedSunlight, bool isSSS){
|
||||
vec3 ComputeShadowMap_COLOR(in vec3 projectedShadowPosition, float distortFactor, float noise, float shadowBlockerDepth, float NdotL, float maxDistFade, vec3 directLightColor, inout float FUNNYSHADOW, inout vec3 tintedSunlight, bool isSSS ,inout float shadowDebug){
|
||||
|
||||
// if(maxDistFade <= 0.0) return 1.0;
|
||||
float backface = NdotL <= 0.0 ? 1.0 : 0.0;
|
||||
@ -792,11 +563,15 @@ vec3 ComputeShadowMap_COLOR(in vec3 projectedShadowPosition, float distortFactor
|
||||
#else
|
||||
shadowColor += directLightColor * shadow2D(shadow, projectedShadowPosition).x;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef BASIC_SHADOW_FILTER
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef debug_SHADOWMAP
|
||||
shadowDebug = shadow2D(shadow, projectedShadowPosition).x;
|
||||
#endif
|
||||
// #ifdef TRANSLUCENT_COLORED_SHADOWS
|
||||
// directLightColor *= mix(vec3(1.0), translucentTint.rgb / samples, maxDistFade);
|
||||
tintedSunlight *= translucentTint.rgb / samples;
|
||||
@ -820,50 +595,17 @@ float CustomPhase(float LightPos){
|
||||
|
||||
vec3 SubsurfaceScattering_sun(vec3 albedo, float Scattering, float Density, float lightPos, float shadows, float distantSSS){
|
||||
|
||||
// Scattering *= sss_density_multiplier;
|
||||
|
||||
// float density = 0.0001 + Density*2.0;
|
||||
|
||||
// float scatterDepth = max(1.0 - Scattering/density,0.0);
|
||||
// scatterDepth = exp((1.0-scatterDepth) * -7.0);
|
||||
|
||||
|
||||
// // this is for SSS when there is no shadow blocker depth
|
||||
// #if defined BASIC_SHADOW_FILTER && defined Variable_Penumbra_Shadows
|
||||
// scatterDepth = max(scatterDepth, pow(shadows, 0.5 + (1.0-Density) * 2.0) );
|
||||
// #else
|
||||
// scatterDepth = exp(-7.0 * pow(1.0-shadows,3.0))*min(2.0-sss_density_multiplier,1.0);
|
||||
// #endif
|
||||
|
||||
// // PBR at its finest :clueless:
|
||||
// vec3 absorbColor = exp(max(luma(albedo) - albedo*vec3(1.0,1.1,1.2), 0.0) * -(20.0 - 19*scatterDepth) * sss_absorbance_multiplier);
|
||||
|
||||
// vec3 scatter = scatterDepth * absorbColor * pow(Density, LabSSS_Curve);
|
||||
|
||||
// scatter *= 1.0 + CustomPhase(lightPos)*6.0; // ~10x brighter at the peak
|
||||
|
||||
// return scatter;
|
||||
|
||||
|
||||
// Scattering *= sss_density_multiplier;
|
||||
// Density = 1.0;
|
||||
Scattering *= sss_density_multiplier;
|
||||
|
||||
float density = 1e-6 + Density * 2.0;
|
||||
|
||||
// float scatterDepth = Scattering;//max(1.0 - Scattering/density,0.0);
|
||||
|
||||
float scatterDepth = max(1.0 - Scattering/density, 0.0);
|
||||
scatterDepth = mix(exp(Scattering * -10.0), scatterDepth, distantSSS);
|
||||
scatterDepth *= exp(-7.0 * (1.0-scatterDepth));
|
||||
|
||||
// vec3 absorbColor = exp(max(luma(albedo) - albedo*vec3(1.0,1.1,1.2), 0.0) * -(20.0 - 19*scatterDepth) * sss_absorbance_multiplier);
|
||||
|
||||
// scatterDepth = mix(exp(Scattering * -10.0), scatterDepth, distantSSS);
|
||||
|
||||
// vec3 scatter = scatterDepth * absorbColor * pow(Density, LabSSS_Curve);// * vec3(1.0);
|
||||
|
||||
vec3 absorbColor = exp(max(luma(albedo) - albedo*vec3(1.0,1.1,1.2), 0.0) * -20.0);
|
||||
|
||||
vec3 scatter = scatterDepth * mix(absorbColor, vec3(1.0), scatterDepth) * pow(Density, LabSSS_Curve);
|
||||
|
||||
vec3 absorbColor = exp(max(luma(albedo) - albedo*vec3(1.0,1.1,1.2), 0.0) * -20.0 * sss_absorbance_multiplier);
|
||||
vec3 scatter = scatterDepth * mix(absorbColor, vec3(1.0), scatterDepth) * (1-min(max((1-Density)-0.9, 0.0)/(1.0-0.9),1.0));
|
||||
|
||||
scatter *= 1.0 + CustomPhase(lightPos)*6.0; // ~10x brighter at the peak
|
||||
|
||||
@ -871,43 +613,24 @@ vec3 SubsurfaceScattering_sun(vec3 albedo, float Scattering, float Density, floa
|
||||
}
|
||||
|
||||
vec3 SubsurfaceScattering_sky(vec3 albedo, float Scattering, float Density){
|
||||
|
||||
// Density = 1.0;
|
||||
#ifdef OLD_INDIRECT_SSS
|
||||
float scatterDepth = 1.0 - pow(1.0-Scattering, 0.5 + Density * 2.5);
|
||||
vec3 absorbColor = vec3(1.0) * exp(-(15.0 - 10.0*scatterDepth) * sss_absorbance_multiplier * 0.01);
|
||||
vec3 scatter = scatterDepth * absorbColor * pow(Density, LabSSS_Curve);
|
||||
#else
|
||||
float scatterDepth = pow(Scattering,4);
|
||||
float scatterDepth = pow(Scattering,3.5);
|
||||
scatterDepth = 1-pow(1-scatterDepth,5);
|
||||
|
||||
vec3 absorbColor = exp(max(luma(albedo) - albedo*vec3(1.0,1.1,1.2), 0.0) * -1.0 * sss_absorbance_multiplier);
|
||||
vec3 scatter = scatterDepth * mix(absorbColor, vec3(1.0), scatterDepth) * pow(Density, LabSSS_Curve);
|
||||
vec3 scatter = scatterDepth * mix(absorbColor, vec3(1.0), scatterDepth) * (1-min(max((1-Density)-0.9, 0.0)/(1.0-0.9),1.0));// * pow(Density, LabSSS_Curve);
|
||||
#endif
|
||||
|
||||
// scatter *= 1.0 + exp(-7.0*(-playerPosNormalized.y*0.5+0.5));
|
||||
|
||||
return scatter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
vec3 blurredAlbedo( float noise, float lineardistance){
|
||||
|
||||
int samples = 7;
|
||||
vec3 blurredColor = vec3(0.0);
|
||||
|
||||
for (int i = 0; i < samples; i++) {
|
||||
|
||||
vec2 offsets = CleanSample(i, samples - 1, noise)*0.02 / lineardistance;
|
||||
|
||||
ivec2 offsetUV = ivec2(gl_FragCoord.xy + offsets*vec2(viewWidth, viewHeight*aspectRatio)*RENDER_SCALE);
|
||||
|
||||
vec3 SAMPLE = texelFetch2D(colortex1, offsetUV, 0).xyz;
|
||||
|
||||
blurredColor += toLinear(vec3(decodeVec2(SAMPLE.x).x, decodeVec2(SAMPLE.y).x, decodeVec2(SAMPLE.z).x));
|
||||
|
||||
}
|
||||
|
||||
return blurredColor/samples;
|
||||
}
|
||||
uniform float wetnessAmount;
|
||||
uniform float wetness;
|
||||
|
||||
@ -920,8 +643,8 @@ void applyPuddles(
|
||||
|
||||
float halfWet = min(wetnessAmount,1.0);
|
||||
float fullWet = clamp(wetnessAmount - 2.0,0.0,1.0);
|
||||
// halfWet = 1.0;
|
||||
// fullWet = 1.0;
|
||||
// halfWet = 0.0;
|
||||
// fullWet = 0.0;
|
||||
float noise = texture2D(noisetex, worldPos.xz * 0.02).b;
|
||||
|
||||
|
||||
@ -955,82 +678,6 @@ void applyPuddles(
|
||||
// albedo = mix(albedo, vec3(1.0), snow);
|
||||
}
|
||||
|
||||
vec2 smoothfilterUV(in vec2 uv)
|
||||
{
|
||||
vec2 textureResolution = vec2(viewWidth,viewHeight);
|
||||
uv = uv*textureResolution + 0.5;
|
||||
vec2 iuv = floor( uv );
|
||||
vec2 fuv = fract( uv );
|
||||
|
||||
#ifndef SMOOTHESTSTEP_INTERPOLATION
|
||||
uv = iuv + (fuv*fuv)*(3.0-2.0*fuv);
|
||||
#endif
|
||||
#ifdef SMOOTHESTSTEP_INTERPOLATION
|
||||
uv = iuv + fuv*fuv*fuv*(fuv*(fuv*6.0-15.0)+10.0);
|
||||
#endif
|
||||
|
||||
uv = (uv - 0.5)/textureResolution;
|
||||
|
||||
return uv;
|
||||
}
|
||||
|
||||
float calculateSSAO(
|
||||
vec3 viewPos, vec3 normal, float noise
|
||||
){
|
||||
int samples = 50;
|
||||
float occlusion = 0.0;
|
||||
float sss = 0.0;
|
||||
|
||||
vec2 jitterOffsets = TAA_Offset*texelSize * 0.5 * RENDER_SCALE - texelSize*0.5;
|
||||
|
||||
// scale the offset radius down as distance increases.
|
||||
float linearViewDistance = length(viewPos);
|
||||
float distanceScale = mix(40.0, 10.0, pow(clamp(1.0 - linearViewDistance/50.0,0.0,1.0),2.0));
|
||||
float depthCancelation = (linearViewDistance*linearViewDistance) / distanceScale ;
|
||||
|
||||
int n = 0;
|
||||
|
||||
for (int i = 0; i < samples; i++) {
|
||||
|
||||
vec2 offsets = CleanSample(i, samples - 1, noise) / distanceScale;
|
||||
|
||||
ivec2 offsetUV = ivec2(gl_FragCoord.xy + offsets*vec2(viewWidth, viewHeight*aspectRatio)*RENDER_SCALE);
|
||||
|
||||
if (offsetUV.x >= 0 && offsetUV.y >= 0 && offsetUV.x < viewWidth*RENDER_SCALE.x && offsetUV.y < viewHeight*RENDER_SCALE.y ) {
|
||||
|
||||
float sampleDepth = texelFetch2D(depthtex1, offsetUV, 0).x;
|
||||
vec2 scaledUV = (offsetUV*texelSize - jitterOffsets) * (1.0/RENDER_SCALE);
|
||||
|
||||
vec3 offsetViewPos = toScreenSpace(vec3(scaledUV, sampleDepth));
|
||||
|
||||
vec3 viewPosDiff = offsetViewPos - viewPos;
|
||||
vec3 viewPosDiff_world = mat3(gbufferModelViewInverse) * viewPosDiff;
|
||||
|
||||
float viewPosDiffSquared = dot(viewPosDiff, viewPosDiff);
|
||||
float threshHold = clamp(1.0 - viewPosDiffSquared/depthCancelation, 0.0,1.0);
|
||||
|
||||
if (viewPosDiffSquared > 1e-5){
|
||||
n += 1;
|
||||
|
||||
occlusion += max(0.0, dot(normalize(viewPosDiff), normal) - 0.5) * threshHold;
|
||||
|
||||
// vec3 dir = (-normalize(viewPosDiff_world) * threshHold + 0.5) * (1.0-occlusion/n);
|
||||
vec3 dir = -(normalize(viewPosDiff_world) + occlusion/n) * threshHold;
|
||||
|
||||
sss += dir.y;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
float finalAO = max(1.0 - occlusion / n, 0.0);
|
||||
float finalSSS = sss/n;
|
||||
|
||||
finalAO = pow(finalAO,10);
|
||||
|
||||
return finalAO;
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
||||
vec3 DEBUG = vec3(1.0);
|
||||
@ -1054,7 +701,6 @@ void main() {
|
||||
|
||||
float z0 = texelFetch2D(depthtex0, ivec2(gl_FragCoord.xy), 0).x;
|
||||
float z = texelFetch2D(depthtex1, ivec2(gl_FragCoord.xy), 0).x;
|
||||
|
||||
float swappedDepth = z;
|
||||
|
||||
bool isDHrange = z >= 1.0;
|
||||
@ -1083,9 +729,6 @@ void main() {
|
||||
float DH_depth1 = 0.0;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
////// --------------- UNPACK OPAQUE GBUFFERS --------------- //////
|
||||
|
||||
vec4 data = texelFetch2D(colortex1, ivec2(gl_FragCoord.xy), 0);
|
||||
@ -1103,15 +746,12 @@ void main() {
|
||||
#if !defined OVERWORLD_SHADER
|
||||
lightmap.y = 1.0;
|
||||
#endif
|
||||
|
||||
// lightmap.y = 0.0;
|
||||
// if(isDHrange) lightmap.y = pow(lightmap.y,25);
|
||||
// if(isEyeInWater == 1) lightmap.y = max(lightmap.y, 0.75);
|
||||
|
||||
////// --------------- UNPACK MISC --------------- //////
|
||||
|
||||
vec4 SpecularTex = texelFetch2D(colortex8, ivec2(gl_FragCoord.xy), 0);
|
||||
float LabSSS = clamp((-65.0 + SpecularTex.z * 255.0) / 190.0 ,0.0,1.0);
|
||||
// LabSSS = 1;
|
||||
|
||||
vec4 normalAndAO = texture2D(colortex15,texcoord);
|
||||
vec3 FlatNormals = normalize(normalAndAO.rgb * 2.0 - 1.0);
|
||||
@ -1150,9 +790,9 @@ void main() {
|
||||
bool entities = abs(opaqueMasks-0.45) < 0.01;
|
||||
bool isGrass = abs(opaqueMasks-0.60) < 0.01;
|
||||
bool hand = abs(opaqueMasks-0.75) < 0.01 && z < 1.0;
|
||||
// bool handwater = abs(translucentMasks-0.3) < 0.01 ;
|
||||
// bool blocklights = abs(opaqueMasks-0.8) <0.01;
|
||||
|
||||
|
||||
if(hand){
|
||||
convertHandDepth(z);
|
||||
convertHandDepth(z0);
|
||||
@ -1165,7 +805,7 @@ void main() {
|
||||
#endif
|
||||
|
||||
vec3 feetPlayerPos = mat3(gbufferModelViewInverse) * viewPos;
|
||||
vec3 feetPlayerPos_normalized = normVec(feetPlayerPos);
|
||||
vec3 feetPlayerPos_normalized = normalize(feetPlayerPos);
|
||||
|
||||
#ifdef POM
|
||||
#ifdef Horrible_slope_normals
|
||||
@ -1175,12 +815,9 @@ void main() {
|
||||
#endif
|
||||
////// --------------- COLORS --------------- //////
|
||||
|
||||
|
||||
// float dirtAmount = Dirt_Amount;
|
||||
// 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 = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);//dirtEpsilon * dirtAmount + waterEpsilon;
|
||||
vec3 totEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
|
||||
vec3 scatterCoef = Dirt_Amount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
|
||||
|
||||
vec3 Absorbtion = vec3(1.0);
|
||||
@ -1204,7 +841,7 @@ void main() {
|
||||
float lightLeakFix = clamp(pow(eyeBrightnessSmooth.y/240. + lightmap.y,2.0) ,0.0,1.0);
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
DirectLightColor = lightCol.rgb / 2400.0;//mix(900.0, 2400.0, lightmap.y);
|
||||
DirectLightColor = lightCol.rgb / 2400.0;
|
||||
AmbientLightColor = averageSkyCol_Clouds / 900.0;
|
||||
shadowColor = DirectLightColor;
|
||||
|
||||
@ -1223,12 +860,6 @@ void main() {
|
||||
|
||||
MinimumLightColor = MinimumLightColor + 0.7 * MinimumLightColor * dot(slopednormal, feetPlayerPos_normalized);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////// START DRAW ////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////// UNDER WATER SHADING ////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -1246,8 +877,6 @@ void main() {
|
||||
|
||||
float Vdiff = distance(feetPlayerPos, playerPos0);
|
||||
float estimatedDepth = Vdiff * abs(feetPlayerPos_normalized.y);// assuming water plane
|
||||
|
||||
// float viewerWaterDepth = Vdiff;// * (1.0 - clamp(exp(-Vdiff),0.0,1.0));
|
||||
|
||||
// force the absorbance to start way closer to the water surface in low light areas, so the water is visible in caves and such.
|
||||
#if MINIMUM_WATER_ABSORBANCE > -1
|
||||
@ -1255,12 +884,8 @@ void main() {
|
||||
#else
|
||||
float minimumAbsorbance = (1.0 - lightLeakFix);
|
||||
#endif
|
||||
|
||||
// viewerWaterDepth += max(estimatedDepth - 1.0, minimumAbsorbance);
|
||||
|
||||
Absorbtion = exp(-totEpsilon * max(Vdiff, minimumAbsorbance));
|
||||
|
||||
// Absorbtion = exp( -2.0 * totEpsilon * viewerWaterDepth);
|
||||
|
||||
// brighten up the fully absorbed parts of water when night vision activates.
|
||||
// if( nightVision > 0.0 ) Absorbtion += exp( -50.0 * totEpsilon) * 50.0 * 7.0 * nightVision;
|
||||
@ -1367,8 +992,7 @@ void main() {
|
||||
float ShadowAlpha = 0.0; // this is for subsurface scattering later.
|
||||
vec3 tintedSunlight = DirectLightColor; // this is for subsurface scattering later.
|
||||
|
||||
shadowColor = ComputeShadowMap_COLOR(projectedShadowPosition, distortFactor, noise_2, filteredShadow.x, flatNormNdotL, shadowMapFalloff, DirectLightColor, ShadowAlpha, tintedSunlight, LabSSS > 0.0);
|
||||
|
||||
shadowColor = ComputeShadowMap_COLOR(projectedShadowPosition, distortFactor, noise_2, filteredShadow.x, flatNormNdotL, shadowMapFalloff, DirectLightColor, ShadowAlpha, tintedSunlight, LabSSS > 0.0,Shadows);
|
||||
|
||||
// transition to fallback lightmap shadow mask.
|
||||
shadowColor *= mix(isWater ? lightLeakFix : LM_shadowMapFallback, 1.0, shadowMapFalloff2);
|
||||
@ -1393,12 +1017,15 @@ void main() {
|
||||
|
||||
#ifdef SCREENSPACE_CONTACT_SHADOWS
|
||||
vec2 SS_directLight = SSRT_Shadows(toScreenSpace_DH(texcoord/RENDER_SCALE, z, DH_depth1), isDHrange, normalize(WsunVec*mat3(gbufferModelViewInverse)), interleaved_gradientNoise_temporal(), sunSSS_density > 0.0 && shadowMapFalloff2 < 1.0, hand);
|
||||
|
||||
// Shadows = SS_directLight.r;
|
||||
|
||||
// combine shadowmap with a minumum shadow determined by the screenspace shadows.
|
||||
shadowColor *= SS_directLight.r;
|
||||
|
||||
// combine shadowmap blocker depth with a minumum determined by the screenspace shadows, starting after the shadowmap ends
|
||||
ShadowBlockerDepth = mix(SS_directLight.g, ShadowBlockerDepth, shadowMapFalloff2);
|
||||
|
||||
// shadowColor = vec3(SS_directLight.r*0 + 1);
|
||||
// ShadowBlockerDepth = SS_directLight.g;
|
||||
#endif
|
||||
#ifdef TRANSLUCENT_COLORED_SHADOWS
|
||||
SSSColor = tintedSunlight;
|
||||
@ -1408,7 +1035,7 @@ void main() {
|
||||
|
||||
SSSColor *= SubsurfaceScattering_sun(albedo, ShadowBlockerDepth, sunSSS_density, clamp(dot(feetPlayerPos_normalized, WsunVec),0.0,1.0), SSS_shadow, shadowMapFalloff2);
|
||||
|
||||
if(isEyeInWater != 1)SSSColor *= lightLeakFix;
|
||||
if(isEyeInWater != 1) SSSColor *= lightLeakFix;
|
||||
|
||||
#ifndef SCREENSPACE_CONTACT_SHADOWS
|
||||
SSSColor = mix(vec3(0.0), SSSColor, shadowMapFalloff2);
|
||||
@ -1447,36 +1074,17 @@ void main() {
|
||||
float skylight = 1.0;
|
||||
|
||||
#if indirect_effect == 0 || indirect_effect == 1 || indirect_effect == 2
|
||||
// float SkylightDir = (slopednormal / dot(abs(slopednormal),vec3(1.0))).y *1.5;
|
||||
// if(isGrass) SkylightDir = 1.5;
|
||||
|
||||
// skylight = max(pow((FlatNormals).y*0.5+0.5,0.1) + SkylightDir, 0.2 + (1-lightmap.y)*0.8);
|
||||
|
||||
// #if indirect_effect == 1
|
||||
// skylight = min(skylight, mix(0.95, 2.5, pow(1-pow(1-SSAO_SSS.x, 0.5),2.0) ));
|
||||
// #endif
|
||||
|
||||
// vec3 lastLightPos = feetPlayerPos + (cameraPosition - lastKnownLightlevel);// - vec3(0,0,0);
|
||||
// lastLightPos.y = min(lastLightPos.y,0.0);
|
||||
|
||||
vec3 indirectNormal = slopednormal / dot(abs(slopednormal),vec3(1.0));
|
||||
|
||||
//(slopednormal / dot(abs(slopednormal),vec3(1.0))).y;
|
||||
float SkylightDir = indirectNormal.y;
|
||||
if(isGrass) SkylightDir = 1.0;
|
||||
|
||||
SkylightDir = clamp(SkylightDir*0.7+0.3, 0.0, pow(1-pow(1-SSAO_SSS.x, 0.5),4.0) * 0.7 + 0.3);
|
||||
// SkylightDir = SkylightDir*0.7+0.3;
|
||||
|
||||
// float indirectPointLight = clamp(dot(slopednormal, -normalize(lastLightPos)),0,1);
|
||||
// float lightAttenuation = 1.0-clamp(1.0-length(lastLightPos)/16,0,1);
|
||||
// SkylightDir = mix(mix(SkylightDir, indirectPointLight, updateFadeTime), SkylightDir, max(lightAttenuation,min(max(lightmap.y-0.9,0)/0.1,1)));
|
||||
|
||||
// skylight = mix(0.2, 2.5, SkylightDir);
|
||||
|
||||
skylight = mix(0.2 + 2.3*(1.0-lightmap.y), 2.5, SkylightDir);
|
||||
|
||||
// skylight = 2.5;
|
||||
|
||||
#endif
|
||||
|
||||
#if indirect_effect == 3 || indirect_effect == 4
|
||||
@ -1575,14 +1183,20 @@ void main() {
|
||||
///////////////////////////// SKY SSS /////////////////////////////
|
||||
#if defined Ambient_SSS && defined OVERWORLD_SHADER && indirect_effect == 1
|
||||
if (!hand){
|
||||
vec3 ambientColor = AmbientLightColor * ambientsss_brightness * 3.0;//mix(0.2,2.5,lightmap.y*lightmap.y); // x2.5 to match the brightness of upfacing skylight
|
||||
vec3 ambientColor = AmbientLightColor * ambientsss_brightness * ambient_brightness * 3.0;
|
||||
|
||||
Indirect_SSS = SubsurfaceScattering_sky(albedo, SkySSS, LabSSS);
|
||||
Indirect_SSS *= lightmap.y;
|
||||
|
||||
// if(texcoord.x>0.5) oIndirect_SSS *= 0.0;
|
||||
// apply to ambient light.
|
||||
Indirect_lighting = max(Indirect_lighting, Indirect_SSS * ambientColor );
|
||||
|
||||
float thingy = SkySSS;
|
||||
thingy = pow(thingy,3.5);
|
||||
thingy = 1-pow(1-thingy,5);
|
||||
|
||||
if(LabSSS > 0.0) Indirect_lighting = Indirect_lighting + Indirect_SSS * ambientColor;
|
||||
// Indirect_lighting = max(Indirect_lighting, Indirect_SSS * ambientColor);
|
||||
// Indirect_lighting += Indirect_SSS * ambientColor;
|
||||
|
||||
// #ifdef OVERWORLD_SHADER
|
||||
@ -1658,8 +1272,12 @@ void main() {
|
||||
Background += stars(orbitstar) * 10.0 * clamp(-unsigned_WsunVec.y*2.0,0.0,1.0);
|
||||
|
||||
#if !defined ambientLight_only && (RESOURCEPACK_SKY == 1 || RESOURCEPACK_SKY == 0)
|
||||
Background += drawSun(dot(lightCol.a * WsunVec, feetPlayerPos_normalized),0, DirectLightColor,vec3(0.0));
|
||||
Background += drawMoon(feetPlayerPos_normalized, lightCol.a * WsunVec, DirectLightColor, Background);
|
||||
Background += drawSun(dot(unsigned_WsunVec, feetPlayerPos_normalized), 0, DirectLightColor,vec3(0.0));
|
||||
|
||||
vec3 moonLightCol = moonCol / 2400.0;
|
||||
|
||||
Background += drawMoon(feetPlayerPos_normalized, WmoonVec, moonLightCol, Background);
|
||||
// Background += drawSun(dot(WmoonVec, feetPlayerPos_normalized),0, moonLightCol,vec3(0.0));
|
||||
#endif
|
||||
|
||||
Background *= atmosphereGround;
|
||||
@ -1702,7 +1320,10 @@ void main() {
|
||||
|
||||
////// DEBUG VIEW STUFF
|
||||
#if DEBUG_VIEW == debug_SHADOWMAP
|
||||
gl_FragData[0].rgb = vec3(0.5) + vec3(1.0) * Shadows * 30.0;
|
||||
gl_FragData[0].rgb = vec3(1.0) * (Shadows * 0.9 + 0.1);
|
||||
|
||||
if(dot(feetPlayerPos_normalized, unsigned_WsunVec) > 0.999 ) gl_FragData[0].rgb = vec3(10,10,0);
|
||||
if(dot(feetPlayerPos_normalized, -WmoonVec) > 0.999 ) gl_FragData[0].rgb = vec3(1,1,10);
|
||||
#endif
|
||||
#if DEBUG_VIEW == debug_NORMALS
|
||||
if(swappedDepth >= 1.0) Direct_lighting = vec3(1.0);
|
||||
@ -1717,41 +1338,23 @@ void main() {
|
||||
gl_FragData[0].rgb = Indirect_lighting;
|
||||
#endif
|
||||
#if DEBUG_VIEW == debug_DIRECT
|
||||
if(swappedDepth >= 1.0) Direct_lighting = vec3(1.0);
|
||||
gl_FragData[0].rgb = Direct_lighting;
|
||||
if(swappedDepth < 1.0) gl_FragData[0].rgb = vec3(NdotL);
|
||||
#endif
|
||||
#if DEBUG_VIEW == debug_VIEW_POSITION
|
||||
gl_FragData[0].rgb = viewPos * 0.001;
|
||||
#endif
|
||||
#if DEBUG_VIEW == debug_FILTERED_STUFF
|
||||
// if(hideGUI == 1){
|
||||
// gl_FragData[0].rgb = texture2D(colortex14, texcoord).xyz;
|
||||
// gl_FragData[0].rgb = vec3(1) * pow(1-texture2D(colortex14, texcoord).y,1);
|
||||
// gl_FragData[0].rgb = vec3(1) * texture2D(colortex14, texcoord).x;
|
||||
float value = SSAO_SSS.y;
|
||||
|
||||
value = pow(value,5);
|
||||
value = 1-pow(1-value,5);
|
||||
if(hideGUI == 0){
|
||||
|
||||
// value = calculateSSAO(viewPos,worldToView(testNorm),R2_dither());
|
||||
value = pow(value,3.5);
|
||||
value = 1-pow(1-value,5);
|
||||
|
||||
if(hideGUI == 1) value = pow(SSAO_SSS.x,6);
|
||||
gl_FragData[0].rgb = vec3(value);
|
||||
if(hideGUI == 1) value = pow(SSAO_SSS.x,6);
|
||||
gl_FragData[0].rgb = vec3(value);
|
||||
|
||||
if(swappedDepth >= 1.0) gl_FragData[0].rgb = vec3(1.0);
|
||||
// }
|
||||
// if(hideGUI == 0) gl_FragData[0].rgb = vec3(1) * exp(-10*filteredShadow.y);//exp(-7*(1-clamp(1.0 - filteredShadow.x,0.0,1.0)));
|
||||
if(swappedDepth >= 1.0) gl_FragData[0].rgb = vec3(1.0);
|
||||
}
|
||||
#endif
|
||||
// gl_FragData[0].rgb = albedo*30;
|
||||
// gl_FragData[0].rgb = vec3(1) * Shadows;
|
||||
// if(swappedDepth >= 1.0) gl_FragData[0].rgb = vec3(0.1);
|
||||
|
||||
// gl_FragData[0].rgb = vec3(1) * ld(texture2D(depthtex1, texcoord).r);
|
||||
// if(texcoord.x > 0.5 )
|
||||
|
||||
// gl_FragData[0].rgb = vec3(1) * filteredShadow.y;
|
||||
// if(swappedDepth >= 1.0) gl_FragData[0].rgb += vec3(0.5);
|
||||
|
||||
|
||||
/* RENDERTARGETS:3 */
|
||||
}
|
@ -12,9 +12,11 @@
|
||||
|
||||
|
||||
flat varying vec3 WsunVec;
|
||||
flat varying vec3 WmoonVec;
|
||||
flat varying vec3 unsigned_WsunVec;
|
||||
flat varying vec3 averageSkyCol_Clouds;
|
||||
flat varying vec4 lightCol;
|
||||
flat varying vec3 moonCol;
|
||||
|
||||
flat varying float exposure;
|
||||
|
||||
@ -27,6 +29,8 @@ uniform float near;
|
||||
|
||||
uniform mat4 gbufferModelViewInverse;
|
||||
uniform vec3 sunPosition;
|
||||
uniform vec3 moonPosition;
|
||||
|
||||
uniform float rainStrength;
|
||||
uniform float sunElevation;
|
||||
uniform int frameCounter;
|
||||
@ -52,10 +56,20 @@ void main() {
|
||||
lightCol.rgb = texelFetch2D(colortex4,ivec2(6,37),0).rgb;
|
||||
lightCol.a = float(sunElevation > 1e-5)*2.0 - 1.0;
|
||||
|
||||
moonCol = texelFetch2D(colortex4,ivec2(9,37),0).rgb;
|
||||
|
||||
averageSkyCol_Clouds = texelFetch2D(colortex4,ivec2(0,37),0).rgb;
|
||||
|
||||
unsigned_WsunVec = normalize(mat3(gbufferModelViewInverse) * sunPosition);
|
||||
WsunVec = lightCol.a*unsigned_WsunVec;
|
||||
|
||||
vec3 moonVec = normalize(mat3(gbufferModelViewInverse) * moonPosition);
|
||||
|
||||
WmoonVec = moonVec;
|
||||
|
||||
if(dot(-moonVec, unsigned_WsunVec) < 0.9999) WmoonVec = -moonVec;
|
||||
|
||||
WsunVec = mix(WmoonVec, unsigned_WsunVec, clamp(lightCol.a,0,1));
|
||||
|
||||
|
||||
exposure = texelFetch2D(colortex4,ivec2(10,37),0).r;
|
||||
|
||||
|
@ -556,7 +556,7 @@ void main() {
|
||||
float atmosphereAlpha = 1.0;
|
||||
|
||||
vec3 sceneColor = texelFetch2D(colortex3,ivec2(tc/texelSize),0).rgb * VolumetricClouds.a + VolumetricClouds.rgb;
|
||||
vec4 VolumetricFog = GetVolumetricFog(viewPos0, BN, directLightColor, indirectLightColor, indirectLightColor_dynamic, atmosphereAlpha, VolumetricClouds.rgb);
|
||||
vec4 VolumetricFog = GetVolumetricFog(viewPos0, WsunVec, BN, directLightColor, indirectLightColor, indirectLightColor_dynamic, atmosphereAlpha, VolumetricClouds.rgb);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -27,6 +27,7 @@ uniform sampler2D colortex4;
|
||||
|
||||
uniform float sunElevation;
|
||||
uniform vec3 sunPosition;
|
||||
uniform vec3 moonPosition;
|
||||
uniform mat4 gbufferModelViewInverse;
|
||||
uniform int frameCounter;
|
||||
|
||||
@ -80,7 +81,13 @@ void main() {
|
||||
#endif
|
||||
|
||||
lightCol.a = float(sunElevation > 1e-5)*2.0 - 1.0;
|
||||
WsunVec = normalize(mat3(gbufferModelViewInverse) * sunPosition) ;
|
||||
WsunVec = normalize(mat3(gbufferModelViewInverse) * sunPosition);
|
||||
|
||||
vec3 moonVec = normalize(mat3(gbufferModelViewInverse) * moonPosition);
|
||||
vec3 WmoonVec = moonVec;
|
||||
if(dot(-moonVec, WsunVec) < 0.9999) WmoonVec = -moonVec;
|
||||
|
||||
WsunVec = mix(WmoonVec, WsunVec, clamp(lightCol.a,0,1));
|
||||
|
||||
refractedSunVec = refract(lightCol.a*WsunVec, -vec3(0.0,1.0,0.0), 1.0/1.33333);
|
||||
|
||||
|
@ -249,7 +249,7 @@ void ApplyDistortion(inout vec2 Texcoord, vec2 TangentNormals, float lineardista
|
||||
Texcoord = mix(Texcoord, UnalteredTexcoord, min(max(0.1-DistortedAlpha,0.0) * 1000.0,1.0)); // remove distortion on non-translucents
|
||||
}
|
||||
|
||||
vec3 doRefractionEffect( inout vec2 texcoord, vec2 normal, float linearDistance){
|
||||
vec3 doRefractionEffect( inout vec2 texcoord, vec2 normal, float linearDistance, bool isReflectiveEntity){
|
||||
|
||||
// make the tangent space normals match the directions of the texcoord UV, this greatly improves the refraction effect.
|
||||
vec2 UVNormal = vec2(normal.x,-normal.y);
|
||||
@ -258,6 +258,8 @@ vec3 doRefractionEffect( inout vec2 texcoord, vec2 normal, float linearDistance)
|
||||
float diffractionMult = 0.035;
|
||||
float smudgeMult = 1.0;
|
||||
|
||||
if(isReflectiveEntity) refractionMult *= 0.5;
|
||||
|
||||
// for diffraction, i wanted to know *when* normals were at an angle, not what the
|
||||
float clampValue = 0.2;
|
||||
vec2 abberationOffset = (clamp(UVNormal,-clampValue, clampValue)/clampValue) * diffractionMult;
|
||||
@ -272,11 +274,18 @@ vec3 doRefractionEffect( inout vec2 texcoord, vec2 normal, float linearDistance)
|
||||
|
||||
vec2 refractedUV = texcoord - (UVNormal + directionalSmudge)*refractionMult;
|
||||
|
||||
|
||||
#ifdef FAKE_DISPERSION_EFFECT
|
||||
refractionMult *= min( decodeVec2(texelFetch2D(colortex11, ivec2((texcoord - ((UVNormal + abberationOffset) + directionalSmudge)*refractionMult)/texelSize),0).b).g,
|
||||
decodeVec2(texelFetch2D(colortex11, ivec2((texcoord + ((UVNormal + abberationOffset) + directionalSmudge)*refractionMult)/texelSize),0).b).g ) > 0.0 ? 1.0 : 0.0;
|
||||
#else
|
||||
refractionMult *= decodeVec2(texelFetch2D(colortex11, ivec2(refractedUV/texelSize),0).b).g > 0.0 ? 1.0 : 0.0;
|
||||
#endif
|
||||
|
||||
// a max bound around screen edges and edges of the refracted screen
|
||||
vec2 vignetteSides = clamp(min((1.0 - refractedUV)/0.05, refractedUV/0.05)+0.5,0.0,1.0);
|
||||
float vignette = vignetteSides.x*vignetteSides.y;
|
||||
|
||||
refractionMult *= decodeVec2(texelFetch2D(colortex11, ivec2(refractedUV/texelSize),0).b).g > 0.0 ? 1.0 : 0.0;
|
||||
refractionMult *= vignette;
|
||||
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
@ -292,11 +301,12 @@ vec3 doRefractionEffect( inout vec2 texcoord, vec2 normal, float linearDistance)
|
||||
color.b = texelFetch2D(colortex3, ivec2(refractedUV/texelSize),0).b;
|
||||
|
||||
#else
|
||||
refractedUV = clamp(texcoord - UVNormal,0.0,1.0);
|
||||
refractedUV = clamp(texcoord - (UVNormal + directionalSmudge)*refractionMult,0,1);
|
||||
color = texture2D(colortex3, refractedUV).rgb;
|
||||
#endif
|
||||
|
||||
// texcoord = texcoord - (UVNormal+directionalSmudge)*refractionMult*vignette;
|
||||
texcoord = texcoord - (UVNormal + directionalSmudge)*refractionMult;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
@ -526,7 +536,7 @@ void main() {
|
||||
#ifdef FAKE_REFRACTION_EFFECT
|
||||
// ApplyDistortion(refractedCoord, tangentNormals, linearDistance, isEntity);
|
||||
// vec3 color = texture2D(colortex3, refractedCoord).rgb;
|
||||
vec3 color = doRefractionEffect(refractedCoord, tangentNormals.xy, linearDistance);
|
||||
vec3 color = doRefractionEffect(refractedCoord, tangentNormals.xy, linearDistance, isReflectiveEntity);
|
||||
#else
|
||||
// vec3 color = texture2D(colortex3, refractedCoord).rgb;
|
||||
vec3 color = texelFetch2D(colortex3, ivec2(refractedCoord/texelSize),0).rgb;
|
||||
@ -534,7 +544,7 @@ void main() {
|
||||
vec4 TranslucentShader = texture2D(colortex2, texcoord);
|
||||
// color = vec3(texcoord-0.5,0.0) * mat3(gbufferModelViewInverse);
|
||||
// apply block breaking effect.
|
||||
// if(albedo.a > 0.01 && !isWater && TranslucentShader.a <= 0.0 && !isEntity) color = mix(color*6.0, color, luma(albedo.rgb)) * albedo.rgb;
|
||||
if(albedo.a > 0.01 && !isWater && TranslucentShader.a <= 0.0 && !isEntity) color = mix(color*6.0, color, luma(albedo.rgb)) * albedo.rgb;
|
||||
|
||||
////// --------------- BLEND TRANSLUCENT GBUFFERS
|
||||
//////////// and do border fog on opaque and translucents
|
||||
@ -562,18 +572,15 @@ void main() {
|
||||
#else
|
||||
float fog = 0.0;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
if (TranslucentShader.a > 0.0){
|
||||
#ifdef Glass_Tint
|
||||
// if(!isWater) color *= mix(normalize(albedo.rgb+1e-7), vec3(1.0), max(fog, min(max(0.1-albedo.a,0.0) * 10.0,1.0))) ;
|
||||
if(!isWater) color *= mix(normalize(albedo.rgb+1e-7), vec3(1.0), max(fog, min(max(0.1-albedo.a,0.0) * 10.0,1.0))) ;
|
||||
#endif
|
||||
|
||||
// #ifdef BorderFog
|
||||
// TranslucentShader = mix(TranslucentShader, vec4(0.0), fog);
|
||||
// #endif
|
||||
|
||||
#ifdef BorderFog
|
||||
TranslucentShader = mix(TranslucentShader, vec4(0.0), fog);
|
||||
#endif
|
||||
|
||||
color *= (1.0-TranslucentShader.a);
|
||||
color += TranslucentShader.rgb*10.0 ;
|
||||
|
@ -57,9 +57,6 @@ uniform sampler2D colortex1;
|
||||
uniform sampler2D colortex3;
|
||||
uniform sampler2D colortex5;
|
||||
uniform sampler2D colortex6;
|
||||
uniform sampler2D colortex10;
|
||||
uniform sampler2D colortex12;
|
||||
uniform sampler2D colortex14;
|
||||
uniform sampler2D depthtex0;
|
||||
uniform sampler2D depthtex1;
|
||||
|
||||
@ -70,6 +67,7 @@ uniform float viewWidth;
|
||||
|
||||
uniform vec3 previousCameraPosition;
|
||||
uniform mat4 gbufferPreviousModelView;
|
||||
uniform mat4 gbufferPreviousModelViewInverse;
|
||||
|
||||
uniform int hideGUI;
|
||||
|
||||
@ -262,7 +260,7 @@ vec3 FastCatmulRom(sampler2D colorTex, vec2 texcoord, vec4 rtMetrics, float shar
|
||||
|
||||
}
|
||||
|
||||
vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth, bool hand)
|
||||
vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth)
|
||||
{
|
||||
vec2 du = vec2(texelSize.x*2., 0.0);
|
||||
vec2 dv = vec2(0.0, texelSize.y*2.);
|
||||
@ -272,14 +270,6 @@ vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth, bool hand)
|
||||
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;
|
||||
@ -294,7 +284,7 @@ vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth, bool hand)
|
||||
return dmin;
|
||||
}
|
||||
|
||||
vec3 closestToCamera5taps_DH(vec2 texcoord, sampler2D depth, sampler2D dhDepth, bool depthCheck, bool hand)
|
||||
vec3 closestToCamera5taps_DH(vec2 texcoord, sampler2D depth, sampler2D dhDepth, bool depthCheck)
|
||||
{
|
||||
vec2 du = vec2(texelSize.x*2., 0.0);
|
||||
vec2 dv = vec2(0.0, texelSize.y*2.);
|
||||
@ -310,14 +300,6 @@ vec3 closestToCamera5taps_DH(vec2 texcoord, sampler2D depth, sampler2D dhDepth,
|
||||
dmc += vec3( 0.0, 0.0, depthCheck ? texture2D(dhDepth, texcoord).x : texture2D(depth, texcoord).x);
|
||||
dbl += vec3(-texelSize.x, texelSize.y, depthCheck ? texture2D(dhDepth, texcoord + dv - du).x : texture2D(depth, texcoord + dv - du).x);
|
||||
dbr += vec3( texelSize.x, texelSize.y, depthCheck ? texture2D(dhDepth, texcoord + dv + du).x : 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;
|
||||
@ -332,24 +314,6 @@ vec3 closestToCamera5taps_DH(vec2 texcoord, sampler2D depth, sampler2D dhDepth,
|
||||
return dmin;
|
||||
}
|
||||
|
||||
vec3 RGB2YCoCg(vec3 RGB)
|
||||
{
|
||||
vec3 o;
|
||||
o.x = 0.25*RGB.r + 0.5*RGB.g + 0.25*RGB.b;
|
||||
o.y = 0.5*RGB.r - 0.5*RGB.b;
|
||||
o.z = -0.25*RGB.r + 0.5*RGB.g - 0.25*RGB.b;
|
||||
return o;
|
||||
}
|
||||
|
||||
vec3 YCoCg2RGB(vec3 YCoCg)
|
||||
{
|
||||
vec3 o;
|
||||
o.r = YCoCg.x + YCoCg.y - YCoCg.z;
|
||||
o.g = YCoCg.x + YCoCg.z;
|
||||
o.b = YCoCg.x - YCoCg.y - YCoCg.z;
|
||||
return o;
|
||||
}
|
||||
|
||||
vec4 computeTAA(vec2 texcoord, bool hand){
|
||||
|
||||
vec2 jitter = offsets[framemod8]*texelSize*0.5;
|
||||
@ -359,15 +323,16 @@ vec4 computeTAA(vec2 texcoord, bool hand){
|
||||
//use velocity from the nearest texel from camera in a 3x3 box in order to improve edge quality in motion
|
||||
#ifdef DISTANT_HORIZONS
|
||||
bool depthCheck = texture2D(depthtex0,adjTC).x >= 1.0;
|
||||
vec3 closestToCamera = closestToCamera5taps_DH(adjTC, depthtex0, dhDepthTex, depthCheck, hand);
|
||||
vec3 closestToCamera = closestToCamera5taps_DH(adjTC, depthtex0, dhDepthTex, depthCheck);
|
||||
vec3 viewPos = toScreenSpace_DH_special(closestToCamera, depthCheck);
|
||||
#else
|
||||
vec3 closestToCamera = closestToCamera5taps(adjTC, depthtex0, hand);
|
||||
vec3 closestToCamera = closestToCamera5taps(adjTC, depthtex0);
|
||||
vec3 viewPos = toScreenSpace(closestToCamera);
|
||||
#endif
|
||||
|
||||
vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition);
|
||||
vec3 previousPosition = mat3(gbufferPreviousModelView) * playerPos + gbufferPreviousModelView[3].xyz;
|
||||
|
||||
#ifdef DISTANT_HORIZONS
|
||||
previousPosition = toClipSpace3Prev_DH(previousPosition, depthCheck);
|
||||
#else
|
||||
@ -375,7 +340,9 @@ vec4 computeTAA(vec2 texcoord, bool hand){
|
||||
#endif
|
||||
|
||||
vec2 velocity = previousPosition.xy - closestToCamera.xy;
|
||||
previousPosition.xy = texcoord + velocity;
|
||||
|
||||
previousPosition.xy = texcoord + (hand ? vec2(0.0) : velocity);
|
||||
|
||||
// sample current frame, and make sure it is de-jittered
|
||||
// vec3 currentFrame = smoothfilter(colortex3, adjTC + jitter).rgb;
|
||||
vec3 currentFrame = texelFetch2D(colortex3, ivec2((adjTC + jitter)/texelSize), 0).rgb;
|
||||
@ -416,13 +383,12 @@ vec4 computeTAA(vec2 texcoord, bool hand){
|
||||
vec3 clampedframeHistory = clamp(frameHistory, colMin, colMax);
|
||||
|
||||
float blendingFactor = BLEND_FACTOR;
|
||||
|
||||
if(hand) blendingFactor = clamp(length(velocity/texelSize),blendingFactor,1.0);
|
||||
|
||||
////// Increases blending factor when far from AABB, reduces ghosting
|
||||
blendingFactor = clamp(blendingFactor + luma(abs(clampedframeHistory - frameHistory)/clampedframeHistory),0.0,1.0);
|
||||
|
||||
// if(luma(abs(clampedframeHistory - frameHistory)) > 0.01) blendingFactor = 1.0;
|
||||
|
||||
////// Blend current pixel with clamped history, apply fast tonemap beforehand to reduce flickering
|
||||
vec3 finalResult = invTonemap(mix(tonemap(clampedframeHistory), tonemap(currentFrame), blendingFactor));
|
||||
|
||||
@ -451,14 +417,11 @@ void main() {
|
||||
vec2 taauTC = clamp(texcoord*RENDER_SCALE, vec2(0.0), RENDER_SCALE - texelSize*2.0);
|
||||
|
||||
float dataUnpacked = decodeVec2(texelFetch2D(colortex1,ivec2(gl_FragCoord.xy*RENDER_SCALE),0).w).y;
|
||||
|
||||
bool hand = abs(dataUnpacked-0.75) < 0.01 && texture2D(depthtex1,taauTC).x < 1.0;
|
||||
|
||||
// vec4 color = TAA_hq(hand);
|
||||
|
||||
vec4 color = computeTAA(smoothfilterUV(texcoord), hand);
|
||||
|
||||
// gl_FragData[0] = clamp(color, 0.0, 65000.0);
|
||||
|
||||
#ifdef SCREENSHOT_MODE
|
||||
gl_FragData[0] = clamp(color, 0.0, 65000.0);
|
||||
#else
|
||||
|
@ -38,6 +38,7 @@ uniform mat4 gbufferPreviousProjection;
|
||||
uniform mat4 gbufferModelViewInverse;
|
||||
uniform mat4 gbufferModelView;
|
||||
uniform mat4 shadowModelView;
|
||||
uniform mat4 shadowModelViewI;
|
||||
uniform mat4 shadowProjection;
|
||||
uniform float sunElevation;
|
||||
uniform vec3 sunPosition;
|
||||
@ -314,7 +315,7 @@ if (gl_FragCoord.x > 18.+257. && gl_FragCoord.y > 1. && gl_FragCoord.x < 18+257+
|
||||
vec4 volumetricClouds = GetVolumetricClouds(viewPos, vec2(noise, 1.0-noise), WsunVec, suncol*2.5, skyGroundCol/30.0);
|
||||
|
||||
float atmosphereAlpha = 1.0;
|
||||
vec4 volumetricFog = GetVolumetricFog(viewPos, vec2(noise, 1.0-noise), suncol*2.5, skyGroundCol/30.0, averageSkyCol_Clouds*5.0, atmosphereAlpha, volumetricClouds.rgb);
|
||||
vec4 volumetricFog = GetVolumetricFog(viewPos, WsunVec, vec2(noise, 1.0-noise), suncol*2.5, skyGroundCol/30.0, averageSkyCol_Clouds*5.0, atmosphereAlpha, volumetricClouds.rgb);
|
||||
|
||||
sky = sky * volumetricClouds.a + volumetricClouds.rgb / 5.0;
|
||||
sky = sky * volumetricFog.a + volumetricFog.rgb / 5.0;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "/lib/settings.glsl"
|
||||
|
||||
uniform sampler2D colortex4;
|
||||
uniform sampler2D colortex1;
|
||||
uniform sampler2D colortex12;
|
||||
|
||||
uniform vec2 texelSize;
|
||||
@ -30,6 +31,17 @@ float DH_invLinZ (float lindepth){
|
||||
float linearizeDepthFast(const in float depth, const in float near, const in float far) {
|
||||
return (near * far) / (depth * (near - far) + far);
|
||||
}
|
||||
|
||||
void convertHandDepth(inout float depth) {
|
||||
float ndcDepth = depth * 2.0 - 1.0;
|
||||
ndcDepth /= MC_HAND_DEPTH;
|
||||
depth = ndcDepth * 0.5 + 0.5;
|
||||
}
|
||||
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//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
@ -39,9 +51,13 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo
|
||||
void main() {
|
||||
/* RENDERTARGETS:4,12 */
|
||||
vec3 oldTex = texelFetch2D(colortex4, ivec2(gl_FragCoord.xy), 0).xyz;
|
||||
|
||||
float newTex = texelFetch2D(depthtex1, ivec2(gl_FragCoord.xy*4), 0).x;
|
||||
|
||||
|
||||
float dataUnpacked = decodeVec2(texelFetch2D(colortex1,ivec2(gl_FragCoord.xy*4),0).w).y;
|
||||
bool hand = abs(dataUnpacked-0.75) < 0.01;
|
||||
|
||||
if(hand) convertHandDepth(newTex);
|
||||
|
||||
#ifdef DISTANT_HORIZONS
|
||||
float QuarterResDepth = texelFetch2D(dhDepthTex, ivec2(gl_FragCoord.xy*4), 0).x;
|
||||
if(newTex >= 1.0) newTex = sqrt(QuarterResDepth);
|
||||
|
@ -449,7 +449,7 @@ void main() {
|
||||
vec4 VolumetricClouds = GetVolumetricClouds(viewPos1, vec2(noise_1, noise_2), WsunVec, directLightColor, indirectLightColor);
|
||||
|
||||
float atmosphereAlpha = 1.0;
|
||||
vec4 VolumetricFog = GetVolumetricFog(viewPos1, vec2(noise_1, noise_2), directLightColor, indirectLightColor, indirectLightColor_dynamic, atmosphereAlpha, VolumetricClouds.rgb);
|
||||
vec4 VolumetricFog = GetVolumetricFog(viewPos1, WsunVec, vec2(noise_1, noise_2), directLightColor, indirectLightColor, indirectLightColor_dynamic, atmosphereAlpha, VolumetricClouds.rgb);
|
||||
|
||||
finalVolumetrics.rgb += VolumetricClouds.rgb;
|
||||
#endif
|
||||
|
@ -23,6 +23,7 @@ flat varying float exposure;
|
||||
uniform float sunElevation;
|
||||
uniform vec2 texelSize;
|
||||
uniform vec3 sunPosition;
|
||||
uniform vec3 moonPosition;
|
||||
uniform mat4 gbufferModelViewInverse;
|
||||
uniform int frameCounter;
|
||||
|
||||
@ -80,8 +81,13 @@ void main() {
|
||||
|
||||
|
||||
lightCol.a = float(sunElevation > 1e-5)*2.0 - 1.0;
|
||||
WsunVec = lightCol.a * normalize(mat3(gbufferModelViewInverse) * sunPosition);
|
||||
// WsunVec = normalize(LightDir);
|
||||
WsunVec = normalize(mat3(gbufferModelViewInverse) * sunPosition);
|
||||
|
||||
vec3 moonVec = normalize(mat3(gbufferModelViewInverse) * moonPosition);
|
||||
vec3 WmoonVec = moonVec;
|
||||
if(dot(-moonVec, WsunVec) < 0.9999) WmoonVec = -moonVec;
|
||||
|
||||
WsunVec = mix(WmoonVec, WsunVec, clamp(lightCol.a,0,1));
|
||||
|
||||
refractedSunVec = refract(WsunVec, -vec3(0.0,1.0,0.0), 1.0/1.33333);
|
||||
|
||||
|
Reference in New Issue
Block a user