Skip to content

Commit c0f58b7

Browse files
committed
fixed(display): Text placed on lines is now always rendered correctly.
improved(display): Text placed on 3D line geometry is now properly aligned. Signed-off-by: Tim Deubler <[email protected]>
1 parent 9b540e3 commit c0f58b7

File tree

2 files changed

+30
-39
lines changed

2 files changed

+30
-39
lines changed

packages/display/src/displays/webgl/glsl/intro_vertex.glsl

100644100755
+10-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ vec4 snapToScreenPixel(vec4 position, vec2 resolution){
1111
return position;
1212
}
1313

14+
15+
vec3 rotateY(vec3 v, float a) {
16+
float s = sin(a);
17+
float c = cos(a);
18+
return mat3(c, 0.0, -s, 0.0, 1.0, 0.0, s, 0.0, c) * v;
19+
}
20+
1421
vec2 rotateZ(vec2 v, float a){
15-
float rotSin = sin(a);
16-
float rotCos = cos(a);
17-
mat2 m = mat2(rotCos, -rotSin, rotSin, rotCos);
18-
return v * m;
22+
float s = sin(a);
23+
float c = cos(a);
24+
return v * mat2(c, -s, s, c);
1925
}
2026

2127
//vec2 rotateZ(vec2 point, float rad){

packages/display/src/displays/webgl/glsl/text_vertex.glsl

+20-35
Original file line numberDiff line numberDiff line change
@@ -27,70 +27,55 @@ const float PI_05 = M_PI * 0.5;
2727
const float PI_15 = M_PI * 1.5;
2828
const float PI_20 = M_PI * 2.0;
2929

30-
mat3 rotation3dY(float angle) {
31-
float s = sin(angle);
32-
float c = cos(angle);
33-
return mat3(
34-
c, 0.0, -s,
35-
0.0, 1.0, 0.0,
36-
s, 0.0, c
37-
);
38-
}
39-
vec3 rotateY(vec3 v, float angle) {
40-
return rotation3dY(angle) * v;
41-
}
42-
vec3 rotateY(vec2 v, float angle) {
43-
return rotation3dY(angle) * vec3(v, 0.0);
44-
}
4530

4631

47-
void main(void){
48-
if (mod(a_position.x, 2.0) == 1.0){
32+
void main(void) {
33+
if (mod(a_position.x, 2.0) == 1.0) {
4934

5035
vec2 position = floor(a_position.xy / 2.0) * EXTENT_SCALE;
5136

5237
vec2 rotLowHi = mod(a_texcoord, 32.0);
53-
float rotation = rotLowHi.y * 32.0 + rotLowHi.x;
38+
float rotationZ = rotLowHi.y * 32.0 + rotLowHi.x;
5439
// texture coodrinates bit6->bit16
5540
v_texcoord = floor(a_texcoord / 32.0) * u_atlasScale;
5641

5742
vec2 labelOffset = vec2(toPixel(u_offset.xy, u_scale), toPixel(u_offset.zw, u_scale));
5843

5944
labelOffset *= DEVICE_PIXEL_RATIO;
6045

61-
rotation = rotation / 1024.0 * PI_20;// 9bit -> 2PI;
46+
rotationZ = rotationZ / 1024.0 * PI_20;// 9bit -> 2PI;
6247

63-
float z = a_position.z * SCALE_UINT16_Z + toPixel(u_offsetZ, u_scale)/ u_zMeterToPixel/ u_scale;
48+
float z = a_position.z * SCALE_UINT16_Z + toPixel(u_offsetZ, u_scale) / u_zMeterToPixel / u_scale;
6449

65-
if (u_alignMap){
66-
float absRotation = mod(u_rotate + rotation, PI_20);
50+
if (u_alignMap) {
51+
float absRotation = mod(u_rotate + rotationZ, PI_20);
52+
float rotationY = a_point.z / 32767.0 * PI_20;
6753

68-
if (absRotation > PI_05 && absRotation < PI_15){
69-
rotation += M_PI;
54+
if (absRotation > PI_05 && absRotation < PI_15) {
55+
rotationZ += M_PI;
7056
labelOffset *= -1.0;
57+
rotationY *= -1.0;
7158
}
7259

73-
vec2 _p = a_point.xy * OFFSET_SCALE + labelOffset;
74-
vec3 p = rotateY(vec3(_p, 1.0), a_point.z/32767.0 * PI_20);
75-
p.xy = rotateZ(_p, rotation);
76-
p = p / u_scale / DEVICE_PIXEL_RATIO;
77-
78-
vec3 posWorld = vec3(u_topLeft + position, p.z -z);
60+
vec3 offset = vec3(a_point.xy * OFFSET_SCALE + labelOffset, 0.0) / u_scale / DEVICE_PIXEL_RATIO;
61+
offset = rotateY(offset, rotationY);
62+
offset.xy = rotateZ(offset.xy, rotationZ);
7963

80-
if (!u_scaleByAltitude){
64+
vec3 posWorld = vec3(u_topLeft + position, -z);
65+
if (!u_scaleByAltitude) {
8166
float scaleDZ = 1.0 + posWorld.z * u_matrix[2][3] / (u_matrix[0][3] * posWorld.x + u_matrix[1][3] * posWorld.y + u_matrix[3][3]);
82-
p.xy *= scaleDZ;
67+
offset.xy *= scaleDZ;
8368
}
69+
gl_Position = u_matrix * vec4(posWorld + offset, 1.0);
8470

85-
gl_Position = u_matrix * vec4(posWorld.xy + p.xy, posWorld.z + p.z, 1.0);
8671
} else {
8772
vec4 cpos = u_matrix * vec4((u_topLeft + position), -z, 1.0);
88-
vec2 offset = rotateZ(a_point.xy * OFFSET_SCALE + labelOffset, rotation);
73+
vec2 offset = rotateZ(a_point.xy * OFFSET_SCALE + labelOffset, rotationZ);
8974
// posOffset = rotateY(vec3(posOffset, 0), a_point.z).xy;
9075
gl_Position = vec4(cpos.xy / cpos.w + vec2(1, -1) * offset / DEVICE_PIXEL_RATIO / u_resolution * 2.0, cpos.z / cpos.w, 1.0);
9176
}
9277

93-
if (u_fixedView){
78+
if (u_fixedView) {
9479
// round/snap to pixelgrid if mapview is static -> crisp
9580
gl_Position = snapToScreenPixel(gl_Position, u_resolution);
9681
}

0 commit comments

Comments
 (0)