Skip to content

Commit ab81864

Browse files
aleksigrongithub-actions[bot]
authored andcommitted
Use integer attributes in shader when CPU side data is integer
GitOrigin-RevId: 1e8ef6f94afdde94bb74006269e3c7566cacbdf7
1 parent ddaac79 commit ab81864

File tree

74 files changed

+520
-421
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+520
-421
lines changed

3d-style/data/bucket/building_bucket.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,9 +847,9 @@ export class BuildingBucket implements BucketWithGroundEffect {
847847
}
848848

849849
if (mesh.buildingPart === BUILDING_PART_WALL) {
850-
building.layoutFloodLightDataArray.uint16.fill(floodLightWallRadiusNormalized, partVertexOffset, partVertexOffset + partVertexCount);
850+
building.layoutFloodLightDataArray.int16.fill(floodLightWallRadiusNormalized, partVertexOffset, partVertexOffset + partVertexCount);
851851
} else {
852-
building.layoutFloodLightDataArray.uint16.fill(0, partVertexOffset, partVertexOffset + partVertexCount);
852+
building.layoutFloodLightDataArray.int16.fill(0, partVertexOffset, partVertexOffset + partVertexCount);
853853
}
854854

855855
if (hasFauxFacade) {

3d-style/data/building_attributes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const buildingBloomAttenuationAttributes: StructArrayLayout = createLayou
3535
]);
3636

3737
export const buildingFloodLightWallRadiusAttributes: StructArrayLayout = createLayout([
38-
{name: 'a_flood_light_wall_radius_1i16', components: 1, type: 'Uint16'}
38+
{name: 'a_flood_light_wall_radius_1i16', components: 1, type: 'Int16'}
3939
]);
4040

4141
export const {members, size, alignment} = buildingPositionAttributes;

3d-style/render/draw_building.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,14 @@ function draw(painter: Painter, source: SourceCache, layer: BuildingStyleLayer,
336336
];
337337

338338
const depthMode = shadowRenderer.getShadowPassDepthMode();
339-
const colorMode = shadowRenderer.getShadowPassColorMode();
340339

341340
drawTiles({
342341
painter,
343342
source,
344343
layer,
345344
coords,
346345
defines: definesForPass,
347-
blendMode: colorMode,
346+
blendMode: ColorMode.disabled,
348347
depthMode,
349348
opacity,
350349
verticalScale,
@@ -361,7 +360,7 @@ function draw(painter: Painter, source: SourceCache, layer: BuildingStyleLayer,
361360
];
362361

363362
if (receiveShadowsEnabled) {
364-
definesForPass = definesForPass.concat("RENDER_SHADOWS", "DEPTH_TEXTURE");
363+
definesForPass = definesForPass.concat("RENDER_SHADOWS");
365364
}
366365

367366
if (painter.shadowRenderer && painter.shadowRenderer.useNormalOffset) {

3d-style/render/draw_model.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function setupMeshDraw(definesValues: Array<string>, dynamicBuffers: Array<Verte
163163

164164
const shadowRenderer = painter.shadowRenderer;
165165
if (shadowRenderer) {
166-
definesValues.push('RENDER_SHADOWS', 'DEPTH_TEXTURE');
166+
definesValues.push('RENDER_SHADOWS');
167167
if (shadowRenderer.useNormalOffset) {
168168
definesValues.push('NORMAL_OFFSET');
169169
}
@@ -343,13 +343,11 @@ function drawShadowCaster(mesh: Mesh, matrix: mat4, painter: Painter, layer: Mod
343343
const shadowRenderer = painter.shadowRenderer;
344344
if (!shadowRenderer) return;
345345
const depthMode = shadowRenderer.getShadowPassDepthMode();
346-
const colorMode = shadowRenderer.getShadowPassColorMode();
347346
const shadowMatrix = shadowRenderer.calculateShadowPassMatrixFromMatrix(matrix);
348347
const uniformValues = modelDepthUniformValues(shadowMatrix);
349-
const definesValues = (painter._shadowMapDebug) ? [] : ['DEPTH_TEXTURE'];
350-
const program = painter.getOrCreateProgram('modelDepth', {defines: (definesValues as DynamicDefinesType[])});
348+
const program = painter.getOrCreateProgram('modelDepth');
351349
const context = painter.context;
352-
program.draw(painter, context.gl.TRIANGLES, depthMode, StencilMode.disabled, colorMode, CullFaceMode.disabled,
350+
program.draw(painter, context.gl.TRIANGLES, depthMode, StencilMode.disabled, ColorMode.disabled, CullFaceMode.disabled,
353351
uniformValues, layer.id, mesh.vertexBuffer, mesh.indexBuffer, mesh.segments, layer.paint, painter.transform.zoom,
354352
undefined, undefined);
355353
}
@@ -957,7 +955,7 @@ function drawInstancedNode(painter: Painter, layer: ModelStyleLayer, node: Model
957955
if (isShadowPass && shadowRenderer) {
958956
program = painter.getOrCreateProgram('modelDepth', {defines: (definesValues as DynamicDefinesType[])});
959957
uniformValues = modelDepthUniformValues(renderData.shadowTileMatrix, renderData.shadowTileMatrix, Float32Array.from(node.globalMatrix));
960-
colorMode = shadowRenderer.getShadowPassColorMode();
958+
colorMode = ColorMode.disabled;
961959
} else {
962960

963961
const ignoreLut = layer.paint.get('model-color-use-theme').constantOr('default') === 'none';

3d-style/render/shadow_renderer.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,11 @@ export class ShadowRenderer {
258258
if (this._cascades.length === 0 || shadowParameters.shadowMapResolution !== this._cascades[0].texture.size[0]) {
259259
this._cascades = [];
260260
for (let i = 0; i < shadowParameters.cascadeCount; ++i) {
261-
const useColor = painter._shadowMapDebug;
262-
263261
const gl = context.gl;
264-
const fbo = context.createFramebuffer(width, height, useColor ? 1 : 0, 'texture');
262+
const fbo = context.createFramebuffer(width, height, 0, 'texture');
265263
const depthTexture = new Texture(context, {width, height, data: null}, gl.DEPTH_COMPONENT16);
266264
fbo.depthAttachment.set(depthTexture.texture);
267265

268-
if (useColor) {
269-
const colorTexture = new Texture(context, {width, height, data: null}, gl.RGBA8);
270-
fbo.colorAttachment0.set(colorTexture.texture);
271-
}
272-
273266
this._cascades.push({
274267
framebuffer: fbo,
275268
texture: depthTexture,
@@ -424,7 +417,7 @@ export class ShadowRenderer {
424417
if (cutoffParams.shouldRenderCutoff) {
425418
baseDefines.push('RENDER_CUTOFF');
426419
}
427-
baseDefines.push('RENDER_SHADOWS', 'DEPTH_TEXTURE');
420+
baseDefines.push('RENDER_SHADOWS');
428421
if (this.useNormalOffset) {
429422
baseDefines.push('NORMAL_OFFSET');
430423
}
@@ -452,10 +445,6 @@ export class ShadowRenderer {
452445
}
453446
}
454447

455-
getShadowPassColorMode(): Readonly<ColorMode> {
456-
return this.painter._shadowMapDebug ? ColorMode.unblended : ColorMode.disabled;
457-
}
458-
459448
getShadowPassDepthMode(): Readonly<DepthMode> {
460449
return this._depthMode;
461450
}

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

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
#include "_prelude_shadow.vertex.glsl"
33

44
in vec3 a_pos_3f;
5-
in vec3 a_normal_3;
6-
in vec3 a_centroid_3;
7-
in float a_flood_light_wall_radius_1i16;
5+
in ivec3 a_normal_3;
6+
in ivec3 a_centroid_3;
87

9-
in vec4 a_faux_facade_data;
10-
in vec2 a_faux_facade_vertical_range;
8+
#ifdef FLOOD_LIGHT
9+
in int a_flood_light_wall_radius_1i16;
10+
#endif
11+
12+
#ifdef BUILDING_FAUX_FACADE
13+
in uvec4 a_faux_facade_data;
14+
in uvec2 a_faux_facade_vertical_range;
15+
#endif
1116

1217
uniform mat4 u_matrix;
1318
uniform mat4 u_normal_matrix;
@@ -59,39 +64,40 @@ mat3 get_tbn(in vec3 normal) {
5964
return mat3(tangent, bitangent, normal);
6065
}
6166
#endif
62-
#pragma mapbox: define-attribute-vertex-shader-only highp vec2 part_color_emissive
63-
#pragma mapbox: define-attribute-vertex-shader-only highp vec2 faux_facade_color_emissive
67+
#pragma mapbox: define-attribute-vertex-shader-only highp uvec2 part_color_emissive
68+
#pragma mapbox: define-attribute-vertex-shader-only highp uvec2 faux_facade_color_emissive
6469

6570
void main() {
66-
#pragma mapbox: initialize-attribute-custom highp vec2 part_color_emissive
67-
#pragma mapbox: initialize-attribute-custom highp vec2 faux_facade_color_emissive
71+
#pragma mapbox: initialize-attribute-custom highp uvec2 part_color_emissive
72+
#pragma mapbox: initialize-attribute-custom highp uvec2 faux_facade_color_emissive
6873

6974
#ifdef FLOOD_LIGHT
70-
v_flood_radius = (a_flood_light_wall_radius_1i16 / MAX_INT_16 * FLOOD_LIGHT_MAX_RADIUS_METER);
75+
v_flood_radius = (float(a_flood_light_wall_radius_1i16) / MAX_INT_16 * FLOOD_LIGHT_MAX_RADIUS_METER);
7176
v_has_flood_light = step(0.0, v_flood_radius);
7277
#endif
7378

74-
vec4 color_emissive = decode_color(part_color_emissive);
79+
vec4 color_emissive = decode_color(vec2(part_color_emissive));
7580
v_color = vec4(sRGBToLinear(color_emissive.rgb), color_emissive.a);
7681

77-
vec3 a_normal_3f = a_normal_3 / MAX_INT_16;
82+
vec3 a_normal_3f = vec3(a_normal_3) / MAX_INT_16;
7883
v_normal = vec3(u_normal_matrix * vec4(a_normal_3f, 0.0));
7984

8085
float hidden = 0.0;
8186
float depth_offset = 0.0;
8287
#ifdef BUILDING_FAUX_FACADE
83-
v_faux_facade = a_faux_facade_data.x;
88+
vec4 faux_facade_data = vec4(a_faux_facade_data);
89+
v_faux_facade = faux_facade_data.x;
8490
if (v_faux_facade > 0.0) {
85-
v_faux_facade_ed = a_faux_facade_data.x * u_tile_to_meter;
91+
v_faux_facade_ed = faux_facade_data.x * u_tile_to_meter;
8692

87-
float window_x_perc = floor(a_faux_facade_data.y / TWO_POW_8);
88-
float window_y_perc = a_faux_facade_data.y - TWO_POW_8 * window_x_perc;
93+
float window_x_perc = floor(faux_facade_data.y / TWO_POW_8);
94+
float window_y_perc = faux_facade_data.y - TWO_POW_8 * window_x_perc;
8995
vec2 window_perc = vec2(window_x_perc, window_y_perc) / MAX_UINT_8;
9096

91-
v_faux_facade_floor = (a_faux_facade_data.zw / MAX_UINT_16 * EXTENT) * u_tile_to_meter;
97+
v_faux_facade_floor = (faux_facade_data.zw / MAX_UINT_16 * EXTENT) * u_tile_to_meter;
9298
v_faux_facade_window = window_perc * v_faux_facade_floor;
9399

94-
v_faux_facade_range = (a_faux_facade_vertical_range / MAX_UINT_16 * EXTENT) * u_tile_to_meter;
100+
v_faux_facade_range = (vec2(a_faux_facade_vertical_range) / MAX_UINT_16 * EXTENT) * u_tile_to_meter;
95101

96102
v_aspect = v_faux_facade_window.x / v_faux_facade_window.y;
97103

@@ -100,11 +106,10 @@ void main() {
100106
v_tbn_1 = tbn[1];
101107
v_tbn_2 = tbn[2];
102108

103-
v_faux_color_emissive = decode_color(faux_facade_color_emissive);
109+
v_faux_color_emissive = decode_color(vec2(faux_facade_color_emissive));
104110
v_faux_color_emissive.rgb = sRGBToLinear(v_faux_color_emissive.rgb);
105111

106-
float height = a_centroid_3.z;
107-
depth_offset = min(1000.0, height) * 0.0000002;
112+
depth_offset = min(1000.0, float(a_centroid_3.z)) * 0.0000002;
108113
}
109114
#endif
110115
v_pos = a_pos_3f;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
in vec3 a_pos_3f;
22

3-
#pragma mapbox: define-attribute-vertex-shader-only highp vec2 part_color_emissive
3+
#pragma mapbox: define-attribute-vertex-shader-only highp uvec2 part_color_emissive
44
#pragma mapbox: define-attribute highp vec4 bloom_attenuation
55

66
out vec4 v_color_emissive;
@@ -12,11 +12,11 @@ vec3 sRGBToLinear(vec3 srgbIn) {
1212
}
1313

1414
void main() {
15-
#pragma mapbox: initialize-attribute-custom highp vec2 part_color_emissive
15+
#pragma mapbox: initialize-attribute-custom highp uvec2 part_color_emissive
1616
#pragma mapbox: initialize-attribute highp vec4 bloom_attenuation
1717

1818
#ifdef HAS_ATTRIBUTE_a_part_color_emissive
19-
vec4 color_emissive = decode_color(part_color_emissive);
19+
vec4 color_emissive = decode_color(vec2(part_color_emissive));
2020
float part_emissive = color_emissive.a * 5.0; // The emissive value was compressed from [0,5] to [0,1]
2121
v_color_emissive = vec4(sRGBToLinear(color_emissive.rgb), part_emissive);
2222
#else
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
in highp float v_depth;
2-
3-
void main() {
4-
#ifndef DEPTH_TEXTURE
5-
glFragColor = pack_depth(v_depth);
6-
#endif
7-
}
1+
void main() {}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
in vec3 a_pos_3f;
22

33
uniform mat4 u_matrix;
4-
out highp float v_depth;
54

65
void main() {
76
gl_Position = u_matrix * vec4(a_pos_3f, 1.0);
8-
v_depth = gl_Position.z / gl_Position.w;
97
}
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
void main() {
2-
#ifndef DEPTH_TEXTURE
3-
glFragColor = vec4(0.);
4-
#endif
52
}

0 commit comments

Comments
 (0)