Skip to content

Commit

Permalink
[AtmosphericScattering] Improved day so that you can actually see a b…
Browse files Browse the repository at this point in the history
…lue gradient instead of the stars
  • Loading branch information
PanosK92 committed Nov 20, 2023
1 parent 11efe39 commit efa98d3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions data/shaders/atmospheric_scattering.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct space

struct sun
{
static float3 compute_mie_scatter_color(float3 view_direction, float3 sun_direction, float mie = 0.01f, float mie_g = -0.9f)
static float3 compute_mie_scatter_color(float3 view_direction, float3 sun_direction, float mie = 0.01f, float mie_g = -0.95f)
{
const float mie_g2 = mie_g * mie_g;

Expand Down Expand Up @@ -133,7 +133,7 @@ struct atmosphere
float3 p1 = position + view_dir * (hm - h);
float3 view_ray_length = p1 - p0;
float cos_theta = dot(view_dir, sun_dir);
float phase = 0.75f * (1.0f + cos_theta * cos_theta);
float phase = (1.0f + cos_theta * cos_theta) * 2.2f; // 2.2 is empirically chosen, it looks good
float optical_depth_r = exp(-h / h0) * length(view_ray_length) / dot(view_dir, float3(0, -1, 0));
float3 scatter = rayleigh_beta * phase * optical_depth_r;

Expand Down
7 changes: 3 additions & 4 deletions data/shaders/common_structs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,9 @@ struct Light
if (light_is_directional())
{
float2 uv = direction_sphere_uv(-forward);
uint mip_level = ENVIRONMENT_MAX_MIP - 3; // instead of taking multiple samples around the direction of the
// sun, we'll use a blurry mip to "capture" more light from that direction
color = tex_environment.SampleLevel(samplers[sampler_trilinear_clamp], uv, mip_level).rgb;
intensity = luminance(color) * 20.0f;
uint mip_level = 8; // sample higher mip to capture more light along that direction
color = tex_environment.SampleLevel(samplers[sampler_trilinear_clamp], uv, mip_level).rgb;
intensity = luminance(color) * 10.0f;
}

// apply occlusion
Expand Down
1 change: 1 addition & 0 deletions runtime/World/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ namespace Spartan
light->SetTemperature(2300.0f);
light->SetIntensity(sun_intensity);
light->SetShadowsEnabled(shadows_enabled ? (light->GetIntensityLumens() > 0.0f) : false);
light->SetShadowsTransparentEnabled(false);
}

// music
Expand Down

0 comments on commit efa98d3

Please sign in to comment.