From a7cbec30ee193f05e6352429ab3308bb502793df Mon Sep 17 00:00:00 2001 From: "Randall E. Barker" Date: Mon, 27 Apr 2020 13:02:01 -0700 Subject: [PATCH] Work around Oculus ColorScale bug (#3259) --- app/src/main/cpp/vrb | 2 +- app/src/oculusvr/cpp/OculusVRLayers.h | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/cpp/vrb b/app/src/main/cpp/vrb index 413e50e79..1ad49c28b 160000 --- a/app/src/main/cpp/vrb +++ b/app/src/main/cpp/vrb @@ -1 +1 @@ -Subproject commit 413e50e79a9cb49f0a9d7716d33e7edd3bfdcc42 +Subproject commit 1ad49c28bed91d67cbb71fa9ac886839216b062e diff --git a/app/src/oculusvr/cpp/OculusVRLayers.h b/app/src/oculusvr/cpp/OculusVRLayers.h index 109cad001..33b5496fb 100644 --- a/app/src/oculusvr/cpp/OculusVRLayers.h +++ b/app/src/oculusvr/cpp/OculusVRLayers.h @@ -77,9 +77,11 @@ class OculusLayerBase : public OculusLayer { virtual void Update(const ovrTracking2 &aTracking, ovrTextureSwapChain *aClearSwapChain) override { vrb::Color tintColor = layer->GetTintColor(); - if (!IsComposited() && layer->GetClearColor().Alpha()) { + if (!IsComposited() && (layer->GetClearColor().Alpha() > 0.0f)) { tintColor = layer->GetClearColor(); + tintColor.SetRGBA(convertColor(tintColor.Red()), convertColor(tintColor.Green()), convertColor(tintColor.Blue()), tintColor.Alpha()); } + ovrLayer.Header.ColorScale.x = tintColor.Red(); ovrLayer.Header.ColorScale.y = tintColor.Green(); ovrLayer.Header.ColorScale.z = tintColor.Blue(); @@ -158,7 +160,17 @@ class OculusLayerBase : public OculusLayer { return (IsComposited() || layer->GetClearColor().Alpha() == 0) ? swapChain : aClearSwapChain; } +protected: virtual ~OculusLayerBase() {} + + // Convert sRGB to linear RGB. Used to work around bug in Oculus compositor. + float convertColor(const float color) { + if (color > 0.04045f) { + return powf(color + 0.055f, 2.4f) / 1.055f; + } else { + return color / 12.92f; + } + } };