mirror of
https://github.com/X0nk/Bliss-Shader.git
synced 2025-06-22 00:37:35 +08:00
surprise commit
new stuff reworked clouds, general lighting, end and nether shaders still WIP lighting is more balanced in general.
This commit is contained in:
@ -9,7 +9,6 @@ uniform sampler2D normals;
|
||||
varying vec3 tangent;
|
||||
varying vec4 tangent_other;
|
||||
varying vec3 viewVector;
|
||||
varying float dist;
|
||||
|
||||
#include "lib/settings.glsl"
|
||||
#include "/lib/res_params.glsl"
|
||||
@ -18,11 +17,13 @@ varying float dist;
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D noisetex;
|
||||
uniform sampler2DShadow shadow;
|
||||
uniform sampler2D gaux2;
|
||||
uniform sampler2D gaux1;
|
||||
// uniform sampler2D gaux2;
|
||||
// uniform sampler2D gaux1;
|
||||
|
||||
// uniform sampler2D colortex4;
|
||||
uniform sampler2D colortex5;
|
||||
uniform sampler2D depthtex1;
|
||||
|
||||
uniform vec4 lightCol;
|
||||
uniform float nightVision;
|
||||
|
||||
uniform vec3 sunVec;
|
||||
@ -50,6 +51,8 @@ uniform int frameCounter;
|
||||
uniform int isEyeInWater;
|
||||
|
||||
|
||||
flat varying vec4 lightCol; //main light source color (rgb),used light source(1=sun,-1=moon)
|
||||
flat varying vec3 avgAmbient;
|
||||
|
||||
|
||||
|
||||
@ -62,6 +65,9 @@ uniform int isEyeInWater;
|
||||
#include "lib/stars.glsl"
|
||||
#include "lib/volumetricClouds.glsl"
|
||||
|
||||
#include "lib/diffuse_lighting.glsl"
|
||||
|
||||
|
||||
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
|
||||
vec2(-1.,3.)/8.,
|
||||
vec2(5.0,1.)/8.,
|
||||
@ -141,7 +147,7 @@ vec3 rayTrace(vec3 dir,vec3 position,float dither, float fresnel, bool inwater){
|
||||
for (int i = 0; i <= int(quality); i++) {
|
||||
#ifdef USE_QUARTER_RES_DEPTH
|
||||
// decode depth buffer
|
||||
float sp = sqrt(texelFetch2D(gaux1,ivec2(spos.xy/texelSize/4),0).w/65000.0);
|
||||
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);
|
||||
@ -181,14 +187,15 @@ float cdist(vec2 coord) {
|
||||
return max(abs(coord.s-0.5),abs(coord.t-0.5))*2.0;
|
||||
}
|
||||
|
||||
#define PW_DEPTH 0.0 //[0.5 1.0 1.5 2.0 2.5 3.0]
|
||||
#define PW_POINTS 1 //[2 4 6 8 16 32]
|
||||
#define PW_DEPTH 1.0 //[0.5 1.0 1.5 2.0 2.5 3.0]
|
||||
#define PW_POINTS 2 //[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);
|
||||
@ -316,19 +323,45 @@ vec4 encode (vec3 n, vec2 lightmaps){
|
||||
float square(float x){
|
||||
return x*x;
|
||||
}
|
||||
float g(float NdotL, float roughness){
|
||||
float alpha = square(max(roughness, 0.02));
|
||||
return 2.0 * NdotL / (NdotL + sqrt(square(alpha) + (1.0 - square(alpha)) * square(NdotL)));
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
vec3 GGX2(vec3 n, vec3 v, vec3 l, float r, vec3 F0,float fresnel) {
|
||||
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 roughness = r;
|
||||
|
||||
float alpha = square(roughness) + 1e-4; // when roughness is zero it fucks up
|
||||
|
||||
@ -343,11 +376,39 @@ vec3 GGX2(vec3 n, vec3 v, vec3 l, float r, vec3 F0,float fresnel) {
|
||||
|
||||
float D = alpha / (0.0541592653589793*square(square(dotNH) * (alpha - 1.0) + 1.0));
|
||||
float G = gSimple(dotNV, roughness) * gSimple(dotNL, roughness);
|
||||
vec3 F = F0 + (1. - F0) * exp2((-5.55473*dotVH-6.98316)*dotVH);
|
||||
float F = F0 + (1. - F0) * exp2((-5.55473*dotVH-6.98316)*dotVH);
|
||||
|
||||
return dotNL * F * (G * D / (4 * dotNV * dotNL + 1e-7));
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
float dotLH = clamp(dot(h,l)*hn,0.,1.);
|
||||
float dotNH = clamp(dot(h,n)*hn,0.,1.) ;
|
||||
float dotNL = clamp(dot(n,l),0.,1.);
|
||||
float dotNHsq = dotNH*dotNH;
|
||||
|
||||
float denom = dotNHsq * r - dotNHsq + 1.;
|
||||
float D = r / (3.141592653589793 * denom * denom);
|
||||
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 pixelCoord (vec3 Coordinates, int Resolution){
|
||||
return floor(Coordinates / Resolution) * Resolution;
|
||||
}
|
||||
#define PHYSICSMOD_FRAGMENT
|
||||
#include "/lib/oceans.glsl"
|
||||
|
||||
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
@ -360,32 +421,30 @@ void main() {
|
||||
float iswater = normalMat.w;
|
||||
vec3 fragC = gl_FragCoord.xyz*vec3(texelSize,1.0);
|
||||
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,-5)*color;
|
||||
// float avgBlockLum = luma(texture2DLod(texture, lmtexcoord.xy,128).rgb*color.rgb);
|
||||
// gl_FragData[0].rgb = clamp((gl_FragData[0].rgb)*pow(avgBlockLum,-0.33)*0.85,0.0,1.0);
|
||||
|
||||
vec3 albedo = toLinear(gl_FragData[0].rgb);
|
||||
gl_FragData[0] = texture2D(texture, lmtexcoord.xy,Texture_MipMap_Bias)*color;
|
||||
float alphalabede = gl_FragData[0].a;
|
||||
vec3 Albedo = toLinear(gl_FragData[0].rgb);
|
||||
//pain
|
||||
|
||||
#ifdef HAND
|
||||
iswater = 0.1;
|
||||
#endif
|
||||
|
||||
#ifndef Vanilla_like_water
|
||||
if (iswater > 0.4) {
|
||||
albedo = vec3(1.0);
|
||||
gl_FragData[0] = vec4(0.42,0.6,0.7,0.7);
|
||||
}
|
||||
if (iswater > 0.9) {
|
||||
gl_FragData[0] = vec4(vec3(0.0),1./255.);
|
||||
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;
|
||||
gl_FragData[0].a = luma(Albedo.rgb);
|
||||
Albedo = color.rgb;
|
||||
}
|
||||
#endif
|
||||
|
||||
gl_FragData[4] = vec4(albedo, gl_FragData[0].a);
|
||||
|
||||
gl_FragData[4] = vec4(Albedo, gl_FragData[0].a);
|
||||
|
||||
vec3 normal = normalMat.xyz;
|
||||
|
||||
@ -393,47 +452,73 @@ void main() {
|
||||
mat3 tbnMatrix = mat3(tangent.x, binormal.x, normal.x,
|
||||
tangent.y, binormal.y, normal.y,
|
||||
tangent.z, binormal.z, normal.z);
|
||||
|
||||
vec3 WaterNormals;
|
||||
vec3 TranslucentNormals;
|
||||
|
||||
if (iswater > 0.4){
|
||||
float bumpmult = 1.;
|
||||
vec3 posxz = p3+cameraPosition;
|
||||
posxz.xz-=posxz.y;
|
||||
vec3 bump;
|
||||
|
||||
if(physics_iterationsNormal < 1.0){
|
||||
float bumpmult = 1.;
|
||||
|
||||
vec3 bump;
|
||||
|
||||
vec3 posxz = p3+cameraPosition;
|
||||
|
||||
posxz.xz -= posxz.y;
|
||||
|
||||
|
||||
posxz.xyz = getParallaxDisplacement(posxz,iswater,bumpmult,normalize(tbnMatrix*fragpos));
|
||||
posxz.xyz = getParallaxDisplacement(posxz,iswater,bumpmult,normalize(tbnMatrix*fragpos)) ;
|
||||
|
||||
bump = normalize(getWaveHeight(posxz.xz,iswater));
|
||||
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
|
||||
normal = normalize(bump * tbnMatrix);
|
||||
}else {
|
||||
|
||||
bump = normalize(getWaveHeight(posxz.xz,iswater));
|
||||
WaterNormals = bump; // 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 PhysicsMod_normal = physics_waveNormal(physics_localPosition.xz, physics_localWaviness, physics_gameTime);
|
||||
|
||||
normal = normalize(worldToView(PhysicsMod_normal) + mix(normal, vec3(0.0), clamp(physics_localWaviness,0.0,1.0)));
|
||||
|
||||
vec3 worldSpaceNormal = normal;
|
||||
|
||||
vec3 bitangent = normalize(cross(tangent, worldSpaceNormal));
|
||||
mat3 tbn_new = mat3(tangent, binormal, worldSpaceNormal);
|
||||
vec3 tangentSpaceNormal = (worldSpaceNormal * tbn_new);
|
||||
|
||||
WaterNormals = tangentSpaceNormal ;
|
||||
}
|
||||
|
||||
}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);
|
||||
normal = applyBump(tbnMatrix,normalTex);
|
||||
}
|
||||
|
||||
TranslucentNormals = normalTex;
|
||||
|
||||
normal = applyBump(tbnMatrix,normalTex);
|
||||
|
||||
}
|
||||
|
||||
TranslucentNormals += WaterNormals;
|
||||
vec4 data0 = vec4(1);
|
||||
vec4 data1 = clamp( encode(viewToWorld(normal), lmtexcoord.zw),0.0,1.0);
|
||||
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));
|
||||
|
||||
float NdotL = lightSign*dot(normal,sunVec);
|
||||
float NdotU = dot(upVec,normal);
|
||||
float diffuseSun = clamp(NdotL,0.0f,1.0f);
|
||||
diffuseSun = clamp((-15 + diffuseSun*255.0) / 240.0 ,0.0,1.0);
|
||||
|
||||
vec3 direct = texelFetch2D(gaux1,ivec2(6,37),0).rgb/127.0;
|
||||
|
||||
#ifdef ambientLight_only
|
||||
direct = vec3(0);
|
||||
#endif
|
||||
float NdotL = clamp(lightSign*dot(normal,sunVec) ,0.0,1.0);
|
||||
NdotL = clamp((-15 + NdotL*255.0) / 240.0 ,0.0,1.0);
|
||||
|
||||
|
||||
float shading = 1.0;
|
||||
|
||||
float Shadows = 1.0;
|
||||
float cloudShadow = 1.0;
|
||||
//compute shadows only if not backface
|
||||
if (diffuseSun > 0.001) {
|
||||
if (NdotL > 0.001) {
|
||||
vec3 p3 = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz;
|
||||
vec3 projectedShadowPosition = mat3(shadowModelView) * p3 + shadowModelView[3].xyz;
|
||||
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
|
||||
@ -444,134 +529,127 @@ void main() {
|
||||
//do shadows only if on shadow map
|
||||
if (abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution){
|
||||
const float threshMul = max(2048.0/shadowMapResolution*shadowDistance/128.0,0.95);
|
||||
float distortThresh = (sqrt(1.0-diffuseSun*diffuseSun)/diffuseSun+0.7)/distortFactor;
|
||||
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);
|
||||
|
||||
shading = 0.0;
|
||||
Shadows = 0.0;
|
||||
float noise = blueNoise();
|
||||
float rdMul = 4.0/shadowMapResolution;
|
||||
|
||||
for(int i = 0; i < 9; i++){
|
||||
vec2 offsetS = tapLocation(i,9, 1.618,noise,0.0);
|
||||
|
||||
float weight = 1.0+(i+noise)*rdMul/9.0*shadowMapResolution;
|
||||
shading += shadow2D(shadow,vec3(projectedShadowPosition + vec3(rdMul*offsetS,-diffthresh*weight))).x/9.0;
|
||||
}
|
||||
direct *= shading;
|
||||
Shadows += shadow2D(shadow,vec3(projectedShadowPosition + vec3(rdMul*offsetS,-diffthresh*weight))).x/9.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef VOLUMETRIC_CLOUDS
|
||||
#ifdef CLOUDS_SHADOWS
|
||||
vec3 campos = (p3 + cameraPosition)-319 ;
|
||||
// get cloud position
|
||||
vec3 cloudPos = campos*Cloud_Size + WsunVec/abs(WsunVec.y) * (2250 - campos.y*Cloud_Size);
|
||||
// get the cloud density and apply it
|
||||
cloudShadow = getCloudDensity(cloudPos, 1);
|
||||
// cloudShadow = exp(-cloudShadow*sqrt(cloudDensity)*25);
|
||||
|
||||
cloudShadow = clamp(exp(-cloudShadow*10),0,1);
|
||||
|
||||
// make these turn to zero when occluded by the cloud shadow
|
||||
direct *= cloudShadow;
|
||||
#endif
|
||||
Shadows *= GetCloudShadow(p3);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
vec3 ambientLight = (texture2D(gaux1,(lmtexcoord.zw*15.+0.5)*texelSize).rgb * 2.0) * 8./150./3.;
|
||||
// vec3 ambientLight = (texture2D(gaux1,(lmtexcoord.zw*15.+0.5)*texelSize).rgb * 2.0) * 8./150./3.;
|
||||
|
||||
direct *= (iswater > 0.9 ? 0.2: 1.0)*diffuseSun*lmtexcoord.w;
|
||||
// direct *= (iswater > 0.9 ? 0.2: 1.0)*NdotL*lmtexcoord.w;
|
||||
|
||||
vec3 directLight = direct;
|
||||
// vec3 directLight = direct;
|
||||
vec3 WS_normal = viewToWorld(normal);
|
||||
vec3 ambientCoefs = WS_normal/dot(abs(WS_normal),vec3(1.));
|
||||
float skylight = clamp(abs(ambientCoefs.y+1),0.35,2.0) ;
|
||||
|
||||
vec3 color = vec3(0);
|
||||
vec3 Indirect_lighting = DoAmbientLighting(avgAmbient, vec3(TORCH_R,TORCH_G,TORCH_B), lmtexcoord.zw, skylight);
|
||||
vec3 Direct_lighting = DoDirectLighting(lightCol.rgb/80.0, Shadows, NdotL, 0.0);
|
||||
|
||||
|
||||
color += ambientLight ;
|
||||
color += directLight;
|
||||
vec3 FinalColor = (Direct_lighting + Indirect_lighting) * Albedo;
|
||||
|
||||
// if (iswater > 0.9) FinalColor = Albedo;
|
||||
|
||||
#ifdef Glass_Tint
|
||||
float alphashit = min(pow(gl_FragData[0].a,2.0),1.0);
|
||||
color *= alphashit;
|
||||
FinalColor *= alphashit;
|
||||
#endif
|
||||
|
||||
color *= albedo;
|
||||
|
||||
vec2 specularstuff = texture2D(specular, lmtexcoord.xy, Texture_MipMap_Bias).rg;
|
||||
specularstuff = iswater > 0.0 && specularstuff.r > 0.0 && specularstuff.g < 0.9 ? specularstuff : vec2(1.0,0.02);
|
||||
|
||||
if (iswater > 0.0){
|
||||
|
||||
float roughness = pow(1.0-specularstuff.r,2.0);
|
||||
float f0 = 0;
|
||||
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 = max(pow(1.0-SpecularTex.r,2.0),0.1);
|
||||
float f0 = SpecularTex.g;
|
||||
|
||||
float F0 = f0;
|
||||
|
||||
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);
|
||||
// float unchangedfresnel = fresnel;
|
||||
|
||||
// snells window looking thing
|
||||
if(isEyeInWater == 1 && iswater > 0.99) fresnel = clamp(pow(1.66 + normalDotEye,25),0.02,1.0);
|
||||
|
||||
fresnel = mix(F0, 1.0, fresnel);
|
||||
if(isEyeInWater == 1 && physics_iterationsNormal > 0.0) fresnel = clamp( 1.0 - (pow( normalDotEye * 1.66 ,25)),0.02,1.0);
|
||||
|
||||
// fresnel = mix(F0, 1.0, fresnel);
|
||||
fresnel = F0 + (1.0 - F0) * fresnel;
|
||||
float indoors = clamp((lmtexcoord.w-0.6)*5.0, 0.0,1.0);
|
||||
vec3 wrefl = mat3(gbufferModelViewInverse)*reflectedVector;
|
||||
|
||||
vec3 sky_c = skyCloudsFromTex(wrefl,gaux1).rgb / 150. * 5. ;
|
||||
sky_c.rgb *= indoors;
|
||||
// SSR, Sky, and Sun reflections
|
||||
vec4 Reflections = vec4(0.0);
|
||||
vec3 SkyReflection = skyCloudsFromTex(wrefl,colortex4).rgb / 150. * 5.;
|
||||
vec3 SunReflection = Direct_lighting * GGX(normal, -normalize(fragpos), lightSign*sunVec, roughness, f0);
|
||||
// vec3 SunReflection = Direct_lighting * SunGGX(normal, -normalize(fragpos), lightSign*sunVec, roughness, f0, fresnel);
|
||||
|
||||
float visibilityFactor = clamp(exp2((pow(roughness,3.0) / F0) * -4),0,1);
|
||||
|
||||
sky_c = mix(sky_c,color,(1.0-indoors)) ;
|
||||
|
||||
vec4 reflection = vec4(0.);
|
||||
#ifdef SCREENSPACE_REFLECTIONS
|
||||
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;
|
||||
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) {
|
||||
reflection.a = 1.0;
|
||||
reflection.rgb = texture2D(gaux2,previousPosition.xy).rgb;
|
||||
if(iswater > 0.0){
|
||||
#ifdef SCREENSPACE_REFLECTIONS
|
||||
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;
|
||||
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) {
|
||||
|
||||
Reflections.a = 1.0;
|
||||
Reflections.rgb = texture2D(colortex5,previousPosition.xy).rgb;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
float visibilityFactor = clamp(exp2((pow(roughness,3.0) / f0) * -4),0,1);
|
||||
|
||||
if(isEyeInWater == 1 ) sky_c.rgb = color.rgb*lmtexcoord.w;
|
||||
Reflections_Final = mix(SkyReflection*indoors, Reflections.rgb, Reflections.a);
|
||||
Reflections_Final = mix(FinalColor, Reflections_Final, fresnel * visibilityFactor);
|
||||
Reflections_Final += SunReflection;
|
||||
|
||||
reflection.rgb = mix(sky_c.rgb, reflection.rgb, reflection.a);
|
||||
|
||||
vec3 sunSpec = shading*directLight * GGX2(normal, -normalize(fragpos), lightSign*sunVec, roughness, vec3(f0), fresnel) ;
|
||||
|
||||
sunSpec *= max(cloudShadow-0.5,0.0);
|
||||
|
||||
vec3 reflected = reflection.rgb*fresnel + sunSpec ;
|
||||
|
||||
// reflected = vec3(0);
|
||||
gl_FragData[0].rgb = Reflections_Final;
|
||||
|
||||
//correct alpha channel with fresnel
|
||||
float alpha0 = gl_FragData[0].a;
|
||||
// //correct alpha channel with fresnel
|
||||
gl_FragData[0].a = -gl_FragData[0].a*fresnel+gl_FragData[0].a+fresnel;
|
||||
gl_FragData[0].rgb = clamp(color/gl_FragData[0].a*alpha0*(1.0-fresnel)*0.1+reflected/gl_FragData[0].a*0.1,0.0,65100.0);
|
||||
|
||||
|
||||
|
||||
if (gl_FragData[0].r > 65000.) gl_FragData[0].rgba = vec4(0.);
|
||||
|
||||
#ifdef BorderFog
|
||||
float fog = 1.0 - clamp( exp2(-pow(length(fragpos / far),10.)*3.0) ,0.0,1.0);
|
||||
gl_FragData[0].a = mix(gl_FragData[0].a, 0.0, fog);
|
||||
#endif
|
||||
// //suffering
|
||||
// #ifdef SPIDEREYES
|
||||
// gl_FragData[0].rgb = Albedo.rgb * 10;
|
||||
// #endif
|
||||
|
||||
}
|
||||
else
|
||||
gl_FragData[0].rgb = color*.1;
|
||||
} else {
|
||||
gl_FragData[0].rgb = FinalColor;
|
||||
}
|
||||
|
||||
#ifndef HAND
|
||||
gl_FragData[1] = vec4(Albedo,iswater);
|
||||
#endif
|
||||
// #endif
|
||||
|
||||
gl_FragData[1] = vec4(albedo,iswater);
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user