Skip to content

Commit

Permalink
Disable srgb correction
Browse files Browse the repository at this point in the history
  • Loading branch information
zarik5 committed Sep 7, 2023
1 parent 46ac92a commit 3039bc2
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 35 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -15,6 +15,7 @@ This is a fork of [ALVR](https://github.com/polygraphene/ALVR).
| Pico 4/Neo 3 | :heavy_check_mark: |
| Vive Focus 3/XR Elite | :heavy_check_mark: |
| YVR 1/2 | :heavy_check_mark: |
| Lynx-R1 | :heavy_check_mark: |
| Google Cardboard | :heavy_check_mark: ([PhoneVR](https://github.com/PhoneVR-Developers/PhoneVR)) |
| Smartphone/Monado | :construction: * |
| GearVR | :construction: * (maybe) |
Expand Down
1 change: 1 addition & 0 deletions alvr/client_core/cpp/bindings.h
Expand Up @@ -22,6 +22,7 @@ struct FfiStreamConfig {
float foveationCenterShiftY;
float foveationEdgeRatioX;
float foveationEdgeRatioY;
unsigned int enableSrgbCorrection;
};

// gltf_model.h
Expand Down
76 changes: 46 additions & 30 deletions alvr/client_core/cpp/graphics.cpp
Expand Up @@ -62,7 +62,7 @@ typedef struct {
enum ovrProgramType {
STREAMER_PROG,
LOBBY_PROG,
MAX_PROGS // Not to be used as a type, just a placeholder for len
MAX_PROGS // Not to be used as a type, just a placeholder for len
};

typedef struct {
Expand Down Expand Up @@ -95,12 +95,11 @@ typedef struct {
} ovrVertexAttribute;

ovrVertexAttribute ProgramVertexAttributes[] = {
{VERTEX_ATTRIBUTE_LOCATION_POSITION, "vertexPosition", {true, true }},
{VERTEX_ATTRIBUTE_LOCATION_COLOR, "vertexColor", {true, false}},
{VERTEX_ATTRIBUTE_LOCATION_UV, "vertexUv", {true, true }},
{VERTEX_ATTRIBUTE_LOCATION_TRANSFORM, "vertexTransform", {false, false}},
{VERTEX_ATTRIBUTE_LOCATION_NORMAL, "vertexNormal", {false, true }}
};
{VERTEX_ATTRIBUTE_LOCATION_POSITION, "vertexPosition", {true, true}},
{VERTEX_ATTRIBUTE_LOCATION_COLOR, "vertexColor", {true, false}},
{VERTEX_ATTRIBUTE_LOCATION_UV, "vertexUv", {true, true}},
{VERTEX_ATTRIBUTE_LOCATION_TRANSFORM, "vertexTransform", {false, false}},
{VERTEX_ATTRIBUTE_LOCATION_NORMAL, "vertexNormal", {false, true}}};

enum E1test {
UNIFORM_VIEW_ID,
Expand Down Expand Up @@ -428,7 +427,10 @@ void ovrGeometry_DestroyVAO(ovrGeometry *geometry) {

static const char *programVersion = "#version 300 es\n";

bool ovrProgram_Create(ovrProgram *program, const char *vertexSource, const char *fragmentSource, ovrProgramType progType) {
bool ovrProgram_Create(ovrProgram *program,
const char *vertexSource,
const char *fragmentSource,
ovrProgramType progType) {
GLint r;

LOGI("Compiling shaders.");
Expand Down Expand Up @@ -468,12 +470,16 @@ bool ovrProgram_Create(ovrProgram *program, const char *vertexSource, const char
// Bind the vertex attribute locations.
for (size_t i = 0; i < sizeof(ProgramVertexAttributes) / sizeof(ProgramVertexAttributes[0]);
i++) {
// Only bind vertex attributes which are used/active in shader else causes uncessary bugs via compiler optimization/aliasing
// Only bind vertex attributes which are used/active in shader else causes uncessary bugs
// via compiler optimization/aliasing
if (ProgramVertexAttributes[i].usedInProg[progType]) {
GL(glBindAttribLocation(program->streamProgram,
ProgramVertexAttributes[i].location,
ProgramVertexAttributes[i].name));
LOGD("Binding ProgramVertexAttribute [id.%d] %s to location %d", i, ProgramVertexAttributes[i].name, ProgramVertexAttributes[i].location);
ProgramVertexAttributes[i].location,
ProgramVertexAttributes[i].name));
LOGD("Binding ProgramVertexAttribute [id.%d] %s to location %d",
i,
ProgramVertexAttributes[i].name,
ProgramVertexAttributes[i].location);
}
}

Expand Down Expand Up @@ -551,19 +557,22 @@ void ovrRenderer_Create(ovrRenderer *renderer,
int hudTexture,
std::vector<GLuint> textures[2],
FFRData ffrData,
bool isLobby) {
bool isLobby,
bool enableSrgbCorrection) {
if (!isLobby) {
renderer->srgbCorrectionPass = std::make_unique<SrgbCorrectionPass>(streamTexture);
renderer->enableFFR = ffrData.enabled;
if (renderer->enableFFR) {
FoveationVars fv = CalculateFoveationVars(ffrData);
renderer->srgbCorrectionPass->Initialize(fv.optimizedEyeWidth, fv.optimizedEyeHeight);
renderer->srgbCorrectionPass->Initialize(
fv.optimizedEyeWidth, fv.optimizedEyeHeight, !enableSrgbCorrection);
renderer->ffr = std::make_unique<FFR>(renderer->srgbCorrectionPass->GetOutputTexture());
renderer->ffr->Initialize(fv);
renderer->streamRenderTexture = renderer->ffr->GetOutputTexture()->GetGLTexture();
} else {
renderer->srgbCorrectionPass->Initialize(width, height);
renderer->streamRenderTexture = renderer->srgbCorrectionPass->GetOutputTexture()->GetGLTexture();
renderer->srgbCorrectionPass->Initialize(width, height, !enableSrgbCorrection);
renderer->streamRenderTexture =
renderer->srgbCorrectionPass->GetOutputTexture()->GetGLTexture();
}
}

Expand All @@ -580,7 +589,8 @@ void ovrRenderer_Create(ovrRenderer *renderer,

ovrProgram_Create(&renderer->streamProgram, VERTEX_SHADER, FRAGMENT_SHADER, STREAMER_PROG);

ovrProgram_Create(&renderer->lobbyProgram, LOBBY_VERTEX_SHADER, LOBBY_FRAGMENT_SHADER, LOBBY_PROG);
ovrProgram_Create(
&renderer->lobbyProgram, LOBBY_VERTEX_SHADER, LOBBY_FRAGMENT_SHADER, LOBBY_PROG);

ovrGeometry_CreatePanel(&renderer->Panel);
ovrGeometry_CreateVAO(&renderer->Panel);
Expand Down Expand Up @@ -734,7 +744,7 @@ void initGraphicsNative() {
g_ctx.streamTexture = std::make_unique<Texture>(false, 0, true);
g_ctx.hudTexture = std::make_unique<Texture>(
false, 0, false, 1280, 720, GL_RGBA8, GL_RGBA, std::vector<uint8_t>(1280 * 720 * 4, 0));

const GLubyte *sVendor, *sRenderer, *sVersion, *sExts;

GL(sVendor = glGetString(GL_VENDOR));
Expand All @@ -747,10 +757,14 @@ void initGraphicsNative() {
}

void destroyGraphicsNative() {
LOGV("Resetting stream texture and hud texture %p, %p", g_ctx.streamTexture.get(), g_ctx.hudTexture.get());
LOGV("Resetting stream texture and hud texture %p, %p",
g_ctx.streamTexture.get(),
g_ctx.hudTexture.get());
g_ctx.streamTexture.reset();
g_ctx.hudTexture.reset();
LOGV("Resetted stream texture and hud texture to %p, %p", g_ctx.streamTexture.get(), g_ctx.hudTexture.get());
LOGV("Resetted stream texture and hud texture to %p, %p",
g_ctx.streamTexture.get(),
g_ctx.hudTexture.get());
}

// on resume
Expand All @@ -774,7 +788,8 @@ void prepareLobbyRoom(int viewWidth,
g_ctx.hudTexture->GetGLTexture(),
g_ctx.lobbySwapchainTextures,
{false},
true);
true,
false);
}

// on pause
Expand Down Expand Up @@ -819,7 +834,8 @@ void streamStartNative(FfiStreamConfig config) {
config.foveationCenterShiftY,
config.foveationEdgeRatioX,
config.foveationEdgeRatioY},
false);
false,
config.enableSrgbCorrection);
}

void updateLobbyHudTexture(const unsigned char *data) {
Expand All @@ -838,14 +854,14 @@ void renderLobbyNative(const FfiViewInput eyeInputs[2]) {
if (!g_ctx.hudTextureBitmap.empty()) {
GL(glBindTexture(GL_TEXTURE_2D, g_ctx.hudTexture->GetGLTexture()));
GL(glTexSubImage2D(GL_TEXTURE_2D,
0,
0,
0,
HUD_TEXTURE_WIDTH,
HUD_TEXTURE_HEIGHT,
GL_RGBA,
GL_UNSIGNED_BYTE,
&g_ctx.hudTextureBitmap[0]));
0,
0,
0,
HUD_TEXTURE_WIDTH,
HUD_TEXTURE_HEIGHT,
GL_RGBA,
GL_UNSIGNED_BYTE,
&g_ctx.hudTextureBitmap[0]));
}
g_ctx.hudTextureBitmap.clear();
}
Expand Down
20 changes: 17 additions & 3 deletions alvr/client_core/cpp/srgb_correction_pass.cpp
Expand Up @@ -32,15 +32,29 @@ const string SRGB_CORRECTION_FRAGMENT_SHADER = R"glsl(#version 300 es
color.rgb = condition * lowValues + (1.0 - condition) * highValues;
}
)glsl";
}
const string PASSTHOUGH_FRAGMENT_SHADER = R"glsl(#version 300 es
#extension GL_OES_EGL_image_external_essl3 : enable
precision mediump float;
uniform samplerExternalOES tex0;
in vec2 uv;
out vec4 color;
void main()
{
color = texture(tex0, uv);
}
)glsl";
} // namespace

SrgbCorrectionPass::SrgbCorrectionPass(Texture *inputSurface) : mInputSurface(inputSurface) {}

void SrgbCorrectionPass::Initialize(uint32_t width, uint32_t height) {
void SrgbCorrectionPass::Initialize(uint32_t width, uint32_t height, bool passthrough) {
mOutputTexture.reset(new Texture(false, 0, false, width * 2, height));
mOutputTextureState = make_unique<RenderState>(mOutputTexture.get());

auto fragmentShader = SRGB_CORRECTION_FRAGMENT_SHADER;
auto fragmentShader =
passthrough ? PASSTHOUGH_FRAGMENT_SHADER : SRGB_CORRECTION_FRAGMENT_SHADER;
mStagingPipeline = unique_ptr<RenderPipeline>(
new RenderPipeline({mInputSurface}, QUAD_2D_VERTEX_SHADER, fragmentShader));
}
Expand Down
2 changes: 1 addition & 1 deletion alvr/client_core/cpp/srgb_correction_pass.h
Expand Up @@ -9,7 +9,7 @@ class SrgbCorrectionPass {
public:
SrgbCorrectionPass(gl_render_utils::Texture *inputSurface);

void Initialize(uint32_t width, uint32_t height);
void Initialize(uint32_t width, uint32_t height, bool passthrough);

void Render() const;

Expand Down
7 changes: 6 additions & 1 deletion alvr/client_core/src/c_api.rs
Expand Up @@ -535,7 +535,12 @@ pub unsafe extern "C" fn alvr_start_stream_opengl(config: AlvrStreamConfig) {
edge_ratio_y: config.foveation_edge_ratio_y,
});

opengl::start_stream(view_resolution, swapchain_textures, foveated_rendering);
opengl::start_stream(
view_resolution,
swapchain_textures,
foveated_rendering,
true,
);
}

#[no_mangle]
Expand Down
2 changes: 2 additions & 0 deletions alvr/client_core/src/opengl.rs
Expand Up @@ -71,6 +71,7 @@ pub fn start_stream(
view_resolution: UVec2,
swapchain_textures: [Vec<u32>; 2],
foveated_rendering: Option<FoveatedRenderingConfig>,
enable_srgb_correction: bool,
) {
#[cfg(target_os = "android")]
unsafe {
Expand Down Expand Up @@ -107,6 +108,7 @@ pub fn start_stream(
.as_ref()
.map(|f| f.edge_ratio_y)
.unwrap_or_default(),
enableSrgbCorrection: enable_srgb_correction as u32,
};

streamStartNative(config);
Expand Down
1 change: 1 addition & 0 deletions alvr/client_openxr/src/lib.rs
Expand Up @@ -786,6 +786,7 @@ pub fn entry_point() {
.collect(),
],
settings.video.foveated_rendering.into_option(),
platform != Platform::Lynx,
);

alvr_client_core::send_playspace(
Expand Down

0 comments on commit 3039bc2

Please sign in to comment.