nice hatching for construction lanes, hackily encoded

This commit is contained in:
Dustin Carlino 2019-10-29 17:19:36 -07:00
parent a5892daedb
commit 7faeafd998
5 changed files with 27 additions and 7 deletions

View File

@ -55,5 +55,14 @@ void main() {
// Let the polygon with its original colors show instead.
discard;
}
} else if (pass_style[0] == 11.0) {
float map_x = (gl_FragCoord.x + transform[0]) / transform[2];
float map_y = (window[1] - gl_FragCoord.y + transform[1]) / transform[2];
if (mod(map_x + map_y, 2.0) <= 0.5) {
f_color = vec4(1.0, 1.0, 1.0, 1.0);
} else {
// Let the polygon with its original colors show instead.
discard;
}
}
}

View File

@ -15,7 +15,9 @@ pub enum Color {
StretchTexture(f32, Angle),
// A polygon with UV coordinates for each point must be used.
CustomUVTexture(f32),
Hatching,
// TODO Figure out how to pack more data into this.
HatchingStyle1,
HatchingStyle2,
}
impl fmt::Display for Color {
@ -29,7 +31,8 @@ impl fmt::Display for Color {
write!(f, "Color::StretchTexture({}, {})", id, angle)
}
Color::CustomUVTexture(id) => write!(f, "Color::CustomUVTexture({})", id),
Color::Hatching => write!(f, "Color::Hatching"),
Color::HatchingStyle1 => write!(f, "Color::HatchingStyle1"),
Color::HatchingStyle2 => write!(f, "Color::HatchingStyle2"),
}
}
}

View File

@ -377,7 +377,8 @@ pub(crate) struct Vertex {
position: [f32; 2],
// If the last component is non-zero, then this is an RGBA value.
// When the last component is 0, then this is (texture ID, tex coord X, text coord Y, 0)
// And one more case -- (10, 0, 0, 0) means to just draw hatching.
// And more cases -- (10, 0, 0, 0) means to just draw hatching style 1. (11, 0, 0, 0) is
// hatching style 2.
// TODO Make this u8?
style: [f32; 4],
}
@ -451,7 +452,8 @@ impl<'a> Prerender<'a> {
maybe_uv.expect("CustomUVTexture with polygon lacking UV")[idx];
[id, tx, ty, 0.0]
}
Color::Hatching => [10.0, 0.0, 0.0, 0.0],
Color::HatchingStyle1 => [10.0, 0.0, 0.0, 0.0],
Color::HatchingStyle2 => [11.0, 0.0, 0.0, 0.0],
};
vertices.push(Vertex {
position: [pt.x() as f32, pt.y() as f32],

View File

@ -253,7 +253,8 @@ impl State for EditMode {
.keys()
.chain(edits.contraflow_lanes.keys())
{
opts.override_colors.insert(ID::Lane(*l), Color::Hatching);
opts.override_colors
.insert(ID::Lane(*l), Color::HatchingStyle1);
ctx.draw_map.get_l(*l).draw(g, &opts, &ctx);
}
for i in edits
@ -262,7 +263,7 @@ impl State for EditMode {
.chain(edits.traffic_signal_overrides.keys())
{
opts.override_colors
.insert(ID::Intersection(*i), Color::Hatching);
.insert(ID::Intersection(*i), Color::HatchingStyle1);
ctx.draw_map.get_i(*i).draw(g, &opts, &ctx);
}

View File

@ -98,7 +98,12 @@ impl DrawLane {
.make_polygons(Distance::meters(0.25)),
);
}
LaneType::Construction => {}
LaneType::Construction => {
draw.push(
cs.get_def("construction hatching", Color::HatchingStyle2),
polygon.clone(),
);
}
};
}