mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 04:37:59 +02:00
Merge pull request #15010 from samcake/quest-demo
Case 21408: Quest demo - Fixing the gamma correction
This commit is contained in:
commit
0691f02198
11 changed files with 121 additions and 37 deletions
|
@ -380,16 +380,26 @@ void OpenGLDisplayPlugin::customizeContext() {
|
||||||
scissorState->setScissorEnable(true);
|
scissorState->setScissorEnable(true);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
#ifdef Q_OS_ANDROID
|
||||||
|
gpu::ShaderPointer program = gpu::Shader::createProgram(shader::gpu::program::DrawTextureGammaLinearToSRGB);
|
||||||
|
#else
|
||||||
gpu::ShaderPointer program = gpu::Shader::createProgram(shader::gpu::program::DrawTexture);
|
gpu::ShaderPointer program = gpu::Shader::createProgram(shader::gpu::program::DrawTexture);
|
||||||
_simplePipeline = gpu::Pipeline::create(program, scissorState);
|
#endif
|
||||||
_hudPipeline = gpu::Pipeline::create(program, blendState);
|
_simplePipeline = gpu::Pipeline::create(program, scissorState);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
gpu::ShaderPointer program = gpu::Shader::createProgram(shader::display_plugins::program::SrgbToLinear);
|
#ifdef Q_OS_ANDROID
|
||||||
|
gpu::ShaderPointer program = gpu::Shader::createProgram(shader::gpu::program::DrawTextureGammaLinearToSRGB);
|
||||||
|
#else
|
||||||
|
gpu::ShaderPointer program = gpu::Shader::createProgram(shader::gpu::program::DrawTextureGammaSRGBToLinear);
|
||||||
|
#endif
|
||||||
_presentPipeline = gpu::Pipeline::create(program, scissorState);
|
_presentPipeline = gpu::Pipeline::create(program, scissorState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
gpu::ShaderPointer program = gpu::Shader::createProgram(shader::gpu::program::DrawTexture);
|
||||||
|
_hudPipeline = gpu::Pipeline::create(program, blendState);
|
||||||
|
}
|
||||||
{
|
{
|
||||||
gpu::ShaderPointer program = gpu::Shader::createProgram(shader::gpu::program::DrawTextureMirroredX);
|
gpu::ShaderPointer program = gpu::Shader::createProgram(shader::gpu::program::DrawTextureMirroredX);
|
||||||
_mirrorHUDPipeline = gpu::Pipeline::create(program, blendState);
|
_mirrorHUDPipeline = gpu::Pipeline::create(program, blendState);
|
||||||
|
@ -885,6 +895,7 @@ void OpenGLDisplayPlugin::updateCompositeFramebuffer() {
|
||||||
auto renderSize = glm::uvec2(getRecommendedRenderSize());
|
auto renderSize = glm::uvec2(getRecommendedRenderSize());
|
||||||
if (!_compositeFramebuffer || _compositeFramebuffer->getSize() != renderSize) {
|
if (!_compositeFramebuffer || _compositeFramebuffer->getSize() != renderSize) {
|
||||||
_compositeFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("OpenGLDisplayPlugin::composite", gpu::Element::COLOR_RGBA_32, renderSize.x, renderSize.y));
|
_compositeFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("OpenGLDisplayPlugin::composite", gpu::Element::COLOR_RGBA_32, renderSize.x, renderSize.y));
|
||||||
|
// _compositeFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("OpenGLDisplayPlugin::composite", gpu::Element::COLOR_SRGBA_32, renderSize.x, renderSize.y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
// OpenGLDisplayPlugin_present.frag
|
|
||||||
|
|
||||||
LAYOUT(binding=0) uniform sampler2D colorMap;
|
|
||||||
|
|
||||||
layout(location=0) in vec2 varTexCoord0;
|
|
||||||
|
|
||||||
layout(location=0) out vec4 outFragColor;
|
|
||||||
|
|
||||||
float sRGBFloatToLinear(float value) {
|
|
||||||
const float SRGB_ELBOW = 0.04045;
|
|
||||||
|
|
||||||
return mix(pow((value + 0.055) / 1.055, 2.4), value / 12.92, float(value <= SRGB_ELBOW));
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 colorToLinearRGB(vec3 srgb) {
|
|
||||||
return vec3(sRGBFloatToLinear(srgb.r), sRGBFloatToLinear(srgb.g), sRGBFloatToLinear(srgb.b));
|
|
||||||
}
|
|
||||||
|
|
||||||
void main(void) {
|
|
||||||
outFragColor.a = 1.0;
|
|
||||||
outFragColor.rgb = colorToLinearRGB(texture(colorMap, varTexCoord0).rgb);
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
VERTEX gpu::vertex::DrawUnitQuadTexcoord
|
|
|
@ -16,20 +16,39 @@
|
||||||
// YCoCg =====> Luma (Y) chrominance green (Cg) and chrominance orange (Co)
|
// YCoCg =====> Luma (Y) chrominance green (Cg) and chrominance orange (Co)
|
||||||
// https://software.intel.com/en-us/node/503873
|
// https://software.intel.com/en-us/node/503873
|
||||||
|
|
||||||
|
// sRGB ====> Linear
|
||||||
float color_scalar_sRGBToLinear(float value) {
|
float color_scalar_sRGBToLinear(float value) {
|
||||||
const float SRGB_ELBOW = 0.04045;
|
// Same as pow(value, 2.2)
|
||||||
|
return mix(pow((value + 0.055) / 1.055, 2.4), value / 12.92, float(value <= 0.04045));
|
||||||
return mix(pow((value + 0.055) / 1.055, 2.4), value / 12.92, float(value <= SRGB_ELBOW));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 color_sRGBToLinear(vec3 srgb) {
|
vec3 color_sRGBToLinear(vec3 srgb) {
|
||||||
return vec3(color_scalar_sRGBToLinear(srgb.r), color_scalar_sRGBToLinear(srgb.g), color_scalar_sRGBToLinear(srgb.b));
|
// return vec3(color_scalar_sRGBToLinear(srgb.r), color_scalar_sRGBToLinear(srgb.g), color_scalar_sRGBToLinear(srgb.b));
|
||||||
|
// Same as pow(value, 2.2)
|
||||||
|
return mix(pow((srgb + vec3(0.055)) / vec3(1.055), vec3(2.4)), srgb / vec3(12.92), vec3(lessThanEqual(srgb, vec3(0.04045))));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 color_sRGBAToLinear(vec4 srgba) {
|
vec4 color_sRGBAToLinear(vec4 srgba) {
|
||||||
return vec4(color_sRGBToLinear(srgba.xyz), srgba.w);
|
return vec4(color_sRGBToLinear(srgba.xyz), srgba.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Linear ====> sRGB
|
||||||
|
float color_scalar_LinearTosRGB(float value) {
|
||||||
|
// Same as return pow(value, 1/2.2)
|
||||||
|
return mix(1.055 * pow(value, 0.41666) - 0.055, value * 12.92, float(value < 0.0031308));
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 color_LinearTosRGB(vec3 lrgb) {
|
||||||
|
// Same as return pow(lrgb, 1/2.2)
|
||||||
|
// return vec3(color_scalar_LinearTosRGB(lrgb.r), color_scalar_LinearTosRGB(lrgb.g), color_scalar_LinearTosRGB(lrgb.b));
|
||||||
|
return mix(vec3(1.055) * pow(vec3(lrgb), vec3(0.41666)) - vec3(0.055), vec3(lrgb) * vec3(12.92), vec3(lessThan(lrgb, vec3(0.0031308))));
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 color_LinearTosRGBA(vec4 lrgba) {
|
||||||
|
return vec4(color_LinearTosRGB(lrgba.xyz), lrgba.w);
|
||||||
|
}
|
||||||
|
|
||||||
vec3 color_LinearToYCoCg(vec3 rgb) {
|
vec3 color_LinearToYCoCg(vec3 rgb) {
|
||||||
// Y = R/4 + G/2 + B/4
|
// Y = R/4 + G/2 + B/4
|
||||||
// Co = R/2 - B/2
|
// Co = R/2 - B/2
|
||||||
|
|
26
libraries/gpu/src/gpu/DrawTextureGammaLinearToSRGB.slf
Normal file
26
libraries/gpu/src/gpu/DrawTextureGammaLinearToSRGB.slf
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<@include gpu/Config.slh@>
|
||||||
|
<$VERSION_HEADER$>
|
||||||
|
// Generated on <$_SCRIBE_DATE$>
|
||||||
|
//
|
||||||
|
// DrawTextureGammaLinearToSRGB.frag
|
||||||
|
//
|
||||||
|
// Draw texture 0 fetched at texcoord.xy, and apply linear to sRGB color space conversion
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 2/24/2019
|
||||||
|
// Copyright 2019 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
<@include gpu/Color.slh@>
|
||||||
|
|
||||||
|
|
||||||
|
LAYOUT(binding=0) uniform sampler2D colorMap;
|
||||||
|
|
||||||
|
layout(location=0) in vec2 varTexCoord0;
|
||||||
|
layout(location=0) out vec4 outFragColor;
|
||||||
|
|
||||||
|
void main(void) {
|
||||||
|
outFragColor = color_LinearTosRGBA(texture(colorMap, varTexCoord0));
|
||||||
|
}
|
1
libraries/gpu/src/gpu/DrawTextureGammaLinearToSRGB.slp
Normal file
1
libraries/gpu/src/gpu/DrawTextureGammaLinearToSRGB.slp
Normal file
|
@ -0,0 +1 @@
|
||||||
|
VERTEX DrawUnitQuadTexcoord
|
26
libraries/gpu/src/gpu/DrawTextureGammaSRGBToLinear.slf
Normal file
26
libraries/gpu/src/gpu/DrawTextureGammaSRGBToLinear.slf
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<@include gpu/Config.slh@>
|
||||||
|
<$VERSION_HEADER$>
|
||||||
|
// Generated on <$_SCRIBE_DATE$>
|
||||||
|
//
|
||||||
|
// DrawTextureGammaSRGBToLinear.frag
|
||||||
|
//
|
||||||
|
// Draw texture 0 fetched at texcoord.xy, and apply sRGB to Linear color space conversion
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 2/24/2019
|
||||||
|
// Copyright 2019 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
<@include gpu/Color.slh@>
|
||||||
|
|
||||||
|
|
||||||
|
LAYOUT(binding=0) uniform sampler2D colorMap;
|
||||||
|
|
||||||
|
layout(location=0) in vec2 varTexCoord0;
|
||||||
|
layout(location=0) out vec4 outFragColor;
|
||||||
|
|
||||||
|
void main(void) {
|
||||||
|
outFragColor = color_sRGBAToLinear(texture(colorMap, varTexCoord0));
|
||||||
|
}
|
1
libraries/gpu/src/gpu/DrawTextureGammaSRGBToLinear.slp
Normal file
1
libraries/gpu/src/gpu/DrawTextureGammaSRGBToLinear.slp
Normal file
|
@ -0,0 +1 @@
|
||||||
|
VERTEX DrawUnitQuadTexcoord
|
|
@ -32,18 +32,19 @@ void Framebuffer::create(const glm::uvec2& size) {
|
||||||
_validTexture = false;
|
_validTexture = false;
|
||||||
|
|
||||||
// Depth renderbuffer
|
// Depth renderbuffer
|
||||||
glGenRenderbuffers(1, &_depth);
|
/* glGenRenderbuffers(1, &_depth);
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, _depth);
|
glBindRenderbuffer(GL_RENDERBUFFER, _depth);
|
||||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, _size.x, _size.y);
|
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, _size.x, _size.y);
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||||
|
*/
|
||||||
// Framebuffer
|
// Framebuffer
|
||||||
glGenFramebuffers(1, &_fbo);
|
glGenFramebuffers(1, &_fbo);
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _fbo);
|
// glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _fbo);
|
||||||
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depth);
|
// glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depth);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
// glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
_swapChain = vrapi_CreateTextureSwapChain3(VRAPI_TEXTURE_TYPE_2D, GL_RGBA8, _size.x, _size.y, 1, 3);
|
_swapChain = vrapi_CreateTextureSwapChain3(VRAPI_TEXTURE_TYPE_2D, GL_RGBA8, _size.x, _size.y, 1, 3);
|
||||||
|
|
||||||
_length = vrapi_GetTextureSwapChainLength(_swapChain);
|
_length = vrapi_GetTextureSwapChainLength(_swapChain);
|
||||||
if (!_length) {
|
if (!_length) {
|
||||||
__android_log_write(ANDROID_LOG_WARN, "QQQ_OVR", "Unable to count swap chain textures");
|
__android_log_write(ANDROID_LOG_WARN, "QQQ_OVR", "Unable to count swap chain textures");
|
||||||
|
|
|
@ -58,7 +58,7 @@ void OculusMobileDisplayPlugin::deinit() {
|
||||||
|
|
||||||
bool OculusMobileDisplayPlugin::internalActivate() {
|
bool OculusMobileDisplayPlugin::internalActivate() {
|
||||||
_renderTargetSize = { 1024, 512 };
|
_renderTargetSize = { 1024, 512 };
|
||||||
_cullingProjection = ovr::toGlm(ovrMatrix4f_CreateProjectionFov(90.0f, 90.0f, 0.0f, 0.0f, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));
|
_cullingProjection = ovr::toGlm(ovrMatrix4f_CreateProjectionFov(90.0f, 90.0f, 90.0f, 90.0f, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));
|
||||||
|
|
||||||
|
|
||||||
withOvrJava([&](const ovrJava* java){
|
withOvrJava([&](const ovrJava* java){
|
||||||
|
@ -131,6 +131,7 @@ glm::mat4 OculusMobileDisplayPlugin::getEyeProjection(Eye eye, const glm::mat4&
|
||||||
|
|
||||||
glm::mat4 OculusMobileDisplayPlugin::getCullingProjection(const glm::mat4& baseProjection) const {
|
glm::mat4 OculusMobileDisplayPlugin::getCullingProjection(const glm::mat4& baseProjection) const {
|
||||||
glm::mat4 result = baseProjection;
|
glm::mat4 result = baseProjection;
|
||||||
|
|
||||||
VrHandler::withOvrMobile([&](ovrMobile* session){
|
VrHandler::withOvrMobile([&](ovrMobile* session){
|
||||||
auto trackingState = vrapi_GetPredictedTracking2(session, 0.0);
|
auto trackingState = vrapi_GetPredictedTracking2(session, 0.0);
|
||||||
ovr::Fov fovs[2];
|
ovr::Fov fovs[2];
|
||||||
|
|
|
@ -148,6 +148,27 @@ Rectangle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Separator {}
|
Separator {}
|
||||||
|
Column {
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
spacing: 5
|
||||||
|
Repeater {
|
||||||
|
model: [ "MSAA:PrepareFramebuffer:numSamples:4:1"
|
||||||
|
]
|
||||||
|
ConfigSlider {
|
||||||
|
label: qsTr(modelData.split(":")[0])
|
||||||
|
integral: true
|
||||||
|
config: render.mainViewTask.getConfig(modelData.split(":")[1])
|
||||||
|
property: modelData.split(":")[2]
|
||||||
|
max: modelData.split(":")[3]
|
||||||
|
min: modelData.split(":")[4]
|
||||||
|
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Separator {}
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
height: childrenRect.height
|
height: childrenRect.height
|
||||||
|
|
Loading…
Reference in a new issue