Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 120
- #define MAX_COLOR_RANGE 48.0
- /*
- Read my terms of mofification/sharing before changing something below please!
- Chocapic13' shaders, derived from SonicEther v10 rc6.
- Place two leading Slashes in front of the following '#define' lines in order to disable an option.
- */
- #define Godrays
- const float exposure = 6.0;
- const float density = 1.0;
- const int NUM_SAMPLES = 2;
- const float grnoise = 1.0;
- #define WaterReflection
- #define WaterReflectionStrength 1.0
- #define UnderwaterWaterCaustics
- #define UnderwaterWaterCausticsStrength 10.5
- #define UnderwaterWaterCausticsSize 0.11
- #define UnderwaterWaterCausticsSpeed 6.5
- #define VolumeLight
- #define VolumeLightMultiplier 3.0
- #define VolumeLightMultiplierDay 1.0
- #define VolumeLightMultiplierNight 0.0
- #define VolumeLightMultiplierSunsetSunrise 1.0
- #define VL_STRENGTH_INSIDE 1.5
- const bool gdepthMipmapEnabled = true;
- //#define Specular
- #define WATER_REFRACT
- #define REFRACT_MULT 7.0
- //don't touch these lines if you don't know what you do!
- const int maxf = 8; //number of refinements
- const float stp = 1.0; //size of one step for raytracing algorithm
- const float ref = 0.05; //refinement multiplier
- const float inc = 2.2; //increasement factor at each step
- //ground constants (lower quality)
- const int Gmaxf = 3; //number of refinements
- const float Gstp = 1.2; //size of one step for raytracing algorithm
- const float Gref = 0.11; //refinement multiplier
- const float Ginc = 3.0; //increasement factor at each step
- varying vec4 texcoord;
- varying vec3 lightVector;
- varying vec3 sunVec;
- varying vec3 moonVec;
- varying vec3 upVec;
- varying vec3 sunlight;
- varying vec3 moonlight;
- varying vec3 ambient_color;
- varying float handItemLight;
- varying float SdotU;
- varying float MdotU;
- varying float sunVisibility;
- varying float moonVisibility;
- uniform sampler2D composite;
- uniform sampler2D gaux4;
- uniform sampler2D gaux3;
- uniform sampler2D gaux1;
- uniform sampler2D depthtex0;
- uniform sampler2D depthtex1;
- uniform sampler2D gnormal;
- uniform sampler2D gdepth;
- uniform sampler2D noisetex;
- uniform sampler2D gcolor;
- uniform sampler2DShadow shadow;
- uniform sampler2D gdepthtex;
- uniform vec3 sunPosition;
- uniform vec3 moonPosition;
- uniform vec3 upPosition;
- uniform vec3 cameraPosition;
- uniform vec3 skyColor;
- uniform mat4 gbufferProjection;
- uniform mat4 gbufferProjectionInverse;
- uniform mat4 gbufferModelViewInverse;
- uniform mat4 shadowModelView;
- uniform mat4 shadowProjection;
- uniform mat4 shadowProjectionInverse;
- uniform mat4 shadowModelViewInverse;
- uniform int isEyeInWater;
- uniform int worldTime;
- uniform float far;
- uniform float near;
- uniform float aspectRatio;
- uniform float viewWidth;
- uniform float viewHeight;
- uniform float rainStrength;
- uniform float wetness;
- uniform float frameTimeCounter;
- uniform int fogMode;
- uniform ivec2 eyeBrightnessSmooth;
- float pw = 1.0/ viewWidth;
- float ph = 1.0/ viewHeight;
- float matflag = texture2D(gaux1,texcoord.xy).g;
- int iswater = int(matflag > 0.04 && matflag < 0.07);
- vec3 fogclr = pow(mix(vec3(0.5,0.5,1.0),vec3(0.3,0.3,0.3),rainStrength)*ambient_color,vec3(2.2));
- vec3 fragpos = vec3(texcoord.st, texture2D(depthtex0, texcoord.st).r);
- vec3 normal = texture2D(gnormal, texcoord.st).rgb * 2.0 - 1.0;
- 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-22000.0)/200.0,0.0,1.0)-clamp((time-23400.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);
- float sky_lightmap = texture2D(gaux1,texcoord.xy).r;
- float iswet = wetness*pow(sky_lightmap,5.0)*sqrt(0.5+max(dot(normal,normalize(upPosition)),0.0));
- vec3 specular = pow(texture2D(gaux3,texcoord.xy).rgb,vec3(2.2));
- float specmap = (specular.r+specular.g*(iswet));
- vec4 color = texture2D(composite,texcoord.xy);
- float ld(float depth) {
- return (2.0 * near) / (far + near - depth * (far - near));
- }
- float timefract = worldTime;
- float rainx = clamp(rainStrength, 0.0f, 1.0f)/1.0f;
- //Calculate Time of Day
- float TimeSunrise = ((clamp(timefract, 23000.0, 24000.0) - 23000.0) / 1000.0) + (1.0 - (clamp(timefract, 0.0, 4000.0)/4000.0));
- float TimeNoon = ((clamp(timefract, 0.0, 4000.0)) / 4000.0) - ((clamp(timefract, 8000.0, 12000.0) - 8000.0) / 4000.0);
- float TimeSunset = ((clamp(timefract, 8000.0, 12000.0) - 8000.0) / 4000.0) - ((clamp(timefract, 12000.0, 12750.0) - 12000.0) / 750.0);
- float TimeMidnight = ((clamp(timefract, 12000.0, 12750.0) - 12000.0) / 750.0) - ((clamp(timefract, 23000.0, 24000.0) - 23000.0) / 1000.0);
- float dynamicExposure()
- {
- return mix(1.0,0.0,(pow(eyeBrightnessSmooth.y / 240.0f, 3.0f)));
- }
- vec3 nvec3(vec4 pos) {
- return pos.xyz/pos.w;
- }
- vec4 nvec4(vec3 pos) {
- return vec4(pos.xyz, 1.0);
- }
- float cdist(vec2 coord) {
- return max(abs(coord.s-0.5),abs(coord.t-0.5))*2.0;
- }
- float luma(vec3 color) {
- return dot(color.rgb,vec3(0.299, 0.587, 0.114));
- }
- float getnoise(vec2 pos) {
- return abs(fract(sin(dot(pos ,vec2(18.9898f,28.633f))) * 4378.5453f));
- }
- vec3 skyLightIntegral (vec3 fposition) {
- vec3 skycoaa = ivec3(28,180,255)/255.0;
- vec3 sky_color = mix(moonlight*2.0,pow(skycoaa,vec3(2.2)),sunVisibility)*2.0;
- sky_color = mix(sky_color,vec3(0.25,0.3,0.4)*length(ambient_color),rainStrength);
- vec3 sVector = normalize(fposition);
- vec3 upVector = normalize(upPosition);
- const float PI = 3.14159265359;
- float Lz = 1.0;
- float T = max(acos(dot(sVector,upVec)),0.0);
- float Y = max(acos(dot(sunVec,sVector)),0.0);
- float M = max(acos(dot(moonVec,sVector)),0.0);
- float blueDif = (1+2.0*cos(T));
- float sunDif = (1.0+2.0*max(cos(Y),0.0));
- float hemisphereIntegral = PI + 2.0*(sin(T+PI/2.0)-sin(T-PI/2.0));
- float sunIntegral = PI + 2.0*max(sin(Y+PI/2.0)*sin(Y+PI/2.0)*sin(Y+PI/2.0)-sin(Y-PI/2.0)*sin(Y-PI/2.0)*sin(Y-PI/2.0),0.0);
- float moonIntegral = PI + 2.0*max(sin(M+PI/2.0)*sin(M+PI/2.0)*sin(M+PI/2.0)-sin(M-PI/2.0)*sin(M-PI/2.0)*sin(M-PI/2.0),0.0);
- return hemisphereIntegral*sky_color*Lz + sunIntegral*(1-rainStrength*0.9) * sunVisibility + moonIntegral * moonlight * moonVisibility;
- }
- float subSurfaceScattering(vec3 pos, float N) {
- return pow(max(dot(lightVector,normalize(pos)),0.0),N)*(N+1)/6.28;
- }
- vec3 getSkyColor(vec3 fposition) {
- //sky gradient
- /*----------*/
- vec3 skycoaa = ivec3(30,170,255)/255.0;
- vec3 sky_color = pow(skycoaa,vec3(2.2));
- vec3 nsunlight = normalize(pow(sunlight,vec3(2.2)));
- vec3 sVector = normalize(fposition);
- vec3 upVector = normalize(upPosition);
- sky_color = normalize(mix(sky_color,vec3(0.25,0.3,0.4)*length(ambient_color),rainStrength)); //normalize colors in order to don't change luminance
- float Lz = 1.0;
- float cosT = dot(sVector,upVector); //T=S-Y
- float absCosT = abs(cosT);
- float cosS = dot(sunVec,upVector);
- float S = acos(cosS); //S=Y+T -> cos(Y+T)=cos(S) -> cos(Y)*cos(T) - sin(Y)*sin(T) = cos(S)
- float cosY = dot(sunVec,sVector);
- float Y = acos(cosY); //Y=S-T
- float a = -0.7;
- float b = -0.2;
- float c = 12.0;
- float d = -0.9;
- float e = 3.0;
- //sun sky color
- float L = (1+a*exp(b/(absCosT+0.01)))*(1+c*exp(d*Y)+e*cosY*cosY);
- //vec3 Lc = 1 + c*exp(d*Y)*sky_color + e*cosY*cosY*sky_color + a*exp(b/(absCosT+0.01))*sky_color + a*exp(b/(absCosT+0.01))*c*exp(d*Y) *nsunlight+ a*exp(b/(absCosT+0.01))*e*cosY*cosY*nsunlight;
- //= 1 + f(Y) + g(Y) + h(T) + i(T,Y) + j(T,Y)
- //S is constant on the frame
- //float T = 2.0*S-Y;
- // cosT2 = abs(cos(S+Y));
- //L = 1 + c*exp(d*Y) + e*cosY*cosY + a*exp(b/(cosT2+0.01)) + a*exp(b/(cosT2+0.01))*c*exp(d*Y) + a*exp(b/(cosT2+0.01))*e*cosY*cosY;
- //1 + c*exp(d*Y) + e*cosY*cosY + a*exp(b/cos(T)) + a*exp(b/cos(T))*c*exp(d*Y) + a*exp(b/cos(T)))*e*cosY*cosY;
- L = pow(L,1.0-rainStrength*0.8)*(1.0-rainStrength*0.2); //modulate intensity when raining
- //vec3 skyColorSun = mix(sky_color,,1-exp(-0.3*L*(1-rainStrength*0.8)));
- vec3 skyColorSun = mix(sky_color, nsunlight,1-exp(-0.13*L*(1-rainStrength*0.8)))*L ; //affect color based on luminance (0% physically accurate)
- skyColorSun *= sunVisibility;
- //moon sky color
- float McosS = dot(moonVec,upVector);
- float MS = acos(McosS);
- float McosY = dot(moonVec,sVector);
- float MY = acos(McosY);
- float L2 = (1+a*exp(b/(absCosT+0.01)))*(1+c*exp(d*MY)+e*McosY*McosY);
- L2 = pow(L2,1.0-rainStrength*0.8)*(1.0-rainStrength*0.2); //modulate intensity when raining
- vec3 skyColormoon = mix(moonlight,normalize(vec3(0.25,0.3,0.4))*length(moonlight),rainStrength)*L2*0.4 ; //affect color based on luminance (0% physically accurate)
- skyColormoon *= moonVisibility;
- sky_color = skyColormoon+skyColorSun/2.0;
- //sky_color = vec3(Lc);
- /*----------*/
- return sky_color;
- }
- vec3 getFogColor(vec3 fposition) {
- vec3 skycoaa = ivec3(30,170,255)/255.0;
- vec3 sky_color = pow(skycoaa,vec3(2.2));
- vec3 nsunlight = normalize(pow(sunlight,vec3(2.2)));
- vec3 sVector = normalize(fposition);
- vec3 upVector = normalize(upPosition);
- sky_color = normalize(mix(sky_color,vec3(0.25,0.3,0.4)*length(ambient_color),rainStrength)); //normalize colors in order to don't change luminance
- float Lz = 1.0;
- float cosT = dot(sVector,upVector); //T=S-Y
- float absCosT = abs(cosT);
- float cosS = dot(sunVec,upVector);
- float S = acos(cosS); //S=Y+T -> cos(Y+T)=cos(S) -> cos(Y)*cos(T) - sin(Y)*sin(T) = cos(S)
- float cosY = dot(sunVec,sVector);
- float Y = acos(cosY); //Y=S-T
- //float L = ((0.91+10*exp(-3*Y)+0.45*cosY*cosY)*(1.0-exp(-0.32/(absCosT+0.01))))/((0.91+10*exp(-3*S)+0.45*cosS*cosS)*(1.0-exp(-0.32))); //CIE clear sky
- float a = -0.7;
- float b = -0.2;
- float c = 12.0;
- float d = -0.9;
- float e = 3.0;
- //sun sky color
- float L = (1+a*exp(b/(absCosT+0.01)))*(1+c*exp(d*Y)+e*cosY*cosY);
- //vec3 Lc = 1 + c*exp(d*Y)*sky_color + e*cosY*cosY*sky_color + a*exp(b/(absCosT+0.01))*sky_color + a*exp(b/(absCosT+0.01))*c*exp(d*Y) *nsunlight+ a*exp(b/(absCosT+0.01))*e*cosY*cosY*nsunlight;
- //= 1 + f(Y) + g(Y) + h(T) + i(T,Y) + j(T,Y)
- //S is constant on the frame
- //float T = 2.0*S-Y;
- //float cosT2 = abs(cos(S+Y));
- //L = 1 + c*exp(d*Y) + e*cosY*cosY + a*exp(b/(cosT2+0.01)) + a*exp(b/(cosT2+0.01))*c*exp(d*Y) + a*exp(b/(cosT2+0.01))*e*cosY*cosY;
- L = pow(L,1.0-rainStrength*0.8)*(1.0-rainStrength*0.2); //modulate intensity when raining
- //vec3 skyColorSun = mix(sky_color,,1-exp(-0.3*L*(1-rainStrength*0.8)));
- vec3 skyColorSun = mix(sky_color, nsunlight,1-exp(-0.05*L*(1-rainStrength*0.8)))*sqrt(L) ; //affect color based on luminance (0% physically accurate)
- skyColorSun *= sunVisibility;
- //moon sky color
- float McosS = dot(moonVec,upVector);
- float MS = acos(McosS);
- float McosY = dot(moonVec,sVector);
- float MY = acos(McosY);
- float L2 = (1+a*exp(b/absCosT))*(1+c*exp(d*MY)+e*McosY*McosY);
- L2 = pow(L2,1.0-rainStrength*0.8)*(1.0-rainStrength*0.2); //modulate intensity when raining
- vec3 skyColormoon = mix(moonlight,normalize(vec3(0.25,0.25,0.25))*length(moonlight),rainStrength)*sqrt(L2) ;
- skyColormoon *= moonVisibility;
- sky_color = skyColormoon+skyColorSun/2.0;
- //sky_color = vec3(Lc);
- /*----------*/
- return sky_color;
- }
- float pixeldepth = texture2D(depthtex0,texcoord.xy).x;
- float getDepth(float depth) {
- return 2.0 * near * far / (far + near - (2.0 * depth - 1.0) * (far - near));
- }
- float waterH(vec2 posxz, float visibility) {
- vec2 movement = vec2(-abs(frameTimeCounter/2000.-0.5),-abs(frameTimeCounter/2000.-0.5));
- vec2 movement2 = vec2(abs(frameTimeCounter/2000.-0.5),abs(frameTimeCounter/2000.-0.5));
- vec2 coord = (posxz/600)+(movement);
- vec2 coord1 = (posxz/599)+(movement2);
- vec2 coord2 = (posxz/598)+(movement);
- vec2 coord3 = (posxz/597)+(movement2);
- float noise = texture2D(noisetex,fract(coord.xy/2.0)).x/8;
- noise += texture2D(noisetex,fract(coord1.xy)).x/16.0;
- noise += texture2D(noisetex,fract(coord2.xy*2.0)).x/8;
- noise += texture2D(noisetex,fract(coord3.xy*2.0)).x/8;
- return noise * visibility;
- }
- vec3 skyGradient (vec3 fposition, vec3 color, vec3 fogclr) {
- return (fogclr*3.+color)/4.;
- }
- vec3 getWaveHeight(vec2 posxz){
- vec2 coord = (posxz);
- float deltaPos = 0.3;
- //float fc = (find_closest(texcoord.st,deltaPos));
- float h0 = waterH(coord, 1.0f);
- float h1 = waterH(coord + vec2(deltaPos,0.0), 1.0f);
- float h2 = waterH(coord + vec2(-deltaPos,0.0), 1.0f);
- float h3 = waterH(coord + vec2(0.0,deltaPos), 1.0f);
- float h4 = waterH(coord + vec2(0.0,-deltaPos), 1.0f);
- float xDelta = ((h1-h0)+(h0-h2))/deltaPos;
- float yDelta = ((h3-h0)+(h0-h4))/deltaPos;
- vec3 wave = normalize(vec3(xDelta,yDelta,1.0-pow(abs(xDelta+yDelta),2.0)));
- return wave;
- }
- float getWaterDepth(){
- vec2 getCustomTc = texcoord.st;
- vec3 uPos = vec3(.0);
- float uDepth = texture2D(depthtex1,getCustomTc).x;
- uPos = nvec3(gbufferProjectionInverse * vec4(vec3(getCustomTc.xy,uDepth) * 2.0 - 1.0, 1.0));
- vec3 uVec = fragpos-uPos;
- float UNdotUP = abs(dot(normalize(uVec),normal));
- float depth = sqrt(dot(uVec,uVec))*UNdotUP;
- //depth *= refractMask;
- return depth;
- }
- float refractmask(in vec2 coord){
- float mask = texture2D(gaux1, coord.st).g;
- mask = float(mask > 0.04 && mask < 0.07);
- return mask;
- }
- void waterRefraction(inout vec3 color, in vec4 worldposition, in vec4 fragposition) {
- vec3 posxz = worldposition.xyz + cameraPosition.xyz;
- float chromaticAbborationAmount = 0.1;
- vec3 refraction = getWaveHeight(posxz.xz + posxz.y);
- float depth = getDepth(texture2D(depthtex1, texcoord.st).x);
- float depth2 = getDepth(pixeldepth);
- float wDepth = depth - depth2;
- float refMult = 1.0;
- refMult = clamp(wDepth,0.0,1.0);
- refMult /= (depth2);
- refMult *= (REFRACT_MULT/75);
- chromaticAbborationAmount *= refMult;
- vec2 coord1 = texcoord.st + refraction.xy * (refMult);
- vec2 coord2 = texcoord.st + refraction.xy * (refMult + chromaticAbborationAmount);
- vec2 coord3 = texcoord.st + refraction.xy * (refMult + chromaticAbborationAmount * 2.0);
- vec3 rA;
- rA.x = texture2D(gcolor, coord1).x;
- rA.y = texture2D(gcolor, coord2).y;
- rA.z = texture2D(gcolor, coord3).z;
- float maskCoord1 = refractmask(coord1);
- float maskCoord2 = refractmask(coord2);
- float maskCoord3 = refractmask(coord3);
- vec3 rB = color.rgb;
- refraction.r = rA.r*maskCoord1 + rB.r*(1-maskCoord1);
- refraction.g = rA.g*maskCoord2 + rB.g*(1-maskCoord2);
- refraction.b = rA.b*maskCoord3 + rB.b*(1-maskCoord3);
- if (iswater > 0.9)
- color = refraction;
- //color += abs(1-clamp(pixeldepth / 1.25,0.0,1.0));
- }
- vec3 calcFog(vec3 fposition, vec3 color) {
- float fog = exp(-pow(length(fposition)/256.0,4.0-(2.7*rainStrength))*40.0);
- float fogfactor = clamp(fog,0.0,1.0);
- fogclr = getFogColor(fposition.xyz);
- return mix((fogclr+color.rgb*2.0*(1-rainStrength*0.9))/(1+2.0*(1-rainStrength*0.9)),color.rgb,fogfactor);
- }
- vec4 raytraceGround(vec3 fragpos, vec3 normal,vec3 fogclr) {
- vec4 color = vec4(0.0);
- vec3 start = fragpos;
- vec3 rvector = normalize(reflect(normalize(fragpos), normalize(normal)));
- vec3 vector = Gstp * rvector;
- vec3 oldpos = fragpos;
- fragpos += vector;
- vec3 tvector = vector;
- int sr = 0;
- for(int i=0;i<30;i++){
- vec3 pos = nvec3(gbufferProjection * nvec4(fragpos)) * 0.5 + 0.5;
- if(pos.x < 0 || pos.x > 1 || pos.y < 0 || pos.y > 1 || pos.z < 0 || pos.z > 1.0) break;
- vec3 spos = vec3(pos.st, texture2D(depthtex1, pos.st).r);
- spos = nvec3(gbufferProjectionInverse * nvec4(spos * 2.0 - 1.0));
- float err = distance(fragpos.xyz,spos.xyz);
- if(err < pow(length(vector)*1.8,1.15)){
- sr++;
- if(sr >= maxf){
- float border = clamp(1.0 - pow(cdist(pos.st), 20.0), 0.0, 1.0);
- color = texture2D(composite, pos.st,0);
- float land = texture2D(gaux1, pos.st).g;
- land = float(land < 0.03);
- spos.z = mix(spos.z,2000.0*(0.25+sunVisibility*0.75),land);
- if (land > 0.0) color.rgb = skyGradient(spos,pow(color.rgb,vec3(2.2))*MAX_COLOR_RANGE,fogclr);
- else color.rgb = vec3(calcFog)(spos,pow(color.rgb,vec3(2.2))*MAX_COLOR_RANGE,fogclr);
- color.a = 1.0;
- color.a *= border;
- break;
- }
- tvector -=vector;
- vector *=Gref;
- }
- vector *= Ginc;
- oldpos = fragpos;
- tvector += vector;
- fragpos = start + tvector;
- }
- return color;
- }
- vec3 drawSun(vec3 fposition,vec3 color,int land) {
- vec3 sVector = normalize(fposition);
- float sun = max(pow(clamp(dot(sVector,normalize(sunPosition))+0.002,0.0,1.0),750.0)-0.002,0.0)*land*(1-rainStrength*0.75)*sunVisibility*20;
- vec3 sunlight = mix(sunlight,vec3(0.25,0.3,0.4)*length(ambient_color),rainStrength*0.8);
- return mix(color,sunlight*30.0,sun);
- }
- vec4 raytrace(vec3 fragpos, vec3 normal) {
- float mult = clamp(texture2D(noisetex, vec2(frameTimeCounter / 10.0)).x,0.8,1.9);
- vec4 color = vec4(0.0);
- vec3 start = fragpos;
- vec3 rvector = normalize(reflect(normalize(fragpos), normalize(normal)));
- vec3 vector = stp * rvector;
- vec3 oldpos = fragpos;
- fragpos += vector;
- vec3 tvector = vector;
- int sr = 0;
- for(int i=0;i<40;i++){
- vec3 pos = nvec3(gbufferProjection * nvec4(fragpos)) * 0.5 + 0.5;
- if(pos.x < 0 || pos.x > 1 || pos.y < 0 || pos.y > 1 || pos.z < 0 || pos.z > 1.0) break;
- vec3 spos = vec3(pos.st, texture2D(depthtex1, pos.st).r);
- spos = nvec3(gbufferProjectionInverse * nvec4(spos * 2.0 - 1.0));
- float err = abs(fragpos.z-spos.z);
- if(err < pow(length(vector)*1.85,1.15)){
- sr++;
- if(sr >= maxf){
- float border = clamp(1.0 - pow(cdist(pos.st), 20.0), 0.0, 1.0);
- color = texture2D(composite, pos.st);
- color.rgb = calcFog(spos,pow(color.rgb,vec3(2.2))*MAX_COLOR_RANGE);
- color.a = 1.0;
- color.a *= border;
- break;
- }
- tvector -=vector;
- vector *=ref;
- }
- vector *= inc;
- oldpos = fragpos;
- tvector += vector;
- fragpos = start + tvector;
- }
- return color;
- }
- vec3 drawCloud(vec3 fposition,vec3 color) {
- vec3 sVector = normalize(fposition);
- float cosT = dot(sVector,upVec);
- float McosY = dot(moonVec,sVector);
- float cosY = dot(sunVec,sVector);
- float MY = acos(McosY);
- //cloud generation
- /*----------*/
- float mult = texture2D(noisetex, vec2(frameTimeCounter / 10.0)).x;
- vec3 tpos = vec3(gbufferModelViewInverse * vec4(fposition,1.0))*mult;
- vec3 wvec = normalize(tpos);
- vec3 wVector = normalize(tpos);
- vec3 intersection = wVector*(0.0/(wVector.y)) + wVector*(wVector.y*0)*mult;
- float canHit = length(intersection)-length(tpos);
- vec2 wind = vec2(frameTimeCounter*(cos(frameTimeCounter/100.0)+0.5),frameTimeCounter*(sin(frameTimeCounter/100.0)+0.5))*mult;
- vec3 wpos = tpos.xyz+cameraPosition;
- vec2 coord = (intersection.xz+ 2.0*cosT*intersection.xz+wind)/512.0*mult;
- float noise = texture2D(noisetex,fract(coord.xy/2.0)).x*mult;
- float coverageVariance = (sin(-intersection.x*0.015+frameTimeCounter*0.1)+cos(intersection.z*0.01-frameTimeCounter*0.04))*(1+sin(frameTimeCounter*0.008))*0.5*mult+(10-rainStrength);
- vec2 tc = vec2(cos(coord.x*0.25-frameTimeCounter*0.003),cos(coord.y*0.25+frameTimeCounter*0.003));
- coverageVariance = (texture2D(noisetex,tc).x*2.0-1.0)*0.1*mult;
- float cl = max(noise-1.02-coverageVariance+rainStrength*0.7,0.0)*mult;
- float cloud = pow((1.0 - (pow(0.2-rainStrength*0.19,cl)))*max(cosT,0.0),2.2)*mult;
- float N = 8.0;
- vec3 cloud_color = moonlight*4.0*moonVisibility*(1-rainStrength*0.9) + sunlight*4.0*sunVisibility*(1-rainStrength*0.9) + ambient_color*5.0 + sunlight*24.0*pow(max(cosY,0.0),N)*(N+1)/6.28 * (1-cloud) * (1-rainStrength)*sunVisibility + moonlight*48.0*pow(max(McosY,0.0),N)*(N+1)/6.28 * (cloud*0.5+0.5) * (1-rainStrength)*moonVisibility ; //coloring clouds
- /*----------*/
- return mix(color,cloud_color*2.0,cloud); //mix up sky color and clouds
- //return cloud*cloud_color;
- }
- float convertVec3ToFloat(in vec3 invec){
- float mixing;
- mixing += invec.x;
- mixing += invec.y;
- mixing += invec.z;
- mixing /= 3.0;
- return mixing;
- }
- vec4 worldposition = vec4(0.0);
- vec4 raytraceGround(vec3 fragpos, vec3 normal) {
- vec4 color = vec4(0.0);
- vec3 start = fragpos;
- vec3 rvector = normalize(reflect(normalize(fragpos), normalize(normal)));
- vec3 vector = Gstp * rvector;
- vec3 oldpos = fragpos;
- fragpos += vector;
- vec3 tvector = vector;
- int sr = 0;
- for(int i=0;i<30;i++){
- vec3 pos = nvec3(gbufferProjection * nvec4(fragpos)) * 0.5 + 0.5;
- if(pos.x < 0 || pos.x > 1 || pos.y < 0 || pos.y > 1 || pos.z < 0 || pos.z > 1.0) break;
- vec3 spos = vec3(pos.st, texture2D(depthtex1, pos.st).r);
- spos = nvec3(gbufferProjectionInverse * nvec4(spos * 2.0 - 1.0));
- float err = distance(fragpos.xyz,spos.xyz);
- if(err < length(vector)){
- sr++;
- if(sr >= maxf){
- float border = clamp(1.0 - pow(cdist(pos.st), 20.0), 0.0, 1.0);
- color = texture2D(composite, pos.st);
- color.rgb = calcFog(spos,pow(color.rgb,vec3(2.2))*MAX_COLOR_RANGE);
- color.a = 1.0;
- color.a *= border;
- break;
- }
- tvector -=vector;
- vector *=Gref;
- }
- vector *= Ginc;
- oldpos = fragpos;
- tvector += vector;
- fragpos = start + tvector;
- }
- return color;
- }
- vec3 waterCaustic(vec3 fposition,vec3 color) {
- vec2 movement = vec2(abs(frameTimeCounter/1000.-0.5),abs(frameTimeCounter/1000.-0.5));
- vec2 movement2 = vec2(abs(frameTimeCounter/1000.-0.5),-abs(frameTimeCounter/1000.-0.5));
- vec2 movement3 = vec2(-abs(frameTimeCounter/1000.-0.5),abs(frameTimeCounter/1000.-0.5));
- vec2 movement4 = vec2(-abs(frameTimeCounter/1000.-0.5),-abs(frameTimeCounter/1000.-0.5));
- vec3 underwaterpos = vec3(texcoord.st, texture2D(depthtex1, texcoord.st).r);
- underwaterpos = nvec3(gbufferProjectionInverse * nvec4(underwaterpos * 2.0 - 1.0));
- vec4 worldpositionuw = gbufferModelViewInverse * vec4(underwaterpos,1.0);
- vec3 wpos = (worldpositionuw.xyz + cameraPosition.xyz);
- vec2 coord = (wpos.xz/(270*UnderwaterWaterCausticsSize))+(movement*(4*UnderwaterWaterCausticsSpeed));
- vec2 coord1 = (wpos.xz/(269.9*UnderwaterWaterCausticsSize))+(movement2*(4*UnderwaterWaterCausticsSpeed));
- vec2 coord2 = (wpos.xz/(269.8*UnderwaterWaterCausticsSize))+(movement3*(4*UnderwaterWaterCausticsSpeed));
- vec2 coord3 = (wpos.xz/(269.7*UnderwaterWaterCausticsSize))+(movement4*(4*UnderwaterWaterCausticsSpeed));
- float noise = texture2D(noisetex,fract(coord.xy/2.0)).x/2.0;
- noise += texture2D(noisetex,fract(coord2.xy/2.0)).x/2.0;
- noise += texture2D(noisetex,fract(coord3.xy/2.0)).x/2.0;
- noise += texture2D(noisetex,fract(coord.xy/2.0)).x/2.0;
- noise += texture2D(noisetex,fract(coord.xy)).x/2.0;
- noise += texture2D(noisetex,fract(coord2.xy)).x/2.0;
- noise += texture2D(noisetex,fract(coord3.xy)).x/2.0;
- noise += texture2D(noisetex,fract(coord.xy)).x/2.0;
- float noise2 = texture2D(noisetex,fract(coord.xy/2.0+0.01)).x/2.0;
- noise2 += texture2D(noisetex,fract(coord2.xy/2.0+0.01)).x/2.0;
- noise2 += texture2D(noisetex,fract(coord3.xy/2.0+0.01)).x/2.0;
- noise2 += texture2D(noisetex,fract(coord.xy/2.0+0.01)).x/2.0;
- noise2 += texture2D(noisetex,fract(coord.xy+0.01)).x/2.0;
- noise2 += texture2D(noisetex,fract(coord2.xy+0.01)).x/2.0;
- noise2 += texture2D(noisetex,fract(coord3.xy+0.01)).x/2.0;
- noise2 += texture2D(noisetex,fract(coord.xy+0.01)).x/2.0;
- float causticstrength = (max(abs(noise-1.95),0.0)+max(abs(noise2-1.95),0.0));
- float wca = (0.1/UnderwaterWaterCausticsStrength);
- float caustic = (1.0 - (pow(wca,causticstrength)));
- vec3 caustic_color = color*(10.0-(0.7-moonVisibility*0.4))*(0.1*moonVisibility); //coloring caustics
- vec3 wc = mix(color,caustic_color,caustic);
- return wc;
- }
- float distx(float dist){
- float d = ((far * (dist - near)) / (dist * (far - near)));
- return d;
- }
- float getnoise2(vec2 pos) {
- return mod((dot(pos.xy, vec2(18.9898f,28.633f)) * 4378.5453f), 1.0);
- }
- #ifdef VolumeLight
- vec3 vlColor(vec3 fogcolor,in vec3 color, in vec2 pos) {
- float VolumeSample = texture2D(gdepth, pos.xy, 3.0).r;
- float iN = (VolumeLightMultiplierNight*moonVisibility);
- float iD = (VolumeLightMultiplierDay*TimeNoon);
- float iSSSR = (VolumeLightMultiplierSunsetSunrise*(1-TimeNoon)*(1-moonVisibility));
- float i = (iN + iD + iSSSR);
- float eBS = mix(1.0,0.0,(pow(eyeBrightnessSmooth.y / 240.0f, 1.0f)));
- float Glow = pow(max(dot(normalize(fragpos),lightVector),0.0),2.5*15);
- float vlGlow = (1-Glow*-(2.5*(1-TimeNoon*-5)*(1+(TimeSunrise + TimeSunset)*15.)*(1-eBS))) * 0.5;
- float vlInside = ((eBS*10.0*VL_STRENGTH_INSIDE*(1-moonVisibility)));
- float vlInsideNight = ((eBS*10.0*VL_STRENGTH_INSIDE*(moonVisibility)));
- float vlFinalInside = (vlInside + vlInsideNight);
- vec3 vlDay = vec3(10.0,10.0,10.0)/50*VolumeLightMultiplierDay;
- vec3 vlNight = vec3(10.0,10.0,10.0)/50 * VolumeLightMultiplierNight;
- vec3 vlSSSR = vec3(10.0,10.0,10.0)/50*(VolumeLightMultiplierSunsetSunrise * (1 - TimeNoon) * (1 - moonVisibility));
- vec3 combined = (vlDay + vlNight + vlSSSR);
- vec3 vlcolor = combined;
- vlcolor = mix(vlcolor,pow(vlcolor,vec3(1.5)) * 2.2,(TimeSunrise + TimeSunset));
- vlcolor *= (1 + (vlFinalInside));
- vlcolor *= (1 + (vlGlow));
- vlcolor = mix(color, vlcolor, VolumeSample / 5.0 * VolumeLightMultiplier * (1-isEyeInWater) * (1-rainx) * transition_fading);
- return vlcolor;
- }
- #endif
- //////////////////////////////VOID MAIN//////////////////////////////
- //////////////////////////////VOID MAIN//////////////////////////////
- //////////////////////////////VOID MAIN//////////////////////////////
- //////////////////////////////VOID MAIN//////////////////////////////
- //////////////////////////////VOID MAIN//////////////////////////////
- void main() {
- color.rgb = pow(color.rgb,vec3(2.2))*MAX_COLOR_RANGE;
- int land = int(matflag < 0.03);
- int iswater = int(matflag > 0.04 && matflag < 0.07);
- int hand = int(matflag > 0.75 && matflag < 0.85);
- fragpos = nvec3(gbufferProjectionInverse * nvec4(fragpos * 2.0 - 1.0));
- float depth = getWaterDepth();
- float depthMap = clamp(exp(-depth / 2.5),0.0,1.0);
- if (iswater > 0.9)color.rgb = mix(color.rgb,getSkyColor(fragpos.rgb)/954,1-depthMap);
- color.rgb = drawSun(fragpos,color.rgb,land);
- #ifdef UnderwaterWaterCaustics
- if (isEyeInWater > 0.9)
- color.rgb += waterCaustic(fragpos, color.rgb)*(depthMap)*1.65;
- else
- color.rgb += waterCaustic(fragpos, color.rgb)*(depthMap)*1.65*iswater;
- #endif
- float fresnel_pow = 5.0;
- float normalDotEye = dot(normal, normalize(fragpos));
- float fresnel = clamp(pow(1.0 + normalDotEye, fresnel_pow),0.0,1.0);
- float fmult = 0.95;
- fresnel = fresnel*fmult + (1-fmult);
- vec4 reflection = vec4(0.0);
- vec3 lc = mix(vec3(0.0),sunlight,sunVisibility);
- if (iswater > 0.9) {
- //compute skybox at reflected position
- vec3 npos = normalize(fragpos);
- vec3 reflectedVector = reflect(normalize(fragpos), normalize(normal));
- reflectedVector = fragpos + reflectedVector * (far-fragpos.z);
- vec3 sky_color = calcFog(reflectedVector,drawCloud(reflectedVector,getSkyColor(reflectedVector)))*clamp(sky_lightmap*2.0-2/16.0,0.0,1.0);
- reflection = raytrace(fragpos, normal);
- reflection.rgb = mix(sky_color, reflection.rgb, reflection.a)*0.75+(color.a*50)*lc*(1.0-rainStrength)*48.0; //fake sky reflection, avoid empty spaces
- reflection.a = min(reflection.a,1.0);
- color.rgb = reflection.rgb*WaterReflectionStrength *fresnel + (1-fresnel)*color.rgb;
- }
- if (land < 0.9 && hand < 0.1) {
- vec3 npos = normalize(fragpos);
- vec3 reflectedVector = reflect(normalize(fragpos), normalize(normal));
- reflectedVector = fragpos + reflectedVector * (far-length(fragpos));
- vec3 sky_color = calcFog(reflectedVector,drawCloud(reflectedVector,getSkyColor(reflectedVector)))*clamp(sky_lightmap*2.0-2/16.0,0.0,1.0);
- #ifdef Specular
- if (specmap*fresnel > 0.005) reflection = raytraceGround(fragpos, normal, sky_color);
- reflection.rgb = mix(sky_color, reflection.rgb, reflection.a)+(color.a)*lc*(1.0-rainStrength)*24.;
- reflection.rgb = mix(reflection.rgb,reflection.rgb*normalize(color.rgb),0.0);
- reflection.rgb = reflection.rgb*3.;
- color.rgb = specmap*fresnel*reflection.rgb + (1-fresnel*specmap)*color.rgb;;
- #endif
- }
- /*
- vec3 npos = normalize(fragpos);
- vec3 reflectedVector = reflect(normalize(fragpos), normalize(normal));
- reflectedVector = fragpos + reflectedVector * (far-length(fragpos));
- vec3 sky_color = calcFog(reflectedVector,drawCloud(reflectedVector,getSkyColor(reflectedVector)))*clamp(sky_lightmap*2.0-2/16.0,0.0,1.0);
- reflection = raytraceGround(fragpos, normal);
- reflection.rgb = mix(sky_color, reflection.rgb, reflection.a)* WaterReflectionStrength + (color.a)*pow(lc,vec3(1/2.2))*(1.0-rainStrength)*256.0; //fake sky reflection, avoid empty spaces
- //reflection.rgb = mix(reflection.rgb,reflection.rgb*normalize(color.rgb),0.5);
- reflection.a = min(reflection.a,1.0);
- reflection.rgb = reflection.rgb;
- color.rgb = reflection.rgb;
- */
- //color.rgb += fresnel*torchcolor*torch_lightmap*specmap;
- vec3 colmult = mix(vec3(1.0),vec3(0.1,0.25,0.45),isEyeInWater);
- float depth_diff = clamp(pow(ld(texture2D(depthtex1, texcoord.st).r)*3.4,2.0),0.0,1.0);
- color.rgb = mix(color.rgb*colmult,vec3(0.05,0.1,0.15),depth_diff*isEyeInWater);
- color.rgb = calcFog(fragpos.xyz,color.rgb);
- float transition_fading = 1.0-(clamp((time-12000.0)/300.0,0.0,1.0)-clamp((time-13500.0)/300.0,0.0,1.0) + clamp((time-22500.0)/300.0,0.0,1.0)-clamp((time-23400.0)/300.0,0.0,1.0)); //fading between sun/moon shadows
- /* DRAWBUFFERS:5 */
- //draw rain
- //color.rgb = texture2D(gaux4,texcoord.xy).rgb*texture2D(gaux4,texcoord.xy).a;
- vec4 tpos = vec4(sunPosition,1.0)*gbufferProjection;
- tpos = vec4(tpos.xyz/tpos.w,1.0);
- vec2 pos1 = tpos.xy/tpos.z;
- vec2 lightPos = pos1*0.5+0.5;
- float gr = 0.0;
- float visiblesun = 0.0;
- float temp;
- float nb = 0;
- //calculate sun occlusion (only on one pixel)
- if (texcoord.x < pw && texcoord.x < ph) {
- for (int i = 0; i < 15;i++) {
- for (int j = 0; j < 15 ;j++) {
- temp = texture2D(gaux1,clamp(lightPos + vec2(pw*(i-7.0),ph*(j-7.0))*15.0,0.0001,0.9999)).g;
- visiblesun += 1.0-float(temp > 0.01) ;
- nb += 1.0;
- }
- }
- visiblesun /= nb;
- }
- #ifdef VolumeLight
- color.rgb = vec3(vlColor(vec3(fogclr), color.rgb, texcoord.st));
- #endif
- /*
- if (texcoord.x > 1.0-pw && texcoord.x > 1.0-ph) {
- float avglum = 0.0;
- for (int i = 0; i < 5;i++) {
- for (int j = 0; j < 5 ;j++) {
- float distFallof = 1.0-sqrt(max(i*1.0,j*1.0)+1.0f)/9.0;
- avglum += luma(texture2D(composite,vec2(0.5) + vec2(pw*(i-2.0),ph*(j-2.0))*vec2(1.0,aspectRatio)*150.0).rgb);
- nb += distFallof;
- }
- }
- visiblesun = avglum/nb;
- }
- if (isEyeInWater < 0.9) color.rgb += (reflect*0.2)*iswet;
- */
- color.rgb = clamp(pow(color.rgb/MAX_COLOR_RANGE,vec3(1.0/2.2)),0.0,1.0);
- gl_FragData[0] = vec4(color.rgb,visiblesun*float(sign(sunPosition.z)<0.0));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement