Skip to content

Commit

Permalink
Atmosphere blending fix (#5235)
Browse files Browse the repository at this point in the history
* Fix atmosphere blending

* Update render tests

* Fix missing uniform

* Fix failing render test + shader comment

* Add changelog entry
  • Loading branch information
kubapelc authored Dec 18, 2024
1 parent abf4f6b commit 35ea568
Show file tree
Hide file tree
Showing 17 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

- Fix holes at the poles when terrain is used with globe ([#5232](https://github.com/maplibre/maplibre-gl-js/pull/5232))
- Fix geometry artifacts when globe terrain is zoomed out too much ([#5232](https://github.com/maplibre/maplibre-gl-js/pull/5232))
- Fix atmosphere improperly blending into the background ([#5235](https://github.com/maplibre/maplibre-gl-js/pull/5235))
- _...Add new stuff here..._

## 5.0.0-pre.10
Expand Down
16 changes: 8 additions & 8 deletions src/shaders/atmosphere.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ vec4 atmosphere(vec3 r, vec3 r0, vec3 pSun, float iSun, float rPlanet, float rAt

// Calculate the step size of the primary ray.
vec2 p = rsi(r0, r, rAtmos);
if (p.x > p.y) return vec4(0,0,0,0);
if (p.x > p.y) {
return vec4(0.0, 0.0, 0.0, 1.0);
}

if (p.x < 0.0) {
p.x = 0.0;
Expand Down Expand Up @@ -130,8 +132,7 @@ vec4 atmosphere(vec3 r, vec3 r0, vec3 pSun, float iSun, float rPlanet, float rAt
}

// Calculate opacity
//float opacity = exp(-(length(kRlh) * iOdRlh + kMie * iOdMie));
float opacity = min(0.75, exp(-(length(kRlh) * length(totalRlh) + kMie * length(totalMie))));
float opacity = exp(-(length(kRlh) * length(totalRlh) + kMie * length(totalMie))); // We need to approximate attenuation with a single "grayscale" value instead of a color.

// Calculate the final color.
vec3 color = iSun * (pRlh * kRlh * totalRlh + pMie * kMie * totalMie);
Expand Down Expand Up @@ -160,9 +161,8 @@ void main() {
);

// Apply exposure.
color.xyz = 1.0 - exp(-1.0 * color.xyz);

vec4 no_effect_color = vec4(0, 0, 0, 0);

fragColor = mix(color, no_effect_color, 1.0 - u_atmosphere_blend);
color.rgb = 1.0 - exp(-1.0 * color.rgb);
// Apply gamma for correctness
color = pow(color, vec4(1.0 / 2.2)); // Gamma-correct the alpha channel as well (blending itself will not be gamma correct, so doing this helps visuals a bit).
fragColor = vec4(color.rgb, 1.0 - color.a) * u_atmosphere_blend;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 35ea568

Please sign in to comment.