Skip to content

Commit 17721a0

Browse files
Andrcraft9github-actions[bot]
authored andcommitted
Cleanup symbol shaders
GitOrigin-RevId: 513206c00a971a0be7cb4947ca7059be6c679813
1 parent 274d217 commit 17721a0

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

src/shaders/symbol.fragment.glsl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
#define ICON 0.0
77

88
uniform sampler2D u_texture;
9+
#ifdef RENDER_TEXT_AND_SYMBOL
910
uniform sampler2D u_texture_icon;
11+
#endif
12+
#ifdef RENDER_SDF
1013
uniform highp float u_gamma_scale;
1114
uniform lowp float u_device_pixel_ratio;
1215
uniform bool u_is_text;
13-
uniform bool u_is_halo;
1416
uniform lowp float u_scale_factor;
17+
#endif
1518
// Boolean-config transition fragment alpha multiplier (dual-pass: originals + deltas).
1619
uniform lowp float u_opacity_multiplier;
1720
#ifdef ICON_TRANSITION
@@ -35,7 +38,9 @@ in vec2 v_tex_a;
3538
in vec2 v_tex_b;
3639
#endif
3740

41+
#ifdef RENDER_SDF
3842
in float v_draw_halo;
43+
#endif
3944
in vec3 v_gamma_scale_size_fade_opacity;
4045
#ifdef RENDER_TEXT_AND_SYMBOL
4146
in float is_sdf;
@@ -62,6 +67,7 @@ in lowp vec4 v_halo_np_color;
6267
in lowp float v_halo_width;
6368
in lowp float v_halo_blur;
6469
#endif
70+
6571
#ifdef LIGHTING_3D_MODE
6672
in lowp float v_emissive_strength;
6773
#endif
@@ -79,6 +85,7 @@ void main() {
7985
halo_width = v_halo_width;
8086
halo_blur = v_halo_blur;
8187
#endif
88+
8289
lowp float emissive_strength = 0.0;
8390
#ifdef LIGHTING_3D_MODE
8491
emissive_strength = v_emissive_strength;

src/shaders/symbol.vertex.glsl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ uniform bool u_is_size_feature_constant;
5252
uniform highp float u_size_t; // used to interpolate between zoom stops when size is a composite function
5353
uniform highp float u_size; // used when size is both zoom and feature constant
5454
uniform mat4 u_matrix;
55+
#ifdef RENDER_SHADOWS
5556
uniform mat4 u_inv_matrix;
57+
#endif
5658
uniform mat4 u_label_plane_matrix;
5759
uniform mat4 u_coord_matrix;
5860
uniform bool u_is_text;
@@ -63,9 +65,15 @@ uniform highp float u_aspect_ratio;
6365
uniform highp float u_camera_to_center_distance;
6466
uniform float u_fade_change;
6567
uniform vec2 u_texsize;
68+
#ifdef PROJECTION_GLOBE_VIEW
6669
uniform vec3 u_up_vector;
70+
#endif
71+
#ifdef RENDER_TEXT_AND_SYMBOL
6772
uniform vec2 u_texsize_icon;
73+
#endif
74+
#ifdef RENDER_SDF
6875
uniform bool u_is_halo;
76+
#endif
6977

7078
#ifdef PROJECTION_GLOBE_VIEW
7179
uniform vec3 u_tile_id;
@@ -82,7 +90,9 @@ out vec2 v_tex_a;
8290
out vec2 v_tex_b;
8391
#endif
8492

93+
#ifdef RENDER_SDF
8594
out float v_draw_halo;
95+
#endif
8696
out vec3 v_gamma_scale_size_fade_opacity;
8797
#ifdef RENDER_TEXT_AND_SYMBOL
8898
out float is_sdf;
@@ -116,13 +126,17 @@ out highp float v_depth;
116126

117127
/// Paint properties for a symbol layer.
118128
struct SymbolPaintProperties {
129+
#ifdef RENDER_SDF
119130
/// Non-premultiplied render fill color.
120131
vec4 fill_np_color;
121132
/// Non-premultiplied render halo color.
122133
vec4 halo_np_color;
134+
#endif
123135
float opacity;
136+
#ifdef RENDER_SDF
124137
float halo_width;
125138
float halo_blur;
139+
#endif
126140
float emissive_strength;
127141
float occlusion_opacity;
128142
float z_offset;
@@ -155,35 +169,47 @@ struct SymbolPropertyHeader {
155169
/// Size of the data-driven block should be aligned to vec4.
156170
uint dataDrivenBlockSizeVec4;
157171
/// Property types and aligned block offsets for each property.
172+
#ifdef RENDER_SDF
158173
PropertyType fill_np_color;
159174
PropertyType halo_np_color;
175+
#endif
160176
PropertyType opacity;
177+
#ifdef RENDER_SDF
161178
PropertyType halo_width;
162179
PropertyType halo_blur;
180+
#endif
163181
PropertyType emissive_strength;
164182
PropertyType occlusion_opacity;
165183
PropertyType z_offset;
166184
PropertyType translate;
167185
};
168186

169187
/// Constant paint properties values shared for all features.
188+
#ifdef RENDER_SDF
170189
uniform lowp vec4 u_spp_fill_np_color;
171190
uniform lowp vec4 u_spp_halo_np_color;
191+
#endif
172192
uniform lowp float u_spp_opacity;
193+
#ifdef RENDER_SDF
173194
uniform lowp float u_spp_halo_width;
174195
uniform lowp float u_spp_halo_blur;
196+
#endif
175197
uniform lowp float u_spp_emissive_strength;
176198
uniform lowp float u_spp_occlusion_opacity;
177199
uniform highp float u_spp_z_offset;
178200
/// [cos(angle), sin(angle)] for translate-anchor rotation; [1,0] = no rotation (viewport anchor).
179201
uniform lowp vec2 u_spp_translate_rotation;
180202

181203
/// Per-property zoom interpolation factor. Only meaningful for zoom-dependent properties.
204+
#ifdef RENDER_SDF
182205
uniform highp float u_spp_fill_color_zoom_factor;
183206
uniform highp float u_spp_halo_color_zoom_factor;
207+
#endif
184208
uniform highp float u_spp_opacity_zoom_factor;
209+
#ifdef RENDER_SDF
185210
uniform highp float u_spp_halo_width_zoom_factor;
186211
uniform highp float u_spp_halo_blur_zoom_factor;
212+
#endif
187213
uniform highp float u_spp_emissive_strength_zoom_factor;
188214
uniform highp float u_spp_occlusion_opacity_zoom_factor;
189215
uniform highp float u_spp_z_offset_zoom_factor;
@@ -216,12 +242,14 @@ layout(std140) uniform SymbolPaintPropertiesIndexUniform {
216242

217243
/// Symbol paint properties need to be interpolated and passed to the fragment shader.
218244
out lowp float v_opacity;
245+
219246
#ifdef RENDER_SDF
220247
out lowp vec4 v_fill_np_color;
221248
out lowp vec4 v_halo_np_color;
222249
out lowp float v_halo_width;
223250
out lowp float v_halo_blur;
224251
#endif
252+
225253
#ifdef LIGHTING_3D_MODE
226254
out lowp float v_emissive_strength;
227255
#endif
@@ -240,11 +268,19 @@ SymbolPropertyHeader readSymbolPropertiesHeader() {
240268
uint dataDrivenMask = u_spp_header.header[0][0];
241269
uint zoomDependentMask = u_spp_header.header[0][1];
242270
header.dataDrivenBlockSizeVec4 = u_spp_header.header[0][2];
271+
272+
#ifdef RENDER_SDF
243273
header.fill_np_color = getPropertyType(0u, dataDrivenMask, zoomDependentMask, u_spp_header.header[0][3], u_spp_fill_color_zoom_factor);
244274
header.halo_np_color = getPropertyType(1u, dataDrivenMask, zoomDependentMask, u_spp_header.header[1][0], u_spp_halo_color_zoom_factor);
275+
#endif
276+
245277
header.opacity = getPropertyType(2u, dataDrivenMask, zoomDependentMask, u_spp_header.header[1][1], u_spp_opacity_zoom_factor);
278+
279+
#ifdef RENDER_SDF
246280
header.halo_width = getPropertyType(3u, dataDrivenMask, zoomDependentMask, u_spp_header.header[1][2], u_spp_halo_width_zoom_factor);
247281
header.halo_blur = getPropertyType(4u, dataDrivenMask, zoomDependentMask, u_spp_header.header[1][3], u_spp_halo_blur_zoom_factor);
282+
#endif
283+
248284
header.emissive_strength = getPropertyType(5u, dataDrivenMask, zoomDependentMask, u_spp_header.header[2][0], u_spp_emissive_strength_zoom_factor);
249285
header.occlusion_opacity = getPropertyType(6u, dataDrivenMask, zoomDependentMask, u_spp_header.header[2][1], u_spp_occlusion_opacity_zoom_factor);
250286
header.z_offset = getPropertyType(7u, dataDrivenMask, zoomDependentMask, u_spp_header.header[2][2], u_spp_z_offset_zoom_factor);
@@ -298,6 +334,7 @@ uint getDataDrivenBlockOffsetVec4(uint dataDrivenBlockSizeVec4) {
298334
return blockIndex * dataDrivenBlockSizeVec4;
299335
}
300336

337+
#ifdef RENDER_SDF
301338
/// Read a color property from the UBO.
302339
/// Non-zoom: vec4 at offsetDwords = [RG, BA, pad, pad]; decode packed vec2.
303340
/// Zoom-dep: vec4 at offsetDwords = [minRG, minBA, maxRG, maxBA]; mix via the property's
@@ -313,6 +350,7 @@ vec4 readColorProperty(PropertyType propertyType, uint dataDrivenBlockSizeVec4)
313350
}
314351
return color;
315352
}
353+
#endif
316354

317355
/// Read a vec2 property (translate) from the UBO.
318356
/// Non-zoom: 2 consecutive floats [tx, ty] within the same vec4 (offset%4 <= 2).
@@ -348,11 +386,19 @@ SymbolPaintProperties readSymbolPaintProperties() {
348386
SymbolPropertyHeader header = readSymbolPropertiesHeader();
349387
uint sizeVec4 = header.dataDrivenBlockSizeVec4;
350388
SymbolPaintProperties props;
389+
390+
#ifdef RENDER_SDF
351391
props.fill_np_color = header.fill_np_color.isDataDriven ? readColorProperty(header.fill_np_color, sizeVec4) : u_spp_fill_np_color;
352392
props.halo_np_color = header.halo_np_color.isDataDriven ? readColorProperty(header.halo_np_color, sizeVec4) : u_spp_halo_np_color;
393+
#endif
394+
353395
props.opacity = header.opacity.isDataDriven ? readFloatProperty(header.opacity, sizeVec4) : u_spp_opacity;
396+
397+
#ifdef RENDER_SDF
354398
props.halo_width = header.halo_width.isDataDriven ? readFloatProperty(header.halo_width, sizeVec4) : u_spp_halo_width;
355399
props.halo_blur = header.halo_blur.isDataDriven ? readFloatProperty(header.halo_blur, sizeVec4) : u_spp_halo_blur;
400+
#endif
401+
356402
props.emissive_strength = header.emissive_strength.isDataDriven ? readFloatProperty(header.emissive_strength, sizeVec4) : u_spp_emissive_strength;
357403
props.occlusion_opacity = header.occlusion_opacity.isDataDriven ? readFloatProperty(header.occlusion_opacity, sizeVec4) : u_spp_occlusion_opacity;
358404
props.z_offset = header.z_offset.isDataDriven ? readFloatProperty(header.z_offset, sizeVec4) : u_spp_z_offset;
@@ -369,12 +415,14 @@ void main() {
369415
SymbolPaintProperties paint_properties = readSymbolPaintProperties();
370416
lowp float opacity = paint_properties.opacity;
371417
v_opacity = opacity;
418+
372419
#ifdef RENDER_SDF
373420
v_fill_np_color = paint_properties.fill_np_color;
374421
v_halo_np_color = paint_properties.halo_np_color;
375422
v_halo_width = paint_properties.halo_width;
376423
v_halo_blur = paint_properties.halo_blur;
377424
#endif
425+
378426
#ifdef LIGHTING_3D_MODE
379427
v_emissive_strength = paint_properties.emissive_strength;
380428
#endif
@@ -568,7 +616,9 @@ void main() {
568616
float gamma_scale = gl_Position.w;
569617

570618
// Cast to float is required to fix a rendering error in Swiftshader
619+
#ifdef RENDER_SDF
571620
v_draw_halo = (u_is_halo && float(gl_InstanceID) == 0.0) ? 1.0 : 0.0;
621+
#endif
572622

573623
v_gamma_scale_size_fade_opacity = vec3(gamma_scale, size, out_fade_opacity);
574624
v_tex_a = a_tex / u_texsize;

0 commit comments

Comments
 (0)