combine end and nether shaders into one group of programs. for my own ease of use.

This commit is contained in:
Xonk 2023-08-03 00:23:29 -04:00
parent cfc8722bc8
commit 848cccd9da
138 changed files with 2362 additions and 4710 deletions

View File

@ -151,7 +151,7 @@ vec3 viewToWorld(vec3 viewPosition) {
#include "/lib/volumetricClouds.glsl" #include "/lib/volumetricClouds.glsl"
#include "/lib/waterBump.glsl" #include "/lib/waterBump.glsl"
#define OVERWORLD #define OVERWORLD_SHADER
#include "/lib/specular.glsl" #include "/lib/specular.glsl"
#include "/lib/diffuse_lighting.glsl" #include "/lib/diffuse_lighting.glsl"

View File

@ -2,21 +2,13 @@
varying vec4 lmtexcoord; varying vec4 lmtexcoord;
varying vec4 color; varying vec4 color;
flat varying vec4 lightCol; //main light source color (rgb),used light source(1=sun,-1=moon)
flat varying vec3 avgAmbient;
uniform vec3 sunVec;
flat varying vec3 WsunVec;
uniform sampler2D texture; uniform sampler2D texture;
uniform sampler2DShadow shadow;
uniform sampler2D gaux1;
uniform sampler2D noisetex;
uniform float frameTimeCounter;
uniform ivec2 eyeBrightnessSmooth;
uniform vec2 texelSize; uniform sampler2D noisetex;
uniform float rainStrength;
uniform sampler2D colortex4;
uniform mat4 gbufferProjectionInverse; uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferModelViewInverse; uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferModelView; uniform mat4 gbufferModelView;
@ -24,12 +16,16 @@ uniform mat4 shadowModelView;
uniform mat4 shadowProjection; uniform mat4 shadowProjection;
uniform vec3 cameraPosition; uniform vec3 cameraPosition;
uniform float frameTimeCounter;
uniform vec2 texelSize;
uniform ivec2 eyeBrightnessSmooth;
uniform float rainStrength;
#include "/lib/settings.glsl" #include "/lib/settings.glsl"
#define END
#define NETHER
#include "/lib/diffuse_lighting.glsl" #include "/lib/diffuse_lighting.glsl"
#include "/lib/sky_gradient.glsl"
vec3 toLinear(vec3 sRGB){ vec3 toLinear(vec3 sRGB){
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878); return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
@ -76,8 +72,23 @@ void main() {
vec3 p3 = mat3(gbufferModelViewInverse) * fragpos; vec3 p3 = mat3(gbufferModelViewInverse) * fragpos;
vec3 np3 = normVec(p3); vec3 np3 = normVec(p3);
vec3 Indirect_lighting = vec3(1.0);
float lightmap = lmtexcoord.z;
vec3 nothing = vec3(0.0);
vec3 Indirect_lighting = DoAmbientLighting_Nether(gl_Fog.color.rgb, vec3(TORCH_R,TORCH_G,TORCH_B), lmtexcoord.z, normalize(vec3(0.0)), normalize(vec3(0.0)), p3 + cameraPosition); #ifdef END_SHADER
float TorchLM = 10.0 - ( 1.0 / (pow(exp(-0.5*inversesqrt(lightmap)),5.0)+0.1));
TorchLM = pow(TorchLM/4,10) + pow(lightmap,1.5)*0.5;
vec3 TorchLight = (vec3(TORCH_R,TORCH_G,TORCH_B) * TorchLM * 0.75) * TORCH_AMOUNT;
Indirect_lighting = max(vec3(0.5,0.75,1.0) * 0.1, (MIN_LIGHT_AMOUNT*0.01 + nightVision*0.5) ) + TorchLight;
#endif
#ifdef NETHER_SHADER
vec3 AmbientLightColor = skyCloudsFromTexLOD2(vec3( 0, 1, 0), colortex4, 6).rgb / 10;
Indirect_lighting = DoAmbientLighting_Nether(AmbientLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap, nothing, nothing, nothing);
#endif
gl_FragData[0].rgb = Indirect_lighting * Albedo; gl_FragData[0].rgb = Indirect_lighting * Albedo;
} }

View File

@ -72,7 +72,7 @@ flat varying vec3 averageSkyCol_Clouds;
#include "/lib/clouds.glsl" #include "/lib/clouds.glsl"
#include "/lib/stars.glsl" #include "/lib/stars.glsl"
#include "/lib/volumetricClouds.glsl" #include "/lib/volumetricClouds.glsl"
#define OVERWORLD #define OVERWORLD_SHADER
#include "/lib/diffuse_lighting.glsl" #include "/lib/diffuse_lighting.glsl"
@ -298,7 +298,6 @@ if (gl_FragCoord.x * texelSize.x < RENDER_SCALE.x && gl_FragCoord.y * texelSize
vec4 COLORTEST = vec4(Albedo,UnchangedAlpha); vec4 COLORTEST = vec4(Albedo,UnchangedAlpha);
vec3 p3 = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz; vec3 p3 = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz;
vec3 normal = normalMat.xyz; vec3 normal = normalMat.xyz;
@ -337,13 +336,12 @@ if (gl_FragCoord.x * texelSize.x < RENDER_SCALE.x && gl_FragCoord.y * texelSize
gl_FragData[2] = vec4(encodeVec2(TangentNormal), encodeVec2(COLORTEST.rg), encodeVec2(COLORTEST.ba), UnchangedAlpha); gl_FragData[2] = vec4(encodeVec2(TangentNormal), encodeVec2(COLORTEST.rg), encodeVec2(COLORTEST.ba), UnchangedAlpha);
vec3 WS_normal = viewToWorld(normal); vec3 WS_normal = viewToWorld(normal);
vec2 lightmaps2 = lmtexcoord.zw; vec2 lightmaps2 = lmtexcoord.zw;
vec3 Indirect_lighting = vec3(0.0); vec3 Indirect_lighting = vec3(0.0);
#ifdef NETHER #ifdef NETHER_SHADER
WS_normal.xz = -WS_normal.xz; WS_normal.xz = -WS_normal.xz;
vec3 AmbientLightColor = skyCloudsFromTexLOD2(WS_normal, colortex4, 6).rgb / 15; vec3 AmbientLightColor = skyCloudsFromTexLOD2(WS_normal, colortex4, 6).rgb / 15;
@ -359,7 +357,7 @@ if (gl_FragCoord.x * texelSize.x < RENDER_SCALE.x && gl_FragCoord.y * texelSize
Indirect_lighting = DoAmbientLighting_Nether(AmbientLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmaps2.x, vec3(0.0), vec3(0.0), vec3(0.0)); Indirect_lighting = DoAmbientLighting_Nether(AmbientLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmaps2.x, vec3(0.0), vec3(0.0), vec3(0.0));
#endif #endif
#ifdef END #ifdef END_SHADER
// do all ambient lighting stuff // do all ambient lighting stuff
Indirect_lighting = DoAmbientLighting_End(gl_Fog.color.rgb, vec3(TORCH_R,TORCH_G,TORCH_B), lightmaps2.x, normal, p3 ); Indirect_lighting = DoAmbientLighting_End(gl_Fog.color.rgb, vec3(TORCH_R,TORCH_G,TORCH_B), lightmaps2.x, normal, p3 );
#endif #endif

View File

@ -0,0 +1,669 @@
#include "/lib/settings.glsl"
#include "/lib/diffuse_lighting.glsl"
varying vec2 texcoord;
const bool colortex5MipmapEnabled = true;
const bool colortex4MipmapEnabled = true;
uniform sampler2D noisetex;//depth
uniform sampler2D depthtex1;//depth
uniform sampler2D depthtex0;//depth
uniform sampler2D colortex0;//clouds
uniform sampler2D colortex1;//albedo(rgb),material(alpha) RGBA16
uniform sampler2D colortex2;
uniform sampler2D colortex3;
uniform sampler2D colortex4;//Skybox
uniform sampler2D colortex5;
uniform sampler2D colortex6;//Skybox
uniform sampler2D colortex7;
uniform sampler2D colortex8;
uniform sampler2D colortex10;
uniform sampler2D colortex15;
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;
uniform vec3 previousCameraPosition;
uniform float far;
uniform float near;
uniform vec2 texelSize;
uniform float viewWidth;
uniform float viewHeight;
uniform float aspectRatio;
flat varying vec2 TAA_Offset;
uniform int frameCounter;
uniform float frameTimeCounter;
uniform float rainStrength;
uniform int isEyeInWater;
uniform ivec2 eyeBrightnessSmooth;
uniform vec3 sunVec;
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
vec3 toScreenSpace(vec3 p) {
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
vec3 p3 = p * 2. - 1.;
vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
return fragposition.xyz / fragposition.w;
}
#include "/lib/color_transforms.glsl"
#include "/lib/waterBump.glsl"
#include "/lib/sky_gradient.glsl"
float ld(float dist) {
return (2.0 * near) / (far + near - dist * (far - near));
}
vec2 RENDER_SCALE = vec2(1.0);
#include "/lib/end_fog.glsl"
#undef LIGHTSOURCE_REFLECTION
#define ENDSPECULAR
#include "/lib/specular.glsl"
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;
dither = center*inversesqrt(abs(center));
return clamp(dither-fsign(center),0.0,1.0);
}
vec3 fp10Dither(vec3 color,float dither){
const vec3 mantissaBits = vec3(6.,6.,5.);
vec3 exponent = floor(log2(color));
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 );
}
vec3 decode (vec2 encn){
vec3 n = vec3(0.0);
encn = encn * 2.0 - 1.0;
n.xy = abs(encn);
n.z = 1.0 - n.x - n.y;
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 ;
}
// float linZ(float depth) {
// return (2.0 * near) / (far + near - depth * (far - near));
// // l = (2*n)/(f+n-d(f-n))
// // f+n-d(f-n) = 2n/l
// // -d(f-n) = ((2n/l)-f-n)
// // d = -((2n/l)-f-n)/(f-n)
// }
// float invLinZ (float lindepth){
// return -((2.0*near/lindepth)-far-near)/(far-near);
// }
// vec3 toClipSpace3(vec3 viewSpacePosition) {
// return projMAD(gbufferProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
// }
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(){
// 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 ;
}
vec2 R2_dither(){
vec2 alpha = vec2(0.75487765, 0.56984026);
return vec2(fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter), fract((1.0-alpha.x) * gl_FragCoord.x + (1.0-alpha.y) * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter));
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * (frameCounter*0.5+0.5) );
}
vec4 blueNoise(vec2 coord){
return texelFetch2D(colortex6, ivec2(coord)%512 , 0) ;
}
vec3 toShadowSpaceProjected(vec3 p3){
p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz;
p3 = mat3(shadowModelView) * p3 + shadowModelView[3].xyz;
p3 = diagonal3(shadowProjection) * p3 + shadowProjection[3].xyz;
return p3;
}
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;
}
float ssao(vec3 fragpos, float dither,vec3 normal)
{
float mulfov = 1.0;
ivec2 pos = ivec2(gl_FragCoord.xy);
const float tan70 = tan(70.*3.14/180.);
float mulfov2 = gbufferProjection[1][1]/tan70;
const float PI = 3.14159265;
const float samplingRadius = 0.712;
float angle_thresh = 0.05;
float rd = mulfov2*0.05;
//pre-rotate direction
float n = 0.;
float occlusion = 0.0;
vec2 acc = -vec2(TAA_Offset)*texelSize*0.5;
float mult = (dot(normal,normalize(fragpos))+1.0)*0.5+0.5;
vec2 v = fract(vec2(dither,interleaved_gradientNoise()) + (frameCounter%10000) * vec2(0.75487765, 0.56984026));
for (int j = 0; j < 7+2 ;j++) {
vec2 sp = tapLocation(j,v.x,7+2,2.,v.y);
vec2 sampleOffset = sp*rd;
ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight));
if (offset.x >= 0 && offset.y >= 0 && offset.x < viewWidth && offset.y < viewHeight ) {
vec3 t0 = toScreenSpace(vec3(offset*texelSize+acc+0.5*texelSize,texelFetch2D(depthtex1,offset,0).x));
vec3 vec = t0.xyz - fragpos;
float dsquared = dot(vec,vec);
if (dsquared > 1e-5){
if (dsquared < fragpos.z*fragpos.z*0.05*0.05*mulfov2*2.*1.412){
float NdotV = clamp(dot(vec*inversesqrt(dsquared), normalize(normal)),0.,1.);
occlusion += NdotV;
}
n += 1.0;
}
}
}
return clamp(1.0-occlusion/n*2.0,0.,1.0);
}
vec3 viewToWorld(vec3 viewPosition) {
vec4 pos;
pos.xyz = viewPosition;
pos.w = 0.0;
pos = gbufferModelViewInverse * pos;
return pos.xyz;
}
vec3 worldToView(vec3 worldPos) {
vec4 pos = vec4(worldPos, 0.0);
pos = gbufferModelView * pos;
return pos.xyz;
}
void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient){
inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value
int spCount = rayMarchSampleCount;
vec3 start = toShadowSpaceProjected(rayStart);
vec3 end = toShadowSpaceProjected(rayEnd);
vec3 dV = (end-start);
//limit ray length at 32 blocks for performance and reducing integration error
//you can't see above this anyway
float maxZ = min(rayLength,12.0)/(1e-8+rayLength);
dV *= maxZ;
vec3 dVWorld = -mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ;
rayLength *= maxZ;
float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength;
estEndDepth *= maxZ;
estSunDepth *= maxZ;
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
float expFactor = 11.0;
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition;
for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
vec3 spPos = start.xyz + dV*d;
progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
vec3 ambientMul = exp(-max(estEndDepth * d,0.0) * waterCoefs);
vec3 light = (ambientMul*ambient) * scatterCoef;
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs *absorbance;
absorbance *= exp(-dd * rayLength * waterCoefs);
}
inColor += vL;
}
void Emission(
inout vec3 Lighting,
vec3 Albedo,
float Emission
){
// if( Emission < 255.0/255.0 ) Lighting = mix(Lighting, Albedo * Emissive_Brightness, pow(Emission, Emissive_Curve)); // old method.... idk why
if( Emission < 255.0/255.0 ) Lighting += (Albedo * Emissive_Brightness * 0.25) * pow(Emission, Emissive_Curve);
}
float rayTraceShadow(vec3 dir,vec3 position,float dither){
const float quality = 16.;
vec3 clipPosition = toClipSpace3(position);
//prevents the ray from going behind the camera
float rayLength = ((position.z + dir.z * far*sqrt(3.)) > -near) ?
(-near -position.z) / dir.z : far*sqrt(3.) ;
vec3 direction = toClipSpace3(position+dir*rayLength)-clipPosition; //convert to clip space
direction.xyz = direction.xyz/max(abs(direction.x)/texelSize.x,abs(direction.y)/texelSize.y); //fixed step size
vec3 stepv = direction * 3.0 * clamp(MC_RENDER_QUALITY,1.,2.0);
vec3 spos = clipPosition;
spos += stepv*dither ;
for (int i = 0; i < int(quality); i++) {
spos += stepv;
float sp = texture2D(depthtex1,spos.xy).x;
if( sp < spos.z) {
float dist = abs(linZ(sp)-linZ(spos.z))/linZ(spos.z);
if (dist < 0.015 ) return i / quality;
}
}
return 1.0;
}
vec3 rayTrace_GI(vec3 dir,vec3 position,float dither, float quality){
vec3 clipPosition = toClipSpace3(position);
float rayLength = ((position.z + dir.z * far*sqrt(3.)) > -near) ?
(-near -position.z) / dir.z : far*sqrt(3.);
vec3 direction = normalize(toClipSpace3(position+dir*rayLength)-clipPosition); //convert to clip space
direction.xy = normalize(direction.xy);
//get at which length the ray intersects with the edge of the screen
vec3 maxLengths = (step(0.,direction)-clipPosition) / direction;
float mult = maxLengths.y;
vec3 stepv = direction * mult / quality*vec3(RENDER_SCALE,1.0) * dither;
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ;
spos.xy += TAA_Offset*texelSize*0.5/RENDER_SCALE;
float biasdist = clamp(position.z*position.z/50.0,1,2); // shrink sample size as distance increases
for(int i = 0; i < int(quality); i++){
spos += stepv;
float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0);
float currZ = linZ(spos.z);
if( sp < currZ) {
float dist = abs(sp-currZ)/currZ;
if (abs(dist) < biasdist*0.05) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0);
}
spos += stepv;
}
return vec3(1.1);
}
vec3 RT(vec3 dir, vec3 position, float noise, float stepsizes){
float dist = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases
float stepSize = stepsizes / dist;
int maxSteps = STEPS;
vec3 clipPosition = toClipSpace3(position);
float rayLength = ((position.z + dir.z * sqrt(3.0)*far) > -sqrt(3.0)*near) ?
(-sqrt(3.0)*near -position.z) / dir.z : sqrt(3.0)*far;
vec3 end = toClipSpace3(position+dir*rayLength) ;
vec3 direction = end-clipPosition ; //convert to clip space
float len = max(abs(direction.x)/texelSize.x,abs(direction.y)/texelSize.y)/stepSize;
//get at which length the ray intersects with the edge of the screen
vec3 maxLengths = (step(0.,direction)-clipPosition) / direction;
float mult = min(min(maxLengths.x,maxLengths.y),maxLengths.z)*2000.0;
vec3 stepv = direction/len;
int iterations = min(int(min(len, mult*len)-2), maxSteps);
//Do one iteration for closest texel (good contact shadows)
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ;
spos.xy += TAA_Offset*texelSize*0.5*RENDER_SCALE;
spos += stepv/(stepSize/2);
float distancered = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases
for(int i = 0; i < iterations; i++){
if (spos.x < 0.0 || spos.y < 0.0 || spos.z < 0.0 || spos.x > 1.0 || spos.y > 1.0 || spos.z > 1.0) return vec3(1.1);
spos += stepv*noise;
float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/ texelSize/4),0).w/65000.0);
float currZ = linZ(spos.z);
if( sp < currZ) {
float dist = abs(sp-currZ)/currZ;
if (dist <= 0.1) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0);
}
}
return vec3(1.1);
}
vec3 cosineHemisphereSample(vec2 Xi, float roughness){
float r = sqrt(Xi.x);
float theta = 2.0 * 3.14159265359 * Xi.y;
float x = r * cos(theta);
float y = r * sin(theta);
return vec3(x, y, sqrt(clamp(1.0 - Xi.x,0.,1.)));
}
vec3 TangentToWorld(vec3 N, vec3 H, float roughness){
vec3 UpVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
vec3 T = normalize(cross(UpVector, N));
vec3 B = cross(N, T);
return vec3((T * H.x) + (B * H.y) + (N * H.z));
}
vec2 R2_samples(int n){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha * n);
}
void ApplySSRT(inout vec3 lighting, vec3 normal,vec2 noise,vec3 fragpos, float lightmaps, vec3 torchcolor){
int nrays = RAY_COUNT;
vec3 radiance = vec3(0.0);
vec3 occlusion = vec3(0.0);
vec3 skycontribution = vec3(0.0);
// float skyLM = 0.0;
// vec3 torchlight = vec3(0.0);
// vec3 blank = vec3(0.0);
// DoRTAmbientLighting(torchcolor, vec2(lightmaps,1.0), skyLM, torchlight, blank);
for (int i = 0; i < nrays; i++){
int seed = (frameCounter%40000)*nrays+i;
vec2 ij = fract(R2_samples(seed) + noise );
vec3 rayDir = TangentToWorld(normal, normalize(cosineHemisphereSample(ij,1.0)) ,1.0);
#ifdef HQ_SSGI
vec3 rayHit = rayTrace_GI( mat3(gbufferModelView) * rayDir, fragpos, blueNoise(), 50.); // ssr rt
#else
vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, fragpos, blueNoise(), 30.); // choc sspt
#endif
skycontribution = lighting;
if (rayHit.z < 1.){
#if indirect_effect == 4
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rayHit) + 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){
radiance += (texture2D(colortex5,previousPosition.xy).rgb + skycontribution) * GI_Strength;
}else{
radiance += skycontribution;
}
#else
radiance += skycontribution;
#endif
occlusion += skycontribution * GI_Strength;
} else {
radiance += skycontribution;
}
}
occlusion *= AO_Strength;
lighting = max(radiance/nrays - occlusion/nrays, 0.0);
}
void main() {
////// --------------- SETUP COORDINATE SPACES --------------- //////
float z0 = texture2D(depthtex0,texcoord).x;
float z = texture2D(depthtex1,texcoord).x;
vec2 tempOffset=TAA_Offset;
float noise = blueNoise();
vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(tempOffset)*texelSize*0.5,z));
vec3 p3 = mat3(gbufferModelViewInverse) * fragpos;
vec3 np3 = normVec(p3);
////// --------------- UNPACK OPAQUE GBUFFERS --------------- //////
vec4 data = texture2D(colortex1,texcoord);
vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y)); // albedo, masks
vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w)); // normals, lightmaps
// vec4 dataUnpacked2 = vec4(decodeVec2(data.z),decodeVec2(data.w));
vec3 albedo = toLinear(vec3(dataUnpacked0.xz,dataUnpacked1.x));
vec2 lightmap = dataUnpacked1.yz;
vec3 normal = decode(dataUnpacked0.yw);
////// --------------- UNPACK MISC --------------- //////
vec4 SpecularTex = texture2D(colortex8,texcoord);
float LabSSS = clamp((-65.0 + SpecularTex.z * 255.0) / 190.0 ,0.0,1.0);
vec4 normalAndAO = texture2D(colortex15,texcoord);
vec3 FlatNormals = normalAndAO.rgb * 2.0 - 1.0;
vec3 slopednormal = normal;
#ifdef POM
#ifdef Horrible_slope_normals
vec3 ApproximatedFlatNormal = normalize(cross(dFdx(p3), dFdy(p3))); // it uses depth that has POM written to it.
slopednormal = normalize(clamp(normal, ApproximatedFlatNormal*2.0 - 1.0, ApproximatedFlatNormal*2.0 + 1.0) );
#endif
#endif
float vanilla_AO = clamp(normalAndAO.a,0,1);
normalAndAO.a = clamp(pow(normalAndAO.a*5,4),0,1);
////// --------------- MASKS/BOOLEANS --------------- //////
bool iswater = texture2D(colortex7,texcoord).a > 0.99;
bool lightningBolt = abs(dataUnpacked1.w-0.5) <0.01;
bool isLeaf = abs(dataUnpacked1.w-0.55) <0.01;
bool entities = abs(dataUnpacked1.w-0.45) < 0.01;
bool hand = abs(dataUnpacked1.w-0.75) < 0.01;
// bool blocklights = abs(dataUnpacked1.w-0.8) <0.01;
////// --------------- COLORS --------------- //////
float dirtAmount = Dirt_Amount;
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;
vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
vec3 Indirect_lighting = vec3(1.0);
vec3 Direct_lighting = vec3(0.0);
///////////////////////////// start drawin :D
if (z >= 1.0) {
gl_FragData[0].rgb = vec3(0.0);
} else {
p3 += gbufferModelViewInverse[3].xyz;
////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// MAJOR LIGHTSOURCE STUFF ////////////////////////
////////////////////////////////////////////////////////////////////////////////////
#ifdef END_SHADER
vec3 LightColor = LightSourceColor(clamp(sqrt(length(p3+cameraPosition) / 150.0 - 1.0) ,0.0,1.0));
vec3 LightPos = LightSourcePosition(p3+cameraPosition, cameraPosition);
float LightFalloff = max(exp2(4.0 + length(LightPos) / -25),0.0);
float NdotL = clamp( dot(normal,normalize(-LightPos)),0.0,1.0);
NdotL = clamp((-15 + NdotL*255.0) / 240.0 ,0.0,1.0);
float fogshadow = GetCloudShadow(p3+cameraPosition, LightPos, blueNoise());
Direct_lighting = (LightColor * max(LightColor - (1-fogshadow) ,0.0)) * LightFalloff * NdotL;
// vec3 LightSource = LightColor * fogshadow * LightFalloff * NdotL ;
float LightFalloff2 = max(1.0-length(LightPos)/120,0.0);
LightFalloff2 = pow(1.0-pow(1.0-LightFalloff2,0.5),2.0);
LightFalloff2 *= 25;
Direct_lighting += (LightColor * max(LightColor - 0.6,0.0)) * vec3(1.0,1.3,1.0) * LightFalloff2 * (NdotL*0.7+0.3);
// float RT_Shadows = rayTraceShadow(worldToView(normalize(-LightPos)), fragpos_RTSHADOW, blueNoise());
// if(!hand) LightSource *= RT_Shadows*RT_Shadows;
#endif
/////////////////////////////////////////////////////////////////////////////////
///////////////////////////// INDIRECT LIGHTING /////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
#ifdef END_SHADER
Indirect_lighting = DoAmbientLighting_End(gl_Fog.color.rgb, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.x, normal, np3);
#endif
#ifdef NETHER_SHADER
vec3 AmbientLightColor = skyCloudsFromTexLOD2(normal, colortex4, 6).rgb / 10;
vec3 up = skyCloudsFromTexLOD2(vec3( 0, 1, 0), colortex4, 6).rgb / 10;
vec3 down = skyCloudsFromTexLOD2(vec3( 0,-1, 0), colortex4, 6).rgb / 10;
up *= pow( max( slopednormal.y, 0), 2);
down *= pow( max(-slopednormal.y, 0), 2);
AmbientLightColor += up + down;
// do all ambient lighting stuff
Indirect_lighting = DoAmbientLighting_Nether(AmbientLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.x, normal, np3, p3 );
#endif
/////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// EFFECTS FOR INDIRECT /////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
#if indirect_effect == 0
vec3 AO = vec3( exp( (vanilla_AO*vanilla_AO) * -5) ) ;
if(!hand) Indirect_lighting *= AO;
#endif
#if indirect_effect == 1
vec3 AO = vec3( exp( (vanilla_AO*vanilla_AO) * -5) ) ;
if(!hand) Indirect_lighting *= ssao(fragpos,noise,FlatNormals) * AO;
#endif
// RTAO and/or SSGI
#if indirect_effect == 3 || indirect_effect == 4
if (!hand) ApplySSRT(Indirect_lighting, normal, blueNoise(gl_FragCoord.xy).rg, fragpos, lightmap.x,vec3(TORCH_R,TORCH_G,TORCH_B));
#endif
/////////////////////////////////////////////////////////////////////////
///////////////////////////// FINALIZE /////////////////////////////
/////////////////////////////////////////////////////////////////////////
gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * albedo;
#ifdef Specular_Reflections
vec3 specNoise = vec3(blueNoise(gl_FragCoord.xy).rg, interleaved_gradientNoise());
DoSpecularReflections(gl_FragData[0].rgb, fragpos, np3, vec3(0.0), specNoise, normal, SpecularTex.r, SpecularTex.g, albedo, vec3(0.0), 1.0, hand);
#endif
Emission(gl_FragData[0].rgb, albedo, SpecularTex.a);
if(lightningBolt) gl_FragData[0].rgb = vec3(1);
}
if (iswater && isEyeInWater == 0){
vec3 fragpos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0));
float Vdiff = distance(fragpos,fragpos0);
float VdotU = np3.y;
float estimatedDepth = Vdiff * abs(VdotU) ; //assuming water plane
vec3 ambientColVol = max(vec3(1.0,0.5,1.0) * 0.3, vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.01 + nightVision));
waterVolumetrics(gl_FragData[0].rgb, fragpos0, fragpos, estimatedDepth , estimatedDepth, Vdiff, noise, totEpsilon, scatterCoef, ambientColVol);
}
/* DRAWBUFFERS:3 */
}

View File

@ -0,0 +1,49 @@
#include "/lib/settings.glsl"
varying vec2 texcoord;
flat varying vec3 avgAmbient;
flat varying float tempOffsets;
flat varying vec2 TAA_Offset;
flat varying vec3 zMults;
uniform sampler2D colortex4;
uniform float far;
uniform float near;
uniform mat4 gbufferModelViewInverse;
uniform vec3 sunPosition;
uniform float rainStrength;
uniform float sunElevation;
uniform int frameCounter;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
vec2(-3,-5.)/8.,
vec2(-5.,5.)/8.,
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
#include "/lib/util.glsl"
void main() {
gl_Position = ftransform();
texcoord = gl_MultiTexCoord0.xy;
tempOffsets = HaltonSeq2(frameCounter%10000);
TAA_Offset = offsets[frameCounter%8];
#ifndef TAA
TAA_Offset = vec2(0.0);
#endif
avgAmbient = texelFetch2D(colortex4,ivec2(0,37),0).rgb;
zMults = vec3((far * near)*2.0,far+near,far-near);
}

View File

@ -0,0 +1,129 @@
#include "/lib/settings.glsl"
uniform sampler2D noisetex;
uniform sampler2D depthtex0;
uniform sampler2D colortex2;
uniform sampler2D colortex3;
// uniform sampler2D colortex4;
uniform vec3 sunVec;
uniform float sunElevation;
uniform float far;
uniform int frameCounter;
uniform float frameTimeCounter;
varying vec2 texcoord;
uniform vec2 texelSize;
flat varying vec2 TAA_Offset;
uniform int isEyeInWater;
uniform float rainStrength;
uniform ivec2 eyeBrightnessSmooth;
#include "/lib/color_transforms.glsl"
#include "/lib/color_dither.glsl"
#include "/lib/projections.glsl"
#ifdef END_SHADER
#include "/lib/end_fog.glsl"
#endif
#ifdef NETHER_SHADER
#include "/lib/nether_fog.glsl"
#endif
#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.)
float interleaved_gradientNoise(){
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+TAA_Offset.x);
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient){
inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value
int spCount = rayMarchSampleCount;
vec3 start = toShadowSpaceProjected(rayStart);
vec3 end = toShadowSpaceProjected(rayEnd);
vec3 dV = (end-start);
//limit ray length at 32 blocks for performance and reducing integration error
//you can't see above this anyway
float maxZ = min(rayLength,12.0)/(1e-8+rayLength);
dV *= maxZ;
rayLength *= maxZ;
float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength;
estEndDepth *= maxZ;
estSunDepth *= maxZ;
vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz;
vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
float expFactor = 11.0;
for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
vec3 spPos = start.xyz + dV*d;
vec3 progressW = start.xyz+cameraPosition+dVWorld;
vec3 ambientMul = exp(-max(estEndDepth * d,0.0) * waterCoefs );
vec3 Indirectlight = ambientMul*ambient;
vec3 light = Indirectlight * scatterCoef;
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
absorbance *= exp(-dd * rayLength * waterCoefs);
}
inColor += vL;
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
/* DRAWBUFFERS:0 */
vec2 tc = floor(gl_FragCoord.xy)*2.0*texelSize+0.5*texelSize;
float z = texture2D(depthtex0,tc).x;
vec3 fragpos = toScreenSpace(vec3(tc,z));
if (isEyeInWater == 0){
vec4 VolumetricFog = GetVolumetricFog(fragpos, blueNoise(), interleaved_gradientNoise());
gl_FragData[0] = clamp(VolumetricFog, 0.000001, 65000.0);
}
if (isEyeInWater == 1){
float dirtAmount = Dirt_Amount;
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;
vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
vec3 fragpos0 = toScreenSpace(vec3(texcoord - TAA_Offset*texelSize*0.5,z));
vec3 ambientColVol = max(vec3(1.0,0.5,1.0) * 0.6, vec3(0.2,0.4,1.0) * MIN_LIGHT_AMOUNT*0.01);
gl_FragData[0].a = 1;
waterVolumetrics(gl_FragData[0].rgb, fragpos0, fragpos, 1 , 1, 1, blueNoise(), totEpsilon, scatterCoef, ambientColVol);
}
}

View File

@ -0,0 +1,20 @@
#include "/lib/util.glsl"
flat varying float tempOffsets;
uniform int frameCounter;
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
gl_Position = ftransform();
tempOffsets = HaltonSeq2(frameCounter%10000);
gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.51*2.0-1.0;
}

View File

@ -0,0 +1,305 @@
#include "/lib/settings.glsl"
flat varying vec3 zMults;
flat varying vec2 TAA_Offset;
uniform sampler2D noisetex;
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
uniform sampler2D colortex0;
uniform sampler2D colortex1;
uniform sampler2D colortex2;
uniform sampler2D colortex3;
// uniform sampler2D colortex4;
uniform sampler2D colortex5;
uniform sampler2D colortex6;
uniform sampler2D colortex7;
uniform sampler2D colortex8;
uniform sampler2D colortex9;
uniform sampler2D colortex11;
uniform sampler2D colortex13;
uniform sampler2D colortex15;
uniform vec2 texelSize;
flat varying vec3 noooormal;
flat varying vec4 lightCol; //main light source color (rgb),used light source(1=sun,-1=moon)
flat varying vec3 WsunVec;
uniform vec3 sunVec;
uniform float frameTimeCounter;
uniform int frameCounter;
uniform float far;
uniform float near;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferModelView;
uniform mat4 gbufferPreviousModelView;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferProjection;
uniform mat4 gbufferPreviousProjection;
uniform vec3 cameraPosition;
uniform vec3 previousCameraPosition;
uniform int isEyeInWater;
uniform ivec2 eyeBrightnessSmooth;
uniform float rainStrength;
uniform float blindness;
uniform float darknessFactor;
uniform float darknessLightFactor;
#include "/lib/waterBump.glsl"
#include "/lib/res_params.glsl"
#include "/lib/sky_gradient.glsl"
#include "/lib/volumetricClouds.glsl"
// #include "/lib/biome_specifics.glsl"
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
float ld(float depth) {
return 1.0 / (zMults.y - depth * zMults.z); // (-depth * (far - near)) = (2.0 * near)/ld - far - near
}
float luma(vec3 color) {
return dot(color,vec3(0.21, 0.72, 0.07));
}
vec3 toLinear(vec3 sRGB){
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
}
vec3 toScreenSpace(vec3 p) {
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
vec3 p3 = p * 2. - 1.;
vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
return fragposition.xyz / fragposition.w;
}
// #include "/lib/specular.glsl"
vec4 BilateralUpscale(sampler2D tex, sampler2D depth,vec2 coord,float frDepth, vec2 distort){
coord = coord;
vec4 vl = vec4(0.0);
float sum = 0.0;
mat3x3 weights;
const ivec2 scaling = ivec2(1.0/VL_RENDER_RESOLUTION);
ivec2 posD = ivec2(coord*VL_RENDER_RESOLUTION + distort)*scaling;
ivec2 posVl = ivec2(coord*VL_RENDER_RESOLUTION + distort);
float dz = zMults.x;
ivec2 pos = (ivec2(gl_FragCoord.xy+frameCounter) % 2 )*2;
ivec2 tcDepth = posD + ivec2(-2,-2) * scaling + pos * scaling;
float dsample = ld(texelFetch2D(depth,tcDepth,0).r);
float w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
vl += texelFetch2D(tex,posVl+ivec2(-2)+pos,0)*w;
sum += w;
tcDepth = posD + ivec2(-2,0) * scaling + pos * scaling;
dsample = ld(texelFetch2D(depth,tcDepth,0).r);
w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
vl += texelFetch2D(tex,posVl+ivec2(-2,0)+pos,0)*w;
sum += w;
tcDepth = posD + ivec2(0) + pos * scaling;
dsample = ld(texelFetch2D(depth,tcDepth,0).r);
w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
vl += texelFetch2D(tex,posVl+ivec2(0)+pos,0)*w;
sum += w;
tcDepth = posD + ivec2(0,-2) * scaling + pos * scaling;
dsample = ld(texelFetch2D(depth,tcDepth,0).r);
w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
vl += texelFetch2D(tex,posVl+ivec2(0,-2)+pos,0)*w;
sum += w;
return vl/sum;
}
vec3 decode (vec2 encn){
vec3 n = vec3(0.0);
encn = encn * 2.0 - 1.0;
n.xy = abs(encn);
n.z = 1.0 - n.x - n.y;
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 ;
}
vec3 worldToView(vec3 worldPos) {
vec4 pos = vec4(worldPos, 0.0);
pos = gbufferModelView * pos;
return pos.xyz;
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
vec4 blueNoise(vec2 coord){
return texelFetch2D(colortex6, ivec2(coord )%512 , 0);
}
vec3 normVec (vec3 vec){
return vec*inversesqrt(dot(vec,vec));
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
vec3 viewToWorld(vec3 viewPosition) {
vec4 pos;
pos.xyz = viewPosition;
pos.w = 0.0;
pos = gbufferModelViewInverse * pos;
return pos.xyz;
}
/// thanks stackoverflow https://stackoverflow.com/questions/944713/help-with-pixel-shader-effect-for-brightness-and-contrast#3027595
void applyContrast(inout vec3 color, float contrast){
color = ((color - 0.5) * max(contrast, 0.0)) + 0.5;
}
void main() {
/* DRAWBUFFERS:73 */
vec2 texcoord = gl_FragCoord.xy*texelSize;
vec4 trpData = texture2D(colortex7,texcoord);
bool iswater = trpData.a > 0.99;
float translucentAlpha = trpData.a;
// vec4 speculartex = texture2D(colortex8,texcoord); // translucents
// float sunlight = speculartex.b;
//3x3 bilateral upscale from half resolution
float z = texture2D(depthtex0,texcoord).x;
float z2 = texture2D(depthtex1,texcoord).x;
float frDepth = ld(z2);
// vec4 vl = texture2D(colortex0,texcoord * 0.5);
////// --------------- UNPACK OPAQUE GBUFFERS --------------- //////
vec4 data_opaque = texture2D(colortex1,texcoord);
vec4 dataUnpacked1 = vec4(decodeVec2(data_opaque.z),decodeVec2(data_opaque.w)); // normals, lightmaps
// vec4 dataUnpacked2 = vec4(decodeVec2(data.z),decodeVec2(data.w));
bool hand = abs(dataUnpacked1.w-0.75) < 0.01;
vec2 lightmap = dataUnpacked1.yz;
////// --------------- UNPACK TRANSLUCENT GBUFFERS --------------- //////
vec3 data = texture2D(colortex11,texcoord).rgb;
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.0) tangentNormals = vec2(0.0);
vec4 TranslucentShader = texture2D(colortex2,texcoord);
float lightleakfix = clamp(pow(eyeBrightnessSmooth.y/240.,2) ,0.0,1.0);
vec2 tempOffset = TAA_Offset;
vec3 fragpos = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z));
vec3 fragpos2 = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z2));
vec3 p3 = mat3(gbufferModelViewInverse) * fragpos;
vec3 np3 = normVec(p3);
vec2 refractedCoord = texcoord;
/// --- REFRACTION --- ///
#ifdef Refraction
refractedCoord += (tangentNormals * clamp((ld(z2) - ld(z)) * 0.5,0.0,0.15)) * RENDER_SCALE;
// refractedCoord += tangentNormals * 0.1 * RENDER_SCALE;
float refractedalpha = decodeVec2(texture2D(colortex11,refractedCoord).b).g;
float refractedalpha2 = texture2D(colortex7,refractedCoord).a;
if( refractedalpha <= 0.001 ||z < 0.56) refractedCoord = texcoord; // remove refracted coords on solids
#endif
/// --- MAIN COLOR BUFFER --- ///
// it is sampled with distorted texcoords
vec3 color = texture2D(colortex3,refractedCoord).rgb;
vec4 vl = BilateralUpscale(colortex0, depthtex1, gl_FragCoord.xy, frDepth, vec2(0.0));
float bloomyFogMult = 1.0;
if (TranslucentShader.a > 0.0){
#ifdef Glass_Tint
if(albedo.a > 0.2) color = color*albedo.rgb + color * clamp(pow(1.0-luma(albedo.rgb),20.),0.0,1.0);
#endif
color = color*(1.0-TranslucentShader.a) + TranslucentShader.rgb;
}
// underwater fog
if (isEyeInWater == 1){
float dirtAmount = Dirt_Amount;
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;
// float fogfade = clamp( exp(length(fragpos) / -20) ,0.0,1.0);
// vec3 fogfade = clamp( exp( (length(fragpos) / -4) * totEpsilon ) ,0.0,1.0);
vec3 fogfade = clamp( exp( (-length(fragpos)) * totEpsilon ) ,0.0,1.0);
fogfade *= 1.0 - clamp( length(fragpos) / far,0.0,1.0);
color.rgb *= fogfade ;
bloomyFogMult *= 0.4;
}
// apply VL fog to the scene
color *= vl.a;
color += vl.rgb;
// bloomy rain effect
float rainDrops = clamp(texture2D(colortex9,texcoord).a, 0.0,1.0);
if(rainDrops > 0.0) bloomyFogMult *= clamp(1.0 - pow(rainDrops*5.0,2),0.0,1.0);
/// lava.
if (isEyeInWater == 2){
color.rgb = vec3(4.0,0.5,0.1);
}
/// powdered snow
if (isEyeInWater == 3){
color.rgb = mix(color.rgb,vec3(10,15,20),clamp(length(fragpos)*0.5,0.,1.));
bloomyFogMult = 0.0;
}
// blidnesss
color.rgb *= mix(1.0,clamp( exp(pow(length(fragpos)*(blindness*0.2),2) * -1),0.,1.) , blindness);
// darkness effect
color.rgb *= mix(1.0, (1.0-darknessLightFactor*2.0) * clamp(1.0-pow(length(fragpos2)*(darknessFactor*0.07),2.0),0.0,1.0), darknessFactor);
#ifdef display_LUT
vec2 movedTC = texcoord;
vec3 thingy = texture2D(colortex4,movedTC).rgb / 150. * 5.0;
if(luma(thingy) > 0.0 ) color.rgb = thingy;
#endif
gl_FragData[0].r = vl.a * bloomyFogMult; // pass fog alpha so bloom can do bloomy fog
gl_FragData[1].rgb = clamp(color.rgb,0.0,68000.0);
}

View File

@ -0,0 +1,17 @@
varying vec2 texcoord;
flat varying vec3 zMults;
uniform float far;
uniform float near;
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
zMults = vec3(1.0/(far * near),far+near,far-near);
gl_Position = ftransform();
texcoord = gl_MultiTexCoord0.xy;
}

View File

@ -0,0 +1,350 @@
#include "/lib/settings.glsl"
const int noiseTextureResolution = 32;
/*
const int colortex0Format = RGBA16F; // low res clouds (deferred->composite2) + low res VL (composite5->composite15)
const int colortex1Format = RGBA16; //terrain gbuffer (gbuffer->composite2)
const int colortex2Format = RGBA16F; //forward + transparencies (gbuffer->composite4)
const int colortex3Format = R11F_G11F_B10F; //frame buffer + bloom (deferred6->final)
const int colortex4Format = RGBA16F; //light values and skyboxes (everything)
const int colortex5Format = R11F_G11F_B10F; //TAA buffer (everything)
const int colortex6Format = R11F_G11F_B10F; //additionnal buffer for bloom (composite3->final)
const int colortex7Format = RGBA8; //Final output, transparencies id (gbuffer->composite4)
*/
//no need to clear the buffers, saves a few fps
const bool colortex0Clear = false;
const bool colortex1Clear = false;
const bool colortex2Clear = true;
const bool colortex3Clear = false;
const bool colortex4Clear = false;
const bool colortex5Clear = false;
const bool colortex6Clear = false;
const bool colortex7Clear = false;
varying vec2 texcoord;
flat varying float exposureA;
flat varying float tempOffsets;
uniform sampler2D colortex3;
uniform sampler2D colortex5;
uniform sampler2D colortex10;
uniform sampler2D depthtex0;
uniform vec2 texelSize;
uniform float frameTimeCounter;
uniform int framemod8;
uniform float viewHeight;
uniform float viewWidth;
uniform vec3 previousCameraPosition;
uniform mat4 gbufferPreviousModelView;
#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.)
#include "/lib/projections.glsl"
float luma(vec3 color) {
return dot(color,vec3(0.21, 0.72, 0.07));
}
float interleaved_gradientNoise(){
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+tempOffsets);
}
float triangularize(float dither)
{
float center = dither*2.0-1.0;
dither = center*inversesqrt(abs(center));
return clamp(dither-fsign(center),0.0,1.0);
}
vec3 fp10Dither(vec3 color,float dither){
const vec3 mantissaBits = vec3(6.,6.,5.);
vec3 exponent = floor(log2(color));
return color + dither*exp2(-mantissaBits)*exp2(exponent);
}
//returns the projected coordinates of the closest point to the camera in the 3x3 neighborhood
vec3 closestToCamera3x3()
{
vec2 du = vec2(texelSize.x, 0.0);
vec2 dv = vec2(0.0, texelSize.y);
vec3 dtl = vec3(texcoord,0.) + vec3(-texelSize, texture2D(depthtex0, texcoord - dv - du).x);
vec3 dtc = vec3(texcoord,0.) + vec3( 0.0, -texelSize.y, texture2D(depthtex0, texcoord - dv).x);
vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture2D(depthtex0, texcoord - dv + du).x);
vec3 dml = vec3(texcoord,0.) + vec3(-texelSize.x, 0.0, texture2D(depthtex0, texcoord - du).x);
vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture2D(depthtex0, texcoord).x);
vec3 dmr = vec3(texcoord,0.) + vec3( texelSize.x, 0.0, texture2D(depthtex0, texcoord + du).x);
vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture2D(depthtex0, texcoord + dv - du).x);
vec3 dbc = vec3(texcoord,0.) + vec3( 0.0, texelSize.y, texture2D(depthtex0, texcoord + dv).x);
vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture2D(depthtex0, texcoord + dv + du).x);
vec3 dmin = dmc;
dmin = dmin.z > dtc.z? dtc : dmin;
dmin = dmin.z > dtr.z? dtr : dmin;
dmin = dmin.z > dml.z? dml : dmin;
dmin = dmin.z > dtl.z? dtl : dmin;
dmin = dmin.z > dmr.z? dmr : dmin;
dmin = dmin.z > dbl.z? dbl : dmin;
dmin = dmin.z > dbc.z? dbc : dmin;
dmin = dmin.z > dbr.z? dbr : dmin;
return dmin;
}
//Modified texture interpolation from inigo quilez
vec4 smoothfilter(in sampler2D tex, 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 texture2D( tex, uv);
}
//Due to low sample count we "tonemap" the inputs to preserve colors and smoother edges
vec3 weightedSample(sampler2D colorTex, vec2 texcoord){
vec3 wsample = texture2D(colorTex,texcoord).rgb*exposureA;
return wsample/(1.0+luma(wsample));
}
//from : https://gist.github.com/TheRealMJP/c83b8c0f46b63f3a88a5986f4fa982b1
vec4 SampleTextureCatmullRom(sampler2D tex, vec2 uv, vec2 texSize )
{
// We're going to sample a a 4x4 grid of texels surrounding the target UV coordinate. We'll do this by rounding
// down the sample location to get the exact center of our "starting" texel. The starting texel will be at
// location [1, 1] in the grid, where [0, 0] is the top left corner.
vec2 samplePos = uv * texSize;
vec2 texPos1 = floor(samplePos - 0.5) + 0.5;
// Compute the fractional offset from our starting texel to our original sample location, which we'll
// feed into the Catmull-Rom spline function to get our filter weights.
vec2 f = samplePos - texPos1;
// Compute the Catmull-Rom weights using the fractional offset that we calculated earlier.
// These equations are pre-expanded based on our knowledge of where the texels will be located,
// which lets us avoid having to evaluate a piece-wise function.
vec2 w0 = f * ( -0.5 + f * (1.0 - 0.5*f));
vec2 w1 = 1.0 + f * f * (-2.5 + 1.5*f);
vec2 w2 = f * ( 0.5 + f * (2.0 - 1.5*f) );
vec2 w3 = f * f * (-0.5 + 0.5 * f);
// Work out weighting factors and sampling offsets that will let us use bilinear filtering to
// simultaneously evaluate the middle 2 samples from the 4x4 grid.
vec2 w12 = w1 + w2;
vec2 offset12 = w2 / (w1 + w2);
// Compute the final UV coordinates we'll use for sampling the texture
vec2 texPos0 = texPos1 - vec2(1.0);
vec2 texPos3 = texPos1 + vec2(2.0);
vec2 texPos12 = texPos1 + offset12;
texPos0 *= texelSize;
texPos3 *= texelSize;
texPos12 *= texelSize;
vec4 result = vec4(0.0);
result += texture2D(tex, vec2(texPos0.x, texPos0.y)) * w0.x * w0.y;
result += texture2D(tex, vec2(texPos12.x, texPos0.y)) * w12.x * w0.y;
result += texture2D(tex, vec2(texPos3.x, texPos0.y)) * w3.x * w0.y;
result += texture2D(tex, vec2(texPos0.x, texPos12.y)) * w0.x * w12.y;
result += texture2D(tex, vec2(texPos12.x, texPos12.y)) * w12.x * w12.y;
result += texture2D(tex, vec2(texPos3.x, texPos12.y)) * w3.x * w12.y;
result += texture2D(tex, vec2(texPos0.x, texPos3.y)) * w0.x * w3.y;
result += texture2D(tex, vec2(texPos12.x, texPos3.y)) * w12.x * w3.y;
result += texture2D(tex, vec2(texPos3.x, texPos3.y)) * w3.x * w3.y;
return result;
}
//approximation from SMAA presentation from siggraph 2016
vec3 FastCatmulRom(sampler2D colorTex, vec2 texcoord, vec4 rtMetrics, float sharpenAmount)
{
vec2 position = rtMetrics.zw * texcoord;
vec2 centerPosition = floor(position - 0.5) + 0.5;
vec2 f = position - centerPosition;
vec2 f2 = f * f;
vec2 f3 = f * f2;
float c = sharpenAmount;
vec2 w0 = -c * f3 + 2.0 * c * f2 - c * f;
vec2 w1 = (2.0 - c) * f3 - (3.0 - c) * f2 + 1.0;
vec2 w2 = -(2.0 - c) * f3 + (3.0 - 2.0 * c) * f2 + c * f;
vec2 w3 = c * f3 - c * f2;
vec2 w12 = w1 + w2;
vec2 tc12 = rtMetrics.xy * (centerPosition + w2 / w12);
vec3 centerColor = texture2D(colorTex, vec2(tc12.x, tc12.y)).rgb;
vec2 tc0 = rtMetrics.xy * (centerPosition - 1.0);
vec2 tc3 = rtMetrics.xy * (centerPosition + 2.0);
vec4 color = vec4(texture2D(colorTex, vec2(tc12.x, tc0.y )).rgb, 1.0) * (w12.x * w0.y ) +
vec4(texture2D(colorTex, vec2(tc0.x, tc12.y)).rgb, 1.0) * (w0.x * w12.y) +
vec4(centerColor, 1.0) * (w12.x * w12.y) +
vec4(texture2D(colorTex, vec2(tc3.x, tc12.y)).rgb, 1.0) * (w3.x * w12.y) +
vec4(texture2D(colorTex, vec2(tc12.x, tc3.y )).rgb, 1.0) * (w12.x * w3.y );
return color.rgb/color.a;
}
vec3 clip_aabb(vec3 q,vec3 aabb_min, vec3 aabb_max)
{
vec3 p_clip = 0.5 * (aabb_max + aabb_min);
vec3 e_clip = 0.5 * (aabb_max - aabb_min) + 0.00000001;
vec3 v_clip = q - vec3(p_clip);
vec3 v_unit = v_clip.xyz / e_clip;
vec3 a_unit = abs(v_unit);
float ma_unit = max(a_unit.x, max(a_unit.y, a_unit.z));
if (ma_unit > 1.0)
return vec3(p_clip) + v_clip / ma_unit;
else
return q;
}
vec3 toClipSpace3Prev(vec3 viewSpacePosition) {
return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
}
vec3 tonemap(vec3 col){
return col/(1+luma(col));
}
vec3 invTonemap(vec3 col){
return col/(1-luma(col));
}
vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth)
{
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);
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;
return dmin;
}
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
vec2(-3,-5.)/8.,
vec2(-5.,5.)/8.,
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
vec3 TAA_hq(){
vec2 adjTC = texcoord;
//use velocity from the nearest texel from camera in a 3x3 box in order to improve edge quality in motion
#ifdef CLOSEST_VELOCITY
vec3 closestToCamera = closestToCamera5taps(adjTC, depthtex0);
#endif
#ifndef CLOSEST_VELOCITY
vec3 closestToCamera = vec3(texcoord,texture2D(depthtex1,adjTC).x);
#endif
//reproject previous frame
vec3 fragposition = toScreenSpace(closestToCamera);
fragposition = mat3(gbufferModelViewInverse) * fragposition + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition);
vec3 previousPosition = mat3(gbufferPreviousModelView) * fragposition + gbufferPreviousModelView[3].xyz;
previousPosition = toClipSpace3Prev(previousPosition);
vec2 velocity = previousPosition.xy - closestToCamera.xy;
previousPosition.xy = texcoord + velocity;
//reject history if off-screen and early exit
if (previousPosition.x < 0.0 || previousPosition.y < 0.0 || previousPosition.x > 1.0 || previousPosition.y > 1.0)
return smoothfilter(colortex3, adjTC + offsets[framemod8]*texelSize*0.5).xyz;
vec3 albedoCurrent0 = texture2D(colortex3, adjTC).rgb;
vec3 albedoCurrent1 = texture2D(colortex3, adjTC + vec2(texelSize.x,texelSize.y)).rgb;
vec3 albedoCurrent2 = texture2D(colortex3, adjTC + vec2(texelSize.x,-texelSize.y)).rgb;
vec3 albedoCurrent3 = texture2D(colortex3, adjTC + vec2(-texelSize.x,-texelSize.y)).rgb;
vec3 albedoCurrent4 = texture2D(colortex3, adjTC + vec2(-texelSize.x,texelSize.y)).rgb;
vec3 albedoCurrent5 = texture2D(colortex3, adjTC + vec2(0.0,texelSize.y)).rgb;
vec3 albedoCurrent6 = texture2D(colortex3, adjTC + vec2(0.0,-texelSize.y)).rgb;
vec3 albedoCurrent7 = texture2D(colortex3, adjTC + vec2(-texelSize.x,0.0)).rgb;
vec3 albedoCurrent8 = texture2D(colortex3, adjTC + vec2(texelSize.x,0.0)).rgb;
//Assuming the history color is a blend of the 3x3 neighborhood, we clamp the history to the min and max of each channel in the 3x3 neighborhood
vec3 cMax = max(max(max(albedoCurrent0,albedoCurrent1),albedoCurrent2),max(albedoCurrent3,max(albedoCurrent4,max(albedoCurrent5,max(albedoCurrent6,max(albedoCurrent7,albedoCurrent8))))));
vec3 cMin = min(min(min(albedoCurrent0,albedoCurrent1),albedoCurrent2),min(albedoCurrent3,min(albedoCurrent4,min(albedoCurrent5,min(albedoCurrent6,min(albedoCurrent7,albedoCurrent8))))));
albedoCurrent0 = smoothfilter(colortex3, adjTC + offsets[framemod8]*texelSize*0.5).rgb;
#ifndef NO_CLIP
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);
float test = 0.05;
bool isEntities = texture2D(colortex10,texcoord).x > 0.0;
// if(isEntities) test = 0.15;
// if(istranslucent) test = 0.1;
//Blend current pixel with clamped history, apply fast tonemap beforehand to reduce flickering
// vec3 supersampled = invTonemap(mix(tonemap(finalcAcc),tonemap(albedoCurrent0),clamp(BLEND_FACTOR + movementRejection, min(luma(motionVector) *255,1.0),1.)));
vec3 supersampled = invTonemap(mix(tonemap(finalcAcc),tonemap(albedoCurrent0),clamp(BLEND_FACTOR + movementRejection, test,1.)));
#endif
#ifdef NO_CLIP
vec3 albedoPrev = texture2D(colortex5, previousPosition.xy).xyz;
vec3 supersampled = mix(albedoPrev,albedoCurrent0,clamp(0.05,0.,1.));
#endif
//De-tonemap
return supersampled;
}
void main() {
/* DRAWBUFFERS:5 */
gl_FragData[0].a = 1.0;
#ifdef TAA
vec3 color = TAA_hq();
gl_FragData[0].rgb = clamp(fp10Dither(color,triangularize(interleaved_gradientNoise())),6.11*1e-5,65000.0);
#endif
#ifndef TAA
vec3 color = clamp(fp10Dither(texture2D(colortex3,texcoord).rgb,triangularize(interleaved_gradientNoise())),0.,65000.);
gl_FragData[0].rgb = color;
#endif
}

View File

@ -0,0 +1,17 @@
#include "/lib/util.glsl"
varying vec2 texcoord;
flat varying float exposureA;
flat varying float tempOffsets;
uniform sampler2D colortex4;
uniform int frameCounter;
void main() {
tempOffsets = HaltonSeq2(frameCounter%10000);
gl_Position = ftransform();
texcoord = gl_MultiTexCoord0.xy;
exposureA = texelFetch2D(colortex4,ivec2(10,37),0).r;
}

View File

@ -0,0 +1,42 @@
uniform sampler2D colortex5;
uniform vec2 texelSize;
uniform float viewWidth;
uniform float viewHeight;
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
/* DRAWBUFFERS:3 */
vec2 resScale = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.))/vec2(1920.,1080.);
vec2 quarterResTC = gl_FragCoord.xy*2.*resScale*texelSize;
//0.5
gl_FragData[0] = texture2D(colortex5,quarterResTC-1.0*vec2(texelSize.x,texelSize.y))/4.*0.5;
gl_FragData[0] += texture2D(colortex5,quarterResTC+1.0*vec2(texelSize.x,texelSize.y))/4.*0.5;
gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(-1.0*texelSize.x,1.0*texelSize.y))/4.*0.5;
gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(1.0*texelSize.x,-1.0*texelSize.y))/4.*0.5;
//0.25
gl_FragData[0] += texture2D(colortex5,quarterResTC-2.0*vec2(texelSize.x,0.0))/2.*0.125;
gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(0.0,texelSize.y))/2.*0.125;
gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(0,-texelSize.y))/2*0.125;
gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(-texelSize.x,0.0))/2*0.125;
//0.125
gl_FragData[0] += texture2D(colortex5,quarterResTC-2.0*vec2(texelSize.x,texelSize.y))/4.*0.125;
gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(texelSize.x,texelSize.y))/4.*0.125;
gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(-2.0*texelSize.x,2.0*texelSize.y))/4.*0.125;
gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(2.0*texelSize.x,-2.0*texelSize.y))/4.*0.125;
//0.125
gl_FragData[0] += texture2D(colortex5,quarterResTC)*0.125;
gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.);
if (quarterResTC.x > 1.0 - 3.5*texelSize.x || quarterResTC.y > 1.0 -3.5*texelSize.y || quarterResTC.x < 3.5*texelSize.x || quarterResTC.y < 3.5*texelSize.y) gl_FragData[0].rgb = vec3(0.0);
}

View File

@ -1,5 +1,3 @@
#version 120
uniform float viewWidth; uniform float viewWidth;
uniform float viewHeight; uniform float viewHeight;
//////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN//////////////////////////////

View File

@ -1,6 +1,3 @@
#version 120
//downsample 1st pass (half res) for bloom
uniform sampler2D colortex3; uniform sampler2D colortex3;
uniform vec2 texelSize; uniform vec2 texelSize;
uniform float viewWidth; uniform float viewWidth;

View File

@ -1,5 +1,3 @@
#version 120
uniform float viewWidth; uniform float viewWidth;
uniform float viewHeight; uniform float viewHeight;
//////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN//////////////////////////////

View File

@ -1,7 +1,3 @@
#version 120
//6 Horizontal gaussian blurs and horizontal downsampling
uniform sampler2D colortex6; uniform sampler2D colortex6;
uniform vec2 texelSize; uniform vec2 texelSize;
varying vec2 texcoord; varying vec2 texcoord;

View File

@ -1,5 +1,3 @@
#version 120
uniform float viewWidth; uniform float viewWidth;
uniform float viewHeight; uniform float viewHeight;
varying vec2 texcoord; varying vec2 texcoord;
@ -17,5 +15,4 @@ void main() {
//0-0.5 //0-0.5
gl_Position.x = (gl_Position.x*0.5+0.5)*0.5/clampedRes.x*1920.0*2.0-1.0; gl_Position.x = (gl_Position.x*0.5+0.5)*0.5/clampedRes.x*1920.0*2.0-1.0;
texcoord = gl_MultiTexCoord0.xy/clampedRes*vec2(1920.,1080.); texcoord = gl_MultiTexCoord0.xy/clampedRes*vec2(1920.,1080.);
} }

View File

@ -1,8 +1,3 @@
#version 120
//6 Vertical gaussian blurs and vertical downsampling
uniform sampler2D colortex6; uniform sampler2D colortex6;
uniform vec2 texelSize; uniform vec2 texelSize;
varying vec2 texcoord; varying vec2 texcoord;

View File

@ -1,5 +1,3 @@
#version 120
uniform float viewWidth; uniform float viewWidth;
uniform float viewHeight; uniform float viewHeight;
varying vec2 texcoord; varying vec2 texcoord;
@ -17,4 +15,5 @@ void main() {
//0-0.5 //0-0.5
gl_Position.x = (gl_Position.x*0.5+0.5)*0.5/clampedRes.x*1920.0*2.0-1.0; gl_Position.x = (gl_Position.x*0.5+0.5)*0.5/clampedRes.x*1920.0*2.0-1.0;
texcoord = gl_MultiTexCoord0.xy/clampedRes*vec2(1920.,1080.); texcoord = gl_MultiTexCoord0.xy/clampedRes*vec2(1920.,1080.);
} }

View File

@ -1,6 +1,3 @@
#version 120
//Merge and upsample the blurs into a 1/4 res bloom buffer
uniform sampler2D colortex3; uniform sampler2D colortex3;
uniform sampler2D colortex6; uniform sampler2D colortex6;

View File

@ -0,0 +1,15 @@
uniform float viewWidth;
uniform float viewHeight;
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
//Improves performances and makes sure bloom radius stays the same at high resolution (>1080p)
vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.));
gl_Position = ftransform();
//*0.51 to avoid errors when sampling outside since clearing is disabled
gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.51/clampedRes*vec2(1920.0,1080.)*2.0-1.0;
}

View File

@ -1,7 +1,3 @@
#version 120
//Vignetting, applies bloom, applies exposure and tonemaps the final image
//#extension GL_EXT_gpu_shader4 : disable
#include "/lib/settings.glsl" #include "/lib/settings.glsl"
#ifdef DOF #ifdef DOF
@ -461,14 +457,8 @@ void main() {
VL_abs = clamp((1.0-VL_abs*1.05)*BLOOMY_FOG*0.5,0.0,1.0)*clamp(1.0-pow(cdist(texcoord.xy),15.0),0.0,1.0); VL_abs = clamp((1.0-VL_abs*1.05)*BLOOMY_FOG*0.5,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; col = ( mix(col, bloom, VL_abs) + bloom*lightScat) * exposure.rgb;
/*
//Purkinje Effect
float lum = dot(col,vec3(0.15,0.3,0.55));
float lum2 = dot(col,vec3(0.85,0.7,0.45))/2;
float rodLum = lum2*300.0;
float rodCurve = mix(1.0, rodLum/(2.5+rodLum), rodExposure/2.0*Purkinje_strength);
col = mix(lum*Purkinje_Multiplier*vec3(Purkinje_R, Purkinje_G, Purkinje_B)+0.001, col, rodCurve);
*/
#ifndef USE_ACES_COLORSPACE_APPROXIMATION #ifndef USE_ACES_COLORSPACE_APPROXIMATION
col = LinearTosRGB(TONEMAP(col)); col = LinearTosRGB(TONEMAP(col));
#else #else

View File

@ -1,6 +1,3 @@
#version 120
//#extension GL_EXT_gpu_shader4 : disable
#include "/lib/settings.glsl" #include "/lib/settings.glsl"
varying vec2 texcoord; varying vec2 texcoord;

View File

@ -0,0 +1,110 @@
#include "/lib/settings.glsl"
// flat varying vec3 ambientUp;
// flat varying vec3 ambientLeft;
// flat varying vec3 ambientRight;
// flat varying vec3 ambientB;
// flat varying vec3 ambientF;
// flat varying vec3 ambientDown;
flat varying vec3 lightSourceColor;
flat varying vec3 sunColor;
flat varying vec3 sunColorCloud;
flat varying vec3 moonColor;
flat varying vec3 moonColorCloud;
flat varying vec3 zenithColor;
flat varying vec3 avgSky;
flat varying vec2 tempOffsets;
flat varying float exposure;
flat varying float rodExposure;
flat varying float avgBrightness;
flat varying float exposureF;
flat varying float fogAmount;
flat varying float VFAmount;
uniform sampler2D colortex4;
uniform sampler2D noisetex;
uniform int frameCounter;
uniform float rainStrength;
uniform float eyeAltitude;
uniform vec3 sunVec;
uniform vec2 texelSize;
uniform float frameTimeCounter;
uniform mat4 gbufferProjection;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferPreviousProjection;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferModelView;
uniform mat4 shadowModelView;
uniform mat4 shadowProjection;
uniform float sunElevation;
uniform vec3 cameraPosition;
uniform float far;
uniform ivec2 eyeBrightnessSmooth;
#include "/lib/util.glsl"
#include "/lib/ROBOBO_sky.glsl"
vec3 toShadowSpaceProjected(vec3 p3){
p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz;
p3 = mat3(shadowModelView) * p3 + shadowModelView[3].xyz;
p3 = diagonal3(shadowProjection) * p3 + shadowProjection[3].xyz;
return p3;
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)+frameCounter/1.6180339887);
return noise;
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
#ifdef END_SHADER
#include "/lib/end_fog.glsl"
#endif
#ifdef NETHER_SHADER
#include "/lib/nether_fog.glsl"
#endif
void main() {
/* DRAWBUFFERS:4 */
gl_FragData[0] = vec4(0.0);
vec2 fogPos = vec2(256.0 - 256.0*0.12,1.0);
//Sky gradient with clouds
if (gl_FragCoord.x > (fogPos.x - fogPos.x*0.22) && gl_FragCoord.y > 0.4 && gl_FragCoord.x < 535){
// vec2 p = clamp(floor(gl_FragCoord.xy-vec2(18.+257,1.))/256.+tempOffsets/256.,0.0,1.0);
vec2 p = clamp(floor(gl_FragCoord.xy-fogPos)/256.+tempOffsets/256.,-0.2,1.2);
vec3 viewVector = cartToSphere(p);
vec3 BackgroundColor = vec3(0.0);
vec4 VL_Fog = GetVolumetricFog(mat3(gbufferModelView)*viewVector*256., fract(frameCounter/1.6180339887), fract(frameCounter/2.6180339887));
BackgroundColor += VL_Fog.rgb/5.0;
gl_FragData[0] = vec4(BackgroundColor, 1.0);
}
//Temporally accumulate sky and light values
vec3 temp = texelFetch2D(colortex4,ivec2(gl_FragCoord.xy),0).rgb;
vec3 curr = gl_FragData[0].rgb*150.;
gl_FragData[0].rgb = clamp(mix(temp,curr,0.07),0.0,65000.);
//Exposure values
if (gl_FragCoord.x > 10. && gl_FragCoord.x < 11. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 )
gl_FragData[0] = vec4(exposure,avgBrightness,exposureF,1.0);
if (gl_FragCoord.x > 14. && gl_FragCoord.x < 15. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 )
gl_FragData[0] = vec4(rodExposure,0.0,0.0,1.0);
}

View File

@ -0,0 +1,104 @@
#include "/lib/settings.glsl"
#include "/lib/res_params.glsl"
flat varying vec2 tempOffsets;
flat varying float exposure;
flat varying float avgBrightness;
flat varying float rodExposure;
flat varying float avgL2;
flat varying float centerDepth;
uniform sampler2D colortex4;
uniform sampler2D colortex6;
uniform sampler2D depthtex0;
uniform mat4 gbufferModelViewInverse;
uniform vec3 sunPosition;
uniform vec2 texelSize;
uniform float sunElevation;
uniform float eyeAltitude;
uniform float near;
uniform float far;
uniform float frameTime;
uniform int frameCounter;
uniform float rainStrength;
// uniform int worldTime;
vec3 sunVec = normalize(mat3(gbufferModelViewInverse) *sunPosition);
#include "/lib/sky_gradient.glsl"
#include "/lib/util.glsl"
#include "/lib/ROBOBO_sky.glsl"
float luma(vec3 color) {
return dot(color,vec3(0.21, 0.72, 0.07));
}
//Low discrepancy 2D sequence, integration error is as low as sobol but easier to compute : http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/
vec2 R2_samples(int n){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha * n);
}
float tanh(float x){
return (exp(x) - exp(-x))/(exp(x) + exp(-x));
}
float ld(float depth) {
return (2.0 * near) / (far + near - depth * (far - near)); // (-depth * (far - near)) = (2.0 * near)/ld - far - near
}
uniform float nightVision;
void main() {
gl_Position = ftransform()*0.5+0.5;
gl_Position.xy = gl_Position.xy*vec2(18.+258*2,258.)*texelSize;
gl_Position.xy = gl_Position.xy*2.-1.0;
//////////////////////////////
/// --- EXPOSURE STUFF --- ///
//////////////////////////////
float avgLuma = 0.0;
float m2 = 0.0;
int n=100;
vec2 clampedRes = max(1.0/texelSize,vec2(1920.0,1080.));
float avgExp = 0.0;
float avgB = 0.0;
vec2 resScale = vec2(1920.,1080.)/clampedRes;
const int maxITexp = 50;
float w = 0.0;
for (int i = 0; i < maxITexp; i++){
vec2 ij = R2_samples((frameCounter%2000)*maxITexp+i);
vec2 tc = 0.5 + (ij-0.5) * 0.7;
vec3 sp = texture2D(colortex6,tc/16. * resScale+vec2(0.375*resScale.x+4.5*texelSize.x,.0)).rgb;
avgExp += log(luma(sp));
avgB += log(min(dot(sp,vec3(0.07,0.22,0.71)),8e-2));
}
avgExp = exp(avgExp/maxITexp);
avgB = exp(avgB/maxITexp);
avgBrightness = clamp(mix(avgExp,texelFetch2D(colortex4,ivec2(10,37),0).g,0.95),0.00003051757,65000.0);
float L = max(avgBrightness,1e-8);
float keyVal = 1.03-2.0/(log(L*4000/150.*8./3.0+1.0)/log(10.0)+2.0);
float expFunc = 0.5+0.5*tanh(log(L));
float targetExposure = 0.18/log2(L*2.5+1.045)*0.62;
avgL2 = clamp(mix(avgB,texelFetch2D(colortex4,ivec2(10,37),0).b,0.985),0.00003051757,65000.0);
float targetrodExposure = max(0.012/log2(avgL2+1.002)-0.1,0.0)*1.2;
exposure = max(targetExposure*EXPOSURE_MULTIPLIER, 0);
float currCenterDepth = ld(texture2D(depthtex0, vec2(0.5)).r);
centerDepth = mix(sqrt(texelFetch2D(colortex4,ivec2(14,37),0).g/65000.0), currCenterDepth, clamp(DoF_Adaptation_Speed*exp(-0.016/frameTime+1.0)/(6.0+currCenterDepth*far),0.0,1.0));
centerDepth = centerDepth * centerDepth * 65000.0;
rodExposure = targetrodExposure;
#ifndef AUTO_EXPOSURE
exposure = Manual_exposure_value;
rodExposure = clamp(log(Manual_exposure_value*2.0+1.0)-0.1,0.0,2.0);
#endif
}

View File

@ -1,5 +1,3 @@
#version 120
//#extension GL_EXT_gpu_shader4 : disable
#include "/lib/settings.glsl" #include "/lib/settings.glsl"
uniform sampler2D colortex4; uniform sampler2D colortex4;

View File

@ -1,5 +1,3 @@
#version 120
//#extension GL_EXT_gpu_shader4 : disable
#include "/lib/settings.glsl" #include "/lib/settings.glsl"
uniform vec2 texelSize; uniform vec2 texelSize;

View File

@ -0,0 +1,139 @@
#include "/lib/settings.glsl"
varying vec2 texcoord;
uniform sampler2D colortex7;
// uniform sampler2D noisetex;
uniform vec2 texelSize;
uniform float viewWidth;
uniform float viewHeight;
uniform float aspectRatio;
uniform float frameTimeCounter;
uniform int frameCounter;
uniform int isEyeInWater;
#include "/lib/color_transforms.glsl"
#include "/lib/color_dither.glsl"
#include "/lib/res_params.glsl"
vec4 SampleTextureCatmullRom(sampler2D tex, vec2 uv, vec2 texSize )
{
// We're going to sample a a 4x4 grid of texels surrounding the target UV coordinate. We'll do this by rounding
// down the sample location to get the exact center of our "starting" texel. The starting texel will be at
// location [1, 1] in the grid, where [0, 0] is the top left corner.
vec2 samplePos = uv * texSize;
vec2 texPos1 = floor(samplePos - 0.5) + 0.5;
// Compute the fractional offset from our starting texel to our original sample location, which we'll
// feed into the Catmull-Rom spline function to get our filter weights.
vec2 f = samplePos - texPos1;
// Compute the Catmull-Rom weights using the fractional offset that we calculated earlier.
// These equations are pre-expanded based on our knowledge of where the texels will be located,
// which lets us avoid having to evaluate a piece-wise function.
vec2 w0 = f * ( -0.5 + f * (1.0 - 0.5*f));
vec2 w1 = 1.0 + f * f * (-2.5 + 1.5*f);
vec2 w2 = f * ( 0.5 + f * (2.0 - 1.5*f) );
vec2 w3 = f * f * (-0.5 + 0.5 * f);
// Work out weighting factors and sampling offsets that will let us use bilinear filtering to
// simultaneously evaluate the middle 2 samples from the 4x4 grid.
vec2 w12 = w1 + w2;
vec2 offset12 = w2 / (w1 + w2);
// Compute the final UV coordinates we'll use for sampling the texture
vec2 texPos0 = texPos1 - vec2(1.0);
vec2 texPos3 = texPos1 + vec2(2.0);
vec2 texPos12 = texPos1 + offset12;
texPos0 *= texelSize;
texPos3 *= texelSize;
texPos12 *= texelSize;
vec4 result = vec4(0.0);
result += texture2D(tex, vec2(texPos0.x, texPos0.y)) * w0.x * w0.y;
result += texture2D(tex, vec2(texPos12.x, texPos0.y)) * w12.x * w0.y;
result += texture2D(tex, vec2(texPos3.x, texPos0.y)) * w3.x * w0.y;
result += texture2D(tex, vec2(texPos0.x, texPos12.y)) * w0.x * w12.y;
result += texture2D(tex, vec2(texPos12.x, texPos12.y)) * w12.x * w12.y;
result += texture2D(tex, vec2(texPos3.x, texPos12.y)) * w3.x * w12.y;
result += texture2D(tex, vec2(texPos0.x, texPos3.y)) * w0.x * w3.y;
result += texture2D(tex, vec2(texPos12.x, texPos3.y)) * w12.x * w3.y;
result += texture2D(tex, vec2(texPos3.x, texPos3.y)) * w3.x * w3.y;
return result;
}
/// thanks stackoverflow https://stackoverflow.com/questions/944713/help-with-pixel-shader-effect-for-brightness-and-contrast#3027595
void applyContrast(inout vec3 color, float contrast){
color = (color - 0.5) * contrast + 0.5;
}
float lowerCurve(float x) {
float y = 16 * x * (0.5 - x) * 0.1;
return clamp(y, 0.0, 1.0);
}
float upperCurve(float x) {
float y = 16 * (0.5 - x) * (x - 1.0) * 0.1;
return clamp(y, 0.0, 1.0);
}
void applyLuminanceCurve(inout vec3 color, float darks, float brights){
// color.r = color.r < 0.5 ? pow(2.0 * color.r, darks) / 2.0 : 1.0 - (pow(2.0 - 2.0 * color.r, brights) / 2.0);
// color.g = color.g < 0.5 ? pow(2.0 * color.g, darks) / 2.0 : 1.0 - (pow(2.0 - 2.0 * color.g, brights) / 2.0);
// color.b = color.b < 0.5 ? pow(2.0 * color.b, darks) / 2.0 : 1.0 - (pow(2.0 - 2.0 * color.b, brights) / 2.0);
color.r += darks * lowerCurve(color.r) + brights * upperCurve(color.r);
color.g += darks * lowerCurve(color.g) + brights * upperCurve(color.g);
color.b += darks * lowerCurve(color.b) + brights * upperCurve(color.b);
}
void applyColorCurve(inout vec3 color, vec4 darks, vec4 brights){
color.r += (darks.r + darks.a) * lowerCurve(color.r) + (brights.r + brights.a) * upperCurve(color.r);
color.g += (darks.g + darks.a) * lowerCurve(color.g) + (brights.g + brights.a) * upperCurve(color.g);
color.b += (darks.b + darks.a) * lowerCurve(color.b) + (brights.b + brights.a) * upperCurve(color.b);
}
void main() {
#ifdef BICUBIC_UPSCALING
vec3 col = SampleTextureCatmullRom(colortex7,texcoord,1.0/texelSize).rgb;
#else
vec3 col = texture2D(colortex7,texcoord).rgb;
#endif
#ifdef CONTRAST_ADAPTATIVE_SHARPENING
//Weights : 1 in the center, 0.5 middle, 0.25 corners
vec3 albedoCurrent1 = texture2D(colortex7, texcoord + vec2(texelSize.x,texelSize.y)/MC_RENDER_QUALITY*0.5).rgb;
vec3 albedoCurrent2 = texture2D(colortex7, texcoord + vec2(texelSize.x,-texelSize.y)/MC_RENDER_QUALITY*0.5).rgb;
vec3 albedoCurrent3 = texture2D(colortex7, texcoord + vec2(-texelSize.x,-texelSize.y)/MC_RENDER_QUALITY*0.5).rgb;
vec3 albedoCurrent4 = texture2D(colortex7, texcoord + vec2(-texelSize.x,texelSize.y)/MC_RENDER_QUALITY*0.5).rgb;
vec3 m1 = -0.5/3.5*col + albedoCurrent1/3.5 + albedoCurrent2/3.5 + albedoCurrent3/3.5 + albedoCurrent4/3.5;
vec3 std = abs(col - m1) + abs(albedoCurrent1 - m1) + abs(albedoCurrent2 - m1) +
abs(albedoCurrent3 - m1) + abs(albedoCurrent3 - m1) + abs(albedoCurrent4 - m1);
float contrast = 1.0 - luma(std)/5.0;
col = col*(1.0+(SHARPENING+UPSCALING_SHARPNENING)*contrast)
- (SHARPENING+UPSCALING_SHARPNENING)/(1.0-0.5/3.5)*contrast*(m1 - 0.5/3.5*col);
#endif
float lum = luma(col);
vec3 diff = col-lum;
col = col + diff*(-lum*CROSSTALK + SATURATION);
vec3 FINAL_COLOR = clamp(int8Dither(col,texcoord),0.0,1.0);
#ifdef COLOR_CURVE
applyColorCurve(FINAL_COLOR, vec4(R_LOWER_CURVE, G_LOWER_CURVE, B_LOWER_CURVE, LOWER_CURVE), vec4(R_UPPER_CURVE, G_UPPER_CURVE, B_UPPER_CURVE, UPPER_CURVE));
#endif
applyContrast(FINAL_COLOR, CONTRAST); // for fun
gl_FragColor.rgb = FINAL_COLOR ;
}

View File

@ -1,24 +1,9 @@
#version 120
//#extension GL_EXT_gpu_shader4 : disable
#include "/lib/settings.glsl" #include "/lib/settings.glsl"
varying vec2 texcoord; varying vec2 texcoord;
flat varying vec4 exposure; flat varying vec4 exposure;
flat varying vec2 rodExposureDepth;
uniform sampler2D colortex4; uniform sampler2D colortex4;
uniform vec2 texelSize;
uniform int framemod8;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
vec2(-3,-5.)/8.,
vec2(-5.,5.)/8.,
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
//////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN//////////////////////////////
@ -27,12 +12,7 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
void main() { void main() {
gl_Position = ftransform(); gl_Position = ftransform();
texcoord = gl_MultiTexCoord0.xy; texcoord = gl_MultiTexCoord0.xy;
exposure=vec4(texelFetch2D(colortex4,ivec2(10,37),0).r*vec3(FinalR,FinalG,FinalB),texelFetch2D(colortex4,ivec2(10,37),0).r); exposure=vec4(texelFetch2D(colortex4,ivec2(10,37),0).r*vec3(FinalR,FinalG,FinalB),texelFetch2D(colortex4,ivec2(10,37),0).r);
rodExposureDepth = texelFetch2D(colortex4,ivec2(14,37),0).rg;
rodExposureDepth.y = sqrt(rodExposureDepth.y/65000.0);
} }

View File

@ -37,7 +37,7 @@ uniform vec3 cameraPosition;
#include "/lib/sky_gradient.glsl" #include "/lib/sky_gradient.glsl"
#include "/lib/volumetricClouds.glsl" #include "/lib/volumetricClouds.glsl"
#define OVERWORLD #define OVERWORLD_SHADER
#include "/lib/diffuse_lighting.glsl" #include "/lib/diffuse_lighting.glsl"
//faster and actually more precise than pow 2.2 //faster and actually more precise than pow 2.2

View File

@ -71,7 +71,7 @@ flat varying vec3 averageSkyCol_Clouds;
#include "/lib/clouds.glsl" #include "/lib/clouds.glsl"
#include "/lib/stars.glsl" #include "/lib/stars.glsl"
#include "/lib/volumetricClouds.glsl" #include "/lib/volumetricClouds.glsl"
#define OVERWORLD #define OVERWORLD_SHADER
#include "/lib/diffuse_lighting.glsl" #include "/lib/diffuse_lighting.glsl"

View File

@ -15,72 +15,64 @@ void DoRTAmbientLighting (vec3 TorchColor, vec2 Lightmap, inout float SkyLM, ino
SkyLight = max(SkyLight * SkyLM, vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.025 + nightVision)); SkyLight = max(SkyLight * SkyLM, vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.025 + nightVision));
} }
//// OVERWORLD //// #ifdef OVERWORLD_SHADER
#ifdef OVERWORLD
vec3 DoAmbientLighting (vec3 SkyColor, vec3 TorchColor, vec2 Lightmap, float skyLightDir){
// Lightmap.x = 0.0;
// Lightmap.y = 1.0;
float TorchLM = 10.0 - ( 1.0 / (pow(exp(-0.5*inversesqrt(Lightmap.x)),5.0)+0.1)); vec3 DoAmbientLighting (vec3 SkyColor, vec3 TorchColor, vec2 Lightmap, float skyLightDir){
TorchLM = pow(TorchLM/4,10) + pow(Lightmap.x,1.5)*0.5; //pow(TorchLM/4.5,10)*2.5 + pow(Lightmap.x,1.5)*0.5; // Lightmap.x = 0.0;
vec3 TorchLight = TorchColor * TorchLM * 0.75; // Lightmap.y = 1.0;
TorchLight *= TORCH_AMOUNT;
SkyColor = (SkyColor * ambient_brightness) / 30.0;
float skyLM = (pow(Lightmap.y,15.0)*2.0 + pow(Lightmap.y,2.5))*0.5;
vec3 SkyLight = max(SkyColor * skyLM, vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.01 + nightVision) );
return SkyLight * skyLightDir + TorchLight;
}
vec3 DoDirectLighting(vec3 SunColor, float Shadow, float NdotL, float SubsurfaceScattering){
// vec3 SunLight = max(NdotL * Shadow, SubsurfaceScattering) * SunColor;
vec3 SunLight = NdotL * Shadow * SunColor;
return SunLight; float TorchLM = 10.0 - ( 1.0 / (pow(exp(-0.5*inversesqrt(Lightmap.x)),5.0)+0.1));
} TorchLM = pow(TorchLM/4,10) + pow(Lightmap.x,1.5)*0.5; //pow(TorchLM/4.5,10)*2.5 + pow(Lightmap.x,1.5)*0.5;
vec3 TorchLight = TorchColor * TorchLM * 0.75;
TorchLight *= TORCH_AMOUNT;
SkyColor = (SkyColor * ambient_brightness) / 30.0;
float skyLM = (pow(Lightmap.y,15.0)*2.0 + pow(Lightmap.y,2.5))*0.5;
vec3 SkyLight = max(SkyColor * skyLM, vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.01 + nightVision) );
return SkyLight * skyLightDir + TorchLight;
}
vec3 DoDirectLighting(vec3 SunColor, float Shadow, float NdotL, float SubsurfaceScattering){
vec3 SunLight = NdotL * Shadow * SunColor;
return SunLight;
}
#endif #endif
#ifdef NETHER #ifdef NETHER_SHADER
//// NETHER //// vec3 DoAmbientLighting_Nether(vec3 FogColor, vec3 TorchColor, float Lightmap, vec3 Normal, vec3 np3, vec3 WorldPos){
vec3 DoAmbientLighting_Nether(vec3 FogColor, vec3 TorchColor, float Lightmap, vec3 Normal, vec3 np3, vec3 WorldPos){
float TorchLM = 10.0 - ( 1.0 / (pow(exp(-0.5*inversesqrt(Lightmap)),5.0)+0.1));
TorchLM = pow(TorchLM/4,10) + pow(Lightmap,1.5)*0.5; //pow(TorchLM/4.5,10)*2.5 + pow(Lightmap.x,1.5)*0.5;
vec3 TorchLight = TorchColor * TorchLM * 0.75;
TorchLight *= TORCH_AMOUNT;
FogColor = max(FogColor, vec3(0.05) * MIN_LIGHT_AMOUNT*0.01 + nightVision); float TorchLM = 10.0 - ( 1.0 / (pow(exp(-0.5*inversesqrt(Lightmap)),5.0)+0.1));
TorchLM = pow(TorchLM/4,10) + pow(Lightmap,1.5)*0.5; //pow(TorchLM/4.5,10)*2.5 + pow(Lightmap.x,1.5)*0.5;
vec3 TorchLight = TorchColor * TorchLM * 0.75;
TorchLight *= TORCH_AMOUNT;
return FogColor + TorchLight ; FogColor = max(FogColor, vec3(0.05) * MIN_LIGHT_AMOUNT*0.01 + nightVision);
}
return FogColor + TorchLight ;
}
#endif #endif
#ifdef END #ifdef END_SHADER
//// END //// vec3 DoAmbientLighting_End(vec3 FogColor, vec3 TorchColor, float Lightmap, vec3 Normal, vec3 np3){
vec3 DoAmbientLighting_End(vec3 FogColor, vec3 TorchColor, float Lightmap, vec3 Normal, vec3 np3){
// vec3 TorchLight = TorchColor * clamp(pow(Lightmap,3.0),0.0,1.0); float TorchLM = 10.0 - ( 1.0 / (pow(exp(-0.5*inversesqrt(Lightmap)),5.0)+0.1));
// vec3 TorchLight = TorchColor * pow(1.0-pow(1.0-clamp(Lightmap,0.0,1.0) ,0.1),2); TorchLM = pow(TorchLM/4,10) + pow(Lightmap,1.5)*0.5;
// TorchLight = exp(TorchLight * 30) - 1.0; vec3 TorchLight = TorchColor * TorchLM * 0.75;
TorchLight *= TORCH_AMOUNT;
float TorchLM = 10.0 - ( 1.0 / (pow(exp(-0.5*inversesqrt(Lightmap)),5.0)+0.1));
TorchLM = pow(TorchLM/4,10) + pow(Lightmap,1.5)*0.5; //pow(TorchLM/4.5,10)*2.5 + pow(Lightmap.x,1.5)*0.5;
vec3 TorchLight = TorchColor * TorchLM * 0.75;
TorchLight *= TORCH_AMOUNT;
FogColor = (FogColor / pow(0.00001 + dot(FogColor,vec3(0.3333)),1.0) ) * 0.1; FogColor = (FogColor / pow(0.00001 + dot(FogColor,vec3(0.3333)),1.0) ) * 0.1;
// vec3 AmbientLight = sqrt( clamp(1.25 + dot(Normal,np3),0.0,1.0)) * (vec3(0.5,0.75,1.0) * 0.05);
// vec3 AmbientLight = sqrt( clamp(1.25 + dot(Normal,np3),0.0,1.0)*0.5) * FogColor;
// vec3 AmbientLight = vec3(0.5,0.75,1.0) * 0.05 + FogColor*clamp(1.1 + dot(Normal,np3),0.0,1.0)*0.5;
vec3 FogTint = FogColor*clamp(1.1 + dot(Normal,np3),0.0,1.0) * 0.05; vec3 FogTint = FogColor*clamp(1.1 + dot(Normal,np3),0.0,1.0) * 0.05;
vec3 AmbientLight = max(vec3(0.5,0.75,1.0) * 0.05, (MIN_LIGHT_AMOUNT*0.01 + nightVision*0.5) ); vec3 AmbientLight = max(vec3(0.5,0.75,1.0) * 0.05, (MIN_LIGHT_AMOUNT*0.01 + nightVision*0.5) );
return TorchLight + AmbientLight + FogTint; return TorchLight + AmbientLight + FogTint;
} }
#endif #endif

View File

@ -223,7 +223,11 @@ float cloudVol(in vec3 pos, int LOD){
} }
mat2x3 getVolumetricRays(float dither,vec3 fragpos,float dither2) { vec4 GetVolumetricFog(
vec3 fragpos,
float dither,
float dither2
) {
int SAMPLES = 16; int SAMPLES = 16;
//project pixel position into projected shadowmap space //project pixel position into projected shadowmap space
vec3 wpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz; vec3 wpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz;
@ -250,12 +254,11 @@ mat2x3 getVolumetricRays(float dither,vec3 fragpos,float dither2) {
vec3 vL = vec3(0.); vec3 vL = vec3(0.);
float dL = length(dVWorld); float dL = length(dVWorld);
vec3 absorbance = vec3(1.0); float absorbance = 1.0;
float expFactor = 11.0; float expFactor = 11.0;
vec3 fogColor = (gl_Fog.color.rgb / max(pow(dot(gl_Fog.color.rgb,vec3(0.3333)),1.1),0.01) ) ; vec3 fogColor = (gl_Fog.color.rgb / max(pow(dot(gl_Fog.color.rgb,vec3(0.3333)),1.1),0.01) ) ;
for (int i=0;i<SAMPLES;i++) { for (int i=0;i<SAMPLES;i++) {
float d = (pow(expFactor, float(i+dither)/float(SAMPLES))/expFactor - 1.0/expFactor)/(1-1.0/expFactor); float d = (pow(expFactor, float(i+dither)/float(SAMPLES))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(SAMPLES)) * log(expFactor) / float(SAMPLES)/(expFactor-1.0); float dd = pow(expFactor, float(i+dither)/float(SAMPLES)) * log(expFactor) / float(SAMPLES)/(expFactor-1.0);
@ -308,7 +311,7 @@ mat2x3 getVolumetricRays(float dither,vec3 fragpos,float dither2) {
absorbance *= exp(-(density+air)*dd*dL); absorbance *= exp(-(density+air)*dd*dL);
} }
return mat2x3(vL,absorbance); return vec4(vL, absorbance);
} }
float GetCloudShadow(vec3 WorldPos, vec3 LightPos, float noise){ float GetCloudShadow(vec3 WorldPos, vec3 LightPos, float noise){

View File

@ -38,7 +38,8 @@ float cloudVol(in vec3 pos){
vec4 GetVolumetricFog( vec4 GetVolumetricFog(
vec3 fragpos, vec3 fragpos,
float dither float dither,
float dither2
){ ){
int SAMPLES = 16; int SAMPLES = 16;
vec3 vL = vec3(0.0); vec3 vL = vec3(0.0);
@ -93,5 +94,5 @@ vec4 GetVolumetricFog(
if (absorbance < 1e-5) break; if (absorbance < 1e-5) break;
} }
return vec4(vL,absorbance); return vec4(vL, absorbance);
} }

View File

@ -231,7 +231,7 @@ void DoSpecularReflections(
// apply background reflections to the final color. make sure it does not exist based on the lightmap // apply background reflections to the final color. make sure it does not exist based on the lightmap
#ifdef Sky_reflection #ifdef Sky_reflection
#ifndef OVERWORLD #ifndef OVERWORLD_SHADER
if(hasReflections) Background_Reflection = (skyCloudsFromTexLOD2(L, colortex4, sqrt(Roughness) * 6.0).rgb / 30.0) * Metals; if(hasReflections) Background_Reflection = (skyCloudsFromTexLOD2(L, colortex4, sqrt(Roughness) * 6.0).rgb / 30.0) * Metals;
#else #else
if(hasReflections) Background_Reflection = (skyCloudsFromTexLOD(L, colortex4, sqrt(Roughness) * 9.0).rgb / 30.0) * Metals; if(hasReflections) Background_Reflection = (skyCloudsFromTexLOD(L, colortex4, sqrt(Roughness) * 9.0).rgb / 30.0) * Metals;

View File

@ -0,0 +1,5 @@
#version 120
#define NETHER_SHADER
#include "/dimensions/composite.fsh"

View File

@ -0,0 +1,5 @@
#version 120
#define NETHER_SHADER
#include "/dimensions/composite.vsh"

View File

@ -0,0 +1,5 @@
#version 120
#define NETHER_SHADER
#include "/dimensions/composite1.fsh"

View File

@ -0,0 +1,5 @@
#version 120
#define NETHER_SHADER
#include "/dimensions/composite1.vsh"

View File

@ -1,107 +0,0 @@
#version 120
//Vignetting, applies bloom, applies exposure and tonemaps the final image
//#extension GL_EXT_gpu_shader4 : disable
#include "/lib/settings.glsl"
#include "/lib/res_params.glsl"
flat varying vec4 exposure;
flat varying vec2 rodExposureDepth;
varying vec2 texcoord;
const bool colortex5MipmapEnabled = true;
// uniform sampler2D colortex4;
uniform sampler2D colortex5;
uniform sampler2D colortex3;
// uniform sampler2D colortex6;
uniform sampler2D colortex7;
// uniform sampler2D colortex8; // specular
// uniform sampler2D colortex9; // specular
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
uniform sampler2D noisetex;
uniform vec2 texelSize;
uniform ivec2 eyeBrightnessSmooth;
uniform float viewWidth;
uniform float viewHeight;
uniform float frameTimeCounter;
uniform int frameCounter;
uniform int isEyeInWater;
uniform float near;
uniform float aspectRatio;
uniform float far;
uniform float rainStrength;
uniform float screenBrightness;
uniform vec4 Moon_Weather_properties; // R = cloud coverage G = fog density
uniform int framemod8;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
vec2(-3,-5.)/8.,
vec2(-5.,5.)/8.,
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferProjectionInverse;
vec4 Weather_properties = Moon_Weather_properties;
#include "/lib/color_transforms.glsl"
#include "/lib/color_dither.glsl"
// #include "/lib/biome_specifics.glsl"
#include "/lib/bokeh.glsl"
float cdist(vec2 coord) {
return max(abs(coord.s-0.5),abs(coord.t-0.5))*2.0;
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
float ld(float depth) {
return (2.0 * near) / (far + near - depth * (far - near)); // (-depth * (far - near)) = (2.0 * near)/ld - far - near
}
void main() {
/* DRAWBUFFERS:7 */
float vignette = (1.5-dot(texcoord-0.5,texcoord-0.5)*2.);
vec3 col = texture2D(colortex5,texcoord).rgb;
vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.));
vec3 bloom = texture2D(colortex3,texcoord/clampedRes*vec2(1920.,1080.)*0.5).rgb/2./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).r;
float purkinje = rodExposureDepth.x/(1.0+rodExposureDepth.x)*Purkinje_strength;
VL_abs = clamp( (1.0-VL_abs)*BLOOMY_FOG*0.75*(1.0-purkinje),0.0,1.0)*clamp(1.0-pow(cdist(texcoord.xy),15.0),0.0,1.0);
float lightleakfix = clamp(eyeBrightnessSmooth.y/240.0,0.0,1.0);
col = (mix(col,bloom,VL_abs)+bloom * lightScat) * exposure.rgb;
//Purkinje Effect
float lum = dot(col,vec3(0.15,0.3,0.55));
float lum2 = dot(col,vec3(0.85,0.7,0.45))/2;
float rodLum = lum2*400.;
float rodCurve = mix(1.0, rodLum/(2.5+rodLum), purkinje);
col = mix(clamp(lum,0.0,0.05)*Purkinje_Multiplier*vec3(Purkinje_R, Purkinje_G, Purkinje_B)+1.5e-3, col, rodCurve);
#ifndef USE_ACES_COLORSPACE_APPROXIMATION
col = LinearTosRGB(TONEMAP(col));
#else
col = col * ACESInputMat;
col = TONEMAP(col);
col = LinearTosRGB(clamp(col * ACESOutputMat, 0.0, 1.0));
#endif
gl_FragData[0].rgb = clamp(int8Dither(col,texcoord),0.0,1.0);
}

View File

@ -1,651 +1,5 @@
#version 120 #version 120
//#extension GL_EXT_gpu_shader4 : disable
#include "/lib/settings.glsl" #define NETHER_SHADER
#define NETHER #include "/dimensions/composite2.fsh"
#include "/lib/diffuse_lighting.glsl"
varying vec2 texcoord;
flat varying vec2 TAA_Offset;
flat varying float tempOffsets;
const bool colortex5MipmapEnabled = true;
const bool colortex4MipmapEnabled = true;
uniform sampler2D colortex0;//clouds
uniform sampler2D colortex1;//albedo(rgb),material(alpha) RGBA16
uniform sampler2D colortex4;//Skybox
uniform sampler2D colortex3;
uniform sampler2D colortex7;
uniform sampler2D colortex5;
uniform sampler2D colortex2;
uniform sampler2D colortex8;
uniform sampler2D colortex15;
uniform sampler2D colortex6;//Skybox
uniform sampler2D depthtex1;//depth
uniform sampler2D depthtex0;//depth
uniform sampler2D noisetex;//depth
uniform int heldBlockLightValue;
uniform int frameCounter;
uniform int isEyeInWater;
uniform mat4 shadowModelViewInverse;
uniform mat4 shadowProjectionInverse;
uniform float far;
uniform float near;
uniform float frameTimeCounter;
uniform float rainStrength;
uniform mat4 gbufferProjection;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferModelViewInverse;
uniform mat4 shadowModelView;
uniform mat4 shadowProjection;
uniform mat4 gbufferModelView;
uniform mat4 gbufferPreviousModelView;
uniform mat4 gbufferPreviousProjection;
uniform vec3 previousCameraPosition;
uniform vec2 texelSize;
uniform float viewWidth;
uniform float viewHeight;
uniform float aspectRatio;
uniform vec3 cameraPosition;
uniform vec3 sunVec;
uniform ivec2 eyeBrightnessSmooth;
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
vec3 toScreenSpace(vec3 p) {
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
vec3 p3 = p * 2. - 1.;
vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
return fragposition.xyz / fragposition.w;
}
#include "/lib/color_transforms.glsl"
#include "/lib/waterBump.glsl"
#include "/lib/sky_gradient.glsl"
float ld(float dist) {
return (2.0 * near) / (far + near - dist * (far - near));
}
vec2 RENDER_SCALE = vec2(1.0);
#undef LIGHTSOURCE_REFLECTION
#include "/lib/specular.glsl"
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;
dither = center*inversesqrt(abs(center));
return clamp(dither-fsign(center),0.0,1.0);
}
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 ;
}
vec2 R2_dither(){
vec2 alpha = vec2(0.75487765, 0.56984026);
return vec2(fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter), fract((1.0-alpha.x) * gl_FragCoord.x + (1.0-alpha.y) * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter));
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * (frameCounter*0.5+0.5) );
}
vec4 blueNoise(vec2 coord){
return texelFetch2D(colortex6, ivec2(coord)%512 , 0) ;
}
vec3 fp10Dither(vec3 color,float dither){
const vec3 mantissaBits = vec3(6.,6.,5.);
vec3 exponent = floor(log2(color));
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 );
}
vec3 decode (vec2 encn){
vec3 n = vec3(0.0);
encn = encn * 2.0 - 1.0;
n.xy = abs(encn);
n.z = 1.0 - n.x - n.y;
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 ;
}
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);
}
vec3 toShadowSpaceProjected(vec3 p3){
p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz;
p3 = mat3(shadowModelView) * p3 + shadowModelView[3].xyz;
p3 = diagonal3(shadowProjection) * p3 + shadowProjection[3].xyz;
return p3;
}
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;
}
float ssao(vec3 fragpos, float dither,vec3 normal)
{
float mulfov = 1.0;
ivec2 pos = ivec2(gl_FragCoord.xy);
const float tan70 = tan(70.*3.14/180.);
float mulfov2 = gbufferProjection[1][1]/tan70;
const float PI = 3.14159265;
const float samplingRadius = 0.712;
float angle_thresh = 0.05;
float rd = mulfov2*0.05;
//pre-rotate direction
float n = 0.;
float occlusion = 0.0;
vec2 acc = -vec2(TAA_Offset)*texelSize*0.5;
float mult = (dot(normal,normalize(fragpos))+1.0)*0.5+0.5;
vec2 v = fract(vec2(dither,interleaved_gradientNoise()) + (frameCounter%10000) * vec2(0.75487765, 0.56984026));
for (int j = 0; j < 7+2 ;j++) {
vec2 sp = tapLocation(j,v.x,7+2,2.,v.y);
vec2 sampleOffset = sp*rd;
ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight));
if (offset.x >= 0 && offset.y >= 0 && offset.x < viewWidth && offset.y < viewHeight ) {
vec3 t0 = toScreenSpace(vec3(offset*texelSize+acc+0.5*texelSize,texelFetch2D(depthtex1,offset,0).x));
vec3 vec = t0.xyz - fragpos;
float dsquared = dot(vec,vec);
if (dsquared > 1e-5){
if (dsquared < fragpos.z*fragpos.z*0.05*0.05*mulfov2*2.*1.412){
float NdotV = clamp(dot(vec*inversesqrt(dsquared), normalize(normal)),0.,1.);
occlusion += NdotV;
}
n += 1.0;
}
}
}
return clamp(1.0-occlusion/n*2.0,0.,1.0);
}
vec3 viewToWorld(vec3 viewPosition) {
vec4 pos;
pos.xyz = viewPosition;
pos.w = 0.0;
pos = gbufferModelViewInverse * pos;
return pos.xyz;
}
vec3 worldToView(vec3 worldPos) {
vec4 pos = vec4(worldPos, 0.0);
pos = gbufferModelView * pos;
return pos.xyz;
}
void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient){
inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value
int spCount = rayMarchSampleCount;
vec3 start = toShadowSpaceProjected(rayStart);
vec3 end = toShadowSpaceProjected(rayEnd);
vec3 dV = (end-start);
//limit ray length at 32 blocks for performance and reducing integration error
//you can't see above this anyway
float maxZ = min(rayLength,12.0)/(1e-8+rayLength);
dV *= maxZ;
rayLength *= maxZ;
float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength;
estEndDepth *= maxZ;
estSunDepth *= maxZ;
vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz;
vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
float expFactor = 11.0;
for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
vec3 spPos = start.xyz + dV*d;
vec3 progressW = start.xyz+cameraPosition+dVWorld;
vec3 ambientMul = exp(-max(estEndDepth * d,0.0) * waterCoefs );
vec3 Indirectlight = ambientMul*ambient;
vec3 light = Indirectlight * scatterCoef;
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
absorbance *= exp(-dd * rayLength * waterCoefs);
}
inColor += vL;
}
void Emission(
inout vec3 Lighting,
vec3 Albedo,
float Emission
){
// if( Emission < 255.0/255.0 ) Lighting = mix(Lighting, Albedo * Emissive_Brightness, pow(Emission, Emissive_Curve)); // old method.... idk why
if( Emission < 255.0/255.0 ) Lighting += (Albedo * Emissive_Brightness * 0.25) * pow(Emission, Emissive_Curve);
}
vec3 SubsurfaceScattering_sky(vec3 albedo, float Scattering, float Density){
vec3 absorbed = max(luma(albedo) - albedo,0.0);
// vec3 scatter = exp(-sqrt(max(Scattering+0.05,0.0) * absorbed * 25)) * exp(Scattering * -5);
vec3 scatter = exp(-sqrt(Scattering * absorbed * 5)) * pow((-Scattering+1.0)*1.25,2.0);
scatter *= pow(Density,LabSSS_Curve);
// temporary
scatter *= ambientsss_brightness;
return scatter;
}
void ScreenSpace_SSS(inout float sss, vec3 fragpos, vec2 noise, vec3 normal){
ivec2 pos = ivec2(gl_FragCoord.xy);
const float tan70 = tan(70.*3.14/180.);
float dist = 1.0 + (clamp(fragpos.z*fragpos.z/50.0,0,2)); // shrink sample size as distance increases
float mulfov2 = gbufferProjection[1][1]/(tan70 * dist);
float dist3 = clamp(1-exp( fragpos.z*fragpos.z / -50),0,1);
float maxR2_2 = mix(10, fragpos.z*fragpos.z*mulfov2*2./50.0, dist3);
float rd = mulfov2 * 0.1;
vec2 acc = -(TAA_Offset*(texelSize/2)) ;
// int seed = (frameCounter%40000)*2 + (1+frameCounter);
// float randomDir = fract(R2_samples(seed).y + noise.x ) * 1.61803398874 ;
float n = 0.0;
vec2 v = fract(vec2(noise.x,interleaved_gradientNoise()) + (frameCounter%10000) * vec2(0.75487765, 0.56984026));
for (int j = 0; j < 7+2 ;j++) {
vec2 sp = tapLocation(j,v.x,7+2,2.,v.y);
// vec2 sp = tapLocation_alternate(j, 0.0, 7, 20, randomDir);
vec2 sampleOffset = sp*rd;
ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight*aspectRatio));
if (offset.x >= 0 && offset.y >= 0 && offset.x < viewWidth && offset.y < viewHeight ) {
vec3 t0 = toScreenSpace(vec3(offset*texelSize+acc+0.5*texelSize,texelFetch2D(depthtex1,offset,0).x) );
vec3 vec = t0.xyz - fragpos;
float dsquared = dot(vec,vec);
if (dsquared > 1e-5){
if(dsquared > maxR2_2){
float NdotV = 1.0 - clamp(dot(vec*dsquared, normalize(normal)),0.,1.);
sss += max((NdotV - (1.0-NdotV)) * clamp(1.0-maxR2_2/dsquared,0.0,1.0) ,0.0);
}
n += 1;
}
}
}
sss = max(1.0 - sss/n, 0.0);
}
vec3 rayTrace_GI(vec3 dir,vec3 position,float dither, float quality){
vec3 clipPosition = toClipSpace3(position);
float rayLength = ((position.z + dir.z * far*sqrt(3.)) > -near) ?
(-near -position.z) / dir.z : far*sqrt(3.);
vec3 direction = normalize(toClipSpace3(position+dir*rayLength)-clipPosition); //convert to clip space
direction.xy = normalize(direction.xy);
//get at which length the ray intersects with the edge of the screen
vec3 maxLengths = (step(0.,direction)-clipPosition) / direction;
float mult = maxLengths.y;
vec3 stepv = direction * mult / quality*vec3(RENDER_SCALE,1.0) * dither;
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ;
spos.xy += TAA_Offset*texelSize*0.5/RENDER_SCALE;
float biasdist = clamp(position.z*position.z/50.0,1,2); // shrink sample size as distance increases
for(int i = 0; i < int(quality); i++){
spos += stepv;
float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0);
float currZ = linZ(spos.z);
if( sp < currZ) {
float dist = abs(sp-currZ)/currZ;
if (abs(dist) < biasdist*0.05) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0);
}
spos += stepv;
}
return vec3(1.1);
}
vec3 RT(vec3 dir, vec3 position, float noise, float stepsizes){
float dist = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases
float stepSize = stepsizes / dist;
int maxSteps = STEPS;
vec3 clipPosition = toClipSpace3(position);
float rayLength = ((position.z + dir.z * sqrt(3.0)*far) > -sqrt(3.0)*near) ?
(-sqrt(3.0)*near -position.z) / dir.z : sqrt(3.0)*far;
vec3 end = toClipSpace3(position+dir*rayLength) ;
vec3 direction = end-clipPosition ; //convert to clip space
float len = max(abs(direction.x)/texelSize.x,abs(direction.y)/texelSize.y)/stepSize;
//get at which length the ray intersects with the edge of the screen
vec3 maxLengths = (step(0.,direction)-clipPosition) / direction;
float mult = min(min(maxLengths.x,maxLengths.y),maxLengths.z)*2000.0;
vec3 stepv = direction/len;
int iterations = min(int(min(len, mult*len)-2), maxSteps);
//Do one iteration for closest texel (good contact shadows)
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ;
spos.xy += TAA_Offset*texelSize*0.5*RENDER_SCALE;
spos += stepv/(stepSize/2);
float distancered = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases
for(int i = 0; i < iterations; i++){
if (spos.x < 0.0 || spos.y < 0.0 || spos.z < 0.0 || spos.x > 1.0 || spos.y > 1.0 || spos.z > 1.0) return vec3(1.1);
spos += stepv*noise;
float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/ texelSize/4),0).w/65000.0);
float currZ = linZ(spos.z);
if( sp < currZ) {
float dist = abs(sp-currZ)/currZ;
if (dist <= 0.1) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0);
}
}
return vec3(1.1);
}
vec3 cosineHemisphereSample(vec2 Xi, float roughness){
float r = sqrt(Xi.x);
float theta = 2.0 * 3.14159265359 * Xi.y;
float x = r * cos(theta);
float y = r * sin(theta);
return vec3(x, y, sqrt(clamp(1.0 - Xi.x,0.,1.)));
}
vec3 TangentToWorld(vec3 N, vec3 H, float roughness){
vec3 UpVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
vec3 T = normalize(cross(UpVector, N));
vec3 B = cross(N, T);
return vec3((T * H.x) + (B * H.y) + (N * H.z));
}
vec2 R2_samples(int n){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha * n);
}
void ApplySSRT(inout vec3 lighting, vec3 normal,vec2 noise,vec3 fragpos, float lightmaps, vec3 torchcolor){
int nrays = RAY_COUNT;
vec3 radiance = vec3(0.0);
vec3 occlusion = vec3(0.0);
vec3 skycontribution = vec3(0.0);
for (int i = 0; i < nrays; i++){
int seed = (frameCounter%40000)*nrays+i;
vec2 ij = fract(R2_samples(seed) + noise );
vec3 rayDir = TangentToWorld(normal, normalize(cosineHemisphereSample(ij,1.0)) ,1.0);
#ifdef HQ_SSGI
vec3 rayHit = rayTrace_GI( mat3(gbufferModelView) * rayDir, fragpos, blueNoise(), 50.); // ssr rt
#else
vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, fragpos, blueNoise(), 30.); // choc sspt
#endif
skycontribution = lighting;
if (rayHit.z < 1.){
#if indirect_effect == 4
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rayHit) + 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){
radiance += (texture2D(colortex5,previousPosition.xy).rgb + skycontribution) * GI_Strength;
}else{
radiance += skycontribution;
}
#else
radiance += skycontribution;
#endif
occlusion += skycontribution * GI_Strength;
} else {
radiance += skycontribution;
}
}
occlusion *= AO_Strength;
lighting = max(radiance/nrays - occlusion/nrays, 0.0);
}
void main() {
float dirtAmount = Dirt_Amount;
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;
vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
float z0 = texture2D(depthtex0,texcoord).x;
float z = texture2D(depthtex1,texcoord).x;
vec2 tempOffset=TAA_Offset;
float noise = blueNoise();
vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(tempOffset)*texelSize*0.5,z));
vec3 p3 = mat3(gbufferModelViewInverse) * fragpos;
vec3 np3 = normVec(p3);
////// --------------- UNPACK OPAQUE GBUFFERS --------------- //////
vec4 data = texture2D(colortex1,texcoord);
vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y)); // albedo, masks
vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w)); // normals, lightmaps
// vec4 dataUnpacked2 = vec4(decodeVec2(data.z),decodeVec2(data.w));
vec3 albedo = toLinear(vec3(dataUnpacked0.xz,dataUnpacked1.x));
vec2 lightmap = dataUnpacked1.yz;
vec3 normal = decode(dataUnpacked0.yw);
////// --------------- UNPACK MISC --------------- //////
vec4 SpecularTex = texture2D(colortex8,texcoord);
float LabSSS = clamp((-65.0 + SpecularTex.z * 255.0) / 190.0 ,0.0,1.0);
vec4 normalAndAO = texture2D(colortex15,texcoord);
vec3 FlatNormals = normalAndAO.rgb * 2.0 - 1.0;
vec3 slopednormal = normal;
#ifdef POM
#ifdef Horrible_slope_normals
vec3 ApproximatedFlatNormal = normalize(cross(dFdx(p3), dFdy(p3))); // it uses depth that has POM written to it.
slopednormal = normalize(clamp(normal, ApproximatedFlatNormal*2.0 - 1.0, ApproximatedFlatNormal*2.0 + 1.0) );
#endif
#endif
float vanilla_AO = normalAndAO.a;
normalAndAO.a = clamp(pow(normalAndAO.a*5,4),0,1);
bool iswater = texture2D(colortex7,texcoord).a > 0.99;
bool lightningBolt = abs(dataUnpacked1.w-0.5) <0.01;
bool isLeaf = abs(dataUnpacked1.w-0.55) <0.01;
bool entities = abs(dataUnpacked1.w-0.45) < 0.01;
bool hand = abs(dataUnpacked1.w-0.75) < 0.01;
// bool blocklights = abs(dataUnpacked1.w-0.8) <0.01;
vec3 waterAmbientLightCol = vec3(0.0);
if (z >=1.0) {
vec3 color = clamp(gl_Fog.color.rgb*pow(luma(gl_Fog.color.rgb),-0.75)*0.65,0.0,1.0)*0.02;
gl_FragData[0].rgb = clamp(fp10Dither(color*8./3. * (1.0-rainStrength*0.4),triangularize(noise)),0.0,65000.);
} else {
p3 += gbufferModelViewInverse[3].xyz + cameraPosition;
// vec3 FogColor = (gl_Fog.color.rgb / pow(0.00001 + dot(gl_Fog.color.rgb,vec3(0.3333)),1.0) ) * 0.2;
// vec3 fogColor = (gl_Fog.color.rgb / max(pow(dot(gl_Fog.color.rgb,vec3(0.3333)),1.1),0.01) ) ;
// vec3 FogColor = (gl_Fog.color.rgb / max(dot(gl_Fog.color.rgb,vec3(0.3333)),0.01) );
vec3 AmbientLightColor = skyCloudsFromTexLOD2(normal, colortex4, 6).rgb / 10;
vec3 up = skyCloudsFromTexLOD2(vec3( 0, 1, 0), colortex4, 6).rgb / 10;
vec3 down = skyCloudsFromTexLOD2(vec3( 0,-1, 0), colortex4, 6).rgb / 10;
waterAmbientLightCol = down;
up *= pow( max( slopednormal.y, 0), 2);
down *= pow( max(-slopednormal.y, 0), 2);
AmbientLightColor += up + down;
// do all ambient lighting stuff
vec3 Indirect_lighting = DoAmbientLighting_Nether(AmbientLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.x, normal, np3, p3 );
#if indirect_effect == 0
vec3 AO = vec3( exp( (vanilla_AO*vanilla_AO) * -5) ) ;
if(!hand) Indirect_lighting *= AO;
#endif
#if indirect_effect == 1
vec3 AO = vec3( exp( (vanilla_AO*vanilla_AO) * -5) ) ;
if(!hand) Indirect_lighting *= ssao(fragpos,noise,FlatNormals) * AO;
#endif
// RTAO and/or SSGI
#if indirect_effect == 3 || indirect_effect == 4
if (!hand) ApplySSRT(Indirect_lighting, normal, blueNoise(gl_FragCoord.xy).rg, fragpos, lightmap.x,vec3(TORCH_R,TORCH_G,TORCH_B));
#endif
// finalize
gl_FragData[0].rgb = Indirect_lighting * albedo;
#ifdef Specular_Reflections
// MaterialReflections_N(gl_FragData[0].rgb, SpecularTex.r, vec3(SpecularTex.g), albedo, normal, np3, fragpos, vec3(blueNoise(gl_FragCoord.xy).rg,noise), hand);
vec3 specNoise = vec3(blueNoise(gl_FragCoord.xy).rg, interleaved_gradientNoise());
DoSpecularReflections(gl_FragData[0].rgb, fragpos, np3, vec3(0.0), specNoise, normal, SpecularTex.r, SpecularTex.g, albedo, vec3(0.0), 1.0, hand);
#endif
Emission(gl_FragData[0].rgb, albedo, SpecularTex.a);
if(lightningBolt) gl_FragData[0].rgb += vec3(77.0, 153.0, 255.0);
// gl_FragData[0].rgb = AmbientLightColor;
}
if (iswater && isEyeInWater == 0){
vec3 fragpos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0));
float Vdiff = distance(fragpos,fragpos0);
float VdotU = np3.y;
float estimatedDepth = Vdiff * abs(VdotU) ; //assuming water plane
vec3 ambientColVol = max(vec3(1.0,0.5,1.0) * 0.3, vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.01 + nightVision));
waterVolumetrics(gl_FragData[0].rgb, fragpos0, fragpos, estimatedDepth , estimatedDepth, Vdiff, noise, totEpsilon, scatterCoef, ambientColVol);
}
/* DRAWBUFFERS:3 */
}

View File

@ -1,51 +1,5 @@
#version 120 #version 120
//#extension GL_EXT_gpu_shader4 : disable
#include "/lib/settings.glsl" #define NETHER_SHADER
varying vec2 texcoord; #include "/dimensions/composite2.vsh"
// flat varying vec3 avgAmbient;
flat varying float tempOffsets;
flat varying vec2 TAA_Offset;
flat varying vec3 zMults;
uniform sampler2D colortex4;
uniform float far;
uniform float near;
uniform mat4 gbufferModelViewInverse;
uniform vec3 sunPosition;
uniform float rainStrength;
uniform float sunElevation;
uniform int frameCounter;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
vec2(-3,-5.)/8.,
vec2(-5.,5.)/8.,
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
#include "/lib/util.glsl"
void main() {
gl_Position = ftransform();
texcoord = gl_MultiTexCoord0.xy;
tempOffsets = HaltonSeq2(frameCounter%10000);
TAA_Offset = offsets[frameCounter%8];
#ifndef TAA
TAA_Offset = vec2(0.0);
#endif
// avgAmbient = texelFetch2D(colortex4,ivec2(0,37),0).rgb;
zMults = vec3((far * near)*2.0,far+near,far-near);
}

View File

@ -1,129 +1,5 @@
#version 120 #version 120
//Volumetric fog rendering
//#extension GL_EXT_gpu_shader4 : disable
#include "/lib/settings.glsl" #define NETHER_SHADER
flat varying float tempOffsets; #include "/dimensions/composite3.fsh"
flat varying vec2 TAA_Offset;
uniform sampler2D noisetex;
uniform sampler2D depthtex0;
uniform sampler2D colortex2;
uniform sampler2D colortex3;
// uniform sampler2D colortex4;
uniform vec3 sunVec;
uniform float far;
uniform int frameCounter;
uniform float rainStrength;
uniform float sunElevation;
uniform ivec2 eyeBrightnessSmooth;
uniform float frameTimeCounter;
uniform int isEyeInWater;
uniform vec2 texelSize;
uniform vec3 previousCameraPosition;
varying vec2 texcoord;
#include "/lib/color_transforms.glsl"
#include "/lib/color_dither.glsl"
#include "/lib/projections.glsl"
#include "/lib/nether_fog.glsl"
#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.)
float interleaved_gradientNoise(){
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+tempOffsets);
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient){
inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value
int spCount = rayMarchSampleCount;
vec3 start = toShadowSpaceProjected(rayStart);
vec3 end = toShadowSpaceProjected(rayEnd);
vec3 dV = (end-start);
//limit ray length at 32 blocks for performance and reducing integration error
//you can't see above this anyway
float maxZ = min(rayLength,12.0)/(1e-8+rayLength);
dV *= maxZ;
rayLength *= maxZ;
float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength;
estEndDepth *= maxZ;
estSunDepth *= maxZ;
vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz;
vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
float expFactor = 11.0;
for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
vec3 spPos = start.xyz + dV*d;
vec3 progressW = start.xyz+cameraPosition+dVWorld;
vec3 ambientMul = exp(-max(estEndDepth * d,0.0) * waterCoefs );
vec3 Indirectlight = ambientMul*ambient;
vec3 light = Indirectlight * scatterCoef;
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
absorbance *= exp(-dd * rayLength * waterCoefs);
}
inColor += vL;
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
/* DRAWBUFFERS:0 */
vec2 tc = floor(gl_FragCoord.xy)*2.0*texelSize+0.5*texelSize;
float z = texture2D(depthtex0,tc).x;
vec3 fragpos = toScreenSpace(vec3(tc,z));
if (isEyeInWater == 0){
vec4 VolumetricFog = GetVolumetricFog(fragpos, blueNoise());
gl_FragData[0] = clamp(VolumetricFog, 0.0, 65000.0);
} else {
float dirtAmount = Dirt_Amount;
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;
vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
vec3 fragpos0 = toScreenSpace(vec3(texcoord - TAA_Offset*texelSize*0.5,z));
vec3 ambientColVol = max(vec3(1.0,0.5,1.0) * 0.6, vec3(0.2,0.4,1.0) * MIN_LIGHT_AMOUNT*0.01);
gl_FragData[0].a = 1;
waterVolumetrics(gl_FragData[0].rgb, fragpos0, fragpos, 1 , 1, 1, blueNoise(), totEpsilon, scatterCoef, ambientColVol);
}
}

View File

@ -1,37 +1,5 @@
#version 120 #version 120
//#extension GL_EXT_gpu_shader4 : disable
flat varying float tempOffsets; #define NETHER_SHADER
uniform int frameCounter; #include "/dimensions/composite3.vsh"
#include "/lib/util.glsl"
flat varying vec2 TAA_Offset;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
vec2(-3,-5.)/8.,
vec2(-5.,5.)/8.,
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
gl_Position = ftransform();
tempOffsets = HaltonSeq2(frameCounter%10000);
TAA_Offset = offsets[frameCounter%8];
#ifndef TAA
TAA_Offset = vec2(0.0);
#endif
gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.51*2.0-1.0;
}

View File

@ -0,0 +1,5 @@
#version 120
#define NETHER_SHADER
#include "/dimensions/composite4.fsh"

View File

@ -0,0 +1,5 @@
#version 120
#define NETHER_SHADER
#include "/dimensions/composite4.vsh"

View File

@ -0,0 +1,5 @@
#version 120
#define NETHER_SHADER
#include "/dimensions/composite5.fsh"

View File

@ -0,0 +1,5 @@
#version 120
#define NETHER_SHADER
#include "/dimensions/composite5.vsh"

View File

@ -1,309 +1,5 @@
#version 120 #version 120
//Horizontal bilateral blur for volumetric fog + Forward rendered objects + Draw volumetric fog
//#extension GL_EXT_gpu_shader4 : disable
#include "/lib/settings.glsl"
flat varying vec3 zMults; #define NETHER_SHADER
flat varying vec2 TAA_Offset;
#include "/dimensions/composite6.fsh"
uniform sampler2D noisetex;
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
uniform sampler2D colortex0;
uniform sampler2D colortex1;
uniform sampler2D colortex2;
uniform sampler2D colortex3;
// uniform sampler2D colortex4;
uniform sampler2D colortex5;
uniform sampler2D colortex6;
uniform sampler2D colortex7;
uniform sampler2D colortex8;
uniform sampler2D colortex9;
uniform sampler2D colortex11;
uniform sampler2D colortex13;
uniform sampler2D colortex15;
uniform vec2 texelSize;
flat varying vec3 noooormal;
flat varying vec4 lightCol; //main light source color (rgb),used light source(1=sun,-1=moon)
flat varying vec3 WsunVec;
uniform vec3 sunVec;
uniform float frameTimeCounter;
uniform int frameCounter;
uniform float far;
uniform float near;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferModelView;
uniform mat4 gbufferPreviousModelView;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferProjection;
uniform mat4 gbufferPreviousProjection;
uniform vec3 cameraPosition;
uniform vec3 previousCameraPosition;
uniform int isEyeInWater;
uniform ivec2 eyeBrightnessSmooth;
uniform float rainStrength;
uniform float blindness;
uniform float darknessFactor;
uniform float darknessLightFactor;
#include "/lib/waterBump.glsl"
#include "/lib/res_params.glsl"
#include "/lib/sky_gradient.glsl"
#include "/lib/volumetricClouds.glsl"
// #include "/lib/biome_specifics.glsl"
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
float ld(float depth) {
return 1.0 / (zMults.y - depth * zMults.z); // (-depth * (far - near)) = (2.0 * near)/ld - far - near
}
float luma(vec3 color) {
return dot(color,vec3(0.21, 0.72, 0.07));
}
vec3 toLinear(vec3 sRGB){
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
}
vec3 toScreenSpace(vec3 p) {
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
vec3 p3 = p * 2. - 1.;
vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
return fragposition.xyz / fragposition.w;
}
// #include "/lib/specular.glsl"
vec4 BilateralUpscale(sampler2D tex, sampler2D depth,vec2 coord,float frDepth, vec2 distort){
coord = coord;
vec4 vl = vec4(0.0);
float sum = 0.0;
mat3x3 weights;
const ivec2 scaling = ivec2(1.0/VL_RENDER_RESOLUTION);
ivec2 posD = ivec2(coord*VL_RENDER_RESOLUTION + distort)*scaling;
ivec2 posVl = ivec2(coord*VL_RENDER_RESOLUTION + distort);
float dz = zMults.x;
ivec2 pos = (ivec2(gl_FragCoord.xy+frameCounter) % 2 )*2;
ivec2 tcDepth = posD + ivec2(-2,-2) * scaling + pos * scaling;
float dsample = ld(texelFetch2D(depth,tcDepth,0).r);
float w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
vl += texelFetch2D(tex,posVl+ivec2(-2)+pos,0)*w;
sum += w;
tcDepth = posD + ivec2(-2,0) * scaling + pos * scaling;
dsample = ld(texelFetch2D(depth,tcDepth,0).r);
w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
vl += texelFetch2D(tex,posVl+ivec2(-2,0)+pos,0)*w;
sum += w;
tcDepth = posD + ivec2(0) + pos * scaling;
dsample = ld(texelFetch2D(depth,tcDepth,0).r);
w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
vl += texelFetch2D(tex,posVl+ivec2(0)+pos,0)*w;
sum += w;
tcDepth = posD + ivec2(0,-2) * scaling + pos * scaling;
dsample = ld(texelFetch2D(depth,tcDepth,0).r);
w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
vl += texelFetch2D(tex,posVl+ivec2(0,-2)+pos,0)*w;
sum += w;
return vl/sum;
}
vec3 decode (vec2 encn){
vec3 n = vec3(0.0);
encn = encn * 2.0 - 1.0;
n.xy = abs(encn);
n.z = 1.0 - n.x - n.y;
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 ;
}
vec3 worldToView(vec3 worldPos) {
vec4 pos = vec4(worldPos, 0.0);
pos = gbufferModelView * pos;
return pos.xyz;
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
vec4 blueNoise(vec2 coord){
return texelFetch2D(colortex6, ivec2(coord )%512 , 0);
}
vec3 normVec (vec3 vec){
return vec*inversesqrt(dot(vec,vec));
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
vec3 viewToWorld(vec3 viewPosition) {
vec4 pos;
pos.xyz = viewPosition;
pos.w = 0.0;
pos = gbufferModelViewInverse * pos;
return pos.xyz;
}
/// thanks stackoverflow https://stackoverflow.com/questions/944713/help-with-pixel-shader-effect-for-brightness-and-contrast#3027595
void applyContrast(inout vec3 color, float contrast){
color = ((color - 0.5) * max(contrast, 0.0)) + 0.5;
}
void main() {
/* DRAWBUFFERS:73 */
vec2 texcoord = gl_FragCoord.xy*texelSize;
vec4 trpData = texture2D(colortex7,texcoord);
bool iswater = trpData.a > 0.99;
float translucentAlpha = trpData.a;
// vec4 speculartex = texture2D(colortex8,texcoord); // translucents
// float sunlight = speculartex.b;
//3x3 bilateral upscale from half resolution
float z = texture2D(depthtex0,texcoord).x;
float z2 = texture2D(depthtex1,texcoord).x;
float frDepth = ld(z2);
// vec4 vl = texture2D(colortex0,texcoord * 0.5);
////// --------------- UNPACK OPAQUE GBUFFERS --------------- //////
vec4 data_opaque = texture2D(colortex1,texcoord);
vec4 dataUnpacked1 = vec4(decodeVec2(data_opaque.z),decodeVec2(data_opaque.w)); // normals, lightmaps
// vec4 dataUnpacked2 = vec4(decodeVec2(data.z),decodeVec2(data.w));
bool hand = abs(dataUnpacked1.w-0.75) < 0.01;
vec2 lightmap = dataUnpacked1.yz;
////// --------------- UNPACK TRANSLUCENT GBUFFERS --------------- //////
vec3 data = texture2D(colortex11,texcoord).rgb;
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.0) tangentNormals = vec2(0.0);
vec4 TranslucentShader = texture2D(colortex2,texcoord);
float lightleakfix = clamp(pow(eyeBrightnessSmooth.y/240.,2) ,0.0,1.0);
vec2 tempOffset = TAA_Offset;
vec3 fragpos = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z));
vec3 fragpos2 = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z2));
vec3 p3 = mat3(gbufferModelViewInverse) * fragpos;
vec3 np3 = normVec(p3);
vec2 refractedCoord = texcoord;
/// --- REFRACTION --- ///
#ifdef Refraction
refractedCoord += (tangentNormals * clamp((ld(z2) - ld(z)) * 0.5,0.0,0.15)) * RENDER_SCALE;
// refractedCoord += tangentNormals * 0.1 * RENDER_SCALE;
float refractedalpha = decodeVec2(texture2D(colortex11,refractedCoord).b).g;
float refractedalpha2 = texture2D(colortex7,refractedCoord).a;
if( refractedalpha <= 0.001 ||z < 0.56) refractedCoord = texcoord; // remove refracted coords on solids
#endif
/// --- MAIN COLOR BUFFER --- ///
// it is sampled with distorted texcoords
vec3 color = texture2D(colortex3,refractedCoord).rgb;
vec4 vl = BilateralUpscale(colortex0, depthtex1, gl_FragCoord.xy, frDepth, vec2(0.0));
float bloomyFogMult = 1.0;
if (TranslucentShader.a > 0.0){
#ifdef Glass_Tint
if(albedo.a > 0.2) color = color*albedo.rgb + color * clamp(pow(1.0-luma(albedo.rgb),20.),0.0,1.0);
#endif
color = color*(1.0-TranslucentShader.a) + TranslucentShader.rgb;
}
// underwater fog
if (isEyeInWater == 1){
float dirtAmount = Dirt_Amount;
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;
// float fogfade = clamp( exp(length(fragpos) / -20) ,0.0,1.0);
// vec3 fogfade = clamp( exp( (length(fragpos) / -4) * totEpsilon ) ,0.0,1.0);
vec3 fogfade = clamp( exp( (-length(fragpos)) * totEpsilon ) ,0.0,1.0);
fogfade *= 1.0 - clamp( length(fragpos) / far,0.0,1.0);
color.rgb *= fogfade ;
bloomyFogMult *= 0.4;
}
// apply VL fog to the scene
color *= vl.a;
color += vl.rgb;
// bloomy rain effect
float rainDrops = clamp(texture2D(colortex9,texcoord).a, 0.0,1.0);
if(rainDrops > 0.0) bloomyFogMult *= clamp(1.0 - pow(rainDrops*5.0,2),0.0,1.0);
/// lava.
if (isEyeInWater == 2){
color.rgb = vec3(4.0,0.5,0.1);
}
/// powdered snow
if (isEyeInWater == 3){
color.rgb = mix(color.rgb,vec3(10,15,20),clamp(length(fragpos)*0.5,0.,1.));
bloomyFogMult = 0.0;
}
// blidnesss
color.rgb *= mix(1.0,clamp( exp(pow(length(fragpos)*(blindness*0.2),2) * -1),0.,1.) , blindness);
// darkness effect
color.rgb *= mix(1.0, (1.0-darknessLightFactor*2.0) * clamp(1.0-pow(length(fragpos2)*(darknessFactor*0.07),2.0),0.0,1.0), darknessFactor);
#ifdef display_LUT
vec2 movedTC = texcoord;
vec3 thingy = texture2D(colortex4,movedTC).rgb / 150. * 5.0;
if(luma(thingy) > 0.0 ) color.rgb = thingy;
#endif
gl_FragData[0].r = vl.a * bloomyFogMult; // pass fog alpha so bloom can do bloomy fog
gl_FragData[1].rgb = clamp(color.rgb,0.0,68000.0);
}

View File

@ -1,19 +1,5 @@
#version 120 #version 120
//#extension GL_EXT_gpu_shader4 : disable
varying vec2 texcoord; #define NETHER_SHADER
flat varying vec3 zMults;
uniform float far;
uniform float near;
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() { #include "/dimensions/composite6.vsh"
zMults = vec3(1.0/(far * near),far+near,far-near);
gl_Position = ftransform();
texcoord = gl_MultiTexCoord0.xy;
}

View File

@ -0,0 +1,5 @@
#version 120
#define NETHER_SHADER
#include "/dimensions/composite7.fsh"

View File

@ -0,0 +1,5 @@
#version 120
#define NETHER_SHADER
#include "/dimensions/composite7.vsh"

View File

@ -1,354 +1,5 @@
#version 120 #version 120
//Temporal Anti-Aliasing + Dynamic exposure calculations (vertex shader)
//#extension GL_EXT_gpu_shader4 : disable
#include "/lib/settings.glsl" #define NETHER_SHADER
#include "/lib/res_params.glsl"
const int noiseTextureResolution = 32; #include "/dimensions/composite8.fsh"
/*
const int colortex0Format = RGBA16F; // low res clouds (deferred->composite2) + low res VL (composite5->composite15)
const int colortex1Format = RGBA16; //terrain gbuffer (gbuffer->composite2)
const int colortex2Format = RGBA16F; //forward + transparencies (gbuffer->composite4)
const int colortex3Format = R11F_G11F_B10F; //frame buffer + bloom (deferred6->final)
const int colortex4Format = RGBA16F; //light values and skyboxes (everything)
const int colortex5Format = R11F_G11F_B10F; //TAA buffer (everything)
const int colortex6Format = R11F_G11F_B10F; //additionnal buffer for bloom (composite3->final)
const int colortex7Format = RGBA8; //Final output, transparencies id (gbuffer->composite4)
*/
//no need to clear the buffers, saves a few fps
const bool colortex0Clear = false;
const bool colortex1Clear = false;
const bool colortex2Clear = true;
const bool colortex3Clear = false;
const bool colortex4Clear = false;
const bool colortex5Clear = false;
const bool colortex6Clear = false;
const bool colortex7Clear = false;
varying vec2 texcoord;
flat varying float exposureA;
flat varying float tempOffsets;
uniform sampler2D colortex3;
uniform sampler2D colortex0;
uniform sampler2D colortex5;
uniform sampler2D colortex6;
uniform sampler2D depthtex0;
uniform vec2 texelSize;
uniform float frameTimeCounter;
uniform int framemod8;
uniform float viewHeight;
uniform float viewWidth;
uniform vec3 previousCameraPosition;
uniform mat4 gbufferPreviousModelView;
#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.)
#include "/lib/projections.glsl"
float luma(vec3 color) {
return dot(color,vec3(0.21, 0.72, 0.07));
}
float interleaved_gradientNoise(){
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+tempOffsets);
}
float triangularize(float dither)
{
float center = dither*2.0-1.0;
dither = center*inversesqrt(abs(center));
return clamp(dither-fsign(center),0.0,1.0);
}
vec3 fp10Dither(vec3 color,float dither){
const vec3 mantissaBits = vec3(6.,6.,5.);
vec3 exponent = floor(log2(color));
return color + dither*exp2(-mantissaBits)*exp2(exponent);
}
//returns the projected coordinates of the closest point to the camera in the 3x3 neighborhood
vec3 closestToCamera3x3()
{
vec2 du = vec2(texelSize.x, 0.0);
vec2 dv = vec2(0.0, texelSize.y);
vec3 dtl = vec3(texcoord,0.) + vec3(-texelSize, texture2D(depthtex0, texcoord - dv - du).x);
vec3 dtc = vec3(texcoord,0.) + vec3( 0.0, -texelSize.y, texture2D(depthtex0, texcoord - dv).x);
vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture2D(depthtex0, texcoord - dv + du).x);
vec3 dml = vec3(texcoord,0.) + vec3(-texelSize.x, 0.0, texture2D(depthtex0, texcoord - du).x);
vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture2D(depthtex0, texcoord).x);
vec3 dmr = vec3(texcoord,0.) + vec3( texelSize.x, 0.0, texture2D(depthtex0, texcoord + du).x);
vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture2D(depthtex0, texcoord + dv - du).x);
vec3 dbc = vec3(texcoord,0.) + vec3( 0.0, texelSize.y, texture2D(depthtex0, texcoord + dv).x);
vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture2D(depthtex0, texcoord + dv + du).x);
vec3 dmin = dmc;
dmin = dmin.z > dtc.z? dtc : dmin;
dmin = dmin.z > dtr.z? dtr : dmin;
dmin = dmin.z > dml.z? dml : dmin;
dmin = dmin.z > dtl.z? dtl : dmin;
dmin = dmin.z > dmr.z? dmr : dmin;
dmin = dmin.z > dbl.z? dbl : dmin;
dmin = dmin.z > dbc.z? dbc : dmin;
dmin = dmin.z > dbr.z? dbr : dmin;
return dmin;
}
//Modified texture interpolation from inigo quilez
vec4 smoothfilter(in sampler2D tex, 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 texture2D( tex, uv);
}
//Due to low sample count we "tonemap" the inputs to preserve colors and smoother edges
vec3 weightedSample(sampler2D colorTex, vec2 texcoord){
vec3 wsample = texture2D(colorTex,texcoord).rgb*exposureA;
return wsample/(1.0+luma(wsample));
}
//from : https://gist.github.com/TheRealMJP/c83b8c0f46b63f3a88a5986f4fa982b1
vec4 SampleTextureCatmullRom(sampler2D tex, vec2 uv, vec2 texSize )
{
// We're going to sample a a 4x4 grid of texels surrounding the target UV coordinate. We'll do this by rounding
// down the sample location to get the exact center of our "starting" texel. The starting texel will be at
// location [1, 1] in the grid, where [0, 0] is the top left corner.
vec2 samplePos = uv * texSize;
vec2 texPos1 = floor(samplePos - 0.5) + 0.5;
// Compute the fractional offset from our starting texel to our original sample location, which we'll
// feed into the Catmull-Rom spline function to get our filter weights.
vec2 f = samplePos - texPos1;
// Compute the Catmull-Rom weights using the fractional offset that we calculated earlier.
// These equations are pre-expanded based on our knowledge of where the texels will be located,
// which lets us avoid having to evaluate a piece-wise function.
vec2 w0 = f * ( -0.5 + f * (1.0 - 0.5*f));
vec2 w1 = 1.0 + f * f * (-2.5 + 1.5*f);
vec2 w2 = f * ( 0.5 + f * (2.0 - 1.5*f) );
vec2 w3 = f * f * (-0.5 + 0.5 * f);
// Work out weighting factors and sampling offsets that will let us use bilinear filtering to
// simultaneously evaluate the middle 2 samples from the 4x4 grid.
vec2 w12 = w1 + w2;
vec2 offset12 = w2 / (w1 + w2);
// Compute the final UV coordinates we'll use for sampling the texture
vec2 texPos0 = texPos1 - vec2(1.0);
vec2 texPos3 = texPos1 + vec2(2.0);
vec2 texPos12 = texPos1 + offset12;
texPos0 *= texelSize;
texPos3 *= texelSize;
texPos12 *= texelSize;
vec4 result = vec4(0.0);
result += texture2D(tex, vec2(texPos0.x, texPos0.y)) * w0.x * w0.y;
result += texture2D(tex, vec2(texPos12.x, texPos0.y)) * w12.x * w0.y;
result += texture2D(tex, vec2(texPos3.x, texPos0.y)) * w3.x * w0.y;
result += texture2D(tex, vec2(texPos0.x, texPos12.y)) * w0.x * w12.y;
result += texture2D(tex, vec2(texPos12.x, texPos12.y)) * w12.x * w12.y;
result += texture2D(tex, vec2(texPos3.x, texPos12.y)) * w3.x * w12.y;
result += texture2D(tex, vec2(texPos0.x, texPos3.y)) * w0.x * w3.y;
result += texture2D(tex, vec2(texPos12.x, texPos3.y)) * w12.x * w3.y;
result += texture2D(tex, vec2(texPos3.x, texPos3.y)) * w3.x * w3.y;
return result;
}
//approximation from SMAA presentation from siggraph 2016
vec3 FastCatmulRom(sampler2D colorTex, vec2 texcoord, vec4 rtMetrics, float sharpenAmount)
{
vec2 position = rtMetrics.zw * texcoord;
vec2 centerPosition = floor(position - 0.5) + 0.5;
vec2 f = position - centerPosition;
vec2 f2 = f * f;
vec2 f3 = f * f2;
float c = sharpenAmount;
vec2 w0 = -c * f3 + 2.0 * c * f2 - c * f;
vec2 w1 = (2.0 - c) * f3 - (3.0 - c) * f2 + 1.0;
vec2 w2 = -(2.0 - c) * f3 + (3.0 - 2.0 * c) * f2 + c * f;
vec2 w3 = c * f3 - c * f2;
vec2 w12 = w1 + w2;
vec2 tc12 = rtMetrics.xy * (centerPosition + w2 / w12);
vec3 centerColor = texture2D(colorTex, vec2(tc12.x, tc12.y)).rgb;
vec2 tc0 = rtMetrics.xy * (centerPosition - 1.0);
vec2 tc3 = rtMetrics.xy * (centerPosition + 2.0);
vec4 color = vec4(texture2D(colorTex, vec2(tc12.x, tc0.y )).rgb, 1.0) * (w12.x * w0.y ) +
vec4(texture2D(colorTex, vec2(tc0.x, tc12.y)).rgb, 1.0) * (w0.x * w12.y) +
vec4(centerColor, 1.0) * (w12.x * w12.y) +
vec4(texture2D(colorTex, vec2(tc3.x, tc12.y)).rgb, 1.0) * (w3.x * w12.y) +
vec4(texture2D(colorTex, vec2(tc12.x, tc3.y )).rgb, 1.0) * (w12.x * w3.y );
return color.rgb/color.a;
}
vec3 clip_aabb(vec3 q,vec3 aabb_min, vec3 aabb_max)
{
vec3 p_clip = 0.5 * (aabb_max + aabb_min);
vec3 e_clip = 0.5 * (aabb_max - aabb_min) + 0.00000001;
vec3 v_clip = q - vec3(p_clip);
vec3 v_unit = v_clip.xyz / e_clip;
vec3 a_unit = abs(v_unit);
float ma_unit = max(a_unit.x, max(a_unit.y, a_unit.z));
if (ma_unit > 1.0)
return vec3(p_clip) + v_clip / ma_unit;
else
return q;
}
vec3 toClipSpace3Prev(vec3 viewSpacePosition) {
return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
}
vec3 tonemap(vec3 col){
return col/(1+luma(col));
}
vec3 invTonemap(vec3 col){
return col/(1-luma(col));
}
vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth)
{
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);
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;
return dmin;
}
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
vec2(-3,-5.)/8.,
vec2(-5.,5.)/8.,
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
vec3 TAA_hq(){
vec2 adjTC = texcoord;
//use velocity from the nearest texel from camera in a 3x3 box in order to improve edge quality in motion
#ifdef CLOSEST_VELOCITY
vec3 closestToCamera = closestToCamera5taps(adjTC, depthtex0);
#endif
#ifndef CLOSEST_VELOCITY
vec3 closestToCamera = vec3(texcoord,texture2D(depthtex1,adjTC).x);
#endif
//reproject previous frame
vec3 fragposition = toScreenSpace(closestToCamera);
fragposition = mat3(gbufferModelViewInverse) * fragposition + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition);
vec3 previousPosition = mat3(gbufferPreviousModelView) * fragposition + gbufferPreviousModelView[3].xyz;
previousPosition = toClipSpace3Prev(previousPosition);
vec2 velocity = previousPosition.xy - closestToCamera.xy;
previousPosition.xy = texcoord + velocity;
//reject history if off-screen and early exit
if (previousPosition.x < 0.0 || previousPosition.y < 0.0 || previousPosition.x > 1.0 || previousPosition.y > 1.0)
return smoothfilter(colortex3, adjTC + offsets[framemod8]*texelSize*0.5).xyz;
vec3 albedoCurrent0 = texture2D(colortex3, adjTC).rgb;
vec3 albedoCurrent1 = texture2D(colortex3, adjTC + vec2(texelSize.x,texelSize.y)).rgb;
vec3 albedoCurrent2 = texture2D(colortex3, adjTC + vec2(texelSize.x,-texelSize.y)).rgb;
vec3 albedoCurrent3 = texture2D(colortex3, adjTC + vec2(-texelSize.x,-texelSize.y)).rgb;
vec3 albedoCurrent4 = texture2D(colortex3, adjTC + vec2(-texelSize.x,texelSize.y)).rgb;
vec3 albedoCurrent5 = texture2D(colortex3, adjTC + vec2(0.0,texelSize.y)).rgb;
vec3 albedoCurrent6 = texture2D(colortex3, adjTC + vec2(0.0,-texelSize.y)).rgb;
vec3 albedoCurrent7 = texture2D(colortex3, adjTC + vec2(-texelSize.x,0.0)).rgb;
vec3 albedoCurrent8 = texture2D(colortex3, adjTC + vec2(texelSize.x,0.0)).rgb;
//Assuming the history color is a blend of the 3x3 neighborhood, we clamp the history to the min and max of each channel in the 3x3 neighborhood
vec3 cMax = max(max(max(albedoCurrent0,albedoCurrent1),albedoCurrent2),max(albedoCurrent3,max(albedoCurrent4,max(albedoCurrent5,max(albedoCurrent6,max(albedoCurrent7,albedoCurrent8))))));
vec3 cMin = min(min(min(albedoCurrent0,albedoCurrent1),albedoCurrent2),min(albedoCurrent3,min(albedoCurrent4,min(albedoCurrent5,min(albedoCurrent6,min(albedoCurrent7,albedoCurrent8))))));
albedoCurrent0 = smoothfilter(colortex3, adjTC + offsets[framemod8]*texelSize*0.5).rgb;
#ifndef NO_CLIP
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);
float test = 0.05;
// if(hand) movementRejection *= 5;
// if(istranslucent) test = 0.1;
//Blend current pixel with clamped history, apply fast tonemap beforehand to reduce flickering
// vec3 supersampled = invTonemap(mix(tonemap(finalcAcc),tonemap(albedoCurrent0),clamp(BLEND_FACTOR + movementRejection, min(luma(motionVector) *255,1.0),1.)));
vec3 supersampled = invTonemap(mix(tonemap(finalcAcc),tonemap(albedoCurrent0),clamp(BLEND_FACTOR + movementRejection, test,1.)));
#endif
#ifdef NO_CLIP
vec3 albedoPrev = texture2D(colortex5, previousPosition.xy).xyz;
vec3 supersampled = mix(albedoPrev,albedoCurrent0,clamp(0.05,0.,1.));
#endif
//De-tonemap
return supersampled;
}
void main() {
/* DRAWBUFFERS:5 */
gl_FragData[0].a = 1.0;
#ifdef TAA
vec3 color = TAA_hq();
gl_FragData[0].rgb = clamp(fp10Dither(color,triangularize(interleaved_gradientNoise())),6.11*1e-5,65000.0);
#endif
#ifndef TAA
vec3 color = clamp(fp10Dither(texture2D(colortex3,texcoord).rgb,triangularize(interleaved_gradientNoise())),0.,65000.);
gl_FragData[0].rgb = color;
#endif
}

View File

@ -1,20 +1,5 @@
#version 120 #version 120
//#extension GL_EXT_gpu_shader4 : disable
#define NETHER_SHADER
varying vec2 texcoord; #include "/dimensions/composite8.vsh"
flat varying float exposureA;
flat varying float tempOffsets;
uniform sampler2D colortex4;
uniform int frameCounter;
#include "/lib/util.glsl"
void main() {
tempOffsets = HaltonSeq2(frameCounter%10000);
gl_Position = ftransform();
texcoord = gl_MultiTexCoord0.xy;
exposureA = texelFetch2D(colortex4,ivec2(10,37),0).r;
}

View File

@ -1,45 +1,5 @@
#version 120 #version 120
//downsample 1st pass (half res) for bloom
uniform sampler2D colortex5; #define NETHER_SHADER
uniform vec2 texelSize;
uniform float viewWidth;
uniform float viewHeight;
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() { #include "/dimensions/composite9.fsh"
/* DRAWBUFFERS:3 */
vec2 resScale = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.))/vec2(1920.,1080.);
vec2 quarterResTC = gl_FragCoord.xy*2.*resScale*texelSize;
//0.5
gl_FragData[0] = texture2D(colortex5,quarterResTC-1.0*vec2(texelSize.x,texelSize.y))/4.*0.5;
gl_FragData[0] += texture2D(colortex5,quarterResTC+1.0*vec2(texelSize.x,texelSize.y))/4.*0.5;
gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(-1.0*texelSize.x,1.0*texelSize.y))/4.*0.5;
gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(1.0*texelSize.x,-1.0*texelSize.y))/4.*0.5;
//0.25
gl_FragData[0] += texture2D(colortex5,quarterResTC-2.0*vec2(texelSize.x,0.0))/2.*0.125;
gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(0.0,texelSize.y))/2.*0.125;
gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(0,-texelSize.y))/2*0.125;
gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(-texelSize.x,0.0))/2*0.125;
//0.125
gl_FragData[0] += texture2D(colortex5,quarterResTC-2.0*vec2(texelSize.x,texelSize.y))/4.*0.125;
gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(texelSize.x,texelSize.y))/4.*0.125;
gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(-2.0*texelSize.x,2.0*texelSize.y))/4.*0.125;
gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(2.0*texelSize.x,-2.0*texelSize.y))/4.*0.125;
//0.125
gl_FragData[0] += texture2D(colortex5,quarterResTC)*0.125;
gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.);
if (quarterResTC.x > 1.0 - 3.5*texelSize.x || quarterResTC.y > 1.0 -3.5*texelSize.y || quarterResTC.x < 3.5*texelSize.x || quarterResTC.y < 3.5*texelSize.y) gl_FragData[0].rgb = vec3(0.0);
}

View File

@ -1,17 +1,5 @@
#version 120 #version 120
uniform float viewWidth; #define NETHER_SHADER
uniform float viewHeight;
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() { #include "/dimensions/composite9.vsh"
//Improves performances and makes sure bloom radius stays the same at high resolution (>1080p)
vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.));
gl_Position = ftransform();
//*0.51 to avoid errors when sampling outside since clearing is disabled
gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.51/clampedRes*vec2(1920.0,1080.)*2.0-1.0;
}

View File

@ -1,92 +1,5 @@
#version 120 #version 120
//#extension GL_EXT_gpu_shader4 : disable
#define NETHER_SHADER
#include "/lib/settings.glsl" #include "/dimensions/deferred.fsh"
flat varying vec2 tempOffsets;
flat varying float exposure;
flat varying float avgBrightness;
flat varying float rodExposure;
flat varying float avgL2;
flat varying float centerDepth;
uniform sampler2D colortex4;
uniform sampler2D noisetex;
uniform int frameCounter;
uniform float rainStrength;
uniform float eyeAltitude;
uniform vec3 sunVec;
uniform vec2 texelSize;
uniform float frameTimeCounter;
uniform mat4 gbufferProjection;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferPreviousProjection;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferModelView;
uniform mat4 shadowModelView;
uniform mat4 shadowProjection;
uniform float sunElevation;
uniform vec3 cameraPosition;
uniform float far;
uniform ivec2 eyeBrightnessSmooth;
#include "/lib/util.glsl"
vec3 toShadowSpaceProjected(vec3 p3){
p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz;
p3 = mat3(shadowModelView) * p3 + shadowModelView[3].xyz;
p3 = diagonal3(shadowProjection) * p3 + shadowProjection[3].xyz;
return p3;
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)+frameCounter/1.6180339887);
return noise;
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
#include "/lib/nether_fog.glsl"
void main() {
/* DRAWBUFFERS:4 */
gl_FragData[0] = vec4(0.0,0.0,0.0,0.0);
vec2 fogPos = vec2(256.0 - 256.0*0.12,1.0);
//Sky gradient with clouds
if (gl_FragCoord.x > (fogPos.x - fogPos.x*0.22) && gl_FragCoord.y > 0.4 && gl_FragCoord.x < 535){
// vec2 p = clamp(floor(gl_FragCoord.xy-vec2(18.+257,1.))/256.+tempOffsets/256.,0.0,1.0);
vec2 p = clamp(floor(gl_FragCoord.xy-fogPos)/256.+tempOffsets/256.,-0.2,1.2);
vec3 viewVector = cartToSphere(p);
// vec3 BackgroundColor = (gl_Fog.color.rgb / max(dot(gl_Fog.color.rgb,vec3(0.3333)),0.01)) / 30.0;
// BackgroundColor *= abs(viewVector.y+0.5);
vec3 BackgroundColor = vec3(0.0);
vec4 VL_Fog = GetVolumetricFog(mat3(gbufferModelView)*viewVector*256., fract(frameCounter/1.6180339887));
BackgroundColor += VL_Fog.rgb/5.0;
gl_FragData[0] = vec4(BackgroundColor,1.0);
}
//Temporally accumulate sky and light values
vec3 temp = texelFetch2D(colortex4,ivec2(gl_FragCoord.xy),0).rgb;
vec3 curr = gl_FragData[0].rgb*150.;
gl_FragData[0].rgb = clamp(mix(temp,curr,0.05),0.0,65000.);
//Exposure values
if (gl_FragCoord.x > 10. && gl_FragCoord.x < 11. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 )
gl_FragData[0] = vec4(exposure,avgBrightness,avgL2,1.0);
if (gl_FragCoord.x > 14. && gl_FragCoord.x < 15. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 )
gl_FragData[0] = vec4(rodExposure,centerDepth,0.0, 1.0);
}

View File

@ -1,108 +1,5 @@
#version 120 #version 120
//#extension GL_EXT_gpu_shader4 : disable #define NETHER_SHADER
#include "/lib/settings.glsl" #include "/dimensions/deferred.vsh"
#include "/lib/res_params.glsl"
flat varying vec2 tempOffsets;
flat varying float exposure;
flat varying float avgBrightness;
flat varying float rodExposure;
flat varying float avgL2;
flat varying float centerDepth;
uniform sampler2D colortex4;
uniform sampler2D colortex6;
uniform sampler2D depthtex0;
uniform mat4 gbufferModelViewInverse;
uniform vec3 sunPosition;
uniform vec2 texelSize;
uniform float sunElevation;
uniform float eyeAltitude;
uniform float near;
uniform float far;
uniform float frameTime;
uniform int frameCounter;
uniform float rainStrength;
// uniform int worldTime;
vec3 sunVec = normalize(mat3(gbufferModelViewInverse) *sunPosition);
#include "/lib/sky_gradient.glsl"
#include "/lib/util.glsl"
#include "/lib/ROBOBO_sky.glsl"
float luma(vec3 color) {
return dot(color,vec3(0.21, 0.72, 0.07));
}
//Low discrepancy 2D sequence, integration error is as low as sobol but easier to compute : http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/
vec2 R2_samples(int n){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha * n);
}
float tanh(float x){
return (exp(x) - exp(-x))/(exp(x) + exp(-x));
}
float ld(float depth) {
return (2.0 * near) / (far + near - depth * (far - near)); // (-depth * (far - near)) = (2.0 * near)/ld - far - near
}
uniform float nightVision;
void main() {
gl_Position = ftransform()*0.5+0.5;
gl_Position.xy = gl_Position.xy*vec2(18.+258*2,258.)*texelSize;
gl_Position.xy = gl_Position.xy*2.-1.0;
//////////////////////////////
/// --- EXPOSURE STUFF --- ///
//////////////////////////////
float avgLuma = 0.0;
float m2 = 0.0;
int n=100;
vec2 clampedRes = max(1.0/texelSize,vec2(1920.0,1080.));
float avgExp = 0.0;
float avgB = 0.0;
vec2 resScale = vec2(1920.,1080.)/clampedRes;
const int maxITexp = 50;
float w = 0.0;
for (int i = 0; i < maxITexp; i++){
vec2 ij = R2_samples((frameCounter%2000)*maxITexp+i);
vec2 tc = 0.5 + (ij-0.5) * 0.7;
vec3 sp = texture2D(colortex6,tc/16. * resScale+vec2(0.375*resScale.x+4.5*texelSize.x,.0)).rgb;
avgExp += log(luma(sp));
avgB += log(min(dot(sp,vec3(0.07,0.22,0.71)),8e-2));
}
avgExp = exp(avgExp/maxITexp);
avgB = exp(avgB/maxITexp);
avgBrightness = clamp(mix(avgExp,texelFetch2D(colortex4,ivec2(10,37),0).g,0.95),0.00003051757,65000.0);
float L = max(avgBrightness,1e-8);
float keyVal = 1.03-2.0/(log(L*4000/150.*8./3.0+1.0)/log(10.0)+2.0);
float expFunc = 0.5+0.5*tanh(log(L));
float targetExposure = 0.18/log2(L*2.5+1.045)*0.62;
avgL2 = clamp(mix(avgB,texelFetch2D(colortex4,ivec2(10,37),0).b,0.985),0.00003051757,65000.0);
float targetrodExposure = max(0.012/log2(avgL2+1.002)-0.1,0.0)*1.2;
exposure = max(targetExposure*EXPOSURE_MULTIPLIER, 0);
float currCenterDepth = ld(texture2D(depthtex0, vec2(0.5)).r);
centerDepth = mix(sqrt(texelFetch2D(colortex4,ivec2(14,37),0).g/65000.0), currCenterDepth, clamp(DoF_Adaptation_Speed*exp(-0.016/frameTime+1.0)/(6.0+currCenterDepth*far),0.0,1.0));
centerDepth = centerDepth * centerDepth * 65000.0;
rodExposure = targetrodExposure;
#ifndef AUTO_EXPOSURE
exposure = Manual_exposure_value;
rodExposure = clamp(log(Manual_exposure_value*2.0+1.0)-0.1,0.0,2.0);
#endif
}

View File

@ -0,0 +1,5 @@
#version 120
#define NETHER_SHADER
#include "/dimensions/deferred1.fsh"

View File

@ -0,0 +1,5 @@
#version 120
#define NETHER_SHADER
#include "/dimensions/deferred1.vsh"

View File

@ -1,109 +1,5 @@
#version 120 #version 120
//Vignetting, applies bloom, applies exposure and tonemaps the final image
//#extension GL_EXT_gpu_shader4 : disable
#include "/lib/settings.glsl" #define NETHER_SHADER
#include "/dimensions/final.fsh"
varying vec2 texcoord;
uniform sampler2D colortex7;
uniform vec2 texelSize;
uniform float viewWidth;
uniform float viewHeight;
uniform float frameTimeCounter;
uniform int frameCounter;
uniform int isEyeInWater;
#include "/lib/color_transforms.glsl"
#include "/lib/color_dither.glsl"
#include "/lib/res_params.glsl"
vec4 SampleTextureCatmullRom(sampler2D tex, vec2 uv, vec2 texSize )
{
// We're going to sample a a 4x4 grid of texels surrounding the target UV coordinate. We'll do this by rounding
// down the sample location to get the exact center of our "starting" texel. The starting texel will be at
// location [1, 1] in the grid, where [0, 0] is the top left corner.
vec2 samplePos = uv * texSize;
vec2 texPos1 = floor(samplePos - 0.5) + 0.5;
// Compute the fractional offset from our starting texel to our original sample location, which we'll
// feed into the Catmull-Rom spline function to get our filter weights.
vec2 f = samplePos - texPos1;
// Compute the Catmull-Rom weights using the fractional offset that we calculated earlier.
// These equations are pre-expanded based on our knowledge of where the texels will be located,
// which lets us avoid having to evaluate a piece-wise function.
vec2 w0 = f * ( -0.5 + f * (1.0 - 0.5*f));
vec2 w1 = 1.0 + f * f * (-2.5 + 1.5*f);
vec2 w2 = f * ( 0.5 + f * (2.0 - 1.5*f) );
vec2 w3 = f * f * (-0.5 + 0.5 * f);
// Work out weighting factors and sampling offsets that will let us use bilinear filtering to
// simultaneously evaluate the middle 2 samples from the 4x4 grid.
vec2 w12 = w1 + w2;
vec2 offset12 = w2 / (w1 + w2);
// Compute the final UV coordinates we'll use for sampling the texture
vec2 texPos0 = texPos1 - vec2(1.0);
vec2 texPos3 = texPos1 + vec2(2.0);
vec2 texPos12 = texPos1 + offset12;
texPos0 *= texelSize;
texPos3 *= texelSize;
texPos12 *= texelSize;
vec4 result = vec4(0.0);
result += texture2D(tex, vec2(texPos0.x, texPos0.y)) * w0.x * w0.y;
result += texture2D(tex, vec2(texPos12.x, texPos0.y)) * w12.x * w0.y;
result += texture2D(tex, vec2(texPos3.x, texPos0.y)) * w3.x * w0.y;
result += texture2D(tex, vec2(texPos0.x, texPos12.y)) * w0.x * w12.y;
result += texture2D(tex, vec2(texPos12.x, texPos12.y)) * w12.x * w12.y;
result += texture2D(tex, vec2(texPos3.x, texPos12.y)) * w3.x * w12.y;
result += texture2D(tex, vec2(texPos0.x, texPos3.y)) * w0.x * w3.y;
result += texture2D(tex, vec2(texPos12.x, texPos3.y)) * w12.x * w3.y;
result += texture2D(tex, vec2(texPos3.x, texPos3.y)) * w3.x * w3.y;
return result;
}
/// thanks stackoverflow https://stackoverflow.com/questions/944713/help-with-pixel-shader-effect-for-brightness-and-contrast#3027595
void applyContrast(inout vec3 color, float contrast){
color = (color - 0.5) * contrast + 0.5;
}
void main() {
#ifdef BICUBIC_UPSCALING
vec3 col = SampleTextureCatmullRom(colortex7,texcoord,1.0/texelSize).rgb;
#else
vec3 col = texture2D(colortex7,texcoord).rgb;
#endif
#ifdef CONTRAST_ADAPTATIVE_SHARPENING
//Weights : 1 in the center, 0.5 middle, 0.25 corners
vec3 albedoCurrent1 = texture2D(colortex7, texcoord + vec2(texelSize.x,texelSize.y)/MC_RENDER_QUALITY*0.5).rgb;
vec3 albedoCurrent2 = texture2D(colortex7, texcoord + vec2(texelSize.x,-texelSize.y)/MC_RENDER_QUALITY*0.5).rgb;
vec3 albedoCurrent3 = texture2D(colortex7, texcoord + vec2(-texelSize.x,-texelSize.y)/MC_RENDER_QUALITY*0.5).rgb;
vec3 albedoCurrent4 = texture2D(colortex7, texcoord + vec2(-texelSize.x,texelSize.y)/MC_RENDER_QUALITY*0.5).rgb;
vec3 m1 = -0.5/3.5*col + albedoCurrent1/3.5 + albedoCurrent2/3.5 + albedoCurrent3/3.5 + albedoCurrent4/3.5;
vec3 std = abs(col - m1) + abs(albedoCurrent1 - m1) + abs(albedoCurrent2 - m1) +
abs(albedoCurrent3 - m1) + abs(albedoCurrent3 - m1) + abs(albedoCurrent4 - m1);
float contrast = 1.0 - luma(std)/5.0;
col = col*(1.0+(SHARPENING)*contrast)
- (SHARPENING)/(1.0-0.5/3.5)*contrast*(m1 - 0.5/3.5*col);
#endif
float lum = luma(col);
vec3 diff = col-lum;
col = col + diff*(-lum*CROSSTALK + SATURATION);
//col = -vec3(-lum*CROSSFADING + SATURATION);
applyContrast(col, CONTRAST);
gl_FragColor.rgb = clamp(int8Dither(col,texcoord),0.0,1.0);
//gl_FragColor.rgb = vec3(contrast);
}

View File

@ -1,20 +1,5 @@
#version 120 #version 120
//#extension GL_EXT_gpu_shader4 : disable
#include "/lib/settings.glsl"
varying vec2 texcoord; #define NETHER_SHADER
flat varying vec4 exposure;
uniform sampler2D colortex4;
//////////////////////////////VOID MAIN////////////////////////////// #include "/dimensions/final.vsh"
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
gl_Position = ftransform();
texcoord = gl_MultiTexCoord0.xy;
exposure=vec4(texelFetch2D(colortex4,ivec2(10,37),0).r*vec3(FinalR,FinalG,FinalB),texelFetch2D(colortex4,ivec2(10,37),0).r);
}

View File

@ -3,4 +3,7 @@
// #define ENTITIES // #define ENTITIES
#define BLOCKENTITIES #define BLOCKENTITIES
#define WORLD #define WORLD
#include "/programs/all_solid.fsh"
#define NETHER_SHADER
#include "/dimensions/all_solid.fsh"

View File

@ -5,4 +5,6 @@
#define BLOCKENTITIES #define BLOCKENTITIES
#define WORLD #define WORLD
#include "/programs/all_solid.vsh" #define NETHER_SHADER
#include "/dimensions/all_solid.vsh"

View File

@ -1,9 +1,10 @@
#version 120 #version 120
#include "/lib/settings.glsl"
varying vec4 color; varying vec4 lmtexcoord;
varying vec2 texcoord; varying vec2 texcoord;
varying vec4 color;
uniform sampler2D texture; uniform sampler2D texture;
//faster and actually more precise than pow 2.2 //faster and actually more precise than pow 2.2
@ -11,24 +12,6 @@ vec3 toLinear(vec3 sRGB){
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878); return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
} }
vec4 encode (vec3 n, vec2 lightmaps){
n.xy = n.xy / dot(abs(n), vec3(1.0));
n.xy = n.z <= 0.0 ? (1.0 - abs(n.yx)) * sign(n.xy) : n.xy;
vec2 encn = clamp(n.xy * 0.5 + 0.5,-1.0,1.0);
return vec4(encn,vec2(lightmaps.x,lightmaps.y));
}
//encoding by jodie
float encodeVec2(vec2 a){
const vec2 constant1 = vec2( 1., 256.) / 65535.;
vec2 temp = floor( a * 255. );
return temp.x*constant1.x+temp.y*constant1.y;
}
float encodeVec2(float x,float y){
return encodeVec2(vec2(x,y));
}
//////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN//////////////////////////////
@ -38,10 +21,9 @@ float encodeVec2(float x,float y){
void main() { void main() {
vec4 Albedo = vec4(texture2D(texture, texcoord).rgb*5.0,1.0); vec4 Albedo = texture2D(texture, texcoord.xy) * color * 1.5;
Albedo *= color;
Albedo.rgb = toLinear(Albedo.rgb); gl_FragData[0] = vec4(toLinear(Albedo.rgb), 1.0);
gl_FragData[1] = vec4(0.0, 0.0, 0.0, 0.5);
gl_FragData[0] = Albedo; }
gl_FragData[1] = vec4(0.0,0.0,0.0,0.9);
}

View File

@ -33,15 +33,11 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
void main() { void main() {
gl_Position = ftransform(); gl_Position = ftransform();
if(gl_Color.a < 1.0 ) gl_Position = vec4(10,10,10,1); if(gl_Color.a < 1.0 ) gl_Position = vec4(10,10,10,1);
texcoord = (gl_MultiTexCoord0).xy; texcoord = (gl_MultiTexCoord0).xy;
color = gl_Color; color = gl_Color;
#ifdef TAA_UPSCALING
gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w;
#endif
#ifdef TAA #ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize; gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif #endif

View File

@ -3,4 +3,6 @@
#define WORLD #define WORLD
#define BLOCKENTITIES #define BLOCKENTITIES
#include "/programs/all_solid.fsh" #define NETHER_SHADER
#include "/dimensions/all_solid.fsh"

View File

@ -2,4 +2,7 @@
#define WORLD #define WORLD
#define BLOCKENTITIES #define BLOCKENTITIES
#include "/programs/all_solid.vsh"
#define NETHER_SHADER
#include "/dimensions/all_solid.vsh"

View File

@ -3,4 +3,6 @@
#define WORLD #define WORLD
#define ENTITIES #define ENTITIES
#include "/programs/all_solid.fsh" #define NETHER_SHADER
#include "/dimensions/all_solid.fsh"

View File

@ -4,4 +4,6 @@
// #define WORLD // #define WORLD
#define ENTITIES #define ENTITIES
#include "/programs/all_solid.vsh" #define NETHER_SHADER
#include "/dimensions/all_solid.vsh"

View File

@ -2,4 +2,7 @@
#define WORLD #define WORLD
#define HAND #define HAND
#include "/programs/all_solid.fsh"
#define NETHER_SHADER
#include "/dimensions/all_solid.fsh"

View File

@ -3,4 +3,6 @@
#define WORLD #define WORLD
#define HAND #define HAND
#include "/programs/all_solid.vsh" #define NETHER_SHADER
#include "/dimensions/all_solid.vsh"

View File

@ -1,3 +1,7 @@
#version 120 #version 120
#include "/programs/all_translucent.fsh" #define NETHER
#define NETHER_SHADER
#include "/dimensions/all_translucent.fsh"

View File

@ -1,3 +1,7 @@
#version 120 #version 120
#include "/programs/all_translucent.vsh" #define NETHER
#define NETHER_SHADER
#include "/dimensions/all_translucent.vsh"

View File

@ -1,9 +1,7 @@
#version 120 #version 120
/* DRAWBUFFERS:3 */ /* RENDERTARGETS:0 */
void main() { void main() {
discard;
} }

View File

@ -1,14 +1,5 @@
#version 120 #version 120
//#extension GL_EXT_gpu_shader4 : disable
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() { void main() {
gl_Position = ftransform();
gl_Position.w = -1.0;
} }

View File

@ -1,24 +1,7 @@
#version 120 #version 120
/* /* RENDERTARGETS:0 */
!! DO NOT REMOVE !!
This code is from Chocapic13' shaders
Read the terms of modification and sharing before changing something below please !
!! DO NOT REMOVE !!
*/
/* DRAWBUFFERS:1 */
varying vec4 color;
varying vec2 texcoord;
//faster and actually more precise than pow 2.2
vec3 toLinear(vec3 sRGB){
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
}
uniform sampler2D texture;
void main() { void main() {
discard;
gl_FragData[0] = texture2D(texture,texcoord.xy)*color;
gl_FragData[0].rgb = gl_FragData[0].rgb*gl_FragData[0].a;
} }

View File

@ -1,36 +1,5 @@
#version 120 #version 120
#define TAA
/*
!! DO NOT REMOVE !!
This code is from Chocapic13' shaders
Read the terms of modification and sharing before changing something below please !
!! DO NOT REMOVE !!
*/
varying vec4 color;
varying vec2 texcoord;
uniform vec2 texelSize;
uniform int framemod8;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
vec2(-3,-5.)/8.,
vec2(-5.,5.)/8.,
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
void main() { void main() {
texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).st;
color = gl_Color;
gl_Position = ftransform(); gl_Position = ftransform();
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
} }

View File

@ -1,9 +1,10 @@
#version 120 #version 120
#include "/lib/settings.glsl"
varying vec4 color; varying vec4 lmtexcoord;
varying vec2 texcoord; varying vec2 texcoord;
varying vec4 color;
uniform sampler2D texture; uniform sampler2D texture;
//faster and actually more precise than pow 2.2 //faster and actually more precise than pow 2.2
@ -11,24 +12,6 @@ vec3 toLinear(vec3 sRGB){
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878); return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
} }
vec4 encode (vec3 n, vec2 lightmaps){
n.xy = n.xy / dot(abs(n), vec3(1.0));
n.xy = n.z <= 0.0 ? (1.0 - abs(n.yx)) * sign(n.xy) : n.xy;
vec2 encn = clamp(n.xy * 0.5 + 0.5,-1.0,1.0);
return vec4(encn,vec2(lightmaps.x,lightmaps.y));
}
//encoding by jodie
float encodeVec2(vec2 a){
const vec2 constant1 = vec2( 1., 256.) / 65535.;
vec2 temp = floor( a * 255. );
return temp.x*constant1.x+temp.y*constant1.y;
}
float encodeVec2(float x,float y){
return encodeVec2(vec2(x,y));
}
//////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN//////////////////////////////
@ -38,12 +21,9 @@ float encodeVec2(float x,float y){
void main() { void main() {
vec4 Albedo = texture2D(texture, texcoord); vec4 Albedo = texture2D(texture, texcoord.xy) * color;
gl_FragData[0] = vec4(toLinear(Albedo.rgb), Albedo.a);
gl_FragData[1] = vec4(0.0, 0.0, 0.0, 0.5);
Albedo *= color; }
Albedo.rgb = toLinear(Albedo.rgb);
gl_FragData[0] = Albedo;
gl_FragData[1] = vec4(0.0,0.0,0.0,0.5);
}

View File

@ -34,14 +34,9 @@ void main() {
gl_Position = ftransform(); gl_Position = ftransform();
// if(gl_Color.a < 0.1 ) gl_Position = vec4(10,10,10,1);
texcoord = (gl_MultiTexCoord0).xy; texcoord = (gl_MultiTexCoord0).xy;
color = gl_Color; color = gl_Color;
#ifdef TAA_UPSCALING
gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w;
#endif
#ifdef TAA #ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize; gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif #endif

View File

@ -1,5 +1,7 @@
#version 120 #version 120
#define NETHER_SHADER
#define WORLD #define WORLD
#include "/programs/all_solid.fsh" #include "/dimensions/all_solid.fsh"

View File

@ -1,5 +1,7 @@
#version 120 #version 120
#define NETHER_SHADER
#define WORLD #define WORLD
#include "/programs/all_solid.vsh" #include "/dimensions/all_solid.vsh"

View File

@ -1,3 +1,6 @@
#version 120 #version 120
#include "/programs/all_particles.fsh"
#define NETHER_SHADER
#include "/dimensions/all_particles.fsh"

View File

@ -1,3 +1,6 @@
#version 120 #version 120
#include "/programs/all_particles.vsh"
#define NETHER_SHADER
#include "/dimensions/all_particles.vsh"

View File

@ -1,3 +1,5 @@
#version 120 #version 120
#include "/programs/all_particles.fsh" #define NETHER_SHADER
#include "/dimensions/all_particles.fsh"

View File

@ -2,4 +2,7 @@
// #define WEATHER // #define WEATHER
#define PARTICLES #define PARTICLES
#include "/programs/all_particles.vsh"
#define NETHER_SHADER
#include "/dimensions/all_particles.vsh"

View File

@ -1,4 +1,7 @@
#version 120 #version 120
#define NETHER #define NETHER
#include "/programs/all_translucent.fsh"
#define NETHER_SHADER
#include "/dimensions/all_translucent.fsh"

View File

@ -1,3 +1,7 @@
#version 120 #version 120
#include "/programs/all_translucent.vsh" #define NETHER
#define NETHER_SHADER
#include "/dimensions/all_translucent.vsh"

View File

@ -1,638 +1,5 @@
#version 120 #version 120
//#extension GL_EXT_gpu_shader4 : disable
#include "/lib/settings.glsl" #define END_SHADER
#define END #include "/dimensions/composite.fsh"
#include "/lib/diffuse_lighting.glsl"
varying vec2 texcoord;
flat varying vec3 avgAmbient;
flat varying vec2 TAA_Offset;
flat varying float tempOffsets;
const bool colortex5MipmapEnabled = true;
const bool colortex4MipmapEnabled = true;
uniform sampler2D colortex0;//clouds
uniform sampler2D colortex1;//albedo(rgb),material(alpha) RGBA16
uniform sampler2D colortex4;//Skybox
uniform sampler2D colortex3;
uniform sampler2D colortex7;
uniform sampler2D colortex5;
uniform sampler2D colortex2;
uniform sampler2D colortex8;
uniform sampler2D colortex10;
uniform sampler2D colortex15;
uniform sampler2D colortex6;//Skybox
uniform sampler2D depthtex1;//depth
uniform sampler2D depthtex0;//depth
uniform sampler2D noisetex;//depth
uniform int heldBlockLightValue;
uniform int frameCounter;
uniform int isEyeInWater;
uniform mat4 shadowModelViewInverse;
uniform mat4 shadowProjectionInverse;
uniform float far;
uniform float near;
uniform float frameTimeCounter;
uniform float rainStrength;
uniform mat4 gbufferProjection;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferModelViewInverse;
uniform mat4 shadowModelView;
uniform mat4 shadowProjection;
uniform mat4 gbufferModelView;
uniform mat4 gbufferPreviousModelView;
uniform mat4 gbufferPreviousProjection;
uniform vec3 previousCameraPosition;
uniform vec2 texelSize;
uniform float viewWidth;
uniform float viewHeight;
uniform float aspectRatio;
uniform vec3 cameraPosition;
uniform vec3 sunVec;
uniform ivec2 eyeBrightnessSmooth;
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
vec3 toScreenSpace(vec3 p) {
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
vec3 p3 = p * 2. - 1.;
vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
return fragposition.xyz / fragposition.w;
}
#include "/lib/color_transforms.glsl"
#include "/lib/waterBump.glsl"
#include "/lib/sky_gradient.glsl"
float ld(float dist) {
return (2.0 * near) / (far + near - dist * (far - near));
}
vec2 RENDER_SCALE = vec2(1.0);
#include "/lib/end_fog.glsl"
#undef LIGHTSOURCE_REFLECTION
#define ENDSPECULAR
#include "/lib/specular.glsl"
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;
dither = center*inversesqrt(abs(center));
return clamp(dither-fsign(center),0.0,1.0);
}
vec3 fp10Dither(vec3 color,float dither){
const vec3 mantissaBits = vec3(6.,6.,5.);
vec3 exponent = floor(log2(color));
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 );
}
vec3 decode (vec2 encn){
vec3 n = vec3(0.0);
encn = encn * 2.0 - 1.0;
n.xy = abs(encn);
n.z = 1.0 - n.x - n.y;
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 ;
}
// float linZ(float depth) {
// return (2.0 * near) / (far + near - depth * (far - near));
// // l = (2*n)/(f+n-d(f-n))
// // f+n-d(f-n) = 2n/l
// // -d(f-n) = ((2n/l)-f-n)
// // d = -((2n/l)-f-n)/(f-n)
// }
// float invLinZ (float lindepth){
// return -((2.0*near/lindepth)-far-near)/(far-near);
// }
// vec3 toClipSpace3(vec3 viewSpacePosition) {
// return projMAD(gbufferProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
// }
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(){
// 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 ;
}
vec2 R2_dither(){
vec2 alpha = vec2(0.75487765, 0.56984026);
return vec2(fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter), fract((1.0-alpha.x) * gl_FragCoord.x + (1.0-alpha.y) * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter));
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * (frameCounter*0.5+0.5) );
}
vec4 blueNoise(vec2 coord){
return texelFetch2D(colortex6, ivec2(coord)%512 , 0) ;
}
vec3 toShadowSpaceProjected(vec3 p3){
p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz;
p3 = mat3(shadowModelView) * p3 + shadowModelView[3].xyz;
p3 = diagonal3(shadowProjection) * p3 + shadowProjection[3].xyz;
return p3;
}
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;
}
float ssao(vec3 fragpos, float dither,vec3 normal)
{
float mulfov = 1.0;
ivec2 pos = ivec2(gl_FragCoord.xy);
const float tan70 = tan(70.*3.14/180.);
float mulfov2 = gbufferProjection[1][1]/tan70;
const float PI = 3.14159265;
const float samplingRadius = 0.712;
float angle_thresh = 0.05;
float rd = mulfov2*0.05;
//pre-rotate direction
float n = 0.;
float occlusion = 0.0;
vec2 acc = -vec2(TAA_Offset)*texelSize*0.5;
float mult = (dot(normal,normalize(fragpos))+1.0)*0.5+0.5;
vec2 v = fract(vec2(dither,interleaved_gradientNoise()) + (frameCounter%10000) * vec2(0.75487765, 0.56984026));
for (int j = 0; j < 7+2 ;j++) {
vec2 sp = tapLocation(j,v.x,7+2,2.,v.y);
vec2 sampleOffset = sp*rd;
ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight));
if (offset.x >= 0 && offset.y >= 0 && offset.x < viewWidth && offset.y < viewHeight ) {
vec3 t0 = toScreenSpace(vec3(offset*texelSize+acc+0.5*texelSize,texelFetch2D(depthtex1,offset,0).x));
vec3 vec = t0.xyz - fragpos;
float dsquared = dot(vec,vec);
if (dsquared > 1e-5){
if (dsquared < fragpos.z*fragpos.z*0.05*0.05*mulfov2*2.*1.412){
float NdotV = clamp(dot(vec*inversesqrt(dsquared), normalize(normal)),0.,1.);
occlusion += NdotV;
}
n += 1.0;
}
}
}
return clamp(1.0-occlusion/n*2.0,0.,1.0);
}
vec3 viewToWorld(vec3 viewPosition) {
vec4 pos;
pos.xyz = viewPosition;
pos.w = 0.0;
pos = gbufferModelViewInverse * pos;
return pos.xyz;
}
vec3 worldToView(vec3 worldPos) {
vec4 pos = vec4(worldPos, 0.0);
pos = gbufferModelView * pos;
return pos.xyz;
}
void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient){
inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value
int spCount = rayMarchSampleCount;
vec3 start = toShadowSpaceProjected(rayStart);
vec3 end = toShadowSpaceProjected(rayEnd);
vec3 dV = (end-start);
//limit ray length at 32 blocks for performance and reducing integration error
//you can't see above this anyway
float maxZ = min(rayLength,12.0)/(1e-8+rayLength);
dV *= maxZ;
vec3 dVWorld = -mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ;
rayLength *= maxZ;
float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength;
estEndDepth *= maxZ;
estSunDepth *= maxZ;
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
float expFactor = 11.0;
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition;
for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
vec3 spPos = start.xyz + dV*d;
progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
vec3 ambientMul = exp(-max(estEndDepth * d,0.0) * waterCoefs);
vec3 light = (ambientMul*ambient) * scatterCoef;
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs *absorbance;
absorbance *= exp(-dd * rayLength * waterCoefs);
}
inColor += vL;
}
void Emission(
inout vec3 Lighting,
vec3 Albedo,
float Emission
){
// if( Emission < 255.0/255.0 ) Lighting = mix(Lighting, Albedo * Emissive_Brightness, pow(Emission, Emissive_Curve)); // old method.... idk why
if( Emission < 255.0/255.0 ) Lighting += (Albedo * Emissive_Brightness * 0.25) * pow(Emission, Emissive_Curve);
}
float rayTraceShadow(vec3 dir,vec3 position,float dither){
const float quality = 16.;
vec3 clipPosition = toClipSpace3(position);
//prevents the ray from going behind the camera
float rayLength = ((position.z + dir.z * far*sqrt(3.)) > -near) ?
(-near -position.z) / dir.z : far*sqrt(3.) ;
vec3 direction = toClipSpace3(position+dir*rayLength)-clipPosition; //convert to clip space
direction.xyz = direction.xyz/max(abs(direction.x)/texelSize.x,abs(direction.y)/texelSize.y); //fixed step size
vec3 stepv = direction * 3.0 * clamp(MC_RENDER_QUALITY,1.,2.0);
vec3 spos = clipPosition;
spos += stepv*dither ;
for (int i = 0; i < int(quality); i++) {
spos += stepv;
float sp = texture2D(depthtex1,spos.xy).x;
if( sp < spos.z) {
float dist = abs(linZ(sp)-linZ(spos.z))/linZ(spos.z);
if (dist < 0.015 ) return i / quality;
}
}
return 1.0;
}
vec3 rayTrace_GI(vec3 dir,vec3 position,float dither, float quality){
vec3 clipPosition = toClipSpace3(position);
float rayLength = ((position.z + dir.z * far*sqrt(3.)) > -near) ?
(-near -position.z) / dir.z : far*sqrt(3.);
vec3 direction = normalize(toClipSpace3(position+dir*rayLength)-clipPosition); //convert to clip space
direction.xy = normalize(direction.xy);
//get at which length the ray intersects with the edge of the screen
vec3 maxLengths = (step(0.,direction)-clipPosition) / direction;
float mult = maxLengths.y;
vec3 stepv = direction * mult / quality*vec3(RENDER_SCALE,1.0) * dither;
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ;
spos.xy += TAA_Offset*texelSize*0.5/RENDER_SCALE;
float biasdist = clamp(position.z*position.z/50.0,1,2); // shrink sample size as distance increases
for(int i = 0; i < int(quality); i++){
spos += stepv;
float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0);
float currZ = linZ(spos.z);
if( sp < currZ) {
float dist = abs(sp-currZ)/currZ;
if (abs(dist) < biasdist*0.05) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0);
}
spos += stepv;
}
return vec3(1.1);
}
vec3 RT(vec3 dir, vec3 position, float noise, float stepsizes){
float dist = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases
float stepSize = stepsizes / dist;
int maxSteps = STEPS;
vec3 clipPosition = toClipSpace3(position);
float rayLength = ((position.z + dir.z * sqrt(3.0)*far) > -sqrt(3.0)*near) ?
(-sqrt(3.0)*near -position.z) / dir.z : sqrt(3.0)*far;
vec3 end = toClipSpace3(position+dir*rayLength) ;
vec3 direction = end-clipPosition ; //convert to clip space
float len = max(abs(direction.x)/texelSize.x,abs(direction.y)/texelSize.y)/stepSize;
//get at which length the ray intersects with the edge of the screen
vec3 maxLengths = (step(0.,direction)-clipPosition) / direction;
float mult = min(min(maxLengths.x,maxLengths.y),maxLengths.z)*2000.0;
vec3 stepv = direction/len;
int iterations = min(int(min(len, mult*len)-2), maxSteps);
//Do one iteration for closest texel (good contact shadows)
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ;
spos.xy += TAA_Offset*texelSize*0.5*RENDER_SCALE;
spos += stepv/(stepSize/2);
float distancered = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases
for(int i = 0; i < iterations; i++){
if (spos.x < 0.0 || spos.y < 0.0 || spos.z < 0.0 || spos.x > 1.0 || spos.y > 1.0 || spos.z > 1.0) return vec3(1.1);
spos += stepv*noise;
float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/ texelSize/4),0).w/65000.0);
float currZ = linZ(spos.z);
if( sp < currZ) {
float dist = abs(sp-currZ)/currZ;
if (dist <= 0.1) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0);
}
}
return vec3(1.1);
}
vec3 cosineHemisphereSample(vec2 Xi, float roughness){
float r = sqrt(Xi.x);
float theta = 2.0 * 3.14159265359 * Xi.y;
float x = r * cos(theta);
float y = r * sin(theta);
return vec3(x, y, sqrt(clamp(1.0 - Xi.x,0.,1.)));
}
vec3 TangentToWorld(vec3 N, vec3 H, float roughness){
vec3 UpVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
vec3 T = normalize(cross(UpVector, N));
vec3 B = cross(N, T);
return vec3((T * H.x) + (B * H.y) + (N * H.z));
}
vec2 R2_samples(int n){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha * n);
}
void ApplySSRT(inout vec3 lighting, vec3 normal,vec2 noise,vec3 fragpos, float lightmaps, vec3 torchcolor){
int nrays = RAY_COUNT;
vec3 radiance = vec3(0.0);
vec3 occlusion = vec3(0.0);
vec3 skycontribution = vec3(0.0);
// float skyLM = 0.0;
// vec3 torchlight = vec3(0.0);
// vec3 blank = vec3(0.0);
// DoRTAmbientLighting(torchcolor, vec2(lightmaps,1.0), skyLM, torchlight, blank);
for (int i = 0; i < nrays; i++){
int seed = (frameCounter%40000)*nrays+i;
vec2 ij = fract(R2_samples(seed) + noise );
vec3 rayDir = TangentToWorld(normal, normalize(cosineHemisphereSample(ij,1.0)) ,1.0);
#ifdef HQ_SSGI
vec3 rayHit = rayTrace_GI( mat3(gbufferModelView) * rayDir, fragpos, blueNoise(), 50.); // ssr rt
#else
vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, fragpos, blueNoise(), 30.); // choc sspt
#endif
skycontribution = lighting;
if (rayHit.z < 1.){
#if indirect_effect == 4
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rayHit) + 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){
radiance += (texture2D(colortex5,previousPosition.xy).rgb + skycontribution) * GI_Strength;
}else{
radiance += skycontribution;
}
#else
radiance += skycontribution;
#endif
occlusion += skycontribution * GI_Strength;
} else {
radiance += skycontribution;
}
}
occlusion *= AO_Strength;
lighting = max(radiance/nrays - occlusion/nrays, 0.0);
}
void main() {
float dirtAmount = Dirt_Amount;
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;
vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
float z0 = texture2D(depthtex0,texcoord).x;
float z = texture2D(depthtex1,texcoord).x;
vec2 tempOffset=TAA_Offset;
float noise = blueNoise();
vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(tempOffset)*texelSize*0.5,z));
vec3 p3 = mat3(gbufferModelViewInverse) * fragpos;
vec3 np3 = normVec(p3);
////// --------------- UNPACK OPAQUE GBUFFERS --------------- //////
vec4 data = texture2D(colortex1,texcoord);
vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y)); // albedo, masks
vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w)); // normals, lightmaps
// vec4 dataUnpacked2 = vec4(decodeVec2(data.z),decodeVec2(data.w));
vec3 albedo = toLinear(vec3(dataUnpacked0.xz,dataUnpacked1.x));
vec2 lightmap = dataUnpacked1.yz;
vec3 normal = decode(dataUnpacked0.yw);
////// --------------- UNPACK MISC --------------- //////
vec4 SpecularTex = texture2D(colortex8,texcoord);
float LabSSS = clamp((-65.0 + SpecularTex.z * 255.0) / 190.0 ,0.0,1.0);
vec4 normalAndAO = texture2D(colortex15,texcoord);
vec3 FlatNormals = normalAndAO.rgb * 2.0 - 1.0;
vec3 slopednormal = normal;
#ifdef POM
#ifdef Horrible_slope_normals
vec3 ApproximatedFlatNormal = normalize(cross(dFdx(p3), dFdy(p3))); // it uses depth that has POM written to it.
slopednormal = normalize(clamp(normal, ApproximatedFlatNormal*2.0 - 1.0, ApproximatedFlatNormal*2.0 + 1.0) );
#endif
#endif
float vanilla_AO = clamp(normalAndAO.a,0,1);
normalAndAO.a = clamp(pow(normalAndAO.a*5,4),0,1);
bool iswater = texture2D(colortex7,texcoord).a > 0.99;
bool lightningBolt = abs(dataUnpacked1.w-0.5) <0.01;
bool isLeaf = abs(dataUnpacked1.w-0.55) <0.01;
bool entities = abs(dataUnpacked1.w-0.45) < 0.01;
bool hand = abs(dataUnpacked1.w-0.75) < 0.01;
// bool blocklights = abs(dataUnpacked1.w-0.8) <0.01;
if (z >= 1.0) {
gl_FragData[0].rgb = vec3(0.0);
} else {
p3 += gbufferModelViewInverse[3].xyz;
// do all ambient lighting stuff
vec3 Indirect_lighting = DoAmbientLighting_End(gl_Fog.color.rgb, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.x, normal, np3);
vec3 LightColor = LightSourceColor(clamp(sqrt(length(p3+cameraPosition) / 150.0 - 1.0) ,0.0,1.0));
vec3 LightPos = LightSourcePosition(p3+cameraPosition, cameraPosition);
float LightFalloff = max(exp2(4.0 + length(LightPos) / -25),0.0);
float NdotL = clamp( dot(normal,normalize(-LightPos)),0.0,1.0);
NdotL = clamp((-15 + NdotL*255.0) / 240.0 ,0.0,1.0);
float fogshadow = GetCloudShadow(p3+cameraPosition, LightPos, blueNoise());
vec3 LightSource = (LightColor * max(LightColor - (1-fogshadow) ,0.0)) * LightFalloff * NdotL;
// vec3 LightSource = LightColor * fogshadow * LightFalloff * NdotL ;
float LightFalloff2 = max(1.0-length(LightPos)/120,0.0);
LightFalloff2 = pow(1.0-pow(1.0-LightFalloff2,0.5),2.0);
LightFalloff2 *= 25;
LightSource += (LightColor * max(LightColor - 0.6,0.0)) * vec3(1.0,1.3,1.0) * LightFalloff2 * (NdotL*0.7+0.3);
// float RT_Shadows = rayTraceShadow(worldToView(normalize(-LightPos)), fragpos_RTSHADOW, blueNoise());
// if(!hand) LightSource *= RT_Shadows*RT_Shadows;
#if indirect_effect == 0
vec3 AO = vec3( exp( (vanilla_AO*vanilla_AO) * -5) ) ;
if(!hand) Indirect_lighting *= AO;
#endif
#if indirect_effect == 1
vec3 AO = vec3( exp( (vanilla_AO*vanilla_AO) * -5) ) ;
if(!hand) Indirect_lighting *= ssao(fragpos,noise,FlatNormals) * AO;
#endif
// RTAO and/or SSGI
#if indirect_effect == 3 || indirect_effect == 4
if (!hand) ApplySSRT(Indirect_lighting, normal, blueNoise(gl_FragCoord.xy).rg, fragpos, lightmap.x,vec3(TORCH_R,TORCH_G,TORCH_B));
#endif
// finalize
gl_FragData[0].rgb = (Indirect_lighting + LightSource) * albedo;
// #ifdef Specular_Reflections
// MaterialReflections_E(gl_FragData[0].rgb, SpecularTex.r, SpecularTex.ggg, albedo, normal, np3, fragpos, vec3(blueNoise(gl_FragCoord.xy).rg,noise), hand, LightColor * LightFalloff, normalize(-LightPos), entities);
// #endif
#ifdef Specular_Reflections
vec3 specNoise = vec3(blueNoise(gl_FragCoord.xy).rg, interleaved_gradientNoise());
DoSpecularReflections(gl_FragData[0].rgb, fragpos, np3, vec3(0.0), specNoise, normal, SpecularTex.r, SpecularTex.g, albedo, vec3(0.0), 1.0, hand);
#endif
Emission(gl_FragData[0].rgb, albedo, SpecularTex.a);
if(lightningBolt) gl_FragData[0].rgb = LightColor * 10 ;
}
if (iswater && isEyeInWater == 0){
vec3 fragpos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0));
float Vdiff = distance(fragpos,fragpos0);
float VdotU = np3.y;
float estimatedDepth = Vdiff * abs(VdotU) ; //assuming water plane
vec3 ambientColVol = max(vec3(1.0,0.5,1.0) * 0.3, vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.01 + nightVision));
waterVolumetrics(gl_FragData[0].rgb, fragpos0, fragpos, estimatedDepth , estimatedDepth, Vdiff, noise, totEpsilon, scatterCoef, ambientColVol);
}
/* DRAWBUFFERS:3 */
}

View File

@ -1,51 +1,5 @@
#version 120 #version 120
//#extension GL_EXT_gpu_shader4 : disable
#include "/lib/settings.glsl" #define END_SHADER
varying vec2 texcoord; #include "/dimensions/composite.vsh"
flat varying vec3 avgAmbient;
flat varying float tempOffsets;
flat varying vec2 TAA_Offset;
flat varying vec3 zMults;
uniform sampler2D colortex4;
uniform float far;
uniform float near;
uniform mat4 gbufferModelViewInverse;
uniform vec3 sunPosition;
uniform float rainStrength;
uniform float sunElevation;
uniform int frameCounter;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
vec2(-3,-5.)/8.,
vec2(-5.,5.)/8.,
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
#include "/lib/util.glsl"
void main() {
gl_Position = ftransform();
texcoord = gl_MultiTexCoord0.xy;
tempOffsets = HaltonSeq2(frameCounter%10000);
TAA_Offset = offsets[frameCounter%8];
#ifndef TAA
TAA_Offset = vec2(0.0);
#endif
avgAmbient = texelFetch2D(colortex4,ivec2(0,37),0).rgb;
zMults = vec3((far * near)*2.0,far+near,far-near);
}

View File

@ -0,0 +1,5 @@
#version 120
#define END_SHADER
#include "/dimensions/composite1.fsh"

View File

@ -0,0 +1,5 @@
#version 120
#define END_SHADER
#include "/dimensions/composite1.vsh"

View File

@ -1,141 +1,5 @@
#version 120 #version 120
//Volumetric fog rendering
//#extension GL_EXT_gpu_shader4 : disable
#include "/lib/settings.glsl" #define END_SHADER
flat varying vec4 lightCol; #include "/dimensions/composite2.fsh"
// flat varying vec3 ambientUp;
// flat varying vec3 ambientLeft;
// flat varying vec3 ambientRight;
// flat varying vec3 ambientB;
// flat varying vec3 ambientF;
// flat varying vec3 ambientDown;
flat varying vec2 TAA_Offset;
flat varying float tempOffsets;
flat varying float fogAmount;
flat varying float VFAmount;
uniform sampler2D noisetex;
uniform sampler2D depthtex0;
uniform sampler2D colortex2;
uniform sampler2D colortex3;
// uniform sampler2D colortex4;
uniform vec3 sunVec;
uniform float far;
uniform int frameCounter;
uniform float rainStrength;
uniform float sunElevation;
uniform ivec2 eyeBrightnessSmooth;
uniform float frameTimeCounter;
uniform int isEyeInWater;
uniform vec2 texelSize;
#include "/lib/color_transforms.glsl"
#include "/lib/color_dither.glsl"
#include "/lib/projections.glsl"
#include "/lib/end_fog.glsl"
#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.)
float interleaved_gradientNoise(){
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+tempOffsets);
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient){
inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value
int spCount = rayMarchSampleCount;
vec3 start = toShadowSpaceProjected(rayStart);
vec3 end = toShadowSpaceProjected(rayEnd);
vec3 dV = (end-start);
//limit ray length at 32 blocks for performance and reducing integration error
//you can't see above this anyway
float maxZ = min(rayLength,12.0)/(1e-8+rayLength);
dV *= maxZ;
rayLength *= maxZ;
float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength;
estEndDepth *= maxZ;
estSunDepth *= maxZ;
vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz;
vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
float expFactor = 11.0;
for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
vec3 spPos = start.xyz + dV*d;
vec3 progressW = start.xyz+cameraPosition+dVWorld;
vec3 ambientMul = exp(-max(estEndDepth * d,0.0) * waterCoefs );
vec3 Indirectlight = ambientMul*ambient;
vec3 light = Indirectlight * scatterCoef;
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
absorbance *= exp(-dd * rayLength * waterCoefs);
}
inColor += vL;
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
varying vec2 texcoord;
void main() {
/* DRAWBUFFERS:0 */
vec2 tc = floor(gl_FragCoord.xy)*2.0*texelSize+0.5*texelSize;
float z = texture2D(depthtex0,tc).x;
vec3 fragpos = toScreenSpace(vec3(tc,z));
if (isEyeInWater == 0){
vec3 fragpos_ALT = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z));
float noise = blueNoise();
mat2x3 vl = getVolumetricRays(noise,fragpos, interleaved_gradientNoise());
float absorbance = dot(vl[1],vec3(0.22,0.71,0.07));
gl_FragData[0] = clamp(vec4(vl[0],absorbance),0.000001,65000.);
} else {
float dirtAmount = Dirt_Amount;
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;
vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
vec3 fragpos0 = toScreenSpace(vec3(texcoord - TAA_Offset*texelSize*0.5,z));
vec3 ambientColVol = max(vec3(1.0,0.5,1.0) * 0.6, vec3(0.2,0.4,1.0) * MIN_LIGHT_AMOUNT*0.01);
gl_FragData[0].a = 1;
waterVolumetrics(gl_FragData[0].rgb, fragpos0, fragpos, 1 , 1, 1, blueNoise(), totEpsilon, scatterCoef, ambientColVol);
}
}

View File

@ -1,22 +1,5 @@
#version 120 #version 120
//#extension GL_EXT_gpu_shader4 : disable
flat varying float tempOffsets; #define END_SHADER
uniform int frameCounter; #include "/dimensions/composite2.vsh"
#include "/lib/util.glsl"
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
gl_Position = ftransform();
tempOffsets = HaltonSeq2(frameCounter%10000);
gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.51*2.0-1.0;
}

View File

@ -1,308 +1,5 @@
#version 120 #version 120
//Horizontal bilateral blur for volumetric fog + Forward rendered objects + Draw volumetric fog
//#extension GL_EXT_gpu_shader4 : disable
#include "/lib/settings.glsl"
flat varying vec3 zMults; #define END_SHADER
flat varying vec2 TAA_Offset;
#include "/dimensions/composite3.fsh"
uniform sampler2D noisetex;
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
uniform sampler2D colortex0;
uniform sampler2D colortex1;
uniform sampler2D colortex2;
uniform sampler2D colortex3;
// uniform sampler2D colortex4;
uniform sampler2D colortex5;
uniform sampler2D colortex6;
uniform sampler2D colortex7;
uniform sampler2D colortex8;
uniform sampler2D colortex9;
uniform sampler2D colortex11;
uniform sampler2D colortex13;
uniform sampler2D colortex15;
uniform vec2 texelSize;
flat varying vec3 noooormal;
flat varying vec4 lightCol; //main light source color (rgb),used light source(1=sun,-1=moon)
flat varying vec3 WsunVec;
uniform vec3 sunVec;
uniform float frameTimeCounter;
uniform int frameCounter;
uniform float far;
uniform float near;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferModelView;
uniform mat4 gbufferPreviousModelView;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferProjection;
uniform mat4 gbufferPreviousProjection;
uniform vec3 cameraPosition;
uniform vec3 previousCameraPosition;
uniform int isEyeInWater;
uniform ivec2 eyeBrightnessSmooth;
uniform float rainStrength;
uniform float blindness;
uniform float darknessFactor;
uniform float darknessLightFactor;
#include "/lib/waterBump.glsl"
#include "/lib/res_params.glsl"
#include "/lib/sky_gradient.glsl"
#include "/lib/volumetricClouds.glsl"
// #include "/lib/biome_specifics.glsl"
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
float ld(float depth) {
return 1.0 / (zMults.y - depth * zMults.z); // (-depth * (far - near)) = (2.0 * near)/ld - far - near
}
float luma(vec3 color) {
return dot(color,vec3(0.21, 0.72, 0.07));
}
vec3 toLinear(vec3 sRGB){
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
}
vec3 toScreenSpace(vec3 p) {
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
vec3 p3 = p * 2. - 1.;
vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
return fragposition.xyz / fragposition.w;
}
// #include "/lib/specular.glsl"
vec4 BilateralUpscale(sampler2D tex, sampler2D depth,vec2 coord,float frDepth, vec2 distort){
coord = coord;
vec4 vl = vec4(0.0);
float sum = 0.0;
mat3x3 weights;
const ivec2 scaling = ivec2(1.0/VL_RENDER_RESOLUTION);
ivec2 posD = ivec2(coord*VL_RENDER_RESOLUTION + distort)*scaling;
ivec2 posVl = ivec2(coord*VL_RENDER_RESOLUTION + distort);
float dz = zMults.x;
ivec2 pos = (ivec2(gl_FragCoord.xy+frameCounter) % 2 )*2;
ivec2 tcDepth = posD + ivec2(-2,-2) * scaling + pos * scaling;
float dsample = ld(texelFetch2D(depth,tcDepth,0).r);
float w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
vl += texelFetch2D(tex,posVl+ivec2(-2)+pos,0)*w;
sum += w;
tcDepth = posD + ivec2(-2,0) * scaling + pos * scaling;
dsample = ld(texelFetch2D(depth,tcDepth,0).r);
w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
vl += texelFetch2D(tex,posVl+ivec2(-2,0)+pos,0)*w;
sum += w;
tcDepth = posD + ivec2(0) + pos * scaling;
dsample = ld(texelFetch2D(depth,tcDepth,0).r);
w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
vl += texelFetch2D(tex,posVl+ivec2(0)+pos,0)*w;
sum += w;
tcDepth = posD + ivec2(0,-2) * scaling + pos * scaling;
dsample = ld(texelFetch2D(depth,tcDepth,0).r);
w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
vl += texelFetch2D(tex,posVl+ivec2(0,-2)+pos,0)*w;
sum += w;
return vl/sum;
}
vec3 decode (vec2 encn){
vec3 n = vec3(0.0);
encn = encn * 2.0 - 1.0;
n.xy = abs(encn);
n.z = 1.0 - n.x - n.y;
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 ;
}
vec3 worldToView(vec3 worldPos) {
vec4 pos = vec4(worldPos, 0.0);
pos = gbufferModelView * pos;
return pos.xyz;
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
vec4 blueNoise(vec2 coord){
return texelFetch2D(colortex6, ivec2(coord )%512 , 0);
}
vec3 normVec (vec3 vec){
return vec*inversesqrt(dot(vec,vec));
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
vec3 viewToWorld(vec3 viewPosition) {
vec4 pos;
pos.xyz = viewPosition;
pos.w = 0.0;
pos = gbufferModelViewInverse * pos;
return pos.xyz;
}
/// thanks stackoverflow https://stackoverflow.com/questions/944713/help-with-pixel-shader-effect-for-brightness-and-contrast#3027595
void applyContrast(inout vec3 color, float contrast){
color = ((color - 0.5) * max(contrast, 0.0)) + 0.5;
}
void main() {
/* DRAWBUFFERS:73 */
vec2 texcoord = gl_FragCoord.xy*texelSize;
vec4 trpData = texture2D(colortex7,texcoord);
bool iswater = trpData.a > 0.99;
float translucentAlpha = trpData.a;
// vec4 speculartex = texture2D(colortex8,texcoord); // translucents
// float sunlight = speculartex.b;
//3x3 bilateral upscale from half resolution
float z = texture2D(depthtex0,texcoord).x;
float z2 = texture2D(depthtex1,texcoord).x;
float frDepth = ld(z2);
// vec4 vl = texture2D(colortex0,texcoord * 0.5);
////// --------------- UNPACK OPAQUE GBUFFERS --------------- //////
vec4 data_opaque = texture2D(colortex1,texcoord);
vec4 dataUnpacked1 = vec4(decodeVec2(data_opaque.z),decodeVec2(data_opaque.w)); // normals, lightmaps
// vec4 dataUnpacked2 = vec4(decodeVec2(data.z),decodeVec2(data.w));
bool hand = abs(dataUnpacked1.w-0.75) < 0.01;
vec2 lightmap = dataUnpacked1.yz;
////// --------------- UNPACK TRANSLUCENT GBUFFERS --------------- //////
vec3 data = texture2D(colortex11,texcoord).rgb;
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.0) tangentNormals = vec2(0.0);
vec4 TranslucentShader = texture2D(colortex2,texcoord);
float lightleakfix = clamp(pow(eyeBrightnessSmooth.y/240.,2) ,0.0,1.0);
vec2 tempOffset = TAA_Offset;
vec3 fragpos = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z));
vec3 fragpos2 = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z2));
vec3 p3 = mat3(gbufferModelViewInverse) * fragpos;
vec3 np3 = normVec(p3);
vec2 refractedCoord = texcoord;
/// --- REFRACTION --- ///
#ifdef Refraction
refractedCoord += (tangentNormals * clamp((ld(z2) - ld(z)) * 0.5,0.0,0.15)) * RENDER_SCALE;
// refractedCoord += tangentNormals * 0.1 * RENDER_SCALE;
float refractedalpha = decodeVec2(texture2D(colortex11,refractedCoord).b).g;
float refractedalpha2 = texture2D(colortex7,refractedCoord).a;
if( refractedalpha <= 0.001 ||z < 0.56) refractedCoord = texcoord; // remove refracted coords on solids
#endif
/// --- MAIN COLOR BUFFER --- ///
// it is sampled with distorted texcoords
vec3 color = texture2D(colortex3,refractedCoord).rgb;
vec4 vl = BilateralUpscale(colortex0, depthtex1, gl_FragCoord.xy, frDepth, vec2(0.0));
float bloomyFogMult = 1.0;
if (TranslucentShader.a > 0.0){
#ifdef Glass_Tint
if(albedo.a > 0.2) color = color*albedo.rgb + color * clamp(pow(1.0-luma(albedo.rgb),20.),0.0,1.0);
#endif
color = color*(1.0-TranslucentShader.a) + TranslucentShader.rgb;
}
// underwater fog
if (isEyeInWater == 1){
float dirtAmount = Dirt_Amount;
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;
// float fogfade = clamp( exp(length(fragpos) / -20) ,0.0,1.0);
// vec3 fogfade = clamp( exp( (length(fragpos) / -4) * totEpsilon ) ,0.0,1.0);
vec3 fogfade = clamp( exp( (-length(fragpos)) * totEpsilon ) ,0.0,1.0);
fogfade *= 1.0 - clamp( length(fragpos) / far,0.0,1.0);
color.rgb *= fogfade ;
bloomyFogMult *= 0.4;
}
// apply VL fog to the scene
color *= vl.a;
color += vl.rgb;
// bloomy rain effect
float rainDrops = clamp(texture2D(colortex9,texcoord).a, 0.0,1.0);
if(rainDrops > 0.0) bloomyFogMult *= clamp(1.0 - pow(rainDrops*5.0,2),0.0,1.0);
/// lava.
if (isEyeInWater == 2){
color.rgb = vec3(4.0,0.5,0.1);
}
/// powdered snow
if (isEyeInWater == 3){
color.rgb = mix(color.rgb,vec3(10,15,20),clamp(length(fragpos)*0.5,0.,1.));
bloomyFogMult = 0.0;
}
// blidnesss
color.rgb *= mix(1.0,clamp( exp(pow(length(fragpos)*(blindness*0.2),2) * -1),0.,1.) , blindness);
// darkness effect
color.rgb *= mix(1.0, (1.0-darknessLightFactor*2.0) * clamp(1.0-pow(length(fragpos2)*(darknessFactor*0.07),2.0),0.0,1.0), darknessFactor);
#ifdef display_LUT
vec2 movedTC = texcoord;
vec3 thingy = texture2D(colortex4,movedTC).rgb / 150. * 5.0;
if(luma(thingy) > 0.0 ) color.rgb = thingy;
#endif
gl_FragData[0].r = vl.a * bloomyFogMult; // pass fog alpha so bloom can do bloomy fog
gl_FragData[1].rgb = clamp(color.rgb,0.0,68000.0);
}

View File

@ -1,19 +1,5 @@
#version 120 #version 120
//#extension GL_EXT_gpu_shader4 : disable
varying vec2 texcoord; #define END_SHADER
flat varying vec3 zMults;
uniform float far;
uniform float near;
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() { #include "/dimensions/composite3.vsh"
zMults = vec3(1.0/(far * near),far+near,far-near);
gl_Position = ftransform();
texcoord = gl_MultiTexCoord0.xy;
}

Some files were not shown because too many files have changed in this diff Show More