Skip to content

Commit

Permalink
[Renderer] Made snow fade in smoother
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosK92 committed Dec 21, 2023
1 parent 5bee472 commit 5f29a3a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions data/shaders/g_buffer.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct sampling
const float sea_level = 0.0f;
const float sand_offset = 4.0f; // how high above sea level the sand should extend
const float snow_level = 55.0f;
const float snow_height = 60.0f; // this is the height at which the terrain is fully covered in snow
const float snow_height = 80.0f; // this is the height at which the terrain is fully covered in snow
const uint texture_index_rock = texture_index + 1;
const uint texture_index_sand = texture_index + 2;
const uint texture_index_snow = texture_index + 3;
Expand Down Expand Up @@ -137,10 +137,19 @@ struct sampling
float4 color = GET_TEXTURE(texture_index).Sample(GET_SAMPLER(sampler_anisotropic_wrap), uv);

// implies vegetation - in which case, blend with some white/snow if the elevation is high enough
if (material_vertex_animate_wind() && (position_world.y > snow_level + 15.0f))
{
float blend_factor = saturate((position_world.y - snow_level) / (snow_height - snow_level));
color.rgb = lerp(color.rgb, 1.0f, saturate(blend_factor - 0.2f));
if (material_vertex_animate_wind() && (position_world.y > snow_level))
{
// calculate a smooth blend factor
float elevation_difference = position_world.y - snow_level;
float transition_range = snow_height - snow_level;
float blend_factor = elevation_difference / transition_range;
blend_factor = saturate(blend_factor);

// smooth step for even smooth transition
blend_factor = smoothstep(0.0f, 1.0f, blend_factor);

// blend the vegetation color with white
color.rgb = lerp(color.rgb, 1.0f, blend_factor);
}

return color;
Expand Down

0 comments on commit 5f29a3a

Please sign in to comment.