mirror of
https://github.com/X0nk/Bliss-Shader.git
synced 2025-06-22 00:37:35 +08:00
Screenspace subsurface scattering, and various tweaks
good old SSSSS. tweaked bitmask handling for SSS, is packed in the same buffer as labSSS
This commit is contained in:
@ -21,13 +21,13 @@ uniform sampler2D colortex4;//Skybox
|
||||
#define WEATHERCLOUDS
|
||||
#include "/lib/climate_settings.glsl"
|
||||
|
||||
float CumulusHeight = 250;
|
||||
float CumulusHeight = Cumulus_height;
|
||||
float MaxCumulusHeight = CumulusHeight + 100;
|
||||
|
||||
float AltostratusHeight = 2000;
|
||||
|
||||
float rainCloudwetness = rainStrength;
|
||||
float cloud_movement = frameTimeCounter * 0;
|
||||
float cloud_movement = frameTimeCounter * Cloud_Speed;
|
||||
|
||||
//3D noise from 2d texture
|
||||
float densityAtPos(in vec3 pos){
|
||||
@ -49,15 +49,14 @@ 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 + CumulusHeight)*0.46, 0.0) / 200;
|
||||
float Topshape = max(pos.y - (MaxCumulusHeight - 75), 0.0) / 200;
|
||||
Topshape += max(exp((pos.y - MaxCumulusHeight) / 10.0 ), 0.0) ;
|
||||
|
||||
float coverage = abs(pow(CloudLarge,1)*2.0 - 1.2)*0.5 - (1.0-CloudSmall);
|
||||
|
||||
float FinalShape = DailyWeather_Cumulus(coverage) - Topshape;
|
||||
|
||||
// cap the top and bottom for reasons
|
||||
float capbase = sqrt(max(CumulusHeight*1.05 - pos.y, 0.0)/50) ;
|
||||
float capbase = sqrt(max((CumulusHeight+12.5) - pos.y, 0.0)/50) ;
|
||||
float captop = max(pos.y - MaxCumulusHeight, 0.0);
|
||||
|
||||
FinalShape = max(FinalShape - capbase - captop, 0.0);
|
||||
@ -88,12 +87,14 @@ float cloudVol(in vec3 pos,in vec3 samplePos,in float cov, in int LoD){
|
||||
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);
|
||||
@ -130,8 +131,7 @@ vec3 Cloud_lighting(
|
||||
vec3 moonContribution,
|
||||
float AmbientShadow,
|
||||
int cloudType,
|
||||
vec3 pos,
|
||||
float altoShadow
|
||||
vec3 pos
|
||||
){
|
||||
float coeeff = -30;
|
||||
// float powder = 1.0 - exp((CloudShape*CloudShape) * -800);
|
||||
@ -166,6 +166,7 @@ vec3 Cloud_lighting(
|
||||
// return skyLighting;
|
||||
}
|
||||
|
||||
|
||||
//Mie phase function
|
||||
float phaseg(float x, float g){
|
||||
float gg = g * g;
|
||||
@ -183,6 +184,13 @@ float CustomPhase(float LightPos, float S_1, float S_2){
|
||||
return A;
|
||||
}
|
||||
|
||||
float PhaseHG(float cosTheta, float g) {
|
||||
float denom = 1 + g * g + 2 * g * cosTheta;
|
||||
const float Inv4Pi = 0.07957747154594766788;
|
||||
|
||||
return Inv4Pi * (1 - g * g) / (denom * sqrt(denom));
|
||||
}
|
||||
|
||||
vec4 renderClouds(
|
||||
vec3 FragPosition,
|
||||
vec2 Dither,
|
||||
@ -235,7 +243,7 @@ vec4 renderClouds(
|
||||
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) * 2;
|
||||
float mieDayMulti = phaseg(SdotV, 0.35) * 2;
|
||||
|
||||
@ -244,16 +252,16 @@ vec4 renderClouds(
|
||||
|
||||
float mieNight = (phaseg(-SdotV,0.8) + phaseg(-SdotV, 0.35)*4) * 6.0;
|
||||
vec3 moonContribution = MoonColor * mieNight;
|
||||
|
||||
|
||||
#ifdef Cumulus
|
||||
for(int i=0;i<maxIT_clouds;i++) {
|
||||
|
||||
// IntersecTerrain = length(progress_view - cameraPosition) > lViewPosM;
|
||||
// if(IntersecTerrain) break;
|
||||
|
||||
float cumulus = GetCumulusDensity(progress_view, cloudLoD);
|
||||
|
||||
float alteredDensity = Cumulus_density * clamp(exp( (progress_view.y - (MaxCumulusHeight + CumulusHeight)*0.455) / 9.0 ),0.0,1.0);
|
||||
|
||||
float alteredDensity = Cumulus_density * clamp(exp( (progress_view.y - (MaxCumulusHeight - 75)) / 9.0 ),0.0,1.0);
|
||||
|
||||
if(cumulus > 1e-5){
|
||||
float muE = cumulus*alteredDensity;
|
||||
@ -278,9 +286,11 @@ vec4 renderClouds(
|
||||
float HighAlt_shadow = GetAltostratusDensity(HighAlt_shadowPos);
|
||||
Sunlight += HighAlt_shadow;
|
||||
#endif
|
||||
|
||||
float phase = PhaseHG(-SdotV, (1.0-cumulus));
|
||||
|
||||
float ambientlightshadow = 1.0-clamp(exp((progress_view.y - (MaxCumulusHeight + CumulusHeight)*0.5) / 100.0),0.0,1.0);
|
||||
vec3 S = Cloud_lighting(muE, cumulus*Cumulus_density, Sunlight, MoonLight, SkyColor, sunContribution, sunContributionMulti, moonContribution, ambientlightshadow, 0, progress_view, HighAlt_shadow);
|
||||
float ambientlightshadow = 1.0-clamp(exp((progress_view.y - (MaxCumulusHeight - 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);
|
||||
|
||||
vec3 Sint = (S - S * exp(-mult*muE)) / muE;
|
||||
color += max(muE*Sint*total_extinction,0.0);
|
||||
@ -308,7 +318,7 @@ vec4 renderClouds(
|
||||
float shadow = GetAltostratusDensity(shadowSamplePos_high);
|
||||
Sunlight += shadow;
|
||||
}
|
||||
vec3 S = Cloud_lighting(altostratus, altostratus, Sunlight, MoonLight, SkyColor, sunContribution, sunContributionMulti, moonContribution, 1, 1, progress_view_high, 0);
|
||||
vec3 S = Cloud_lighting(altostratus, altostratus, Sunlight, MoonLight, SkyColor, sunContribution, sunContributionMulti, moonContribution, 1, 1, progress_view_high);
|
||||
|
||||
vec3 Sint = (S - S * exp(-20*altostratus)) / altostratus;
|
||||
color += max(altostratus*Sint*total_extinction,0.0);
|
||||
@ -320,7 +330,7 @@ vec4 renderClouds(
|
||||
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,CumulusHeight)/abs(normView.y);
|
||||
float dist = max(cameraPosition.y+CumulusHeight,abs(CumulusHeight))/abs(normView.y);
|
||||
float fog = exp(dist / -5000.0 * (1.0+rainCloudwetness*8.));
|
||||
|
||||
// if(IntersecTerrain) fog = 1.0;
|
||||
@ -329,6 +339,9 @@ vec4 renderClouds(
|
||||
// return vec4(color,total_extinction);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
float GetCloudShadow(vec3 eyePlayerPos){
|
||||
vec3 playerPos = eyePlayerPos + cameraPosition;
|
||||
playerPos.y += 0.05;
|
||||
@ -336,8 +349,8 @@ float GetCloudShadow(vec3 eyePlayerPos){
|
||||
|
||||
// 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 + CumulusHeight)*0.44 - playerPos.y,0.0) ;
|
||||
shadow += GetCumulusDensity(lowShadowStart,1)*cloudDensity;
|
||||
vec3 lowShadowStart = playerPos + WsunVec/abs(WsunVec.y) * max((MaxCumulusHeight - 70) - playerPos.y,0.0) ;
|
||||
shadow += GetCumulusDensity(lowShadowStart,1)*Cumulus_density;
|
||||
#endif
|
||||
|
||||
#ifdef Altostratus
|
||||
@ -346,7 +359,7 @@ float GetCloudShadow(vec3 eyePlayerPos){
|
||||
#endif
|
||||
|
||||
shadow = shadow/2.0; // perhaps i should average the 2 shadows being added....
|
||||
shadow = clamp(exp(-shadow*15.0),0.0,1.0);
|
||||
shadow = clamp(exp(-shadow*20.0),0.0,1.0);
|
||||
|
||||
return shadow;
|
||||
}
|
||||
@ -356,8 +369,8 @@ float GetCloudShadow_VLFOG(vec3 WorldPos){
|
||||
|
||||
// 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 + WsunVec/abs(WsunVec.y) * max((MaxCumulusHeight + CumulusHeight)*0.435 - WorldPos.y,0.0) ;
|
||||
shadow += GetCumulusDensity(lowShadowStart,0)*cloudDensity;
|
||||
vec3 lowShadowStart = WorldPos + WsunVec/abs(WsunVec.y) * max((MaxCumulusHeight - 70) - WorldPos.y,0.0) ;
|
||||
shadow += GetCumulusDensity(lowShadowStart,0)*Cumulus_density;
|
||||
#endif
|
||||
|
||||
#ifdef Altostratus
|
||||
@ -379,7 +392,7 @@ float GetAltoOcclusion(vec3 eyePlayerPos){
|
||||
vec3 playerPos = eyePlayerPos + cameraPosition;
|
||||
playerPos.y += 0.05;
|
||||
float shadow;
|
||||
vec3 lowShadowStart = playerPos + normalize(vec3(0,1,0)) * max((MaxCumulusHeight + CumulusHeight)*0.433 - playerPos.y,0.0) ;
|
||||
vec3 lowShadowStart = playerPos + normalize(vec3(0,1,0)) * max((MaxCumulusHeight - 70) - playerPos.y,0.0) ;
|
||||
shadow = GetCumulusDensity(lowShadowStart,0) * cloudDensity;
|
||||
|
||||
shadow = clamp(exp(shadow * -1),0.0,1.0);
|
||||
|
Reference in New Issue
Block a user