mirror of
https://github.com/X0nk/Bliss-Shader.git
synced 2025-06-22 08:42:50 +08:00
INTERNAL REWORK. testers are needed.
This commit is contained in:
@ -1,11 +1,22 @@
|
||||
// #version 120
|
||||
#include "/lib/settings.glsl"
|
||||
#include "/lib/res_params.glsl"
|
||||
#include "/lib/Shadow_Params.glsl"
|
||||
|
||||
varying vec4 lmtexcoord;
|
||||
varying vec4 color;
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
const bool shadowHardwareFiltering = true;
|
||||
uniform sampler2DShadow shadow;
|
||||
|
||||
flat varying vec3 WsunVec;
|
||||
|
||||
flat varying vec3 averageSkyCol_Clouds;
|
||||
flat varying vec4 lightCol;
|
||||
#endif
|
||||
|
||||
uniform sampler2D texture;
|
||||
|
||||
uniform sampler2D noisetex;
|
||||
|
||||
uniform sampler2D colortex4;
|
||||
|
||||
|
||||
@ -23,7 +34,15 @@ uniform vec2 texelSize;
|
||||
uniform ivec2 eyeBrightnessSmooth;
|
||||
uniform float rainStrength;
|
||||
|
||||
#include "/lib/settings.glsl"
|
||||
#ifndef OVERWORLD_SHADER
|
||||
uniform float nightVision;
|
||||
#endif
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
#define CLOUDSHADOWSONLY
|
||||
#include "/lib/volumetricClouds.glsl"
|
||||
#endif
|
||||
|
||||
#include "/lib/diffuse_lighting.glsl"
|
||||
#include "/lib/sky_gradient.glsl"
|
||||
|
||||
@ -51,8 +70,10 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
|
||||
vec2(3,7.)/8.,
|
||||
vec2(7.,-7.)/8.);
|
||||
|
||||
vec3 normVec (vec3 vec){
|
||||
return vec*inversesqrt(dot(vec,vec));
|
||||
//Mie phase function
|
||||
float phaseg(float x, float g){
|
||||
float gg = g * g;
|
||||
return (gg * -0.25 + 0.25) * pow(-2.0 * (g * x) + (gg + 1.0), -1.5) / 3.14;
|
||||
}
|
||||
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
@ -60,26 +81,83 @@ vec3 normVec (vec3 vec){
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
/* DRAWBUFFERS:2 */
|
||||
|
||||
/* DRAWBUFFERS:29 */
|
||||
|
||||
void main() {
|
||||
|
||||
gl_FragData[0] = texture2D(texture, lmtexcoord.xy)*color;
|
||||
|
||||
vec3 Albedo = toLinear(gl_FragData[0].rgb);
|
||||
|
||||
vec2 tempOffset = offsets[framemod8];
|
||||
vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0));
|
||||
vec3 p3 = mat3(gbufferModelViewInverse) * fragpos;
|
||||
vec3 np3 = normVec(p3);
|
||||
vec3 viewPos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0));
|
||||
vec3 feetPlayerPos = mat3(gbufferModelViewInverse) * viewPos;
|
||||
vec3 feetPlayerPos_normalized = normalize(feetPlayerPos);
|
||||
|
||||
vec3 Indirect_lighting = vec3(1.0);
|
||||
float lightmap = lmtexcoord.z;
|
||||
vec3 nothing = vec3(0.0);
|
||||
vec4 TEXTURE = texture2D(texture, lmtexcoord.xy)*color;
|
||||
|
||||
vec3 Albedo = toLinear(TEXTURE.rgb);
|
||||
|
||||
vec2 lightmap = lmtexcoord.zw;
|
||||
|
||||
#ifndef OVERWORLD_SHADER
|
||||
lightmap.y = 1.0;
|
||||
#endif
|
||||
|
||||
#ifdef WEATHER
|
||||
// lightmap.x = clamp(max(lightmap.x - 0.5, 0.0) * 2.5, 0.0, 1.0);
|
||||
gl_FragData[1].a = TEXTURE.a; // for bloomy rain and stuff
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef WEATHER
|
||||
#ifndef LINES
|
||||
gl_FragData[0].a = TEXTURE.a;
|
||||
#else
|
||||
gl_FragData[0].a = 1.0;
|
||||
#endif
|
||||
|
||||
gl_FragData[1].a = 0.0; // for bloomy rain and stuff
|
||||
|
||||
vec3 Direct_lighting = vec3(0.0);
|
||||
vec3 Indirect_lighting = vec3(0.0);
|
||||
vec3 Torch_Color = vec3(TORCH_R,TORCH_G,TORCH_B);
|
||||
|
||||
#ifdef LIT
|
||||
Torch_Color *= LIT_PARTICLE_BRIGHTNESS;
|
||||
#endif
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
float Shadows = 1.0;
|
||||
|
||||
vec3 feetPlayerPos_shadow = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
|
||||
vec3 projectedShadowPosition = mat3(shadowModelView) * feetPlayerPos_shadow + shadowModelView[3].xyz;
|
||||
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
|
||||
|
||||
//apply distortion
|
||||
float distortFactor = calcDistort(projectedShadowPosition.xy);
|
||||
projectedShadowPosition.xy *= distortFactor;
|
||||
|
||||
//do shadows only if on shadow map
|
||||
if (abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution){
|
||||
|
||||
projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5);
|
||||
|
||||
Shadows = shadow2D(shadow, projectedShadowPosition).x;
|
||||
}
|
||||
|
||||
float cloudShadow = GetCloudShadow(feetPlayerPos);
|
||||
|
||||
Direct_lighting = (lightCol.rgb/80.0) * Shadows * cloudShadow;
|
||||
|
||||
#ifndef LINES
|
||||
Direct_lighting *= phaseg(clamp(dot(feetPlayerPos_normalized, WsunVec),0.0,1.0), 0.65)*2 + 0.5;
|
||||
#endif
|
||||
|
||||
Indirect_lighting = DoAmbientLighting(averageSkyCol_Clouds, Torch_Color, clamp(lightmap.xy,0,1), 3.0);
|
||||
#endif
|
||||
|
||||
#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;
|
||||
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;
|
||||
|
||||
vec3 TorchLight = (Torch_Color * 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
|
||||
@ -87,8 +165,17 @@ void main() {
|
||||
#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);
|
||||
vec3 nothing = vec3(0.0);
|
||||
Indirect_lighting = DoAmbientLighting_Nether(AmbientLightColor, Torch_Color, lightmap.x, nothing, nothing, nothing);
|
||||
#endif
|
||||
|
||||
gl_FragData[0].rgb = Indirect_lighting * Albedo;
|
||||
|
||||
#ifndef LINES
|
||||
gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * Albedo;
|
||||
#else
|
||||
gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * toLinear(color.rgb);
|
||||
#endif
|
||||
|
||||
// distance fade targeting the world border...
|
||||
if(TEXTURE.a < 0.7 && TEXTURE.a > 0.2) gl_FragData[0] *= clamp(1.0 - length(feetPlayerPos) / 100.0 ,0.0,1.0);
|
||||
#endif
|
||||
}
|
@ -1,7 +1,5 @@
|
||||
// #version 120
|
||||
//#extension GL_EXT_gpu_shader4 : disable
|
||||
|
||||
#include "/lib/settings.glsl"
|
||||
#include "/lib/res_params.glsl"
|
||||
|
||||
/*
|
||||
!! DO NOT REMOVE !!
|
||||
@ -12,9 +10,21 @@ Read the terms of modification and sharing before changing something below pleas
|
||||
|
||||
varying vec4 lmtexcoord;
|
||||
varying vec4 color;
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
flat varying vec3 averageSkyCol_Clouds;
|
||||
flat varying vec4 lightCol;
|
||||
flat varying vec3 WsunVec;
|
||||
uniform sampler2D colortex4;
|
||||
#endif
|
||||
|
||||
uniform vec3 sunPosition;
|
||||
uniform float sunElevation;
|
||||
|
||||
uniform vec2 texelSize;
|
||||
uniform int framemod8;
|
||||
|
||||
uniform mat4 gbufferModelViewInverse;
|
||||
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
|
||||
vec2(-1.,3.)/8.,
|
||||
vec2(5.0,1.)/8.,
|
||||
@ -34,11 +44,24 @@ void main() {
|
||||
gl_Position = ftransform();
|
||||
|
||||
lmtexcoord.xy = (gl_MultiTexCoord0).xy;
|
||||
vec2 lmcoord = gl_MultiTexCoord1.xy/255.;
|
||||
vec2 lmcoord = gl_MultiTexCoord1.xy / 255.0; // is this even correct? lol'
|
||||
lmtexcoord.zw = lmcoord;
|
||||
|
||||
color = gl_Color;
|
||||
|
||||
#ifdef LINES
|
||||
color.a = 1.0;
|
||||
#endif
|
||||
#ifdef OVERWORLD_SHADER
|
||||
lightCol.rgb = texelFetch2D(colortex4,ivec2(6,37),0).rgb;
|
||||
lightCol.a = float(sunElevation > 1e-5)*2.0 - 1.0;
|
||||
|
||||
averageSkyCol_Clouds = texelFetch2D(colortex4,ivec2(0,37),0).rgb;
|
||||
|
||||
WsunVec = lightCol.a * normalize(mat3(gbufferModelViewInverse) * sunPosition);
|
||||
#endif
|
||||
#ifdef TAA_UPSCALING
|
||||
gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w;
|
||||
#endif
|
||||
#ifdef TAA
|
||||
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
|
||||
#endif
|
||||
|
@ -1,11 +1,14 @@
|
||||
//#extension GL_EXT_gpu_shader4 : disable
|
||||
//#extension GL_ARB_shader_texture_lod : disable
|
||||
#extension GL_EXT_gpu_shader4 : enable
|
||||
#extension GL_ARB_shader_texture_lod : enable
|
||||
|
||||
#include "/lib/settings.glsl"
|
||||
|
||||
|
||||
flat varying int NameTags;
|
||||
|
||||
#ifdef HAND
|
||||
#undef POM
|
||||
#endif
|
||||
|
||||
#ifndef USE_LUMINANCE_AS_HEIGHTMAP
|
||||
#ifndef MC_NORMAL_MAP
|
||||
#undef POM
|
||||
@ -38,23 +41,28 @@ vec2 dcdy = dFdy(vtexcoord.st*vtexcoordam.pq)*exp2(Texture_MipMap_Bias);
|
||||
// #endif
|
||||
|
||||
#include "/lib/res_params.glsl"
|
||||
|
||||
varying vec4 lmtexcoord;
|
||||
|
||||
varying vec4 color;
|
||||
varying vec4 NoSeasonCol;
|
||||
varying vec4 seasonColor;
|
||||
|
||||
uniform float far;
|
||||
|
||||
|
||||
uniform float wetness;
|
||||
varying vec4 normalMat;
|
||||
|
||||
|
||||
#ifdef MC_NORMAL_MAP
|
||||
varying vec4 tangent;
|
||||
uniform sampler2D normals;
|
||||
varying vec4 tangent;
|
||||
varying vec3 FlatNormals;
|
||||
#endif
|
||||
|
||||
|
||||
uniform sampler2D specular;
|
||||
|
||||
flat varying int lightningBolt;
|
||||
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D colortex1;//albedo(rgb),material(alpha) RGBA16
|
||||
uniform float frameTimeCounter;
|
||||
@ -67,21 +75,46 @@ uniform vec3 cameraPosition;
|
||||
uniform float rainStrength;
|
||||
uniform sampler2D noisetex;//depth
|
||||
uniform sampler2D depthtex0;
|
||||
|
||||
uniform vec4 entityColor;
|
||||
|
||||
// in vec3 velocity;
|
||||
|
||||
flat varying int PHYSICSMOD_SNOW;
|
||||
flat varying float blockID;
|
||||
|
||||
flat varying float SSSAMOUNT;
|
||||
flat varying float EMISSIVE;
|
||||
flat varying int LIGHTNING;
|
||||
flat varying int PORTAL;
|
||||
flat varying int SIGN;
|
||||
|
||||
flat varying float HELD_ITEM_BRIGHTNESS;
|
||||
|
||||
flat varying float HELD_ITEM_BRIGHTNESS;
|
||||
uniform float noPuddleAreas;
|
||||
|
||||
|
||||
// float interleaved_gradientNoise(){
|
||||
// return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+frameTimeCounter*51.9521);
|
||||
// }
|
||||
float interleaved_gradientNoise_temp(){
|
||||
vec2 alpha = vec2(0.75487765, 0.56984026);
|
||||
vec2 coord = vec2(alpha.x * gl_FragCoord.x,alpha.y * gl_FragCoord.y)+ 1.0/1.6180339887 * frameCounter;
|
||||
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
|
||||
return noise;
|
||||
}
|
||||
float interleaved_gradientNoise(){
|
||||
vec2 coord = gl_FragCoord.xy;
|
||||
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
|
||||
return noise;
|
||||
}
|
||||
float blueNoise(){
|
||||
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
|
||||
}
|
||||
|
||||
float R2_dither(){
|
||||
vec2 alpha = vec2(0.75487765, 0.56984026);
|
||||
return fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter) ;
|
||||
}
|
||||
|
||||
mat3 inverse(mat3 m) {
|
||||
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
|
||||
@ -99,15 +132,6 @@ mat3 inverse(mat3 m) {
|
||||
b21, (-a21 * a00 + a01 * a20), (a11 * a00 - a01 * a10)) / det;
|
||||
}
|
||||
|
||||
|
||||
#ifdef MC_NORMAL_MAP
|
||||
vec3 applyBump(mat3 tbnMatrix, vec3 bump, float puddle_values){
|
||||
float bumpmult = clamp(puddle_values,0.0,1.0);
|
||||
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
|
||||
return normalize(bump*tbnMatrix);
|
||||
}
|
||||
#endif
|
||||
|
||||
vec3 viewToWorld(vec3 viewPosition) {
|
||||
vec4 pos;
|
||||
pos.xyz = viewPosition;
|
||||
@ -115,13 +139,11 @@ vec3 viewToWorld(vec3 viewPosition) {
|
||||
pos = gbufferModelViewInverse * pos;
|
||||
return pos.xyz;
|
||||
}
|
||||
|
||||
vec3 worldToView(vec3 worldPos) {
|
||||
vec4 pos = vec4(worldPos, 0.0);
|
||||
pos = gbufferModelView * pos;
|
||||
return pos.xyz;
|
||||
}
|
||||
|
||||
vec4 encode (vec3 n, vec2 lightmaps){
|
||||
n.xy = n.xy / dot(abs(n), vec3(1.0));
|
||||
n.xy = n.z <= 0.0 ? (1.0 - abs(n.yx)) * sign(n.xy) : n.xy;
|
||||
@ -140,6 +162,15 @@ float encodeVec2(float x,float y){
|
||||
return encodeVec2(vec2(x,y));
|
||||
}
|
||||
|
||||
#ifdef MC_NORMAL_MAP
|
||||
vec3 applyBump(mat3 tbnMatrix, vec3 bump, float puddle_values){
|
||||
float bumpmult = clamp(puddle_values,0.0,1.0);
|
||||
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
|
||||
return normalize(bump*tbnMatrix);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
|
||||
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
|
||||
|
||||
@ -164,10 +195,17 @@ vec3 toClipSpace3(vec3 viewSpacePosition) {
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
|
||||
vec2(-1.,3.)/8.,
|
||||
vec2(5.0,1.)/8.,
|
||||
@ -176,11 +214,75 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
|
||||
vec2(-7.,-1.)/8.,
|
||||
vec2(3,7.)/8.,
|
||||
vec2(7.,-7.)/8.);
|
||||
vec3 srgbToLinear2(vec3 srgb){
|
||||
return mix(
|
||||
srgb / 12.92,
|
||||
pow(.947867 * srgb + .0521327, vec3(2.4) ),
|
||||
step( .04045, srgb )
|
||||
);
|
||||
}
|
||||
vec3 blackbody2(float Temp)
|
||||
{
|
||||
float t = pow(Temp, -1.5);
|
||||
float lt = log(Temp);
|
||||
|
||||
float bias(){
|
||||
return Texture_MipMap_Bias + (blueNoise()-0.5)*0.5;
|
||||
vec3 col = vec3(0.0);
|
||||
col.x = 220000.0 * t + 0.58039215686;
|
||||
col.y = 0.39231372549 * lt - 2.44549019608;
|
||||
col.y = Temp > 6500. ? 138039.215686 * t + 0.72156862745 : col.y;
|
||||
col.z = 0.76078431372 * lt - 5.68078431373;
|
||||
col = clamp(col,0.0,1.0);
|
||||
col = Temp < 1000. ? col * Temp * 0.001 : col;
|
||||
|
||||
return srgbToLinear2(col);
|
||||
}
|
||||
|
||||
uniform float near;
|
||||
|
||||
|
||||
float ld(float dist) {
|
||||
return (2.0 * near) / (far + near - dist * (far - near));
|
||||
}
|
||||
|
||||
|
||||
vec4 readNoise(in vec2 coord){
|
||||
// return texture2D(noisetex,coord*vtexcoordam.pq+vtexcoord.st);
|
||||
return texture2DGradARB(noisetex,coord*vtexcoordam.pq + vtexcoordam.st,dcdx,dcdy);
|
||||
}
|
||||
float EndPortalEffect(
|
||||
inout vec4 ALBEDO,
|
||||
vec3 FragPos,
|
||||
vec3 WorldPos,
|
||||
mat3 tbnMatrix
|
||||
){
|
||||
|
||||
int maxdist = 25;
|
||||
int quality = 35;
|
||||
|
||||
vec3 viewVec = normalize(tbnMatrix*FragPos);
|
||||
if ( viewVec.z < 0.0 && length(FragPos) < maxdist) {
|
||||
float endportalGLow = 0.0;
|
||||
float Depth = 0.3;
|
||||
vec3 interval = (viewVec.xyz /-viewVec.z/quality*Depth) * (0.7 + (blueNoise()-0.5)*0.1);
|
||||
|
||||
vec3 coord = vec3(WorldPos.xz , 1.0);
|
||||
coord += interval;
|
||||
|
||||
for (int loopCount = 0; (loopCount < quality) && (1.0 - Depth + Depth * ( 1.0-readNoise(coord.st).r - readNoise(-coord.st*3).b*0.2 ) ) < coord.p && coord.p >= 0.0; ++loopCount) {
|
||||
coord = coord+interval ;
|
||||
endportalGLow += (0.3/quality);
|
||||
}
|
||||
|
||||
ALBEDO.rgb = vec3(0.5,0.75,1.0) * sqrt(endportalGLow);
|
||||
|
||||
return clamp(pow(endportalGLow*3.5,3),0,1);
|
||||
}
|
||||
}
|
||||
|
||||
float bias(){
|
||||
// return (Texture_MipMap_Bias + (blueNoise()-0.5)*0.5) - (1.0-RENDER_SCALE.x) * 2.0;
|
||||
return Texture_MipMap_Bias - (1.0-RENDER_SCALE.x) * 2.0;
|
||||
}
|
||||
vec4 texture2D_POMSwitch(
|
||||
sampler2D sampler,
|
||||
vec2 lightmapCoord,
|
||||
@ -193,6 +295,9 @@ vec4 texture2D_POMSwitch(
|
||||
return texture2D(sampler, lightmapCoord, bias());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
@ -222,9 +327,8 @@ void main() {
|
||||
|
||||
vec2 tempOffset=offsets[framemod8];
|
||||
|
||||
vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0));
|
||||
vec3 worldpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz + cameraPosition;
|
||||
|
||||
vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0));
|
||||
vec3 worldpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz + cameraPosition;
|
||||
|
||||
float torchlightmap = lmtexcoord.z;
|
||||
|
||||
@ -234,103 +338,159 @@ void main() {
|
||||
|
||||
float lightmap = clamp( (lmtexcoord.w-0.8) * 10.0,0.,1.);
|
||||
|
||||
|
||||
vec2 adjustedTexCoord = lmtexcoord.xy;
|
||||
|
||||
#ifdef POM
|
||||
|
||||
adjustedTexCoord = fract(vtexcoord.st)*vtexcoordam.pq+vtexcoordam.st;
|
||||
|
||||
vec3 viewVector = normalize(tbnMatrix*fragpos);
|
||||
float dist = length(fragpos);
|
||||
|
||||
gl_FragDepth = gl_FragCoord.z;
|
||||
|
||||
#ifdef WORLD
|
||||
if (dist < MAX_OCCLUSION_DISTANCE) {
|
||||
|
||||
float depthmap = readNormal(vtexcoord.st).a;
|
||||
float used_POM_DEPTH = 1.0;
|
||||
|
||||
if ( viewVector.z < 0.0 && depthmap < 0.9999 && depthmap > 0.00001) {
|
||||
|
||||
#ifdef Adaptive_Step_length
|
||||
vec3 interval = (viewVector.xyz /-viewVector.z/MAX_OCCLUSION_POINTS * POM_DEPTH) * clamp(1.0-pow(depthmap,2),0.1,1.0) ;
|
||||
used_POM_DEPTH = 1.0;
|
||||
#else
|
||||
vec3 interval = viewVector.xyz /-viewVector.z/MAX_OCCLUSION_POINTS*POM_DEPTH;
|
||||
#endif
|
||||
vec3 coord = vec3(vtexcoord.st, 1.0);
|
||||
|
||||
coord += interval * used_POM_DEPTH;
|
||||
|
||||
float sumVec = 0.5;
|
||||
for (int loopCount = 0; (loopCount < MAX_OCCLUSION_POINTS) && (1.0 - POM_DEPTH + POM_DEPTH * readNormal(coord.st).a ) < coord.p && coord.p >= 0.0; ++loopCount) {
|
||||
coord = coord+interval * used_POM_DEPTH;
|
||||
sumVec += 1.0 * used_POM_DEPTH;
|
||||
}
|
||||
|
||||
if (coord.t < mincoord) {
|
||||
if (readTexture(vec2(coord.s,mincoord)).a == 0.0) {
|
||||
coord.t = mincoord;
|
||||
discard;
|
||||
}
|
||||
}
|
||||
adjustedTexCoord = mix(fract(coord.st)*vtexcoordam.pq+vtexcoordam.st, adjustedTexCoord, max(dist-MIX_OCCLUSION_DISTANCE,0.0)/(MAX_OCCLUSION_DISTANCE-MIX_OCCLUSION_DISTANCE));
|
||||
|
||||
vec3 truePos = fragpos + sumVec*inverse(tbnMatrix)*interval;
|
||||
|
||||
gl_FragDepth = toClipSpace3(truePos).z;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
float rainfall = rainStrength * noPuddleAreas;
|
||||
float Puddle_shape = 0.;
|
||||
|
||||
#if defined Puddles && defined WORLD && !defined ENTITIES && !defined HAND
|
||||
Puddle_shape = (1.0 - clamp(exp(-15 * pow(texture2D(noisetex, worldpos.xz * (0.020 * Puddle_Size) ).b ,5)),0,1)) * lightmap ;
|
||||
Puddle_shape *= clamp( viewToWorld(normal).y*0.5+0.5 ,0.0,1.0);
|
||||
Puddle_shape *= rainfall;
|
||||
#endif
|
||||
|
||||
|
||||
vec2 adjustedTexCoord = lmtexcoord.xy;
|
||||
|
||||
#if defined POM && defined WORLD && !defined ENTITIES && !defined HAND
|
||||
// vec2 tempOffset=offsets[framemod8];
|
||||
adjustedTexCoord = fract(vtexcoord.st)*vtexcoordam.pq+vtexcoordam.st;
|
||||
// vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0));
|
||||
vec3 viewVector = normalize(tbnMatrix*fragpos);
|
||||
float dist = length(fragpos);
|
||||
|
||||
float maxdist = MAX_OCCLUSION_DISTANCE;
|
||||
if(!ifPOM) maxdist = 0.0;
|
||||
|
||||
gl_FragDepth = gl_FragCoord.z;
|
||||
|
||||
if (dist < maxdist) {
|
||||
|
||||
float depthmap = readNormal(vtexcoord.st).a;
|
||||
float used_POM_DEPTH = 1.0;
|
||||
|
||||
if ( viewVector.z < 0.0 && depthmap < 0.9999 && depthmap > 0.00001) {
|
||||
// float noise = interleaved_gradientNoise_temp();
|
||||
#ifdef Adaptive_Step_length
|
||||
vec3 interval = (viewVector.xyz /-viewVector.z/MAX_OCCLUSION_POINTS * POM_DEPTH) * clamp(1.0-pow(depthmap,2),0.1,1.0);
|
||||
used_POM_DEPTH = 1.0;
|
||||
#else
|
||||
vec3 interval = viewVector.xyz /-viewVector.z/MAX_OCCLUSION_POINTS*POM_DEPTH;
|
||||
#endif
|
||||
vec3 coord = vec3(vtexcoord.st , 1.0);
|
||||
|
||||
coord += interval * used_POM_DEPTH;
|
||||
|
||||
float sumVec = 0.5;
|
||||
for (int loopCount = 0; (loopCount < MAX_OCCLUSION_POINTS) && (1.0 - POM_DEPTH + POM_DEPTH * readNormal(coord.st).a ) < coord.p && coord.p >= 0.0; ++loopCount) {
|
||||
coord = coord + interval * used_POM_DEPTH;
|
||||
sumVec += 1.0 * used_POM_DEPTH;
|
||||
}
|
||||
|
||||
if (coord.t < mincoord) {
|
||||
if (readTexture(vec2(coord.s,mincoord)).a == 0.0) {
|
||||
coord.t = mincoord;
|
||||
discard;
|
||||
}
|
||||
}
|
||||
|
||||
adjustedTexCoord = mix(fract(coord.st)*vtexcoordam.pq+vtexcoordam.st, adjustedTexCoord, max(dist-MIX_OCCLUSION_DISTANCE,0.0)/(MAX_OCCLUSION_DISTANCE-MIX_OCCLUSION_DISTANCE));
|
||||
|
||||
vec3 truePos = fragpos + sumVec*inverse(tbnMatrix)*interval;
|
||||
// #ifdef Depth_Write_POM
|
||||
gl_FragDepth = toClipSpace3(truePos).z;
|
||||
// #endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if(!ifPOM) adjustedTexCoord = lmtexcoord.xy;
|
||||
|
||||
|
||||
////////////////////////////////
|
||||
//////////////////////////////// ALBEDO
|
||||
////////////////////////////////
|
||||
|
||||
//////////////////////////////// ////////////////////////////////
|
||||
//////////////////////////////// ALBEDO ////////////////////////////////
|
||||
//////////////////////////////// ////////////////////////////////
|
||||
|
||||
vec4 Albedo = texture2D_POMSwitch(texture, adjustedTexCoord.xy, vec4(dcdx,dcdy), ifPOM) * color;
|
||||
|
||||
if(LIGHTNING > 0) Albedo = vec4(1);
|
||||
|
||||
// float ENDPORTAL_EFFECT = 0.0;
|
||||
// #ifndef ENTITIES
|
||||
// ENDPORTAL_EFFECT = PORTAL > 0 ? EndPortalEffect(Albedo, fragpos, worldpos, tbnMatrix) : 0;
|
||||
// #endif
|
||||
|
||||
#ifdef WhiteWorld
|
||||
Albedo.rgb = vec3(1.0);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef AEROCHROME_MODE
|
||||
vec3 aerochrome_color = mix(vec3(1.0, 0.0, 0.0), vec3(0.715, 0.303, 0.631), AEROCHROME_PINKNESS);
|
||||
float gray = dot(Albedo.rgb, vec3(0.2, 01.0, 0.07));
|
||||
if(blockID == 10001 || blockID == 10003 || blockID == 10004 || blockID == 10006) {
|
||||
// IR Reflective (Pink-red)
|
||||
Albedo.rgb = mix(vec3(gray), aerochrome_color, 0.7);
|
||||
}
|
||||
else if(blockID == 10008) {
|
||||
// Special handling for grass block
|
||||
float strength = 1.0 - color.b;
|
||||
Albedo.rgb = mix(Albedo.rgb, aerochrome_color, strength);
|
||||
}
|
||||
#ifdef AEROCHROME_WOOL_ENABLED
|
||||
else if(blockID == 200) {
|
||||
// Wool
|
||||
Albedo.rgb = mix(Albedo.rgb, aerochrome_color, 0.3);
|
||||
}
|
||||
#endif
|
||||
else if(blockID == 8 || blockID == 10002)
|
||||
{
|
||||
// IR Absorbsive? Dark.
|
||||
Albedo.rgb = mix(Albedo.rgb, vec3(0.01, 0.08, 0.15), 0.5);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WORLD
|
||||
if (Albedo.a > 0.1) Albedo.a = normalMat.a;
|
||||
else Albedo.a = 0.0;
|
||||
#endif
|
||||
|
||||
#ifdef HAND
|
||||
#if defined HAND
|
||||
if (Albedo.a > 0.1) Albedo.a = 0.75;
|
||||
else Albedo.a = 0.0;
|
||||
#endif
|
||||
|
||||
#ifdef WhiteWorld
|
||||
Albedo.rgb = vec3(1.0);
|
||||
|
||||
//////////////////////////////// ////////////////////////////////
|
||||
//////////////////////////////// NORMAL ////////////////////////////////
|
||||
//////////////////////////////// ////////////////////////////////
|
||||
|
||||
#if defined WORLD && defined MC_NORMAL_MAP
|
||||
vec3 NormalTex = texture2D_POMSwitch(normals, adjustedTexCoord.xy, vec4(dcdx,dcdy), ifPOM).xya;
|
||||
float Heightmap = 1.0 - NormalTex.z;
|
||||
|
||||
NormalTex.xy = NormalTex.xy*2.0-1.0;
|
||||
NormalTex.z = clamp(sqrt(1.0 - dot(NormalTex.xy, NormalTex.xy)),0.0,1.0) ;
|
||||
|
||||
#if defined HEIGTHMAP_DEPTH_OFFSET && !defined HAND
|
||||
gl_FragDepth = gl_FragCoord.z;
|
||||
vec3 truePos = fragpos;
|
||||
truePos.z -= Heightmap * POM_DEPTH * (1.0 + ld(truePos.z));
|
||||
|
||||
gl_FragDepth = toClipSpace3(truePos).z;
|
||||
#endif
|
||||
|
||||
if(PHYSICSMOD_SNOW < 1) normal = applyBump(tbnMatrix, NormalTex.xyz, mix(1.0,1-Puddle_shape,rainfall) );
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//////////////////////////////// NORMAL
|
||||
////////////////////////////////
|
||||
|
||||
#ifdef WORLD
|
||||
#ifdef MC_NORMAL_MAP
|
||||
|
||||
vec4 NormalTex = texture2D_POMSwitch(normals, adjustedTexCoord.xy, vec4(dcdx,dcdy), ifPOM);
|
||||
NormalTex.xy = NormalTex.xy*2.0-1.0;
|
||||
NormalTex.z = clamp(sqrt(1.0 - dot(NormalTex.xy, NormalTex.xy)),0.0,1.0) ;
|
||||
|
||||
normal = applyBump(tbnMatrix, NormalTex.xyz, 1.0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//////////////////////////////// SPECULAR
|
||||
////////////////////////////////
|
||||
|
||||
//////////////////////////////// ////////////////////////////////
|
||||
//////////////////////////////// SPECULAR ////////////////////////////////
|
||||
//////////////////////////////// ////////////////////////////////
|
||||
|
||||
#ifdef WORLD
|
||||
vec4 SpecularTex = texture2D_POMSwitch(specular, adjustedTexCoord.xy, vec4(dcdx,dcdy), ifPOM);
|
||||
|
||||
SpecularTex.r = max(SpecularTex.r, Puddle_shape);
|
||||
SpecularTex.g = max(SpecularTex.g, Puddle_shape*0.02);
|
||||
|
||||
gl_FragData[2].rg = SpecularTex.rg;
|
||||
|
||||
#if EMISSIVE_TYPE == 0
|
||||
@ -366,35 +526,51 @@ void main() {
|
||||
#if SSS_TYPE == 3
|
||||
gl_FragData[2].b = SpecularTex.b;
|
||||
#endif
|
||||
|
||||
// hit glow effect...
|
||||
#ifdef ENTITIES
|
||||
Albedo.rgb = mix(Albedo.rgb, entityColor.rgb, entityColor.a);
|
||||
gl_FragData[2].a = mix(gl_FragData[2].a, 0.9, entityColor.a);;
|
||||
#endif
|
||||
|
||||
|
||||
// #ifndef ENTITIES
|
||||
// if(PORTAL > 0){
|
||||
// gl_FragData[2].rgb = vec3(0);
|
||||
// gl_FragData[2].a = clamp(ENDPORTAL_EFFECT * 0.9, 0,0.9);
|
||||
// }
|
||||
// #endif
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//////////////////////////////// FINALIZE
|
||||
////////////////////////////////
|
||||
// hit glow effect...
|
||||
#ifdef ENTITIES
|
||||
Albedo.rgb = mix(Albedo.rgb, entityColor.rgb, entityColor.a);
|
||||
gl_FragData[2].a = mix(gl_FragData[2].a, 0.25, clamp(entityColor.a*5,0,1));
|
||||
#endif
|
||||
|
||||
vec4 data1 = clamp( encode(viewToWorld(normal), (blueNoise()*vec2(torchlightmap,lmtexcoord.w) / (30.0 * (1+ (1-RENDER_SCALE.x))) ) + vec2(torchlightmap,lmtexcoord.w)), 0.0, 1.0);
|
||||
gl_FragData[0] = vec4(encodeVec2(Albedo.x,data1.x), encodeVec2(Albedo.y,data1.y), encodeVec2(Albedo.z,data1.z), encodeVec2(data1.w,Albedo.w));
|
||||
|
||||
gl_FragData[1].a = 0.0;
|
||||
|
||||
////////////////////////////////
|
||||
//////////////////////////////// OTHER STUFF
|
||||
////////////////////////////////
|
||||
//////////////////////////////// ////////////////////////////////
|
||||
//////////////////////////////// FINALIZE ////////////////////////////////
|
||||
//////////////////////////////// ////////////////////////////////
|
||||
|
||||
#ifdef WORLD
|
||||
gl_FragData[3] = vec4(FlatNormals * 0.5 + 0.5,VanillaAO);
|
||||
|
||||
#ifdef Puddles
|
||||
float porosity = 0.4;
|
||||
#ifdef Porosity
|
||||
porosity = SpecularTex.z >= 64.5/255.0 ? 0.0 : (SpecularTex.z*255.0/64.0)*0.65;
|
||||
#endif
|
||||
if(SpecularTex.g < 229.5/255.0) Albedo.rgb = mix(Albedo.rgb, vec3(0), Puddle_shape*porosity);
|
||||
#endif
|
||||
|
||||
// apply noise to lightmaps to reduce banding.
|
||||
vec2 PackLightmaps = vec2(torchlightmap, lmtexcoord.w);
|
||||
|
||||
#if !defined ENTITIES && !defined HAND
|
||||
// PackLightmaps = clamp(PackLightmaps*blueNoise()*0.05 + PackLightmaps,0.0,1.0);
|
||||
#endif
|
||||
|
||||
|
||||
vec4 data1 = clamp( encode(viewToWorld(normal), PackLightmaps), 0.0, 1.0);
|
||||
|
||||
gl_FragData[0] = vec4(encodeVec2(Albedo.x,data1.x), encodeVec2(Albedo.y,data1.y), encodeVec2(Albedo.z,data1.z), encodeVec2(data1.w,Albedo.w));
|
||||
|
||||
|
||||
gl_FragData[3] = vec4(FlatNormals * 0.5 + 0.5, VanillaAO);
|
||||
|
||||
#endif
|
||||
|
||||
// gl_FragData[4].x = 0;
|
||||
|
||||
// #ifdef ENTITIES
|
||||
// gl_FragData[4].x = 1;
|
||||
// #endif
|
||||
|
||||
gl_FragData[1].a = 0.0;
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
//#extension GL_EXT_gpu_shader4 : disable
|
||||
#extension GL_EXT_gpu_shader4 : enable
|
||||
#include "/lib/settings.glsl"
|
||||
|
||||
#include "/lib/res_params.glsl"
|
||||
#include "/lib/bokeh.glsl"
|
||||
|
||||
/*
|
||||
!! DO NOT REMOVE !!
|
||||
@ -61,12 +61,24 @@ flat varying float HELD_ITEM_BRIGHTNESS;
|
||||
flat varying int PHYSICSMOD_SNOW;
|
||||
flat varying int NameTags;
|
||||
|
||||
uniform int frameCounter;
|
||||
uniform float far;
|
||||
uniform float aspectRatio;
|
||||
uniform float viewHeight;
|
||||
uniform float viewWidth;
|
||||
uniform int hideGUI;
|
||||
uniform float screenBrightness;
|
||||
|
||||
flat varying float SSSAMOUNT;
|
||||
flat varying float EMISSIVE;
|
||||
flat varying int LIGHTNING;
|
||||
flat varying int PORTAL;
|
||||
flat varying int SIGN;
|
||||
|
||||
// in vec3 at_velocity;
|
||||
// out vec3 velocity;
|
||||
|
||||
|
||||
|
||||
uniform mat4 gbufferModelView;
|
||||
uniform mat4 gbufferModelViewInverse;
|
||||
@ -83,6 +95,7 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
|
||||
vec2(-7.,-1.)/8.,
|
||||
vec2(3,7.)/8.,
|
||||
vec2(7.,-7.)/8.);
|
||||
|
||||
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
|
||||
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
|
||||
vec4 toClipSpace3(vec3 viewSpacePosition) {
|
||||
@ -212,12 +225,19 @@ void main() {
|
||||
FlatNormals = normalMat.xyz;
|
||||
|
||||
blockID = mc_Entity.x;
|
||||
// velocity = at_velocity;
|
||||
|
||||
if(mc_Entity.x == 10009) normalMat.a = 0.60;
|
||||
|
||||
|
||||
PORTAL = 0;
|
||||
SIGN = 0;
|
||||
|
||||
#ifdef WORLD
|
||||
// disallow POM to work on signs.
|
||||
if(blockEntityId == 2200) SIGN = 1;
|
||||
|
||||
if(blockEntityId == 2100) PORTAL = 1;
|
||||
#endif
|
||||
|
||||
NameTags = 0;
|
||||
@ -255,7 +275,7 @@ void main() {
|
||||
#ifdef ENTITIES
|
||||
if(entityId == 12345){
|
||||
LIGHTNING = 1;
|
||||
normalMat.a = 0.5;
|
||||
normalMat.a = 0.50;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -270,26 +290,32 @@ void main() {
|
||||
|
||||
|
||||
#ifdef WORLD
|
||||
|
||||
|
||||
/////// ----- SSS ON BLOCKS ----- ///////
|
||||
// strong
|
||||
if(mc_Entity.x == 10001 || mc_Entity.x == 10003 || mc_Entity.x == 10004) SSSAMOUNT = 1.0;
|
||||
if(mc_Entity.x == 10001 || mc_Entity.x == 10003 || mc_Entity.x == 10004 || mc_Entity.x == 10009) SSSAMOUNT = 1.0;
|
||||
|
||||
// medium
|
||||
if(mc_Entity.x == 10006 || mc_Entity.x == 200) SSSAMOUNT = 0.75;
|
||||
|
||||
// low
|
||||
if(mc_Entity.x == 10007 || mc_Entity.x == 10008) SSSAMOUNT = 0.5;
|
||||
|
||||
|
||||
#ifdef MISC_BLOCK_SSS
|
||||
if(mc_Entity.x == 10007 || mc_Entity.x == 10008) SSSAMOUNT = 0.5; // weird SSS on blocks like grass and stuff
|
||||
#endif
|
||||
|
||||
#ifdef ENTITIES
|
||||
/////// ----- SSS ON MOBS----- ///////
|
||||
// strong
|
||||
if(entityId == 1100) SSSAMOUNT = 0.75;
|
||||
|
||||
// medium
|
||||
|
||||
// low
|
||||
if(entityId == 1200) SSSAMOUNT = 0.3;
|
||||
#ifdef MOB_SSS
|
||||
/////// ----- SSS ON MOBS----- ///////
|
||||
// strong
|
||||
if(entityId == 1100) SSSAMOUNT = 0.75;
|
||||
|
||||
// medium
|
||||
|
||||
// low
|
||||
if(entityId == 1200) SSSAMOUNT = 0.3;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef BLOCKENTITIES
|
||||
@ -304,14 +330,62 @@ void main() {
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef WAVY_PLANTS
|
||||
bool istopv = gl_MultiTexCoord0.t < mc_midTexCoord.t;
|
||||
|
||||
if ((mc_Entity.x == 10001 || mc_Entity.x == 10009) && istopv && abs(position.z) < 64.0) {
|
||||
vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz + cameraPosition;
|
||||
worldpos.xyz += calcMovePlants(worldpos.xyz)*lmtexcoord.w - cameraPosition;
|
||||
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
|
||||
}
|
||||
|
||||
if (mc_Entity.x == 10003 && abs(position.z) < 64.0) {
|
||||
vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz + cameraPosition;
|
||||
worldpos.xyz += calcMoveLeaves(worldpos.xyz, 0.0040, 0.0064, 0.0043, 0.0035, 0.0037, 0.0041, vec3(1.0,0.2,1.0), vec3(0.5,0.1,0.5))*lmtexcoord.w - cameraPosition;
|
||||
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
|
||||
}
|
||||
#endif
|
||||
|
||||
gl_Position = toClipSpace3(position);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef Seasons
|
||||
#ifdef WORLD
|
||||
#ifndef BLOCKENTITIES
|
||||
#ifndef ENTITIES
|
||||
#ifndef HAND
|
||||
float blank = 0.0;
|
||||
YearCycleColor(color.rgb, gl_Color.rgb, blank);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef TAA_UPSCALING
|
||||
gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w;
|
||||
#endif
|
||||
#ifdef TAA
|
||||
gl_Position.xy += offsets[framemod8] * gl_Position.w * texelSize;
|
||||
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
|
||||
#endif
|
||||
|
||||
|
||||
#if DOF_QUALITY == 5
|
||||
vec2 jitter = clamp(jitter_offsets[frameCounter % 64], -1.0, 1.0);
|
||||
jitter = rotate(radians(float(frameCounter))) * jitter;
|
||||
jitter.y *= aspectRatio;
|
||||
jitter.x *= DOF_ANAMORPHIC_RATIO;
|
||||
|
||||
#if MANUAL_FOCUS == -2
|
||||
float focusMul = 0;
|
||||
#elif MANUAL_FOCUS == -1
|
||||
float focusMul = gl_Position.z - mix(pow(512.0, screenBrightness), 512.0 * screenBrightness, 0.25);
|
||||
#else
|
||||
float focusMul = gl_Position.z - MANUAL_FOCUS;
|
||||
#endif
|
||||
|
||||
vec2 totalOffset = (jitter * JITTER_STRENGTH) * focusMul * 1e-2;
|
||||
gl_Position.xy += hideGUI >= 1 ? totalOffset : vec2(0);
|
||||
#endif
|
||||
}
|
||||
|
@ -4,6 +4,16 @@
|
||||
varying vec4 lmtexcoord;
|
||||
varying vec4 color;
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
const bool shadowHardwareFiltering = true;
|
||||
uniform sampler2DShadow shadow;
|
||||
|
||||
uniform float lightSign;
|
||||
flat varying vec3 WsunVec;
|
||||
|
||||
flat varying vec3 averageSkyCol_Clouds;
|
||||
flat varying vec4 lightCol;
|
||||
#endif
|
||||
|
||||
const bool colortex4MipmapEnabled = true;
|
||||
uniform sampler2D noisetex;
|
||||
@ -17,14 +27,15 @@ uniform sampler2D normals;
|
||||
varying vec4 tangent;
|
||||
varying vec4 normalMat;
|
||||
varying vec3 binormal;
|
||||
|
||||
varying vec3 flatnormal;
|
||||
|
||||
varying vec3 viewVector;
|
||||
|
||||
|
||||
|
||||
uniform vec3 sunVec;
|
||||
uniform float near;
|
||||
uniform float far;
|
||||
// uniform float far;
|
||||
uniform float sunElevation;
|
||||
|
||||
uniform int isEyeInWater;
|
||||
@ -37,7 +48,6 @@ uniform float frameTimeCounter;
|
||||
uniform vec2 texelSize;
|
||||
uniform int framemod8;
|
||||
|
||||
flat varying vec3 WsunVec;
|
||||
uniform mat4 gbufferPreviousModelView;
|
||||
uniform vec3 previousCameraPosition;
|
||||
|
||||
@ -57,10 +67,17 @@ uniform vec3 nsunColor;
|
||||
#include "/lib/waterBump.glsl"
|
||||
#include "/lib/clouds.glsl"
|
||||
#include "/lib/stars.glsl"
|
||||
#include "/lib/volumetricClouds.glsl"
|
||||
#define OVERWORLD
|
||||
#include "/lib/diffuse_lighting.glsl"
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
flat varying float Flashing;
|
||||
#include "/lib/lightning_stuff.glsl"
|
||||
#include "/lib/volumetricClouds.glsl"
|
||||
#else
|
||||
uniform sampler2D colortex4;
|
||||
uniform float nightVision;
|
||||
#endif
|
||||
|
||||
#include "/lib/diffuse_lighting.glsl"
|
||||
|
||||
float blueNoise(){
|
||||
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
|
||||
@ -134,9 +151,9 @@ vec2 tapLocation(int sampleNumber,int nb, float nbRot,float jitter,float distort
|
||||
}
|
||||
|
||||
|
||||
vec3 viewToWorld(vec3 viewPosition) {
|
||||
vec3 viewToWorld(vec3 viewPos) {
|
||||
vec4 pos;
|
||||
pos.xyz = viewPosition;
|
||||
pos.xyz = viewPos;
|
||||
pos.w = 0.0;
|
||||
pos = gbufferModelViewInverse * pos;
|
||||
return pos.xyz;
|
||||
@ -173,7 +190,7 @@ float ld(float dist) {
|
||||
return (2.0 * near) / (far + near - dist * (far - near));
|
||||
}
|
||||
|
||||
vec3 rayTrace(vec3 dir,vec3 position,float dither, float fresnel, bool inwater){
|
||||
vec3 rayTrace(vec3 dir, vec3 position,float dither, float fresnel, bool inwater){
|
||||
|
||||
float quality = mix(15,SSR_STEPS,fresnel);
|
||||
vec3 clipPosition = toClipSpace3(position);
|
||||
@ -187,29 +204,30 @@ vec3 rayTrace(vec3 dir,vec3 position,float dither, float fresnel, bool inwater){
|
||||
float mult = min(min(maxLengths.x,maxLengths.y),maxLengths.z);
|
||||
|
||||
|
||||
vec3 stepv = direction * mult / quality;
|
||||
vec3 stepv = direction * mult / quality * vec3(RENDER_SCALE,1.0);
|
||||
|
||||
|
||||
vec3 spos = clipPosition+ stepv*dither;
|
||||
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) + stepv*dither;
|
||||
float minZ = clipPosition.z;
|
||||
float maxZ = spos.z+stepv.z*0.5;
|
||||
|
||||
spos.xy += offsets[framemod8]*texelSize*0.5;
|
||||
spos.xy += offsets[framemod8]*texelSize*0.5/RENDER_SCALE;
|
||||
|
||||
float dist = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases
|
||||
for (int i = 0; i <= int(quality); i++) {
|
||||
#ifdef USE_QUARTER_RES_DEPTH
|
||||
// decode depth buffer
|
||||
float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0);
|
||||
sp = invLinZ(sp);
|
||||
|
||||
if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ)) return vec3(spos.xy,sp);
|
||||
// decode depth buffer
|
||||
// float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0);
|
||||
#ifdef HAND
|
||||
vec2 testthing = spos.xy*texelSize; // fix for ssr on hand
|
||||
#else
|
||||
float sp = texelFetch2D(depthtex1,ivec2(spos.xy/texelSize),0).r;
|
||||
if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ)) return vec3(spos.xy,sp);
|
||||
|
||||
|
||||
vec2 testthing = spos.xy/texelSize/4.0;
|
||||
#endif
|
||||
float sp = sqrt((texelFetch2D(colortex4,ivec2(testthing),0).a+0.1)/65000.0);
|
||||
sp = invLinZ(sp);
|
||||
|
||||
if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ)) return vec3(spos.xy/RENDER_SCALE,sp);
|
||||
|
||||
|
||||
spos += stepv;
|
||||
//small bias
|
||||
@ -255,12 +273,17 @@ vec3 GGX (vec3 n, vec3 v, vec3 l, float r, vec3 F0) {
|
||||
/* RENDERTARGETS:2,7,11,14 */
|
||||
void main() {
|
||||
if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 ) {
|
||||
|
||||
vec2 tempOffset = offsets[framemod8];
|
||||
vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0));
|
||||
vec3 viewPos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0));
|
||||
vec3 feetPlayerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
|
||||
|
||||
////////////////////////////////
|
||||
//////////////////////////////// ALBEDO
|
||||
////////////////////////////////
|
||||
|
||||
gl_FragData[0] = texture2D(texture, lmtexcoord.xy, Texture_MipMap_Bias) * color;
|
||||
vec3 Albedo = toLinear(gl_FragData[0].rgb);
|
||||
|
||||
float UnchangedAlpha = gl_FragData[0].a;
|
||||
|
||||
float iswater = normalMat.w;
|
||||
@ -282,20 +305,21 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
#endif
|
||||
|
||||
|
||||
vec4 COLORTEST = vec4(Albedo,UnchangedAlpha);
|
||||
vec4 COLORTEST = vec4(Albedo, UnchangedAlpha);
|
||||
|
||||
|
||||
vec3 p3 = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz;
|
||||
|
||||
////////////////////////////////
|
||||
//////////////////////////////// NORMAL
|
||||
////////////////////////////////
|
||||
|
||||
vec3 normal = normalMat.xyz;
|
||||
vec2 TangentNormal = vec2(0); // for refractions
|
||||
|
||||
vec3 tangent2 = normalize(cross(tangent.rgb,normal)*tangent.w);
|
||||
mat3 tbnMatrix = mat3(tangent.x, tangent2.x, normal.x,
|
||||
tangent.y, tangent2.y, normal.y,
|
||||
tangent.z, tangent2.z, normal.z);
|
||||
|
||||
/// ------ NORMALS ------ ///
|
||||
tangent.y, tangent2.y, normal.y,
|
||||
tangent.z, tangent2.z, normal.z);
|
||||
|
||||
vec4 NormalTex = texture2D(normals, lmtexcoord.xy, Texture_MipMap_Bias).rgba;
|
||||
NormalTex.xy = NormalTex.xy*2.0-1.0;
|
||||
@ -304,30 +328,108 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
|
||||
normal = applyBump(tbnMatrix, NormalTex.xyz, 1.0);
|
||||
|
||||
if (iswater > 0.95){
|
||||
float bumpmult = 1.0;
|
||||
vec3 bump = vec3(0);
|
||||
vec3 posxz = p3+cameraPosition;
|
||||
|
||||
#ifndef HAND
|
||||
if (iswater > 0.95){
|
||||
float bumpmult = 1.0;
|
||||
vec3 bump = vec3(0);
|
||||
vec3 posxz = feetPlayerPos+cameraPosition;
|
||||
|
||||
posxz.xz -= posxz.y;
|
||||
posxz.xyz = getParallaxDisplacement(posxz,iswater,bumpmult,normalize(tbnMatrix*fragpos)) ;
|
||||
posxz.xz -= posxz.y;
|
||||
posxz.xyz = getParallaxDisplacement(posxz,iswater,bumpmult,normalize(tbnMatrix*viewPos)) ;
|
||||
|
||||
bump = normalize(getWaveHeight(posxz.xz,iswater));
|
||||
|
||||
TangentNormal = bump.xy*0.5+0.5; // tangent space normals for refraction
|
||||
bump = normalize(getWaveHeight(posxz.xz,iswater));
|
||||
|
||||
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
|
||||
normal = normalize(bump * tbnMatrix);
|
||||
}
|
||||
TangentNormal = bump.xy*0.5+0.5; // tangent space normals for refraction
|
||||
|
||||
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
|
||||
normal = normalize(bump * tbnMatrix);
|
||||
}
|
||||
#endif
|
||||
|
||||
gl_FragData[2] = vec4(encodeVec2(TangentNormal), encodeVec2(COLORTEST.rg), encodeVec2(COLORTEST.ba), UnchangedAlpha);
|
||||
|
||||
|
||||
|
||||
vec3 WS_normal = viewToWorld(normal);
|
||||
////////////////////////////////
|
||||
//////////////////////////////// DIFFUSE LIGHTING
|
||||
////////////////////////////////
|
||||
|
||||
vec2 lightmaps2 = lmtexcoord.zw;
|
||||
vec2 lightmap = lmtexcoord.zw;
|
||||
#ifndef OVERWORLD_SHADER
|
||||
lightmap.y = 1.0;
|
||||
#endif
|
||||
vec3 Indirect_lighting = vec3(0.0);
|
||||
vec3 Direct_lighting = vec3(0.0);
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
float NdotL = clamp(dot(normal, normalize(WsunVec*mat3(gbufferModelViewInverse))),0.0,1.0); NdotL = clamp((-15 + NdotL*255.0) / 240.0 ,0.0,1.0);
|
||||
float Shadows = 0.0;
|
||||
bool inShadowmapBounds = false;
|
||||
|
||||
vec3 feetPlayerPos_shadow = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
|
||||
|
||||
vec3 projectedShadowPosition = mat3(shadowModelView) * feetPlayerPos_shadow + shadowModelView[3].xyz;
|
||||
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
|
||||
|
||||
//apply distortion
|
||||
float distortFactor = calcDistort(projectedShadowPosition.xy);
|
||||
projectedShadowPosition.xy *= distortFactor;
|
||||
|
||||
bool ShadowBounds = false;
|
||||
if(shadowDistanceRenderMul > 0.0) ShadowBounds = length(feetPlayerPos_shadow) < max(shadowDistance - 20,0.0);
|
||||
|
||||
if(shadowDistanceRenderMul < 0.0) ShadowBounds = abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.z) < 6.0;
|
||||
|
||||
// sample shadows only if on shadow map
|
||||
if(ShadowBounds){
|
||||
if (NdotL > 0.0){
|
||||
Shadows = 0.0;
|
||||
projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5);
|
||||
|
||||
#ifndef HAND
|
||||
#ifdef BASIC_SHADOW_FILTER
|
||||
const float threshMul = max(2048.0/shadowMapResolution*shadowDistance/128.0,0.95);
|
||||
float distortThresh = (sqrt(1.0-NdotL*NdotL)/NdotL+0.7)/distortFactor;
|
||||
float diffthresh = distortThresh/6000.0*threshMul;
|
||||
|
||||
float rdMul = 4.0/shadowMapResolution;
|
||||
float noise = blueNoise();
|
||||
|
||||
int SampleCount = 7;
|
||||
for(int i = 0; i < SampleCount; i++){
|
||||
vec2 offsetS = tapLocation(i,SampleCount,1.618,noise,0.0);
|
||||
|
||||
float weight = 1.0+(i+noise)*rdMul/9.0*shadowMapResolution;
|
||||
float isShadow = shadow2D(shadow, projectedShadowPosition + vec3(rdMul*offsetS, -diffthresh*weight)).x / SampleCount;
|
||||
Shadows += isShadow;
|
||||
}
|
||||
|
||||
#else
|
||||
Shadows = shadow2D(shadow, projectedShadowPosition - vec3(0.0,0.0,0.0001)).x;
|
||||
#endif
|
||||
#else
|
||||
Shadows = shadow2D(shadow, projectedShadowPosition - vec3(0.0,0.0,0.0005)).x;
|
||||
#endif
|
||||
}
|
||||
inShadowmapBounds = true;
|
||||
}
|
||||
|
||||
// if(!inShadowmapBounds && !iswater) Shadows = min(max(lightmap.y-0.8, 0.0) * 25,1.0);
|
||||
if(!inShadowmapBounds) Shadows = 1.0;
|
||||
|
||||
Shadows *= GetCloudShadow(feetPlayerPos);
|
||||
|
||||
Direct_lighting = (lightCol.rgb/80.0) * NdotL * Shadows;
|
||||
|
||||
|
||||
vec3 ambientcoefs = WS_normal / dot(abs(WS_normal), vec3(1));
|
||||
float SkylightDir = ambientcoefs.y*1.5;
|
||||
|
||||
float skylight = max(pow(viewToWorld(flatnormal).y*0.5+0.5,0.1) + SkylightDir, 0.25);
|
||||
|
||||
// float skylight = max(pow(viewToWorld(flatnormal).y*0.5+0.5,0.1) + viewToWorld(normal).y, 0.25) * 1.35;
|
||||
Indirect_lighting = DoAmbientLighting(averageSkyCol_Clouds, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.xy, skylight);
|
||||
#endif
|
||||
|
||||
#ifdef NETHER_SHADER
|
||||
WS_normal.xz = -WS_normal.xz;
|
||||
@ -342,25 +444,31 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
AmbientLightColor += up + down;
|
||||
|
||||
// do all ambient lighting stuff
|
||||
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), lightmap.x, vec3(0.0), vec3(0.0), vec3(0.0));
|
||||
#endif
|
||||
|
||||
#ifdef END_SHADER
|
||||
// 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), lightmap.x, normal, feetPlayerPos );
|
||||
#endif
|
||||
|
||||
vec3 FinalColor = Indirect_lighting * Albedo;
|
||||
vec3 FinalColor = (Indirect_lighting + Direct_lighting) * Albedo;
|
||||
|
||||
#ifdef Glass_Tint
|
||||
float alphashit = min(pow(gl_FragData[0].a,2.0),1.0);
|
||||
FinalColor *= alphashit;
|
||||
FinalColor *= min(pow(gl_FragData[0].a,2.0),1.0);
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//////////////////////////////// SPECULAR
|
||||
////////////////////////////////
|
||||
#ifdef DAMAGE_BLOCK_EFFECT
|
||||
#undef WATER_REFLECTIONS
|
||||
#endif
|
||||
|
||||
#ifdef WATER_REFLECTIONS
|
||||
vec2 SpecularTex = texture2D(specular, lmtexcoord.xy, Texture_MipMap_Bias).rg;
|
||||
|
||||
SpecularTex = (iswater > 0.0 && iswater < 0.9) && SpecularTex.r > 0.0 && SpecularTex.g < 0.9 ? SpecularTex : vec2(1.0,0.1);
|
||||
SpecularTex = (iswater > 0.0 && iswater < 0.9) && SpecularTex.r > 0.0 && SpecularTex.g < 0.9 ? SpecularTex : vec2(1.0,0.02);
|
||||
|
||||
float roughness = max(pow(1.0-SpecularTex.r,2.0),0.05);
|
||||
float f0 = SpecularTex.g;
|
||||
@ -369,28 +477,41 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
vec3 Reflections_Final = vec3(0.0);
|
||||
vec4 Reflections = vec4(0.0);
|
||||
vec3 SkyReflection = vec3(0.0);
|
||||
vec3 SunReflection = vec3(0.0);
|
||||
|
||||
float indoors = clamp((lightmap.y-0.6)*5.0, 0.0,1.0);
|
||||
|
||||
|
||||
vec3 reflectedVector = reflect(normalize(fragpos), normal);
|
||||
float normalDotEye = dot(normal, normalize(fragpos));
|
||||
float fresnel = pow(clamp(1.0 + normalDotEye,0.0,1.0), 5.0);
|
||||
vec3 reflectedVector = reflect(normalize(viewPos), normal);
|
||||
|
||||
float normalDotEye = dot(normal, normalize(viewPos));
|
||||
float fresnel = pow(clamp(1.0 + dot(normal, normalize(viewPos)), 0.0, 1.0),5.0);
|
||||
|
||||
// float fresnel = exp(clamp(0.0 - dot(normal, normalize(viewPos)), 0.0, 1.0) * -5);
|
||||
|
||||
// snells window looking thing
|
||||
if(isEyeInWater == 1 ) fresnel = pow(clamp(1.66 + normalDotEye,0.0,1.0), 25.0);
|
||||
|
||||
fresnel = mix(f0, 1.0, fresnel);
|
||||
|
||||
vec3 wrefl = mat3(gbufferModelViewInverse)*reflectedVector;
|
||||
|
||||
// SSR, Sky, and Sun reflections
|
||||
#ifdef WATER_BACKGROUND_SPECULAR
|
||||
SkyReflection = skyCloudsFromTexLOD2(wrefl, colortex4, 0).rgb / 30.0;
|
||||
if(isEyeInWater == 1) SkyReflection = vec3(0.0);
|
||||
// Sun, Sky, and screen-space reflections
|
||||
#ifdef OVERWORLD_SHADER
|
||||
#ifdef WATER_SUN_SPECULAR
|
||||
SunReflection = Direct_lighting * GGX(normal, -normalize(viewPos), WsunVec*mat3(gbufferModelViewInverse), roughness, vec3(f0));
|
||||
#endif
|
||||
#ifdef WATER_BACKGROUND_SPECULAR
|
||||
SkyReflection = skyCloudsFromTex(mat3(gbufferModelViewInverse) * reflectedVector, colortex4).rgb / 30.0;
|
||||
if(isEyeInWater == 1) SkyReflection = vec3(0.0);
|
||||
#endif
|
||||
#else
|
||||
#ifdef WATER_BACKGROUND_SPECULAR
|
||||
SkyReflection = skyCloudsFromTexLOD2(mat3(gbufferModelViewInverse) * reflectedVector, colortex4, 0).rgb / 30.0;
|
||||
if(isEyeInWater == 1) SkyReflection = vec3(0.0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SCREENSPACE_REFLECTIONS
|
||||
if(iswater > 0.0){
|
||||
vec3 rtPos = rayTrace(reflectedVector,fragpos.xyz, interleaved_gradientNoise(), fresnel, isEyeInWater == 1);
|
||||
vec3 rtPos = rayTrace(reflectedVector, viewPos.xyz, interleaved_gradientNoise(), fresnel, isEyeInWater == 1);
|
||||
if (rtPos.z < 1.){
|
||||
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rtPos) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition;
|
||||
previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz;
|
||||
@ -405,8 +526,10 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
|
||||
float visibilityFactor = clamp(exp2((pow(roughness,3.0) / f0) * -4),0,1);
|
||||
|
||||
Reflections_Final = mix(SkyReflection, Reflections.rgb, Reflections.a);
|
||||
Reflections_Final = mix(FinalColor, Reflections_Final, fresnel * visibilityFactor);
|
||||
Reflections_Final = mix(SkyReflection*indoors, Reflections.rgb, Reflections.a);
|
||||
Reflections_Final = mix(FinalColor, Reflections_Final, fresnel);
|
||||
Reflections_Final += SunReflection;
|
||||
|
||||
|
||||
gl_FragData[0].rgb = Reflections_Final;
|
||||
|
||||
@ -423,7 +546,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
#endif
|
||||
|
||||
#ifndef HAND
|
||||
gl_FragData[1] = vec4(Albedo,iswater);
|
||||
gl_FragData[1] = vec4(Albedo, iswater);
|
||||
#endif
|
||||
|
||||
gl_FragData[3].a = max(lmtexcoord.w*blueNoise()*0.05 + lmtexcoord.w,0.0);
|
||||
|
@ -1,8 +1,7 @@
|
||||
// #version 120
|
||||
//#extension GL_EXT_gpu_shader4 : disable
|
||||
#include "/lib/settings.glsl"
|
||||
#include "/lib/res_params.glsl"
|
||||
#include "/lib/bokeh.glsl"
|
||||
#include "/lib/Shadow_Params.glsl"
|
||||
|
||||
/*
|
||||
!! DO NOT REMOVE !!
|
||||
@ -13,9 +12,17 @@ Read the terms of modification and sharing before changing something below pleas
|
||||
|
||||
varying vec4 lmtexcoord;
|
||||
varying vec4 color;
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
flat varying vec3 averageSkyCol_Clouds;
|
||||
flat varying vec4 lightCol;
|
||||
flat varying vec3 WsunVec;
|
||||
#endif
|
||||
|
||||
varying vec4 normalMat;
|
||||
varying vec3 binormal;
|
||||
varying vec4 tangent;
|
||||
varying vec3 flatnormal;
|
||||
|
||||
uniform mat4 gbufferModelViewInverse;
|
||||
varying vec3 viewVector;
|
||||
@ -28,13 +35,12 @@ attribute vec4 mc_Entity;
|
||||
uniform sampler2D colortex4;
|
||||
|
||||
uniform vec3 sunPosition;
|
||||
flat varying vec3 WsunVec;
|
||||
uniform float sunElevation;
|
||||
|
||||
varying vec4 tangent_other;
|
||||
|
||||
uniform int frameCounter;
|
||||
uniform float far;
|
||||
// uniform float far;
|
||||
uniform float aspectRatio;
|
||||
uniform float viewHeight;
|
||||
uniform float viewWidth;
|
||||
@ -77,7 +83,6 @@ void main() {
|
||||
vec3 position = mat3(gl_ModelViewMatrix) * vec3(Swtich_gl_vertex) + gl_ModelViewMatrix[3].xyz;
|
||||
gl_Position = toClipSpace3(position);
|
||||
|
||||
color = vec4(gl_Color.rgb,1.0);
|
||||
|
||||
float mat = 0.0;
|
||||
|
||||
@ -106,10 +111,30 @@ void main() {
|
||||
mat3 tbnMatrix = mat3(tangent2.x, binormal.x, normalMat.x,
|
||||
tangent2.y, binormal.y, normalMat.y,
|
||||
tangent2.z, binormal.z, normalMat.z);
|
||||
|
||||
flatnormal = normalMat.xyz;
|
||||
|
||||
viewVector = ( gl_ModelViewMatrix * Swtich_gl_vertex).xyz;
|
||||
viewVector = normalize(tbnMatrix * viewVector);
|
||||
|
||||
|
||||
color = vec4(gl_Color.rgb, 1.0);
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
lightCol.rgb = texelFetch2D(colortex4,ivec2(6,37),0).rgb;
|
||||
lightCol.a = float(sunElevation > 1e-5)*2.0 - 1.0;
|
||||
|
||||
averageSkyCol_Clouds = texelFetch2D(colortex4,ivec2(0,37),0).rgb;
|
||||
|
||||
WsunVec = lightCol.a * normalize(mat3(gbufferModelViewInverse) * sunPosition);
|
||||
// WsunVec = normalize(LightDir);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef TAA_UPSCALING
|
||||
gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w;
|
||||
#endif
|
||||
#ifdef TAA
|
||||
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
|
||||
#endif
|
||||
|
67
shaders/dimensions/all_vanilla_emissives.fsh
Normal file
67
shaders/dimensions/all_vanilla_emissives.fsh
Normal file
@ -0,0 +1,67 @@
|
||||
varying vec4 color;
|
||||
varying vec2 texcoord;
|
||||
|
||||
uniform sampler2D texture;
|
||||
|
||||
//faster and actually more precise than pow 2.2
|
||||
vec3 toLinear(vec3 sRGB){
|
||||
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//////////////////////////////
|
||||
#if defined SPIDER_EYES || defined BEACON_BEAM || defined GLOWING
|
||||
/* DRAWBUFFERS:1 */
|
||||
#endif
|
||||
|
||||
#ifdef ENCHANT_GLINT
|
||||
/* DRAWBUFFERS:2 */
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
|
||||
vec4 Albedo = texture2D(texture, texcoord);
|
||||
|
||||
#if defined SPIDER_EYES || defined BEACON_BEAM || defined GLOWING
|
||||
vec4 data1 = vec4(1.0); float materialMask = 1.0;
|
||||
|
||||
#if defined SPIDER_EYES || defined GLOWING
|
||||
if(Albedo.a < 0.1) discard;
|
||||
Albedo.rgb *= color.a;
|
||||
#endif
|
||||
|
||||
#ifdef BEACON_BEAM
|
||||
Albedo.rgb = Albedo.rgb * color.rgb;
|
||||
materialMask = 0.75;
|
||||
#endif
|
||||
|
||||
gl_FragData[0] = vec4(encodeVec2(Albedo.x,data1.x), encodeVec2(Albedo.y,data1.y), encodeVec2(Albedo.z,data1.z), encodeVec2(data1.w, materialMask));
|
||||
#endif
|
||||
|
||||
#ifdef ENCHANT_GLINT
|
||||
vec3 GlintColor = toLinear(Albedo.rgb * color.rgb) * Albedo.a;
|
||||
|
||||
gl_FragData[0] = vec4(GlintColor, Albedo.a * 0.1);
|
||||
#endif
|
||||
}
|
54
shaders/dimensions/all_vanilla_emissives.vsh
Normal file
54
shaders/dimensions/all_vanilla_emissives.vsh
Normal file
@ -0,0 +1,54 @@
|
||||
#include "/lib/settings.glsl"
|
||||
#include "/lib/res_params.glsl"
|
||||
|
||||
/*
|
||||
!! 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//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
|
||||
void main() {
|
||||
|
||||
gl_Position = ftransform();
|
||||
|
||||
texcoord = (gl_MultiTexCoord0).xy;
|
||||
#ifdef ENCHANT_GLINT
|
||||
texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).st;
|
||||
// float exposure = texelFetch2D(colortex4, ivec2(10,37),0).r;
|
||||
#endif
|
||||
|
||||
color = gl_Color;
|
||||
#ifdef BEACON_BEAM
|
||||
if(gl_Color.a < 1.0) gl_Position = vec4(10,10,10,0);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef TAA_UPSCALING
|
||||
gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w;
|
||||
#endif
|
||||
#ifdef TAA
|
||||
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
|
||||
#endif
|
||||
}
|
@ -1,119 +1,80 @@
|
||||
#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 vec3 WsunVec;
|
||||
flat varying vec2 TAA_Offset;
|
||||
|
||||
uniform int frameCounter;
|
||||
uniform float frameTimeCounter;
|
||||
|
||||
uniform float rainStrength;
|
||||
uniform int isEyeInWater;
|
||||
uniform ivec2 eyeBrightnessSmooth;
|
||||
#include "/lib/res_params.glsl"
|
||||
|
||||
uniform sampler2D depthtex1;
|
||||
uniform sampler2D colortex1;
|
||||
uniform sampler2D colortex6; // Noise
|
||||
uniform sampler2D colortex8; // Noise
|
||||
uniform sampler2D colortex15; // Noise
|
||||
uniform sampler2D shadow;
|
||||
uniform sampler2D noisetex;
|
||||
uniform vec3 sunVec;
|
||||
uniform vec2 texelSize;
|
||||
uniform float frameTimeCounter;
|
||||
uniform float rainStrength;
|
||||
uniform int frameCounter;
|
||||
uniform mat4 gbufferProjection;
|
||||
uniform mat4 gbufferProjectionInverse;
|
||||
uniform mat4 gbufferModelViewInverse;
|
||||
uniform mat4 gbufferModelView;
|
||||
|
||||
uniform mat4 shadowModelView;
|
||||
uniform mat4 shadowProjection;
|
||||
uniform vec3 cameraPosition;
|
||||
uniform float viewWidth;
|
||||
uniform float aspectRatio;
|
||||
uniform float viewHeight;
|
||||
// uniform float far;
|
||||
uniform float near;
|
||||
|
||||
#define ffstep(x,y) clamp((y - x) * 1e35,0.0,1.0)
|
||||
#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));
|
||||
vec3 worldToView(vec3 worldPos) {
|
||||
vec4 pos = vec4(worldPos, 0.0);
|
||||
pos = gbufferModelView * pos;
|
||||
return pos.xyz;
|
||||
}
|
||||
|
||||
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)
|
||||
vec2 tapLocation(int sampleNumber,int nb, float nbRot,float jitter,float distort)
|
||||
{
|
||||
float center = dither*2.0-1.0;
|
||||
dither = center*inversesqrt(abs(center));
|
||||
return clamp(dither-fsign(center),0.0,1.0);
|
||||
float alpha = (sampleNumber+jitter)/nb;
|
||||
float angle = jitter*6.28+alpha * nbRot * 6.28;
|
||||
float sin_v, cos_v;
|
||||
|
||||
sin_v = sin(angle);
|
||||
cos_v = cos(angle);
|
||||
|
||||
return vec2(cos_v, sin_v)*alpha;
|
||||
}
|
||||
vec2 tapLocation2(int sampleNumber, int nb, float jitter){
|
||||
float alpha = (sampleNumber+jitter)/nb;
|
||||
float angle = jitter*6.28 + alpha * 84.0 * 6.28;
|
||||
|
||||
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 sin_v, cos_v;
|
||||
|
||||
sin_v = sin(angle);
|
||||
cos_v = cos(angle);
|
||||
|
||||
return vec2(cos_v, sin_v)*sqrt(alpha);
|
||||
}
|
||||
|
||||
|
||||
|
||||
float facos(float sx){
|
||||
float x = clamp(abs( sx ),0.,1.);
|
||||
return sqrt( 1. - x ) * ( -0.16882 * x + 1.56734 );
|
||||
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 ;
|
||||
}
|
||||
vec3 decode (vec2 encn){
|
||||
vec3 n = vec3(0.0);
|
||||
@ -128,542 +89,185 @@ vec2 decodeVec2(float a){
|
||||
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(){
|
||||
float 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));
|
||||
return fract(alpha.x * gl_FragCoord.x + 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) );
|
||||
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 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;
|
||||
return texelFetch2D(colortex6, ivec2(coord )%512 , 0);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
vec2 tapLocation_alternate(
|
||||
int sampleNumber,
|
||||
float spinAngle,
|
||||
int nb,
|
||||
float nbRot,
|
||||
float r0
|
||||
){
|
||||
float alpha = (float(sampleNumber*1.0f + r0) * (1.0 / (nb)));
|
||||
float angle = alpha * (nbRot * 3.14) ;
|
||||
|
||||
void ApplySSRT(inout vec3 lighting, vec3 normal,vec2 noise,vec3 fragpos, float lightmaps, vec3 torchcolor){
|
||||
int nrays = RAY_COUNT;
|
||||
float ssR = alpha + spinAngle*3.14;
|
||||
float sin_v, cos_v;
|
||||
|
||||
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);
|
||||
sin_v = sin(angle);
|
||||
cos_v = cos(angle);
|
||||
return vec2(cos_v, sin_v)*ssR;
|
||||
}
|
||||
vec3 viewToWorld(vec3 viewPos) {
|
||||
vec4 pos;
|
||||
pos.xyz = viewPos;
|
||||
pos.w = 0.0;
|
||||
pos = gbufferModelViewInverse * pos;
|
||||
return pos.xyz;
|
||||
}
|
||||
|
||||
|
||||
// Emin's and Gri's combined ideas to stop peter panning and light leaking, also has little shadowacne so thats nice
|
||||
// https://www.complementary.dev/reimagined
|
||||
// https://github.com/gri573
|
||||
void GriAndEminShadowFix(
|
||||
inout vec3 WorldPos,
|
||||
vec3 FlatNormal,
|
||||
float VanillaAO,
|
||||
float SkyLightmap,
|
||||
bool Entities
|
||||
){
|
||||
float DistanceOffset = clamp(0.1 + length(WorldPos) / (shadowMapResolution*0.20), 0.0,1.0) ;
|
||||
vec3 Bias = FlatNormal * DistanceOffset; // adjust the bias thingy's strength as it gets farther away.
|
||||
|
||||
// stop lightleaking
|
||||
if(SkyLightmap < 0.1 && !Entities) {
|
||||
WorldPos += mix(Bias, 0.5 * (0.5 - fract(WorldPos + cameraPosition + FlatNormal*0.01 ) ), VanillaAO) ;
|
||||
}else{
|
||||
WorldPos += Bias;
|
||||
}
|
||||
}
|
||||
|
||||
#include "/lib/Shadow_Params.glsl"
|
||||
|
||||
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 */
|
||||
}
|
||||
vec2 texcoord = gl_FragCoord.xy*texelSize;
|
||||
|
||||
float z = texture2D(depthtex1,texcoord).x;
|
||||
|
||||
vec2 tempOffset=TAA_Offset;
|
||||
|
||||
vec4 data = texture2D(colortex1,texcoord);
|
||||
vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y));
|
||||
vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w));
|
||||
vec3 normal = mat3(gbufferModelViewInverse) * clamp(worldToView( decode(dataUnpacked0.yw) ),-1.,1.);
|
||||
vec2 lightmap = dataUnpacked1.yz;
|
||||
|
||||
|
||||
// bool lightningBolt = abs(dataUnpacked1.w-0.5) <0.01;
|
||||
// bool isLeaf = abs(dataUnpacked1.w-0.55) <0.01;
|
||||
// bool translucent2 = abs(dataUnpacked1.w-0.6) <0.01; // Weak translucency
|
||||
// bool translucent4 = abs(dataUnpacked1.w-0.65) <0.01; // Weak translucency
|
||||
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;
|
||||
|
||||
|
||||
float minshadowfilt = Min_Shadow_Filter_Radius;
|
||||
float maxshadowfilt = Max_Shadow_Filter_Radius;
|
||||
|
||||
float NdotL = clamp(dot(normal,WsunVec),0.0,1.0);
|
||||
|
||||
// vec4 normalAndAO = texture2D(colortex15,texcoord);
|
||||
// vec3 FlatNormals = normalAndAO.rgb * 2.0 - 1.0;
|
||||
// float vanillAO = clamp(normalAndAO.a,0.0,1.0) ;
|
||||
|
||||
float vanillAO = clamp(texture2D(colortex15,texcoord).a,0.0,1.0) ;
|
||||
|
||||
if(lightmap.y < 0.1 && !entities){
|
||||
// minshadowfilt *= vanillAO;
|
||||
maxshadowfilt = mix(minshadowfilt, maxshadowfilt, vanillAO);
|
||||
}
|
||||
|
||||
|
||||
float SpecularTex = texture2D(colortex8,texcoord).z;
|
||||
float LabSSS = clamp((-64.0 + SpecularTex * 255.0) / 191.0 ,0.0,1.0);
|
||||
|
||||
#ifndef Variable_Penumbra_Shadows
|
||||
if (LabSSS > 0.0 && !hand && NdotL < 0.001) minshadowfilt += 50;
|
||||
#endif
|
||||
|
||||
gl_FragData[0] = vec4(minshadowfilt, 0.1, 0.0, 0.0);
|
||||
|
||||
gl_FragData[0].y = 0;
|
||||
if (z < 1.0 && !hand){
|
||||
|
||||
vec3 viewPos = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z));
|
||||
|
||||
#ifdef Variable_Penumbra_Shadows
|
||||
|
||||
if (NdotL > 0.001 || LabSSS > 0.0) {
|
||||
|
||||
vec3 feetPlayerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
|
||||
|
||||
// GriAndEminShadowFix(p3, viewToWorld(FlatNormals), vanillAO, lightmap.y, entities);
|
||||
|
||||
vec3 projectedShadowPosition = mat3(shadowModelView) * feetPlayerPos + shadowModelView[3].xyz;
|
||||
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
|
||||
|
||||
//apply distortion
|
||||
float distortFactor = calcDistort(projectedShadowPosition.xy);
|
||||
projectedShadowPosition.xy *= distortFactor;
|
||||
|
||||
//do shadows only if on shadow map
|
||||
if (abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.z) < 6.0){
|
||||
const float threshMul = max(2048.0/shadowMapResolution*shadowDistance/128.0,0.95);
|
||||
float distortThresh = (sqrt(1.0-NdotL*NdotL)/NdotL+0.7)/distortFactor;
|
||||
float diffthresh = distortThresh/6000.0*threshMul;
|
||||
projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5,0.5,0.5);
|
||||
|
||||
float mult = maxshadowfilt;
|
||||
float avgBlockerDepth = 0.0;
|
||||
vec2 scales = vec2(0.0, 120.0 - Max_Filter_Depth);
|
||||
float blockerCount = 0.0;
|
||||
float rdMul = distortFactor*(1.0+mult)*d0*k/shadowMapResolution;
|
||||
float diffthreshM = diffthresh*mult*d0*k/20.;
|
||||
float avgDepth = 0.0;
|
||||
|
||||
int seed = (frameCounter%40000) * 2 + (1+frameCounter);
|
||||
float samplePos = fract(R2_samples(seed).x + blueNoise(gl_FragCoord.xy).x) * 1.61803398874;
|
||||
float noise = 0.5+blueNoise();
|
||||
|
||||
for(int i = 0; i < VPS_Search_Samples; i++){
|
||||
|
||||
vec2 offsetS = tapLocation_alternate(i+1, i/VPS_Search_Samples, 7, 20, samplePos) * noise;
|
||||
|
||||
|
||||
float weight = 3.0 + (i+blueNoise() ) *rdMul/SHADOW_FILTER_SAMPLE_COUNT*shadowMapResolution*distortFactor/2.7;
|
||||
// float d = texelFetch2D( shadow, ivec2((projectedShadowPosition.xy+offsetS*rdMul)*shadowMapResolution),0).x;
|
||||
float d = texelFetch2D( shadow, ivec2((projectedShadowPosition.xy+offsetS*rdMul)*shadowMapResolution),0).x;
|
||||
|
||||
|
||||
float b = smoothstep(weight*diffthresh/2.0, weight*diffthresh, projectedShadowPosition.z - d);
|
||||
|
||||
blockerCount += b;
|
||||
avgDepth += max(projectedShadowPosition.z - d, 0.0)*1000.;
|
||||
avgBlockerDepth += d * b;
|
||||
}
|
||||
|
||||
gl_FragData[0].g = avgDepth / VPS_Search_Samples;
|
||||
gl_FragData[0].b = blockerCount / VPS_Search_Samples;
|
||||
if (blockerCount >= 0.9){
|
||||
avgBlockerDepth /= blockerCount;
|
||||
float ssample = max(projectedShadowPosition.z - avgBlockerDepth,0.0)*1500.0;
|
||||
gl_FragData[0].r = clamp(ssample, scales.x, scales.y)/(scales.y)*(mult-minshadowfilt)+minshadowfilt;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
@ -1,24 +1,21 @@
|
||||
|
||||
//#extension GL_EXT_gpu_shader4 : disable
|
||||
|
||||
#include "/lib/settings.glsl"
|
||||
|
||||
varying vec2 texcoord;
|
||||
|
||||
flat varying vec3 avgAmbient;
|
||||
|
||||
flat varying float tempOffsets;
|
||||
flat varying vec2 TAA_Offset;
|
||||
flat varying vec3 zMults;
|
||||
flat varying vec3 WsunVec;
|
||||
|
||||
uniform sampler2D colortex4;
|
||||
|
||||
uniform float far;
|
||||
uniform float near;
|
||||
uniform mat4 gbufferModelViewInverse;
|
||||
uniform vec3 sunPosition;
|
||||
uniform float rainStrength;
|
||||
uniform float sunElevation;
|
||||
uniform int frameCounter;
|
||||
uniform float sunElevation;
|
||||
uniform vec3 sunPosition;
|
||||
uniform mat4 gbufferModelViewInverse;
|
||||
#include "/lib/util.glsl"
|
||||
#include "/lib/res_params.glsl"
|
||||
|
||||
uniform int framemod8;
|
||||
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
|
||||
vec2(-1.,3.)/8.,
|
||||
vec2(5.0,1.)/8.,
|
||||
@ -27,23 +24,14 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./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);
|
||||
WsunVec = (float(sunElevation > 1e-5)*2-1.)*normalize(mat3(gbufferModelViewInverse) * sunPosition);
|
||||
|
||||
TAA_Offset = offsets[frameCounter%8];
|
||||
|
||||
#ifndef TAA
|
||||
TAA_Offset = vec2(0.0);
|
||||
TAA_Offset = offsets[framemod8];
|
||||
|
||||
#ifdef TAA_UPSCALING
|
||||
gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0;
|
||||
#endif
|
||||
|
||||
|
||||
avgAmbient = texelFetch2D(colortex4,ivec2(0,37),0).rgb;
|
||||
zMults = vec3((far * near)*2.0,far+near,far-near);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,20 +1,57 @@
|
||||
#include "/lib/util.glsl"
|
||||
#include "/lib/settings.glsl"
|
||||
#include "/lib/res_params.glsl"
|
||||
|
||||
flat varying float tempOffsets;
|
||||
flat varying float Flashing;
|
||||
|
||||
flat varying vec3 WsunVec;
|
||||
flat varying vec3 averageSkyCol_Clouds;
|
||||
flat varying vec4 lightCol;
|
||||
|
||||
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;
|
||||
|
||||
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//////////////////////////////
|
||||
|
||||
#include "/lib/util.glsl"
|
||||
#include "/lib/Shadow_Params.glsl"
|
||||
|
||||
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;
|
||||
Flashing = texelFetch2D(colortex4,ivec2(1,1),0).x/150.0;
|
||||
|
||||
zMults = vec3((far * near)*2.0,far+near,far-near);
|
||||
|
||||
lightCol.rgb = texelFetch2D(colortex4,ivec2(6,37),0).rgb;
|
||||
lightCol.a = float(sunElevation > 1e-5)*2.0 - 1.0;
|
||||
|
||||
averageSkyCol_Clouds = texelFetch2D(colortex4,ivec2(0,37),0).rgb;
|
||||
|
||||
WsunVec = lightCol.a*normalize(mat3(gbufferModelViewInverse) * sunPosition);
|
||||
// WsunVec = normalize(LightDir);
|
||||
|
||||
|
||||
TAA_Offset = offsets[framemod8];
|
||||
|
||||
#ifdef TAA_UPSCALING
|
||||
gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0;
|
||||
#endif
|
||||
}
|
||||
|
102
shaders/dimensions/composite10.fsh
Normal file
102
shaders/dimensions/composite10.fsh
Normal file
@ -0,0 +1,102 @@
|
||||
uniform sampler2D colortex3;
|
||||
uniform sampler2D colortex6;
|
||||
|
||||
uniform vec2 texelSize;
|
||||
uniform float viewWidth;
|
||||
uniform float viewHeight;
|
||||
|
||||
float w0(float a)
|
||||
{
|
||||
return (1.0/6.0)*(a*(a*(-a + 3.0) - 3.0) + 1.0);
|
||||
}
|
||||
|
||||
float w1(float a)
|
||||
{
|
||||
return (1.0/6.0)*(a*a*(3.0*a - 6.0) + 4.0);
|
||||
}
|
||||
|
||||
float w2(float a)
|
||||
{
|
||||
return (1.0/6.0)*(a*(a*(-3.0*a + 3.0) + 3.0) + 1.0);
|
||||
}
|
||||
|
||||
float w3(float a)
|
||||
{
|
||||
return (1.0/6.0)*(a*a*a);
|
||||
}
|
||||
|
||||
float g0(float a)
|
||||
{
|
||||
return w0(a) + w1(a);
|
||||
}
|
||||
|
||||
float g1(float a)
|
||||
{
|
||||
return w2(a) + w3(a);
|
||||
}
|
||||
|
||||
float h0(float a)
|
||||
{
|
||||
return -1.0 + w1(a) / (w0(a) + w1(a));
|
||||
}
|
||||
|
||||
float h1(float a)
|
||||
{
|
||||
return 1.0 + w3(a) / (w2(a) + w3(a));
|
||||
}
|
||||
|
||||
vec4 texture2D_bicubic(sampler2D tex, vec2 uv)
|
||||
{
|
||||
vec4 texelSize = vec4(texelSize,1.0/texelSize);
|
||||
uv = uv*texelSize.zw;
|
||||
vec2 iuv = floor( uv );
|
||||
vec2 fuv = fract( uv );
|
||||
|
||||
float g0x = g0(fuv.x);
|
||||
float g1x = g1(fuv.x);
|
||||
float h0x = h0(fuv.x);
|
||||
float h1x = h1(fuv.x);
|
||||
float h0y = h0(fuv.y);
|
||||
float h1y = h1(fuv.y);
|
||||
|
||||
vec2 p0 = (vec2(iuv.x + h0x, iuv.y + h0y) - 0.5) * texelSize.xy;
|
||||
vec2 p1 = (vec2(iuv.x + h1x, iuv.y + h0y) - 0.5) * texelSize.xy;
|
||||
vec2 p2 = (vec2(iuv.x + h0x, iuv.y + h1y) - 0.5) * texelSize.xy;
|
||||
vec2 p3 = (vec2(iuv.x + h1x, iuv.y + h1y) - 0.5) * texelSize.xy;
|
||||
|
||||
return g0(fuv.y) * (g0x * texture2D(tex, p0) +
|
||||
g1x * texture2D(tex, p1)) +
|
||||
g1(fuv.y) * (g0x * texture2D(tex, p2) +
|
||||
g1x * texture2D(tex, p3));
|
||||
}
|
||||
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
|
||||
void main() {
|
||||
/* DRAWBUFFERS:3 */
|
||||
vec2 resScale = vec2(1920.,1080.)/max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.));
|
||||
vec2 texcoord = ((gl_FragCoord.xy)*2.+0.5)*texelSize;
|
||||
vec3 bloom = texture2D_bicubic(colortex3,texcoord/2.0).rgb; //1/4 res
|
||||
|
||||
bloom += texture2D_bicubic(colortex6,texcoord/4.).rgb; //1/8 res
|
||||
|
||||
bloom += texture2D_bicubic(colortex6,texcoord/8.+vec2(0.25*resScale.x+2.5*texelSize.x,.0)).rgb; //1/16 res
|
||||
|
||||
bloom += texture2D_bicubic(colortex6,texcoord/16.+vec2(0.375*resScale.x+4.5*texelSize.x,.0)).rgb; //1/32 res
|
||||
|
||||
bloom += texture2D_bicubic(colortex6,texcoord/32.+vec2(0.4375*resScale.x+6.5*texelSize.x,.0)).rgb*1.0; //1/64 res
|
||||
|
||||
bloom += texture2D_bicubic(colortex6,texcoord/64.+vec2(0.46875*resScale.x+8.5*texelSize.x,.0)).rgb*1.0; //1/128 res
|
||||
|
||||
bloom += texture2D_bicubic(colortex6,texcoord/128.+vec2(0.484375*resScale.x+10.5*texelSize.x,.0)).rgb*1.0; //1/256 res
|
||||
|
||||
//bloom = texture2D_bicubic(colortex6,texcoord).rgb*6.; //1/8 res
|
||||
|
||||
gl_FragData[0].rgb = bloom*2.;
|
||||
|
||||
gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.);
|
||||
}
|
15
shaders/dimensions/composite10.vsh
Normal file
15
shaders/dimensions/composite10.vsh
Normal 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;
|
||||
}
|
143
shaders/dimensions/composite11.fsh
Normal file
143
shaders/dimensions/composite11.fsh
Normal file
@ -0,0 +1,143 @@
|
||||
#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;
|
||||
|
||||
#if DOF_QUALITY >= 0 && DOF_QUALITY < 5
|
||||
/*--------------------------------*/
|
||||
float z = ld(texture2D(depthtex0, texcoord.st*RENDER_SCALE).r)*far;
|
||||
#if MANUAL_FOCUS == -2
|
||||
float focus = rodExposureDepth.y*far;
|
||||
#elif MANUAL_FOCUS == -1
|
||||
float focus = mix(pow(512.0, screenBrightness), 512.0 * screenBrightness, 0.25);
|
||||
#elif MANUAL_FOCUS > 0
|
||||
float focus = MANUAL_FOCUS;
|
||||
#endif
|
||||
float pcoc = min(abs(aperture * (focal/100.0 * (z - focus)) / (z * (focus - focal/100.0))),texelSize.x*15.0);
|
||||
#ifdef FAR_BLUR_ONLY
|
||||
pcoc *= float(z > focus);
|
||||
#endif
|
||||
float noise = blueNoise()*6.28318530718;
|
||||
mat2 noiseM = mat2( cos( noise ), -sin( noise ),
|
||||
sin( noise ), cos( noise )
|
||||
);
|
||||
vec3 bcolor = vec3(0.);
|
||||
float nb = 0.0;
|
||||
vec2 bcoord = vec2(0.0);
|
||||
/*--------------------------------*/
|
||||
float dofLodLevel = pcoc * 200.0;
|
||||
for ( int i = 0; i < BOKEH_SAMPLES; i++) {
|
||||
bcolor += texture2DLod(colortex5, texcoord.xy + bokeh_offsets[i]*pcoc*vec2(DOF_ANAMORPHIC_RATIO,aspectRatio), dofLodLevel).rgb;
|
||||
}
|
||||
col = bcolor/BOKEH_SAMPLES;
|
||||
#endif
|
||||
|
||||
vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.));
|
||||
|
||||
|
||||
|
||||
// vec3 bloom = (texture2D(colortex3,texcoord/clampedRes*vec2(1920.,1080.)*0.5*BLOOM_QUALITY).rgb)/2./7.0;
|
||||
|
||||
vec3 bloom = texture2D(colortex3, texcoord/clampedRes*vec2(1920.,1080.)*BLOOM_QUALITY).rgb / 2.0 / 7.0;
|
||||
|
||||
|
||||
float lightScat = clamp(BLOOM_STRENGTH * 0.05 * pow(exposure.a, 0.2) ,0.0,1.0)*vignette;
|
||||
|
||||
float VL_abs = texture2D(colortex7,texcoord*RENDER_SCALE).r;
|
||||
float 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);
|
||||
|
||||
// bloom *= lightScat;
|
||||
// apply bloom and bloomy fog
|
||||
// col = mix(col, bloom, VL_abs);
|
||||
// col += bloom*lightScat;
|
||||
|
||||
// // apply exposure
|
||||
// col *= 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*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);
|
||||
}
|
20
shaders/dimensions/composite11.vsh
Normal file
20
shaders/dimensions/composite11.vsh
Normal file
@ -0,0 +1,20 @@
|
||||
#include "/lib/settings.glsl"
|
||||
|
||||
varying vec2 texcoord;
|
||||
flat varying vec4 exposure;
|
||||
flat varying float rodExposure;
|
||||
uniform sampler2D colortex4;
|
||||
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////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);
|
||||
rodExposure = texelFetch2D(colortex4,ivec2(14,37),0).r;
|
||||
}
|
@ -1,305 +1,278 @@
|
||||
#include "/lib/settings.glsl"
|
||||
|
||||
flat varying vec3 zMults;
|
||||
flat varying vec2 TAA_Offset;
|
||||
|
||||
flat varying vec4 lightCol;
|
||||
flat varying vec3 averageSkyCol;
|
||||
// flat varying vec3 averageSkyCol_Clouds;
|
||||
|
||||
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 float sunElevation;
|
||||
// uniform float far;
|
||||
|
||||
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 float frameTimeCounter;
|
||||
|
||||
varying vec2 texcoord;
|
||||
uniform vec2 texelSize;
|
||||
flat varying vec2 TAA_Offset;
|
||||
|
||||
uniform int isEyeInWater;
|
||||
uniform ivec2 eyeBrightnessSmooth;
|
||||
uniform float rainStrength;
|
||||
uniform float blindness;
|
||||
uniform float darknessFactor;
|
||||
uniform float darknessLightFactor;
|
||||
uniform ivec2 eyeBrightnessSmooth;
|
||||
|
||||
|
||||
#include "/lib/waterBump.glsl"
|
||||
#include "/lib/color_transforms.glsl"
|
||||
#include "/lib/color_dither.glsl"
|
||||
#include "/lib/projections.glsl"
|
||||
#include "/lib/res_params.glsl"
|
||||
|
||||
#include "/lib/sky_gradient.glsl"
|
||||
#include "/lib/volumetricClouds.glsl"
|
||||
// #include "/lib/biome_specifics.glsl"
|
||||
#include "/lib/Shadow_Params.glsl"
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
|
||||
const bool shadowHardwareFiltering = true;
|
||||
uniform sampler2DShadow shadow;
|
||||
|
||||
flat varying vec3 refractedSunVec;
|
||||
|
||||
#define TIMEOFDAYFOG
|
||||
#include "/lib/lightning_stuff.glsl"
|
||||
#include "/lib/volumetricClouds.glsl"
|
||||
#include "/lib/volumetricFog.glsl"
|
||||
#endif
|
||||
#ifdef NETHER_SHADER
|
||||
uniform sampler2D colortex4;
|
||||
#include "/lib/nether_fog.glsl"
|
||||
#endif
|
||||
#ifdef END_SHADER
|
||||
uniform sampler2D colortex4;
|
||||
#include "/lib/end_fog.glsl"
|
||||
#endif
|
||||
|
||||
|
||||
#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));
|
||||
}
|
||||
#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.)
|
||||
|
||||
float interleaved_gradientNoise(){
|
||||
vec2 coord = gl_FragCoord.xy;
|
||||
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
|
||||
return noise;
|
||||
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+ 1.0/1.6180339887 * frameCounter);
|
||||
}
|
||||
vec3 viewToWorld(vec3 viewPosition) {
|
||||
vec4 pos;
|
||||
pos.xyz = viewPosition;
|
||||
pos.w = 0.0;
|
||||
pos = gbufferModelViewInverse * pos;
|
||||
return pos.xyz;
|
||||
float blueNoise(){
|
||||
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a+ 1.0/1.6180339887 * frameCounter );
|
||||
}
|
||||
|
||||
/// 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 waterVolumetrics_notoverworld(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;
|
||||
|
||||
}
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
float waterCaustics(vec3 wPos, vec3 lightSource) { // water waves
|
||||
|
||||
vec2 pos = wPos.xz + (lightSource.xz/lightSource.y*wPos.y);
|
||||
if(isEyeInWater==1) pos = wPos.xz - (lightSource.xz/lightSource.y*wPos.y); // fix the fucky
|
||||
vec2 movement = vec2(-0.035*frameTimeCounter);
|
||||
float caustic = 0.0;
|
||||
float weightSum = 0.0;
|
||||
float radiance = 2.39996;
|
||||
mat2 rotationMatrix = mat2(vec2(cos(radiance), -sin(radiance)), vec2(sin(radiance), cos(radiance)));
|
||||
|
||||
const vec2 wave_size[4] = vec2[](
|
||||
vec2(64.),
|
||||
vec2(32.,16.),
|
||||
vec2(16.,32.),
|
||||
vec2(48.)
|
||||
);
|
||||
|
||||
for (int i = 0; i < 4; i++){
|
||||
pos = rotationMatrix * pos;
|
||||
|
||||
vec2 speed = movement;
|
||||
float waveStrength = 1.0;
|
||||
|
||||
if( i == 0) {
|
||||
speed *= 0.15;
|
||||
waveStrength = 2.0;
|
||||
}
|
||||
|
||||
float small_wave = texture2D(noisetex, pos / wave_size[i] + speed ).b * waveStrength;
|
||||
|
||||
caustic += max( 1.0-sin( 1.0-pow( 0.5+sin( small_wave*3.0 )*0.5, 25.0) ), 0);
|
||||
|
||||
weightSum -= exp2(caustic*0.1);
|
||||
}
|
||||
return caustic / weightSum;
|
||||
}
|
||||
|
||||
void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEyeDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){
|
||||
int spCount = 8;
|
||||
|
||||
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,32.0)/(1e-8+rayLength);
|
||||
dV *= maxZ;
|
||||
vec3 dVWorld = mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ;
|
||||
rayLength *= maxZ;
|
||||
float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength;
|
||||
|
||||
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition;
|
||||
// vec3 WsunVec = mat3(gbufferModelViewInverse) * sunVec * lightCol.a;
|
||||
|
||||
float phase = (phaseg(VdotL,0.6) + phaseg(VdotL,0.8)) * 0.5;
|
||||
|
||||
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); // exponential step position (0-1)
|
||||
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0); //step length (derivative)
|
||||
vec3 spPos = start.xyz + dV*d;
|
||||
progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
|
||||
//project into biased shadowmap space
|
||||
float distortFactor = calcDistort(spPos.xy);
|
||||
vec3 pos = vec3(spPos.xy*distortFactor, spPos.z);
|
||||
|
||||
float sh = 1.0;
|
||||
if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){
|
||||
pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5;
|
||||
sh = shadow2D( shadow, pos).x;
|
||||
}
|
||||
|
||||
sh *= GetCloudShadow_VLFOG(progressW, WsunVec);
|
||||
|
||||
|
||||
vec3 sunMul = exp(-max((estSunDepth - dY * d) ,0.0)/abs(refractedSunVec.y) * waterCoefs);
|
||||
vec3 ambientMul = exp(-max(estEyeDepth - dY * d,0.0) * waterCoefs) * 2.0 ;
|
||||
|
||||
float np3_Y = normalize(mat3(gbufferModelViewInverse) * rayEnd).y;
|
||||
float ambfogfade = clamp(exp(np3_Y*1.5 - 1.5),0.0,1.0) ;
|
||||
|
||||
float sunCaustics = clamp(pow(waterCaustics(progressW, WsunVec)+1,5) * 2.0, phase*0.8+0.2, 1.0);
|
||||
|
||||
|
||||
// make it such that the volume is brighter farther away from the camera.
|
||||
float bubbleOfClearness = max(pow(length(d*dVWorld)/16,5)*100.0,0.0) + 1;
|
||||
float bubbleOfClearness2 = max(pow(length(d*dVWorld)/24,5)*100.0,0.0) + 1;
|
||||
|
||||
vec3 Directlight = (lightSource * sunCaustics * phase * (sunMul+0.5)) * sh * pow(abs(WsunVec.y),2) * bubbleOfClearness;
|
||||
vec3 Indirectlight = max(ambient * ambientMul, vec3(0.6,0.6,1.0) * exp(-waterCoefs) * bubbleOfClearness2) * ambfogfade ;
|
||||
|
||||
vec3 light = (Directlight + Indirectlight) * scatterCoef ;
|
||||
|
||||
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
|
||||
absorbance *= exp(-dd * rayLength * waterCoefs);
|
||||
}
|
||||
inColor += vL;
|
||||
}
|
||||
#endif
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
|
||||
|
||||
void main() {
|
||||
/* DRAWBUFFERS:73 */
|
||||
/* DRAWBUFFERS:0 */
|
||||
|
||||
vec2 texcoord = gl_FragCoord.xy*texelSize;
|
||||
vec2 tc = floor(gl_FragCoord.xy)/VL_RENDER_RESOLUTION*texelSize+0.5*texelSize;
|
||||
float z = texture2D(depthtex0,tc).x;
|
||||
vec3 viewPos = toScreenSpace(vec3(tc/RENDER_SCALE,z));
|
||||
|
||||
vec4 trpData = texture2D(colortex7,texcoord);
|
||||
float noise_1 = blueNoise();
|
||||
float noise_2 = interleaved_gradientNoise();
|
||||
|
||||
bool iswater = trpData.a > 0.99;
|
||||
float translucentAlpha = trpData.a;
|
||||
|
||||
// vec4 speculartex = texture2D(colortex8,texcoord); // translucents
|
||||
// float sunlight = speculartex.b;
|
||||
if (isEyeInWater == 0){
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
vec4 VolumetricFog = GetVolumetricFog(viewPos, noise_1, lightCol.rgb/80.0, averageSkyCol/30.0);
|
||||
#endif
|
||||
#ifdef NETHER_SHADER
|
||||
vec4 VolumetricFog = GetVolumetricFog(viewPos, noise_1, noise_2);
|
||||
#endif
|
||||
#ifdef END_SHADER
|
||||
vec4 VolumetricFog = GetVolumetricFog(viewPos, noise_1, noise_2);
|
||||
#endif
|
||||
|
||||
//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));
|
||||
gl_FragData[0] = clamp(VolumetricFog, 0.0, 65000.0);
|
||||
}
|
||||
|
||||
bool hand = abs(dataUnpacked1.w-0.75) < 0.01;
|
||||
vec2 lightmap = dataUnpacked1.yz;
|
||||
if (isEyeInWater == 1){
|
||||
|
||||
////// --------------- UNPACK TRANSLUCENT GBUFFERS --------------- //////
|
||||
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 data = texture2D(colortex11,texcoord).rgb;
|
||||
#ifdef OVERWORLD_SHADER
|
||||
|
||||
vec4 unpack0 = vec4(decodeVec2(data.r),decodeVec2(data.g)) ;
|
||||
vec4 unpack1 = vec4(decodeVec2(data.b),0,0) ;
|
||||
|
||||
|
||||
float estEyeDepth = 1.0-clamp(eyeBrightnessSmooth.y/240.0,0.,1.0);
|
||||
estEyeDepth = pow(estEyeDepth,3.0) * 32.0;
|
||||
|
||||
vec4 albedo = vec4(unpack0.ba,unpack1.rg);
|
||||
vec3 lightColVol = lightCol.rgb / 80.;
|
||||
|
||||
vec2 tangentNormals = unpack0.xy*2.0-1.0;
|
||||
vec3 lightningColor = (lightningEffect / 3) * (max(eyeBrightnessSmooth.y,0)/240.);
|
||||
vec3 ambientColVol = (averageSkyCol/30.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);
|
||||
vec3 vl = vec3(0.0);
|
||||
waterVolumetrics(vl, vec3(0.0), viewPos, estEyeDepth, estEyeDepth, length(viewPos), noise_1, totEpsilon, scatterCoef, ambientColVol, lightColVol*(1.0-pow(1.0-sunElevation*lightCol.a,5.0)) , dot(normalize(viewPos), normalize(sunVec* lightCol.a ) ));
|
||||
gl_FragData[0] = clamp(vec4(vl,1.0),0.000001,65000.);
|
||||
|
||||
#else
|
||||
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_notoverworld(gl_FragData[0].rgb, fragpos0, viewPos, 1 , 1, 1, blueNoise(), totEpsilon, scatterCoef, ambientColVol);
|
||||
#endif
|
||||
}
|
||||
}
|
@ -1,17 +1,45 @@
|
||||
#include "/lib/settings.glsl"
|
||||
#include "/lib/util.glsl"
|
||||
|
||||
flat varying vec4 lightCol;
|
||||
flat varying vec3 averageSkyCol;
|
||||
|
||||
flat varying vec3 WsunVec;
|
||||
flat varying vec3 refractedSunVec;
|
||||
|
||||
flat varying float tempOffsets;
|
||||
|
||||
uniform sampler2D colortex4;
|
||||
|
||||
uniform float sunElevation;
|
||||
uniform vec3 sunPosition;
|
||||
uniform mat4 gbufferModelViewInverse;
|
||||
uniform int frameCounter;
|
||||
|
||||
|
||||
|
||||
varying vec2 texcoord;
|
||||
flat varying vec3 zMults;
|
||||
uniform float far;
|
||||
uniform float near;
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
|
||||
|
||||
#include "/lib/Shadow_Params.glsl"
|
||||
void main() {
|
||||
zMults = vec3(1.0/(far * near),far+near,far-near);
|
||||
gl_Position = ftransform();
|
||||
texcoord = gl_MultiTexCoord0.xy;
|
||||
|
||||
gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.51*2.0-1.0;
|
||||
|
||||
tempOffsets = HaltonSeq2(frameCounter%10000);
|
||||
|
||||
averageSkyCol = texelFetch2D(colortex4,ivec2(1,37),0).rgb;
|
||||
|
||||
lightCol.a = float(sunElevation > 1e-5)*2.0 - 1.0;
|
||||
lightCol.rgb = texelFetch2D(colortex4,ivec2(6,37),0).rgb;
|
||||
|
||||
WsunVec = lightCol.a * normalize(mat3(gbufferModelViewInverse) * sunPosition);
|
||||
// WsunVec = normalize(LightDir);
|
||||
|
||||
refractedSunVec = refract(WsunVec, -vec3(0.0,1.0,0.0), 1.0/1.33333);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
@ -1,17 +1,17 @@
|
||||
#include "/lib/util.glsl"
|
||||
|
||||
varying vec2 texcoord;
|
||||
flat varying float exposureA;
|
||||
flat varying float tempOffsets;
|
||||
uniform sampler2D colortex4;
|
||||
uniform int frameCounter;
|
||||
|
||||
|
||||
flat varying vec3 zMults;
|
||||
uniform float far;
|
||||
uniform float near;
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
|
||||
void main() {
|
||||
|
||||
tempOffsets = HaltonSeq2(frameCounter%10000);
|
||||
zMults = vec3(1.0/(far * near),far+near,far-near);
|
||||
gl_Position = ftransform();
|
||||
texcoord = gl_MultiTexCoord0.xy;
|
||||
exposureA = texelFetch2D(colortex4,ivec2(10,37),0).r;
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
uniform sampler2D colortex5;
|
||||
uniform vec2 texelSize;
|
||||
uniform float viewWidth;
|
||||
uniform float viewHeight;
|
||||
#include "/lib/settings.glsl"
|
||||
|
||||
uniform sampler2D colortex3;
|
||||
// Compute 3x3 min max for TAA
|
||||
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
@ -9,34 +10,35 @@ uniform float viewHeight;
|
||||
//////////////////////////////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);
|
||||
|
||||
|
||||
/* DRAWBUFFERS:06 */
|
||||
ivec2 center = ivec2(gl_FragCoord.xy);
|
||||
vec3 current = texelFetch2D(colortex3, center, 0).rgb;
|
||||
vec3 cMin = current;
|
||||
vec3 cMax = current;
|
||||
current = texelFetch2D(colortex3, center + ivec2(-1, -1), 0).rgb;
|
||||
cMin = min(cMin, current);
|
||||
cMax = max(cMax, current);
|
||||
current = texelFetch2D(colortex3, center + ivec2(-1, 0), 0).rgb;
|
||||
cMin = min(cMin, current);
|
||||
cMax = max(cMax, current);
|
||||
current = texelFetch2D(colortex3, center + ivec2(-1, 1), 0).rgb;
|
||||
cMin = min(cMin, current);
|
||||
cMax = max(cMax, current);
|
||||
current = texelFetch2D(colortex3, center + ivec2(0, -1), 0).rgb;
|
||||
cMin = min(cMin, current);
|
||||
cMax = max(cMax, current);
|
||||
current = texelFetch2D(colortex3, center + ivec2(0, 1), 0).rgb;
|
||||
cMin = min(cMin, current);
|
||||
cMax = max(cMax, current);
|
||||
current = texelFetch2D(colortex3, center + ivec2(1, -1), 0).rgb;
|
||||
cMin = min(cMin, current);
|
||||
cMax = max(cMax, current);
|
||||
current = texelFetch2D(colortex3, center + ivec2(1, 0), 0).rgb;
|
||||
cMin = min(cMin, current);
|
||||
cMax = max(cMax, current);
|
||||
current = texelFetch2D(colortex3, center + ivec2(1, 1), 0).rgb;
|
||||
cMin = min(cMin, current);
|
||||
cMax = max(cMax, current);
|
||||
gl_FragData[0].rgb = cMax;
|
||||
gl_FragData[1].rgb = cMin;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
uniform float viewWidth;
|
||||
uniform float viewHeight;
|
||||
#include "/lib/settings.glsl"
|
||||
#include "/lib/res_params.glsl"
|
||||
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
@ -7,9 +8,9 @@ uniform float viewHeight;
|
||||
//////////////////////////////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;
|
||||
|
||||
#ifdef TAA_UPSCALING
|
||||
gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0;
|
||||
#endif
|
||||
}
|
||||
|
@ -1,42 +1,286 @@
|
||||
#include "/lib/settings.glsl"
|
||||
#include "/lib/res_params.glsl"
|
||||
|
||||
/*
|
||||
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 colortex6Format = R11F_G11F_B10F; //additionnal buffer for bloom (composite3->final)
|
||||
const int colortex7Format = RGBA8; //Final output, transparencies id (gbuffer->composite4)
|
||||
|
||||
const int colortex11Format = RGBA16; // unchanged translucents albedo, alpha and tangent normals
|
||||
const int colortex15Format = RGBA8; // flat normals and vanilla AO
|
||||
*/
|
||||
|
||||
//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;
|
||||
const bool colortex11Clear = true;
|
||||
|
||||
#ifdef SCREENSHOT_MODE
|
||||
/*
|
||||
const int colortex5Format = RGBA32F; //TAA buffer (everything)
|
||||
*/
|
||||
#else
|
||||
/*
|
||||
const int colortex5Format = R11F_G11F_B10F; //TAA buffer (everything)
|
||||
*/
|
||||
#endif
|
||||
|
||||
|
||||
varying vec2 texcoord;
|
||||
flat varying float tempOffsets;
|
||||
uniform sampler2D colortex0;
|
||||
uniform sampler2D colortex3;
|
||||
uniform sampler2D colortex5;
|
||||
uniform sampler2D colortex6;
|
||||
uniform sampler2D colortex10;
|
||||
uniform sampler2D depthtex0;
|
||||
|
||||
uniform vec2 texelSize;
|
||||
uniform float viewWidth;
|
||||
uniform float frameTimeCounter;
|
||||
uniform int framemod8;
|
||||
uniform float viewHeight;
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
uniform float viewWidth;
|
||||
uniform vec3 previousCameraPosition;
|
||||
uniform mat4 gbufferPreviousModelView;
|
||||
|
||||
void main() {
|
||||
|
||||
/* DRAWBUFFERS:6 */
|
||||
vec2 resScale = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.))/vec2(1920.,1080.);
|
||||
vec2 quarterResTC = gl_FragCoord.xy*2.*texelSize;
|
||||
|
||||
//0.5
|
||||
gl_FragData[0] = texture2D(colortex3,quarterResTC-1.0*vec2(texelSize.x,texelSize.y))/4.*0.5;
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC+1.0*vec2(texelSize.x,texelSize.y))/4.*0.5;
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC+vec2(-1.0*texelSize.x,1.0*texelSize.y))/4.*0.5;
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC+vec2(1.0*texelSize.x,-1.0*texelSize.y))/4.*0.5;
|
||||
|
||||
//0.25
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC-2.0*vec2(texelSize.x,0.0))/2.*0.125;
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC+2.0*vec2(0.0,texelSize.y))/2.*0.125;
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC+2.0*vec2(0,-texelSize.y))/2*0.125;
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC+2.0*vec2(-texelSize.x,0.0))/2*0.125;
|
||||
|
||||
//0.125
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC-2.0*vec2(texelSize.x,texelSize.y))/4.*0.125;
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC+2.0*vec2(texelSize.x,texelSize.y))/4.*0.125;
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC+vec2(-2.0*texelSize.x,2.0*texelSize.y))/4.*0.125;
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC+vec2(2.0*texelSize.x,-2.0*texelSize.y))/4.*0.125;
|
||||
|
||||
//0.125
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC)*0.125;
|
||||
|
||||
gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.);
|
||||
uniform int hideGUI;
|
||||
|
||||
|
||||
|
||||
|
||||
#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);
|
||||
}
|
||||
vec4 fp10Dither(vec4 color ,float dither){
|
||||
const vec3 mantissaBits = vec3(6.,6.,5.);
|
||||
vec3 exponent = floor(log2(color.rgb));
|
||||
return vec4(color.rgb + dither*exp2(-mantissaBits)*exp2(exponent), color.a);
|
||||
}
|
||||
|
||||
//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);
|
||||
}
|
||||
//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;
|
||||
|
||||
#ifdef TAA_UPSCALING
|
||||
dmin.xy = dmin.xy/RENDER_SCALE;
|
||||
#endif
|
||||
|
||||
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.);
|
||||
|
||||
vec4 TAA_hq(){
|
||||
|
||||
#ifdef TAA_UPSCALING
|
||||
vec2 adjTC = clamp(texcoord*RENDER_SCALE, vec2(0.0), RENDER_SCALE - texelSize*2.0);
|
||||
#else
|
||||
vec2 adjTC = texcoord;
|
||||
#endif
|
||||
|
||||
//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 viewPos = toScreenSpace(closestToCamera);
|
||||
viewPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition);
|
||||
|
||||
vec3 previousPosition = mat3(gbufferPreviousModelView) * viewPos + 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 vec4(smoothfilter(colortex3, adjTC + offsets[framemod8]*texelSize*0.5).xyz,1.0);
|
||||
|
||||
|
||||
#ifdef TAA_UPSCALING
|
||||
vec3 albedoCurrent0 = smoothfilter(colortex3, adjTC + offsets[framemod8]*texelSize*0.5).xyz;
|
||||
// Interpolating neighboorhood clampling boundaries between pixels
|
||||
vec3 cMax = texture2D(colortex0, adjTC).rgb;
|
||||
vec3 cMin = texture2D(colortex6, adjTC).rgb;
|
||||
#else
|
||||
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;
|
||||
#endif
|
||||
|
||||
#ifndef SCREENSHOT_MODE
|
||||
vec3 albedoPrev = max(FastCatmulRom(colortex5, previousPosition.xy,vec4(texelSize, 1.0/texelSize), 0.75).xyz, 0.0);
|
||||
vec3 finalcAcc = clamp(albedoPrev, cMin, cMax);
|
||||
|
||||
//Increases blending factor when far from AABB and in motion, reduces ghosting
|
||||
float isclamped = distance(albedoPrev,finalcAcc)/luma(albedoPrev) * 0.5;
|
||||
float movementRejection = (0.12+isclamped)*clamp(length(velocity/texelSize),0.0,1.0);
|
||||
|
||||
//Blend current pixel with clamped history, apply fast tonemap beforehand to reduce flickering
|
||||
vec4 supersampled = vec4(invTonemap(mix(tonemap(finalcAcc), tonemap(albedoCurrent0), clamp(BLEND_FACTOR + movementRejection, 0.0,1.0))), 1.0);
|
||||
|
||||
//De-tonemap
|
||||
return supersampled;
|
||||
#endif
|
||||
|
||||
#ifdef SCREENSHOT_MODE
|
||||
vec4 albedoPrev = texture2D(colortex5, previousPosition.xy);
|
||||
vec3 supersampled = albedoPrev.rgb * albedoPrev.a + albedoCurrent0;
|
||||
|
||||
if (length(velocity) > 1e-6 || hideGUI < 1) return vec4(albedoCurrent0,1.0);
|
||||
return vec4(supersampled/(albedoPrev.a+1.0), albedoPrev.a+1.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void main() {
|
||||
/* DRAWBUFFERS:5 */
|
||||
|
||||
gl_FragData[0].a = 1.0;
|
||||
|
||||
#ifdef TAA
|
||||
vec4 color = TAA_hq();
|
||||
|
||||
#ifdef SCREENSHOT_MODE
|
||||
gl_FragData[0] = clamp(color, 0.0, 65000.0);
|
||||
#else
|
||||
gl_FragData[0] = clamp(fp10Dither(color, triangularize(interleaved_gradientNoise())), 0.0, 65000.0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef TAA
|
||||
vec3 color = clamp(fp10Dither(texture2D(colortex3,texcoord).rgb, triangularize(interleaved_gradientNoise())),0.0,65000.);
|
||||
gl_FragData[0].rgb = color;
|
||||
#endif
|
||||
}
|
@ -1,15 +1,29 @@
|
||||
uniform float viewWidth;
|
||||
uniform float viewHeight;
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
#include "/lib/util.glsl"
|
||||
#include "/lib/res_params.glsl"
|
||||
|
||||
varying vec2 texcoord;
|
||||
flat varying float tempOffsets;
|
||||
uniform sampler2D colortex4;
|
||||
uniform int frameCounter;
|
||||
|
||||
|
||||
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() {
|
||||
//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.26/clampedRes*vec2(1920.0,1080.)*2-1.0;
|
||||
texcoord = gl_MultiTexCoord0.xy;
|
||||
|
||||
tempOffsets = HaltonSeq2(frameCounter%10000);
|
||||
|
||||
#ifdef TAA_UPSCALING
|
||||
gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0;
|
||||
#endif
|
||||
}
|
||||
|
@ -1,22 +1,7 @@
|
||||
uniform sampler2D colortex6;
|
||||
uniform sampler2D colortex5;
|
||||
uniform vec2 texelSize;
|
||||
varying vec2 texcoord;
|
||||
uniform float viewWidth;
|
||||
uniform float viewHeight;
|
||||
vec2 resScale = vec2(1920.,1080.)/max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.));
|
||||
vec3 gauss1D(vec2 coord,vec2 dir,float alpha,int maxIT){
|
||||
vec4 tot = vec4(0.);
|
||||
float maxTC = 0.25*resScale.x;
|
||||
float minTC = 0.;
|
||||
for (int i = -maxIT;i<maxIT+1;i++){
|
||||
float weight = exp(-i*i*alpha*4.0);
|
||||
//here we take advantage of bilinear filtering for 2x less sample, as a side effect the gaussian won't be totally centered for small blurs
|
||||
vec2 spCoord = coord+dir*texelSize*(2.0*i+0.5);
|
||||
tot += vec4(texture2D(colortex6,spCoord).rgb,1.0)*weight*float(spCoord.x > minTC && spCoord.x < maxTC);
|
||||
}
|
||||
return tot.rgb/max(1.0,tot.a);
|
||||
}
|
||||
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
@ -24,34 +9,35 @@ vec3 gauss1D(vec2 coord,vec2 dir,float alpha,int maxIT){
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
|
||||
void main() {
|
||||
/* DRAWBUFFERS:6 */
|
||||
|
||||
vec2 texcoord = (gl_FragCoord.xy*vec2(2.0,4.0))*texelSize;
|
||||
vec2 gaussDir = vec2(1.0,0.0);
|
||||
gl_FragData[0].rgb = vec3(0.0);
|
||||
vec2 tc2 = texcoord*vec2(2.0,1.)/2.;
|
||||
if (tc2.x < 1.0*resScale.x && tc2.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(tc2/2,gaussDir,0.16,0);
|
||||
/* DRAWBUFFERS:3 */
|
||||
|
||||
vec2 tc4 = texcoord*vec2(4.0,1.)/2.-vec2(0.5*resScale.x+4.0*texelSize.x,0.)*2.0;
|
||||
if (tc4.x > 0.0 && tc4.y > 0.0 && tc4.x < 1.0*resScale.x && tc4.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(tc4/2,gaussDir,0.16,3);
|
||||
vec2 resScale = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.))/vec2(1920.,1080.);
|
||||
vec2 quarterResTC = gl_FragCoord.xy*2.*resScale*texelSize;
|
||||
|
||||
vec2 tc8 = texcoord*vec2(8.0,1.)/2.-vec2(0.75*resScale.x+8.*texelSize.x,0.)*4.0;
|
||||
if (tc8.x > 0.0 && tc8.y > 0.0 && tc8.x < 1.0*resScale.x && tc8.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(tc8/2,gaussDir,0.035,6);
|
||||
//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;
|
||||
|
||||
vec2 tc16 = texcoord*vec2(8.0,1./2.)-vec2(0.875*resScale.x+12.*texelSize.x,0.)*8.0;
|
||||
if (tc16.x > 0.0 && tc16.y > 0.0 && tc16.x < 1.0*resScale.x && tc16.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(tc16/2,gaussDir,0.0085,12);
|
||||
//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;
|
||||
|
||||
vec2 tc32 = texcoord*vec2(16.0,1./2.)-vec2(0.9375*resScale.x+16.*texelSize.x,0.)*16.0;
|
||||
if (tc32.x > 0.0 && tc32.y > 0.0 && tc32.x < 1.0*resScale.x && tc32.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(tc32/2,gaussDir,0.002,28);
|
||||
//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);
|
||||
|
||||
vec2 tc64 = texcoord*vec2(32.0,1./2.)-vec2(0.96875*resScale.x+20.*texelSize.x,0.)*32.0;
|
||||
if (tc64.x > 0.0 && tc64.y > 0.0 && tc64.x < 1.0*resScale.x && tc64.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(tc64/2,gaussDir,0.0005,60);
|
||||
|
||||
gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
uniform float viewWidth;
|
||||
uniform float viewHeight;
|
||||
varying vec2 texcoord;
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
@ -8,11 +7,9 @@ varying vec2 texcoord;
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
|
||||
void main() {
|
||||
vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.0));
|
||||
//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-0.25
|
||||
gl_Position.y = (gl_Position.y*0.5+0.5)*0.25/clampedRes.y*1080.0*2.0-1.0;
|
||||
//0-0.5
|
||||
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.);
|
||||
//*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;
|
||||
}
|
||||
|
@ -1,21 +1,7 @@
|
||||
uniform sampler2D colortex6;
|
||||
uniform sampler2D colortex3;
|
||||
uniform vec2 texelSize;
|
||||
varying vec2 texcoord;
|
||||
uniform float viewWidth;
|
||||
uniform float viewHeight;
|
||||
vec2 resScale = vec2(1920.,1080.)/max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.));
|
||||
vec3 gauss1D(vec2 coord,vec2 dir,float alpha,int maxIT){
|
||||
vec4 tot = vec4(0.);
|
||||
float maxTC = 0.25*resScale.y;
|
||||
float minTC = 0.;
|
||||
for (int i = -maxIT;i<maxIT+1;i++){
|
||||
float weight = exp(-i*i*alpha*4.0);
|
||||
vec2 spCoord = coord+dir*texelSize*(2.0*i+0.5);
|
||||
tot += vec4(texture2D(colortex6,spCoord).rgb,1.0)*weight*float(spCoord.y > minTC && spCoord.y < maxTC);
|
||||
}
|
||||
return tot.rgb/max(1.0,tot.a);
|
||||
}
|
||||
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
@ -23,34 +9,34 @@ vec3 gauss1D(vec2 coord,vec2 dir,float alpha,int maxIT){
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
|
||||
void main() {
|
||||
|
||||
/* DRAWBUFFERS:6 */
|
||||
vec2 texcoord = (gl_FragCoord.xy*vec2(2.0,4.0))*texelSize;
|
||||
vec2 resScale = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.))/vec2(1920.,1080.);
|
||||
vec2 quarterResTC = gl_FragCoord.xy*2.*texelSize;
|
||||
|
||||
vec2 gaussDir = vec2(0.0,1.0);
|
||||
gl_FragData[0].rgb = vec3(0.0);
|
||||
vec2 tc2 = texcoord*vec2(2.0,1.);
|
||||
if (tc2.x < 1.0*resScale.x && tc2.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(texcoord/vec2(2.0,4.0),gaussDir,0.16,0);
|
||||
//0.5
|
||||
gl_FragData[0] = texture2D(colortex3,quarterResTC-1.0*vec2(texelSize.x,texelSize.y))/4.*0.5;
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC+1.0*vec2(texelSize.x,texelSize.y))/4.*0.5;
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC+vec2(-1.0*texelSize.x,1.0*texelSize.y))/4.*0.5;
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC+vec2(1.0*texelSize.x,-1.0*texelSize.y))/4.*0.5;
|
||||
|
||||
vec2 tc4 = texcoord*vec2(4.0,2.)-vec2(0.5*resScale.x+4.0*texelSize.x,0.)*4.0;
|
||||
if (tc4.x > 0.0 && tc4.y > 0.0 && tc4.x < 1.0*resScale.x && tc4.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(texcoord/vec2(2.0,2.0),gaussDir,0.16,3);
|
||||
//0.25
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC-2.0*vec2(texelSize.x,0.0))/2.*0.125;
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC+2.0*vec2(0.0,texelSize.y))/2.*0.125;
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC+2.0*vec2(0,-texelSize.y))/2*0.125;
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC+2.0*vec2(-texelSize.x,0.0))/2*0.125;
|
||||
|
||||
vec2 tc8 = texcoord*vec2(8.0,4.)-vec2(0.75*resScale.x+8.*texelSize.x,0.)*8.0;
|
||||
if (tc8.x > 0.0 && tc8.y > 0.0 && tc8.x < 1.0*resScale.x && tc8.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(texcoord*vec2(1.0,2.0)/vec2(2.0,2.0),gaussDir,0.035,6);
|
||||
//0.125
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC-2.0*vec2(texelSize.x,texelSize.y))/4.*0.125;
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC+2.0*vec2(texelSize.x,texelSize.y))/4.*0.125;
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC+vec2(-2.0*texelSize.x,2.0*texelSize.y))/4.*0.125;
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC+vec2(2.0*texelSize.x,-2.0*texelSize.y))/4.*0.125;
|
||||
|
||||
vec2 tc16 = texcoord*vec2(16.0,8.)-vec2(0.875*resScale.x+12.*texelSize.x,0.)*16.0;
|
||||
if (tc16.x > 0.0 && tc16.y > 0.0 && tc16.x < 1.0*resScale.x && tc16.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(texcoord*vec2(1.0,4.0)/vec2(2.0,2.0),gaussDir,0.0085,12);
|
||||
//0.125
|
||||
gl_FragData[0] += texture2D(colortex3,quarterResTC)*0.125;
|
||||
|
||||
gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.);
|
||||
|
||||
vec2 tc32 = texcoord*vec2(32.0,16.)-vec2(0.9375*resScale.x+16.*texelSize.x,0.)*32.0;
|
||||
if (tc32.x > 0.0 && tc32.y > 0.0 && tc32.x < 1.0*resScale.x && tc32.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(texcoord*vec2(1.0,8.0)/vec2(2.0,2.0),gaussDir,0.002,30);
|
||||
|
||||
vec2 tc64 = texcoord*vec2(64.0,32.)-vec2(0.96875*resScale.x+20.*texelSize.x,0.)*64.0;
|
||||
if (tc64.x > 0.0 && tc64.y > 0.0 && tc64.x < 1.0*resScale.x && tc64.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(texcoord*vec2(1.0,16.0)/vec2(2.0,2.0),gaussDir,0.0005,60);
|
||||
|
||||
gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
uniform float viewWidth;
|
||||
uniform float viewHeight;
|
||||
varying vec2 texcoord;
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
@ -8,12 +7,9 @@ varying vec2 texcoord;
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
|
||||
void main() {
|
||||
vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.0));
|
||||
//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-0.25
|
||||
gl_Position.y = (gl_Position.y*0.5+0.5)*0.25/clampedRes.y*1080.0*2.0-1.0;
|
||||
//0-0.5
|
||||
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.);
|
||||
|
||||
//*0.51 to avoid errors when sampling outside since clearing is disabled
|
||||
gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.26/clampedRes*vec2(1920.0,1080.)*2-1.0;
|
||||
}
|
||||
|
@ -1,73 +1,20 @@
|
||||
uniform sampler2D colortex3;
|
||||
uniform sampler2D colortex6;
|
||||
|
||||
uniform vec2 texelSize;
|
||||
varying vec2 texcoord;
|
||||
uniform float viewWidth;
|
||||
uniform float viewHeight;
|
||||
|
||||
float w0(float a)
|
||||
{
|
||||
return (1.0/6.0)*(a*(a*(-a + 3.0) - 3.0) + 1.0);
|
||||
}
|
||||
|
||||
float w1(float a)
|
||||
{
|
||||
return (1.0/6.0)*(a*a*(3.0*a - 6.0) + 4.0);
|
||||
}
|
||||
|
||||
float w2(float a)
|
||||
{
|
||||
return (1.0/6.0)*(a*(a*(-3.0*a + 3.0) + 3.0) + 1.0);
|
||||
}
|
||||
|
||||
float w3(float a)
|
||||
{
|
||||
return (1.0/6.0)*(a*a*a);
|
||||
}
|
||||
|
||||
float g0(float a)
|
||||
{
|
||||
return w0(a) + w1(a);
|
||||
}
|
||||
|
||||
float g1(float a)
|
||||
{
|
||||
return w2(a) + w3(a);
|
||||
}
|
||||
|
||||
float h0(float a)
|
||||
{
|
||||
return -1.0 + w1(a) / (w0(a) + w1(a));
|
||||
}
|
||||
|
||||
float h1(float a)
|
||||
{
|
||||
return 1.0 + w3(a) / (w2(a) + w3(a));
|
||||
}
|
||||
|
||||
vec4 texture2D_bicubic(sampler2D tex, vec2 uv)
|
||||
{
|
||||
vec4 texelSize = vec4(texelSize,1.0/texelSize);
|
||||
uv = uv*texelSize.zw;
|
||||
vec2 iuv = floor( uv );
|
||||
vec2 fuv = fract( uv );
|
||||
|
||||
float g0x = g0(fuv.x);
|
||||
float g1x = g1(fuv.x);
|
||||
float h0x = h0(fuv.x);
|
||||
float h1x = h1(fuv.x);
|
||||
float h0y = h0(fuv.y);
|
||||
float h1y = h1(fuv.y);
|
||||
|
||||
vec2 p0 = (vec2(iuv.x + h0x, iuv.y + h0y) - 0.5) * texelSize.xy;
|
||||
vec2 p1 = (vec2(iuv.x + h1x, iuv.y + h0y) - 0.5) * texelSize.xy;
|
||||
vec2 p2 = (vec2(iuv.x + h0x, iuv.y + h1y) - 0.5) * texelSize.xy;
|
||||
vec2 p3 = (vec2(iuv.x + h1x, iuv.y + h1y) - 0.5) * texelSize.xy;
|
||||
|
||||
return g0(fuv.y) * (g0x * texture2D(tex, p0) +
|
||||
g1x * texture2D(tex, p1)) +
|
||||
g1(fuv.y) * (g0x * texture2D(tex, p2) +
|
||||
g1x * texture2D(tex, p3));
|
||||
vec2 resScale = vec2(1920.,1080.)/max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.));
|
||||
vec3 gauss1D(vec2 coord,vec2 dir,float alpha,int maxIT){
|
||||
vec4 tot = vec4(0.);
|
||||
float maxTC = 0.25*resScale.x;
|
||||
float minTC = 0.;
|
||||
for (int i = -maxIT;i<maxIT+1;i++){
|
||||
float weight = exp(-i*i*alpha*4.0);
|
||||
//here we take advantage of bilinear filtering for 2x less sample, as a side effect the gaussian won't be totally centered for small blurs
|
||||
vec2 spCoord = coord+dir*texelSize*(2.0*i+0.5);
|
||||
tot += vec4(texture2D(colortex6,spCoord).rgb,1.0)*weight*float(spCoord.x > minTC && spCoord.x < maxTC);
|
||||
}
|
||||
return tot.rgb/max(1.0,tot.a);
|
||||
}
|
||||
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
@ -77,24 +24,34 @@ vec4 texture2D_bicubic(sampler2D tex, vec2 uv)
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
|
||||
void main() {
|
||||
/* DRAWBUFFERS:3 */
|
||||
vec2 resScale = vec2(1920.,1080.)/max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.));
|
||||
vec2 texcoord = ((gl_FragCoord.xy)*2.+0.5)*texelSize;
|
||||
vec3 bloom = texture2D_bicubic(colortex3,texcoord/2.0).rgb; //1/4 res
|
||||
/* DRAWBUFFERS:6 */
|
||||
|
||||
bloom += texture2D_bicubic(colortex6,texcoord/4.).rgb; //1/8 res
|
||||
vec2 texcoord = (gl_FragCoord.xy*vec2(2.0,4.0))*texelSize;
|
||||
vec2 gaussDir = vec2(1.0,0.0);
|
||||
gl_FragData[0].rgb = vec3(0.0);
|
||||
vec2 tc2 = texcoord*vec2(2.0,1.)/2.;
|
||||
if (tc2.x < 1.0*resScale.x && tc2.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(tc2/2,gaussDir,0.16,0);
|
||||
|
||||
bloom += texture2D_bicubic(colortex6,texcoord/8.+vec2(0.25*resScale.x+2.5*texelSize.x,.0)).rgb; //1/16 res
|
||||
vec2 tc4 = texcoord*vec2(4.0,1.)/2.-vec2(0.5*resScale.x+4.0*texelSize.x,0.)*2.0;
|
||||
if (tc4.x > 0.0 && tc4.y > 0.0 && tc4.x < 1.0*resScale.x && tc4.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(tc4/2,gaussDir,0.16,3);
|
||||
|
||||
bloom += texture2D_bicubic(colortex6,texcoord/16.+vec2(0.375*resScale.x+4.5*texelSize.x,.0)).rgb; //1/32 res
|
||||
vec2 tc8 = texcoord*vec2(8.0,1.)/2.-vec2(0.75*resScale.x+8.*texelSize.x,0.)*4.0;
|
||||
if (tc8.x > 0.0 && tc8.y > 0.0 && tc8.x < 1.0*resScale.x && tc8.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(tc8/2,gaussDir,0.035,6);
|
||||
|
||||
bloom += texture2D_bicubic(colortex6,texcoord/32.+vec2(0.4375*resScale.x+6.5*texelSize.x,.0)).rgb*1.0; //1/64 res
|
||||
bloom += texture2D_bicubic(colortex6,texcoord/64.+vec2(0.46875*resScale.x+8.5*texelSize.x,.0)).rgb*1.0; //1/128 res
|
||||
bloom += texture2D_bicubic(colortex6,texcoord/128.+vec2(0.484375*resScale.x+10.5*texelSize.x,.0)).rgb*1.0; //1/256 res
|
||||
vec2 tc16 = texcoord*vec2(8.0,1./2.)-vec2(0.875*resScale.x+12.*texelSize.x,0.)*8.0;
|
||||
if (tc16.x > 0.0 && tc16.y > 0.0 && tc16.x < 1.0*resScale.x && tc16.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(tc16/2,gaussDir,0.0085,12);
|
||||
|
||||
//bloom = texture2D_bicubic(colortex6,texcoord).rgb*6.; //1/8 res
|
||||
vec2 tc32 = texcoord*vec2(16.0,1./2.)-vec2(0.9375*resScale.x+16.*texelSize.x,0.)*16.0;
|
||||
if (tc32.x > 0.0 && tc32.y > 0.0 && tc32.x < 1.0*resScale.x && tc32.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(tc32/2,gaussDir,0.002,28);
|
||||
|
||||
gl_FragData[0].rgb = bloom*2.;
|
||||
vec2 tc64 = texcoord*vec2(32.0,1./2.)-vec2(0.96875*resScale.x+20.*texelSize.x,0.)*32.0;
|
||||
if (tc64.x > 0.0 && tc64.y > 0.0 && tc64.x < 1.0*resScale.x && tc64.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(tc64/2,gaussDir,0.0005,60);
|
||||
|
||||
gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
uniform float viewWidth;
|
||||
uniform float viewHeight;
|
||||
varying vec2 texcoord;
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
@ -7,9 +8,11 @@ uniform float viewHeight;
|
||||
//////////////////////////////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.));
|
||||
vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.0));
|
||||
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;
|
||||
//0-0.25
|
||||
gl_Position.y = (gl_Position.y*0.5+0.5)*0.25/clampedRes.y*1080.0*2.0-1.0;
|
||||
//0-0.5
|
||||
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.);
|
||||
}
|
||||
|
@ -1,473 +1,56 @@
|
||||
#include "/lib/settings.glsl"
|
||||
|
||||
#ifdef DOF
|
||||
//hexagon pattern
|
||||
const vec2 hex_offsets[60] = vec2[60] ( vec2( 0.2165, 0.1250 ),
|
||||
vec2( 0.0000, 0.2500 ),
|
||||
vec2( -0.2165, 0.1250 ),
|
||||
vec2( -0.2165, -0.1250 ),
|
||||
vec2( -0.0000, -0.2500 ),
|
||||
vec2( 0.2165, -0.1250 ),
|
||||
vec2( 0.4330, 0.2500 ),
|
||||
vec2( 0.0000, 0.5000 ),
|
||||
vec2( -0.4330, 0.2500 ),
|
||||
vec2( -0.4330, -0.2500 ),
|
||||
vec2( -0.0000, -0.5000 ),
|
||||
vec2( 0.4330, -0.2500 ),
|
||||
vec2( 0.6495, 0.3750 ),
|
||||
vec2( 0.0000, 0.7500 ),
|
||||
vec2( -0.6495, 0.3750 ),
|
||||
vec2( -0.6495, -0.3750 ),
|
||||
vec2( -0.0000, -0.7500 ),
|
||||
vec2( 0.6495, -0.3750 ),
|
||||
vec2( 0.8660, 0.5000 ),
|
||||
vec2( 0.0000, 1.0000 ),
|
||||
vec2( -0.8660, 0.5000 ),
|
||||
vec2( -0.8660, -0.5000 ),
|
||||
vec2( -0.0000, -1.0000 ),
|
||||
vec2( 0.8660, -0.5000 ),
|
||||
vec2( 0.2163, 0.3754 ),
|
||||
vec2( -0.2170, 0.3750 ),
|
||||
vec2( -0.4333, -0.0004 ),
|
||||
vec2( -0.2163, -0.3754 ),
|
||||
vec2( 0.2170, -0.3750 ),
|
||||
vec2( 0.4333, 0.0004 ),
|
||||
vec2( 0.4328, 0.5004 ),
|
||||
vec2( -0.2170, 0.6250 ),
|
||||
vec2( -0.6498, 0.1246 ),
|
||||
vec2( -0.4328, -0.5004 ),
|
||||
vec2( 0.2170, -0.6250 ),
|
||||
vec2( 0.6498, -0.1246 ),
|
||||
vec2( 0.6493, 0.6254 ),
|
||||
vec2( -0.2170, 0.8750 ),
|
||||
vec2( -0.8663, 0.2496 ),
|
||||
vec2( -0.6493, -0.6254 ),
|
||||
vec2( 0.2170, -0.8750 ),
|
||||
vec2( 0.8663, -0.2496 ),
|
||||
vec2( 0.2160, 0.6259 ),
|
||||
vec2( -0.4340, 0.5000 ),
|
||||
vec2( -0.6500, -0.1259 ),
|
||||
vec2( -0.2160, -0.6259 ),
|
||||
vec2( 0.4340, -0.5000 ),
|
||||
vec2( 0.6500, 0.1259 ),
|
||||
vec2( 0.4325, 0.7509 ),
|
||||
vec2( -0.4340, 0.7500 ),
|
||||
vec2( -0.8665, -0.0009 ),
|
||||
vec2( -0.4325, -0.7509 ),
|
||||
vec2( 0.4340, -0.7500 ),
|
||||
vec2( 0.8665, 0.0009 ),
|
||||
vec2( 0.2158, 0.8763 ),
|
||||
vec2( -0.6510, 0.6250 ),
|
||||
vec2( -0.8668, -0.2513 ),
|
||||
vec2( -0.2158, -0.8763 ),
|
||||
vec2( 0.6510, -0.6250 ),
|
||||
vec2( 0.8668, 0.2513 ));
|
||||
|
||||
const vec2 offsets[60] = vec2[60] ( vec2( 0.0000, 0.2500 ),
|
||||
vec2( -0.2165, 0.1250 ),
|
||||
vec2( -0.2165, -0.1250 ),
|
||||
vec2( -0.0000, -0.2500 ),
|
||||
vec2( 0.2165, -0.1250 ),
|
||||
vec2( 0.2165, 0.1250 ),
|
||||
vec2( 0.0000, 0.5000 ),
|
||||
vec2( -0.2500, 0.4330 ),
|
||||
vec2( -0.4330, 0.2500 ),
|
||||
vec2( -0.5000, 0.0000 ),
|
||||
vec2( -0.4330, -0.2500 ),
|
||||
vec2( -0.2500, -0.4330 ),
|
||||
vec2( -0.0000, -0.5000 ),
|
||||
vec2( 0.2500, -0.4330 ),
|
||||
vec2( 0.4330, -0.2500 ),
|
||||
vec2( 0.5000, -0.0000 ),
|
||||
vec2( 0.4330, 0.2500 ),
|
||||
vec2( 0.2500, 0.4330 ),
|
||||
vec2( 0.0000, 0.7500 ),
|
||||
vec2( -0.2565, 0.7048 ),
|
||||
vec2( -0.4821, 0.5745 ),
|
||||
vec2( -0.6495, 0.3750 ),
|
||||
vec2( -0.7386, 0.1302 ),
|
||||
vec2( -0.7386, -0.1302 ),
|
||||
vec2( -0.6495, -0.3750 ),
|
||||
vec2( -0.4821, -0.5745 ),
|
||||
vec2( -0.2565, -0.7048 ),
|
||||
vec2( -0.0000, -0.7500 ),
|
||||
vec2( 0.2565, -0.7048 ),
|
||||
vec2( 0.4821, -0.5745 ),
|
||||
vec2( 0.6495, -0.3750 ),
|
||||
vec2( 0.7386, -0.1302 ),
|
||||
vec2( 0.7386, 0.1302 ),
|
||||
vec2( 0.6495, 0.3750 ),
|
||||
vec2( 0.4821, 0.5745 ),
|
||||
vec2( 0.2565, 0.7048 ),
|
||||
vec2( 0.0000, 1.0000 ),
|
||||
vec2( -0.2588, 0.9659 ),
|
||||
vec2( -0.5000, 0.8660 ),
|
||||
vec2( -0.7071, 0.7071 ),
|
||||
vec2( -0.8660, 0.5000 ),
|
||||
vec2( -0.9659, 0.2588 ),
|
||||
vec2( -1.0000, 0.0000 ),
|
||||
vec2( -0.9659, -0.2588 ),
|
||||
vec2( -0.8660, -0.5000 ),
|
||||
vec2( -0.7071, -0.7071 ),
|
||||
vec2( -0.5000, -0.8660 ),
|
||||
vec2( -0.2588, -0.9659 ),
|
||||
vec2( -0.0000, -1.0000 ),
|
||||
vec2( 0.2588, -0.9659 ),
|
||||
vec2( 0.5000, -0.8660 ),
|
||||
vec2( 0.7071, -0.7071 ),
|
||||
vec2( 0.8660, -0.5000 ),
|
||||
vec2( 0.9659, -0.2588 ),
|
||||
vec2( 1.0000, -0.0000 ),
|
||||
vec2( 0.9659, 0.2588 ),
|
||||
vec2( 0.8660, 0.5000 ),
|
||||
vec2( 0.7071, 0.7071 ),
|
||||
vec2( 0.5000, 0.8660 ),
|
||||
vec2( 0.2588, 0.9659 ));
|
||||
|
||||
const vec2 shadow_offsets[209] = vec2[209](vec2(0.8886414f , 0.07936136f),
|
||||
vec2(0.8190064f , 0.1900164f),
|
||||
vec2(0.8614115f , -0.06991258f),
|
||||
vec2(0.7685533f , 0.03792081f),
|
||||
vec2(0.9970094f , 0.02585129f),
|
||||
vec2(0.9686818f , 0.1570935f),
|
||||
vec2(0.9854341f , -0.09172997f),
|
||||
vec2(0.9330608f , 0.3326486f),
|
||||
vec2(0.8329557f , -0.2438523f),
|
||||
vec2(0.664771f , -0.0837701f),
|
||||
vec2(0.7429124f , -0.1530652f),
|
||||
vec2(0.9506453f , -0.2174281f),
|
||||
vec2(0.8192949f , 0.3485171f),
|
||||
vec2(0.6851269f , 0.2711877f),
|
||||
vec2(0.7665657f , 0.5014166f),
|
||||
vec2(0.673241f , 0.3793408f),
|
||||
vec2(0.6981376f , 0.1465924f),
|
||||
vec2(0.6521665f , -0.2384985f),
|
||||
vec2(0.5145761f , -0.05752508f),
|
||||
vec2(0.5641244f , -0.169443f),
|
||||
vec2(0.5916035f , 0.06004957f),
|
||||
vec2(0.57079f , 0.234188f),
|
||||
vec2(0.509311f , 0.1523665f),
|
||||
vec2(0.4204576f , 0.05759521f),
|
||||
vec2(0.8200846f , -0.3601041f),
|
||||
vec2(0.6893264f , -0.3473432f),
|
||||
vec2(0.4775535f , -0.3062558f),
|
||||
vec2(0.438106f , -0.1796866f),
|
||||
vec2(0.4056528f , -0.08251233f),
|
||||
vec2(0.5771964f , 0.5502692f),
|
||||
vec2(0.5094061f , 0.4025192f),
|
||||
vec2(0.6908483f , 0.572951f),
|
||||
vec2(0.5379036f , -0.4542191f),
|
||||
vec2(0.8167359f , -0.4793735f),
|
||||
vec2(0.6829269f , -0.4557574f),
|
||||
vec2(0.5725697f , -0.3477072f),
|
||||
vec2(0.5767449f , -0.5782524f),
|
||||
vec2(0.3979413f , -0.4172934f),
|
||||
vec2(0.4282598f , -0.5145645f),
|
||||
vec2(0.938814f , -0.3239739f),
|
||||
vec2(0.702452f , -0.5662871f),
|
||||
vec2(0.2832307f , -0.1285671f),
|
||||
vec2(0.3230537f , -0.2691054f),
|
||||
vec2(0.2921676f , -0.3734582f),
|
||||
vec2(0.2534037f , -0.4906001f),
|
||||
vec2(0.4343273f , 0.5223463f),
|
||||
vec2(0.3605334f , 0.3151571f),
|
||||
vec2(0.3498518f , 0.451428f),
|
||||
vec2(0.3230703f , 0.00287089f),
|
||||
vec2(0.1049206f , -0.1476725f),
|
||||
vec2(0.2063161f , -0.2608192f),
|
||||
vec2(0.7266634f , 0.6725333f),
|
||||
vec2(0.4027067f , -0.6185485f),
|
||||
vec2(0.2655533f , -0.5912259f),
|
||||
vec2(0.4947965f , 0.3025357f),
|
||||
vec2(0.5760762f , 0.68844f),
|
||||
vec2(0.4909205f , -0.6975324f),
|
||||
vec2(0.8609334f , 0.4559f),
|
||||
vec2(0.1836646f , 0.03724086f),
|
||||
vec2(0.2878554f , 0.178938f),
|
||||
vec2(0.3948484f , 0.1618928f),
|
||||
vec2(0.3519658f , -0.7628763f),
|
||||
vec2(0.6338583f , -0.673193f),
|
||||
vec2(0.5511802f , -0.8283072f),
|
||||
vec2(0.4090595f , -0.8717521f),
|
||||
vec2(0.1482169f , -0.374728f),
|
||||
vec2(0.1050598f , -0.2613987f),
|
||||
vec2(0.4210334f , 0.6578422f),
|
||||
vec2(0.2430464f , 0.4383665f),
|
||||
vec2(0.3329675f , 0.5512741f),
|
||||
vec2(0.2147711f , 0.3245511f),
|
||||
vec2(0.1227196f , 0.2529026f),
|
||||
vec2(-0.03937457f , 0.156439f),
|
||||
vec2(0.05618772f , 0.06690486f),
|
||||
vec2(0.06519571f , 0.3974038f),
|
||||
vec2(0.1360903f , 0.1466078f),
|
||||
vec2(-0.00170609f , 0.3089452f),
|
||||
vec2(0.1357622f , -0.5088975f),
|
||||
vec2(0.1604694f , -0.7453476f),
|
||||
vec2(0.1245694f , -0.6337074f),
|
||||
vec2(0.02542936f , -0.3728781f),
|
||||
vec2(0.02222222f , -0.649554f),
|
||||
vec2(0.09870815f , 0.5357338f),
|
||||
vec2(0.2073958f , 0.5452989f),
|
||||
vec2(0.216654f , -0.8935689f),
|
||||
vec2(0.2422334f , 0.665805f),
|
||||
vec2(0.0574713f , 0.6742729f),
|
||||
vec2(0.2021346f , 0.8144029f),
|
||||
vec2(0.3086587f , 0.7504997f),
|
||||
vec2(0.02122174f , -0.7498575f),
|
||||
vec2(-0.1551729f , 0.1809731f),
|
||||
vec2(-0.1947583f , 0.06246066f),
|
||||
vec2(-0.05754202f , -0.03901273f),
|
||||
vec2(-0.1083095f , 0.2952235f),
|
||||
vec2(-0.03259534f , -0.492394f),
|
||||
vec2(-0.02488567f , -0.2081116f),
|
||||
vec2(-0.1820729f , -0.1829884f),
|
||||
vec2(-0.1674413f , -0.04529009f),
|
||||
vec2(0.04342153f , -0.0368562f),
|
||||
vec2(0.801399f , -0.5845526f),
|
||||
vec2(0.3158276f , -0.9124843f),
|
||||
vec2(-0.05945269f , 0.6727523f),
|
||||
vec2(0.07701834f , 0.8579889f),
|
||||
vec2(-0.05778154f , 0.5699022f),
|
||||
vec2(0.1191713f , 0.7542591f),
|
||||
vec2(-0.2578296f , 0.3630984f),
|
||||
vec2(-0.1428598f , 0.4557526f),
|
||||
vec2(-0.3304029f , 0.5055485f),
|
||||
vec2(-0.3227198f , 0.1847367f),
|
||||
vec2(-0.4183801f , 0.3412776f),
|
||||
vec2(0.2538475f , 0.9317476f),
|
||||
vec2(0.406249f , 0.8423664f),
|
||||
vec2(0.4718862f , 0.7592828f),
|
||||
vec2(0.168472f , -0.06605823f),
|
||||
vec2(0.2632498f , -0.7084918f),
|
||||
vec2(-0.2816192f , -0.1023492f),
|
||||
vec2(-0.3161443f , 0.02489911f),
|
||||
vec2(-0.4677814f , 0.08450397f),
|
||||
vec2(-0.4156994f , 0.2408664f),
|
||||
vec2(-0.237449f , 0.2605326f),
|
||||
vec2(-0.0912179f , 0.06491816f),
|
||||
vec2(0.01475127f , 0.7670643f),
|
||||
vec2(0.1216858f , -0.9368939f),
|
||||
vec2(0.07010741f , -0.841011f),
|
||||
vec2(-0.1708607f , -0.4152923f),
|
||||
vec2(-0.1345006f , -0.5842513f),
|
||||
vec2(-0.09419055f , -0.3213732f),
|
||||
vec2(-0.2149337f , 0.730642f),
|
||||
vec2(-0.1102187f , 0.8425013f),
|
||||
vec2(-0.1808572f , 0.6244397f),
|
||||
vec2(-0.2414505f , -0.7063725f),
|
||||
vec2(-0.2410318f , -0.537854f),
|
||||
vec2(-0.1005938f , -0.7635075f),
|
||||
vec2(0.1053517f , 0.9678772f),
|
||||
vec2(-0.3340288f , 0.6926677f),
|
||||
vec2(-0.2363931f , 0.8464488f),
|
||||
vec2(-0.4057773f , 0.7786722f),
|
||||
vec2(-0.5484858f , 0.1686208f),
|
||||
vec2(-0.64842f , 0.02256887f),
|
||||
vec2(-0.5544513f , -0.02348978f),
|
||||
vec2(-0.492855f , -0.1083694f),
|
||||
vec2(-0.4248196f , 0.4674786f),
|
||||
vec2(-0.5873146f , 0.4072608f),
|
||||
vec2(-0.6439911f , 0.3038489f),
|
||||
vec2(-0.6419188f , 0.1293737f),
|
||||
vec2(-0.005880734f , 0.4699725f),
|
||||
vec2(-0.4239455f , 0.6250131f),
|
||||
vec2(-0.1701273f , 0.9506347f),
|
||||
vec2(7.665656E-05f , 0.9941212f),
|
||||
vec2(-0.7070159f , 0.4426281f),
|
||||
vec2(-0.7481344f , 0.3139496f),
|
||||
vec2(-0.8330062f , 0.2472693f),
|
||||
vec2(-0.7271438f , 0.2024286f),
|
||||
vec2(-0.5179888f , 0.3149576f),
|
||||
vec2(-0.8258062f , 0.3779382f),
|
||||
vec2(-0.8063191f , 0.1262931f),
|
||||
vec2(-0.2690676f , -0.4360798f),
|
||||
vec2(-0.3714577f , -0.5887412f),
|
||||
vec2(-0.3736085f , -0.4018324f),
|
||||
vec2(-0.3228985f , -0.2063406f),
|
||||
vec2(-0.2414576f , -0.2875458f),
|
||||
vec2(-0.4720859f , -0.3823904f),
|
||||
vec2(-0.4937642f , -0.2686005f),
|
||||
vec2(-0.01500604f , -0.9587054f),
|
||||
vec2(-0.08535925f , -0.8820614f),
|
||||
vec2(-0.6436375f , -0.3157263f),
|
||||
vec2(-0.5736347f , -0.4224878f),
|
||||
vec2(-0.5026127f , -0.5516239f),
|
||||
vec2(-0.8200902f , 0.5370023f),
|
||||
vec2(-0.7196413f , 0.57133f),
|
||||
vec2(-0.5849072f , 0.5917885f),
|
||||
vec2(-0.1598758f , -0.9739854f),
|
||||
vec2(-0.4230629f , -0.01858409f),
|
||||
vec2(-0.9403627f , 0.2213769f),
|
||||
vec2(-0.685889f , -0.2192711f),
|
||||
vec2(-0.6693704f , -0.4884708f),
|
||||
vec2(-0.7967147f , -0.3078234f),
|
||||
vec2(-0.596441f , -0.1686891f),
|
||||
vec2(-0.7366468f , -0.3939891f),
|
||||
vec2(-0.7963406f , 0.02246814f),
|
||||
vec2(-0.9177913f , 0.0929693f),
|
||||
vec2(-0.9284672f , 0.3329005f),
|
||||
vec2(-0.6497722f , 0.6851863f),
|
||||
vec2(-0.496019f , 0.7013303f),
|
||||
vec2(-0.3930301f , -0.6892192f),
|
||||
vec2(-0.2122009f , -0.8777389f),
|
||||
vec2(-0.3660335f , -0.801644f),
|
||||
vec2(-0.386839f , -0.1191898f),
|
||||
vec2(-0.7020127f , -0.0776734f),
|
||||
vec2(-0.7760845f , -0.1566844f),
|
||||
vec2(-0.5444778f , -0.6516482f),
|
||||
vec2(-0.5331346f , 0.4946506f),
|
||||
vec2(-0.3288236f , 0.9408244f),
|
||||
vec2(0.5819826f , 0.8101937f),
|
||||
vec2(-0.4894184f , -0.8290837f),
|
||||
vec2(-0.5183194f , 0.8454953f),
|
||||
vec2(-0.7665774f , -0.5223897f),
|
||||
vec2(-0.6703191f , -0.6217513f),
|
||||
vec2(-0.8902924f , -0.2446688f),
|
||||
vec2(-0.8574848f , -0.09174173f),
|
||||
vec2(-0.3544409f , -0.9239591f),
|
||||
vec2(-0.969833f , -0.1172272f),
|
||||
vec2(-0.8968207f , -0.4079512f),
|
||||
vec2(-0.5891477f , 0.7724466f),
|
||||
vec2(-0.2146262f , 0.5286855f),
|
||||
vec2(-0.3762444f , -0.3014335f),
|
||||
vec2(-0.9466863f , -0.008970681f),
|
||||
vec2(-0.596356f , -0.7976127f),
|
||||
vec2(-0.8877738f , 0.4569088f));
|
||||
#endif
|
||||
flat varying vec4 exposure;
|
||||
flat varying float rodExposure;
|
||||
varying vec2 texcoord;
|
||||
uniform sampler2D colortex4;
|
||||
uniform sampler2D colortex5;
|
||||
uniform sampler2D colortex3;
|
||||
uniform sampler2D colortex7;
|
||||
uniform sampler2D depthtex0;
|
||||
uniform sampler2D noisetex;
|
||||
uniform sampler2D colortex6;
|
||||
uniform vec2 texelSize;
|
||||
|
||||
varying vec2 texcoord;
|
||||
uniform float viewWidth;
|
||||
uniform float viewHeight;
|
||||
uniform float frameTimeCounter;
|
||||
uniform int frameCounter;
|
||||
uniform int isEyeInWater;
|
||||
uniform float near;
|
||||
uniform float aspectRatio;
|
||||
uniform float far;
|
||||
|
||||
|
||||
#include "/lib/color_transforms.glsl"
|
||||
#include "/lib/color_dither.glsl"
|
||||
|
||||
|
||||
|
||||
float cdist(vec2 coord) {
|
||||
return max(abs(coord.s-0.5),abs(coord.t-0.5))*2.0;
|
||||
vec2 resScale = vec2(1920.,1080.)/max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.));
|
||||
vec3 gauss1D(vec2 coord,vec2 dir,float alpha,int maxIT){
|
||||
vec4 tot = vec4(0.);
|
||||
float maxTC = 0.25*resScale.y;
|
||||
float minTC = 0.;
|
||||
for (int i = -maxIT;i<maxIT+1;i++){
|
||||
float weight = exp(-i*i*alpha*4.0);
|
||||
vec2 spCoord = coord+dir*texelSize*(2.0*i+0.5);
|
||||
tot += vec4(texture2D(colortex6,spCoord).rgb,1.0)*weight*float(spCoord.y > minTC && spCoord.y < maxTC);
|
||||
}
|
||||
return tot.rgb/max(1.0,tot.a);
|
||||
}
|
||||
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
|
||||
}
|
||||
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);
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
|
||||
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;
|
||||
}
|
||||
void main() {
|
||||
/* DRAWBUFFERS:7 */
|
||||
float vignette = (1.5-dot(texcoord-0.5,texcoord-0.5)*2.5);
|
||||
vec3 col = texture2D(colortex5,texcoord).rgb;
|
||||
#ifdef DOF
|
||||
/*--------------------------------*/
|
||||
float z = ld(texture2D(depthtex0, texcoord.st).r)*far;
|
||||
#ifdef AUTOFOCUS
|
||||
float focus = ld(texture2D(depthtex0, vec2(0.5)).r)*far;
|
||||
#else
|
||||
float focus = MANUAL_FOCUS;
|
||||
#endif
|
||||
float pcoc = min(abs(aperture * (focal/100.0 * (z - focus)) / (z * (focus - focal/100.0))),texelSize.x*15.0);
|
||||
#ifdef FAR_BLUR_ONLY
|
||||
pcoc *= float(z > focus);
|
||||
#endif
|
||||
float noise = blueNoise()*6.28318530718;
|
||||
mat2 noiseM = mat2( cos( noise ), -sin( noise ),
|
||||
sin( noise ), cos( noise )
|
||||
);
|
||||
vec3 bcolor = vec3(0.);
|
||||
float nb = 0.0;
|
||||
vec2 bcoord = vec2(0.0);
|
||||
/*--------------------------------*/
|
||||
#ifndef HQ_DOF
|
||||
bcolor = col;
|
||||
#ifdef HEXAGONAL_BOKEH
|
||||
for ( int i = 0; i < 60; i++) {
|
||||
bcolor += texture2D(colortex5, texcoord.xy + hex_offsets[i]*pcoc*vec2(1.0,aspectRatio)).rgb;
|
||||
}
|
||||
col = bcolor/61.0;
|
||||
#else
|
||||
for ( int i = 0; i < 60; i++) {
|
||||
bcolor += texture2D(colortex5, texcoord.xy + offsets[i]*pcoc*vec2(1.0,aspectRatio)).rgb;
|
||||
}
|
||||
/*--------------------------------*/
|
||||
col = bcolor/61.0;
|
||||
#endif
|
||||
#endif
|
||||
#ifdef HQ_DOF
|
||||
for ( int i = 0; i < 209; i++) {
|
||||
bcolor += texture2D(colortex5, texcoord.xy + noiseM*shadow_offsets[i]*pcoc*vec2(1.0,aspectRatio)).rgb;
|
||||
}
|
||||
col = bcolor/209.0;
|
||||
#endif
|
||||
#endif
|
||||
vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.));
|
||||
/* DRAWBUFFERS:6 */
|
||||
vec2 texcoord = (gl_FragCoord.xy*vec2(2.0,4.0))*texelSize;
|
||||
|
||||
vec3 bloom = texture2D(colortex3,texcoord/clampedRes*vec2(1920.,1080.)*0.5).rgb/2./7.0;
|
||||
vec2 gaussDir = vec2(0.0,1.0);
|
||||
gl_FragData[0].rgb = vec3(0.0);
|
||||
vec2 tc2 = texcoord*vec2(2.0,1.);
|
||||
if (tc2.x < 1.0*resScale.x && tc2.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(texcoord/vec2(2.0,4.0),gaussDir,0.16,0);
|
||||
|
||||
float lightScat = clamp(BLOOM_STRENGTH * 0.05 * pow(exposure.a ,0.2) ,0.0,1.0)*vignette;
|
||||
vec2 tc4 = texcoord*vec2(4.0,2.)-vec2(0.5*resScale.x+4.0*texelSize.x,0.)*4.0;
|
||||
if (tc4.x > 0.0 && tc4.y > 0.0 && tc4.x < 1.0*resScale.x && tc4.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(texcoord/vec2(2.0,2.0),gaussDir,0.16,3);
|
||||
|
||||
float VL_abs = texture2D(colortex7,texcoord).r;
|
||||
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);
|
||||
vec2 tc8 = texcoord*vec2(8.0,4.)-vec2(0.75*resScale.x+8.*texelSize.x,0.)*8.0;
|
||||
if (tc8.x > 0.0 && tc8.y > 0.0 && tc8.x < 1.0*resScale.x && tc8.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(texcoord*vec2(1.0,2.0)/vec2(2.0,2.0),gaussDir,0.035,6);
|
||||
|
||||
col = ( mix(col, bloom, VL_abs) + bloom*lightScat) * exposure.rgb;
|
||||
vec2 tc16 = texcoord*vec2(16.0,8.)-vec2(0.875*resScale.x+12.*texelSize.x,0.)*16.0;
|
||||
if (tc16.x > 0.0 && tc16.y > 0.0 && tc16.x < 1.0*resScale.x && tc16.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(texcoord*vec2(1.0,4.0)/vec2(2.0,2.0),gaussDir,0.0085,12);
|
||||
|
||||
vec2 tc32 = texcoord*vec2(32.0,16.)-vec2(0.9375*resScale.x+16.*texelSize.x,0.)*32.0;
|
||||
if (tc32.x > 0.0 && tc32.y > 0.0 && tc32.x < 1.0*resScale.x && tc32.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(texcoord*vec2(1.0,8.0)/vec2(2.0,2.0),gaussDir,0.002,30);
|
||||
|
||||
#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
|
||||
//col = ACESFitted(texture2D(colortex4,texcoord/3.).rgb/500.);
|
||||
gl_FragData[0].rgb = clamp(int8Dither(col,texcoord),0.0,1.0);
|
||||
//if (nightMode < 0.99 && texcoord.x < 0.5) gl_FragData[0].rgb =vec3(0.0,1.0,0.0);
|
||||
vec2 tc64 = texcoord*vec2(64.0,32.)-vec2(0.96875*resScale.x+20.*texelSize.x,0.)*64.0;
|
||||
if (tc64.x > 0.0 && tc64.y > 0.0 && tc64.x < 1.0*resScale.x && tc64.y <1.0*resScale.y)
|
||||
gl_FragData[0].xyz = gauss1D(texcoord*vec2(1.0,16.0)/vec2(2.0,2.0),gaussDir,0.0005,60);
|
||||
|
||||
gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.);
|
||||
}
|
||||
|
@ -1,10 +1,6 @@
|
||||
#include "/lib/settings.glsl"
|
||||
|
||||
uniform float viewWidth;
|
||||
uniform float viewHeight;
|
||||
varying vec2 texcoord;
|
||||
flat varying vec4 exposure;
|
||||
flat varying float rodExposure;
|
||||
uniform sampler2D colortex4;
|
||||
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
@ -12,9 +8,12 @@ uniform sampler2D colortex4;
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
|
||||
void main() {
|
||||
|
||||
vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.0));
|
||||
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);
|
||||
rodExposure = texelFetch2D(colortex4,ivec2(14,37),0).r;
|
||||
//0-0.25
|
||||
gl_Position.y = (gl_Position.y*0.5+0.5)*0.25/clampedRes.y*1080.0*2.0-1.0;
|
||||
//0-0.5
|
||||
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.);
|
||||
|
||||
}
|
||||
|
@ -1,37 +1,33 @@
|
||||
#include "/lib/settings.glsl"
|
||||
|
||||
#define ReflectedFog
|
||||
|
||||
// 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 averageSkyCol_Clouds;
|
||||
flat varying vec3 averageSkyCol;
|
||||
|
||||
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 vec3 zenithColor;
|
||||
|
||||
flat varying vec3 WsunVec;
|
||||
|
||||
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 colortex4;
|
||||
uniform sampler2D noisetex;
|
||||
|
||||
uniform float frameTime;
|
||||
uniform int frameCounter;
|
||||
uniform float frameTimeCounter;
|
||||
uniform float rainStrength;
|
||||
uniform float eyeAltitude;
|
||||
uniform vec3 sunVec;
|
||||
uniform vec2 texelSize;
|
||||
uniform float frameTimeCounter;
|
||||
uniform mat4 gbufferProjection;
|
||||
uniform mat4 gbufferProjectionInverse;
|
||||
uniform mat4 gbufferPreviousProjection;
|
||||
@ -41,11 +37,15 @@ uniform mat4 shadowModelView;
|
||||
uniform mat4 shadowProjection;
|
||||
uniform float sunElevation;
|
||||
uniform vec3 cameraPosition;
|
||||
uniform float far;
|
||||
// uniform float far;
|
||||
uniform ivec2 eyeBrightnessSmooth;
|
||||
|
||||
vec4 lightCol = vec4(lightSourceColor, float(sunElevation > 1e-5)*2-1.);
|
||||
|
||||
#include "/lib/util.glsl"
|
||||
#include "/lib/ROBOBO_sky.glsl"
|
||||
#include "/lib/sky_gradient.glsl"
|
||||
#include "/lib/Shadow_Params.glsl"
|
||||
|
||||
vec3 toShadowSpaceProjected(vec3 p3){
|
||||
p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz;
|
||||
@ -64,42 +64,204 @@ float blueNoise(){
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
|
||||
// const bool shadowHardwareFiltering = true;
|
||||
uniform sampler2DShadow shadow;
|
||||
#define TEST
|
||||
#define TIMEOFDAYFOG
|
||||
#include "/lib/lightning_stuff.glsl"
|
||||
#include "/lib/volumetricClouds.glsl"
|
||||
#include "/lib/volumetricFog.glsl"
|
||||
|
||||
#endif
|
||||
#ifdef NETHER_SHADER
|
||||
uniform sampler2D colortex4;
|
||||
#include "/lib/nether_fog.glsl"
|
||||
#endif
|
||||
#ifdef END_SHADER
|
||||
uniform sampler2D colortex4;
|
||||
#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);
|
||||
float mixhistory = 0.07;
|
||||
|
||||
vec2 fogPos = vec2(256.0 - 256.0*0.12,1.0);
|
||||
#ifdef OVERWORLD_SHADER
|
||||
///////////////////////////////
|
||||
/// --- STORE COLOR LUT --- ///
|
||||
///////////////////////////////
|
||||
|
||||
//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 AmbientLightTint = vec3(AmbientLight_R, AmbientLight_G, AmbientLight_B);
|
||||
|
||||
// --- the color of the atmosphere + the average color of the atmosphere.
|
||||
vec3 skyGroundCol = skyFromTex(vec3(0, -1 ,0), colortex4).rgb ;
|
||||
|
||||
/// --- Save light values
|
||||
if (gl_FragCoord.x < 1. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 )
|
||||
gl_FragData[0] = vec4(averageSkyCol_Clouds * AmbientLightTint,1.0);
|
||||
|
||||
if (gl_FragCoord.x > 1. && gl_FragCoord.x < 2. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 )
|
||||
gl_FragData[0] = vec4((skyGroundCol/150.0) * AmbientLightTint,1.0);
|
||||
|
||||
if (gl_FragCoord.x > 6. && gl_FragCoord.x < 7. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 )
|
||||
gl_FragData[0] = vec4(lightSourceColor,1.0);
|
||||
|
||||
if (gl_FragCoord.x > 8. && gl_FragCoord.x < 9. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 )
|
||||
gl_FragData[0] = vec4(sunColor,1.0);
|
||||
|
||||
if (gl_FragCoord.x > 13. && gl_FragCoord.x < 14. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 )
|
||||
gl_FragData[0] = vec4(moonColor,1.0);
|
||||
|
||||
////////////////////////////////
|
||||
/// --- ATMOSPHERE IMAGE --- ///
|
||||
////////////////////////////////
|
||||
|
||||
/// --- Sky only
|
||||
if (gl_FragCoord.x > 18. && gl_FragCoord.y > 1. && gl_FragCoord.x < 18+257){
|
||||
vec2 p = clamp(floor(gl_FragCoord.xy-vec2(18.,1.))/256.+tempOffsets/256.,0.0,1.0);
|
||||
vec3 viewVector = cartToSphere(p);
|
||||
|
||||
vec3 BackgroundColor = vec3(0.0);
|
||||
vec2 planetSphere = vec2(0.0);
|
||||
vec3 sky = vec3(0.0);
|
||||
vec3 skyAbsorb = vec3(0.0);
|
||||
vec3 WsunVec = mat3(gbufferModelViewInverse)*sunVec;
|
||||
|
||||
vec4 VL_Fog = GetVolumetricFog(mat3(gbufferModelView)*viewVector*256., fract(frameCounter/1.6180339887), fract(frameCounter/2.6180339887));
|
||||
sky = calculateAtmosphere(averageSkyCol*4000./2.0, viewVector, vec3(0.0,1.0,0.0), WsunVec, -WsunVec, planetSphere, skyAbsorb, 10, blueNoise());
|
||||
|
||||
// sky = mix(sky, (averageSkyCol + skyAbsorb)*4000./2.0 ,(1.0 - exp(pow(clamp(-viewVector.y+0.5,0.0,1.0),2) * -25)));
|
||||
|
||||
// fade atmosphere conditions for rain away when you pass above the cloud plane.
|
||||
float heightRelativeToClouds = clamp(1.0 - max(eyeAltitude - Cumulus_height,0.0) / 200.0 ,0.0,1.0);
|
||||
if(rainStrength > 0.0) sky = mix(sky, 3.0 + averageSkyCol*4000 * (skyAbsorb*0.7+0.3), clamp(1.0 - exp(pow(clamp(-viewVector.y+0.9,0.0,1.0),2) * -5.0),0.0,1.0) * heightRelativeToClouds * rainStrength);
|
||||
|
||||
BackgroundColor += VL_Fog.rgb/5.0;
|
||||
#ifdef AEROCHROME_MODE
|
||||
sky *= vec3(0.0, 0.18, 0.35);
|
||||
#endif
|
||||
|
||||
gl_FragData[0] = vec4(BackgroundColor, 1.0);
|
||||
gl_FragData[0] = vec4(sky / 4000.0 * Sky_Brightness, 1.0);
|
||||
}
|
||||
|
||||
/// --- Sky + clouds + fog
|
||||
if (gl_FragCoord.x > 18.+257. && gl_FragCoord.y > 1. && gl_FragCoord.x < 18+257+257.){
|
||||
vec2 p = clamp(floor(gl_FragCoord.xy-vec2(18.+257,1.))/256.+tempOffsets/256.,0.0,1.0);
|
||||
vec3 viewVector = cartToSphere(p);
|
||||
|
||||
vec3 WsunVec = mat3(gbufferModelViewInverse)*sunVec;
|
||||
vec3 sky = texelFetch2D(colortex4,ivec2(gl_FragCoord.xy)-ivec2(257,0),0).rgb/150.0;
|
||||
|
||||
if(viewVector.y < -0.025) sky = sky * clamp( exp(viewVector.y) - 1.0,0.25,1.0) ;
|
||||
|
||||
vec4 clouds = renderClouds(mat3(gbufferModelView)*viewVector*1024.,vec2(fract(frameCounter/1.6180339887),1-fract(frameCounter/1.6180339887)), sunColor, moonColor, skyGroundCol/30.0);
|
||||
sky = sky*clouds.a + clouds.rgb / 5.0;
|
||||
|
||||
vec4 VL_Fog = GetVolumetricFog(mat3(gbufferModelView)*viewVector*1024., fract(frameCounter/1.6180339887), lightSourceColor*1.75, skyGroundCol/30.0);
|
||||
sky = sky * VL_Fog.a + VL_Fog.rgb / 5.0;
|
||||
|
||||
gl_FragData[0] = vec4(sky,1.0);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef NETHER_SHADER
|
||||
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-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);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef END_SHADER
|
||||
|
||||
/* ---------------------- FOG SHADER ---------------------- */
|
||||
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-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);
|
||||
|
||||
}
|
||||
|
||||
/* ---------------------- TIMER ---------------------- */
|
||||
|
||||
float flash = 0.0;
|
||||
float maxWaitTime = 10;
|
||||
|
||||
float Timer = texelFetch2D(colortex4, ivec2(3,1), 0).x/150.0;
|
||||
Timer -= frameTime;
|
||||
|
||||
if(Timer <= 0.0){
|
||||
flash = 1.0;
|
||||
|
||||
Timer = pow(hash11(frameCounter), 5) * maxWaitTime;
|
||||
}
|
||||
|
||||
vec2 pixelPos0 = vec2(3,1);
|
||||
if (gl_FragCoord.x > pixelPos0.x && gl_FragCoord.x < pixelPos0.x + 1 && gl_FragCoord.y > pixelPos0.y && gl_FragCoord.y < pixelPos0.y + 1){
|
||||
mixhistory = 1.0;
|
||||
gl_FragData[0] = vec4(Timer, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
/* ---------------------- FLASHING ---------------------- */
|
||||
|
||||
vec2 pixelPos1 = vec2(1,1);
|
||||
if (gl_FragCoord.x > pixelPos1.x && gl_FragCoord.x < pixelPos1.x + 1 && gl_FragCoord.y > pixelPos1.y && gl_FragCoord.y < pixelPos1.y + 1){
|
||||
mixhistory = clamp(5.0 * frameTime,0.0,1.0);
|
||||
gl_FragData[0] = vec4(flash, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
/* ---------------------- POSITION ---------------------- */
|
||||
|
||||
vec2 pixelPos2 = vec2(2,1);
|
||||
if (gl_FragCoord.x > pixelPos2.x && gl_FragCoord.x < pixelPos2.x + 1 && gl_FragCoord.y > pixelPos2.y && gl_FragCoord.y < pixelPos2.y + 1){
|
||||
mixhistory = clamp(500.0 * frameTime,0.0,1.0);
|
||||
|
||||
vec3 LastPos = (texelFetch2D(colortex4,ivec2(2,1),0).xyz/150.0) * 2.0 - 1.0;
|
||||
|
||||
LastPos += (hash31(frameCounter / 75) * 2.0 - 1.0);
|
||||
LastPos = LastPos * 0.5 + 0.5;
|
||||
|
||||
if(Timer > maxWaitTime * 0.7 ){
|
||||
LastPos = vec3(0.0);
|
||||
}
|
||||
|
||||
gl_FragData[0] = vec4(LastPos, 1.0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
//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.);
|
||||
gl_FragData[0].rgb = clamp(mix(temp, curr, mixhistory),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 )
|
||||
@ -107,4 +269,4 @@ 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);
|
||||
|
||||
}
|
||||
}
|
@ -1,5 +1,16 @@
|
||||
#include "/lib/settings.glsl"
|
||||
#include "/lib/res_params.glsl"
|
||||
#include "/lib/Shadow_Params.glsl"
|
||||
|
||||
// #extension GL_EXT_gpu_shader4 : enable
|
||||
|
||||
flat varying vec3 averageSkyCol_Clouds;
|
||||
flat varying vec3 averageSkyCol;
|
||||
|
||||
flat varying vec3 sunColor;
|
||||
flat varying vec3 moonColor;
|
||||
flat varying vec3 lightSourceColor;
|
||||
flat varying vec3 zenithColor;
|
||||
|
||||
flat varying vec2 tempOffsets;
|
||||
flat varying float exposure;
|
||||
@ -18,13 +29,14 @@ uniform vec2 texelSize;
|
||||
uniform float sunElevation;
|
||||
uniform float eyeAltitude;
|
||||
uniform float near;
|
||||
uniform float far;
|
||||
// uniform float far;
|
||||
uniform float frameTime;
|
||||
uniform int frameCounter;
|
||||
uniform float rainStrength;
|
||||
|
||||
// uniform int worldTime;
|
||||
vec3 sunVec = normalize(mat3(gbufferModelViewInverse) *sunPosition);
|
||||
vec3 sunVec = normalize(mat3(gbufferModelViewInverse) * sunPosition);
|
||||
// vec3 sunVec = normalize(LightDir);
|
||||
|
||||
#include "/lib/sky_gradient.glsl"
|
||||
#include "/lib/util.glsl"
|
||||
@ -55,6 +67,79 @@ void main() {
|
||||
gl_Position.xy = gl_Position.xy*vec2(18.+258*2,258.)*texelSize;
|
||||
gl_Position.xy = gl_Position.xy*2.-1.0;
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
|
||||
///////////////////////////////////
|
||||
/// --- AMBIENT LIGHT STUFF --- ///
|
||||
///////////////////////////////////
|
||||
|
||||
averageSkyCol_Clouds = vec3(0.0);
|
||||
averageSkyCol = vec3(0.0);
|
||||
|
||||
vec2 sample3x3[9] = vec2[](
|
||||
|
||||
vec2(-1.0, -0.3),
|
||||
vec2( 0.0, 0.0),
|
||||
vec2( 1.0, -0.3),
|
||||
|
||||
vec2(-1.0, -0.5),
|
||||
vec2( 0.0, -0.5),
|
||||
vec2( 1.0, -0.5),
|
||||
|
||||
vec2(-1.0, -1.0),
|
||||
vec2( 0.0, -1.0),
|
||||
vec2( 1.0, -1.0)
|
||||
);
|
||||
|
||||
// sample in a 3x3 pattern to get a good area for average color
|
||||
vec3 pos = normalize(vec3(0,1,0));
|
||||
int maxIT = 9;
|
||||
for (int i = 0; i < maxIT; i++) {
|
||||
pos = normalize(vec3(0,1,0));
|
||||
pos.xy += normalize(sample3x3[i]) * vec2(0.3183,0.90);
|
||||
|
||||
averageSkyCol_Clouds += 2.0*skyCloudsFromTex(pos,colortex4).rgb/maxIT/150.;
|
||||
|
||||
// pos = normalize(vec3(0,1,0));
|
||||
// pos.xy += normalize(sample3x3[i]) * vec2(0.3183,0.90);
|
||||
averageSkyCol += 1.5*skyFromTex(pos,colortex4).rgb/maxIT/150.; // please dont do an infinite feedback loop....
|
||||
|
||||
}
|
||||
|
||||
/// TOOO DAMN BLUE
|
||||
// // only need to sample one spot for this
|
||||
// averageSkyCol += 2.0*skyFromTex(normalize(vec3(0.0,1.0,0.0)),colortex4).rgb/150.;
|
||||
vec3 minimimlight = vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.0005 + nightVision);
|
||||
averageSkyCol_Clouds = max(averageSkyCol_Clouds, minimimlight);
|
||||
averageSkyCol = max(averageSkyCol, minimimlight);
|
||||
|
||||
////////////////////////////////////////
|
||||
/// --- SUNLIGHT/MOONLIGHT STUFF --- ///
|
||||
////////////////////////////////////////
|
||||
|
||||
vec2 planetSphere = vec2(0.0);
|
||||
vec3 sky = vec3(0.0);
|
||||
vec3 skyAbsorb = vec3(0.0);
|
||||
|
||||
float sunVis = clamp(sunElevation,0.0,0.05)/0.05*clamp(sunElevation,0.0,0.05)/0.05;
|
||||
float moonVis = clamp(-sunElevation,0.0,0.05)/0.05*clamp(-sunElevation,0.0,0.05)/0.05;
|
||||
|
||||
// zenithColor = calculateAtmosphere(vec3(0.0), vec3(0.0,1.0,0.0), vec3(0.0,1.0,0.0), sunVec, -sunVec, planetSphere, skyAbsorb, 25,tempOffsets.x);
|
||||
skyAbsorb = vec3(0.0);
|
||||
vec3 absorb = vec3(0.0);
|
||||
sunColor = calculateAtmosphere(vec3(0.0), sunVec, vec3(0.0,1.0,0.0), sunVec, -sunVec, planetSphere, skyAbsorb, 25,0.0);
|
||||
sunColor = sunColorBase/4000. * skyAbsorb;
|
||||
|
||||
skyAbsorb = vec3(1.0);
|
||||
moonColor = calculateAtmosphere(vec3(0.0), -sunVec, vec3(0.0,1.0,0.0), sunVec, -sunVec, planetSphere, skyAbsorb, 25,0.5);
|
||||
moonColor = moonColorBase/4000.0;
|
||||
|
||||
lightSourceColor = sunVis >= 1e-5 ? sunColor * sunVis : moonColor * moonVis;
|
||||
|
||||
float lightDir = float( sunVis >= 1e-5)*2.0-1.0;
|
||||
|
||||
#endif
|
||||
|
||||
//////////////////////////////
|
||||
/// --- EXPOSURE STUFF --- ///
|
||||
//////////////////////////////
|
||||
@ -71,7 +156,7 @@ void main() {
|
||||
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;
|
||||
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));
|
||||
}
|
||||
|
@ -6,10 +6,10 @@ uniform sampler2D depthtex1;
|
||||
uniform float near;
|
||||
uniform float far;
|
||||
|
||||
|
||||
float linZ(float depth) {
|
||||
return (2.0 * near) / (far + near - depth * (far - near));
|
||||
}
|
||||
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
|
112
shaders/dimensions/deferred2.fsh
Normal file
112
shaders/dimensions/deferred2.fsh
Normal file
@ -0,0 +1,112 @@
|
||||
|
||||
//#extension GL_EXT_gpu_shader4 : disable
|
||||
#include "/lib/settings.glsl"
|
||||
//Computes volumetric clouds at variable resolution (default 1/4 res)
|
||||
|
||||
|
||||
|
||||
flat varying vec3 sunColor;
|
||||
flat varying vec3 moonColor;
|
||||
|
||||
flat varying vec3 averageSkyCol;
|
||||
|
||||
|
||||
|
||||
flat varying float tempOffsets;
|
||||
// uniform float far;
|
||||
uniform float near;
|
||||
uniform sampler2D depthtex0;
|
||||
// uniform sampler2D colortex4;
|
||||
uniform sampler2D noisetex;
|
||||
|
||||
flat varying vec3 WsunVec;
|
||||
uniform vec3 sunVec;
|
||||
uniform vec2 texelSize;
|
||||
uniform float frameTimeCounter;
|
||||
uniform float rainStrength;
|
||||
uniform int frameCounter;
|
||||
uniform int framemod8;
|
||||
uniform mat4 gbufferProjectionInverse;
|
||||
uniform mat4 gbufferModelViewInverse;
|
||||
uniform vec3 cameraPosition;
|
||||
|
||||
uniform mat4 gbufferModelView;
|
||||
// flat varying vec2 TAA_Offset;
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
float R2_dither(){
|
||||
vec2 alpha = vec2(0.75487765, 0.56984026);
|
||||
return fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter);
|
||||
}
|
||||
float R2_dither2(){
|
||||
vec2 alpha = vec2(0.75487765, 0.56984026);
|
||||
return fract(alpha.x * (1.0-gl_FragCoord.x) + alpha.y * (1.0-gl_FragCoord.y) + 1.0/1.6180339887 * frameCounter);
|
||||
}
|
||||
float interleaved_gradientNoise(){
|
||||
vec2 alpha = vec2(0.75487765, 0.56984026);
|
||||
vec2 coord = vec2(alpha.x * gl_FragCoord.x,alpha.y * gl_FragCoord.y)+ 1.0/1.6180339887 * frameCounter;
|
||||
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
|
||||
return noise;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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.);
|
||||
float blueNoise(){
|
||||
return fract(texelFetch2D(noisetex, ivec2(1.0-gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
|
||||
}
|
||||
float blueNoise2(){
|
||||
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
|
||||
}
|
||||
|
||||
vec3 normVec (vec3 vec){
|
||||
return vec*inversesqrt(dot(vec,vec));
|
||||
}
|
||||
|
||||
#include "/lib/lightning_stuff.glsl"
|
||||
|
||||
#include "/lib/sky_gradient.glsl"
|
||||
#include "/lib/volumetricClouds.glsl"
|
||||
#include "/lib/res_params.glsl"
|
||||
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
|
||||
|
||||
void main() {
|
||||
/* DRAWBUFFERS:0 */
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
#ifdef VOLUMETRIC_CLOUDS
|
||||
vec2 halfResTC = vec2(floor(gl_FragCoord.xy)/CLOUDS_QUALITY/RENDER_SCALE+0.5+offsets[framemod8]*CLOUDS_QUALITY*RENDER_SCALE*0.5);
|
||||
|
||||
vec3 viewPos = toScreenSpace(vec3(halfResTC*texelSize,1));
|
||||
|
||||
vec4 VolumetricClouds = renderClouds(viewPos, vec2(R2_dither(),blueNoise2()), sunColor/80., moonColor/150., averageSkyCol/30.0);
|
||||
|
||||
gl_FragData[0] = VolumetricClouds;
|
||||
|
||||
|
||||
#else
|
||||
gl_FragData[0] = vec4(0.0,0.0,0.0,1.0);
|
||||
#endif
|
||||
#else
|
||||
gl_FragData[0] = vec4(0.0,0.0,0.0,1.0);
|
||||
#endif
|
||||
}
|
40
shaders/dimensions/deferred2.vsh
Normal file
40
shaders/dimensions/deferred2.vsh
Normal file
@ -0,0 +1,40 @@
|
||||
|
||||
//#extension GL_EXT_gpu_shader4 : disable
|
||||
#include "/lib/settings.glsl"
|
||||
|
||||
flat varying vec3 averageSkyCol;
|
||||
flat varying vec3 sunColor;
|
||||
flat varying vec3 moonColor;
|
||||
|
||||
|
||||
flat varying float tempOffsets;
|
||||
flat varying vec3 WsunVec;
|
||||
uniform mat4 gbufferModelViewInverse;
|
||||
uniform vec3 sunPosition;
|
||||
uniform float sunElevation;
|
||||
|
||||
uniform sampler2D colortex4;
|
||||
uniform int frameCounter;
|
||||
|
||||
#include "/lib/util.glsl"
|
||||
#include "/lib/res_params.glsl"
|
||||
|
||||
#include "/lib/Shadow_Params.glsl"
|
||||
|
||||
void main() {
|
||||
|
||||
gl_Position = ftransform();
|
||||
gl_Position.xy = (gl_Position.xy*0.5+0.5)*clamp(CLOUDS_QUALITY+0.01,0.0,1.0)*2.0-1.0;
|
||||
|
||||
averageSkyCol = texelFetch2D(colortex4,ivec2(1,37),0).rgb;
|
||||
sunColor = texelFetch2D(colortex4,ivec2(6,37),0).rgb;
|
||||
moonColor = texelFetch2D(colortex4,ivec2(13,37),0).rgb;
|
||||
|
||||
WsunVec = ( float(sunElevation > 1e-5)*2-1. )*normalize(mat3(gbufferModelViewInverse) *sunPosition);
|
||||
// WsunVec = normalize(LightDir);
|
||||
|
||||
tempOffsets = HaltonSeq2(frameCounter%10000);
|
||||
#ifdef TAA_UPSCALING
|
||||
gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0;
|
||||
#endif
|
||||
}
|
@ -3,15 +3,12 @@
|
||||
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;
|
||||
|
||||
uniform sampler2D shadowcolor0;
|
||||
uniform sampler2D shadowtex0;
|
||||
uniform sampler2D shadowtex1;
|
||||
|
||||
#include "/lib/color_transforms.glsl"
|
||||
#include "/lib/color_dither.glsl"
|
||||
@ -99,6 +96,30 @@ void applyColorCurve(inout vec3 color, vec4 darks, vec4 brights){
|
||||
|
||||
}
|
||||
|
||||
#ifdef HURT_AND_DEATH_EFFECT
|
||||
uniform float hurt;
|
||||
uniform float dying;
|
||||
uniform float dead;
|
||||
|
||||
void PlayerDamagedEffect(inout vec3 outColor){
|
||||
|
||||
if(dying > 0){
|
||||
|
||||
float vignette2 = clamp(1.0 - exp(-(sin(frameTimeCounter*7)*15+50) * dot(texcoord-0.5,texcoord-0.5)),0.0,1.0);
|
||||
|
||||
outColor = mix(outColor, vec3(0.0), min(dying,1.0)*vignette2);
|
||||
outColor = mix(outColor, vec3(0.0), dead);
|
||||
|
||||
}else{
|
||||
|
||||
float vignette = clamp(1.0 - exp(-5 * dot(texcoord-0.5,texcoord-0.5)),0.0,1.0);
|
||||
|
||||
outColor = mix(outColor, vec3(0.3,0.0,0.0), vignette*sqrt(hurt));
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
#ifdef BICUBIC_UPSCALING
|
||||
vec3 col = SampleTextureCatmullRom(colortex7,texcoord,1.0/texelSize).rgb;
|
||||
@ -119,14 +140,18 @@ void main() {
|
||||
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);
|
||||
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);
|
||||
|
||||
|
||||
#ifdef HURT_AND_DEATH_EFFECT
|
||||
PlayerDamagedEffect(col);
|
||||
#endif
|
||||
|
||||
vec3 FINAL_COLOR = clamp(int8Dither(col,texcoord),0.0,1.0);
|
||||
|
||||
#ifdef COLOR_CURVE
|
||||
@ -135,5 +160,15 @@ void main() {
|
||||
|
||||
applyContrast(FINAL_COLOR, CONTRAST); // for fun
|
||||
|
||||
gl_FragColor.rgb = FINAL_COLOR ;
|
||||
gl_FragColor.rgb = FINAL_COLOR;
|
||||
|
||||
|
||||
|
||||
// uniform sampler2D shadowcolor0;
|
||||
// uniform sampler2D shadowtex0;
|
||||
// uniform sampler2D shadowtex1;
|
||||
// if(texcoord.x > 0.5) gl_FragColor.rgb = texture2D(shadowcolor0, texcoord * vec2(2.0, 1.0) - vec2(1.0, 0.0)).rgb;
|
||||
// vec2 texrood = texcoord * vec2(2.0, 1.0) - vec2(1.0, 0.0);
|
||||
|
||||
// if(texrood.x > 0.49 && texrood.x < 0.51 && texrood.y > 0.49 && texrood.y < 0.51) gl_FragColor.rgb = vec3(1,0,0);
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
#include "/lib/settings.glsl"
|
||||
|
||||
varying vec2 texcoord;
|
||||
flat varying vec4 exposure;
|
||||
uniform sampler2D colortex4;
|
||||
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
@ -11,8 +9,6 @@ uniform sampler2D colortex4;
|
||||
//////////////////////////////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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user