Skip to content

Commit

Permalink
Improved cloud rendering (tippesi#25)
Browse files Browse the repository at this point in the history
* Better clouds with perlin noise

* Better cloud integration

* Added better phase function

* Using blue noise for clouds

* Improved secondary cloud noise

* Cloud height changes

* Significantly improved quality of clouds

* New icon, updated license, clouds have dark edges

* Cloud fog integration works well now

* Pause application when it is hidden

* Fixed shadow integrator for cloud rendering

* Fixed bugs regarding window minimizing on Windows

* Fixed instance extension issue when profiling from Nsight

* Final cloud settings

* Default cloud settings

* Changed default scene to Sponza again
  • Loading branch information
tippesi authored Mar 8, 2023
1 parent feae867 commit 13e0eb9
Show file tree
Hide file tree
Showing 34 changed files with 524 additions and 227 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Simon Tippe
Copyright (c) 2023 Simon Tippe

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Binary file modified data/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions data/shader/clouds/clouds.hsh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,72 @@ float Worley(vec3 pos, float scale, float seed) {

}

// Perlin noise from Brian Sharpe
// http://briansharpe.wordpress.com
// https://github.com/BrianSharpe
void FAST32_hash_3D(vec3 gridcell,
vec3 scale,
out vec4 lowz_hash_0,
out vec4 lowz_hash_1,
out vec4 lowz_hash_2,
out vec4 highz_hash_0,
out vec4 highz_hash_1,
out vec4 highz_hash_2) {
const vec2 OFFSET = vec2( 50.0, 161.0 );
const float DOMAIN = 69.0;
const vec3 SOMELARGEFLOATS = vec3( 635.298681, 682.357502, 668.926525 );
const vec3 ZINC = vec3( 48.500388, 65.294118, 63.934599 );

// truncate the domain
gridcell.xyz = gridcell.xyz - floor(gridcell.xyz * ( 1.0 / DOMAIN )) * DOMAIN;
vec3 gridcell_inc1 = step( gridcell, vec3( DOMAIN - 1.5 ) ) * ( gridcell + 1.0 );

gridcell_inc1 = mod(gridcell_inc1, scale);

// calculate the noise
vec4 P = vec4( gridcell.xy, gridcell_inc1.xy ) + OFFSET.xyxy;
P *= P;
P = P.xzxz * P.yyww;
vec3 lowz_mod = vec3( 1.0 / ( SOMELARGEFLOATS.xyz + gridcell.zzz * ZINC.xyz ) );
vec3 highz_mod = vec3( 1.0 / ( SOMELARGEFLOATS.xyz + gridcell_inc1.zzz * ZINC.xyz ) );
lowz_hash_0 = fract( P * lowz_mod.xxxx );
highz_hash_0 = fract( P * highz_mod.xxxx );
lowz_hash_1 = fract( P * lowz_mod.yyyy );
highz_hash_1 = fract( P * highz_mod.yyyy );
lowz_hash_2 = fract( P * lowz_mod.zzzz );
highz_hash_2 = fract( P * highz_mod.zzzz );
}

vec3 Interpolation_C2( vec3 x ) { return x * x * x * (x * (x * 6.0 - 15.0) + 10.0); }

float Perlin3D(vec3 P, float scale) {
vec3 Pi = floor(P);
vec3 Pf = P - Pi;
vec3 Pf_min1 = Pf - 1.0;

vec4 hashx0, hashy0, hashz0, hashx1, hashy1, hashz1;
FAST32_hash_3D(Pi, vec3(scale), hashx0, hashy0, hashz0, hashx1, hashy1, hashz1 );

// calculate the gradients
vec4 grad_x0 = hashx0 - 0.49999;
vec4 grad_y0 = hashy0 - 0.49999;
vec4 grad_z0 = hashz0 - 0.49999;
vec4 grad_x1 = hashx1 - 0.49999;
vec4 grad_y1 = hashy1 - 0.49999;
vec4 grad_z1 = hashz1 - 0.49999;
vec4 grad_results_0 = inversesqrt( grad_x0 * grad_x0 + grad_y0 * grad_y0 + grad_z0 * grad_z0 ) * ( vec2( Pf.x, Pf_min1.x ).xyxy * grad_x0 + vec2( Pf.y, Pf_min1.y ).xxyy * grad_y0 + Pf.zzzz * grad_z0 );
vec4 grad_results_1 = inversesqrt( grad_x1 * grad_x1 + grad_y1 * grad_y1 + grad_z1 * grad_z1 ) * ( vec2( Pf.x, Pf_min1.x ).xyxy * grad_x1 + vec2( Pf.y, Pf_min1.y ).xxyy * grad_y1 + Pf_min1.zzzz * grad_z1 );

// Classic Perlin Interpolation
vec3 blend = Interpolation_C2( Pf );
vec4 res0 = mix( grad_results_0, grad_results_1, blend.z );
vec4 blend2 = vec4( blend.xy, vec2( 1.0 - blend.xy ) );
float final = dot( res0, blend2.zxzx * blend2.wwyy );
final /= sqrt(0.75);
return 0.5 * final + 0.5;

}

float Worley4Octaves(vec3 pos, float scale, float seed, vec4 weights) {

float octave0 = Worley(pos, 1.0 * scale, seed) * weights.x;
Expand All @@ -43,6 +109,15 @@ float Worley4Octaves(vec3 pos, float scale, float seed, vec4 weights) {

}

float Perlin2Octaves(vec3 pos, float scale, vec2 weights) {

float octave0 = Perlin3D(pos * scale, scale) * weights.x;
float octave1 = Perlin3D(pos * 2.0 * scale, 2.0 * scale) * weights.y;

return 0.5 * ((octave0 + octave1) / sum(weights)) + 0.5;

}

float Remap(float originalValue, float originalMin, float originalMax, float newMin, float newMax) {
return newMin + (((originalValue - originalMin) / (originalMax - originalMin)) * (newMax - newMin));
}
Expand Down
Loading

0 comments on commit 13e0eb9

Please sign in to comment.