mirror of
https://github.com/X0nk/Bliss-Shader.git
synced 2024-12-23 01:59:39 +08:00
bring translucent shaders for nether and end up to speed
This commit is contained in:
parent
7c5a4b39bd
commit
cfc8722bc8
@ -566,9 +566,13 @@ void ApplySSRT(inout vec3 lighting, vec3 normal,vec2 noise,vec3 fragpos, vec2 li
|
||||
int nrays = RAY_COUNT;
|
||||
|
||||
vec3 radiance = vec3(0.0);
|
||||
|
||||
vec3 occlusion = vec3(0.0);
|
||||
vec3 skycontribution = vec3(0.0);
|
||||
|
||||
vec3 occlusion2 = vec3(0.0);
|
||||
vec3 skycontribution2 = vec3(0.0);
|
||||
|
||||
float skyLM = 0.0;
|
||||
vec3 torchlight = vec3(0.0);
|
||||
DoRTAmbientLighting(torchcolor, lightmaps, skyLM, torchlight, skylightcolor);
|
||||
@ -594,6 +598,11 @@ void ApplySSRT(inout vec3 lighting, vec3 normal,vec2 noise,vec3 fragpos, vec2 li
|
||||
float SkyLightDir = rayDir.y > 0.0 ? 1.0 : max(rayDir.y,0.25); // the positons where the occlusion happens
|
||||
|
||||
skycontribution = skylightcolor * SkyLightDir + torchlight;
|
||||
|
||||
#if indirect_effect == 4
|
||||
skycontribution2 = skylightcolor + torchlight;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
if (rayHit.z < 1.){
|
||||
@ -615,6 +624,9 @@ void ApplySSRT(inout vec3 lighting, vec3 normal,vec2 noise,vec3 fragpos, vec2 li
|
||||
|
||||
occlusion += skycontribution * GI_Strength;
|
||||
|
||||
#if indirect_effect == 4
|
||||
occlusion2 += skycontribution2 * GI_Strength;
|
||||
#endif
|
||||
|
||||
} else {
|
||||
radiance += skycontribution;
|
||||
@ -623,13 +635,11 @@ void ApplySSRT(inout vec3 lighting, vec3 normal,vec2 noise,vec3 fragpos, vec2 li
|
||||
|
||||
occlusion *= AO_Strength;
|
||||
|
||||
lighting = radiance/nrays - occlusion/nrays;
|
||||
|
||||
|
||||
|
||||
// lighting = GI ;
|
||||
// radiance = radiance/nrays - (skycontribution + occlusion/nrays);
|
||||
// lighting = skycontribution - occlusion/nrays + radiance;
|
||||
#if indirect_effect == 4
|
||||
lighting = max(radiance/nrays - max(occlusion, occlusion2*0.5)/nrays, 0.0);
|
||||
#else
|
||||
lighting = max(radiance/nrays - occlusion/nrays, 0.0);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
@ -425,7 +425,7 @@ void main() {
|
||||
#endif
|
||||
|
||||
#ifdef WhiteWorld
|
||||
Albedo.rgb = vec3(0.5);
|
||||
Albedo.rgb = vec3(1.0);
|
||||
#endif
|
||||
|
||||
#ifdef AEROCHROME_MODE
|
||||
|
@ -362,7 +362,6 @@ if (gl_FragCoord.x * texelSize.x < RENDER_SCALE.x && gl_FragCoord.y * texelSize
|
||||
#endif
|
||||
}
|
||||
|
||||
// cannot encode alpha or it will shit its pants
|
||||
gl_FragData[2] = vec4(encodeVec2(TangentNormal), encodeVec2(COLORTEST.rg), encodeVec2(COLORTEST.ba), UnchangedAlpha);
|
||||
|
||||
|
||||
|
@ -51,12 +51,7 @@ vec3 DoAmbientLighting_Nether(vec3 FogColor, vec3 TorchColor, float Lightmap, ve
|
||||
vec3 TorchLight = TorchColor * TorchLM * 0.75;
|
||||
TorchLight *= TORCH_AMOUNT;
|
||||
|
||||
vec3 LavaGlow = vec3(TORCH_R,TORCH_G,TORCH_B);
|
||||
LavaGlow *= pow(clamp(1.0-max(Normal.y,0.0) + dot(Normal,np3),0.0,1.0),3.0);
|
||||
LavaGlow *= clamp(exp2(-max((WorldPos.y - 50.0) / 5,0.0)),0.0,1.0);
|
||||
LavaGlow *= pow(Lightmap,0.2);
|
||||
|
||||
FogColor = max(FogColor, vec3(0.05) * (MIN_LIGHT_AMOUNT*0.01 + nightVision*0.5) );
|
||||
FogColor = max(FogColor, vec3(0.05) * MIN_LIGHT_AMOUNT*0.01 + nightVision);
|
||||
|
||||
return FogColor + TorchLight ;
|
||||
}
|
||||
|
@ -3,11 +3,15 @@
|
||||
|
||||
varying vec4 lmtexcoord;
|
||||
varying vec4 color;
|
||||
|
||||
|
||||
uniform sampler2D normals;
|
||||
varying vec4 tangent;
|
||||
|
||||
varying vec4 normalMat;
|
||||
varying vec3 binormal;
|
||||
uniform sampler2D normals;
|
||||
varying vec3 tangent;
|
||||
varying vec4 tangent_other;
|
||||
|
||||
|
||||
varying vec3 viewVector;
|
||||
|
||||
#include "/lib/settings.glsl"
|
||||
@ -18,10 +22,13 @@ uniform sampler2D texture;
|
||||
uniform sampler2D noisetex;
|
||||
uniform sampler2DShadow shadow;
|
||||
// uniform sampler2D gaux2;
|
||||
uniform sampler2D gaux1;
|
||||
uniform sampler2D depthtex1;
|
||||
uniform sampler2D colortex5;
|
||||
// uniform sampler2D gaux1;
|
||||
|
||||
uniform sampler2D colortex5;
|
||||
uniform sampler2D depthtex1;
|
||||
|
||||
|
||||
const bool colortex4MipmapEnabled = true;
|
||||
|
||||
uniform vec3 sunVec;
|
||||
uniform float frameTimeCounter;
|
||||
@ -46,21 +53,49 @@ uniform int framemod8;
|
||||
uniform sampler2D specular;
|
||||
uniform int frameCounter;
|
||||
uniform int isEyeInWater;
|
||||
uniform ivec2 eyeBrightness;
|
||||
uniform ivec2 eyeBrightnessSmooth;
|
||||
|
||||
|
||||
flat varying vec4 lightCol; //main light source color (rgb),used light source(1=sun,-1=moon)
|
||||
flat varying vec3 avgAmbient;
|
||||
|
||||
flat varying vec3 averageSkyCol_Clouds;
|
||||
// flat varying vec3 averageSkyCol;
|
||||
|
||||
|
||||
|
||||
#include "/lib/Shadow_Params.glsl"
|
||||
#include "/lib/color_transforms.glsl"
|
||||
#include "/lib/projections.glsl"
|
||||
#include "/lib/sky_gradient.glsl"
|
||||
#include "/lib/waterBump.glsl"
|
||||
|
||||
#define END
|
||||
#define NETHER
|
||||
#include "/lib/clouds.glsl"
|
||||
#include "/lib/stars.glsl"
|
||||
#include "/lib/volumetricClouds.glsl"
|
||||
#define OVERWORLD
|
||||
#include "/lib/diffuse_lighting.glsl"
|
||||
|
||||
|
||||
float blueNoise(){
|
||||
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
|
||||
}
|
||||
float R2_dither(){
|
||||
vec2 alpha = vec2(0.75487765, 0.56984026);
|
||||
return fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter) ;
|
||||
}
|
||||
float interleaved_gradientNoise(){
|
||||
vec2 coord = gl_FragCoord.xy + (frameCounter%40000);
|
||||
// vec2 coord = gl_FragCoord.xy + frameTimeCounter;
|
||||
// vec2 coord = gl_FragCoord.xy;
|
||||
float noise = fract( 52.9829189 * fract( (coord.x * 0.06711056) + (coord.y * 0.00583715)) );
|
||||
return noise ;
|
||||
}
|
||||
float interleaved_gradientNoise(float temporal){
|
||||
vec2 coord = gl_FragCoord.xy;
|
||||
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)+temporal);
|
||||
return noise;
|
||||
}
|
||||
|
||||
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
|
||||
vec2(-1.,3.)/8.,
|
||||
vec2(5.0,1.)/8.,
|
||||
@ -69,50 +104,89 @@ flat varying vec3 avgAmbient;
|
||||
vec2(-7.,-1.)/8.,
|
||||
vec2(3,7.)/8.,
|
||||
vec2(7.,-7.)/8.);
|
||||
float interleaved_gradientNoise(float temporal){
|
||||
vec2 coord = gl_FragCoord.xy;
|
||||
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)+temporal);
|
||||
return noise;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define PW_DEPTH 1.0 //[0.5 1.0 1.5 2.0 2.5 3.0]
|
||||
#define PW_POINTS 1 //[2 4 6 8 16 32]
|
||||
|
||||
vec3 getParallaxDisplacement(vec3 posxz, float iswater,float bumpmult,vec3 viewVec) {
|
||||
float waveZ = mix(20.0,0.25,iswater);
|
||||
float waveM = mix(0.0,4.0,iswater);
|
||||
|
||||
vec3 parallaxPos = posxz;
|
||||
vec2 vec = viewVector.xy * (1.0 / float(PW_POINTS)) * 22.0 * PW_DEPTH;
|
||||
float waterHeight = getWaterHeightmap(posxz.xz, waveM, waveZ, iswater) ;
|
||||
|
||||
parallaxPos.xz += waterHeight * vec;
|
||||
|
||||
return parallaxPos;
|
||||
|
||||
}
|
||||
vec3 srgbToLinear2(vec3 srgb){
|
||||
return mix(
|
||||
srgb / 12.92,
|
||||
pow(.947867 * srgb + .0521327, vec3(2.4) ),
|
||||
step( .04045, srgb )
|
||||
);
|
||||
|
||||
vec3 applyBump(mat3 tbnMatrix, vec3 bump, float puddle_values){
|
||||
float bumpmult = 1;
|
||||
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
|
||||
return normalize(bump*tbnMatrix);
|
||||
}
|
||||
vec3 blackbody2(float Temp)
|
||||
|
||||
vec2 tapLocation(int sampleNumber,int nb, float nbRot,float jitter,float distort)
|
||||
{
|
||||
float t = pow(Temp, -1.5);
|
||||
float lt = log(Temp);
|
||||
float alpha = (sampleNumber+jitter)/nb;
|
||||
float angle = jitter*6.28 + alpha * nbRot * 6.28;
|
||||
|
||||
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;
|
||||
float sin_v, cos_v;
|
||||
|
||||
return srgbToLinear2(col);
|
||||
sin_v = sin(angle);
|
||||
cos_v = cos(angle);
|
||||
|
||||
return vec2(cos_v, sin_v)*sqrt(alpha);
|
||||
}
|
||||
|
||||
float blueNoise(){
|
||||
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
|
||||
|
||||
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;
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
float invLinZ (float lindepth){
|
||||
return -((2.0*near/lindepth)-far-near)/(far-near);
|
||||
}
|
||||
float ld(float dist) {
|
||||
return (2.0 * near) / (far + near - dist * (far - near));
|
||||
}
|
||||
vec3 nvec3(vec4 pos){
|
||||
return pos.xyz/pos.w;
|
||||
}
|
||||
|
||||
vec4 nvec4(vec3 pos){
|
||||
return vec4(pos.xyz, 1.0);
|
||||
}
|
||||
vec3 rayTrace(vec3 dir,vec3 position,float dither, float fresnel, bool inwater){
|
||||
|
||||
float quality = mix(15,SSR_STEPS,fresnel);
|
||||
@ -127,109 +201,43 @@ 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 = texelFetch2D(depthtex1,ivec2(spos.xy/texelSize),0).x;
|
||||
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/RENDER_SCALE,sp);
|
||||
#else
|
||||
float sp = texelFetch2D(depthtex1,ivec2(spos.xy/texelSize),0).r;
|
||||
if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ)) return vec3(spos.xy/RENDER_SCALE,sp);
|
||||
|
||||
|
||||
if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ) ) return vec3(spos.xy,sp);
|
||||
#endif
|
||||
|
||||
spos += stepv;
|
||||
|
||||
//small bias
|
||||
float biasamount = 0.0002 / dist;
|
||||
|
||||
minZ = maxZ-biasamount / ld(spos.z);
|
||||
|
||||
minZ = maxZ-(0.0001/dist)/ld(spos.z);
|
||||
if(inwater) minZ = maxZ-0.0004/ld(spos.z);
|
||||
maxZ += stepv.z;
|
||||
}
|
||||
|
||||
return vec3(1.1);
|
||||
}
|
||||
|
||||
|
||||
float facos(float sx){
|
||||
float x = clamp(abs( sx ),0.,1.);
|
||||
float a = sqrt( 1. - x ) * ( -0.16882 * x + 1.56734 );
|
||||
return sx > 0. ? a : pi - a;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
float bayer2(vec2 a){
|
||||
a = floor(a);
|
||||
return fract(dot(a,vec2(0.5,a.y*0.75)));
|
||||
}
|
||||
|
||||
float cdist(vec2 coord) {
|
||||
return max(abs(coord.s-0.5),abs(coord.t-0.5))*2.0;
|
||||
}
|
||||
|
||||
#define PW_DEPTH 1.0 //[0.5 1.0 1.5 2.0 2.5 3.0]
|
||||
#define PW_POINTS 1 //[2 4 6 8 16 32]
|
||||
#define bayer4(a) (bayer2( .5*(a))*.25+bayer2(a))
|
||||
#define bayer8(a) (bayer4( .5*(a))*.25+bayer2(a))
|
||||
#define bayer16(a) (bayer8( .5*(a))*.25+bayer2(a))
|
||||
#define bayer32(a) (bayer16(.5*(a))*.25+bayer2(a))
|
||||
#define bayer64(a) (bayer32(.5*(a))*.25+bayer2(a))
|
||||
#define bayer128(a) fract(bayer64(.5*(a))*.25+bayer2(a))
|
||||
vec3 getParallaxDisplacement(vec3 posxz, float iswater,float bumpmult,vec3 viewVec) {
|
||||
float waveZ = mix(20.0,0.25,iswater);
|
||||
float waveM = mix(0.0,4.0,iswater);
|
||||
|
||||
vec3 parallaxPos = posxz;
|
||||
vec2 vec = viewVector.xy * (1.0 / float(PW_POINTS)) * 22.0 * PW_DEPTH;
|
||||
float waterHeight = getWaterHeightmap(posxz.xz, waveM, waveZ, iswater) ;
|
||||
|
||||
parallaxPos.xz += waterHeight * vec;
|
||||
|
||||
return parallaxPos;
|
||||
|
||||
}
|
||||
vec2 tapLocation(int sampleNumber,int nb, float nbRot,float jitter,float distort)
|
||||
{
|
||||
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)*sqrt(alpha);
|
||||
}
|
||||
//Low discrepancy 2D sequence, integration error is as low as sobol but easier to compute : http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/
|
||||
vec2 R2_samples(int n){
|
||||
vec2 alpha = vec2(0.75487765, 0.56984026);
|
||||
return fract(alpha * n);
|
||||
}
|
||||
vec4 hash44(vec4 p4)
|
||||
{
|
||||
p4 = fract(p4 * vec4(.1031, .1030, .0973, .1099));
|
||||
p4 += dot(p4, p4.wzxy+33.33);
|
||||
return fract((p4.xxyz+p4.yzzw)*p4.zywx);
|
||||
}
|
||||
vec3 TangentToWorld(vec3 N, vec3 H)
|
||||
{
|
||||
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));
|
||||
}
|
||||
float GGX (vec3 n, vec3 v, vec3 l, float r, float F0) {
|
||||
r*=r;r*=r;
|
||||
vec3 GGX (vec3 n, vec3 v, vec3 l, float r, vec3 F0) {
|
||||
r = pow(r,2.5);
|
||||
// r*=r;
|
||||
|
||||
vec3 h = l + v;
|
||||
float hn = inversesqrt(dot(h, h));
|
||||
@ -241,270 +249,121 @@ float GGX (vec3 n, vec3 v, vec3 l, float r, float F0) {
|
||||
|
||||
float denom = dotNHsq * r - dotNHsq + 1.;
|
||||
float D = r / (3.141592653589793 * denom * denom);
|
||||
float F = F0 + (1. - F0) * exp2((-5.55473*dotLH-6.98316)*dotLH);
|
||||
vec3 F = F0 + (1. - F0) * exp2((-5.55473*dotLH-6.98316)*dotLH);
|
||||
float k2 = .25 * r;
|
||||
|
||||
return dotNL * D * F / (dotLH*dotLH*(1.0-k2)+k2);
|
||||
}
|
||||
|
||||
vec3 applyBump(mat3 tbnMatrix, vec3 bump){
|
||||
float bumpmult = 1.0;
|
||||
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
|
||||
return normalize(bump*tbnMatrix);
|
||||
}
|
||||
|
||||
#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.)
|
||||
float triangularize(float dither)
|
||||
{
|
||||
float center = dither*2.0-1.0;
|
||||
dither = center*inversesqrt(abs(center));
|
||||
return clamp(dither-fsign(center),0.0,1.0);
|
||||
}
|
||||
vec3 fp10Dither(vec3 color,float dither){
|
||||
const vec3 mantissaBits = vec3(6.,6.,5.);
|
||||
vec3 exponent = floor(log2(color));
|
||||
return color + dither*exp2(-mantissaBits)*exp2(exponent);
|
||||
}
|
||||
float R2_dither(){
|
||||
vec2 alpha = vec2(0.75487765, 0.56984026);
|
||||
return fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter) ;
|
||||
}
|
||||
float interleaved_gradientNoise(){
|
||||
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 ;
|
||||
}
|
||||
//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));
|
||||
}
|
||||
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;
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
float square(float x){
|
||||
return x*x;
|
||||
}
|
||||
|
||||
float gSimple(float dp, float roughness){
|
||||
float k = roughness + 1;
|
||||
k *= k/8.0;
|
||||
return dp / (dp * (1.0-k) + k);
|
||||
}
|
||||
vec3 GGX2_2(vec3 n, vec3 v, vec3 l, float r, vec3 F0) {
|
||||
|
||||
float alpha = square(r) + 1e-4; // when roughness is zero it fucks up
|
||||
|
||||
vec3 h = normalize(l + v) ;
|
||||
|
||||
float dotNH = clamp(dot(h,n),0.,1.);
|
||||
float dotVH = clamp(dot(h,v),0.,1.);
|
||||
|
||||
float D = alpha / (2.2 * square( (dotNH * alpha - 1.0) * square(dotNH) + 1.0) );
|
||||
|
||||
vec3 F = F0 + (1. - F0) * pow(clamp(1.0 - dotVH,0.0,1.0),5.0);
|
||||
|
||||
return F * D;
|
||||
}
|
||||
// float SunGGX(vec3 n, vec3 v, vec3 l, float Roughness, float F0){
|
||||
|
||||
// vec3 h = normalize(l + v) ;
|
||||
|
||||
// float dotNH = clamp(dot(h,n),0.,1.);
|
||||
// float dotVH = clamp(dot(h,v),0.,1.);
|
||||
|
||||
// float alpha =max(square(Roughness),1e-4) ;
|
||||
|
||||
// float WallFresnel = F0 + (1. - F0) * pow(clamp(1.0 - dotVH,0.0,1.0),5.0);
|
||||
// float Sun = square( dotNH - pow(alpha,1.5) - 1.0);
|
||||
|
||||
// float Final = ((alpha / (10.0 * Sun + 1e-4)) * WallFresnel);
|
||||
|
||||
// return Final ;
|
||||
// }
|
||||
float SunGGX(vec3 n, vec3 v, vec3 l, float roughness,float F0, float fresnel){
|
||||
|
||||
|
||||
float alpha = square(roughness) + 1e-4; // when roughness is zero it fucks up
|
||||
|
||||
vec3 h = normalize(l + v) * mix(1.000, 1.0025, pow(fresnel,2) );
|
||||
|
||||
float dotLH = clamp(dot(h,l),0.,1.);
|
||||
float dotNH = clamp(dot(h,n),0.,1.);
|
||||
float dotNL = clamp(dot(n,l),0.,1.);
|
||||
float dotNV = clamp(dot(n,v),0.,1.);
|
||||
float dotVH = clamp(dot(h,v),0.,1.);
|
||||
|
||||
|
||||
float D = alpha / (0.0541592653589793*square(square(dotNH) * (alpha - 1.0) + 1.0));
|
||||
float G = gSimple(dotNV, roughness) * gSimple(dotNL, roughness);
|
||||
float F = F0 + (1. - F0) * exp2((-5.55473*dotVH-6.98316)*dotVH);
|
||||
|
||||
return dotNL * F * (G * D / (4 * dotNV * dotNL + 1e-7));
|
||||
}
|
||||
|
||||
|
||||
vec3 normVec (vec3 vec){
|
||||
return vec*inversesqrt(dot(vec,vec));
|
||||
}
|
||||
float getWaterHeightmap_dimension(vec2 posxz, float waveM, float waveZ, float iswater) { // water waves
|
||||
vec2 movement = vec2(frameTimeCounter*0.01);
|
||||
vec2 pos = posxz ;
|
||||
float caustic = 1.0;
|
||||
float weightSum = 0.0;
|
||||
|
||||
float radiance = 2.39996;
|
||||
mat2 rotationMatrix = mat2(vec2(cos(radiance), -sin(radiance)), vec2(sin(radiance), cos(radiance)));
|
||||
|
||||
for (int i = 0; i < 3; i++){
|
||||
pos = rotationMatrix * pos ;
|
||||
|
||||
float Waves = texture2D(noisetex, pos / 64.0 + movement).b;
|
||||
|
||||
|
||||
caustic += exp2(pow(Waves,3.0) * -5.0);
|
||||
weightSum += exp2(-(3.0-caustic));
|
||||
}
|
||||
return ((3.0-caustic) * weightSum / (30.0 * 3.0));
|
||||
}
|
||||
|
||||
vec3 getWaveHeightmap_dimension(vec2 posxz, float iswater){
|
||||
|
||||
vec2 coord = posxz;
|
||||
|
||||
float deltaPos = 0.25;
|
||||
|
||||
float waveZ = mix(20.0,0.25,iswater);
|
||||
float waveM = mix(0.0,4.0,iswater);
|
||||
|
||||
float h0 = getWaterHeightmap_dimension(coord, waveM, waveZ, iswater);
|
||||
float h1 = getWaterHeightmap_dimension(coord + vec2(deltaPos,0.0), waveM, waveZ, iswater);
|
||||
float h3 = getWaterHeightmap_dimension(coord + vec2(0.0,deltaPos), waveM, waveZ, iswater);
|
||||
|
||||
|
||||
float xDelta = ((h1-h0))/deltaPos*2.;
|
||||
float yDelta = ((h3-h0))/deltaPos*2.;
|
||||
|
||||
vec3 wave = normalize(vec3(xDelta,yDelta,1.0-pow(abs(xDelta+yDelta),2.0)));
|
||||
|
||||
return wave;
|
||||
}
|
||||
#define PHYSICSMOD_FRAGMENT
|
||||
#include "/lib/oceans.glsl"
|
||||
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
/* RENDERTARGETS:2,7,1,11,13,14 */
|
||||
|
||||
/* RENDERTARGETS:2,7,11,14 */
|
||||
void main() {
|
||||
if (gl_FragCoord.x * texelSize.x < 1 && gl_FragCoord.y * texelSize.y < 1 ) {
|
||||
if (gl_FragCoord.x * texelSize.x < RENDER_SCALE.x && gl_FragCoord.y * texelSize.y < RENDER_SCALE.y ) {
|
||||
vec2 tempOffset = offsets[framemod8];
|
||||
vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0));
|
||||
|
||||
gl_FragData[0] = texture2D(texture, lmtexcoord.xy, Texture_MipMap_Bias) * color;
|
||||
vec3 Albedo = toLinear(gl_FragData[0].rgb);
|
||||
|
||||
float UnchangedAlpha = gl_FragData[0].a;
|
||||
|
||||
float iswater = normalMat.w;
|
||||
|
||||
#ifdef HAND
|
||||
iswater = 0.1;
|
||||
#endif
|
||||
#ifndef Vanilla_like_water
|
||||
|
||||
#ifdef Vanilla_like_water
|
||||
if (iswater > 0.5) {
|
||||
gl_FragData[0].a = luma(Albedo.rgb);
|
||||
Albedo = color.rgb * sqrt(luma(Albedo.rgb));
|
||||
}
|
||||
#else
|
||||
if (iswater > 0.9) {
|
||||
Albedo = vec3(0.0);
|
||||
gl_FragData[0] = vec4(vec3(0.0),1.0/255.0);
|
||||
}
|
||||
#endif
|
||||
#ifdef Vanilla_like_water
|
||||
if (iswater > 0.5) {
|
||||
gl_FragData[0].a = luma(Albedo.rgb);
|
||||
Albedo = color.rgb;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// gl_FragData[4] = vec4(Albedo, gl_FragData[0].a);
|
||||
vec4 COLORTEST = vec4(Albedo,UnchangedAlpha);
|
||||
|
||||
|
||||
vec2 tempOffset=offsets[framemod8];
|
||||
vec3 fragC = gl_FragCoord.xyz*vec3(texelSize,1.0);
|
||||
vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0));
|
||||
vec3 p3 = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz;
|
||||
vec3 np3 = normVec(p3);
|
||||
|
||||
|
||||
vec3 normal = normalMat.xyz;
|
||||
vec3 WaterNormals;
|
||||
vec3 TranslucentNormals;
|
||||
vec2 TangentNormal = vec2(0); // for refractions
|
||||
|
||||
mat3 tbnMatrix = mat3(tangent.x, binormal.x, normal.x,
|
||||
tangent.y, binormal.y, normal.y,
|
||||
tangent.z, binormal.z, normal.z);
|
||||
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 ------ ///
|
||||
|
||||
vec4 NormalTex = texture2D(normals, lmtexcoord.xy, Texture_MipMap_Bias).rgba;
|
||||
NormalTex.xy = NormalTex.xy*2.0-1.0;
|
||||
NormalTex.z = clamp(sqrt(1.0 - dot(NormalTex.xy, NormalTex.xy)),0.0,1.0) ;
|
||||
TangentNormal = NormalTex.xy*0.5+0.5;
|
||||
|
||||
normal = applyBump(tbnMatrix, NormalTex.xyz, 1.0);
|
||||
|
||||
if (iswater > 0.4){
|
||||
float bumpmult = 1.;
|
||||
if (iswater > 0.95){
|
||||
float bumpmult = 1.0;
|
||||
vec3 bump = vec3(0);
|
||||
vec3 posxz = p3+cameraPosition;
|
||||
|
||||
posxz.xz -= posxz.y;
|
||||
|
||||
vec3 bump;
|
||||
|
||||
posxz.xyz = getParallaxDisplacement(posxz,iswater,bumpmult,normalize(tbnMatrix*fragpos)) ;
|
||||
|
||||
bump = normalize(getWaveHeightmap_dimension(posxz.xz,iswater));
|
||||
WaterNormals = bump; // tangent space normals for refraction
|
||||
bump = normalize(getWaveHeight(posxz.xz,iswater));
|
||||
|
||||
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);
|
||||
|
||||
|
||||
}else{
|
||||
vec3 normalTex = texture2D(normals, lmtexcoord.xy, Texture_MipMap_Bias).rgb;
|
||||
|
||||
normalTex.xy = normalTex.xy*2.0-1.0;
|
||||
normalTex.z = clamp(sqrt(1.0 - dot(normalTex.xy, normalTex.xy)),0.0,1.0);
|
||||
|
||||
TranslucentNormals = normalTex;
|
||||
|
||||
normal = applyBump(tbnMatrix,normalTex);
|
||||
}
|
||||
|
||||
TranslucentNormals += WaterNormals;
|
||||
|
||||
vec4 data0 = vec4(1);
|
||||
vec4 data1 = clamp( encode(TranslucentNormals, lmtexcoord.zw),0.0,1.0);
|
||||
gl_FragData[3] = vec4(encodeVec2(data0.x,data1.x), encodeVec2(data0.y,data1.y), encodeVec2(data0.z,data1.z), encodeVec2(data1.w,data0.w));
|
||||
gl_FragData[5] = vec4(encodeVec2(lmtexcoord.a,lmtexcoord.a), encodeVec2(lmtexcoord.a,lmtexcoord.a), encodeVec2(lmtexcoord.a,lmtexcoord.a), encodeVec2(lmtexcoord.a,lmtexcoord.a));
|
||||
gl_FragData[2] = vec4(encodeVec2(TangentNormal), encodeVec2(COLORTEST.rg), encodeVec2(COLORTEST.ba), UnchangedAlpha);
|
||||
|
||||
|
||||
vec3 Indirect_lighting = DoAmbientLighting_Nether(gl_Fog.color.rgb, vec3(TORCH_R,TORCH_G,TORCH_B), lmtexcoord.z, viewToWorld(normal), np3, p3 + cameraPosition);
|
||||
|
||||
vec3 WS_normal = viewToWorld(normal);
|
||||
|
||||
vec2 lightmaps2 = lmtexcoord.zw;
|
||||
vec3 Indirect_lighting = vec3(0.0);
|
||||
|
||||
#ifdef NETHER
|
||||
WS_normal.xz = -WS_normal.xz;
|
||||
vec3 AmbientLightColor = skyCloudsFromTexLOD2(WS_normal, colortex4, 6).rgb / 15;
|
||||
|
||||
vec3 up = skyCloudsFromTexLOD2(vec3( 0, 1, 0), colortex4, 6).rgb / 15;
|
||||
vec3 down = skyCloudsFromTexLOD2(vec3( 0,-1, 0), colortex4, 6).rgb / 15;
|
||||
|
||||
|
||||
up *= pow( max( WS_normal.y, 0), 2);
|
||||
down *= pow( max(-WS_normal.y, 0), 2);
|
||||
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));
|
||||
#endif
|
||||
|
||||
#ifdef END
|
||||
// do all ambient lighting stuff
|
||||
Indirect_lighting = DoAmbientLighting_End(gl_Fog.color.rgb, vec3(TORCH_R,TORCH_G,TORCH_B), lightmaps2.x, normal, p3 );
|
||||
#endif
|
||||
|
||||
vec3 FinalColor = Indirect_lighting * Albedo;
|
||||
|
||||
#ifdef Glass_Tint
|
||||
@ -512,29 +371,39 @@ void main() {
|
||||
FinalColor *= alphashit;
|
||||
#endif
|
||||
|
||||
#ifdef WATER_REFLECTIONS
|
||||
vec2 SpecularTex = texture2D(specular, lmtexcoord.xy, Texture_MipMap_Bias).rg;
|
||||
SpecularTex = iswater > 0.0 && SpecularTex.r > 0.0 && SpecularTex.g < 0.9 ? SpecularTex : vec2(1.0,0.02);
|
||||
|
||||
if (iswater > 0.0 || (SpecularTex.g > 0.0 || SpecularTex.r > 0.0)){
|
||||
vec3 Reflections_Final = vec3(0.0);
|
||||
float roughness = pow(1.0-SpecularTex.r,2.0);
|
||||
SpecularTex = (iswater > 0.0 && iswater < 0.9) && SpecularTex.r > 0.0 && SpecularTex.g < 0.9 ? SpecularTex : vec2(1.0,0.1);
|
||||
|
||||
float roughness = max(pow(1.0-SpecularTex.r,2.0),0.05);
|
||||
float f0 = SpecularTex.g;
|
||||
float F0 = f0;
|
||||
|
||||
float visibilityFactor = clamp(exp2((pow(roughness,3.0) / f0) * -4),0,1);
|
||||
if (iswater > 0.0){
|
||||
vec3 Reflections_Final = vec3(0.0);
|
||||
vec4 Reflections = vec4(0.0);
|
||||
vec3 SkyReflection = vec3(0.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);
|
||||
|
||||
// snells window looking thing
|
||||
if(isEyeInWater == 1 && iswater > 0.99) fresnel = clamp(pow(1.66 + normalDotEye,25),0.02,1.0);
|
||||
if(isEyeInWater == 1 ) fresnel = pow(clamp(1.66 + normalDotEye,0.0,1.0), 25.0);
|
||||
|
||||
fresnel = F0 + (1.0 - F0) * fresnel;
|
||||
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);
|
||||
#endif
|
||||
|
||||
vec4 Reflections = vec4(0.0);
|
||||
if(iswater > 0){
|
||||
#ifdef SCREENSPACE_REFLECTIONS
|
||||
if(iswater > 0.0){
|
||||
vec3 rtPos = rayTrace(reflectedVector,fragpos.xyz, interleaved_gradientNoise(), fresnel, isEyeInWater == 1);
|
||||
if (rtPos.z < 1.){
|
||||
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rtPos) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition;
|
||||
@ -545,33 +414,32 @@ void main() {
|
||||
Reflections.rgb = texture2D(colortex5,previousPosition.xy).rgb;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
float visibilityFactor = clamp(exp2((pow(roughness,3.0) / f0) * -4),0,1);
|
||||
|
||||
Reflections_Final = mix(FinalColor, Reflections.rgb, Reflections.a * fresnel * visibilityFactor);
|
||||
|
||||
|
||||
float F2 = pow(clamp(1.0 + normalDotEye,0.0,1.0),pow(1.0-roughness,2.0) * 1.5 + 0.5);
|
||||
F2 = mix(f0, 1.0, F2);
|
||||
|
||||
Reflections_Final += mix( gl_Fog.color.rgb * 0.25, vec3(0.0), Reflections.a * visibilityFactor) ;
|
||||
Reflections_Final = mix(SkyReflection, Reflections.rgb, Reflections.a);
|
||||
Reflections_Final = mix(FinalColor, Reflections_Final, fresnel * visibilityFactor);
|
||||
|
||||
gl_FragData[0].rgb = Reflections_Final;
|
||||
|
||||
//correct alpha channel with fresnel
|
||||
float alpha0 = gl_FragData[0].a;
|
||||
gl_FragData[0].a = -gl_FragData[0].a*fresnel+gl_FragData[0].a+fresnel;
|
||||
gl_FragData[0].a = mix(gl_FragData[0].a, 1.0, fresnel);
|
||||
|
||||
if (gl_FragData[0].r > 65000.) gl_FragData[0].rgba = vec4(0.);
|
||||
|
||||
|
||||
} else {
|
||||
gl_FragData[0].rgb = FinalColor;
|
||||
}
|
||||
#else
|
||||
gl_FragData[0].rgb = FinalColor;
|
||||
#endif
|
||||
|
||||
#ifndef HAND
|
||||
gl_FragData[1] = vec4(Albedo,iswater);
|
||||
#endif
|
||||
|
||||
gl_FragData[3].a = max(lmtexcoord.w*blueNoise()*0.05 + lmtexcoord.w,0.0);
|
||||
}
|
||||
}
|
@ -254,6 +254,7 @@ vec3 worldToView(vec3 worldPos) {
|
||||
}
|
||||
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);
|
||||
@ -262,31 +263,38 @@ void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estE
|
||||
//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 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;
|
||||
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 progressW = start.xyz+cameraPosition+dVWorld;
|
||||
|
||||
vec3 ambientMul = exp(-max(estEndDepth * d,0.0) * waterCoefs );
|
||||
vec3 Indirectlight = ambientMul*ambient;
|
||||
|
||||
vec3 light = (ambientMul*ambient) * scatterCoef;
|
||||
vec3 light = Indirectlight * scatterCoef;
|
||||
|
||||
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
|
||||
absorbance *= exp(-dd * rayLength * waterCoefs);
|
||||
}
|
||||
inColor += vL;
|
||||
|
||||
}
|
||||
|
||||
void Emission(
|
||||
@ -562,6 +570,8 @@ void main() {
|
||||
bool hand = abs(dataUnpacked1.w-0.75) < 0.01;
|
||||
// bool blocklights = abs(dataUnpacked1.w-0.8) <0.01;
|
||||
|
||||
vec3 waterAmbientLightCol = vec3(0.0);
|
||||
|
||||
if (z >=1.0) {
|
||||
vec3 color = clamp(gl_Fog.color.rgb*pow(luma(gl_Fog.color.rgb),-0.75)*0.65,0.0,1.0)*0.02;
|
||||
|
||||
@ -580,6 +590,8 @@ void main() {
|
||||
vec3 up = skyCloudsFromTexLOD2(vec3( 0, 1, 0), colortex4, 6).rgb / 10;
|
||||
vec3 down = skyCloudsFromTexLOD2(vec3( 0,-1, 0), colortex4, 6).rgb / 10;
|
||||
|
||||
waterAmbientLightCol = down;
|
||||
|
||||
up *= pow( max( slopednormal.y, 0), 2);
|
||||
down *= pow( max(-slopednormal.y, 0), 2);
|
||||
AmbientLightColor += up + down;
|
||||
@ -619,38 +631,21 @@ void main() {
|
||||
|
||||
// gl_FragData[0].rgb = AmbientLightColor;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ////// border Fog
|
||||
// if(Translucent_Programs > 0.0){
|
||||
// vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z));
|
||||
// float fogdistfade = 1.0 - clamp( exp(-pow(length(fragpos / far),2.)*5.0) ,0.0,1.0);
|
||||
|
||||
// gl_FragData[0].rgb = mix(gl_FragData[0].rgb, gl_Fog.color.rgb*0.5*NetherFog_brightness, fogdistfade) ;
|
||||
// }
|
||||
|
||||
|
||||
////// Water Fog
|
||||
if ((isEyeInWater == 0 && iswater) || (isEyeInWater == 1 && !iswater)){
|
||||
vec3 fragpos0 = toScreenSpace(vec3(texcoord-vec2(tempOffset)*texelSize*0.5,z0));
|
||||
if (iswater && isEyeInWater == 0){
|
||||
vec3 fragpos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0));
|
||||
float Vdiff = distance(fragpos,fragpos0);
|
||||
|
||||
if(isEyeInWater == 1) Vdiff = (length(fragpos));
|
||||
|
||||
float VdotU = np3.y;
|
||||
float estimatedDepth = Vdiff; //assuming water plane
|
||||
float estimatedSunDepth = estimatedDepth; //assuming water plane
|
||||
float estimatedDepth = Vdiff * abs(VdotU) ; //assuming water plane
|
||||
|
||||
vec3 ambientColVol = vec3(1.0,0.25,0.5) * 0.33 ;
|
||||
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 , estimatedSunDepth, Vdiff, noise, totEpsilon, scatterCoef, ambientColVol);
|
||||
waterVolumetrics(gl_FragData[0].rgb, fragpos0, fragpos, estimatedDepth , estimatedDepth, Vdiff, noise, totEpsilon, scatterCoef, ambientColVol);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// gl_FragData[0].rgb = SubsurfaceScattering_sky(albedo, Indirect_SSS, 1.0) * vec3(1);
|
||||
/* DRAWBUFFERS:3 */
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "/lib/settings.glsl"
|
||||
|
||||
flat varying float tempOffsets;
|
||||
flat varying vec2 TAA_Offset;
|
||||
uniform sampler2D noisetex;
|
||||
uniform sampler2D depthtex0;
|
||||
|
||||
@ -42,6 +43,51 @@ float blueNoise(){
|
||||
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
|
||||
}
|
||||
|
||||
void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient){
|
||||
inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value
|
||||
|
||||
int spCount = rayMarchSampleCount;
|
||||
vec3 start = toShadowSpaceProjected(rayStart);
|
||||
vec3 end = toShadowSpaceProjected(rayEnd);
|
||||
vec3 dV = (end-start);
|
||||
//limit ray length at 32 blocks for performance and reducing integration error
|
||||
//you can't see above this anyway
|
||||
float maxZ = min(rayLength,12.0)/(1e-8+rayLength);
|
||||
dV *= maxZ;
|
||||
|
||||
|
||||
rayLength *= maxZ;
|
||||
|
||||
float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength;
|
||||
estEndDepth *= maxZ;
|
||||
estSunDepth *= maxZ;
|
||||
|
||||
vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz;
|
||||
vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
|
||||
|
||||
vec3 absorbance = vec3(1.0);
|
||||
vec3 vL = vec3(0.0);
|
||||
|
||||
float expFactor = 11.0;
|
||||
for (int i=0;i<spCount;i++) {
|
||||
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
|
||||
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
|
||||
vec3 spPos = start.xyz + dV*d;
|
||||
|
||||
vec3 progressW = start.xyz+cameraPosition+dVWorld;
|
||||
|
||||
vec3 ambientMul = exp(-max(estEndDepth * d,0.0) * waterCoefs );
|
||||
vec3 Indirectlight = ambientMul*ambient;
|
||||
|
||||
vec3 light = Indirectlight * scatterCoef;
|
||||
|
||||
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
|
||||
absorbance *= exp(-dd * rayLength * waterCoefs);
|
||||
}
|
||||
inColor += vL;
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
@ -54,16 +100,30 @@ float blueNoise(){
|
||||
void main() {
|
||||
/* DRAWBUFFERS:0 */
|
||||
|
||||
// if (isEyeInWater == 0){
|
||||
vec2 tc = floor(gl_FragCoord.xy)*2.0*texelSize+0.5*texelSize;
|
||||
float z = texture2D(depthtex0,tc).x;
|
||||
vec3 fragpos = toScreenSpace(vec3(tc,z));
|
||||
|
||||
if (isEyeInWater == 0){
|
||||
|
||||
vec4 VolumetricFog = GetVolumetricFog(fragpos, blueNoise());
|
||||
|
||||
gl_FragData[0] = clamp(VolumetricFog, 0.0, 65000.0);
|
||||
|
||||
// } else {
|
||||
// gl_FragData[0] = vec4(0.0);
|
||||
// }
|
||||
} else {
|
||||
|
||||
float dirtAmount = Dirt_Amount;
|
||||
vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
|
||||
vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B);
|
||||
vec3 totEpsilon = dirtEpsilon*dirtAmount + waterEpsilon;
|
||||
vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
|
||||
|
||||
vec3 fragpos0 = toScreenSpace(vec3(texcoord - TAA_Offset*texelSize*0.5,z));
|
||||
|
||||
vec3 ambientColVol = max(vec3(1.0,0.5,1.0) * 0.6, vec3(0.2,0.4,1.0) * MIN_LIGHT_AMOUNT*0.01);
|
||||
|
||||
gl_FragData[0].a = 1;
|
||||
waterVolumetrics(gl_FragData[0].rgb, fragpos0, fragpos, 1 , 1, 1, blueNoise(), totEpsilon, scatterCoef, ambientColVol);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,16 @@ uniform int frameCounter;
|
||||
|
||||
#include "/lib/util.glsl"
|
||||
|
||||
flat varying vec2 TAA_Offset;
|
||||
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
|
||||
vec2(-1.,3.)/8.,
|
||||
vec2(5.0,1.)/8.,
|
||||
vec2(-3,-5.)/8.,
|
||||
vec2(-5.,5.)/8.,
|
||||
vec2(-7.,-1.)/8.,
|
||||
vec2(3,7.)/8.,
|
||||
vec2(7.,-7.)/8.);
|
||||
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
@ -17,6 +27,11 @@ void main() {
|
||||
gl_Position = ftransform();
|
||||
|
||||
tempOffsets = HaltonSeq2(frameCounter%10000);
|
||||
TAA_Offset = offsets[frameCounter%8];
|
||||
|
||||
#ifndef TAA
|
||||
TAA_Offset = vec2(0.0);
|
||||
#endif
|
||||
|
||||
gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.51*2.0-1.0;
|
||||
}
|
||||
|
@ -1,81 +1,121 @@
|
||||
#version 120
|
||||
//Horizontal bilateral blur for volumetric fog + Forward rendered objects + Draw volumetric fog
|
||||
//#extension GL_EXT_gpu_shader4 : disable
|
||||
|
||||
#include "/lib/settings.glsl"
|
||||
|
||||
|
||||
varying vec2 texcoord;
|
||||
flat varying vec3 zMults;
|
||||
flat varying vec2 TAA_Offset;
|
||||
|
||||
|
||||
uniform sampler2D noisetex;
|
||||
uniform sampler2D depthtex0;
|
||||
uniform sampler2D depthtex1;
|
||||
uniform sampler2D colortex13;
|
||||
uniform sampler2D colortex11;
|
||||
uniform sampler2D colortex7;
|
||||
uniform sampler2D colortex3;
|
||||
uniform sampler2D colortex4;
|
||||
uniform sampler2D colortex2;
|
||||
uniform sampler2D colortex0;
|
||||
uniform sampler2D noisetex;
|
||||
uniform sampler2D colortex1;
|
||||
uniform sampler2D colortex2;
|
||||
uniform sampler2D colortex3;
|
||||
// uniform sampler2D colortex4;
|
||||
uniform sampler2D colortex5;
|
||||
uniform sampler2D colortex6;
|
||||
uniform sampler2D colortex7;
|
||||
uniform sampler2D colortex8;
|
||||
uniform sampler2D colortex9;
|
||||
uniform sampler2D colortex11;
|
||||
uniform sampler2D colortex13;
|
||||
uniform sampler2D colortex15;
|
||||
uniform vec2 texelSize;
|
||||
|
||||
flat varying vec3 noooormal;
|
||||
flat varying vec4 lightCol; //main light source color (rgb),used light source(1=sun,-1=moon)
|
||||
flat varying vec3 WsunVec;
|
||||
|
||||
uniform vec3 sunVec;
|
||||
uniform float frameTimeCounter;
|
||||
uniform int frameCounter;
|
||||
uniform float far;
|
||||
uniform float near;
|
||||
uniform mat4 gbufferModelViewInverse;
|
||||
uniform mat4 gbufferProjectionInverse;
|
||||
uniform mat4 gbufferModelView;
|
||||
uniform vec2 texelSize;
|
||||
uniform mat4 gbufferPreviousModelView;
|
||||
uniform mat4 gbufferProjectionInverse;
|
||||
uniform mat4 gbufferProjection;
|
||||
uniform mat4 gbufferPreviousProjection;
|
||||
uniform vec3 cameraPosition;
|
||||
uniform vec3 previousCameraPosition;
|
||||
|
||||
uniform int isEyeInWater;
|
||||
uniform ivec2 eyeBrightnessSmooth;
|
||||
uniform float rainStrength;
|
||||
uniform float blindness;
|
||||
uniform float darknessFactor;
|
||||
uniform float darknessLightFactor;
|
||||
|
||||
|
||||
#include "/lib/waterBump.glsl"
|
||||
#include "/lib/res_params.glsl"
|
||||
|
||||
#include "/lib/sky_gradient.glsl"
|
||||
#include "/lib/volumetricClouds.glsl"
|
||||
// #include "/lib/biome_specifics.glsl"
|
||||
|
||||
|
||||
|
||||
|
||||
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
|
||||
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
|
||||
|
||||
float ld(float depth) {
|
||||
return 1.0 / (zMults.y - depth * zMults.z); // (-depth * (far - near)) = (2.0 * near)/ld - far - near
|
||||
}
|
||||
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
|
||||
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
|
||||
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;
|
||||
}
|
||||
vec4 BilateralUpscale(sampler2D tex, sampler2D depth,vec2 coord,float frDepth){
|
||||
|
||||
|
||||
// #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;
|
||||
ivec2 posD = ivec2(coord/2.0)*2;
|
||||
ivec2 posVl = ivec2(coord/2.0);
|
||||
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;
|
||||
//pos = ivec2(1,-1);
|
||||
|
||||
ivec2 tcDepth = posD + ivec2(-4,-4) + pos*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(-4,0) + pos*2;
|
||||
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*2;
|
||||
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,-4) + pos*2;
|
||||
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;
|
||||
@ -92,7 +132,6 @@ vec3 decode (vec2 encn){
|
||||
n.xy = n.z <= 0.0 ? (1.0 - n.yx) * sign(encn) : encn;
|
||||
return clamp(normalize(n.xyz),-1.0,1.0);
|
||||
}
|
||||
|
||||
vec2 decodeVec2(float a){
|
||||
const vec2 constant1 = 65535. / vec2( 256., 65536.);
|
||||
const float constant2 = 256. / 255.;
|
||||
@ -104,94 +143,158 @@ vec3 worldToView(vec3 worldPos) {
|
||||
pos = gbufferModelView * pos;
|
||||
return pos.xyz;
|
||||
}
|
||||
float luma(vec3 color) {
|
||||
return dot(color,vec3(0.21, 0.72, 0.07));
|
||||
float blueNoise(){
|
||||
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
|
||||
}
|
||||
vec4 blueNoise(vec2 coord){
|
||||
return texelFetch2D(colortex6, ivec2(coord )%512 , 0);
|
||||
}
|
||||
vec3 normVec (vec3 vec){
|
||||
return vec*inversesqrt(dot(vec,vec));
|
||||
}
|
||||
|
||||
float interleaved_gradientNoise(){
|
||||
vec2 coord = gl_FragCoord.xy;
|
||||
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
|
||||
return noise;
|
||||
}
|
||||
vec3 viewToWorld(vec3 viewPosition) {
|
||||
vec4 pos;
|
||||
pos.xyz = viewPosition;
|
||||
pos.w = 0.0;
|
||||
pos = gbufferModelViewInverse * pos;
|
||||
return pos.xyz;
|
||||
}
|
||||
|
||||
/// thanks stackoverflow https://stackoverflow.com/questions/944713/help-with-pixel-shader-effect-for-brightness-and-contrast#3027595
|
||||
void applyContrast(inout vec3 color, float contrast){
|
||||
color = ((color - 0.5) * max(contrast, 0.0)) + 0.5;
|
||||
}
|
||||
void main() {
|
||||
/* DRAWBUFFERS:73 */
|
||||
|
||||
vec2 texcoord = gl_FragCoord.xy*texelSize;
|
||||
|
||||
vec4 trpData = texture2D(colortex7,texcoord);
|
||||
|
||||
bool iswater = trpData.a > 0.99;
|
||||
float translucentAlpha = trpData.a;
|
||||
|
||||
// vec4 speculartex = texture2D(colortex8,texcoord); // translucents
|
||||
// float sunlight = speculartex.b;
|
||||
|
||||
//3x3 bilateral upscale from half resolution
|
||||
float z = texture2D(depthtex0,texcoord).x;
|
||||
float z2 = texture2D(depthtex1,texcoord).x;
|
||||
float frDepth = ld(z);
|
||||
float glassdepth = clamp((ld(z2) - ld(z)) * 0.5,0.0,0.15);
|
||||
float frDepth = ld(z2);
|
||||
|
||||
// vec4 vl = BilateralUpscale(colortex0,depthtex0,gl_FragCoord.xy,frDepth);
|
||||
float bloomyFogMult = 1.0;
|
||||
// vec4 vl = texture2D(colortex0,texcoord * 0.5);
|
||||
|
||||
////// --------------- UNPACK OPAQUE GBUFFERS --------------- //////
|
||||
vec4 data_opaque = texture2D(colortex1,texcoord);
|
||||
vec4 dataUnpacked1 = vec4(decodeVec2(data_opaque.z),decodeVec2(data_opaque.w)); // normals, lightmaps
|
||||
// vec4 dataUnpacked2 = vec4(decodeVec2(data.z),decodeVec2(data.w));
|
||||
|
||||
bool hand = abs(dataUnpacked1.w-0.75) < 0.01;
|
||||
vec2 lightmap = dataUnpacked1.yz;
|
||||
|
||||
////// --------------- UNPACK TRANSLUCENT GBUFFERS --------------- //////
|
||||
|
||||
vec3 data = texture2D(colortex11,texcoord).rgb;
|
||||
|
||||
vec4 unpack0 = vec4(decodeVec2(data.r),decodeVec2(data.g)) ;
|
||||
vec4 unpack1 = vec4(decodeVec2(data.b),0,0) ;
|
||||
|
||||
|
||||
|
||||
vec4 albedo = vec4(unpack0.ba,unpack1.rg);
|
||||
|
||||
vec2 tangentNormals = unpack0.xy*2.0-1.0;
|
||||
|
||||
if(albedo.a <= 0.0) tangentNormals = vec2(0.0);
|
||||
|
||||
vec4 TranslucentShader = texture2D(colortex2,texcoord);
|
||||
|
||||
float lightleakfix = clamp(pow(eyeBrightnessSmooth.y/240.,2) ,0.0,1.0);
|
||||
|
||||
|
||||
vec2 tempOffset = TAA_Offset;
|
||||
vec3 fragpos = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z));
|
||||
vec3 fragpos2 = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z2));
|
||||
|
||||
|
||||
vec3 p3 = mat3(gbufferModelViewInverse) * fragpos;
|
||||
vec3 np3 = normVec(p3);
|
||||
|
||||
vec4 Translucent_Programs = texture2D(colortex2,texcoord); // the shader for all translucent progams.
|
||||
|
||||
vec4 trpData = texture2D(colortex7,texcoord);
|
||||
bool iswater = trpData.a > 0.99;
|
||||
vec2 refractedCoord = texcoord;
|
||||
|
||||
|
||||
|
||||
vec2 data = texture2D(colortex11,texcoord).xy; // translucents
|
||||
vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y));
|
||||
|
||||
vec3 normals = mat3(gbufferModelViewInverse) * worldToView(decode(dataUnpacked0.yw) );
|
||||
|
||||
vec4 vl = BilateralUpscale(colortex0,depthtex0,gl_FragCoord.xy,frDepth);
|
||||
|
||||
/// --- REFRACTION --- ///
|
||||
#ifdef Refraction
|
||||
refractedCoord += normals.xy * glassdepth;
|
||||
refractedCoord += (tangentNormals * clamp((ld(z2) - ld(z)) * 0.5,0.0,0.15)) * RENDER_SCALE;
|
||||
// refractedCoord += tangentNormals * 0.1 * RENDER_SCALE;
|
||||
|
||||
float refractedalpha = texture2D(colortex13,refractedCoord).a;
|
||||
if(refractedalpha <= 0.0) refractedCoord = texcoord; // remove refracted coords on solids
|
||||
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;
|
||||
|
||||
if (Translucent_Programs.a > 0.0){
|
||||
vec4 vl = BilateralUpscale(colortex0, depthtex1, gl_FragCoord.xy, frDepth, vec2(0.0));
|
||||
float bloomyFogMult = 1.0;
|
||||
|
||||
if (TranslucentShader.a > 0.0){
|
||||
#ifdef Glass_Tint
|
||||
vec3 GlassAlbedo = texture2D(colortex13,texcoord).rgb * 5.0;
|
||||
color = color*GlassAlbedo.rgb + color * clamp(pow(1.0-luma(GlassAlbedo.rgb),10.),0.0,1.0);
|
||||
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-Translucent_Programs.a) + Translucent_Programs.rgb;
|
||||
color = color*(1.0-TranslucentShader.a) + TranslucentShader.rgb;
|
||||
}
|
||||
|
||||
// if (isEyeInWater == 0){
|
||||
// vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z));
|
||||
// float fogdistfade = 1.0 - clamp( exp(-pow(length(fragpos / far),2.)*5.0) ,0.0,1.0);
|
||||
// bloomyFogMult = 1.0 - fogdistfade*0.5 ;
|
||||
|
||||
// color.rgb = mix(color.rgb, gl_Fog.color.rgb*0.5*NetherFog_brightness, fogdistfade) ;
|
||||
// }
|
||||
|
||||
color *= vl.a;
|
||||
color += vl.rgb;
|
||||
|
||||
|
||||
|
||||
// underwater fog
|
||||
if (isEyeInWater == 1){
|
||||
vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z));
|
||||
float fogfade = clamp(exp(-length(fragpos) /5. ) ,0.0,1.0);
|
||||
bloomyFogMult *= fogfade*0.70+0.3 ;
|
||||
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){
|
||||
vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z));
|
||||
color.rgb = mix(color.rgb,vec3(10,15,20),clamp(length(fragpos)*0.5,0.,1.));
|
||||
bloomyFogMult = 0.0;
|
||||
}
|
||||
// blidnesss
|
||||
if (blindness > 0.0){
|
||||
vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z));
|
||||
color.rgb *= mix(1.0,clamp( exp(pow(length(fragpos)*(blindness*0.2),2) * -5),0.,1.) , blindness);
|
||||
}
|
||||
// darkness effect
|
||||
if(darknessFactor > 0.0){
|
||||
vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z2));
|
||||
color.rgb *= mix(1.0, (1.0-darknessLightFactor*2.0) * clamp(1.0-pow(length(fragpos)*(darknessFactor*0.07),2.0),0.0,1.0), darknessFactor);
|
||||
}
|
||||
|
||||
gl_FragData[0].r = vl.a * bloomyFogMult;
|
||||
// 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;
|
||||
@ -199,5 +302,8 @@ void main() {
|
||||
if(luma(thingy) > 0.0 ) color.rgb = thingy;
|
||||
#endif
|
||||
|
||||
gl_FragData[1].rgb = clamp(color,6.11*1e-5,65000.0);
|
||||
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,3 +1,4 @@
|
||||
#version 120
|
||||
|
||||
#define NETHER
|
||||
#include "/programs/all_translucent.fsh"
|
@ -622,30 +622,17 @@ void main() {
|
||||
|
||||
}
|
||||
|
||||
// ////// border Fog
|
||||
// if(Translucent_Programs > 0.0){
|
||||
// vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z));
|
||||
// float fogdistfade = 1.0 - clamp( exp(-pow(length(fragpos / far),2.)*5.0) ,0.0,1.0);
|
||||
|
||||
// gl_FragData[0].rgb = mix(gl_FragData[0].rgb, gl_Fog.color.rgb*0.5*NetherFog_brightness, fogdistfade) ;
|
||||
// }
|
||||
|
||||
|
||||
////// Water Fog
|
||||
if ((isEyeInWater == 0 && iswater) || (isEyeInWater == 1 && !iswater)){
|
||||
vec3 fragpos0 = toScreenSpace(vec3(texcoord-vec2(tempOffset)*texelSize*0.5,z0));
|
||||
if (iswater && isEyeInWater == 0){
|
||||
vec3 fragpos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0));
|
||||
float Vdiff = distance(fragpos,fragpos0);
|
||||
|
||||
if(isEyeInWater == 1) Vdiff = (length(fragpos));
|
||||
|
||||
float VdotU = np3.y;
|
||||
float estimatedDepth = Vdiff; //assuming water plane
|
||||
float estimatedSunDepth = estimatedDepth; //assuming water plane
|
||||
float estimatedDepth = Vdiff * abs(VdotU) ; //assuming water plane
|
||||
|
||||
vec3 ambientColVol = vec3(1.0,0.25,0.5) * 0.33 ;
|
||||
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 , estimatedSunDepth, Vdiff, noise, totEpsilon, scatterCoef, ambientColVol);
|
||||
waterVolumetrics(gl_FragData[0].rgb, fragpos0, fragpos, estimatedDepth , estimatedDepth, Vdiff, noise, totEpsilon, scatterCoef, ambientColVol);
|
||||
}
|
||||
|
||||
|
||||
/* DRAWBUFFERS:3 */
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ flat varying vec4 lightCol;
|
||||
// flat varying vec3 ambientB;
|
||||
// flat varying vec3 ambientF;
|
||||
// flat varying vec3 ambientDown;
|
||||
flat varying vec2 TAA_Offset;
|
||||
flat varying float tempOffsets;
|
||||
flat varying float fogAmount;
|
||||
flat varying float VFAmount;
|
||||
@ -48,6 +49,51 @@ float blueNoise(){
|
||||
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
|
||||
}
|
||||
|
||||
void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient){
|
||||
inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value
|
||||
|
||||
int spCount = rayMarchSampleCount;
|
||||
vec3 start = toShadowSpaceProjected(rayStart);
|
||||
vec3 end = toShadowSpaceProjected(rayEnd);
|
||||
vec3 dV = (end-start);
|
||||
//limit ray length at 32 blocks for performance and reducing integration error
|
||||
//you can't see above this anyway
|
||||
float maxZ = min(rayLength,12.0)/(1e-8+rayLength);
|
||||
dV *= maxZ;
|
||||
|
||||
|
||||
rayLength *= maxZ;
|
||||
|
||||
float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength;
|
||||
estEndDepth *= maxZ;
|
||||
estSunDepth *= maxZ;
|
||||
|
||||
vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz;
|
||||
vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
|
||||
|
||||
vec3 absorbance = vec3(1.0);
|
||||
vec3 vL = vec3(0.0);
|
||||
|
||||
float expFactor = 11.0;
|
||||
for (int i=0;i<spCount;i++) {
|
||||
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
|
||||
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
|
||||
vec3 spPos = start.xyz + dV*d;
|
||||
|
||||
vec3 progressW = start.xyz+cameraPosition+dVWorld;
|
||||
|
||||
vec3 ambientMul = exp(-max(estEndDepth * d,0.0) * waterCoefs );
|
||||
vec3 Indirectlight = ambientMul*ambient;
|
||||
|
||||
vec3 light = Indirectlight * scatterCoef;
|
||||
|
||||
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
|
||||
absorbance *= exp(-dd * rayLength * waterCoefs);
|
||||
}
|
||||
inColor += vL;
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
@ -59,11 +105,12 @@ varying vec2 texcoord;
|
||||
void main() {
|
||||
/* DRAWBUFFERS:0 */
|
||||
|
||||
if (isEyeInWater == 0){
|
||||
vec2 tc = floor(gl_FragCoord.xy)*2.0*texelSize+0.5*texelSize;
|
||||
float z = texture2D(depthtex0,tc).x;
|
||||
vec3 fragpos = toScreenSpace(vec3(tc,z));
|
||||
|
||||
if (isEyeInWater == 0){
|
||||
|
||||
vec3 fragpos_ALT = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z));
|
||||
|
||||
float noise = blueNoise();
|
||||
@ -73,7 +120,22 @@ void main() {
|
||||
|
||||
gl_FragData[0] = clamp(vec4(vl[0],absorbance),0.000001,65000.);
|
||||
|
||||
|
||||
} else {
|
||||
gl_FragData[0] = vec4(0.0);
|
||||
|
||||
float dirtAmount = Dirt_Amount;
|
||||
vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
|
||||
vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B);
|
||||
vec3 totEpsilon = dirtEpsilon*dirtAmount + waterEpsilon;
|
||||
vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
|
||||
|
||||
vec3 fragpos0 = toScreenSpace(vec3(texcoord - TAA_Offset*texelSize*0.5,z));
|
||||
|
||||
vec3 ambientColVol = max(vec3(1.0,0.5,1.0) * 0.6, vec3(0.2,0.4,1.0) * MIN_LIGHT_AMOUNT*0.01);
|
||||
|
||||
gl_FragData[0].a = 1;
|
||||
waterVolumetrics(gl_FragData[0].rgb, fragpos0, fragpos, 1 , 1, 1, blueNoise(), totEpsilon, scatterCoef, ambientColVol);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,81 +1,121 @@
|
||||
#version 120
|
||||
//Horizontal bilateral blur for volumetric fog + Forward rendered objects + Draw volumetric fog
|
||||
#extension GL_EXT_gpu_shader4 : disable
|
||||
|
||||
//#extension GL_EXT_gpu_shader4 : disable
|
||||
#include "/lib/settings.glsl"
|
||||
|
||||
|
||||
varying vec2 texcoord;
|
||||
flat varying vec3 zMults;
|
||||
flat varying vec2 TAA_Offset;
|
||||
|
||||
|
||||
uniform sampler2D noisetex;
|
||||
uniform sampler2D depthtex0;
|
||||
uniform sampler2D depthtex1;
|
||||
uniform sampler2D colortex13;
|
||||
uniform sampler2D colortex11;
|
||||
uniform sampler2D colortex7;
|
||||
uniform sampler2D colortex4;
|
||||
uniform sampler2D colortex3;
|
||||
uniform sampler2D colortex2;
|
||||
uniform sampler2D colortex0;
|
||||
uniform sampler2D noisetex;
|
||||
uniform sampler2D colortex1;
|
||||
uniform sampler2D colortex2;
|
||||
uniform sampler2D colortex3;
|
||||
// uniform sampler2D colortex4;
|
||||
uniform sampler2D colortex5;
|
||||
uniform sampler2D colortex6;
|
||||
uniform sampler2D colortex7;
|
||||
uniform sampler2D colortex8;
|
||||
uniform sampler2D colortex9;
|
||||
uniform sampler2D colortex11;
|
||||
uniform sampler2D colortex13;
|
||||
uniform sampler2D colortex15;
|
||||
uniform vec2 texelSize;
|
||||
|
||||
flat varying vec3 noooormal;
|
||||
flat varying vec4 lightCol; //main light source color (rgb),used light source(1=sun,-1=moon)
|
||||
flat varying vec3 WsunVec;
|
||||
|
||||
uniform vec3 sunVec;
|
||||
uniform float frameTimeCounter;
|
||||
uniform int frameCounter;
|
||||
uniform float far;
|
||||
uniform float near;
|
||||
uniform mat4 gbufferModelViewInverse;
|
||||
uniform mat4 gbufferProjectionInverse;
|
||||
uniform mat4 gbufferModelView;
|
||||
uniform vec2 texelSize;
|
||||
uniform mat4 gbufferPreviousModelView;
|
||||
uniform mat4 gbufferProjectionInverse;
|
||||
uniform mat4 gbufferProjection;
|
||||
uniform mat4 gbufferPreviousProjection;
|
||||
uniform vec3 cameraPosition;
|
||||
uniform vec3 previousCameraPosition;
|
||||
|
||||
uniform int isEyeInWater;
|
||||
uniform ivec2 eyeBrightnessSmooth;
|
||||
uniform float rainStrength;
|
||||
uniform float blindness;
|
||||
uniform float darknessFactor;
|
||||
uniform float darknessLightFactor;
|
||||
|
||||
|
||||
#include "/lib/waterBump.glsl"
|
||||
#include "/lib/res_params.glsl"
|
||||
|
||||
#include "/lib/sky_gradient.glsl"
|
||||
#include "/lib/volumetricClouds.glsl"
|
||||
// #include "/lib/biome_specifics.glsl"
|
||||
|
||||
|
||||
|
||||
|
||||
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
|
||||
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
|
||||
|
||||
float ld(float depth) {
|
||||
return 1.0 / (zMults.y - depth * zMults.z); // (-depth * (far - near)) = (2.0 * near)/ld - far - near
|
||||
}
|
||||
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
|
||||
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
|
||||
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;
|
||||
}
|
||||
vec4 BilateralUpscale(sampler2D tex, sampler2D depth,vec2 coord,float frDepth){
|
||||
|
||||
|
||||
// #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;
|
||||
ivec2 posD = ivec2(coord/2.0)*2;
|
||||
ivec2 posVl = ivec2(coord/2.0);
|
||||
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;
|
||||
//pos = ivec2(1,-1);
|
||||
|
||||
ivec2 tcDepth = posD + ivec2(-4,-4) + pos*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(-4,0) + pos*2;
|
||||
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*2;
|
||||
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,-4) + pos*2;
|
||||
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;
|
||||
@ -92,7 +132,6 @@ vec3 decode (vec2 encn){
|
||||
n.xy = n.z <= 0.0 ? (1.0 - n.yx) * sign(encn) : encn;
|
||||
return clamp(normalize(n.xyz),-1.0,1.0);
|
||||
}
|
||||
|
||||
vec2 decodeVec2(float a){
|
||||
const vec2 constant1 = 65535. / vec2( 256., 65536.);
|
||||
const float constant2 = 256. / 255.;
|
||||
@ -104,96 +143,166 @@ vec3 worldToView(vec3 worldPos) {
|
||||
pos = gbufferModelView * pos;
|
||||
return pos.xyz;
|
||||
}
|
||||
float luma(vec3 color) {
|
||||
return dot(color,vec3(0.21, 0.72, 0.07));
|
||||
float blueNoise(){
|
||||
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
|
||||
}
|
||||
vec4 blueNoise(vec2 coord){
|
||||
return texelFetch2D(colortex6, ivec2(coord )%512 , 0);
|
||||
}
|
||||
vec3 normVec (vec3 vec){
|
||||
return vec*inversesqrt(dot(vec,vec));
|
||||
}
|
||||
|
||||
float interleaved_gradientNoise(){
|
||||
vec2 coord = gl_FragCoord.xy;
|
||||
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
|
||||
return noise;
|
||||
}
|
||||
vec3 viewToWorld(vec3 viewPosition) {
|
||||
vec4 pos;
|
||||
pos.xyz = viewPosition;
|
||||
pos.w = 0.0;
|
||||
pos = gbufferModelViewInverse * pos;
|
||||
return pos.xyz;
|
||||
}
|
||||
|
||||
/// thanks stackoverflow https://stackoverflow.com/questions/944713/help-with-pixel-shader-effect-for-brightness-and-contrast#3027595
|
||||
void applyContrast(inout vec3 color, float contrast){
|
||||
color = ((color - 0.5) * max(contrast, 0.0)) + 0.5;
|
||||
}
|
||||
void main() {
|
||||
/* DRAWBUFFERS:73 */
|
||||
|
||||
vec2 texcoord = gl_FragCoord.xy*texelSize;
|
||||
|
||||
vec4 trpData = texture2D(colortex7,texcoord);
|
||||
|
||||
bool iswater = trpData.a > 0.99;
|
||||
float translucentAlpha = trpData.a;
|
||||
|
||||
// vec4 speculartex = texture2D(colortex8,texcoord); // translucents
|
||||
// float sunlight = speculartex.b;
|
||||
|
||||
//3x3 bilateral upscale from half resolution
|
||||
float z = texture2D(depthtex0,texcoord).x;
|
||||
float z2 = texture2D(depthtex1,texcoord).x;
|
||||
float frDepth = ld(z);
|
||||
float glassdepth = clamp((ld(z2) - ld(z)) * 0.5,0.0,0.15);
|
||||
float frDepth = ld(z2);
|
||||
|
||||
vec4 vl = BilateralUpscale(colortex0,depthtex0,gl_FragCoord.xy,frDepth);
|
||||
// vec4 vl = texture2D(colortex0,texcoord * 0.5);
|
||||
|
||||
float bloomyfogmult = 1.0;
|
||||
////// --------------- UNPACK OPAQUE GBUFFERS --------------- //////
|
||||
vec4 data_opaque = texture2D(colortex1,texcoord);
|
||||
vec4 dataUnpacked1 = vec4(decodeVec2(data_opaque.z),decodeVec2(data_opaque.w)); // normals, lightmaps
|
||||
// vec4 dataUnpacked2 = vec4(decodeVec2(data.z),decodeVec2(data.w));
|
||||
|
||||
bool hand = abs(dataUnpacked1.w-0.75) < 0.01;
|
||||
vec2 lightmap = dataUnpacked1.yz;
|
||||
|
||||
////// --------------- UNPACK TRANSLUCENT GBUFFERS --------------- //////
|
||||
|
||||
vec3 data = texture2D(colortex11,texcoord).rgb;
|
||||
|
||||
vec4 unpack0 = vec4(decodeVec2(data.r),decodeVec2(data.g)) ;
|
||||
vec4 unpack1 = vec4(decodeVec2(data.b),0,0) ;
|
||||
|
||||
|
||||
|
||||
vec4 albedo = vec4(unpack0.ba,unpack1.rg);
|
||||
|
||||
vec2 tangentNormals = unpack0.xy*2.0-1.0;
|
||||
|
||||
if(albedo.a <= 0.0) tangentNormals = vec2(0.0);
|
||||
|
||||
vec4 TranslucentShader = texture2D(colortex2,texcoord);
|
||||
|
||||
float lightleakfix = clamp(pow(eyeBrightnessSmooth.y/240.,2) ,0.0,1.0);
|
||||
|
||||
|
||||
vec2 tempOffset = TAA_Offset;
|
||||
vec3 fragpos = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z));
|
||||
vec3 fragpos2 = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z2));
|
||||
|
||||
|
||||
vec3 p3 = mat3(gbufferModelViewInverse) * fragpos;
|
||||
vec3 np3 = normVec(p3);
|
||||
|
||||
vec4 Translucent_Programs = texture2D(colortex2,texcoord); // the shader for all translucent progams.
|
||||
|
||||
vec4 trpData = texture2D(colortex7,texcoord);
|
||||
bool iswater = trpData.a > 0.99;
|
||||
vec2 refractedCoord = texcoord;
|
||||
|
||||
|
||||
|
||||
vec2 data = texture2D(colortex11,texcoord).xy; // translucents
|
||||
vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y));
|
||||
|
||||
vec3 normals = mat3(gbufferModelViewInverse) * worldToView(decode(dataUnpacked0.yw) );
|
||||
|
||||
|
||||
/// --- REFRACTION --- ///
|
||||
#ifdef Refraction
|
||||
refractedCoord += normals.xy * glassdepth;
|
||||
refractedCoord += (tangentNormals * clamp((ld(z2) - ld(z)) * 0.5,0.0,0.15)) * RENDER_SCALE;
|
||||
// refractedCoord += tangentNormals * 0.1 * RENDER_SCALE;
|
||||
|
||||
float refractedalpha = texture2D(colortex13,refractedCoord).a;
|
||||
if(refractedalpha <= 0.0) refractedCoord = texcoord; // remove refracted coords on solids
|
||||
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;
|
||||
|
||||
if (Translucent_Programs.a > 0.0){
|
||||
vec4 vl = BilateralUpscale(colortex0, depthtex1, gl_FragCoord.xy, frDepth, vec2(0.0));
|
||||
float bloomyFogMult = 1.0;
|
||||
|
||||
if (TranslucentShader.a > 0.0){
|
||||
#ifdef Glass_Tint
|
||||
vec3 GlassAlbedo = texture2D(colortex13,texcoord).rgb * 5.0;
|
||||
color = color*GlassAlbedo.rgb + color * clamp(pow(1.0-luma(GlassAlbedo.rgb),10.),0.0,1.0);
|
||||
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-Translucent_Programs.a) + Translucent_Programs.rgb;
|
||||
color = color*(1.0-TranslucentShader.a) + TranslucentShader.rgb;
|
||||
}
|
||||
|
||||
color *= vl.a;
|
||||
color += vl.rgb;
|
||||
|
||||
bloomyfogmult *= vl.a*0.8+0.2;
|
||||
|
||||
// underwater fog
|
||||
if (isEyeInWater == 1){
|
||||
vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z));
|
||||
float fogfade = clamp(exp(-length(fragpos) /5. ) ,0.0,1.0);
|
||||
bloomyfogmult *= fogfade*0.70+0.3 ;
|
||||
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){
|
||||
vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z));
|
||||
color.rgb = mix(color.rgb,vec3(10,15,20),clamp(length(fragpos)*0.5,0.,1.));
|
||||
bloomyfogmult = 0.0;
|
||||
bloomyFogMult = 0.0;
|
||||
}
|
||||
|
||||
// blidnesss
|
||||
if (blindness > 0.0){
|
||||
vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z));
|
||||
color.rgb *= mix(1.0,clamp( exp(pow(length(fragpos)*(blindness*0.2),2) * -5),0.,1.) , blindness);
|
||||
}
|
||||
color.rgb *= mix(1.0,clamp( exp(pow(length(fragpos)*(blindness*0.2),2) * -1),0.,1.) , blindness);
|
||||
|
||||
// darkness effect
|
||||
if(darknessFactor > 0.0){
|
||||
vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z2));
|
||||
color.rgb *= mix(1.0, (1.0-darknessLightFactor*2.0) * clamp(1.0-pow(length(fragpos)*(darknessFactor*0.07),2.0),0.0,1.0), darknessFactor);
|
||||
}
|
||||
|
||||
gl_FragData[0].r = bloomyfogmult;
|
||||
|
||||
|
||||
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.0;
|
||||
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);
|
||||
|
||||
gl_FragData[1].rgb = clamp(color,6.11*1e-5,65000.0);
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
#version 120
|
||||
|
||||
#define END
|
||||
#include "/programs/all_translucent.fsh"
|
Loading…
Reference in New Issue
Block a user