raylib: fix experimental mode path gradient (#36033)

* fix!

* this is enough to fix the broken colors

* clean up

* fix

* use last colors -- need this so we don't have to always pass perfect gradient

* clean up

* clean up

* clean up
pull/36035/head^2
Shane Smiskol 1 day ago committed by GitHub
parent 870d19f33d
commit d0069c136b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 16
      selfdrive/ui/onroad/model_renderer.py
  2. 4
      system/ui/lib/shader_polygon.py

@ -187,9 +187,9 @@ class ModelRenderer(Widget):
self._path.raw_points, 0.9, self._path_offset_z, max_idx, allow_invert=False
)
self._update_experimental_gradient(self._rect.height)
self._update_experimental_gradient()
def _update_experimental_gradient(self, height):
def _update_experimental_gradient(self):
"""Pre-calculate experimental mode gradient colors"""
if not self._experimental_mode:
return
@ -201,14 +201,14 @@ class ModelRenderer(Widget):
i = 0
while i < max_len:
track_idx = max_len - i - 1 # flip idx to start from bottom right
track_y = self._path.projected_points[track_idx][1]
if track_y < 0 or track_y > height:
# Some points are out of frame
track_y = self._path.projected_points[i][1]
if track_y < self._rect.y or track_y > self._rect.height:
i += 1
continue
# Calculate color based on acceleration
lin_grad_point = (height - track_y) / height
# Calculate color based on acceleration (0 is bottom, 1 is top)
lin_grad_point = 1 - (track_y - self._rect.y) / self._rect.height
# speed up: 120, slow down: 0
path_hue = max(min(60 + self._acceleration_x[i] * 35, 120), 0)
@ -280,7 +280,7 @@ class ModelRenderer(Widget):
if self._experimental_mode:
# Draw with acceleration coloring
if len(self._exp_gradient['colors']) > 2:
if len(self._exp_gradient['colors']) > 1:
draw_polygon(self._rect, self._path.projected_points, gradient=self._exp_gradient)
else:
draw_polygon(self._rect, self._path.projected_points, rl.Color(255, 255, 255, 30))

@ -39,6 +39,10 @@ vec4 getGradientColor(vec2 pos) {
float t = clamp(dot(pos - gradientStart, normalizedDir) / gradientLength, 0.0, 1.0);
if (gradientColorCount <= 1) return gradientColors[0];
// handle t before first / after last stop
if (t <= gradientStops[0]) return gradientColors[0];
if (t >= gradientStops[gradientColorCount-1]) return gradientColors[gradientColorCount-1];
for (int i = 0; i < gradientColorCount - 1; i++) {
if (t >= gradientStops[i] && t <= gradientStops[i+1]) {
float segmentT = (t - gradientStops[i]) / (gradientStops[i+1] - gradientStops[i]);

Loading…
Cancel
Save