Skip to content

Commit e3dec29

Browse files
astojiljgithub-actions[bot]
authored andcommitted
[DRIVE3D-3504] Pull elevated-road variable line width depth 0.5
GitOrigin-RevId: 25674f4b698d3407e8a9fe6511e68d1543ecb91a
1 parent d05284d commit e3dec29

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/render/program/line_program.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export type LineUniformsType = {
3030
['u_trim_gradient_mix_range']: Uniform2f;
3131
['u_trim_color']: Uniform4f;
3232
['u_zbias_factor']: Uniform1f;
33+
['u_road_view_depth_bias']: Uniform1f;
34+
['u_road_clip_to_view']: Uniform4f;
3335
['u_tile_to_meter']: Uniform1f;
3436
['u_ground_shadow_factor']: Uniform3f;
3537
['u_opacity_multiplier']: Uniform1f;
@@ -77,6 +79,8 @@ const lineUniforms = (context: Context): LineUniformsType => ({
7779
'u_trim_gradient_mix_range': new Uniform2f(context),
7880
'u_trim_color': new Uniform4f(context),
7981
'u_zbias_factor': new Uniform1f(context),
82+
'u_road_view_depth_bias': new Uniform1f(context),
83+
'u_road_clip_to_view': new Uniform4f(context),
8084
'u_tile_to_meter': new Uniform1f(context),
8185
'u_ground_shadow_factor': new Uniform3f(context),
8286
'u_opacity_multiplier': new Uniform1f(context),
@@ -144,6 +148,8 @@ const lineUniformValues = (
144148
'u_trim_gradient_mix_range': [1.0, 1.0],
145149
'u_trim_color': layer.paint.get('line-trim-color').toPremultipliedRenderColor(ignoreLut ? null : layer.lut).toArray01(),
146150
'u_zbias_factor': zbiasFactor,
151+
'u_road_view_depth_bias': 0,
152+
'u_road_clip_to_view': [0, 0, 0, 0],
147153
'u_tile_to_meter': tileToMeter(tile.tileID.canonical, 0.0),
148154
'u_ground_shadow_factor': groundShadowFactor,
149155
'u_opacity_multiplier': 1,

src/shaders/line.vertex.glsl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ uniform float u_width_scale;
4747
// in that case the value is passed as a vertex attribute instead of a uniform.
4848
uniform float u_z_offset;
4949

50+
// Elevated-road VLW carpet: 0.5 m view-depth pull toward camera (0 when disabled).
51+
// Always declared so GL locations resolve on all line program variants.
52+
uniform highp float u_road_view_depth_bias;
53+
uniform highp vec4 u_road_clip_to_view; // a,b,c,d for view = (a*z+b)/(c*z+d)
54+
5055
#ifdef RENDER_LINE_CURVE
5156
// Encodes curve control points in 3x3 matrices for x, y, z
5257
// Note: Could be replaced with an uniform array once Metal support is implemented
@@ -413,6 +418,25 @@ void main() {
413418
v_tile_pos = (v_tile_pos + extrude) / EXTENT;
414419
#ifdef ELEVATED_ROADS
415420
gl_Position = gl_Position + projected_extrude;
421+
#ifdef VARIABLE_LINE_WIDTH
422+
#ifndef ELEVATED
423+
// Depth-only pull toward camera (xy/w unchanged — no world-Z float).
424+
// Cap: 0.5 m in view/camera Z (same units as feature cutout). OpenGL view Z is
425+
// negative; +bias = toward camera. Matches route cutout depth margin.
426+
if (u_road_view_depth_bias > 0.0) {
427+
highp float z_in = gl_Position.z / gl_Position.w * 0.5 + 0.5;
428+
highp float a = u_road_clip_to_view.x;
429+
highp float b = u_road_clip_to_view.y;
430+
highp float c = u_road_clip_to_view.z;
431+
highp float d = u_road_clip_to_view.w;
432+
highp float view = (a * z_in + b) / (c * z_in + d);
433+
highp float view_new = view + u_road_view_depth_bias;
434+
highp float z_new = (view_new * d - b) / (a - view_new * c);
435+
z_new = clamp(z_new, 0.0, 1.0);
436+
gl_Position.z = (z_new * 2.0 - 1.0) * gl_Position.w;
437+
}
438+
#endif // ELEVATED
439+
#endif // VARIABLE_LINE_WIDTH
416440
#else
417441
gl_Position = mix(gl_Position + projected_extrude, AWAY, hidden);
418442
#endif

0 commit comments

Comments
 (0)