Skip to content

Commit

Permalink
Fix shader preprocessor define leading to invalid shaders on producti…
Browse files Browse the repository at this point in the history
…on build variants (#10582)

* Prevent shader stripping issue on production builds
Always use same function signature independently of shader variant

* Use const for the unused param

* Directly use inlined parameter

* Fixup

* Fix render tests
Cannot use const as 'out' or 'inout' parameters.
  • Loading branch information
karimnaaji committed Apr 16, 2021
1 parent de24952 commit e8f7d74
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
6 changes: 1 addition & 5 deletions src/shaders/_prelude_fog.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ vec3 fog_apply(vec3 color, vec3 pos) {
}

// Apply fog and haze which were computed in the vertex shader
vec3 fog_apply_from_vert(vec3 color, float fog_opac
#ifdef FOG_HAZE
, vec4 haze
#endif
) {
vec3 fog_apply_from_vert(vec3 color, float fog_opac, vec4 haze) {
#ifdef FOG_HAZE
color = srgb_to_linear(color);
color = mix(color, tonemap(color + haze.rgb), haze.a);
Expand Down
7 changes: 1 addition & 6 deletions src/shaders/_prelude_fog.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ vec3 fog_position(vec2 pos) {
return fog_position(vec3(pos, 0));
}

void fog_haze(
vec3 pos, out float fog_opac
#ifdef FOG_HAZE
, out vec4 haze
#endif
) {
void fog_haze(vec3 pos, out float fog_opac, out vec4 haze) {
// Map [near, far] to [0, 1]
float t = (length(pos) - u_fog_range.x) / (u_fog_range.y - u_fog_range.x);

Expand Down
7 changes: 4 additions & 3 deletions src/shaders/terrain_raster.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ varying vec4 v_haze_color;
void main() {
vec4 color = texture2D(u_image0, v_pos0);
#ifdef FOG
color.rgb = fog_dither(fog_apply_from_vert(color.rgb, v_fog_opacity
#ifdef FOG_HAZE
, v_haze_color
color.rgb = fog_dither(fog_apply_from_vert(color.rgb, v_fog_opacity, v_haze_color));
#else
vec4 unused;
color.rgb = fog_dither(fog_apply_from_vert(color.rgb, v_fog_opacity, unused));
#endif
));
#endif
gl_FragColor = color;
#ifdef TERRAIN_WIREFRAME
Expand Down
7 changes: 4 additions & 3 deletions src/shaders/terrain_raster.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ void main() {
gl_Position = u_matrix * vec4(decodedPos, elevation, 1.0);

#ifdef FOG
fog_haze(fog_position(vec3(decodedPos, elevation)), v_fog_opacity
#ifdef FOG_HAZE
, v_haze_color
fog_haze(fog_position(vec3(decodedPos, elevation)), v_fog_opacity, v_haze_color);
#else
vec4 unused;
fog_haze(fog_position(vec3(decodedPos, elevation)), v_fog_opacity, unused);
#endif
);
#endif
}

0 comments on commit e8f7d74

Please sign in to comment.