system/ui: update camera view shader to support rendering on device (#35326)

update shader to support rendering on device
pull/35257/head^2
Dean Lee 3 days ago committed by GitHub
parent f38a98fc09
commit fdfba3f9f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 31
      system/ui/widgets/cameraview.py

@ -2,20 +2,41 @@ import pyray as rl
from msgq.visionipc import VisionIpcClient, VisionStreamType from msgq.visionipc import VisionIpcClient, VisionStreamType
from openpilot.system.ui.lib.application import gui_app from openpilot.system.ui.lib.application import gui_app
VERTEX_SHADER = """
#version 300 es
in vec3 vertexPosition;
in vec2 vertexTexCoord;
in vec3 vertexNormal;
in vec4 vertexColor;
uniform mat4 mvp;
out vec2 fragTexCoord;
out vec4 fragColor;
void main() {
fragTexCoord = vertexTexCoord;
fragColor = vertexColor;
gl_Position = mvp * vec4(vertexPosition, 1.0);
}
"""
FRAME_FRAGMENT_SHADER = """ FRAME_FRAGMENT_SHADER = """
#version 330 core #version 300 es
in vec2 fragTexCoord; uniform sampler2D texture0, texture1; out vec4 fragColor; precision mediump float;
in vec2 fragTexCoord;
uniform sampler2D texture0;
uniform sampler2D texture1;
out vec4 fragColor;
void main() { void main() {
float y = texture(texture0, fragTexCoord).r; float y = texture(texture0, fragTexCoord).r;
vec2 uv = texture(texture1, fragTexCoord).ra - 0.5; vec2 uv = texture(texture1, fragTexCoord).ra - 0.5;
fragColor = vec4(y + 1.402*uv.y, y - 0.344*uv.x - 0.714*uv.y, y + 1.772*uv.x, 1.0); fragColor = vec4(y + 1.402*uv.y, y - 0.344*uv.x - 0.714*uv.y, y + 1.772*uv.x, 1.0);
}""" }
"""
class CameraView: class CameraView:
def __init__(self, name: str, stream_type: VisionStreamType): def __init__(self, name: str, stream_type: VisionStreamType):
self.client = VisionIpcClient(name, stream_type, False) self.client = VisionIpcClient(name, stream_type, False)
self.shader = rl.load_shader_from_memory(rl.ffi.NULL, FRAME_FRAGMENT_SHADER) self.shader = rl.load_shader_from_memory(VERTEX_SHADER, FRAME_FRAGMENT_SHADER)
self.texture_y: rl.Texture | None = None self.texture_y: rl.Texture | None = None
self.texture_uv: rl.Texture | None = None self.texture_uv: rl.Texture | None = None
self.frame = None self.frame = None

Loading…
Cancel
Save