mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-04-07 10:02:24 +02:00
FIxing the gamma correction for Quest, intoducing simple gpu lib conversion shaders
This commit is contained in:
parent
f4a79a1e92
commit
26ad42b965
7 changed files with 93 additions and 15 deletions
|
@ -380,16 +380,26 @@ void OpenGLDisplayPlugin::customizeContext() {
|
|||
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);
|
||||
_simplePipeline = gpu::Pipeline::create(program, scissorState);
|
||||
_hudPipeline = gpu::Pipeline::create(program, blendState);
|
||||
#endif
|
||||
_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);
|
||||
}
|
||||
|
||||
{
|
||||
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);
|
||||
_mirrorHUDPipeline = gpu::Pipeline::create(program, blendState);
|
||||
|
@ -516,7 +526,6 @@ void OpenGLDisplayPlugin::renderFromTexture(gpu::Batch& batch, const gpu::Textur
|
|||
#ifndef USE_GLES
|
||||
batch.setPipeline(_presentPipeline);
|
||||
#else
|
||||
//batch.setPipeline(_presentPipeline);
|
||||
batch.setPipeline(_simplePipeline);
|
||||
#endif
|
||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
|
@ -631,8 +640,7 @@ void OpenGLDisplayPlugin::compositeScene() {
|
|||
batch.setStateScissorRect(ivec4(uvec2(), _compositeFramebuffer->getSize()));
|
||||
batch.resetViewTransform();
|
||||
batch.setProjectionTransform(mat4());
|
||||
// batch.setPipeline(_simplePipeline);
|
||||
batch.setPipeline(_presentPipeline);
|
||||
batch.setPipeline(_simplePipeline);
|
||||
batch.setResourceTexture(0, _currentFrame->framebuffer->getRenderBuffer(0));
|
||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
});
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
// YCoCg =====> Luma (Y) chrominance green (Cg) and chrominance orange (Co)
|
||||
// https://software.intel.com/en-us/node/503873
|
||||
|
||||
// sRGB ====> Linear
|
||||
float color_scalar_sRGBToLinear(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));
|
||||
// Same as pow(value, 2.2)
|
||||
return mix(pow((value + 0.055) / 1.055, 2.4), value / 12.92, float(value <= 0.04045));
|
||||
}
|
||||
|
||||
vec3 color_sRGBToLinear(vec3 srgb) {
|
||||
|
@ -30,6 +30,21 @@ vec4 color_sRGBAToLinear(vec4 srgba) {
|
|||
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));
|
||||
}
|
||||
|
||||
vec4 color_LinearTosRGBA(vec4 lrgba) {
|
||||
return vec4(color_LinearTosRGB(lrgba.xyz), lrgba.w);
|
||||
}
|
||||
|
||||
vec3 color_LinearToYCoCg(vec3 rgb) {
|
||||
// Y = R/4 + G/2 + B/4
|
||||
// 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$>
|
||||
//
|
||||
// DrawTexture.frag
|
||||
//
|
||||
// Draw texture 0 fetched at texcoord.xy
|
||||
//
|
||||
// Created by Sam Gateau on 6/22/2015
|
||||
// Copyright 2015 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$>
|
||||
//
|
||||
// DrawTexture.frag
|
||||
//
|
||||
// Draw texture 0 fetched at texcoord.xy
|
||||
//
|
||||
// Created by Sam Gateau on 6/22/2015
|
||||
// Copyright 2015 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;
|
||||
|
||||
// Depth renderbuffer
|
||||
glGenRenderbuffers(1, &_depth);
|
||||
/* glGenRenderbuffers(1, &_depth);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, _depth);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, _size.x, _size.y);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
|
||||
*/
|
||||
// Framebuffer
|
||||
glGenFramebuffers(1, &_fbo);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _fbo);
|
||||
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depth);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
// glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _fbo);
|
||||
// glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depth);
|
||||
// glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
_swapChain = vrapi_CreateTextureSwapChain3(VRAPI_TEXTURE_TYPE_2D, GL_RGBA8, _size.x, _size.y, 1, 3);
|
||||
|
||||
_length = vrapi_GetTextureSwapChainLength(_swapChain);
|
||||
if (!_length) {
|
||||
__android_log_write(ANDROID_LOG_WARN, "QQQ_OVR", "Unable to count swap chain textures");
|
||||
|
|
Loading…
Reference in a new issue