Skip to content

Commit 66e37f8

Browse files
aleksigrongithub-actions[bot]
authored andcommitted
Fix translucent fill-extrusion render artifact happening on
some GPUs GitOrigin-RevId: 38ffc42fec0d92820bcfc2f5d2e011a02e9079e6
1 parent 156c60b commit 66e37f8

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

3d-style/shaders/fill_extrusion_depth.vertex.glsl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ void main() {
3838
base *= u_vertical_scale;
3939
height *= u_vertical_scale;
4040

41-
vec3 pos_normal = vec3(a_pos_normal_ed.xyz);
42-
vec3 pos_nx = floor(pos_normal * 0.5);
41+
vec3 top_up_ny = vec3(a_pos_normal_ed.xyz & 1);
42+
vec3 pos_nx = vec3(a_pos_normal_ed.xyz >> 1);
4343
// The least significant bits of a_pos_normal_ed.xyz hold:
4444
// x is 1 if it's on top, 0 for ground.
4545
// y is 1 if the normal points up, and 0 if it points to side.
4646
// z is sign of ny: 1 for positive, 0 for values <= 0.
47-
mediump vec3 top_up_ny = pos_normal - 2.0 * pos_nx;
4847

4948
base = max(0.0, base);
5049
height = max(0.0, top_up_ny.y == 0.0 && top_up_ny.x == 1.0 ? height - u_edge_radius : height);

src/shaders/fill_extrusion.vertex.glsl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ uniform float u_edge_radius;
1414
uniform float u_width_scale;
1515

1616
in ivec4 a_pos_normal_ed;
17+
18+
#if defined(HAS_CENTROID) || defined(TERRAIN)
1719
in uvec2 a_centroid_pos;
20+
#endif
1821

1922
#ifdef RENDER_WALL_MODE
2023
in ivec3 a_join_normal_inside;
@@ -101,28 +104,26 @@ void main() {
101104
base *= u_vertical_scale;
102105
height *= u_vertical_scale;
103106

104-
vec4 pos_normal_ed = vec4(a_pos_normal_ed);
105-
vec4 pos_nx = floor(pos_normal_ed * 0.5);
107+
vec4 top_up_ny_start = vec4(a_pos_normal_ed & 1);
108+
vec4 pos_nx = vec4(a_pos_normal_ed >> 1);
106109
// The least significant bits of a_pos_normal_ed hold:
107110
// x is 1 if it's on top, 0 for ground.
108111
// y is 1 if the normal points up, and 0 if it points to side.
109112
// z is sign of ny: 1 for positive, 0 for values <= 0.
110113
// w marks edge's start, 0 is for edge end, edgeDistance increases from start to end.
111-
vec4 top_up_ny_start = pos_normal_ed - 2.0 * pos_nx;
112-
vec3 top_up_ny = top_up_ny_start.xyz;
113114

114115
float x_normal = pos_nx.z / 8192.0;
115-
vec3 normal = top_up_ny.y == 1.0 ? vec3(0.0, 0.0, 1.0) : normalize(vec3(x_normal, (2.0 * top_up_ny.z - 1.0) * (1.0 - abs(x_normal)), 0.0));
116+
vec3 normal = top_up_ny_start.y == 1.0 ? vec3(0.0, 0.0, 1.0) : normalize(vec3(x_normal, (2.0 * top_up_ny_start.z - 1.0) * (1.0 - abs(x_normal)), 0.0));
116117
#if defined(ZERO_ROOF_RADIUS) || defined(RENDER_SHADOWS) || defined(LIGHTING_3D_MODE)
117118
v_normal = normal;
118119
#endif
119120

120121
base = max(0.0, base);
121122

122123
float attr_height = height;
123-
height = max(0.0, top_up_ny.y == 0.0 && top_up_ny.x == 1.0 ? height - u_edge_radius : height);
124+
height = max(0.0, top_up_ny_start.y == 0.0 && top_up_ny_start.x == 1.0 ? height - u_edge_radius : height);
124125

125-
float t = top_up_ny.x;
126+
float t = top_up_ny_start.x;
126127

127128
vec2 centroid_pos = vec2(0.0);
128129
#if defined(HAS_CENTROID) || defined(TERRAIN)
@@ -141,11 +142,10 @@ void main() {
141142
float h_height = is_flat_height ? max(c_ele + height, ele + base + 2.0) : ele + height;
142143
float h_base = is_flat_base ? max(c_ele + base, ele + base) : ele + (base == 0.0 ? -5.0 : base);
143144
h = t > 0.0 ? max(h_base, h_height) : h_base;
144-
pos = vec3(pos_nx.xy, h);
145145
#else
146146
h = t > 0.0 ? height : base;
147-
pos = vec3(pos_nx.xy, h);
148147
#endif
148+
pos = vec3(pos_nx.xy, h);
149149

150150
#ifdef PROJECTION_GLOBE_VIEW
151151
// If t > 0 (top) we always add the lift, otherwise (ground) we only add it if base height is > 0
@@ -247,7 +247,7 @@ void main() {
247247
y_ground += y_ground * 5.0 / max(3.0, top_height);
248248
#endif // TERRAIN
249249
v_ao = vec2(mix(concave, -concave, start), y_ground);
250-
NdotL *= (1.0 + 0.05 * (1.0 - top_up_ny.y) * u_ao[0]); // compensate sides faux ao shading contribution
250+
NdotL *= (1.0 + 0.05 * (1.0 - top_up_ny_start.y) * u_ao[0]); // compensate sides faux ao shading contribution
251251

252252
#ifdef PROJECTION_GLOBE_VIEW
253253
top_height += u_height_lift;
@@ -258,7 +258,7 @@ void main() {
258258
#ifdef LIGHTING_3D_MODE
259259

260260
#ifdef FLOOD_LIGHT
261-
float is_wall = 1.0 - float(t > 0.0 && top_up_ny.y > 0.0);
261+
float is_wall = 1.0 - float(t > 0.0 && top_up_ny_start.y > 0.0);
262262
v_has_floodlight = float(flood_light_wall_radius > 0.0 && is_wall > 0.0);
263263
v_flood_radius = flood_light_wall_radius * u_vertical_scale;
264264
#endif // FLOOD_LIGHT

src/shaders/fill_extrusion_pattern.vertex.glsl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ uniform lowp vec3 u_lightpos;
1717
uniform lowp float u_lightintensity;
1818

1919
in ivec4 a_pos_normal_ed;
20+
21+
#if defined(HAS_CENTROID) || defined(TERRAIN)
2022
in uvec2 a_centroid_pos;
23+
#endif
2124

2225
#ifdef RENDER_WALL_MODE
2326
in ivec3 a_join_normal_inside;
@@ -79,26 +82,24 @@ void main() {
7982
vec2 pattern_tl = vec2(pattern.xy);
8083
vec2 pattern_br = vec2(pattern.zw);
8184

82-
vec4 pos_normal_ed = vec4(a_pos_normal_ed);
83-
vec4 pos_nx = floor(pos_normal_ed * 0.5);
85+
vec4 top_up_ny_start = vec4(a_pos_normal_ed & 1);
86+
vec4 pos_nx = vec4(a_pos_normal_ed >> 1);
8487
// The least significant bits of a_pos_normal_ed hold:
8588
// x is 1 if it's on top, 0 for ground.
8689
// y is 1 if the normal points up, and 0 if it points to side.
8790
// z is sign of ny: 1 for positive, 0 for values <= 0.
8891
// w marks edge's start, 0 is for edge end, edgeDistance increases from start to end.
89-
mediump vec4 top_up_ny_start = pos_normal_ed - 2.0 * pos_nx;
90-
mediump vec3 top_up_ny = top_up_ny_start.xyz;
9192

9293
float x_normal = pos_nx.z / 8192.0;
93-
vec3 normal = top_up_ny.y == 1.0 ? vec3(0.0, 0.0, 1.0) : normalize(vec3(x_normal, (2.0 * top_up_ny.z - 1.0) * (1.0 - abs(x_normal)), 0.0));
94-
float edgedistance = pos_normal_ed.w;
94+
vec3 normal = top_up_ny_start.y == 1.0 ? vec3(0.0, 0.0, 1.0) : normalize(vec3(x_normal, (2.0 * top_up_ny_start.z - 1.0) * (1.0 - abs(x_normal)), 0.0));
95+
float edgedistance = float(a_pos_normal_ed.w);
9596

9697
vec2 display_size = (pattern_br - pattern_tl) / pixel_ratio;
9798

9899
base = max(0.0, base);
99100
height = max(0.0, height);
100101

101-
float t = top_up_ny.x;
102+
float t = top_up_ny_start.x;
102103
float z = t > 0.0 ? height : base;
103104

104105
vec2 centroid_pos = vec2(0.0);
@@ -180,7 +181,7 @@ void main() {
180181
y_ground += y_ground * 5.0 / max(3.0, top_height);
181182
#endif
182183
v_ao = vec3(mix(concave, -concave, start), y_ground, h - ele);
183-
NdotL *= (1.0 + 0.05 * (1.0 - top_up_ny.y) * u_ao[0]); // compensate sides faux ao shading contribution
184+
NdotL *= (1.0 + 0.05 * (1.0 - top_up_ny_start.y) * u_ao[0]); // compensate sides faux ao shading contribution
184185

185186
#ifdef PROJECTION_GLOBE_VIEW
186187
top_height += u_height_lift;

0 commit comments

Comments
 (0)