INTERNAL REWORK. testers are needed.

This commit is contained in:
Xonk
2023-10-07 22:18:20 -04:00
parent 4d8a5105ed
commit a2fc114c4f
236 changed files with 5437 additions and 10283 deletions

View File

@ -0,0 +1,3 @@
#if Cumulus_coverage == 1.0
variable.float.VariableCoverage = 1.0
#endif

View File

@ -122,7 +122,7 @@ float calculate_maximum_horizon_angle(
for (int i = 0; i < GTAO_HORIZON_STEPS; ++i, ray_pos += ray_step) {
float depth = texelFetch(depthtex1, ivec2(clamp(ray_pos,0.0,1.0) * view_res * taau_render_scale - 0.5), 0).x;
float depth = texelFetch2D(depthtex1, ivec2(clamp(ray_pos,0.0,1.0) * view_res * taau_render_scale - 0.5), 0).x;
if (depth == 1.0 || depth < hand_depth || depth == screen_pos.z) continue;
@ -142,9 +142,8 @@ float calculate_maximum_horizon_angle(
return fast_acos(clamp(max_cos_theta, -1.0, 1.0));
}
float ambient_occlusion(vec3 screen_pos, vec3 view_pos, vec3 view_normal, vec2 dither , inout vec3 debug) {
float ambient_occlusion(vec3 screen_pos, vec3 view_pos, vec3 view_normal, vec2 dither) {
float ao = 0.0;
vec3 bent_normal = vec3(0.0);
// Construct local working space
vec3 viewer_dir = normalize(-view_pos);
@ -176,11 +175,9 @@ float ambient_occlusion(vec3 screen_pos, vec3 view_pos, vec3 view_normal, vec2 d
max_horizon_angles = gamma + clamp(vec2(-1.0, 1.0) * max_horizon_angles - gamma, -half_pi, half_pi) ;
vec3 max_horizon_angles2 = mat3(gbufferModelViewInverse) * projected_normal;
ao += integrate_arc(max_horizon_angles, gamma, cos_gamma) * len_sq * norm * max_horizon_angles.y ;
ao += integrate_arc(max_horizon_angles, gamma, cos_gamma) * len_sq * norm ;
}
ao *= rcp(float(GTAO_SLICES));
return ao;
return ao*(ao*0.5+0.5);
}

View File

@ -95,19 +95,19 @@ vec3 sky_transmittance(vec3 position, vec3 direction, const float steps) {
vec3 calculateAtmosphere(vec3 background, vec3 viewVector, vec3 upVector, vec3 sunVector, vec3 moonVector, out vec2 pid, out vec3 transmittance, const int iSteps, float noise) {
const int jSteps = 4;
vec3 viewPosition = (sky_planetRadius + eyeAltitude) * upVector;
vec3 viewPos = (sky_planetRadius + eyeAltitude) * upVector;
vec2 aid = rsi(viewPosition, viewVector, sky_atmosphereRadius);
vec2 aid = rsi(viewPos, viewVector, sky_atmosphereRadius);
if (aid.y < 0.0) {transmittance = vec3(1.0); return vec3(0.0);}
pid = rsi(viewPosition, viewVector, sky_planetRadius * 0.998);
pid = rsi(viewPos, viewVector, sky_planetRadius * 0.998);
bool planetIntersected = pid.y >= 0.0;
vec2 sd = vec2((planetIntersected && pid.x < 0.0) ? pid.y : max(aid.x, 0.0), (planetIntersected && pid.x > 0.0) ? pid.x : aid.y);
float stepSize = (sd.y - sd.x) * (1.0 / iSteps);
vec3 increment = viewVector * stepSize;
vec3 position = viewVector * sd.x + viewPosition;
vec3 position = viewVector * sd.x + viewPos;
position += increment * (0.34*noise);
vec2 phaseSun = sky_phase(dot(viewVector, sunVector ), 0.8);

View File

@ -1,4 +1,3 @@
const float k = 1.8;
const float d0 = 0.04;
const float d1 = 0.61;
@ -12,8 +11,63 @@ vec4 BiasShadowProjection(in vec4 projectedShadowSpacePosition) {
return projectedShadowSpacePosition;
}
float calcDistort(vec2 worldpos){
return 1.0/(log(length(worldpos)*b+a)*k);
}
uniform float far;
/*
mat4 BuildOrthoProjectionMatrix(const in float width, const in float height, const in float zNear, const in float zFar) {
return mat4(
vec4(2.0 / width, 0.0, 0.0, 0.0),
vec4(0.0, 2.0 / height, 0.0, 0.0),
vec4(0.0, 0.0, -2.0 / (zFar - zNear), 0.0),
vec4(0.0, 0.0, -(zFar + zNear)/(zFar - zNear), 1.0));
}
mat4 BuildTranslationMatrix(const in vec3 delta) {
return mat4(
vec4(1.0, 0.0, 0.0, 0.0),
vec4(0.0, 1.0, 0.0, 0.0),
vec4(0.0, 0.0, 1.0, 0.0),
vec4(delta, 1.0));
}
vec3 LightDir = vec3(0.0, 1.0, 0.0);
// vec3 LightDir = vec3(sin(frameTimeCounter*10), 0.2, -cos(frameTimeCounter*10));
uniform vec3 CamPos;
const float shadowIntervalSize = 2.0f;
vec3 GetShadowIntervalOffset() {
return fract(CamPos / shadowIntervalSize) * shadowIntervalSize - vec3(3,0,1);
}
mat4 BuildShadowViewMatrix(const in vec3 localLightDir) {
//#ifndef WORLD_END
// return shadowModelView;
//#else
const vec3 worldUp = vec3(0, 0, -1);
vec3 zaxis = localLightDir;
vec3 xaxis = normalize(cross(worldUp, zaxis));
vec3 yaxis = normalize(cross(zaxis, xaxis));
mat4 shadowModelViewEx = mat4(1.0);
shadowModelViewEx[0].xyz = vec3(xaxis.x, yaxis.x, zaxis.x);
shadowModelViewEx[1].xyz = vec3(xaxis.y, yaxis.y, zaxis.y);
shadowModelViewEx[2].xyz = vec3(xaxis.z, yaxis.z, zaxis.z);
vec3 intervalOffset = GetShadowIntervalOffset();
mat4 translation = BuildTranslationMatrix(intervalOffset);
return shadowModelViewEx * translation ;
//#endif
}
mat4 BuildShadowProjectionMatrix() {
float maxDist = min(shadowDistance, far);
return BuildOrthoProjectionMatrix(maxDist, maxDist, -far, far);
}
*/

23
shaders/lib/Shadows.glsl Normal file
View File

@ -0,0 +1,23 @@
// Emin's and Gri's combined ideas to stop peter panning and light leaking, also has little shadowacne so thats nice
// https://www.complementary.dev/reimagined
// https://github.com/gri573
void GriAndEminShadowFix(
inout vec3 WorldPos,
vec3 FlatNormal,
float VanillaAO,
float SkyLightmap,
bool Entities
){
float DistanceOffset = clamp(0.17 + length(WorldPos) / (shadowMapResolution*0.20), 0.0,1.0) ;
vec3 Bias = FlatNormal * DistanceOffset; // adjust the bias thingy's strength as it gets farther away.
vec3 finalBias = Bias;
// stop lightleaking
vec2 scale = vec2(0.5); scale.y *= 0.5;
vec3 zoomShadow = scale.y - scale.x * fract(WorldPos + cameraPosition + Bias*scale.y);
if(SkyLightmap < 0.1 && !Entities) finalBias = mix(Bias, zoomShadow, clamp(VanillaAO*5,0,1));
WorldPos += finalBias;
}

View File

@ -144,45 +144,64 @@
///////////////////////////// BIOME SPECIFICS /////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
#ifdef Biome_specific_environment
uniform float nightVision;
uniform float isJungles;
uniform float isSwamps;
// uniform float isLush;
// uniform float isDeserts;
uniform float isDarkForests;
uniform float sandStorm;
uniform float snowStorm;
#ifdef PER_BIOME_ENVIRONMENT
void BiomeFogColor(
inout vec3 FinalFogColor
){
){
// this is a little complicated? lmao
vec3 BiomeColors;
BiomeColors.r = isSwamps*0.7 + isJungles*0.5 + sandStorm*1.0 + snowStorm*0.5;
BiomeColors.g = isSwamps*1.0 + isJungles*1.0 + sandStorm*0.5 + snowStorm*0.6;
BiomeColors.b = isSwamps*0.35 + isJungles*0.8 + sandStorm*0.3 + snowStorm*1.0;
vec3 BiomeColors = vec3(0.0);
BiomeColors.r = isSwamps*SWAMP_R + isJungles*JUNGLE_R + isDarkForests*DARKFOREST_R + sandStorm*1.0 + snowStorm*0.6;
BiomeColors.g = isSwamps*SWAMP_G + isJungles*JUNGLE_G + isDarkForests*DARKFOREST_G + sandStorm*0.5 + snowStorm*0.8;
BiomeColors.b = isSwamps*SWAMP_B + isJungles*JUNGLE_B + isDarkForests*DARKFOREST_B + sandStorm*0.3 + snowStorm*1.0;
// insure the biome colors are locked to the fog shape and lighting, but not its orignal color.
BiomeColors *= dot(FinalFogColor,vec3(0.33333));
BiomeColors *= max(dot(FinalFogColor,vec3(0.33333)), MIN_LIGHT_AMOUNT*0.025 + nightVision*0.2);
// these range 0.0-1.0. they will never overlap.
float Inbiome = isJungles+isSwamps+sandStorm;
float Inbiome = isJungles+isSwamps+isDarkForests+sandStorm+snowStorm;
// interpoloate between normal fog colors and biome colors. the transition speeds are conrolled by the biome uniforms.
FinalFogColor = mix(FinalFogColor, BiomeColors, Inbiome);
}
void BiomeSunlightColor(
inout vec3 FinalSunlightColor
){
// this is a little complicated? lmao
vec3 BiomeColors = vec3(0.0);
BiomeColors.r = isSwamps*SWAMP_R + isJungles*JUNGLE_R + isDarkForests*DARKFOREST_R + sandStorm*1.0 + snowStorm*0.6;
BiomeColors.g = isSwamps*SWAMP_G + isJungles*JUNGLE_G + isDarkForests*DARKFOREST_G + sandStorm*0.5 + snowStorm*0.8;
BiomeColors.b = isSwamps*SWAMP_B + isJungles*JUNGLE_B + isDarkForests*DARKFOREST_B + sandStorm*0.3 + snowStorm*1.0;
// these range 0.0-1.0. they will never overlap.
float Inbiome = isJungles+isSwamps+isDarkForests+sandStorm+snowStorm;
// interpoloate between normal fog colors and biome colors. the transition speeds are conrolled by the biome uniforms.
FinalSunlightColor = mix(FinalSunlightColor, FinalSunlightColor * (BiomeColors*0.8+0.2), Inbiome);
}
void BiomeFogDensity(
inout vec4 UniformDensity,
inout vec4 CloudyDensity
){
// these range 0.0-1.0. they will never overlap.
float Inbiome = isJungles+isSwamps+sandStorm+snowStorm;
vec2 BiomeFogDensity; // x = uniform || y = cloudy
BiomeFogDensity.x = isSwamps*1 + isJungles*5 + sandStorm*15 + snowStorm*15;
BiomeFogDensity.y = isSwamps*5 + isJungles*2 + sandStorm*255 + snowStorm*100;
float Inbiome = isJungles+isSwamps+isDarkForests+sandStorm+snowStorm;
vec2 BiomeFogDensity = vec2(0.0); // x = uniform || y = cloudy
BiomeFogDensity.x = isSwamps*SWAMP_UNIFORM_DENSITY + isJungles*JUNGLE_UNIFORM_DENSITY + isDarkForests*DARKFOREST_UNIFORM_DENSITY + sandStorm*15 + snowStorm*150;
BiomeFogDensity.y = isSwamps*SWAMP_CLOUDY_DENSITY + isJungles*JUNGLE_CLOUDY_DENSITY + isDarkForests*DARKFOREST_CLOUDY_DENSITY + sandStorm*255 + snowStorm*255;
UniformDensity = mix(UniformDensity, vec4(BiomeFogDensity.x), Inbiome);
CloudyDensity = mix(CloudyDensity, vec4(BiomeFogDensity.y), Inbiome);
}
@ -196,7 +215,7 @@
// uniform int worldTime;
void TimeOfDayFog(inout float Uniform, inout float Cloudy) {
float Time = (worldTime%24000)*1.0;
float Time = worldTime%24000;
// set schedules for fog to appear at specific ranges of time in the day.
float Morning = clamp((Time-22000)/2000,0,1) + clamp((2000-Time)/2000,0,1);
@ -213,7 +232,7 @@
DailyWeather_FogDensity(UniformDensity, CloudyDensity); // let daily weather influence fog densities.
#endif
#ifdef Biome_specific_environment
#ifdef PER_BIOME_ENVIRONMENT
BiomeFogDensity(UniformDensity, CloudyDensity); // let biome fog hijack to control densities, and overrride any other density controller...
#endif

View File

@ -1,10 +1,10 @@
vec3 cloud2D(vec3 fragpos,vec3 col){
vec3 wpos = fragpos;
vec3 cloud2D(vec3 viewPos,vec3 col){
vec3 wpos = viewPos;
float wind = frameTimeCounter/200.;
vec2 intersection = ((2000.0-cameraPosition.y)*wpos.xz*inversesqrt(wpos.y+cameraPosition.y/512.-50./512.) + cameraPosition.xz+wind)/40000.;
float phase = pow(clamp(dot(fragpos,sunVec),0.,1.),2.)*0.5+0.5;
float phase = pow(clamp(dot(viewPos,sunVec),0.,1.),2.)*0.5+0.5;
float fbm = clamp((texture2D(noisetex,intersection*vec2(1.,1.5)).a + texture2D(noisetex,intersection*vec2(2.,7.)+wind*0.4).a/2.)-0.5*(1.0-rainStrength),0.,1.) ;

View File

@ -1,6 +1,6 @@
// in this here file im doing all the lighting for sunlight, ambient light, torches, for solids and translucents.
uniform float nightVision;
// uniform float nightVision;
void DoRTAmbientLighting (vec3 TorchColor, vec2 Lightmap, inout float SkyLM, inout vec3 TorchLight, inout vec3 SkyLight){
@ -66,13 +66,14 @@ void DoRTAmbientLighting (vec3 TorchColor, vec2 Lightmap, inout float SkyLM, ino
TorchLight *= TORCH_AMOUNT;
FogColor = (FogColor / pow(0.00001 + dot(FogColor,vec3(0.3333)),1.0) ) * 0.1;
FogColor = FogColor / max(dot(FogColor,vec3(0.3333)),0.05);
vec3 FogTint = FogColor*clamp(1.1 + dot(Normal,np3),0.0,1.0) * 0.05;
vec3 FogTint = FogColor*clamp(1.1 + dot(Normal,np3),0.0,1.0) * 0.1;
vec3 AmbientLight = max(vec3(0.5,0.75,1.0) * 0.05, (MIN_LIGHT_AMOUNT*0.01 + nightVision*0.5) );
vec3 AmbientLight = max(vec3(0.5,0.75,1.0)* 0.1, (MIN_LIGHT_AMOUNT*0.01 + nightVision*0.5) );
return TorchLight + AmbientLight + FogTint;
return TorchLight + AmbientLight;// + AmbientLight + FogTint;
}
#endif

View File

@ -1,63 +1,91 @@
vec3 srgbToLinear2(vec3 srgb){
return mix(
srgb / 12.92,
pow(.947867 * srgb + .0521327, vec3(2.4) ),
step( .04045, srgb )
);
}
vec3 blackbody2(float Temp)
{
float t = pow(Temp, -1.5);
float lt = log(Temp);
// Hash without Sine
// MIT License...
/* Copyright (c)2014 David Hoskins.
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;
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
return srgbToLinear2(col);
}
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
//----------------------------------------------------------------------------------------
vec3 hash31(float p)
{
vec3 p3 = fract(vec3(p) * vec3(.1031, .1030, .0973));
p3 += dot(p3, p3.yzx+33.33);
return fract((p3.xxy+p3.yzz)*p3.zyx);
}
float hash11(float p)
{
p = fract(p * .1031);
p *= p + 33.33;
p *= p + p;
return fract(p);
}
//----------------------------------------------------------------------------------------
// Integer Hash - II
// - Inigo Quilez, Integer Hash - II, 2017
// https://www.shadertoy.com/view/XlXcW4
uvec3 iqint2(uvec3 x)
{
const uint k = 1103515245u;
//----------------------------------------------------------------------------------------
x = ((x>>8U)^x.yzx)*k;
x = ((x>>8U)^x.yzx)*k;
x = ((x>>8U)^x.yzx)*k;
uvec3 iqint2(uvec3 x)
{
const uint k = 1103515245u;
return x;
}
x = ((x>>8U)^x.yzx)*k;
x = ((x>>8U)^x.yzx)*k;
x = ((x>>8U)^x.yzx)*k;
uvec3 hash(vec2 s)
{
return x;
}
uvec4 u = uvec4(s, uint(s.x) ^ uint(s.y), uint(s.x) + uint(s.y)); // Play with different values for 3rd and 4th params. Some hashes are okay with constants, most aren't.
return iqint2(u.xyz);
}
vec3 hash31(float p)
{
vec3 p3 = fract(vec3(p) * vec3(.1031, .1030, .0973));
p3 += dot(p3, p3.yzx+33.33);
return fract((p3.xxy+p3.yzz)*p3.zyx);
}
uvec3 hash(vec2 s)
{
uvec4 u = uvec4(s, uint(s.x) ^ uint(s.y), uint(s.x) + uint(s.y)); // Play with different values for 3rd and 4th params. Some hashes are okay with constants, most aren't.
return iqint2(u.xyz);
}
///////////////// POSITION
///////////////// POSITION
///////////////// POSITION
//----------------------------------------------------------------------------------------
vec3 RandomPosition = hash31(frameTimeCounter);
// vec3 RandomPosition = hash31(frameTimeCounter);
vec3 ManualLightPos = vec3(ORB_X, ORB_Y, ORB_Z);
void LightSourcePosition(vec3 WorldPos, vec3 CameraPos, inout vec3 Pos1, inout vec3 Pos2){
Pos1 = WorldPos - vec3(0,200,0);
vec3 Origin = WorldPos - CameraPos - ManualLightPos;
float cellSize = 200;
vec3 cellPos = CameraPos ;
Origin += fract(cellPos/cellSize)*cellSize - cellSize*0.5;
// Origin -= vec3(sin(frameTimeCounter),0,-cos(frameTimeCounter)) * 20;
vec3 randomPos = texelFetch2D(colortex4,ivec2(2,1),0).xyz / 150.0;
Origin -= (randomPos * 2.0 - 1.0);
Pos2 = Origin;
}
float densityAtPosFog(in vec3 pos){
pos /= 18.;
pos.xz *= 0.5;
@ -72,264 +100,215 @@ float densityAtPosFog(in vec3 pos){
return mix(xy.r,xy.g, f.y);
}
vec3 LightSourcePosition(vec3 WorldPos, vec3 CameraPos){
vec3 Origin = WorldPos ;
// make the swirl only happen within a radius
float SwirlBounds = clamp(sqrt(length(vec3(Origin.x,Origin.y-100,Origin.z)) / 150.0 - 1.0) ,0.0,1.0);
// Create a rising swirl centered around some origin.
void SwirlAroundOrigin(inout vec3 alteredOrigin, vec3 origin){
if( SwirlBounds < 1.0) {
Origin.y -= 260;
} else {
Origin = WorldPos - CameraPos ;
#ifdef THE_ORB
if(ManualLightPos == vec3(0.0)){
#endif
float nosie = (densityAtPosFog(Origin / 30 + sin(frameTimeCounter/5)*100)-0.15) * 15 ;
Origin.xz += vec2( sin(nosie),-cos(nosie) )*50;
Origin.y -= sin(nosie)*100;
#ifdef THE_ORB
} else {
Origin -= ManualLightPos;
}
#endif
float cellSize = 100.0;
vec3 cellPos = CameraPos - vec3(0,10,0) ;
// cellPos += vec3(frameTimeCounter,0,0)*25.0;
Origin += (fract(cellPos/cellSize)*cellSize - cellSize*0.5);
}
return Origin;
}
///////////////// COLOR
///////////////// COLOR
///////////////// COLOR
vec3 LightSourceColor(float SwirlBounds){
vec3 Color = vec3(0.7, 0.8, 1.0);
#ifndef THE_ORB
if( SwirlBounds < 1.0) {
// Color = vec3(0.5, 0.5, 1.0);
} else {
// #ifdef THE_ORB
// Color = vec3(ORB_R, ORB_G, ORB_B) * ORB_ColMult;
// #endif
// Color *= blackbody2(RandomPosition.y*4000 + 1000);
float Timing = dot(RandomPosition, vec3(1.0/3.0));
float Flash = max(sin(frameTimeCounter) * cos(Timing) ,0.0);
Color *= Flash;
}
#else
Color = vec3(ORB_R, ORB_G, ORB_B) * ORB_ColMult;
#endif
return Color;
}
///////////////// SHAPE
///////////////// SHAPE
///////////////// SHAPE
vec3 LightSourceShape(vec3 WorldPos){
vec3 Shapes = vec3(0.0);
vec3 Origin = WorldPos ;
float radiance = 2.39996 + alteredOrigin.y/1.5 + frameTimeCounter/50;
mat2 rotationMatrix = mat2(vec2(cos(radiance), -sin(radiance)), vec2(sin(radiance), cos(radiance)));
// make the swirl only happen within a radius
float SwirlBounds = clamp(sqrt(length(Origin) / 200.0 - 1.0) ,0.0,1.0);
float SwirlBounds = clamp(sqrt(length(vec3(origin.x, origin.y-100,origin.z)) / 200.0 - 1.0) ,0.0,1.0);
alteredOrigin.xz = mix(alteredOrigin.xz * rotationMatrix, alteredOrigin.xz, SwirlBounds);
}
if( SwirlBounds < 1.0) {
// vec3 Origin = WorldPos;
Origin.y -= 200;
// control where the fog volume should and should not be using a sphere.
void VolumeBounds(inout float Volume, vec3 Origin){
vec3 Origin2 = Origin;
Origin2.y = (Origin2.y + 100.0) * 0.8;
vec3 Origin2 = (Origin - vec3(0,100,0));
Origin2.y *= 0.8;
float Center1 = length(Origin2);
float Center = length(Origin);
float AltCenter = length(Origin2);
// the max of a sphere is another smaller sphere. this creates a hollow sphere.
Shapes.r = max(1.0 - AltCenter / 75.0, max(AltCenter / 150.0 - 1.0, 0.0));
// donut to make the hurricane shape
float radius = 200.0;
float thickness = 25.0 * radius;
Shapes.r = (thickness - clamp( pow( length( vec2(length(Origin2.xz) - radius, Origin2.y*0.75) ),2.0) - radius, 0.0, thickness) ) / thickness;
Shapes.r = max(Shapes.r, max(1.0 - AltCenter / 75.0, 0.0));
float Bounds = max(1.0 - Center1 / 75.0, 0.0) * 5.0;
float radius = 150.0;
float thickness = 50.0 * radius;
float Torus = (thickness - clamp( pow( length( vec2(length(Origin.xz) - radius, Origin2.y) ),2.0) - radius, 0.0, thickness) ) / thickness;
Origin2.xz *= 0.3;
Origin2.y -= 100;
// debug donut
// radius = 50.0;
// thickness = 5.0 * radius;
// Shapes.b = (thickness - clamp( pow( length( vec2(length(Origin2.xy) - radius, Origin2.z*0.75) ),2.0) - radius, 0.0, thickness) ) / thickness;
}
float orb = clamp((1.0 - length(Origin2) / 15.0) * 1.5,0.0,1.0);
Volume = max(Volume - Bounds - Torus, orb);
}
return Shapes;
// create the volume shape
float cloudVol(in vec3 pos){
float Output = 0.0;
vec3 samplePos = pos*vec3(1.0,1./48.,1.0);
// swirly swirly :DDDDDDDDDDD
SwirlAroundOrigin(samplePos, pos);
float NoisePlane = texture2D(noisetex, samplePos.xz/1024 ).b;
float MainShape = clamp(max(0.5 - densityAtPosFog(samplePos * 16),0.0) * 2,0.0,1.0);
float Erosion = abs(0.6 - densityAtPosFog(samplePos * (160. - MainShape*50) - vec3(0,frameTimeCounter*3,0) ));
Output = MainShape;
Output = max(Output - Erosion*0.5,0.0);
// apply limts
VolumeBounds(Output, pos);
// Output = max(max(100 - pos.y,0.0) - NoisePlane * 50 ,0.0);
return Output;
}
float EndLightMie(vec3 LightPos){
float mie = exp(length(LightPos) / -150);
mie *= mie;
mie *= mie;
mie *= 100;
return mie;
}
void LightSourceColors(inout vec3 Color1, inout vec3 Color2){
Color1 = vec3(0.7,0.88,1.0);
Color2 = vec3(ORB_R,ORB_G,ORB_B);
}
vec3 LightSourceLighting( vec3 WorldPos, vec3 LightPos, float Dither, float VolumeDensity, vec3 LightColor, float Phase ){
float Mie = EndLightMie(LightPos);
float Shadow = 0.0;
for (int j=0; j < 3; j++){
vec3 shadowSamplePos = WorldPos - LightPos * (0.05 + j * (0.25 + Dither*0.15));
Shadow += cloudVol(shadowSamplePos);
}
vec3 FinalLighting = LightColor * Mie * exp(Shadow * -5.0) ;
FinalLighting += LightColor * exp2(-5 * max(2.5-Shadow,0.0) * vec3(1.2,1.0,0.8+VolumeDensity*0.4)) * (Mie*Mie) * clamp((1.0 - length(LightPos) / 100.0),0.0,1.0);
return FinalLighting;
}
float cloudVol(in vec3 pos, int LOD){
// THE OOOOOOOOOOOOOOOOOOOOOORB
vec3 Shapes = LightSourceShape(pos);
vec3 samplePos = pos*vec3(1.0,1./32.,1.0);
vec3 samplePos2 = pos*vec3(1.0,1./48.,1.0);
// #ifndef THE_ORB
float radiance = 2.39996 + samplePos.y + frameTimeCounter/10;
mat2 rotationMatrix = mat2(vec2(cos(radiance), -sin(radiance)), vec2(sin(radiance), cos(radiance)));
// make the swirl only happen within a radius
float SwirlBounds = clamp(sqrt(length(vec3(pos.x,pos.y-100,pos.z)) / 200.0 - 1.0) ,0.0,1.0);
samplePos.xz = mix(samplePos.xz * rotationMatrix, samplePos.xz, SwirlBounds);
samplePos2.xz = mix(samplePos2.xz * rotationMatrix, samplePos2.xz, SwirlBounds);
// #endif
samplePos2.y -= frameTimeCounter/15;
float finalfog = 0.0;
finalfog += max(0.6-densityAtPosFog(samplePos * 16.0) * 2,0.0);
float smallnoise = max(densityAtPosFog(samplePos2 * (160. - finalfog*3))-0.1,0.0);
finalfog -= ((1-smallnoise) - max(0.15 - abs(smallnoise * 2.0 - 0.55) * 0.5,0.0)*1.5) * 0.3;
// make the eye of the swirl have no fog, so you can actually see.
finalfog = max(finalfog - Shapes.r, 0.0);
finalfog += Shapes.b;
return finalfog;
}
#define lightsourceCount 2 // [1 2]
vec4 GetVolumetricFog(
vec3 fragpos,
float dither,
float dither2
) {
int SAMPLES = 16;
//project pixel position into projected shadowmap space
vec3 wpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz;
vec3 viewPos,
float dither,
float dither2
){
int SAMPLES = 32;
vec3 vL = vec3(0.0);
float absorbance = 1.0;
//project pixel position into projected shadowmap space
vec3 wpos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
vec3 fragposition = mat3(shadowModelView) * wpos + shadowModelView[3].xyz;
fragposition = diagonal3(shadowProjection) * fragposition + shadowProjection[3].xyz;
//project view origin into projected shadowmap space
vec3 start = vec3(0.0);
//rayvector into projected shadow map space
//we can use a projected vector because its orthographic projection
//however we still have to send it to curved shadow map space every step
vec3 dV = (fragposition-start);
vec3 dV = fragposition-start;
vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
float maxLength = min(length(dVWorld),32.0 * 12.0)/length(dVWorld);
dV *= maxLength;
dVWorld *= maxLength;
//apply dither
vec3 progress = start.xyz;
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition;
vec3 vL = vec3(0.);
float dL = length(dVWorld);
vec3 fogcolor = (gl_Fog.color.rgb / max(dot(gl_Fog.color.rgb,vec3(0.3333)),0.05)) ;
vec3 LightCol1 = vec3(0); vec3 LightCol2 = vec3(0);
LightSourceColors(LightCol1, LightCol2);
float Flashing = texelFetch2D(colortex4,ivec2(1,1),0).x/150.0;
// LightCol1 *= Flashing;
LightCol2 *= Flashing;
vec3 LightPos1 = vec3(0); vec3 LightPos2 = vec3(0);
LightSourcePosition(cameraPosition, cameraPosition, LightPos1, LightPos2);
float Phase1 = sqrt(1.0 - clamp( dot(normalize(dVWorld), normalize(-LightPos1)),0.0,1.0));
Phase1 = exp(Phase1 * -5.0) * 10;
float Phase2 = sqrt(1.0 - clamp( dot(normalize(dVWorld), normalize(-LightPos2)),0.0,1.0));
Phase2 = exp(Phase2 * -5.0) * 10;
float absorbance = 1.0;
float expFactor = 11.0;
vec3 fogColor = (gl_Fog.color.rgb / max(pow(dot(gl_Fog.color.rgb,vec3(0.3333)),1.1),0.01) ) ;
for (int i=0;i<SAMPLES;i++) {
float d = (pow(expFactor, float(i+dither)/float(SAMPLES))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(SAMPLES)) * log(expFactor) / float(SAMPLES)/(expFactor-1.0);
progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
vec3 progress = start.xyz + d*dV;
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
float densityVol = cloudVol(progressW,1);
float density = min(densityVol,0.09);
float air = 0.005;
// vec3 LightPos1 = vec3(0); vec3 LightPos2 = vec3(0);
LightSourcePosition(progressW, cameraPosition, LightPos1, LightPos2);
/// THE OOOOOOOOOOOOOOOOOOOOOORB
vec3 LightColor = LightSourceColor(clamp(sqrt(length(vec3(progressW.x,progressW.y-100,progressW.z)) / 150.0 - 1.0) ,0.0,1.0));
vec3 LightPos = LightSourcePosition(progressW, cameraPosition);
// float OrbMie = exp(length(LightPos) * -0.03) * 64.0;
// float OrbMie = max(exp2(4.0 + length(LightPos) / -20),0.0);
float VolumeDensity = max(cloudVol(progressW),0.0);
float Density = max(VolumeDensity,0.0);
float OrbMie = max(1.0-length(LightPos)/250,0.0);
float N = 2.50;
OrbMie = pow(1.0-pow(1.0-OrbMie,1.0/N),N);
OrbMie *= 10.0;
// LightColor *= OrbMie;
float CastLight = 0.0;
for (int j=0; j < 3; j++){
vec3 shadowSamplePos = progressW - LightPos * (pow(j+dither2/3,0.75)*0.3);
// vec3 shadowSamplePos = progressW - LightPos * (pow(j+dither2,0.75)*0.25);
float densityVol2 = cloudVol(shadowSamplePos,1);
CastLight += densityVol2;
}
////////////////////////////////////////////////////////////////
///////////////////////// AMBIENT LIGHT ////////////////////////
////////////////////////////////////////////////////////////////
vec3 CastedLight = LightColor * OrbMie * exp(CastLight * 15 * (LightColor*(1.0-CastLight/3)-1.50)) ;
CastedLight += (LightColor * vec3(1.0,1.3,1.0)) * exp(abs(densityVol*2.0 - 0.3) * 15 * (LightColor*CastLight)) * (max(OrbMie - density*10,0.0)/10);
vec3 vL0 = fogcolor * exp2(VolumeDensity * -25) * 0.1 ;
#ifdef THE_ORB
density += clamp((1.0 - length(LightPos) / 10.0) * 10 ,0.0,1.0) ;
#endif
vec3 AmbientLight = fogColor * 0.05 * pow(exp(density * -2),20);
////////////////////////////////////////////////////////////////
/////////////////////// MAIN LIGHTSOURCE ///////////////////////
////////////////////////////////////////////////////////////////
vec3 Light1 = vec3(0); vec3 Light2 = vec3(0);
vec3 vL0 = AmbientLight + CastedLight;
vec3 vL1 = vec3(0.5,0.75,1.0) * 0.05 ;
// vL1 += (LightColor* vec3(1.0,1.3,1.0)) * max(LightColor - (exp(CastLight * 5)-OrbMie),0.0) * OrbMie;
vL += (vL0 - vL0*exp(-density*dd*dL)) * absorbance;
vL += (vL1 - vL1*exp(-air*dd*dL)) * absorbance;
// Density += clamp((1.0 - length(LightPos1) / 10.0) * 10 ,0.0,1.0); // THE ORRRRRRRRRRRRRRRRRRRRRRRRRRB
Light1 = LightSourceLighting(progressW, LightPos1, dither2, VolumeDensity, LightCol1, Phase1);
absorbance *= exp(-(density+air)*dd*dL);
#if lightsourceCount == 2
Density += clamp((1.0 - length(LightPos2) / 10.0) * 10 ,0.0,1.0); // THE ORRRRRRRRRRRRRRRRRRRRRRRRRRB
Light2 += LightSourceLighting(progressW, LightPos2, dither2, VolumeDensity, LightCol2, Phase2);
#endif
vL0 += Light1 + Light2;
////////////////////////////////////////////////////////////////
/////////////////////////// FINALIZE ///////////////////////////
////////////////////////////////////////////////////////////////
float AirDensity = 0.002;
// AirDensity = 0.0;
vec3 vL1 = vec3(0.5,0.75,1.0);
// vL1 += Light1 + Light2;
vL += (vL1 - vL1*exp2(-AirDensity*dd*dL)) * absorbance;
vL += (vL0 - vL0*exp(-Density*dd*dL)) * absorbance;
absorbance *= exp2(-(AirDensity+Density)*dd*dL);
if (absorbance < 1e-5) break;
}
return vec4(vL, absorbance);
}
float GetCloudShadow(vec3 WorldPos, vec3 LightPos, float noise){
float GetCloudShadow(vec3 WorldPos, vec3 LightPos){
float Shadow = 0.0;
for (int i=0; i < 3; i++){
vec3 shadowSamplePos = WorldPos - LightPos * (0.25 + pow(i,0.75)*0.25);
float Cast = cloudVol(shadowSamplePos,1);
vec3 shadowSamplePos = WorldPos - LightPos * (0.1 + pow(i,0.75)*0.25);
// vec3 shadowSamplePos = WorldPos - LightPos * i * 0.5;
float Cast = cloudVol(shadowSamplePos);
Shadow += Cast;
}
return clamp(exp(-Shadow*5),0.0,1.0);
// return (Shadow);
}
float GetCloudShadow2(vec3 WorldPos){
float Shadow = cloudVol(WorldPos,1);
return clamp( exp2(Shadow * -3),0.0,1.0);
return clamp(exp(-Shadow*5.0),0.0,1.0);
}

View File

@ -0,0 +1,323 @@
vec2 R2_samples(int n){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha * n);
}
////////////////////////////////////////////////////////////////
///////////////////////////// SSAO ////////////////////////
////////////////////////////////////////////////////////////////
vec2 tapLocation_alternate(
int sampleNumber, float spinAngle, int nb, float nbRot, float r0
){
float alpha = (float(sampleNumber*1.0f + r0) * (1.0 / (nb)));
float angle = alpha * (nbRot * 3.14) ;
float ssR = alpha + spinAngle*3.14;
float sin_v, cos_v;
sin_v = sin(angle);
cos_v = cos(angle);
return vec2(cos_v, sin_v)*ssR;
}
vec2 SSAO(
vec3 viewPos, vec3 normal, bool hand, bool leaves
){
if(hand) return vec2(1,0);
// float radius[7] = float[](
// 0.15,
// 0.15,
// 0.15,
// 0.15,
// 0.15,
// 0.15,
// 0.15
// );
float dist = 1.0 + clamp(viewPos.z*viewPos.z/50.0,0,5); // shrink sample size as distance increases
float mulfov2 = gbufferProjection[1][1]/(3 * dist);
float maxR2 = viewPos.z*viewPos.z*mulfov2*2.*5/50.0;
#ifdef Ambient_SSS
float maxR2_2 = viewPos.z*viewPos.z*mulfov2*2.*2./50.0;
float dist3 = clamp(1-exp( viewPos.z*viewPos.z / -50),0,1);
if(leaves) maxR2_2 = mix(10, maxR2_2, dist3);
#endif
vec2 acc = -(TAA_Offset*(texelSize/2))*RENDER_SCALE ;
int seed = (frameCounter%40000) * 2 + (1+frameCounter);
float samplePos = fract(R2_samples(seed).x + blueNoise(gl_FragCoord.xy).x) * 1.61803398874;
int samples = 7;
float occlusion = 0.0; float sss = 0.0;
int n = 0;
for (int i = 0; i < samples; i++) {
vec2 sp = tapLocation_alternate(i, 0.0, samples, 20, samplePos)* 0.2;
float rd = mulfov2 ;
vec2 sampleOffset = sp * rd;
ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight*aspectRatio)*RENDER_SCALE);
if (offset.x >= 0 && offset.y >= 0 && offset.x < viewWidth*RENDER_SCALE.x && offset.y < viewHeight*RENDER_SCALE.y ) {
vec3 t0 = toScreenSpace(vec3(offset*texelSize+acc+0.5*texelSize, texelFetch2D(depthtex1, offset,0).x) * vec3(1.0/RENDER_SCALE, 1.0) );
vec3 vec = (t0.xyz - viewPos);
float dsquared = dot(vec, vec);
if (dsquared > 1e-5){
if (dsquared < maxR2){
float NdotV = clamp(dot(vec*inversesqrt(dsquared), normalize(normal)),0.,1.);
occlusion += NdotV * clamp(1.0-dsquared/maxR2,0.0,1.0);
}
#ifdef Ambient_SSS
if(dsquared > maxR2_2){
float NdotV = 1.0 - clamp(dot(vec*dsquared, normalize(normal)),0.,1.);
sss += max((NdotV - (1.0-NdotV)) * clamp(1.0-maxR2_2/dsquared,0.0,1.0) ,0.0);
}
#endif
n += 1;
}
}
}
return max(1.0 - vec2(occlusion, sss)/n, 0.0);
}
float ScreenSpace_SSS(
vec3 viewPos, vec3 normal, bool hand, bool leaves
){
if(hand) return 1.0;
// float radius[7] = float[](
// 0.15,
// 0.15,
// 0.15,
// 0.15,
// 0.15,
// 0.15,
// 0.15
// );
float dist = 1.0 + clamp(viewPos.z*viewPos.z/50.0,0,5); // shrink sample size as distance increases
float mulfov2 = gbufferProjection[1][1]/(3 * dist);
float maxR2_2 = viewPos.z*viewPos.z*mulfov2*2.*2./50.0;
float dist3 = clamp(1-exp( viewPos.z*viewPos.z / -50),0,1);
if(leaves) maxR2_2 = mix(10, maxR2_2, dist3);
vec2 acc = -(TAA_Offset*(texelSize/2))*RENDER_SCALE ;
int seed = (frameCounter%40000) * 2 + (1+frameCounter);
float samplePos = fract(R2_samples(seed).x + blueNoise(gl_FragCoord.xy).x) * 1.61803398874;
int samples = 7;
float sss = 0.0;
int n = 0;
for (int i = 0; i < samples; i++) {
vec2 sp = tapLocation_alternate(i, 0.0, samples, 20, samplePos)* 0.2;
float rd = mulfov2 ;
vec2 sampleOffset = sp * rd;
ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight*aspectRatio)*RENDER_SCALE);
if (offset.x >= 0 && offset.y >= 0 && offset.x < viewWidth*RENDER_SCALE.x && offset.y < viewHeight*RENDER_SCALE.y ) {
vec3 t0 = toScreenSpace(vec3(offset*texelSize+acc+0.5*texelSize, texelFetch2D(depthtex1, offset,0).x) * vec3(1.0/RENDER_SCALE, 1.0) );
vec3 vec = (t0.xyz - viewPos);
float dsquared = dot(vec, vec);
if (dsquared > 1e-5){
if(dsquared > maxR2_2){
float NdotV = 1.0 - clamp(dot(vec*dsquared, normalize(normal)),0.,1.);
sss += max((NdotV - (1.0-NdotV)) * clamp(1.0-maxR2_2/dsquared,0.0,1.0) ,0.0);
}
n += 1;
}
}
}
return max(1.0 - sss/n, 0.0);
}
////////////////////////////////////////////////////////////////////
///////////////////////////// RTAO/SSGI ////////////////////////
////////////////////////////////////////////////////////////////////
vec3 rayTrace_GI(vec3 dir,vec3 position,float dither, float quality){
vec3 clipPosition = toClipSpace3(position);
float rayLength = ((position.z + dir.z * far*sqrt(3.)) > -near) ?
(-near -position.z) / dir.z : far*sqrt(3.);
vec3 direction = normalize(toClipSpace3(position+dir*rayLength)-clipPosition); //convert to clip space
direction.xy = normalize(direction.xy);
//get at which length the ray intersects with the edge of the screen
vec3 maxLengths = (step(0.,direction)-clipPosition) / direction;
float mult = maxLengths.y;
vec3 stepv = direction * mult / quality*vec3(RENDER_SCALE,1.0) * dither;
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ;
spos.xy += TAA_Offset*texelSize*0.5/RENDER_SCALE;
float biasdist = clamp(position.z*position.z/50.0,1,2); // shrink sample size as distance increases
for(int i = 0; i < int(quality); i++){
spos += stepv;
float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0);
float currZ = linZ(spos.z);
if( sp < currZ) {
float dist = abs(sp-currZ)/currZ;
if (abs(dist) < biasdist*0.05) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0);
}
spos += stepv;
}
return vec3(1.1);
}
vec3 RT(vec3 dir, vec3 position, float noise, float stepsizes){
float dist = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases
float stepSize = stepsizes / dist;
int maxSteps = STEPS;
vec3 clipPosition = toClipSpace3(position);
float rayLength = ((position.z + dir.z * sqrt(3.0)*far) > -sqrt(3.0)*near) ?
(-sqrt(3.0)*near -position.z) / dir.z : sqrt(3.0)*far;
vec3 end = toClipSpace3(position+dir*rayLength) ;
vec3 direction = end-clipPosition ; //convert to clip space
float len = max(abs(direction.x)/texelSize.x,abs(direction.y)/texelSize.y)/stepSize;
//get at which length the ray intersects with the edge of the screen
vec3 maxLengths = (step(0.,direction)-clipPosition) / direction;
float mult = min(min(maxLengths.x,maxLengths.y),maxLengths.z)*2000.0;
vec3 stepv = direction/len;
int iterations = min(int(min(len, mult*len)-2), maxSteps);
//Do one iteration for closest texel (good contact shadows)
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ;
spos.xy += TAA_Offset*texelSize*0.5*RENDER_SCALE;
spos += stepv/(stepSize/2);
float distancered = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases
for(int i = 0; i < iterations; i++){
if (spos.x < 0.0 || spos.y < 0.0 || spos.z < 0.0 || spos.x > 1.0 || spos.y > 1.0 || spos.z > 1.0) return vec3(1.1);
spos += stepv*noise;
float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/ texelSize/4),0).w/65000.0);
float currZ = linZ(spos.z);
if( sp < currZ) {
float dist = abs(sp-currZ)/currZ;
if (dist <= 0.1) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0);
}
}
return vec3(1.1);
}
vec3 cosineHemisphereSample(vec2 Xi, float roughness){
float r = sqrt(Xi.x);
float theta = 2.0 * 3.14159265359 * Xi.y;
float x = r * cos(theta);
float y = r * sin(theta);
return vec3(x, y, sqrt(clamp(1.0 - Xi.x,0.,1.)));
}
vec3 TangentToWorld(vec3 N, vec3 H, float roughness){
vec3 UpVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
vec3 T = normalize(cross(UpVector, N));
vec3 B = cross(N, T);
return vec3((T * H.x) + (B * H.y) + (N * H.z));
}
void ApplySSRT(inout vec3 lighting, vec3 normal,vec2 noise,vec3 viewPos, vec2 lightmaps, vec3 skylightcolor, vec3 torchcolor, bool isGrass){
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);
for (int i = 0; i < nrays; i++){
int seed = (frameCounter%40000)*nrays+i;
vec2 ij = fract(R2_samples(seed) + noise );
vec3 rayDir = TangentToWorld(normal, normalize(cosineHemisphereSample(ij,1.0)) ,1.0);
#ifdef HQ_SSGI
vec3 rayHit = rayTrace_GI( mat3(gbufferModelView) * rayDir, viewPos, blueNoise(), 50.); // ssr rt
#else
vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, viewPos, blueNoise(), 30.); // choc sspt
#endif
#ifdef SKY_CONTRIBUTION_IN_SSRT
if(isGrass) rayDir.y = clamp(rayDir.y + 0.5,-1,1);
skycontribution = (skyCloudsFromTex(rayDir, colortex4).rgb / 15.0) * skyLM + torchlight;
#else
if(isGrass) rayDir.y = clamp(rayDir.y + 0.25,-1,1);
skycontribution = skylightcolor * 2 * (max(rayDir.y,0.0)*0.9+0.1) + torchlight;
#if indirect_effect == 4
skycontribution2 = skylightcolor + torchlight;
#endif
#endif
if (rayHit.z < 1.){
#if indirect_effect == 4
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rayHit) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition;
previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz;
previousPosition.xy = projMAD(gbufferPreviousProjection, previousPosition).xy / -previousPosition.z * 0.5 + 0.5;
if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0){
radiance += (texture2D(colortex5,previousPosition.xy).rgb + skycontribution) * GI_Strength;
} else{
radiance += skycontribution;
}
#else
radiance += skycontribution;
#endif
occlusion += skycontribution * GI_Strength;
#if indirect_effect == 4
occlusion2 += skycontribution2 * GI_Strength;
#endif
} else {
radiance += skycontribution;
}
}
occlusion *= AO_Strength;
#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
}

View File

@ -0,0 +1,62 @@
uniform vec3 lightningEffect;
#ifdef IS_IRIS
uniform vec4 lightningBoltPosition;
#else
vec4 lightningBoltPosition = vec4(0.0, 100.0, 0.0, lightningEffect.x);
#endif
vec3 Iris_Lightningflash(vec3 feetPlayerPos, vec3 lightningBoltPos, vec3 WorldSpace_normal, inout float Phase){
if(lightningBoltPosition.w > 0.0){
vec3 LightningPos = feetPlayerPos - vec3(lightningBoltPosition.x, clamp(feetPlayerPos.y, lightningBoltPosition.y+16, lightningBoltPosition.y+116.0),lightningBoltPosition.z);
// point light, max distance is ~500 blocks (the maximim entity render distance)
float lightDistance = 300.0 ;
float lightningLight = max(1.0 - length(LightningPos) / lightDistance, 0.0);
// the light above ^^^ is a linear curve. me no likey. here's an exponential one instead.
lightningLight = exp((1.0 - lightningLight) * -10.0);
// a phase for subsurface scattering.
vec3 PhasePos = normalize(feetPlayerPos) + vec3(lightningBoltPosition.x, lightningBoltPosition.y + 60, lightningBoltPosition.z);
float PhaseOrigin = 1.0 - clamp(dot(normalize(feetPlayerPos), normalize(PhasePos)),0.0,1.0);
Phase = exp(sqrt(PhaseOrigin) * -2.0) * 5.0 * lightningLight;
// good old NdotL. only normals facing towards the lightning bolt origin rise to 1.0
float NdotL = clamp(dot(LightningPos, -WorldSpace_normal), 0.0, 1.0);
return lightningEffect * lightningLight * NdotL;
}else return vec3(0.0);
}
vec3 Iris_Lightningflash_VLcloud(vec3 feetPlayerPos, vec3 lightningBoltPos){
if(lightningBoltPosition.w > 0.0){
vec3 LightningPos = feetPlayerPos - vec3(lightningBoltPosition.x, clamp(feetPlayerPos.y, lightningBoltPosition.y, lightningBoltPosition.y+116.0),lightningBoltPosition.z);
float lightDistance = 400.0;
float lightningLight = max(1.0 - length(LightningPos) / lightDistance, 0.0);
lightningLight = exp((1.0 - lightningLight) * -10.0);
return lightningEffect * lightningLight;
}else return vec3(0.0);
}
vec3 Iris_Lightningflash_VLfog(vec3 feetPlayerPos, vec3 lightningBoltPos){
if(lightningBoltPosition.w > 0.0){
if(lightningBoltPosition.w < 1.0) return vec3(0.0);
vec3 LightningPos = feetPlayerPos - vec3(lightningBoltPosition.x, clamp(feetPlayerPos.y, lightningBoltPosition.y, lightningBoltPosition.y+116.0),lightningBoltPosition.z);
#ifdef TEST
float lightningLight = max(1.0 - length(LightningPos) / 50, 0.0);
lightningLight = exp((1.0 - lightningLight) * -15.0) ;
#else
float lightDistance = 300.0;
float lightningLight = max(1.0 - length(LightningPos) / lightDistance, 0.0) ;
lightningLight = exp((1.0 - lightningLight) * -15.0) ;
#endif
return lightningEffect * lightningLight;
}else return vec3(0.0);
}

View File

@ -37,7 +37,7 @@ float cloudVol(in vec3 pos){
}
vec4 GetVolumetricFog(
vec3 fragpos,
vec3 viewPos,
float dither,
float dither2
){
@ -46,7 +46,7 @@ vec4 GetVolumetricFog(
float absorbance = 1.0;
//project pixel position into projected shadowmap space
vec3 wpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz;
vec3 wpos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
vec3 fragposition = mat3(shadowModelView) * wpos + shadowModelView[3].xyz;
fragposition = diagonal3(shadowProjection) * fragposition + shadowProjection[3].xyz;
@ -84,13 +84,13 @@ vec4 GetVolumetricFog(
// do background fog lighting
float Air = 0.01;
float AirDensity = 0.01;
vec3 vL1 = fogcolor / 20.0;
vL += (vL1 - vL1*exp(-Air*dd*dL)) * absorbance;
vL += (vL1 - vL1*exp(-AirDensity*dd*dL)) * absorbance;
vL += (vL0 - vL0*exp(-Density*dd*dL)) * absorbance;
absorbance *= exp(-(Density+Air)*dd*dL);
absorbance *= exp(-(Density+AirDensity)*dd*dL);
if (absorbance < 1e-5) break;
}

View File

@ -36,10 +36,10 @@
#define WAVY_STRENGTH 1.0 // [0.1 0.25 0.5 0.75 1.0 1.25 1.5 1.75 2.0]
#define WAVY_SPEED 1.0 // [0.001 0.01 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 1.0 1.25 1.5 2.0 3.0 4.0]
#define Seasons
// #define Seasons
#define Season_Length 24 // [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91]
#define Start_Season 0 // [0 1 2 3]
#define Snowy_Winter
// #define Snowy_Winter
#define Summer_R 1.0 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0]
#define Summer_G 1.0 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0]
@ -75,11 +75,9 @@
#define MIN_LIGHT_AMOUNT 1.0 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0]
#define ambient_brightness 1.0 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 ]
#define ambient_colortype 0 // [0 1]
#define ambient_temp 9000 // [1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 15000 50000]
#define AmbientLight_R 0.91 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define AmbientLight_G 0.86 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define AmbientLight_B 1.0 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define AmbientLight_R 1.0 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0]
#define AmbientLight_G 1.0 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0]
#define AmbientLight_B 1.0 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0]
#define Hand_Held_lights
#define TORCH_AMOUNT 1.0 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.0 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 10.0]
@ -176,7 +174,41 @@ const float sunPathRotation = -35; //[-90 -89 -88 -87 -86 -85 -84 -83 -82 -81 -8
// #define BorderFog
#define SEA_LEVEL 70 // [0 10 20 30 40 50 60 70 80 90 100 110 120 130 150 170 190]
#define Biome_specific_environment
//////////////////////////////////////////////////////
// ----- BIOME SPECIFIC ENVIORNMENTS SETTINGS ----- //
//////////////////////////////////////////////////////
#define PER_BIOME_ENVIRONMENT
#define SWAMP_ENV
#define SWAMP_UNIFORM_DENSITY 50 // [0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 15.0 20.0 25.0 30.0 35.0 40.0 45.0 50.0 75.0 100.0 125.0 150.0 175.0 200.0 255.]
#define SWAMP_CLOUDY_DENSITY 0 // [0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 15.0 20.0 25.0 30.0 35.0 40.0 45.0 50.0 75.0 100.0 125.0 150.0 175.0 200.0 255.]
#define SWAMP_R 0.15 // [0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define SWAMP_G 0.25 // [0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define SWAMP_B 0.05 // [0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define JUNGLE_ENV
#define JUNGLE_UNIFORM_DENSITY 10 // [0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 15.0 20.0 25.0 30.0 35.0 40.0 45.0 50.0 75.0 100.0 125.0 150.0 175.0 200.0 255.]
#define JUNGLE_CLOUDY_DENSITY 150 // [0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 15.0 20.0 25.0 30.0 35.0 40.0 45.0 50.0 75.0 100.0 125.0 150.0 175.0 200.0 255.]
#define JUNGLE_R 0.5 // [0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define JUNGLE_G 1.0 // [0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define JUNGLE_B 0.5 // [0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define DARKFOREST_ENV
#define DARKFOREST_UNIFORM_DENSITY 15 // [0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 15.0 20.0 25.0 30.0 35.0 40.0 45.0 50.0 75.0 100.0 125.0 150.0 175.0 200.0 255.]
#define DARKFOREST_CLOUDY_DENSITY 0 // [0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 15.0 20.0 25.0 30.0 35.0 40.0 45.0 50.0 75.0 100.0 125.0 150.0 175.0 200.0 255.]
#define DARKFOREST_R 0.3 // [0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define DARKFOREST_G 0.4 // [0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define DARKFOREST_B 1.0 // [0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
// i have to do this so it shows up in the menu lmao
#ifdef SWAMP_ENV
#endif
#ifdef JUNGLE_ENV
#endif
#ifdef DARKFOREST_ENV
#endif
///////////////////////////////////////////////////
// ----- LABPBR MATERIALS RELATED SETTINGS ----- //
@ -187,7 +219,7 @@ const float sunPathRotation = -35; //[-90 -89 -88 -87 -86 -85 -84 -83 -82 -81 -8
// #define Sky_reflection
// #define Rough_reflections
#define Dynamic_SSR_quality
#define Sun_specular_Strength 3 // [1 2 3 4 5 6 7 8 9 10]
#define Sun_specular_Strength 1 // [0 1 2 3 4 5 6 7 8 9 10]
#define reflection_quality 30 // [6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0 20.0 25.0 30.0 35.0 40.0 45.0 50.0 55.0 60.0 65.0 70.0 75.0 80.0 85.0 90.0 95.0 100.0 ]
#define Roughness_Threshold 1.5 // [1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 ]
@ -207,6 +239,11 @@ const float sunPathRotation = -35; //[-90 -89 -88 -87 -86 -85 -84 -83 -82 -81 -8
#define MAX_ITERATIONS 35 // [5 10 15 20 25 30 40 50 60 70 80 90 100 125 150 200 400]
#define MAX_DIST 25.0 // [5.0 10.0 15.0 20.0 25.0 30.0 40.0 50.0 60.0 70.0 80.0 90.0 100.0 125.0 150.0 200.0 400.0]
// #define HEIGTHMAP_DEPTH_OFFSET
#ifdef POM
#undef HEIGTHMAP_DEPTH_OFFSET
#endif
#define SSS_TYPE 2 // [0 1 2 3]
#define LabSSS_Curve 1.0 // [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 ]
@ -292,13 +329,14 @@ uniform int moonPhase;
#define Cumulus_density 0.5 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.00]
#define Cumulus_height 250 // [-100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 320 330 340 350 360 370 380 390 400 410 420 430 440 450 460 470 480 490 500 510 520 530 540 550 560 570 580 590 600 700 800 900 1000]
#define Altostratus
#define Alto_coverage 0.1 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0]
#define Alto_density 0.1 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.00]
#define Rain_coverage 1.1 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0]
#define fbmAmount 0.50 // [0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 0.22 0.24 0.26 0.28 0.30 0.32 0.34 0.36 0.38 0.40 0.42 0.44 0.46 0.48 0.50 0.52 0.54 0.56 0.58 0.60 0.62 0.64 0.66 0.68 0.70 0.72 0.74 0.76 0.78 0.80 0.82 0.84 0.86 0.88 0.90 0.92 0.94 0.96 0.98 1.00 1.02 1.04 1.06 1.08 1.10 1.12 1.14 1.16 1.18 1.20 1.22 1.24 1.26 1.28 1.30 1.32 1.34 1.36 1.38 1.40 1.42 1.44 1.46 1.48 1.50 1.52 1.54 1.56 1.58 1.60 1.62 1.64 1.66 1.68 1.70 1.72 1.74 1.76 1.78 1.80 1.82 1.84 1.86 1.88 1.90 1.92 1.94 1.96 1.98 2.00 2.02 2.04 2.06 2.08 2.10 2.12 2.14 2.16 2.18 2.20 2.22 2.24 2.26 2.28 2.30 2.32 2.34 2.36 2.38 2.40 2.42 2.44 2.46 2.48 2.50 2.52 2.54 2.56 2.58 2.60 2.62 2.64 2.66 2.68 2.70 2.72 2.74 2.76 2.78 2.80 2.82 2.84 2.86 2.88 2.90 2.92 2.94 2.96 2.98 3.00]
#define fbmAmount 0.5 // [0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 0.22 0.24 0.26 0.28 0.30 0.32 0.34 0.36 0.38 0.40 0.42 0.44 0.46 0.48 0.50 0.52 0.54 0.56 0.58 0.60 0.62 0.64 0.66 0.68 0.70 0.72 0.74 0.76 0.78 0.80 0.82 0.84 0.86 0.88 0.90 0.92 0.94 0.96 0.98 1.00 1.02 1.04 1.06 1.08 1.10 1.12 1.14 1.16 1.18 1.20 1.22 1.24 1.26 1.28 1.30 1.32 1.34 1.36 1.38 1.40 1.42 1.44 1.46 1.48 1.50 1.52 1.54 1.56 1.58 1.60 1.62 1.64 1.66 1.68 1.70 1.72 1.74 1.76 1.78 1.80 1.82 1.84 1.86 1.88 1.90 1.92 1.94 1.96 1.98 2.00 2.02 2.04 2.06 2.08 2.10 2.12 2.14 2.16 2.18 2.20 2.22 2.24 2.26 2.28 2.30 2.32 2.34 2.36 2.38 2.40 2.42 2.44 2.46 2.48 2.50 2.52 2.54 2.56 2.58 2.60 2.62 2.64 2.66 2.68 2.70 2.72 2.74 2.76 2.78 2.80 2.82 2.84 2.86 2.88 2.90 2.92 2.94 2.96 2.98 3.00]
#define fbmPower1 3.00 // [1.0 1.50 1.52 1.54 1.56 1.58 1.60 1.62 1.64 1.66 1.68 1.70 1.72 1.74 1.76 1.78 1.80 1.82 1.84 1.86 1.88 1.90 1.92 1.94 1.96 1.98 2.00 2.02 2.04 2.06 2.08 2.10 2.12 2.14 2.16 2.18 2.20 2.22 2.24 2.26 2.28 2.30 2.32 2.34 2.36 2.38 2.40 2.42 2.44 2.46 2.48 2.50 2.52 2.54 2.56 2.58 2.60 2.62 2.64 2.66 2.68 2.70 2.72 2.74 2.76 2.78 2.80 2.82 2.84 2.86 2.88 2.90 2.92 2.94 2.96 2.98 3.00 3.02 3.04 3.06 3.08 3.10 3.12 3.14 3.16 3.18 3.20 3.22 3.24 3.26 3.28 3.30 3.32 3.34 3.36 3.38 3.40 3.42 3.44 3.46 3.48 3.50 3.52 3.54 3.56 3.58 3.60 3.62 3.64 3.66 3.68 3.70 3.72 3.74 3.76 3.78 3.80 3.82 3.84 3.86 3.88 3.90 3.92 3.94 3.96 3.98 4.00 5. 6. 7. 8. 9. 10.]
#define fbmPower2 2.50 // [1.00 1.50 1.52 1.54 1.56 1.58 1.60 1.62 1.64 1.66 1.68 1.70 1.72 1.74 1.76 1.78 1.80 1.82 1.84 1.86 1.88 1.90 1.92 1.94 1.96 1.98 2.00 2.02 2.04 2.06 2.08 2.10 2.12 2.14 2.16 2.18 2.20 2.22 2.24 2.26 2.28 2.30 2.32 2.34 2.36 2.38 2.40 2.42 2.44 2.46 2.48 2.50 2.52 2.54 2.56 2.58 2.60 2.62 2.64 2.66 2.68 2.70 2.72 2.74 2.76 2.78 2.80 2.82 2.84 2.86 2.88 2.90 2.92 2.94 2.96 2.98 3.00 3.02 3.04 3.06 3.08 3.10 3.12 3.14 3.16 3.18 3.20 3.22 3.24 3.26 3.28 3.30 3.32 3.34 3.36 3.38 3.40 3.42 3.44 3.46 3.48 3.50 3.52 3.54 3.56 3.58 3.60 3.62 3.64 3.66 3.68 3.70 3.72 3.74 3.76 3.78 3.80 3.82 3.84 3.86 3.88 3.90 3.92 3.94 3.96 3.98 4.00 5. 6. 7. 8. 9. 10.]
@ -313,8 +351,6 @@ uniform int moonPhase;
#define HQ_CLOUDS
//////////////////////////////////////
// ----- TAA RELATED SETTINGS ----- //
//////////////////////////////////////
@ -415,7 +451,7 @@ uniform int moonPhase;
// #define DEBUG_endfog
// #define THE_ORB
#define ORB_X 0 // [-200 -195 -190 -185 -180 -175 -170 -165 -160 -155 -150 -145 -140 -135 -130 -125 -120 -115 -110 -105 -100 -95 -90 -85 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200]
#define ORB_Y 0 // [-200 -195 -190 -185 -180 -175 -170 -165 -160 -155 -150 -145 -140 -135 -130 -125 -120 -115 -110 -105 -100 -95 -90 -85 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200]
#define ORB_Y 0 // [-200 -195 -190 -185 -180 -175 -170 -165 -160 -155 -150 -145 -140 -135 -130 -125 -120 -115 -110 -105 -100 -95 -90 -85 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200 210 220 230 240 250]
#define ORB_Z 0 // [-200 -195 -190 -185 -180 -175 -170 -165 -160 -155 -150 -145 -140 -135 -130 -125 -120 -115 -110 -105 -100 -95 -90 -85 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200]
#define ORB_R 1.0 // [0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
@ -434,7 +470,7 @@ uniform int moonPhase;
// #define WhiteWorld // THIS IS A DEBUG VIEW. uses to see AO easier. used to see fake GI better (green light)
// #define Compositing_Sky // make the sky some color to make compositing a sky in some photoediting software easier.
// #define display_LUT
// #define ambientSSS_view
// #define SSS_view
#define Texture_MipMap_Bias 0.0 // [-5.00 -4.75 -4.50 -4.25 -4.00 -3.75 -3.50 -3.25 -3.00 -2.75 -2.50 -2.25 -2.00 -1.75 -1.50 -1.25 -1.00 -0.75 -0.50 -0.25 0.00 0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 3.25 3.50 3.75 4.00 4.25 4.50 4.75 5.00]
@ -446,4 +482,11 @@ uniform int moonPhase;
// #define OLD_LIGHTLEAK_FIX
#define LIT_PARTICLE_BRIGHTNESS 2.0 // [1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 15.0 20.0 25.0 30.0 35.0 40.0 45.0 50.0 100.]
#define LIT_PARTICLE_BRIGHTNESS 2.0 // [1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 15.0 20.0 25.0 30.0 35.0 40.0 45.0 50.0 100.]
#define HURT_AND_DEATH_EFFECT
#define LIGHTNING_FLASH // FOR OPTIFINE USERS. some mods change the sky color, which can trigger the lightning flash detection.
#ifdef LIGHTNING_FLASH
#endif

View File

@ -1,23 +1,38 @@
#define ffstep(x,y) clamp((y - x) * 1e35,0.0,1.0)
vec3 drawSun(float cosY, float sunInt,vec3 nsunlight,vec3 inColor){
return inColor+nsunlight/0.0008821203*pow(smoothstep(cos(0.0093084168595*3.2),cos(0.0093084168595*1.8),cosY),3.)*0.62;
}
const float pi = 3.141592653589793238462643383279502884197169;
vec2 sphereToCarte(vec3 dir) {
float lonlat = atan(-dir.x, -dir.z);
return vec2(lonlat * (0.5/pi) +0.5,0.5*dir.y+0.5);
vec3 drawMoon(vec3 PlayerPos, vec3 WorldSunVec, vec3 Color, inout vec3 occludeStars){
float Shape = clamp((exp(1 + -1000 * dot(WorldSunVec+PlayerPos,PlayerPos)) - 1.5),0.0,25.0);
occludeStars *= max(1.0-Shape*5,0.0);
float shape2 = pow(exp(Shape * -10),0.15) * 255.0;
vec3 sunNormal = vec3(dot(WorldSunVec+PlayerPos, vec3(shape2,0,0)), dot(PlayerPos+WorldSunVec, vec3(0,shape2,0)), -dot(WorldSunVec, PlayerPos) * 15.0);
// even has a little tilt approximation haha.... yeah....
vec3[8] phase = vec3[8](
vec3( -1.0, -0.5, 1.0 ),
vec3( -1.0, -0.5, 0.35 ),
vec3( -1.0, -0.5, 0.2 ),
vec3( -1.0, -0.5, 0.1 ),
vec3( 1.0, 0.25, -1.0 ),
vec3( 1.0, 0.25, 0.1 ),
vec3( 1.0, 0.25, 0.2 ),
vec3( 1.0, 0.25, 0.35 )
);
vec3 LightDir = phase[moonPhase];
return Shape * pow(clamp(dot(sunNormal,LightDir)/5,0.0,1.5),5) * Color + clamp(Shape * 4.0 * pow(shape2/200,2.0),0.0,1.0)*0.004;
}
vec3 skyFromTex(vec3 pos,sampler2D sampler){
vec2 p = sphereToCarte(pos);
return texture2D(sampler,p*texelSize*256.+vec2(18.5,1.5)*texelSize).rgb;
}
vec3 skyFromTexLOD(vec3 pos,sampler2D sampler, float LOD){
vec2 p = sphereToCarte(pos);
return texture2DLod(sampler,p*texelSize*256.+vec2(18.5,1.5)*texelSize,LOD).rgb;
}
const float pi = 3.141592653589793238462643383279502884197169;
float w0(float a)
@ -84,6 +99,19 @@ vec4 texture2D_bicubic(sampler2D tex, vec2 uv)
g1(fuv.y) * (g0x * texture2D(tex, p2) +
g1x * texture2D(tex, p3));
}
vec2 sphereToCarte(vec3 dir) {
float lonlat = atan(-dir.x, -dir.z);
return vec2(lonlat * (0.5/pi) +0.5,0.5*dir.y+0.5);
}
vec3 skyFromTex(vec3 pos,sampler2D sampler){
vec2 p = sphereToCarte(pos);
return texture2D(sampler,p*texelSize*256.+vec2(18.5,1.5)*texelSize).rgb;
}
vec3 skyFromTexLOD(vec3 pos,sampler2D sampler, float LOD){
vec2 p = sphereToCarte(pos);
return texture2DLod(sampler,p*texelSize*256.+vec2(18.5,1.5)*texelSize,LOD).rgb;
}
vec4 skyCloudsFromTex(vec3 pos,sampler2D sampler){
vec2 p = sphereToCarte(pos);
return texture2D(sampler,p*texelSize*256.+vec2(18.5+257.,1.5)*texelSize);
@ -92,12 +120,8 @@ vec4 skyCloudsFromTexLOD(vec3 pos,sampler2D sampler, float LOD){
vec2 p = sphereToCarte(pos);
return texture2DLod(sampler,p*texelSize*256. + vec2(18.5 + 257., 1.5)*texelSize,LOD);
}
// vec2 p = clamp(floor(gl_FragCoord.xy-vec2(18.+257,1.))/256.+tempOffsets/256.,0.0,1.0);
// vec2 p = clamp(floor(gl_FragCoord.xy-vec2(256*0.75,256*0.25))/150.+tempOffsets/150.,0.0,1.0);
// vec2 p = clamp(floor(gl_FragCoord.xy-fogPos)/256.+tempOffsets/256.,-0.33,1.0);
vec4 skyCloudsFromTexLOD2(vec3 pos,sampler2D sampler, float LOD){
vec2 p = sphereToCarte(pos);
return texture2DLod(sampler,p*texelSize*256. + vec2(256.0 - 256.0*0.12,1.5)*texelSize,LOD);
}
}

View File

@ -1,4 +1,3 @@
uniform int framemod8;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
@ -10,11 +9,11 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
vec3 mix_vec3(vec3 X, vec3 Y, float A){
vec3 lerp(vec3 X, vec3 Y, float A){
return X * (1.0 - A) + Y * A;
}
float mix_float(float X, float Y, float A){
float lerp(float X, float Y, float A){
return X * (1.0 - A) + Y * A;
}
@ -22,14 +21,14 @@ float square(float x){
return x*x;
}
float invLinZ (float lindepth){
return -((2.0*near/lindepth)-far-near)/(far-near);
}
vec3 toClipSpace3(vec3 viewSpacePosition) {
return projMAD(gbufferProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
}
float invLinZ (float lindepth){
return -((2.0*near/lindepth)-far-near)/(far-near);
}
float linZ(float depth) {
return (2.0 * near) / (far + near - depth * (far - near));
// l = (2*n)/(f+n-d(f-n))
@ -57,11 +56,6 @@ mat3 CoordBase(vec3 n){
return mat3(x,y,n);
}
float unpackRoughness(float x){
float r = 1.0 - x;
return clamp(r*r,0,1);
}
vec2 R2_Sample(int n){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha * n);
@ -194,7 +188,8 @@ void DoSpecularReflections(
Lightmap = clamp((Lightmap-0.6)*5.0, 0.0,1.0);
Roughness = unpackRoughness(Roughness);
// Roughness = unpackRoughness(Roughness);
Roughness = 1.0 - Roughness; Roughness *= Roughness;
F0 = F0 == 0.0 ? 0.02 : F0;
// Roughness = 0.0;
@ -214,7 +209,7 @@ void DoSpecularReflections(
vec3 L = Basis * Ln;
float Fresnel = pow(clamp(1.0 + dot(-Ln, SamplePoints),0.0,1.0), 5.0); // Schlick's approximation
float RayContribution = mix_float(F0, 1.0, Fresnel); // ensure that when the angle is 0 that the correct F0 is used.
float RayContribution = lerp(F0, 1.0, Fresnel); // ensure that when the angle is 0 that the correct F0 is used.
#ifdef Rough_reflections
if(Hand) RayContribution = RayContribution * pow(1.0-Roughness,3.0);
@ -225,7 +220,7 @@ void DoSpecularReflections(
bool hasReflections = Roughness_Threshold == 1.0 ? true : F0 * (1.0 - Roughness * Roughness_Threshold) > 0.01;
// mulitply all reflections by the albedo if it is a metal.
vec3 Metals = F0 > 229.5/255.0 ? mix_vec3(Albedo, vec3(1.0), Fresnel) : vec3(1.0);
vec3 Metals = F0 > 229.5/255.0 ? lerp(Albedo, vec3(1.0), Fresnel) : vec3(1.0);
// --------------- BACKGROUND REFLECTIONS
// apply background reflections to the final color. make sure it does not exist based on the lightmap
@ -238,7 +233,7 @@ void DoSpecularReflections(
#endif
// take fresnel and lightmap levels into account and write to the final color
Final_Reflection = mix_vec3(Output, Background_Reflection, Lightmap * RayContribution);
Final_Reflection = lerp(Output, Background_Reflection, Lightmap * RayContribution);
#endif
// --------------- SCREENSPACE REFLECTIONS
@ -246,15 +241,17 @@ void DoSpecularReflections(
#ifdef Screen_Space_Reflections
if(hasReflections){
#ifdef Dynamic_SSR_quality
float SSR_Quality = mix_float(reflection_quality, 6.0, RayContribution); // Scale quality with ray contribution
float SSR_Quality = lerp(reflection_quality, 6.0, RayContribution); // Scale quality with ray contribution
#else
float SSR_Quality = reflection_quality;
#endif
float reflectLength = 0.0;
vec3 RaytracePos = rayTraceSpeculars(mat3(gbufferModelView) * L, FragPos, Noise.z, SSR_Quality, Hand, reflectLength);
vec3 RaytracePos = rayTraceSpeculars(mat3(gbufferModelView) * L, FragPos, Noise.z, float(SSR_Quality), Hand, reflectLength);
float LOD = clamp(pow(reflectLength, pow(1.0-sqrt(Roughness),5.0) * 3.0) * 6.0, 0.0, 6.0); // use higher LOD as the reflection goes on, to blur it. this helps denoise a little.
if(Roughness <= 0.0) LOD = 0.0;
if (RaytracePos.z < 1.0){
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(RaytracePos) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition;
previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz;
@ -266,10 +263,10 @@ void DoSpecularReflections(
}
}
// make sure it takes the fresnel into account for SSR.
SS_Reflections.rgb = mix_vec3(Output, SS_Reflections.rgb, RayContribution);
SS_Reflections.rgb = lerp(Output, SS_Reflections.rgb, RayContribution);
// occlude the background with the SSR and write to the final color.
Final_Reflection = mix_vec3(Final_Reflection, SS_Reflections.rgb, SS_Reflections.a);
Final_Reflection = lerp(Final_Reflection, SS_Reflections.rgb, SS_Reflections.a);
}
#endif
@ -277,7 +274,7 @@ void DoSpecularReflections(
// slap the main lightsource reflections to the final color.
#ifdef LIGHTSOURCE_REFLECTION
Lightsource_Reflection = Diffuse * GGX(Normal, -WorldPos, LightPos, Roughness, F0) * Metals;
Final_Reflection += Lightsource_Reflection;
Final_Reflection += Lightsource_Reflection * Sun_specular_Strength;
#endif
Output = Final_Reflection;

View File

@ -39,10 +39,10 @@ float StableStarField( in vec2 vSamplePos, float fThreshhold )
return StarVal;
}
float stars(vec3 fragpos){
float stars(vec3 viewPos){
float elevation = clamp(fragpos.y,0.,1.);
vec2 uv = fragpos.xz/(1.5+elevation);
float elevation = clamp(viewPos.y,0.,1.);
vec2 uv = viewPos.xz/(1.5+elevation);
return StableStarField(uv*1000.,0.999)*0.5*(0.3-0.3*rainStrength);
return StableStarField(uv*1000.,0.999)*0.5*0.3;
}

View File

@ -14,19 +14,13 @@
const int cloudShadowLoD = cloud_ShadowLevelOfDetailLQ;
#endif
uniform float viewHeight;
uniform float viewWidth;
uniform sampler2D colortex4;//Skybox
// uniform float viewHeight;
// uniform float viewWidth;
uniform int worldTime;
#define WEATHERCLOUDS
uniform int worldTime;
#include "/lib/climate_settings.glsl"
// #ifdef Daily_Weather
// uniform float CloudHeight;
// #endif
float CumulusHeight = Cumulus_height;
float MaxCumulusHeight = CumulusHeight + 100;
float AltostratusHeight = 2000;
@ -56,6 +50,7 @@ float cloudCov(in vec3 pos,vec3 samplePos){
float CloudLarge = texture2D(noisetex, (samplePos.xz + cloud_movement) / 5000 ).b;
float CloudSmall = texture2D(noisetex, (samplePos.xz - cloud_movement) / 500 ).r;
float Topshape = max(pos.y - (MaxCumulusHeight - 75), 0.0) / 200;
Topshape += max(exp((pos.y - MaxCumulusHeight) / 10.0 ), 0.0) ;
@ -63,10 +58,10 @@ float cloudCov(in vec3 pos,vec3 samplePos){
float FinalShape = DailyWeather_Cumulus(coverage) - Topshape;
// cap the top and bottom for reasons
float capbase = sqrt(max((CumulusHeight+12.5) - pos.y, 0.0)/50) ;
float capbase = sqrt(max((CumulusHeight+12.5) - pos.y, 0.0)/50) * (1-rainStrength);
float captop = max(pos.y - MaxCumulusHeight, 0.0);
FinalShape = max(FinalShape - capbase - captop, 0.0);
FinalShape = max(FinalShape - capbase - captop , 0.0);
return FinalShape;
}
@ -83,26 +78,24 @@ float cloudVol(in vec3 pos,in vec3 samplePos,in float cov, in int LoD){
samplePos.xz += pow( max(pos.y - (CumulusHeight+20), 0.0) / 20.0,1.50);
noise += 1.0-densityAtPos(samplePos * 200.) ;
float smallnoise = densityAtPos(samplePos * 600.);
if (LoD > 0) noise += ((1-smallnoise) - max(0.15 - abs(smallnoise * 2.0 - 0.55) * 0.5,0.0)*1.5) * 0.5;
float smallnoise = densityAtPos(samplePos * 600.);
if (LoD > 0) noise += ((1-smallnoise) - max(0.15 - abs(smallnoise * 2.0 - 0.55) * 0.5,0.0)*1.5) * 0.6 * sqrt(noise);
noise *= 1.0-cov;
noise = noise*noise;
float cloud = max(cov - noise*noise*fbmAmount,0.0);
return cloud;
}
float GetCumulusDensity(in vec3 pos, in int LoD){
vec3 samplePos = pos*vec3(1.0,1./48.,1.0)/4;
float coverageSP = cloudCov(pos,samplePos);
if (coverageSP > 0.001) {
if (LoD < 0) return max(coverageSP - 0.27*fbmAmount,0.0);
return cloudVol(pos,samplePos,coverageSP,LoD);
@ -113,9 +106,12 @@ float GetAltostratusDensity(vec3 pos){
float large = texture2D(noisetex, (pos.xz + cloud_movement)/100000. ).b;
float small = texture2D(noisetex, (pos.xz - cloud_movement)/10000. - vec2(-large,1-large)/5).b;
float shape = (small + pow((1.0-large),2.0))/2.0;
// float erode = 1-texture2D(noisetex, (pos.xz / ((1-small)*0.5+1.0) - cloud_movement)/1000. + vec2(-small,1-small)/5).b;
// float shape = max((small + pow((1.0-large),2.0))/2.0 - erode*0.05,0.0);
float Coverage; float Density;
DailyWeather_Alto(Coverage, Density);
@ -125,6 +121,17 @@ float GetAltostratusDensity(vec3 pos){
return shape;
}
#ifndef CLOUDSHADOWSONLY
uniform sampler2D colortex4;//Skybox
//Mie phase function
float phaseg(float x, float g){
float gg = g * g;
return (gg * -0.25 + 0.25) * pow(-2.0 * (g * x) + (gg + 1.0), -1.5) / 3.14;
}
// random magic number bullshit go!
@ -142,9 +149,8 @@ vec3 Cloud_lighting(
vec3 pos,
float time
){
float coeeff = -30;
// float powder = 1.0 - exp((CloudShape*CloudShape) * -800);
float powder = 1.0 - exp(CloudShape * coeeff/3);
float powder = 1.0 - exp(CloudShape * -10);
float lesspowder = powder*0.4+0.6;
vec3 skyLighting = SkyColors;
@ -154,45 +160,31 @@ vec3 Cloud_lighting(
float cov = 0.0;
float den = 0.0;
DailyWeather_Alto(cov, den);
skyLighting += (sunContributionMulti * exp(-SunShadowing)) * clamp( 1.0 - pow( abs(den - 0.35) * 4.0 , 5.0) ,0.0,1.0) * cov;
skyLighting += sunContributionMulti * 0.3 * exp2(AmbientShadow * SkyShadowing * -20) * clamp( 1.0 - pow( abs(den - 0.35) * 4.0 , 5.0) ,0.0,1.0) * cov;
#endif
skyLighting *= exp(SkyShadowing * AmbientShadow * coeeff/2.0 ) * lesspowder ;
// skyLighting *= (1.0 - sqrt(exp2((1.0-SkyShadowing) * AmbientShadow * -10))) * lesspowder ;
skyLighting *= exp2((AmbientShadow*AmbientShadow) * SkyShadowing * -35) * lesspowder;
vec3 sunLighting = exp(SunShadowing * -15 + powder ) * sunContribution ;
sunLighting += exp(SunShadowing * -4) * sunContributionMulti * (powder*0.7+0.3);
vec3 moonLighting = exp(MoonShadowing * -7 + powder) * moonContribution;
if(cloudType == 1){
coeeff = -10;
skyLighting = SkyColors * exp(SkyShadowing * coeeff/15) * lesspowder;
skyLighting = SkyColors * exp(-sqrt(SkyShadowing)) * lesspowder;
sunLighting = exp(SunShadowing * -5 ) * sunContribution;
sunLighting += exp(SunShadowing * -1) * sunContributionMulti * powder;
}
vec3 sunLighting = exp(SunShadowing * coeeff + powder) * sunContribution;
sunLighting += exp(SunShadowing * coeeff/4 + powder*2) * sunContributionMulti;
vec3 moonLighting = exp(MoonShadowing * coeeff/4 + powder) * moonContribution;
return skyLighting + moonLighting + sunLighting ;
return skyLighting + moonLighting + sunLighting ;
}
//Mie phase function
float phaseg(float x, float g){
float gg = g * g;
return (gg * -0.25 + 0.25) * pow(-2.0 * (g * x) + (gg + 1.0), -1.5) / 3.14;
}
float CustomPhase(float LightPos, float S_1, float S_2){
float SCALE = S_2 + 0.001; // remember the epislons 0.001 is fine.
float N = S_1;
float N2 = N / SCALE;
float R = 1;
float A = pow(1.0 - pow(max(R-LightPos,0.0), N2 ),N);
return A;
}
uniform vec3 lightningEffect;
vec4 renderClouds(
vec3 FragPosition,
vec2 Dither,
@ -203,66 +195,80 @@ vec4 renderClouds(
#ifndef VOLUMETRIC_CLOUDS
return vec4(0.0,0.0,0.0,1.0);
#endif
float total_extinction = 1.0;
vec3 color = vec3(0.0);
//project pixel position into projected shadowmap space
vec4 fragpos = normalize(gbufferModelViewInverse*vec4(FragPosition,1.0));
vec4 viewPos = normalize(gbufferModelViewInverse*vec4(FragPosition,1.0));
vec3 eyeplayepos = normalize(mat3(gbufferModelViewInverse) * FragPosition.xyz);
maxIT_clouds = int(clamp( maxIT_clouds / sqrt(exp2(fragpos.y)),0.0, maxIT));
maxIT_clouds = int(clamp(maxIT_clouds / sqrt(exp2(viewPos.y)),0.0, maxIT));
vec3 dV_view = normalize(fragpos.xyz);
vec3 dV_view = normalize(viewPos.xyz);
vec3 dV_view2 = dV_view;
dV_view.y += 0.05;
vec3 dV_view2 = dV_view;
float mult2 = length(dV_view2);
//setup ray to start at the start of the cloud plane and end at the end of the cloud plane
dV_view *= max(MaxCumulusHeight - CumulusHeight, 0.0)/abs(dV_view.y)/maxIT_clouds;
float mult = length(dV_view);
// i want the samples to stay at one point in the world, but as the height coordinates go negative everything goes insideout, so this is a work around....
float startFlip = mix(max(cameraPosition.y - MaxCumulusHeight,0.0), max(CumulusHeight-cameraPosition.y,0), clamp(dV_view.y,0,1));
// vec3 progress_view = dV_view*Dither.x + cameraPosition + (dV_view/abs(dV_view.y))*startFlip;
vec3 progress_view = dV_view*Dither.x + cameraPosition + (dV_view/abs(dV_view.y))*startFlip;
vec3 progress_view = dV_view*Dither.x + cameraPosition + (dV_view/abs(dV_view.y))*startFlip ;
// thank you emin for this world interseciton thing
// float lViewPosM = length(FragPosition) < far * 1.5 ? length(FragPosition) - 1.0 : 1000000000.0;
// bool IntersecTerrain = false;
////// lighitng stuff
////// lighting stuff
float shadowStep = 200.;
vec3 dV_Sun = normalize(mat3(gbufferModelViewInverse)*sunVec)*shadowStep;
vec3 dV_Sun_small = dV_Sun/shadowStep;
// vec3 dV_Sun = normalize(mat3(gbufferModelViewInverse)*sunVec)*shadowStep;
vec3 dV_Sun = WsunVec*shadowStep;
// vec3 dV_Sun_small = dV_Sun/shadowStep;
float SdotV = dot(sunVec,normalize(FragPosition));
float SdotV = dot(mat3(gbufferModelView)*WsunVec,normalize(FragPosition));
SkyColor *= clamp(abs(dV_Sun.y)/100.,0.75,1.0);
SkyColor *= clamp(abs(dV_Sun.y)/100.,0.5,1.0);
SunColor = SunColor * clamp(dV_Sun.y ,0.0,1.0);
MoonColor *= clamp(-dV_Sun.y,0.0,1.0);
if(dV_Sun.y/shadowStep < -0.1) dV_Sun = -dV_Sun;
float mieDay = phaseg(SdotV, 0.75) * 3.14;
float mieDayMulti = phaseg(SdotV, 0.35) * 2;
float mieDay = phaseg(SdotV, 0.75);
float mieDayMulti = (phaseg(SdotV, 0.35) + phaseg(-SdotV, 0.35) * 0.5) ;
vec3 sunContribution = SunColor * mieDay;
vec3 sunContributionMulti = SunColor * mieDayMulti ;
vec3 sunContribution = SunColor * mieDay * 3.14;
vec3 sunContributionMulti = SunColor * mieDayMulti * 4.0;
float mieNight = (phaseg(-SdotV,0.8) + phaseg(-SdotV, 0.35)*4);
vec3 moonContribution = MoonColor * mieNight;
float timing = 1.0 - clamp(pow(abs(dV_Sun.y)/150.0,2.0),0.0,1.0);
vec3 lightningColor = lightningEffect * 4.0;
#ifdef Cumulus
// float shadowStepSize[3] = float[](
// 0.05,
// 0.25 + Dither.y*0.1,
// 0.50 + Dither.y*0.1
// );
for(int i=0;i<maxIT_clouds;i++) {
// IntersecTerrain = length(progress_view - cameraPosition) > lViewPosM;
// if(IntersecTerrain) break;
float cumulus = GetCumulusDensity(progress_view, 1);
float cumulus = GetCumulusDensity(progress_view, 1) ;
// cumulus = max(cumulus - (1-texture2D(noisetex, (eyeplayepos + cameraPosition / 500).xz*10).b)*0.1, 0.0 );
float alteredDensity = Cumulus_density * clamp(exp( (progress_view.y - (MaxCumulusHeight - 75)) / 9.0 ),0.0,1.0);
@ -271,16 +277,16 @@ vec4 renderClouds(
float Sunlight = 0.0;
float MoonLight = 0.0;
for (int j=0; j < 3; j++){
vec3 shadowSamplePos = progress_view + (dV_Sun * 0.15) * (1 + Dither.y/2 + j);
// vec3 shadowSamplePos = progress_view + dV_Sun * (shadowStepSize[j] + Dither.y*shadowdither[j]);
// float shadow = GetCumulusDensity(shadowSamplePos, max(1-j,0)) * Cumulus_density;
vec3 shadowSamplePos = progress_view + dV_Sun * (0.1 + j * (0.1 + Dither.y*0.05));
float shadow = GetCumulusDensity(shadowSamplePos, 0) * Cumulus_density;
Sunlight += shadow / (1 + j);
Sunlight += shadow;
MoonLight += shadow;
}
#ifdef Altostratus
@ -291,15 +297,19 @@ vec4 renderClouds(
#endif
float ambientlightshadow = 1.0 - clamp(exp((progress_view.y - (MaxCumulusHeight - 50)) / 100.0),0.0,1.0) ;
// float ambientlightshadow = 1.0 - clamp(exp((progress_view.y - (MaxCumulusHeight - 50)) / 100.0),0.0,1.0) ;
float ambientlightshadow = clamp((MaxCumulusHeight - progress_view.y - 50) / 100.0, 0.0,1.0);
vec3 S = Cloud_lighting(muE, cumulus*Cumulus_density, Sunlight, MoonLight, SkyColor, sunContribution, sunContributionMulti, moonContribution, ambientlightshadow, 0, progress_view, WsunVec.y);
#ifndef TEST
S += Iris_Lightningflash_VLcloud(progress_view - cameraPosition, lightningBoltPosition.xyz) * ambientlightshadow * exp(muE * -10.0) ;
#endif
vec3 S = Cloud_lighting(muE, cumulus*Cumulus_density, Sunlight, MoonLight, SkyColor, sunContribution, sunContributionMulti, moonContribution, ambientlightshadow, 0, progress_view, 1);
S += lightningColor * exp((1.0-cumulus) * -10) * ambientlightshadow;
vec3 Sint = (S - S * exp(-mult*muE)) / muE;
vec3 Sint = (S - S * exp(-mult*muE)) / max(muE,1e-5);
color += max(muE*Sint*total_extinction,0.0);
total_extinction *= max(exp(-mult*muE),0.0);
total_extinction *= max(exp(-mult*muE),0.0);
if (total_extinction < 1e-5) break;
}
progress_view += dV_view;
@ -318,80 +328,101 @@ vec4 renderClouds(
if(altostratus > 1e-5){
for (int j = 0; j < 2; j++){
vec3 shadowSamplePos_high = progress_view_high + dV_Sun * float(j+Dither.y);
vec3 shadowSamplePos_high = progress_view_high + (dV_Sun * (1.0 - abs(WsunVec.y))) * (1 + j + Dither.y);
float shadow = GetAltostratusDensity(shadowSamplePos_high);
Sunlight += shadow;
Sunlight += shadow / (1 + j);
// vec3 shadowSamplePos_high = progress_view_high + dV_Sun * float(j+Dither.y);
// float shadow = GetAltostratusDensity(shadowSamplePos_high);
// Sunlight += shadow;
}
vec3 S = Cloud_lighting(altostratus, altostratus, Sunlight, MoonLight, SkyColor, sunContribution, sunContributionMulti, moonContribution, 1, 1, progress_view_high, timing);
vec3 Sint = (S - S * exp(-20*altostratus)) / altostratus;
vec3 Sint = (S - S * exp(-mult*altostratus)) / max(altostratus,1e-5);
color += max(altostratus*Sint*total_extinction,0.0);
total_extinction *= max(exp(-20*altostratus),0.0);
total_extinction *= max(exp(-mult*altostratus),0.0);
}
}
#endif
vec3 normView = normalize(dV_view);
// Assume fog color = sky gradient at long distance
vec3 fogColor = skyFromTex(normView, colortex4)/150. * 5.0;
float dist = max(cameraPosition.y+CumulusHeight,max(CumulusHeight,150))/(abs(normView.y)+0.001);
float fog = exp(dist / -5000.0 * (1.0+rainCloudwetness*8.));
return mix(vec4(fogColor,0.0), vec4(color,total_extinction), fog);
// return vec4(color,total_extinction);
vec4 fogColor = vec4(skyFromTex(normView, colortex4)/30.0, 0.0);
float fog = clamp(abs(max(cameraPosition.y, 255.0) + MaxCumulusHeight) / max(abs(CumulusHeight-cameraPosition.y),0.00001) * abs(normView.y/1.5),0,1);
// fog = pow(1.0 - exp(fog * -(5 - rainStrength*3)),2.0);
fog = 1.0 - clamp(exp((fog*fog) * -5.0),0.0,1.0);
// fog = 1.0;
// if(IntersecTerrain) fog = 1.0;
// return vec4(vec3(fog),0.0);
return mix(fogColor, vec4(color, total_extinction), clamp(fog,0.0,1.0));
}
#endif
float GetCloudShadow(vec3 feetPlayerPos){
#ifdef CLOUDS_SHADOWS
vec3 playerPos = feetPlayerPos + cameraPosition;
float GetCloudShadow(vec3 eyePlayerPos){
vec3 playerPos = eyePlayerPos + cameraPosition;
playerPos.y += 0.05;
float shadow = 0.0;
// assume a flat layer of cloud, and stretch the sampled density along the sunvector, starting from some vertical layer in the cloud.
#ifdef Cumulus
vec3 lowShadowStart = playerPos + WsunVec/abs(WsunVec.y) * max((MaxCumulusHeight - 70) - playerPos.y,0.0) ;
shadow += GetCumulusDensity(lowShadowStart,1)*Cumulus_density;
shadow += GetCumulusDensity(lowShadowStart, 1)*Cumulus_density;
#endif
#ifdef Altostratus
vec3 highShadowStart = playerPos + WsunVec/abs(WsunVec.y) * max(AltostratusHeight - playerPos.y,0.0);
shadow += GetAltostratusDensity(highShadowStart);
shadow += GetAltostratusDensity(highShadowStart) * 0.5;
#endif
shadow = shadow/2.0; // perhaps i should average the 2 shadows being added....
shadow = clamp(exp(-shadow*20.0),0.0,1.0);
shadow = clamp(shadow,0.0,1.0);
shadow *= shadow;
shadow = exp2(shadow * -100.0);
return shadow;
#else
return 1.0;
#endif
}
float GetCloudShadow_VLFOG(vec3 WorldPos, vec3 WorldSpace_sunVec){
#ifdef CLOUDS_SHADOWS
float shadow = 0.0;
// assume a flat layer of cloud, and stretch the sampled density along the sunvector, starting from some vertical layer in the cloud.
#ifdef Cumulus
vec3 lowShadowStart = WorldPos + WorldSpace_sunVec/abs(WorldSpace_sunVec.y) * max((MaxCumulusHeight - 60) - WorldPos.y,0.0) ;
shadow += max(GetCumulusDensity(lowShadowStart,0) - 0.2,0.0)*Cumulus_density;
shadow += max(GetCumulusDensity(lowShadowStart, 0) , 0.0)*Cumulus_density;
#endif
#ifdef Altostratus
vec3 highShadowStart = WorldPos + WorldSpace_sunVec/abs(WorldSpace_sunVec.y) * max(AltostratusHeight - WorldPos.y,0.0);
shadow += GetAltostratusDensity(highShadowStart);
shadow += GetAltostratusDensity(highShadowStart)*0.5;
#endif
// shadow = shadow/2.0; // perhaps i should average the 2 shadows being added....
shadow = clamp(exp(-shadow*255.0),0.0,1.0);
shadow = clamp(shadow,0.0,1.0);
shadow *= shadow;
// do not allow it to exist above the lowest cloud plane
// shadow *= clamp(((MaxCumulusHeight + CumulusHeight)*0.435 - WorldPos.y)/100,0.0,1.0) ;
shadow = exp2(shadow * -150.0);
return shadow;
#else
return 1.0;
#endif
}
float GetCloudSkyOcclusion(vec3 WorldPos){
#ifdef CLOUDS_SHADOWS
float shadow = 0.0;
vec3 shadowDir = vec3(0,1,0);
@ -407,4 +438,7 @@ float GetCloudSkyOcclusion(vec3 WorldPos){
shadow = clamp(exp(-shadow*25.0) ,0.0,1.0);
return shadow;
#else
return 1.0;
#endif
}

View File

@ -2,8 +2,6 @@
vec3 normVec (vec3 vec){
return vec*inversesqrt(dot(vec,vec));
}
float phaseRayleigh(float cosTheta) {
const vec2 mul_add = vec2(0.1, 0.28) /acos(-1.0);
return cosTheta * mul_add.x + mul_add.y; // optimized version from [Elek09], divided by 4 pi for energy conservation
@ -27,23 +25,24 @@ float cloudVol(in vec3 pos){
vec3 samplePos = pos*vec3(1.0,1./24.,1.0);
vec3 samplePos2 = pos*vec3(1.0,1./48.,1.0);
float fogYstart = SEA_LEVEL-6;
float mult = exp( -max((pos.y - SEA_LEVEL) / 35.,0.0));
float mult = exp( -max((pos.y - fogYstart) / 35.,0.0));
float fog_shape = 1.0 - densityAtPosFog(samplePos * 24.0 );
float fog_eroded = 1.0 - densityAtPosFog(samplePos2 * 200.0 );
// float CloudyFog = max( (fog_shape*2.0 - fog_eroded*0.5) - 1.2, max(fog_shape-0.8,0.0)) * mult;
float heightlimit = exp2( -max((pos.y - SEA_LEVEL) / 25.,0.0));
float heightlimit = exp2( -max((pos.y - fogYstart * (1.0+snowStorm)) / 25.,0.0));
float CloudyFog = max((fog_shape*1.2 - fog_eroded*0.2) - 0.75,0.0) * heightlimit ;
float UniformFog = exp2( -max((pos.y - SEA_LEVEL) / 25.,0.0));
float UniformFog = exp( max(pos.y - fogYstart,0.0) / -25) + 0.05;
// UniformFog = 1.0;
float RainFog = max(fog_shape*10. - 7.,0.5) * exp2( -max((pos.y - SEA_LEVEL) / 25.,0.0)) * 5. * rainStrength * noPuddleAreas * RainFog_amount;
// float RainFog = max(fog_shape*10. - 7.,0.5) * exp2( -max((pos.y - SEA_LEVEL) / 25.,0.0)) * 72. * rainStrength * noPuddleAreas * RainFog_amount;
float RainFog = (2 + max(fog_shape*10. - 7.,0.5)*2.0) * UniformFog * rainStrength * noPuddleAreas * RainFog_amount;
#ifdef Biome_specific_environment
#ifdef PER_BIOME_ENVIRONMENT
// sandstorms and snowstorms
if(sandStorm > 0 || snowStorm > 0) CloudyFog = mix(CloudyFog, max(densityAtPosFog((samplePos2 - vec3(frameTimeCounter,0,frameTimeCounter)*10) * 100.0 ) - 0.2,0.0) * heightlimit, sandStorm+snowStorm);
#endif
@ -53,27 +52,50 @@ float cloudVol(in vec3 pos){
return CloudyFog + UniformFog + RainFog;
}
// // uniform vec4 lightningBoltPosition;
// float Iris_Lightningflash_VLfog(vec3 feetPlayerPos, vec3 lightningBoltPos){
vec4 getVolumetricRays(
vec3 fragpos,
// vec3 LightningPos = feetPlayerPos - vec3(lightningBoltPosition.x, clamp(feetPlayerPos.y, lightningBoltPosition.y, lightningBoltPosition.y+116.0),lightningBoltPosition.z);
// // point light, max distance is ~500 blocks (the maximim entity render distance)
// float lightDistance = 300.0;
// #ifdef TEST
// float lightningLight = 0.0;
// #else
// float lightningLight = max(1.0 - length(LightningPos) / lightDistance, 0.0) ;
// lightningLight = exp((1.0 - lightningLight) * -15.0) ;
// #endif
// // lightningLight = pow(lightningLight,5.0);
// return lightningLight ;
// }
uniform bool inSpecialBiome;
vec4 GetVolumetricFog(
vec3 viewPosition,
float dither,
vec3 LightColor,
vec3 AmbientColor
){
//project pixel position into projected shadowmap space
vec3 wpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz;
vec3 wpos = mat3(gbufferModelViewInverse) * viewPosition + gbufferModelViewInverse[3].xyz;
vec3 fragposition = mat3(shadowModelView) * wpos + shadowModelView[3].xyz;
fragposition = diagonal3(shadowProjection) * fragposition + shadowProjection[3].xyz;
//project view origin into projected shadowmap space
vec3 start = toShadowSpaceProjected(vec3(0.));
vec3 start = toShadowSpaceProjected(vec3(0.0));
//rayvector into projected shadow map space
//we can use a projected vector because its orthographic projection
//however we still have to send it to curved shadow map space every step
vec3 dV = fragposition-start;
vec3 dV = fragposition - start;
vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
float maxLength = min(length(dVWorld),far)/length(dVWorld);
float maxLength = min(length(dVWorld), far)/length(dVWorld);
dV *= maxLength;
dVWorld *= maxLength;
@ -82,33 +104,42 @@ vec4 getVolumetricRays(
vec3 vL = vec3(0.);
float SdotV = dot(sunVec,normalize(fragpos))*lightCol.a;
float SdotV = dot(sunVec,normalize(viewPosition))*lightCol.a;
float dL = length(dVWorld);
//Mie phase + somewhat simulates multiple scattering (Horizon zero down cloud approx)
float mie = phaseg(SdotV,0.7)*5.0 + 1.0;
float mie = phaseg(SdotV,0.7)*5.0 + 0.1;
float rayL = phaseRayleigh(SdotV);
// Makes fog more white idk how to simulate it correctly
vec3 sunColor = lightCol.rgb / 80.0;
vec3 skyCol0 = AmbientColor / 150. * 5. ; // * max(abs(WsunVec.y)/150.0,0.);
vec3 lightningColor = (lightningEffect / 10) * (max(eyeBrightnessSmooth.y,0)/240.);
vec3 np3 = normVec(wpos);
float ambfogfade = clamp(exp(np3.y* 2 - 2),0.0,1.0) * 4 ;
skyCol0 += lightningColor * ambfogfade;
#ifdef Biome_specific_environment
// recolor change sun and sky color to some color, but make sure luminance is preserved.
BiomeFogColor(sunColor);
BiomeFogColor(skyCol0);
#endif
vec3 rC = vec3(fog_coefficientRayleighR*1e-6, fog_coefficientRayleighG*1e-5, fog_coefficientRayleighB*1e-5);
vec3 mC = vec3(fog_coefficientMieR*1e-6, fog_coefficientMieG*1e-6, fog_coefficientMieB*1e-6);
// Makes fog more white idk how to simulate it correctly
vec3 LightSourceColor = LightColor;
vec3 skyCol0 = AmbientColor / 2.0;
// recolor change sun and sky color to a color, but make sure luminance is preserved.
#ifdef PER_BIOME_ENVIRONMENT
BiomeFogColor(LightSourceColor);
BiomeFogColor(skyCol0);
#endif
// float upGradient = 1.0 - (normalize(wpos).y*0.5 + 0.5);
// skyCol0 *= exp(upGradient * -5.0)*1.5 + 0.5;
// float upGradient = np3.y;
// skyCol0 = max(skyCol0 + skyCol0*upGradient,0.0);
// #if defined Cave_fog && defined TEST
// vec3 cavefogCol = vec3(CaveFogColor_R,CaveFogColor_G,CaveFogColor_B);
// #ifdef PER_BIOME_ENVIRONMENT
// BiomeFogColor(cavefogCol);
// #endif
// cavefogCol = cavefogCol * clamp(1.0 - normalize(wpos).y, 0.0, 1.0) * 0.001 ;
// #endif
float mu = 1.0;
float muS = mu;
@ -117,7 +148,7 @@ vec4 getVolumetricRays(
vec3 WsunVec = mat3(gbufferModelViewInverse) * sunVec * lightCol.a;
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition;
vec3 progressW = gbufferModelViewInverse[3].xyz + cameraPosition;
float lightleakfix = clamp(pow(eyeBrightnessSmooth.y/240.,2) ,0.0,1.0);
for (int i=0;i<VL_SAMPLES;i++) {
@ -129,38 +160,58 @@ vec4 getVolumetricRays(
//project into biased shadowmap space
float distortFactor = calcDistort(progress.xy);
vec3 pos = vec3(progress.xy*distortFactor, progress.z);
float densityVol = cloudVol(progressW);
float sh = 1.0;
if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){
pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5;
sh = shadow2D( shadow, pos).x;
sh = shadow2D(shadow, pos).x;
}
// #ifdef TEST
// lightleakfix = 1.0;
// #endif
#ifdef VL_CLOUDS_SHADOWS
sh *= GetCloudShadow_VLFOG(progressW,WsunVec);
sh *= GetCloudShadow_VLFOG(progressW, WsunVec);
#endif
float densityVol = cloudVol(progressW) * lightleakfix;
//Water droplets(fog)
float density = densityVol*mu*300.;
//Just air
vec2 airCoef = exp(-max(progressW.y-SEA_LEVEL,0.0)/vec2(8.0e3, 1.2e3)*vec2(6.,7.0)) * 24 * Haze_amount;
vec2 airCoef = exp(-max(progressW.y - SEA_LEVEL, 0.0) / vec2(8.0e3, 1.2e3) * vec2(6.,7.0)) * 24 * Haze_amount;
//Pbr for air, yolo mix between mie and rayleigh for water droplets
vec3 rL = rC*airCoef.x;
vec3 m = (airCoef.y+density)*mC;
vec3 m = (airCoef.y+density) * mC;
vec3 DirectLight = (sunColor*sh) * (rayL*rL+m*mie);
vec3 DirectLight = (LightSourceColor*sh) * (rayL*rL*3.0 + m*mie);
vec3 AmbientLight = skyCol0 * m;
vec3 AtmosphericFog = skyCol0 * (rL+m) ;
// #ifdef TEST
// vec3 Lightning = vec3(0.0);
// #else
vec3 Lightning = Iris_Lightningflash_VLfog(progressW-cameraPosition, lightningBoltPosition.xyz) * m;
// #endif
vec3 AtmosphericFog = skyCol0 * (rL*3.0 + m);// + (LightSourceColor * sh) * (rayL*rL*3.0 + m*mie);
// extra fog effects
vec3 rainRays = (sunColor*sh) * (rayL*phaseg(SdotV,0.5)) * clamp(pow(WsunVec.y,5)*2,0.0,1) * rainStrength * noPuddleAreas * RainFog_amount * 0.5;
vec3 CaveRays = (sunColor*sh) * phaseg(SdotV,0.7) * 0.001 * (1.0 - lightleakfix);
// vec3 rainRays = (LightSourceColor*sh) * (rayL*(phaseg(SdotV,0.7))) * clamp(pow(WsunVec.y,5)*2,0.0,1) * rainStrength * noPuddleAreas * RainFog_amount;
// vec3 CaveRays = (LightSourceColor*sh) * phaseg(SdotV,0.7) * 0.001 * (1.0 - lightleakfix);
vec3 vL0 = (DirectLight + AmbientLight + AtmosphericFog + rainRays ) * lightleakfix ;
vec3 vL0 = (AtmosphericFog + AmbientLight + DirectLight + Lightning) * lightleakfix;
// #if defined Cave_fog && defined TEST
// vL0 += cavefogCol;
// #endif
vL += (vL0 - vL0 * exp(-(rL+m)*dd*dL)) / ((rL+m)+0.00000001)*absorbance;
@ -169,10 +220,10 @@ vec4 getVolumetricRays(
return vec4(vL,absorbance);
}
/*
/// really dumb lmao
vec4 InsideACloudFog(
vec3 fragpos,
vec3 viewPosition,
vec2 Dither,
vec3 SunColor,
vec3 MoonColor,
@ -182,7 +233,7 @@ vec4 InsideACloudFog(
vec3 color = vec3(0.0);
//project pixel position into projected shadowmap space
vec3 wpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz;
vec3 wpos = mat3(gbufferModelViewInverse) * viewPosition + gbufferModelViewInverse[3].xyz;
vec3 fragposition = mat3(shadowModelView) * wpos + shadowModelView[3].xyz;
fragposition = diagonal3(shadowProjection) * fragposition + shadowProjection[3].xyz;
@ -212,7 +263,7 @@ vec4 InsideACloudFog(
float shadowStep = 200.;
vec3 dV_Sun = normalize(mat3(gbufferModelViewInverse)*sunVec)*shadowStep;
float SdotV = dot(sunVec,normalize(fragpos));
float SdotV = dot(sunVec,normalize(viewPosition));
SkyColor *= clamp(abs(dV_Sun.y)/100.,0.75,1.0);
SunColor = SunColor * clamp(dV_Sun.y ,0.0,1.0);
@ -222,7 +273,7 @@ vec4 InsideACloudFog(
float fogSdotV = dot(sunVec,normalize(fragpos))*lightCol.a;
float fogSdotV = dot(sunVec,normalize(viewPosition))*lightCol.a;
float fogmie = phaseg(fogSdotV,0.7)*5.0 + 1.0;
// Makes fog more white idk how to simulate it correctly
@ -258,7 +309,7 @@ vec4 InsideACloudFog(
float mie = phaseg(SdotV,0.7)*5.0 + 1.0;
float rayL = phaseRayleigh(SdotV);
#ifdef Biome_specific_environment
#ifdef PER_BIOME_ENVIRONMENT
// recolor change sun and sky color to some color, but make sure luminance is preserved.
BiomeFogColor(Fog_SunCol);
BiomeFogColor(Fog_SkyCol);
@ -366,4 +417,5 @@ vec4 InsideACloudFog(
if (total_extinction < 1e-5) break;
}
return vec4(color, total_extinction);
}
}
*/