Skip to content

Commit

Permalink
Apply PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rreusser committed Apr 6, 2021
1 parent 1158b88 commit 62f0ac2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/render/painter.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ class Painter {
// rendering. Removing the fog flag during tile rendering avoids additional defines.
if (fog && !rtt) {
defines.push('FOG');
if (haze) defines.push('HAZE');
if (haze) defines.push('FOG_HAZE');
}
if (rtt) defines.push('RENDER_TO_TEXTURE');
if (this._showOverdrawInspector) defines.push('OVERDRAW_INSPECTOR');
Expand Down
9 changes: 6 additions & 3 deletions src/shaders/_prelude_fog.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ float fog_sky_blending(vec3 camera_dir) {
return u_fog_opacity * exp(-3.0 * t * t);
}

// This function gives the fog opacity when strength is 1. Otherwise it's multiplied
// Computes the fog opacity when fog strength = 1. Otherwise it's multiplied
// by a smoothstep to a power to decrease the amount of fog relative to haze.
// This function much match src/style/fog.js
// - t: depth, rescaled to 0 at fogStart and 1 at fogEnd
// See: https://www.desmos.com/calculator/3taufutxid
// This function much match src/style/fog.js
float fog_opacity(float t) {
const float decay = 6.0;
float falloff = 1.0 - min(1.0, exp(-decay * t));
Expand All @@ -40,6 +41,8 @@ float fog_opacity(float t) {
return u_fog_opacity * min(1.0, 1.00747 * falloff);
}

// This function is only used in rare places like heatmap where opacity is used
// directly, outside the normal fog_apply method.
float fog_opacity (vec3 pos) {
return fog_opacity((length(pos) - u_fog_range.x) / (u_fog_range.y - u_fog_range.x));
}
Expand All @@ -51,7 +54,7 @@ vec3 fog_apply(vec3 color, vec3 pos) {
float haze_opac = fog_opacity(pos);
float fog_opac = haze_opac * pow(smoothstep(0.0, 1.0, t), u_fog_exponent);

#ifdef HAZE
#ifdef FOG_HAZE
vec3 haze = (haze_opac * u_haze_energy) * u_haze_color_linear;

// The smoothstep fades in tonemapping slightly before the fog layer. This causes
Expand Down
2 changes: 0 additions & 2 deletions src/style/fog.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ export class FogSampler {
// Account for fog strength
falloff *= Math.pow(smoothstep(0, 1, t), fogExponent);

// We may wish to account for haze's effect on obscuring symbols

return falloff * fogOpacity;
}

Expand Down

0 comments on commit 62f0ac2

Please sign in to comment.