Untitled diff

Created Diff never expires
16 removals
493 lines
10 additions
487 lines
#version 120
#version 120
/*
/*
_____ _____ ___________
_____ _____ ___________
/ ___|_ _| _ | ___ \
/ ___|_ _| _ | ___ \
\ `--. | | | | | | |_/ /
\ `--. | | | | | | |_/ /
`--. \ | | | | | | __/
`--. \ | | | | | | __/
/\__/ / | | \ \_/ / |
/\__/ / | | \ \_/ / |
\____/ \_/ \___/\_|
\____/ \_/ \___/\_|
Before editing anything here make sure you've
Before editing anything here make sure you've
read The agreement, which you accepted by downloading
read The agreement, which you accepted by downloading
my shaderpack. The agreement can be found here:
my shaderpack. The agreement can be found here:
http://www.minecraftforum.net/topic/1953873-164-172-sildurs-shaders-pcmacintel/
http://www.minecraftforum.net/topic/1953873-164-172-sildurs-shaders-pcmacintel/
Sildur's shaders, derived from Chocapic's shaders */
Sildur's shaders, derived from Chocapic's shaders */
/*--------------------
/*--------------------
//ADJUSTABLE VARIABLES//
//ADJUSTABLE VARIABLES//
---------------------*/
---------------------*/
//SHADOWS//
//SHADOWS//
const int shadowMapResolution = 1572;
const int shadowMapResolution = 1572;
const float shadowDistance = 128.0f;
const float shadowDistance = 128.0f;
//END OF SHADOWS//
//END OF SHADOWS//
//LIGHTING//
//LIGHTING//
#define SUNLIGHTAMOUNT 1.7
#define SUNLIGHTAMOUNT 1.7
//#define NightIsTooDarkForMe //Enable to make the night bright!
//#define NightIsTooDarkForMe //Enable to make the night bright!
//END OF LIGHTING//
//END OF LIGHTING//
//VISUAL//
//VISUAL//
#define GODRAYS
#define GODRAYS
#ifdef GODRAYS
#ifdef GODRAYS
const float density = 0.7;
const float density = 0.7;
const int NUM_SAMPLES = 5;
const int NUM_SAMPLES = 5;
const float grnoise = 0.012;
const float grnoise = 0.012;
#endif
#endif
#define SSAO //Works, but eats a bunch frames
#define SSAO //Works, but eats a bunch frames
#ifdef SSAO
#ifdef SSAO
const int nbdir = 5;
const int nbdir = 5;
const float sampledir = 5;
const float sampledir = 5;
const float ssaorad = 1.0;
const float ssaorad = 1.0;
#endif
#endif
//#define CELSHADING
//#define CELSHADING
#define BORDER 1.0
#define BORDER 1.0
//END OF VISUAL//
//END OF VISUAL//
/*---------------------------
/*---------------------------
//END OF ADJUSTABLE VARIABLES//
//END OF ADJUSTABLE VARIABLES//
----------------------------*/
----------------------------*/
const int R8 = 0;
const int R8 = 0;
const int gdepthFormat = R8;
const int gdepthFormat = R8;
const bool generateShadowMipmap = false;
const bool generateShadowMipmap = false;
const float shadowIntervalSize = 4.0f;
const float shadowIntervalSize = 4.0f;
const float wetnessHalflife = 70.0f;
const float wetnessHalflife = 70.0f;
const float drynessHalflife = 70.0f;
const float drynessHalflife = 70.0f;
const float sunPathRotation = -40.0f; //determines sun/moon inclination /-35.0 is default - 0.0 is normal rotation
const float sunPathRotation = -40.0f; //determines sun/moon inclination /-35.0 is default - 0.0 is normal rotation
const float ambientOcclusionLevel = 1.0f; //level of Minecraft smooth lighting, 1.0f is default
const float ambientOcclusionLevel = 1.0f; //level of Minecraft smooth lighting, 1.0f is default
varying vec4 texcoord;
varying vec4 texcoord;
varying vec3 lightVector;
varying vec3 lightVector;
varying vec3 sunlight_color;
varying vec3 sunlight_color;
varying vec3 ambient_color;
varying vec3 ambient_color;
varying float handItemLight;
varying float handItemLight;
uniform sampler2D gcolor;
uniform sampler2D gcolor;
uniform sampler2D depthtex0;
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
uniform sampler2D depthtex1;
uniform sampler2D gnormal;
uniform sampler2D gnormal;
uniform sampler2D shadow;
uniform sampler2D shadow;
uniform sampler2D gaux1;
uniform sampler2D gaux1;
uniform sampler2D gaux3;
uniform sampler2D gaux3;
uniform mat4 gbufferProjection;
uniform mat4 gbufferProjection;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferModelViewInverse;
uniform mat4 shadowProjection;
uniform mat4 shadowProjection;
uniform mat4 shadowModelView;
uniform mat4 shadowModelView;
uniform vec3 sunPosition;
uniform vec3 sunPosition;
uniform vec3 upPosition;
uniform vec3 upPosition;
uniform vec3 cameraPosition;
uniform vec3 cameraPosition;
uniform float near;
uniform float near;
uniform float far;
uniform float far;
uniform float viewWidth;
uniform float viewWidth;
uniform float viewHeight;
uniform float viewHeight;
uniform float rainStrength;
uniform float rainStrength;
uniform float wetness;
uniform float wetness;
uniform float aspectRatio;
uniform float aspectRatio;
uniform float frameTimeCounter;
uniform float frameTimeCounter;
uniform ivec2 eyeBrightnessSmooth;
uniform ivec2 eyeBrightnessSmooth;
uniform int isEyeInWater;
uniform int isEyeInWater;
uniform int worldTime;
uniform int worldTime;
float timefract = worldTime;
float timefract = worldTime;
float TimeRealNightMorning = ((clamp(timefract, 12000.0, 12750.0) - 12000.0) / 750.0) - ((clamp(timefract, 23000.0, 23200.0) - 23000.0) / 200.0);
float TimeRealNightMorning = ((clamp(timefract, 12000.0, 12750.0) - 12000.0) / 750.0) - ((clamp(timefract, 23000.0, 23200.0) - 23000.0) / 200.0);
uniform int fogMode;
uniform int fogMode;
#ifdef SSAO
#ifdef SSAO
float cdist(vec2 coord){
float cdist(vec2 coord){
return distance(coord,vec2(0.5))*2.0;
return distance(coord,vec2(0.5))*2.0;
}
}
vec3 convertScreenSpaceToWorldSpace(vec2 co, float depth) {
vec3 convertScreenSpaceToWorldSpace(vec2 co, float depth) {
vec4 fragposition = gbufferProjectionInverse * vec4(vec3(co, depth) * 2.0 - 1.0, 1.0);
vec4 fragposition = gbufferProjectionInverse * vec4(vec3(co, depth) * 2.0 - 1.0, 1.0);
fragposition /= fragposition.w;
fragposition /= fragposition.w;
return fragposition.xyz;
return fragposition.xyz;
}
}
vec3 convertCameraSpaceToScreenSpace(vec3 cameraSpace) {
vec3 convertCameraSpaceToScreenSpace(vec3 cameraSpace) {
vec4 clipSpace = gbufferProjection * vec4(cameraSpace, 1.0);
vec4 clipSpace = gbufferProjection * vec4(cameraSpace, 1.0);
vec3 NDCSpace = clipSpace.xyz / clipSpace.w;
vec3 NDCSpace = clipSpace.xyz / clipSpace.w;
vec3 screenSpace = 0.5 * NDCSpace + 0.5;
vec3 screenSpace = 0.5 * NDCSpace + 0.5;
return screenSpace;
return screenSpace;
}
}
float luma(vec3 color) {
float luma(vec3 color) {
return dot(color,vec3(0.299, 0.587, 0.114));
return dot(color,vec3(0.299, 0.587, 0.114));
}
}
#endif
#endif
float edepth(vec2 coord) {
float edepth(vec2 coord) {
return texture2D(depthtex0,coord).z;
return texture2D(depthtex0,coord).z;
}
}
float ld(float depth) {
float ld(float depth) {
return (2.0 * near) / (far + near - depth * (far - near));
return (2.0 * near) / (far + near - depth * (far - near));
}
}
vec3 nvec3(vec4 pos) {
vec3 nvec3(vec4 pos) {
return pos.xyz/pos.w;
return pos.xyz/pos.w;
}
}
vec4 nvec4(vec3 pos) {
vec4 nvec4(vec3 pos) {
return vec4(pos.xyz, 1.0);
return vec4(pos.xyz, 1.0);
}
}
vec2 texel = vec2(1.0/viewWidth,1.0/viewHeight);
vec2 texel = vec2(1.0/viewWidth,1.0/viewHeight);
vec3 aux = texture2D(gaux1, texcoord.st).rgb;
vec3 aux = texture2D(gaux1, texcoord.st).rgb;
vec3 sunPos = sunPosition;
vec3 sunPos = sunPosition;
vec3 normal = texture2D(gnormal, texcoord.st).rgb * 2.0f - 1.0f;
vec3 normal = texture2D(gnormal, texcoord.st).rgb * 2.0f - 1.0f;
float pixeldepth = texture2D(depthtex0,texcoord.xy).x;
float pixeldepth = texture2D(depthtex0,texcoord.xy).x;
float pw = 1.0/ viewWidth;
float pw = 1.0/ viewWidth;
float ph = 1.0/ viewHeight;
float ph = 1.0/ viewHeight;
float shadowexit = 0.0;
float shadowexit = 0.0;
float handlight = handItemLight;
float handlight = handItemLight;
const float speed = 1.5;
const float speed = 1.5;
float light_jitter = 1.0-sin(frameTimeCounter*1.4*speed+cos(frameTimeCounter*1.9*speed))*0.025; //little light variations
float light_jitter = 1.0-sin(frameTimeCounter*1.4*speed+cos(frameTimeCounter*1.9*speed))*0.025; //little light variations
float torch_lightmap = pow(aux.b*light_jitter,2.0)*1.5;
float torch_lightmap = pow(aux.b*light_jitter,2.0)*1.5;
float sky_lightmap = pow(aux.r,3.0);
float sky_lightmap = pow(aux.r,3.0);
float iswet = wetness*pow(sky_lightmap,5.0)*sqrt(0.5+max(dot(normal,normalize(upPosition)),0.0));
float iswet = wetness*pow(sky_lightmap,5.0)*sqrt(0.5+max(dot(normal,normalize(upPosition)),0.0));
vec3 specular = texture2D(gaux3,texcoord.xy).rgb;
vec3 specular = texture2D(gaux3,texcoord.xy).rgb;
float specmap = specular.r*(1.0-specular.b)+specular.g*iswet+specular.b*0.85;
float specmap = specular.r*(1.0-specular.b)+specular.g*iswet+specular.b*0.85;
//poisson distribution for shadow sampling
//poisson distribution for shadow sampling
const vec2 circle_offsets[25] = vec2[25](vec2(-0.4894566f,-0.3586783f),
const vec2 circle_offsets[25] = vec2[25](vec2(-0.4894566f,-0.3586783f),
vec2(-0.1717194f,0.6272162f),
vec2(-0.1717194f,0.6272162f),
vec2(-0.4709477f,-0.01774091f),
vec2(-0.4709477f,-0.01774091f),
vec2(-0.9910634f,0.03831699f),
vec2(-0.9910634f,0.03831699f),
vec2(-0.2101292f,0.2034733f),
vec2(-0.2101292f,0.2034733f),
vec2(-0.7889516f,-0.5671548f),
vec2(-0.7889516f,-0.5671548f),
vec2(-0.1037751f,-0.1583221f),
vec2(-0.1037751f,-0.1583221f),
vec2(-0.5728408f,0.3416965f),
vec2(-0.5728408f,0.3416965f),
vec2(-0.1863332f,0.5697952f),
vec2(-0.1863332f,0.5697952f),
vec2(0.3561834f,0.007138769f),
vec2(0.3561834f,0.007138769f),
vec2(0.2868255f,-0.5463203f),
vec2(0.2868255f,-0.5463203f),
vec2(-0.4640967f,-0.8804076f),
vec2(-0.4640967f,-0.8804076f),
vec2(0.1969438f,0.6236954f),
vec2(0.1969438f,0.6236954f),
vec2(0.6999109f,0.6357007f),
vec2(0.6999109f,0.6357007f),
vec2(-0.3462536f,0.8966291f),
vec2(-0.3462536f,0.8966291f),
vec2(0.172607f,0.2832828f),
vec2(0.172607f,0.2832828f),
vec2(0.4149241f,0.8816f),
vec2(0.4149241f,0.8816f),
vec2(0.136898f,-0.9716249f),
vec2(0.136898f,-0.9716249f),
vec2(-0.6272043f,0.6721309f),
vec2(-0.6272043f,0.6721309f),
vec2(-0.8974028f,0.4271871f),
vec2(-0.8974028f,0.4271871f),
vec2(0.5551881f,0.324069f),
vec2(0.5551881f,0.324069f),
vec2(0.9487136f,0.2605085f),
vec2(0.9487136f,0.2605085f),
vec2(0.7140148f,-0.312601f),
vec2(0.7140148f,-0.312601f),
vec2(0.0440252f,0.9363738f),
vec2(0.0440252f,0.9363738f),
vec2(0.620311f,-0.6673451f)
vec2(0.620311f,-0.6673451f)
);
);
float ctorspec(vec3 ppos, vec3 lvector, vec3 normal,float rough,float fpow) {
float ctorspec(vec3 ppos, vec3 lvector, vec3 normal,float rough,float fpow) {
//half vector
//half vector
vec3 pos = -normalize(ppos);
vec3 pos = -normalize(ppos);
vec3 cHalf = normalize(lvector + pos);
vec3 cHalf = normalize(lvector + pos);
// beckman's distribution function D
// beckman's distribution function D
float normalDotHalf = dot(normal, cHalf);
float normalDotHalf = dot(normal, cHalf);
float normalDotHalf2 = normalDotHalf * normalDotHalf;
float normalDotHalf2 = normalDotHalf * normalDotHalf;
float roughness2 = rough;
float roughness2 = rough;
float exponent = -(1.0 - normalDotHalf2) / (normalDotHalf2 * roughness2);
float exponent = -(1.0 - normalDotHalf2) / (normalDotHalf2 * roughness2);
float e = 2.71828182846;
float e = 2.71828182846;
float D = pow(e, exponent) / (roughness2 * normalDotHalf2 * normalDotHalf2);
float D = pow(e, exponent) / (roughness2 * normalDotHalf2 * normalDotHalf2);
// fresnel term F
// fresnel term F
float normalDotEye = dot(normal, pos);
float normalDotEye = dot(normal, pos);
float F = pow(1.0 - normalDotEye, fpow);
float F = pow(1.0 - normalDotEye, fpow);
// self shadowing term G
// self shadowing term G
float normalDotLight = dot(normal, lvector);
float normalDotLight = dot(normal, lvector);
float X = 2.0 * normalDotHalf / dot(pos, cHalf);
float X = 2.0 * normalDotHalf / dot(pos, cHalf);
float G = min(1.0, min(X * normalDotLight, X * normalDotEye));
float G = min(1.0, min(X * normalDotLight, X * normalDotEye));
float pi = 3.1415927;
float pi = 3.1415927;
float CookTorrance = (D*F*G)/(pi*normalDotEye);
float CookTorrance = (D*F*G)/(pi*normalDotEye);
return max(CookTorrance/pi,0.0);
return max(CookTorrance/pi,0.0);
}
}
float diffuseorennayar(vec3 pos, vec3 lvector, vec3 normal, float spec, float roughness) {
float diffuseorennayar(vec3 pos, vec3 lvector, vec3 normal, float spec, float roughness) {
vec3 v=normalize(pos);
vec3 v=normalize(pos);
vec3 l=normalize(lvector);
vec3 l=normalize(lvector);
vec3 n=normalize(normal);
vec3 n=normalize(normal);
float vdotn=dot(v,n);
float vdotn=dot(v,n);
float ldotn=dot(l,n);
float ldotn=dot(l,n);
float cos_theta_r=vdotn;
float cos_theta_r=vdotn;
float cos_theta_i=ldotn;
float cos_theta_i=ldotn;
float cos_phi_diff=dot(normalize(v-n*vdotn),normalize(l-n*ldotn));
float cos_phi_diff=dot(normalize(v-n*vdotn),normalize(l-n*ldotn));
float cos_alpha=min(cos_theta_i,cos_theta_r); // alpha=max(theta_i,theta_r);
float cos_alpha=min(cos_theta_i,cos_theta_r); // alpha=max(theta_i,theta_r);
float cos_beta=max(cos_theta_i,cos_theta_r); // beta=min(theta_i,theta_r)
float cos_beta=max(cos_theta_i,cos_theta_r); // beta=min(theta_i,theta_r)
float r2=roughness*roughness;
float r2=roughness*roughness;
float a=1.0-0.5*r2/(r2+0.33);
float a=1.0-0.5*r2/(r2+0.33);
float b_term;
float b_term;
if(cos_phi_diff>=0.0) {
if(cos_phi_diff>=0.0) {
float b=0.45*r2/(r2+0.09);
float b=0.45*r2/(r2+0.09);
b_term = b*sin(cos_alpha)*tan(cos_beta)*cos_phi_diff;
b_term = b*sin(cos_alpha)*tan(cos_beta)*cos_phi_diff;
}
}
else b_term=0.0;
else b_term=0.0;
return clamp(cos_theta_i*(a+b_term),0.0,1.0);
return clamp(cos_theta_i*(a+b_term),0.0,1.0);
}
}
#ifdef CELSHADING
#ifdef CELSHADING
vec3 celshade(vec3 clrr) {
vec3 celshade(vec3 clrr) {
//edge detect
//edge detect
float d = edepth(texcoord.xy);
float d = edepth(texcoord.xy);
float dtresh = 1/(far-near)/5000.0;
float dtresh = 1/(far-near)/5000.0;
vec4 dc = vec4(d,d,d,d);
vec4 dc = vec4(d,d,d,d);
vec4 sa;
vec4 sa;
vec4 sb;
vec4 sb;
sa.x = edepth(texcoord.xy + vec2(-pw,-ph)*BORDER);
sa.x = edepth(texcoord.xy + vec2(-pw,-ph)*BORDER);
sa.y = edepth(texcoord.xy + vec2(pw,-ph)*BORDER);
sa.y = edepth(texcoord.xy + vec2(pw,-ph)*BORDER);
sa.z = edepth(texcoord.xy + vec2(-pw,0.0)*BORDER);
sa.z = edepth(texcoord.xy + vec2(-pw,0.0)*BORDER);
sa.w = edepth(texcoord.xy + vec2(0.0,ph)*BORDER);
sa.w = edepth(texcoord.xy + vec2(0.0,ph)*BORDER);
//opposite side samples
//opposite side samples
sb.x = edepth(texcoord.xy + vec2(pw,ph)*BORDER);
sb.x = edepth(texcoord.xy + vec2(pw,ph)*BORDER);
sb.y = edepth(texcoord.xy + vec2(-pw,ph)*BORDER);
sb.y = edepth(texcoord.xy + vec2(-pw,ph)*BORDER);
sb.z = edepth(texcoord.xy + vec2(pw,0.0)*BORDER);
sb.z = edepth(texcoord.xy + vec2(pw,0.0)*BORDER);
sb.w = edepth(texcoord.xy + vec2(0.0,-ph)*BORDER);
sb.w = edepth(texcoord.xy + vec2(0.0,-ph)*BORDER);
vec4 dd = abs(2.0* dc - sa - sb) - dtresh;
vec4 dd = abs(2.0* dc - sa - sb) - dtresh;
dd = vec4(step(dd.x,0.0),step(dd.y,0.0),step(dd.z,0.0),step(dd.w,0.0));
dd = vec4(step(dd.x,0.0),step(dd.y,0.0),step(dd.z,0.0),step(dd.w,0.0));
float e = clamp(dot(dd,vec4(0.5f,0.5f,0.5f,0.5f)),0.0,1.0);
float e = clamp(dot(dd,vec4(0.5f,0.5f,0.5f,0.5f)),0.0,1.0);
return clrr*e;
return clrr*e;
}
}
#endif
#endif
float getnoise(vec2 pos) {
float getnoise(vec2 pos) {
return abs(fract(sin(dot(pos ,vec2(18.9898f,28.633f))) * 4378.5453f));
return abs(fract(sin(dot(pos ,vec2(18.9898f,28.633f))) * 4378.5453f));
}
}
float interpolate(vec3 truepos,float center,vec3 poscenter,float value2,vec3 pos2,float value3,vec3 pos3,float value4,vec3 pos4,float value5,vec3 pos5) {
float interpolate(vec3 truepos,float center,vec3 poscenter,float value2,vec3 pos2,float value3,vec3 pos3,float value4,vec3 pos4,float value5,vec3 pos5) {
return center*(1.0-distance(truepos,poscenter))+value2*(1.0-distance(truepos,pos2))+value3*(1.0-distance(truepos,pos3))+value4*(1.0-distance(truepos,pos4))+value5*(1.0-distance(truepos,pos5));
return center*(1.0-distance(truepos,poscenter))+value2*(1.0-distance(truepos,pos2))+value3*(1.0-distance(truepos,pos3))+value4*(1.0-distance(truepos,pos4))+value5*(1.0-distance(truepos,pos5));
}
}
void main() {
void main() {
float shadowexit = float(aux.g > 0.1 && aux.g < 0.3);
float shadowexit = float(aux.g > 0.1 && aux.g < 0.3);
float land = float(aux.g > 0.04);
float land = float(aux.g > 0.04);
float iswater = float(aux.g > 0.04 && aux.g < 0.07);
float iswater = float(aux.g > 0.04 && aux.g < 0.07);
float translucent = float(aux.g > 0.3 && aux.g < 0.5);
float translucent = float(aux.g > 0.3 && aux.g < 0.5);
float hand = float(aux.g > 0.75 && aux.g < 0.85);
float hand = float(aux.g > 0.75 && aux.g < 0.85);
float roughness = mix(1.0-(pow(specular.g,2.0))+specular.b+iswet*specular.g*0.5,0.05,iswater);
float roughness = mix(1.0-(pow(specular.g,2.0))+specular.b+iswet*specular.g*0.5,0.05,iswater);
if (specular.r+specular.g+specular.b < 1.0/255.0 && iswater < 0.09) roughness = 0.0;
if (specular.r+specular.g+specular.b < 1.0/255.0 && iswater < 0.09) roughness = 0.0;
float fresnel_pow = pow(1.0-(specular.b+specular.g)/2.0,1.25+iswet*0.75)*3.5;
float fresnel_pow = pow(1.0-(specular.b+specular.g)/2.0,1.25+iswet*0.75)*3.5;
vec3 color = texture2D(gcolor, texcoord.st).rgb;
vec3 color = texture2D(gcolor, texcoord.st).rgb;
color = pow(color,vec3(2.2));
color = pow(color,vec3(2.2));
color = pow(color,vec3(1.0+iswet*0.5));
color = pow(color,vec3(1.0+iswet*0.5));
vec4 fragposition = gbufferProjectionInverse * vec4(texcoord.s * 2.0f - 1.0f, texcoord.t * 2.0f - 1.0f, 2.0f * pixeldepth - 1.0f, 1.0f);
vec4 fragposition = gbufferProjectionInverse * vec4(texcoord.s * 2.0f - 1.0f, texcoord.t * 2.0f - 1.0f, 2.0f * pixeldepth - 1.0f, 1.0f);
fragposition /= fragposition.w;
fragposition /= fragposition.w;
float shading = 1.0f;
float shading = 1.0f;
vec3 radiance = vec3(0.5);
vec3 radiance = vec3(0.5);
float spec = 0.0;
float spec = 0.0;
float time = float(worldTime);
float time = float(worldTime);
float transition_fading = 1.0-(clamp((time-12000.0)/300.0,0.0,1.0)-clamp((time-13000.0)/300.0,0.0,1.0) + clamp((time-22800.0)/200.0,0.0,1.0)-clamp((time-23400.0)/200.0,0.0,1.0)); //fading between sun/moon shadows
float transition_fading = 1.0-(clamp((time-12000.0)/300.0,0.0,1.0)-clamp((time-13000.0)/300.0,0.0,1.0) + clamp((time-22800.0)/200.0,0.0,1.0)-clamp((time-23400.0)/200.0,0.0,1.0)); //fading between sun/moon shadows
float night = clamp((time-12000.0)/300.0,0.0,1.0)-clamp((time-22800.0)/200.0,0.0,1.0);
float night = clamp((time-12000.0)/300.0,0.0,1.0)-clamp((time-22800.0)/200.0,0.0,1.0);
if (land > 0.9 && isEyeInWater < 0.1) {
if (land > 0.9 && isEyeInWater < 0.1) {
float dist = length(fragposition.xyz);
float dist = length(fragposition.xyz);
float shadingsharp = 0.0f;
float shadingsharp = 0.0f;
vec4 worldposition = vec4(0.0);
vec4 worldposition = vec4(0.0);
vec4 worldpositionraw = vec4(0.0);
vec4 worldpositionraw = vec4(0.0);
worldposition = gbufferModelViewInverse * fragposition;
worldposition = gbufferModelViewInverse * fragposition;
float xzDistanceSquared = worldposition.x * worldposition.x + worldposition.z * worldposition.z;
float xzDistanceSquared = worldposition.x * worldposition.x + worldposition.z * worldposition.z;
float yDistanceSquared = worldposition.y * worldposition.y;
float yDistanceSquared = worldposition.y * worldposition.y;
worldpositionraw = worldposition;
worldpositionraw = worldposition;
worldposition = shadowModelView * worldposition;
worldposition = shadowModelView * worldposition;
float comparedepth = -worldposition.z;
float comparedepth = -worldposition.z;
worldposition = shadowProjection * worldposition;
worldposition = shadowProjection * worldposition;
worldposition /= worldposition.w;
worldposition /= worldposition.w;
float distb = sqrt(worldposition.x * worldposition.x + worldposition.y * worldposition.y);
float distb = sqrt(worldposition.x * worldposition.x + worldposition.y * worldposition.y);
float distortFactor = (1.0f - 0.85) + distb * 0.85;
float distortFactor = (1.0f - 0.85) + distb * 0.85;
worldposition.xy *= 1.0f / distortFactor;
worldposition.xy *= 1.0f / distortFactor;
worldposition = worldposition * 0.5f + 0.5f;
worldposition = worldposition * 0.5f + 0.5f;
int vpsize = 0;
int vpsize = 0;
float diffthresh = 1.0*distortFactor+iswater+translucent;
float diffthresh = 1.0*distortFactor+iswater+translucent;
float isshadow = 0.0;
float isshadow = 0.0;
float ssample;
float ssample;
float distof = clamp(1.0-dist/shadowDistance,0.0,1.0);
float distof = clamp(1.0-dist/shadowDistance,0.0,1.0);
float distof2 = clamp(1.0-dist/(shadowDistance*0.75),0.0,1.0);
float distof2 = clamp(1.0-dist/(shadowDistance*0.75),0.0,1.0);
float shadow_fade = clamp(distof*12.0,0.0,1.0);
float shadow_fade = clamp(distof*12.0,0.0,1.0);
float sss_fade = pow(distof2,0.2);
float sss_fade = pow(distof2,0.2);
float step = 1.0/shadowMapResolution*(1.0+rainStrength*10.0);
float step = 1.0/shadowMapResolution*(1.0+rainStrength*10.0);
if (dist < shadowDistance) {
if (dist < shadowDistance) {
if (shadowexit > 0.1) {
if (shadowexit > 0.1) {
shading = 1.0;
shading = 1.0;
} else {
} else {
for(int i = 0; i < 25; i++){
for(int i = 0; i < 25; i++){
shadingsharp += (clamp(comparedepth - (0.05 + (texture2D(shadow, worldposition.st + circle_offsets[i]*step).z) * (256.0 - 0.05)), 0.0, diffthresh)/(diffthresh));
shadingsharp += (clamp(comparedepth - (0.05 + (texture2D(shadow, worldposition.st + circle_offsets[i]*step).z) * (256.0 - 0.05)), 0.0, diffthresh)/(diffthresh));
}
}
shadingsharp /= 25.0;
shadingsharp /= 25.0;
shading = 1.0-shadingsharp;
shading = 1.0-shadingsharp;
isshadow = 1.0;
isshadow = 1.0;
}
}
}
}
float ao = 1.0;
float ao = 1.0;
#ifdef SSAO
#ifdef SSAO
if (land > 0.9 && iswater < 0.9 && hand < 0.9) {
if (land > 0.9 && iswater < 0.9 && hand < 0.9) {
vec3 norm = texture2D(gnormal,texcoord.xy).rgb*2.0-1.0;
vec3 norm = texture2D(gnormal,texcoord.xy).rgb*2.0-1.0;
vec3 projpos = convertScreenSpaceToWorldSpace(texcoord.xy,pixeldepth);
vec3 projpos = convertScreenSpaceToWorldSpace(texcoord.xy,pixeldepth);
float progress = 0.0;
float progress = 0.0;
ao = 0.0;
ao = 0.0;
float projrad = clamp(distance(convertCameraSpaceToScreenSpace(projpos + vec3(ssaorad,ssaorad,ssaorad)).xy,texcoord.xy),7.5*pw,60.0*pw);
float projrad = clamp(distance(convertCameraSpaceToScreenSpace(projpos + vec3(ssaorad,ssaorad,ssaorad)).xy,texcoord.xy),7.5*pw,60.0*pw);
for (int i = 1; i < nbdir; i++) {
for (int i = 1; i < nbdir; i++) {
for (int j = 1; j < sampledir; j++) {
for (int j = 1; j < sampledir; j++) {
vec2 samplecoord = vec2(cos(progress),sin(progress))*(j/sampledir)*projrad + texcoord.xy;
vec2 samplecoord = vec2(cos(progress),sin(progress))*(j/sampledir)*projrad + texcoord.xy;
float sample = texture2D(depthtex0,samplecoord).x;
float sample = texture2D(depthtex0,samplecoord).x;
vec3 sprojpos = convertScreenSpaceToWorldSpace(samplecoord,sample);
vec3 sprojpos = convertScreenSpaceToWorldSpace(samplecoord,sample);
float angle = pow(min(1.0-dot(norm,normalize(sprojpos-projpos)),1.0),2.0);
float angle = pow(min(1.0-dot(norm,normalize(sprojpos-projpos)),1.0),2.0);
float dist = pow(min(abs(ld(sample)-ld(pixeldepth)),0.015)/0.015,2.0);
float dist = pow(min(abs(ld(sample)-ld(pixeldepth)),0.015)/0.015,2.0);
float temp = min(dist+angle,1.0);
float temp = min(dist+angle,1.0);
ao += pow(temp,3.0);
ao += pow(temp,3.0);
}
}
progress = i*1.256;
progress = i*1.256;
}
}
ao /= (nbdir-1)*(sampledir-1);
ao /= (nbdir-1)*(sampledir-1);
}
}
#endif
#endif
float sss_transparency = mix(0.0,0.75,translucent); //subsurface scattering amount
float sss_transparency = mix(0.0,0.75,translucent); //subsurface scattering amount
float sunlight_direct = 1.0;
float sunlight_direct = 1.0;
float direct = 1.0;
float direct = 1.0;
float sss = 0.0;
float sss = 0.0;
vec3 npos = normalize(fragposition.xyz);
vec3 npos = normalize(fragposition.xyz);
float NdotL = 1.0;
float NdotL = 1.0;
NdotL = dot(normal, lightVector);
NdotL = dot(normal, lightVector);
direct = NdotL;
direct = NdotL;
sunlight_direct = diffuseorennayar(fragposition.xyz, lightVector, normal, specmap, roughness+0.01);
sunlight_direct = diffuseorennayar(fragposition.xyz, lightVector, normal, specmap, roughness+0.01);
sunlight_direct = mix(sunlight_direct,0.5,translucent*min(sss_fade+0.4,1.0));
sunlight_direct = mix(sunlight_direct,0.5,translucent*min(sss_fade+0.4,1.0));
sss += pow(max(dot(npos, lightVector),0.0),20.0)*sss_transparency*clamp(-NdotL,0.0,1.0)*translucent*4.0;
sss += pow(max(dot(npos, lightVector),0.0),20.0)*sss_transparency*clamp(-NdotL,0.0,1.0)*translucent*4.0;
sss = mix(0.0,sss,sss_fade);
sss = mix(0.0,sss,sss_fade);
shading = clamp(shading,0.0,1.0);
shading = clamp(shading,0.0,1.0);
float handlightAmount = clamp(1.0-dist/5.0,0.0,1.0);
float handLight = (handlight*5.0)/pow(length(fragposition.xyz),1.5)*diffuseorennayar(fragposition.xyz, -fragposition.xyz, normal, specmap, roughness+0.01);
float handLight = (handlightAmount*handlightAmount)*handlight;
float handSpec = ctorspec(fragposition.xyz,-fragposition.xyz,normalize(normal),roughness+0.01,fresnel_pow)*specmap*handLight*4.0;
float handSpec = ctorspec(fragposition.xyz,-fragposition.xyz,normalize(normal),roughness+0.01,fresnel_pow)*specmap*handLight*4.0;
//Apply different lightmaps to image
//Apply different lightmaps to image
//Sun & Sky
//Sun & Sky
vec3 Sunlight_lightmap = sunlight_color*mix(max(sky_lightmap-rainStrength*0.85,0.0),shading*(1.0-rainStrength*0.85),shadow_fade)*SUNLIGHTAMOUNT *sunlight_direct*transition_fading ;
vec3 Sunlight_lightmap = sunlight_color*mix(max(sky_lightmap-rainStrength*0.85,0.0),shading*(1.0-rainStrength*0.85),shadow_fade)*SUNLIGHTAMOUNT *sunlight_direct*transition_fading ;
float visibility = (dot(normal,normalize(upPosition))*0.05+0.95)*sky_lightmap;
float visibility = (dot(normal,normalize(upPosition))*0.05+0.95)*sky_lightmap;
float bouncefactor = (dot(normal,normalize(upPosition))*0.5+0.5)*sky_lightmap;
float bouncefactor = (dot(normal,normalize(upPosition))*0.5+0.5)*sky_lightmap;
vec3 reflected_sunlight = 0.1*sky_lightmap*sunlight_color*max(-NdotL*0.6+0.4,0.0)*SUNLIGHTAMOUNT*radiance*ao*0.3;
vec3 reflected_sunlight = 0.1*sky_lightmap*sunlight_color*max(-NdotL*0.6+0.4,0.0)*SUNLIGHTAMOUNT*radiance*ao*0.3;
vec3 sky_light = 0.1*pow(ambient_color,vec3(1.2))*ao * mix(radiance*0.5,vec3(0.5),bouncefactor) * visibility*2.0;
vec3 sky_light = 0.1*pow(ambient_color,vec3(1.2))*ao * mix(radiance*0.5,vec3(0.5),bouncefactor) * visibility*2.0;
vec3 color_sunlight = Sunlight_lightmap;
vec3 color_sunlight = Sunlight_lightmap;
//Torch
//Torch
vec3 torchcolor = vec3(0.89,0.55,0.2);
vec3 torchcolor = vec3(0.89,0.55,0.2);
vec3 Torchlight_lightmap = (torch_lightmap + handLight) * torchcolor ;
vec3 Torchlight_lightmap = (torch_lightmap + handLight) * torchcolor;
vec3 color_torchlight = Torchlight_lightmap;
vec3 color_torchlight = Torchlight_lightmap;
#ifndef NightIsTooDarkForMe
if (TimeRealNightMorning > 0.9){
float lightAmount = (abs(worldTime - 12000)/12000.0) * 15.0;
color *= 1.0*torch_lightmap;
color *= color_torchlight + Sunlight_lightmap + reflected_sunlight + sky_light * lightAmount;
}
#else
if (TimeRealNightMorning > 0.05) {
color.r = color.r*1.3+0.01;
color.g = color.g*1.2;
color.b = color.b*0.75+0.10;
color *= 0.5;
}
#endif
//Add all light elements together
//Add all light elements together
color = (reflected_sunlight + sky_light + 0.1*ao + Sunlight_lightmap + color_torchlight*ao + sss * sunlight_color * shading *(1.0-rainStrength*0.9)*transition_fading)*color + handSpec * torchcolor ;
color = (reflected_sunlight + sky_light + 0.1*ao + Sunlight_lightmap + color_torchlight*ao + sss * sunlight_color * shading *(1.0-rainStrength*0.9)*transition_fading)*color + handSpec * torchcolor ;
} else if (isEyeInWater < 0.1 && (aux.g < 0.02) ){
} else if (isEyeInWater < 0.1 && (aux.g < 0.02) ){
color = mix(color,(gl_Fog.color.rgb+vec3(0.12,0.12,0.12))/2.0,rainStrength)*vec3(0.45,0.45,1.0);
color = mix(color,(gl_Fog.color.rgb+vec3(0.12,0.12,0.12))/2.0,rainStrength)*vec3(0.45,0.45,1.0);
}
}
/* DRAWBUFFERS:31 */
/* DRAWBUFFERS:31 */
spec = ctorspec(fragposition.xyz,lightVector,normalize(normal),roughness+0.01,fresnel_pow) * (specmap+iswater)*land * (1.0-isEyeInWater) * shading * (1.0-night*0.75)*0.25;
spec = ctorspec(fragposition.xyz,lightVector,normalize(normal),roughness+0.01,fresnel_pow) * (specmap+iswater)*land * (1.0-isEyeInWater) * shading * (1.0-night*0.75)*0.25;
#ifdef CELSHADING
#ifdef CELSHADING
if (land > 0.9 && iswater < 0.9) color = celshade(color);
if (land > 0.9 && iswater < 0.9) color = celshade(color);
#endif
#endif
#ifdef GODRAYS
#ifdef GODRAYS
vec4 tpos = vec4(sunPosition,1.0)*gbufferProjection;
vec4 tpos = vec4(sunPosition,1.0)*gbufferProjection;
tpos = vec4(tpos.xyz/tpos.w,1.0);
tpos = vec4(tpos.xyz/tpos.w,1.0);
vec2 pos1 = tpos.xy/tpos.z;
vec2 pos1 = tpos.xy/tpos.z;
vec2 lightPos = pos1*0.5+0.5;
vec2 lightPos = pos1*0.5+0.5;
float gr = 0.0;
float gr = 0.0;
float truepos = pow(clamp(dot(-lightVector,tpos.xyz)/length(tpos.xyz),0.0,1.0),0.5); //temporary fix that check if the sun/moon position is correct
float truepos = pow(clamp(dot(-lightVector,tpos.xyz)/length(tpos.xyz),0.0,1.0),0.5); //temporary fix that check if the sun/moon position is correct
if (truepos > 0.05) {
if (truepos > 0.05) {
vec2 deltaTextCoord = vec2( texcoord.st - lightPos.xy );
vec2 deltaTextCoord = vec2( texcoord.st - lightPos.xy );
vec2 textCoord = texcoord.st;
vec2 textCoord = texcoord.st;
deltaTextCoord *= 1.0 / float(NUM_SAMPLES) * density;
deltaTextCoord *= 1.0 / float(NUM_SAMPLES) * density;
float avgdecay = 0.0;
float avgdecay = 0.0;
float distx = abs(texcoord.x*aspectRatio-lightPos.x*aspectRatio);
float distx = abs(texcoord.x*aspectRatio-lightPos.x*aspectRatio);
float disty = abs(texcoord.y-lightPos.y);
float disty = abs(texcoord.y-lightPos.y);
vec2 noise = vec2(getnoise(textCoord),getnoise(-textCoord.yx+0.05));
vec2 noise = vec2(getnoise(textCoord),getnoise(-textCoord.yx+0.05));
for(int i=0; i < NUM_SAMPLES ; i++) {
for(int i=0; i < NUM_SAMPLES ; i++) {
textCoord -= deltaTextCoord;
textCoord -= deltaTextCoord;
float sample = step(texture2D(gaux1, textCoord+ textCoord*noise*grnoise).g,0.01);
float sample = step(texture2D(gaux1, textCoord+ textCoord*noise*grnoise).g,0.01);
gr += sample;
gr += sample;
}
}
}
}
#endif
#endif
color = pow(color,vec3(1.0/2.2));
color = pow(color,vec3(1.0/2.2));
color = clamp(color,0.0,1.0);
color = clamp(color,0.0,1.0);
gl_FragData[0] = vec4(color, spec);
gl_FragData[0] = vec4(color, spec);
gl_FragData[1] = vec4(vec3((gr/NUM_SAMPLES)),1.0);
gl_FragData[1] = vec4(vec3((gr/NUM_SAMPLES)),1.0);
}
}