Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

Adding Continuums True Volumetric Clouds

All Code Goes In Composite1.fsh

on line 36 Copy and Paste this code in


///////////////////////////////////////////////////////////////////////////////////
////////////////////////////
#define TRUE_VOLUMETRIC_CLOUDS //True Volumetric clouds from Continuum
#define SOFT_FLUFFY_CLOUDS // dissable to fully
remove dither Pattern ripple, adds a little pixel noise on cloud edge
#define Volumetric_Cloud_Type //Turn this off to change the
way Volumetric clouds are rendered,If off there will be less detail in the clouds
BUT there will be less Dither Pattern ripple in them. Best set Vol_Cloud_Coverage
to 0.52 if off!
#define Cloud3Height 200 //[100 120 140 160 180
200 220 240 250] //Sets the Volumetric clouds3 Height
#define VOLUMETRIC_CLOUD_SPEED 2.0 //[0.1 0.2 0.3 0.4 0.5 0.6
0.7 0.8 0.9 1.0 1.2 1.4 1.6 1.8 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5
8.0] //Default is 2.0f, Lower number to slow speed, Higher number to increase speed

#define CLOUD_DISPERSE 10.0f // increase this for thicker


clouds and so that they don't fizzle away when you fly close to them, 10 is default
Dont Go Over 30 will lag and maybe crash
#define Vol_Cloud_Coverage 0.48 // Vol_Cloud_Coverage. 0.20 =
Lowest Cover. 0.60 = Highest Cover [0.20 0.30 0.35 0.40 0.45 0.48 0.50 0.52 0.55
0.60 0.70]

///////////////////////////////////////////////////////////////////////////////////
////////////////////////////

On Line 1662 Hit ENTER And Copy And Paste This Code In
///////////////////////////////////////////////////////////////////////////////////
////////////////////////////
float Get3DNoise2(in vec3 pos)
{
pos.z += 0.0f;

vec3 p = floor(pos);
vec3 f = fract(pos);

vec2 uv = (p.xy + p.z * vec2(17.0f)) + f.xy;


vec2 uv2 = (p.xy + (p.z + 1.0f) * vec2(17.0f)) + f.xy;

vec2 coord = (uv + 0.5f) / noiseTextureResolution;


vec2 coord2 = (uv2 + 0.5f) / noiseTextureResolution;

float xy1 = texture2D(noisetex, coord).x;


float xy2 = texture2D(noisetex, coord2).x;
return mix(xy1, xy2, f.z);
}

float Get3DNoise3(in vec3 pos)


{
pos.z += 0.0f;

pos.xyz += 0.5f;

vec3 p = floor(pos);
vec3 f = fract(pos);

f.x = f.x * f.x * (3.0f - 2.0f * f.x);


f.y = f.y * f.y * (3.0f - 2.0f * f.y);
f.z = f.z * f.z * (3.0f - 2.0f * f.z);

vec2 uv = (p.xy + p.z * vec2(17.0f)) + f.xy;


vec2 uv2 = (p.xy + (p.z + 1.0f) * vec2(17.0f)) + f.xy;

uv -= 0.5f;
uv2 -= 0.5f;

vec2 coord = (uv + 0.5f) / noiseTextureResolution;


vec2 coord2 = (uv2 + 0.5f) / noiseTextureResolution;
float xy1 = texture2D(noisetex, coord).x;
float xy2 = texture2D(noisetex, coord2).x;
return mix(xy1, xy2, f.z);
}

float GetCoverage2(in float coverage, in float density, in float clouds)


{
clouds = clamp(clouds - (1.0f - coverage), 0.0f, 1.0f -density) / (1.0f -
density);
clouds = max(0.0f, clouds * 1.1f - 0.1f);
clouds = clouds = clouds * clouds * (3.0f - 2.0f * clouds);

return clouds;
}

///////////////////////////////////////////////////////////////////////////////////
////////////////////////////

On Line 1961 Hit ENTER And Copy And Paste This Code In
///////////////////////////////////////////////////////////////////////////////////
////////////////////////////
vec4 CloudColor3(in vec4 worldPosition, in float sunglow, in vec3 worldLightVector)
{
float cloudHeight = Cloud3Height;

float cloudDepth = 150.0f;

float cloudUpperHeight = cloudHeight + (cloudDepth / 2.0f);


float cloudLowerHeight = cloudHeight - (cloudDepth / 2.0f);

if (worldPosition.y < cloudLowerHeight || worldPosition.y > cloudUpperHeight)


return vec4(0.0f);
else
{

vec3 p = worldPosition.xyz / 150.0f;

float t = frameTimeCounter * VOLUMETRIC_CLOUD_SPEED ;


#ifdef Volumetric_Cloud_Type
p.x -= t * 0.02f;

vec3 p1 = p * vec3(1.0f, 0.5f, 1.0f) + vec3(0.0f, t * 0.01f, 0.0f);


float noise = Get3DNoise2(p)
* 1.0f; p *= 4.0f; p.x += t * 0.02f; vec3 p2 = p;
noise += (1.0f - abs(Get3DNoise2(p) * 3.0f - 1.0f)) * 0.20f;
p *= 3.0f; p.xz += t * 0.05f;
noise += (1.0f - abs(Get3DNoise2(p) * 3.0f - 1.5f)-0.2) *
0.065f; p.xz -=t * 0.165f; p.xz += t * 0.05f;
noise += (1.0f - abs(Get3DNoise2(p) * 3.0f - 1.0f)) * 0.05f;
p *= 2.0f;
noise += (1.0 - abs(Get3DNoise3(p) * 2.0 - 1.0)) * 0.015f;
noise /= 1.2f;

#else

t *= 0.0095;

p.x *= 0.5f;
p.x -= t * 0.01f;

vec3 p1 = p * vec3(1.0f, 0.5f, 1.0f) + vec3(0.0f, t * 0.01f, 0.0f);

float noise = Get3DNoise(p * vec3(1.0f, 0.5f, 1.0f) + vec3(0.0f, t *


0.01f, 0.0f)) * 1.3; p *= 2.0f; p.x -= t * 0.557f; vec3 p2 = p;
noise += (2.0f - abs(Get3DNoise(p) * 2.0f - 0.0f)) * (0.35f);
p *= 3.0f; p.xz -= t * 0.905f; p.x *= 2.0f;
vec3 p3 = p; float largeNoise = noise;
noise += (3.0f - abs(Get3DNoise(p) * 3.0f - 0.0f)) * (0.085f);
p *= 3.0f; p.xz -= t * 3.905f; vec3 p4 = p;
noise += (3.0f - abs(Get3DNoise(p) * 3.0f - 0.0f)) * (0.035f);
p *= 3.0f; p.xz -= t * 3.905f;
noise += ((Get3DNoise(p))) * (0.04f);
p *= 3.0f;
noise /= 2.375f;

#endif

const float lightOffset = 0.3f;

float heightGradient = clamp(( - (cloudLowerHeight - worldPosition.y) /


(cloudDepth * 1.0f)), 0.0f, 1.0f);
float heightGradient2 = clamp(( - (cloudLowerHeight - (worldPosition.y
+ worldLightVector.y * lightOffset * 150.0f)) / (cloudDepth * 1.0f)), 0.0f, 1.0f);

float cloudAltitudeWeight = 1.0f - clamp(distance(worldPosition.y,


cloudHeight) / (cloudDepth / 2.0f), 0.0f, 1.0f);
cloudAltitudeWeight = (-cos(cloudAltitudeWeight * 3.1415f)) *
0.5 + 0.5;
cloudAltitudeWeight = pow(cloudAltitudeWeight, mix(0.33f, 0.8f,
rainStrength));

float cloudAltitudeWeight2 = 1.0f - clamp(distance(worldPosition.y +


worldLightVector.y * lightOffset * 150.0f, cloudHeight) / (cloudDepth / 2.0f),
0.0f, 1.0f);
cloudAltitudeWeight2 = (-cos(cloudAltitudeWeight2 * 3.1415f)) *
0.5 + 0.5;
cloudAltitudeWeight2 = pow(cloudAltitudeWeight2, mix(0.33f,
0.8f, rainStrength));

noise *= cloudAltitudeWeight;

//cloud edge
float rainy = mix(wetness, 1.0f, rainStrength);
float coverage = Vol_Cloud_Coverage + rainy * 0.335;
coverage = mix(coverage, 0.77f, rainStrength);

float dist = length(worldPosition.xz - cameraPosition.xz);


coverage *= max(0.0f, 1.0f - dist / 40000.0f);

float density = 0.90f;


noise = GetCoverage2(coverage, density, noise);
noise = pow(noise, 1.5);

if (noise <= 0.001f)


{
return vec4(0.0f, 0.0f, 0.0f, 0.0f);
}

float sundiff = Get3DNoise3(p1 + worldLightVector.xyz * lightOffset);


sundiff += (1.0 - abs(Get3DNoise3(p2 + worldLightVector.xyz *
lightOffset / 2.0f) * 1.0f - 0.5f) - 0.1) * 0.55f;
sundiff *= 0.955f;
sundiff *= cloudAltitudeWeight2;
float preCoverage = sundiff;
sundiff = -GetCoverage2(coverage * 1.0f, density * 0.5, sundiff);

float sundiff2 = -GetCoverage2(coverage * 1.0f, 0.0, preCoverage);


float firstOrder = pow(clamp(sundiff * 1.2f + 1.7f, 0.0f, 1.0f), 8.0f);
float secondOrder = pow(clamp(sundiff2 * 1.2f + 1.1f, 0.0f, 1.0f),
4.0f);

float anisoBackFactor = mix(clamp(pow(noise, 1.6f) * 2.5f, 0.0f, 1.0f), 1.0f,


pow(sunglow, 1.0f));
firstOrder *= anisoBackFactor * 0.99 + 0.01;
secondOrder *= anisoBackFactor * 1.19 + 0.9;

float directLightFalloff = clamp(pow(-(cloudLowerHeight - worldPosition.y) /


cloudDepth, 3.5f), 0.0f, 1.0f);
directLightFalloff *= mix( clamp(pow(noise, 0.9f), 0.0f, 1.0f),
clamp(pow(1.0f - noise, 10.3f), 0.0f, 0.5f), pow(sunglow, 0.2f));

vec3 colorDirect = colorSunlight * 4.0f;


colorDirect = mix(colorDirect, colorDirect * vec3(0.1f, 0.2f, 0.3f)*2,
timeMidnight);
colorDirect = mix(colorDirect, colorDirect * vec3(0.2f, 0.2f, 0.2f),
rainStrength);
colorDirect *= 1.0f + pow(sunglow, 2.0f) * 50.0f;

vec3 colorAmbient = mix(colorSkylight, colorSunlight, 0.15f) * 0.065f;


colorAmbient *= mix(1.0f, 0.3f, timeMidnight);

vec3 colorBounced = colorBouncedSunlight * 0.35f;


colorBounced *= pow((1.0f - heightGradient), 12.0f);
colorBounced *= anisoBackFactor + 0.5;
colorBounced *= 1.0 - rainStrength;

vec3 color = mix(colorAmbient, colorDirect, vec3(directLightFalloff));


// color += colorBounced;

//color *= 1.0f;

vec4 result = vec4(color.rgb, noise);


return result;
}
}

void CalculateClouds (inout vec3 color, inout SurfaceStruct surface)


{
surface.cloudAlpha = 0.0f;

vec2 coord = texcoord.st * 2.0f;

vec4 worldPosition = gbufferModelViewInverse *


surface.screenSpacePosition;
worldPosition.xyz += cameraPosition.xyz;

float cloudHeight = 150.0f;


float cloudDepth = 140.0f;
float cloudDensity = 1.0f;

float startingRayDepth = far - 5.0f;

float rayDepth = startingRayDepth;

float rayIncrement = far / CLOUD_DISPERSE;

#ifdef SOFT_FLUFFY_CLOUDS
rayDepth += CalculateDitherPattern1() * rayIncrement;
#else
rayDepth += CalculateDitherPattern2() * rayIncrement;
#endif

int i = 0;

vec3 cloudColor3 = colorSunlight;


vec4 cloudSum = vec4(0.0f);
cloudSum.rgb = color.rgb;

float sunglow = min(CalculateSunglow(surface), 2.0);

float cloudDistanceMult = 400.0f / far;

float surfaceDistance = length(worldPosition.xyz - cameraPosition.xyz);

while (rayDepth > 0.0f) {


//determine worldspace ray position
vec4 rayPosition = GetCloudSpacePosition(texcoord.st, rayDepth,
cloudDistanceMult);

float rayDistance = length((rayPosition.xyz - cameraPosition.xyz)


/ cloudDistanceMult);

vec4 proximity = CloudColor3(rayPosition, sunglow/1.2,


surface.worldLightVector);
proximity.a *= cloudDensity;

if (surfaceDistance < rayDistance * cloudDistanceMult &&


surface.mask.sky == 0.0)
proximity.a = 0.0f;
cloudSum.rgb = mix( cloudSum.rgb, proximity.rgb, vec3(min(1.0f,
proximity.a * cloudDensity)) );
cloudSum.a += proximity.a * cloudDensity;

surface.cloudAlpha += proximity.a;

//Increment ray
rayDepth -= rayIncrement;
i++;
}

color.rgb = mix(color.rgb, cloudSum.rgb, vec3(min(1.0f, cloudSum.a *


50.0f)));

if (cloudSum.a > 0.00f)


{
surface.mask.volumeCloud = 1.0;
}
}

///////////////////////////////////////////////////////////////////////////////////
////////////////////////////

On Line 3204 Hit ENTER And Copy And Paste This Code IN
///////////////////////////////////////////////////////////////////////////////////
////////////////////////////
#ifdef TRUE_VOLUMETRIC_CLOUDS
CalculateClouds(finalComposite.rgb, surface);
#endif

///////////////////////////////////////////////////////////////////////////////////
////////////////////////////

And Enjoy True Volumetric Clouds!

You might also like