Skip to content

Commit

Permalink
Calculate fog opacity in terrain raster fragment shader when zero exa…
Browse files Browse the repository at this point in the history
…ggeration is used
  • Loading branch information
endanke committed Nov 30, 2022
1 parent d12e8f9 commit 16da14d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
7 changes: 0 additions & 7 deletions src/shaders/_prelude_fog.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ vec3 fog_apply(vec3 color, vec3 pos) {
return mix(color, u_fog_color.rgb, opacity);
}

// Apply fog computed in the vertex shader
vec4 fog_apply_from_vert(vec4 color, float fog_opac) {
float alpha = EPSILON + color.a;
color.rgb = mix(color.rgb / alpha, u_fog_color.rgb, fog_opac) * alpha;
return color;
}

// Assumes z up
vec3 fog_apply_sky_gradient(vec3 camera_ray, vec3 sky_color) {
float horizon_blend = fog_horizon_blending(normalize(camera_ray));
Expand Down
8 changes: 4 additions & 4 deletions src/shaders/terrain_raster.fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
uniform sampler2D u_image0;
varying vec2 v_pos0;

#ifdef FOG
varying float v_fog_opacity;
#endif

#ifdef RENDER_SHADOWS
varying vec4 v_pos_light_view_0;
varying vec4 v_pos_light_view_1;
Expand All @@ -19,7 +15,11 @@ void main() {
#endif

#ifdef FOG
#ifdef ZERO_EXAGGERATION
color = fog_dither(fog_apply_premultiplied(color, v_fog_pos));
#else
color = fog_dither(fog_apply_from_vert(color, v_fog_opacity));
#endif
#endif
gl_FragColor = color;
#ifdef TERRAIN_WIREFRAME
Expand Down
8 changes: 4 additions & 4 deletions src/shaders/terrain_raster.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ attribute vec2 a_texture_pos;

varying vec2 v_pos0;

#ifdef FOG
varying float v_fog_opacity;
#endif

#ifdef RENDER_SHADOWS
uniform mat4 u_light_matrix_0;
uniform mat4 u_light_matrix_1;
Expand All @@ -32,8 +28,12 @@ void main() {
gl_Position = u_matrix * vec4(decodedPos, elevation, 1.0);

#ifdef FOG
#ifdef ZERO_EXAGGERATION
v_fog_pos = fog_position(decodedPos);
#else
v_fog_opacity = fog(fog_position(vec3(decodedPos, elevation)));
#endif
#endif

#ifdef RENDER_SHADOWS
vec3 pos = vec3(decodedPos, elevation);
Expand Down

0 comments on commit 16da14d

Please sign in to comment.