Skip to content

Commit

Permalink
Chroma key passthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
beiller committed Apr 13, 2024
1 parent dfadf6c commit 02320ea
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
23 changes: 20 additions & 3 deletions alvr/client_core/cpp/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,22 @@ in lowp vec2 uv;
in lowp vec4 fragmentColor;
out lowp vec4 outColor;
uniform sampler2D Texture0;
void main()
{
vec2 RGBToCC(vec4 rgba) {
float Y = 0.299 * rgba.r + 0.587 * rgba.g + 0.114 * rgba.b;
return vec2((rgba.b - Y) * 0.565, (rgba.r - Y) * 0.713);
}
void main() {
vec4 keyRGBA = vec4(0.0, 1.0, 0.0, 1.0); // key color as rgba
vec2 keyCC = RGBToCC(keyRGBA); // the CC part of YCC color model of key color
vec2 range = vec2(0.3, 0.4); // the smoothstep range
outColor = texture(Texture0, uv);
vec2 CC = RGBToCC(outColor);
float mask = sqrt(pow(keyCC.x - CC.x, 2.0) + pow(keyCC.y - CC.y, 2.0));
outColor.a = smoothstep(range.x, range.y, mask);
}
)glsl";

Expand Down Expand Up @@ -683,7 +696,11 @@ void renderEye(
GL(glBindVertexArray(0));
GL(glBindTexture(GL_TEXTURE_2D, 0));
} else {
GL(glClear(GL_DEPTH_BUFFER_BIT));
GL(glClearColor(0.0f, 0.0f, 0.0f, 0.0f));
GL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));

GL(glEnable(GL_BLEND));
GL(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));

GL(glBindVertexArray(renderer->Panel.VertexArrayObject));

Expand Down
3 changes: 3 additions & 0 deletions alvr/client_openxr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ required = false
name = "oculus.software.handtracking"
required = false
[[package.metadata.android.uses_feature]]
name = "com.oculus.feature.PASSTHROUGH"
required = false
[[package.metadata.android.uses_feature]]
name = "com.oculus.software.body_tracking"
required = false
[[package.metadata.android.uses_feature]]
Expand Down
11 changes: 11 additions & 0 deletions alvr/client_openxr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ pub fn entry_point() {
exts.htc_facial_tracking = available_extensions.htc_facial_tracking;
exts.htc_vive_focus3_controller_interaction =
available_extensions.htc_vive_focus3_controller_interaction;
exts.fb_passthrough = available_extensions.fb_passthrough;
#[cfg(target_os = "android")]
{
exts.khr_android_create_instance = true;
Expand Down Expand Up @@ -203,6 +204,16 @@ pub fn entry_point() {
session: xr_session.clone(),
};

let passthrough = xr_session
.create_passthrough(xr::PassthroughFlagsFB::IS_RUNNING_AT_CREATION)
.unwrap();

let _passthrough_layer = xr_session.create_passthrough_layer(
&passthrough,
xr::PassthroughFlagsFB::IS_RUNNING_AT_CREATION,
xr::PassthroughLayerPurposeFB::RECONSTRUCTION
).unwrap();

let views_config = xr_instance
.enumerate_view_configuration_views(
xr_system,
Expand Down

0 comments on commit 02320ea

Please sign in to comment.