Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MAPS3D-659] Remove unnecessary attribute in terrain related rendering code. #12472

Merged
merged 1 commit into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/shaders/ground_shadow.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ uniform mat4 u_light_matrix_0;
uniform mat4 u_light_matrix_1;

attribute vec2 a_pos;
attribute vec2 a_texture_pos;

varying vec4 v_pos_light_view_0;
varying vec4 v_pos_light_view_1;
Expand Down
3 changes: 1 addition & 2 deletions src/shaders/terrain_depth.vertex.glsl
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
uniform mat4 u_matrix;
attribute vec2 a_pos;
attribute vec2 a_texture_pos;

varying float v_depth;

void main() {
float elevation = elevation(a_texture_pos);
float elevation = elevation(a_pos);
gl_Position = u_matrix * vec4(a_pos, elevation, 1.0);
v_depth = gl_Position.z / gl_Position.w;
}
7 changes: 3 additions & 4 deletions src/shaders/terrain_raster.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ uniform mat4 u_matrix;
uniform float u_skirt_height;

attribute vec2 a_pos;
attribute vec2 a_texture_pos;

varying vec2 v_pos0;

Expand All @@ -22,13 +21,13 @@ const float skirtOffset = 24575.0;
const float wireframeOffset = 0.00015;

void main() {
v_pos0 = a_texture_pos / 8192.0;
float skirt = float(a_pos.x >= skirtOffset);
float elevation = elevation(a_texture_pos) - skirt * u_skirt_height;
vec2 decodedPos = a_pos - vec2(skirt * skirtOffset, 0.0);
float elevation = elevation(decodedPos) - skirt * u_skirt_height;
#ifdef TERRAIN_WIREFRAME
elevation += wireframeOffset;
#endif
vec2 decodedPos = a_pos - vec2(skirt * skirtOffset, 0.0);
v_pos0 = decodedPos / 8192.0;
gl_Position = u_matrix * vec4(decodedPos, elevation, 1.0);

#ifdef FOG
Expand Down
12 changes: 6 additions & 6 deletions src/terrain/terrain.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import Point from '@mapbox/point-geometry';
import SourceCache from '../source/source_cache.js';
import {OverscaledTileID} from '../source/tile_id.js';
import Tile from '../source/tile.js';
import boundsAttributes from '../data/bounds_attributes.js';
import {RasterBoundsArray, TriangleIndexArray, LineIndexArray} from '../data/array_types.js';
import posAttributes from '../data/pos_attributes.js';
import {TriangleIndexArray, LineIndexArray, PosArray} from '../data/array_types.js';
import SegmentVector from '../data/segment.js';
import Texture from '../render/texture.js';
import Program from '../render/program.js';
Expand Down Expand Up @@ -249,7 +249,7 @@ export class Terrain extends Elevation {
// edge vertices from neighboring tiles evaluate to the same 3D point.
const [triangleGridArray, triangleGridIndices, skirtIndicesOffset] = createGrid(GRID_DIM + 1);
const context = painter.context;
this.gridBuffer = context.createVertexBuffer(triangleGridArray, boundsAttributes.members);
this.gridBuffer = context.createVertexBuffer(triangleGridArray, posAttributes.members);
this.gridIndexBuffer = context.createIndexBuffer(triangleGridIndices);
this.gridSegments = SegmentVector.simpleSegment(0, 0, triangleGridArray.length, triangleGridIndices.length);
this.gridNoSkirtSegments = SegmentVector.simpleSegment(0, 0, triangleGridArray.length, skirtIndicesOffset);
Expand Down Expand Up @@ -1489,8 +1489,8 @@ function sortByDistanceToCamera(tileIDs, painter) {
* @param {number} count Count of rows and columns
* @private
*/
function createGrid(count: number): [RasterBoundsArray, TriangleIndexArray, number] {
const boundsArray = new RasterBoundsArray();
function createGrid(count: number): [PosArray, TriangleIndexArray, number] {
const boundsArray = new PosArray();
// Around the grid, add one more row/column padding for "skirt".
const indexArray = new TriangleIndexArray();
const size = count + 2;
Expand All @@ -1508,7 +1508,7 @@ function createGrid(count: number): [RasterBoundsArray, TriangleIndexArray, numb
const offset = (x < 0 || x > gridBound || y < 0 || y > gridBound) ? skirtOffset : 0;
const xi = clamp(Math.round(x), 0, EXTENT);
const yi = clamp(Math.round(y), 0, EXTENT);
boundsArray.emplaceBack(xi + offset, yi, xi, yi);
boundsArray.emplaceBack(xi + offset, yi);
}
}

Expand Down