mirror of
https://github.com/X0nk/Bliss-Shader.git
synced 2025-06-22 00:37:35 +08:00
INTERNAL REWORK. testers are needed.
This commit is contained in:
@ -1,350 +1,347 @@
|
||||
#include "/lib/settings.glsl"
|
||||
|
||||
const int noiseTextureResolution = 32;
|
||||
flat varying vec3 zMults;
|
||||
flat varying vec2 TAA_Offset;
|
||||
|
||||
|
||||
/*
|
||||
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 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 framemod8;
|
||||
uniform float viewHeight;
|
||||
uniform float viewWidth;
|
||||
uniform vec3 previousCameraPosition;
|
||||
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"
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
#include "/lib/sky_gradient.glsl"
|
||||
#include "/lib/lightning_stuff.glsl"
|
||||
#include "/lib/volumetricClouds.glsl"
|
||||
#endif
|
||||
#ifndef OVERWORLD_SHADER
|
||||
#include "/lib/climate_settings.glsl"
|
||||
#endif
|
||||
|
||||
|
||||
#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.)
|
||||
|
||||
#include "/lib/projections.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){
|
||||
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)*scaling;
|
||||
ivec2 posVl = ivec2(coord*VL_RENDER_RESOLUTION);
|
||||
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(){
|
||||
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+tempOffsets);
|
||||
vec2 coord = gl_FragCoord.xy;
|
||||
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
|
||||
return noise;
|
||||
}
|
||||
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);
|
||||
vec3 viewToWorld(vec3 viewPosition) {
|
||||
vec4 pos;
|
||||
pos.xyz = viewPosition;
|
||||
pos.w = 0.0;
|
||||
pos = gbufferModelViewInverse * pos;
|
||||
return pos.xyz;
|
||||
}
|
||||
|
||||
|
||||
//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;
|
||||
/// 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;
|
||||
}
|
||||
|
||||
//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:73 */
|
||||
|
||||
/* DRAWBUFFERS:5 */
|
||||
gl_FragData[0].a = 1.0;
|
||||
vec2 texcoord = gl_FragCoord.xy*texelSize;
|
||||
|
||||
#ifdef TAA
|
||||
vec3 color = TAA_hq();
|
||||
gl_FragData[0].rgb = clamp(fp10Dither(color,triangularize(interleaved_gradientNoise())),6.11*1e-5,65000.0);
|
||||
#endif
|
||||
vec4 trpData = texture2D(colortex7,texcoord);
|
||||
|
||||
#ifndef TAA
|
||||
vec3 color = clamp(fp10Dither(texture2D(colortex3,texcoord).rgb,triangularize(interleaved_gradientNoise())),0.,65000.);
|
||||
gl_FragData[0].rgb = color;
|
||||
#endif
|
||||
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);
|
||||
|
||||
|
||||
|
||||
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;
|
||||
|
||||
float lightleakfix = clamp(pow(eyeBrightnessSmooth.y/240.,2) ,0.0,1.0);
|
||||
|
||||
#if defined OVERWORLD_SHADER && defined BorderFog
|
||||
vec3 sky = skyFromTex(np3,colortex4) / 150. * 5.0;
|
||||
float fog = 1.0 - clamp(exp(-pow(length(fragpos / far),10.)*4.0) ,0.0,1.0);
|
||||
float heightFalloff = clamp( pow(abs(np3.y-1.01),5) ,0,1) ;
|
||||
|
||||
if(z < 1.0 && isEyeInWater == 0) color.rgb = mix(color.rgb, sky, fog * heightFalloff * lightleakfix);
|
||||
#endif
|
||||
|
||||
vec4 vl = BilateralUpscale(colortex0, depthtex1, gl_FragCoord.xy, frDepth);
|
||||
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;
|
||||
|
||||
#ifdef BorderFog
|
||||
if(z < 1.0 && isEyeInWater == 0) color.rgb = mix(color.rgb, sky, fog * heightFalloff * lightleakfix);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
#ifdef Cave_fog
|
||||
if (isEyeInWater == 0){
|
||||
|
||||
float fogdistfade = clamp( pow(length(fragpos) / far, CaveFogFallOff) ,0.0,1.0);
|
||||
|
||||
fogdistfade = fogdistfade*0.95 + clamp( pow(1.0 - exp((length(fragpos) / far) * -5), 2.0) ,0.0,1.0)*0.05;
|
||||
float fogfade = clamp( exp(clamp(np3.y * 0.5 + 0.5,0,1) * -3.0) ,0.0,1.0);
|
||||
|
||||
vec3 cavefogCol = vec3(CaveFogColor_R,CaveFogColor_G,CaveFogColor_B);
|
||||
|
||||
#ifdef PER_BIOME_ENVIRONMENT
|
||||
BiomeFogColor(cavefogCol);
|
||||
#endif
|
||||
|
||||
color.rgb = mix(color.rgb, cavefogCol*fogfade, fogdistfade * (1.0-lightleakfix) * (1.0-darknessFactor) * clamp( 1.5 - np3.y,0.,1)) ;
|
||||
// color.rgb = mix(color.rgb, vec3(0.), fogdistfade * (1.0-lightleakfix) * (1.0-darknessFactor) * clamp( 1.5 - np3.y,0.,1)) ;
|
||||
// color.rgb = vec3(CaveFogColor_R,CaveFogColor_G,CaveFogColor_B)*fogfade ;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// 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) / -4) * 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;
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
// 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);
|
||||
#endif
|
||||
|
||||
/// 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) * -5),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 / 30;
|
||||
if(luma(thingy) > 0.0){
|
||||
color.rgb = thingy;
|
||||
vl.a = 1.0;
|
||||
}
|
||||
#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);
|
||||
}
|
Reference in New Issue
Block a user