Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Working] Green Screen Chroma Key Passthrough - Enable OpenXR #1881

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 13 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,18 @@ 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
Loading