Skip to content

Commit

Permalink
fix(line_wall_shader): possibly fixed the line wall unit problem (#2051)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pureblackkk and lzxue authored Nov 24, 2023
1 parent 738510f commit 84d1241
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
33 changes: 25 additions & 8 deletions packages/core/src/shaders/projection.glsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define TILE_SIZE 512.0
#define PI 3.1415926536
#define WORLD_SCALE TILE_SIZE / (PI * 2.0)
#define EARTH_CIRCUMFERENCE 40.03e6

#define COORDINATE_SYSTEM_LNGLAT 1.0 // mapbox
#define COORDINATE_SYSTEM_LNGLAT_OFFSET 2.0 // mapbox offset
Expand Down Expand Up @@ -107,13 +108,17 @@ vec4 project_position(vec4 position) {
);
}

// if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) {
if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) {
// return vec4(
// (position.xy * WORLD_SCALE * u_ZoomScale) * vec2(1., -1.),
// project_scale(position.z),
// position.w);

// return vec4(
// position.xy,
// project_scale(position.z),
// position.w);
// }
return vec4(
position.xy,
project_scale(position.z),
position.w);
}
return position;

// TODO: 瓦片坐标系 & 常规世界坐标系
Expand Down Expand Up @@ -148,7 +153,7 @@ float project_pixel_texture(float pixel) {
if (u_CoordinateSystem == COORDINATE_SYSTEM_P20_OFFSET) {
return pixel * pow(0.5, u_Zoom)* u_FocalDistance ;
}

// amap zoom < 12
if (u_CoordinateSystem == COORDINATE_SYSTEM_P20) {
return pixel * pow(2.0, (20.0 - u_Zoom))* u_FocalDistance ;
Expand All @@ -173,6 +178,18 @@ float project_float_pixel(float pixel) {
return pixel * u_FocalDistance;
}

// Project meter into the unit of pixel which used in the camera world space
float project_float_meter(float meter) {
if (u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {
// Since the zoom level uniform is updated by mapservice and it's alread been subtracted by 1
// Not sure if we are supposed to do that again
return u_FocalDistance * TILE_SIZE * pow(2.0, u_Zoom) * meter / EARTH_CIRCUMFERENCE;
}

// TODO: change the following code to make adaptations for amap
return u_FocalDistance * TILE_SIZE * pow(2.0, u_Zoom) * meter / EARTH_CIRCUMFERENCE;
}

float project_pixel(float pixel) {
if (u_CoordinateSystem == COORDINATE_SYSTEM_P20 || u_CoordinateSystem == COORDINATE_SYSTEM_P20_OFFSET) {
// amap P20 坐标系下,为了和 Web 墨卡托坐标系统一,zoom 默认减1
Expand Down Expand Up @@ -249,4 +266,4 @@ vec4 project_common_position_to_clipspace_v2(vec4 position) {
} else {
return project_common_position_to_clipspace(position);
}
}
}
2 changes: 1 addition & 1 deletion packages/layers/src/line/shaders/wall/wall_vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void main() {

float originSize = a_Size.x; // 固定高度
if(u_heightfixed < 1.0) { // 高度随 zoom 调整
originSize = project_float_pixel(a_Size.x);
originSize = project_float_meter(a_Size.x);
}

float wallHeight = originSize * miter;
Expand Down

0 comments on commit 84d1241

Please sign in to comment.