From f9891775fcb0a1246ff669fbbfd5a0fdf93544dc Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 21 Jan 2019 23:07:59 -0800 Subject: [PATCH 01/11] Enabling msaa framebuffer and testing for forward --- .../gpu-gl-common/src/gpu/gl/GLTexture.cpp | 14 ++++++++++++-- .../gpu-gl/src/gpu/gl45/GL45BackendOutput.cpp | 5 +++++ .../gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp | 17 ++++++++++++++--- libraries/gpu/src/gpu/State.h | 2 +- libraries/gpu/src/gpu/Texture.cpp | 8 ++++++++ libraries/gpu/src/gpu/Texture.h | 3 +++ .../render-utils/src/RenderForwardTask.cpp | 17 +++++++++++------ 7 files changed, 54 insertions(+), 12 deletions(-) diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLTexture.cpp b/libraries/gpu-gl-common/src/gpu/gl/GLTexture.cpp index e9494a1271..c8d6dbfdf0 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLTexture.cpp +++ b/libraries/gpu-gl-common/src/gpu/gl/GLTexture.cpp @@ -60,9 +60,17 @@ GLenum GLTexture::getGLTextureType(const Texture& texture) { switch (texture.getType()) { case Texture::TEX_2D: if (!texture.isArray()) { - return GL_TEXTURE_2D; + if (!texture.isMultisample()) { + return GL_TEXTURE_2D; + } else { + return GL_TEXTURE_2D_MULTISAMPLE; + } } else { - return GL_TEXTURE_2D_ARRAY; + if (!texture.isMultisample()) { + return GL_TEXTURE_2D_ARRAY; + } else { + return GL_TEXTURE_2D_MULTISAMPLE_ARRAY; + } } break; @@ -81,7 +89,9 @@ GLenum GLTexture::getGLTextureType(const Texture& texture) { uint8_t GLTexture::getFaceCount(GLenum target) { switch (target) { case GL_TEXTURE_2D: + case GL_TEXTURE_2D_MULTISAMPLE: case GL_TEXTURE_2D_ARRAY: + case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: return TEXTURE_2D_NUM_FACES; case GL_TEXTURE_CUBE_MAP: return TEXTURE_CUBE_NUM_FACES; diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendOutput.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendOutput.cpp index 86332558e3..7a299e792b 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendOutput.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendOutput.cpp @@ -62,6 +62,8 @@ public: if (gltexture) { if (gltexture->_target == GL_TEXTURE_2D) { glNamedFramebufferTexture(_id, colorAttachments[unit], gltexture->_texture, 0); + } else if (gltexture->_target == GL_TEXTURE_2D_MULTISAMPLE) { + glNamedFramebufferTexture(_id, colorAttachments[unit], gltexture->_texture, 0); } else { glNamedFramebufferTextureLayer(_id, colorAttachments[unit], gltexture->_texture, 0, b._subresource); } @@ -93,6 +95,9 @@ public: if (gltexture) { if (gltexture->_target == GL_TEXTURE_2D) { glNamedFramebufferTexture(_id, attachement, gltexture->_texture, 0); + } + else if (gltexture->_target == GL_TEXTURE_2D_MULTISAMPLE) { + glNamedFramebufferTexture(_id, attachement, gltexture->_texture, 0); } else { glNamedFramebufferTextureLayer(_id, attachement, gltexture->_texture, 0, _gpuObject.getDepthStencilBufferSubresource()); diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp index e02f12819e..4f193e0ae8 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp @@ -375,11 +375,22 @@ void GL45FixedAllocationTexture::allocateStorage() const { const auto dimensions = _gpuObject.getDimensions(); const auto mips = _gpuObject.getNumMips(); const auto numSlices = _gpuObject.getNumSlices(); + const auto numSamples = _gpuObject.getNumSamples(); - if (!_gpuObject.isArray()) { - glTextureStorage2D(_id, mips, texelFormat.internalFormat, dimensions.x, dimensions.y); + + if (!_gpuObject.isMultisample()) { + if (!_gpuObject.isArray()) { + glTextureStorage2D(_id, mips, texelFormat.internalFormat, dimensions.x, dimensions.y); + } else { + glTextureStorage3D(_id, mips, texelFormat.internalFormat, dimensions.x, dimensions.y, numSlices); + } } else { - glTextureStorage3D(_id, mips, texelFormat.internalFormat, dimensions.x, dimensions.y, numSlices); + if (!_gpuObject.isArray()) { + glTextureStorage2DMultisample(_id, numSamples, texelFormat.internalFormat, dimensions.x, dimensions.y, GL_FALSE); + } + else { + glTextureStorage3DMultisample(_id, numSamples, texelFormat.internalFormat, dimensions.x, dimensions.y, numSlices, GL_FALSE); + } } glTextureParameteri(_id, GL_TEXTURE_BASE_LEVEL, 0); diff --git a/libraries/gpu/src/gpu/State.h b/libraries/gpu/src/gpu/State.h index e68e829fb5..83f96f7925 100755 --- a/libraries/gpu/src/gpu/State.h +++ b/libraries/gpu/src/gpu/State.h @@ -263,7 +263,7 @@ public: frontFaceClockwise(false), depthClampEnable(false), scissorEnable(false), - multisampleEnable(false), + multisampleEnable(true), antialisedLineEnable(true), alphaToCoverageEnable(false) {} diff --git a/libraries/gpu/src/gpu/Texture.cpp b/libraries/gpu/src/gpu/Texture.cpp index c6f3cd9b9a..5c2e181810 100755 --- a/libraries/gpu/src/gpu/Texture.cpp +++ b/libraries/gpu/src/gpu/Texture.cpp @@ -176,10 +176,18 @@ TexturePointer Texture::createRenderBuffer(const Element& texelFormat, uint16 wi return create(TextureUsageType::RENDERBUFFER, TEX_2D, texelFormat, width, height, 1, 1, 0, numMips, sampler); } +TexturePointer Texture::createRenderBufferMultisample(const Element& texelFormat, uint16 width, uint16 height, uint16 numSamples, const Sampler& sampler) { + return create(TextureUsageType::RENDERBUFFER, TEX_2D, texelFormat, width, height, 1, numSamples, 0, gpu::Texture::SINGLE_MIP, sampler); +} + TexturePointer Texture::createRenderBufferArray(const Element& texelFormat, uint16 width, uint16 height, uint16 numSlices, uint16 numMips, const Sampler& sampler) { return create(TextureUsageType::RENDERBUFFER, TEX_2D, texelFormat, width, height, 1, 1, numSlices, numMips, sampler); } +TexturePointer Texture::createRenderBufferMultisampleArray(const Element& texelFormat, uint16 width, uint16 height, uint16 numSlices, uint16 numSamples, const Sampler& sampler) { + return create(TextureUsageType::RENDERBUFFER, TEX_2D, texelFormat, width, height, 1, numSamples, numSlices, gpu::Texture::SINGLE_MIP, sampler); +} + TexturePointer Texture::create1D(const Element& texelFormat, uint16 width, uint16 numMips, const Sampler& sampler) { return create(TextureUsageType::RESOURCE, TEX_1D, texelFormat, width, 1, 1, 1, 0, numMips, sampler); } diff --git a/libraries/gpu/src/gpu/Texture.h b/libraries/gpu/src/gpu/Texture.h index 73ed1b15dc..24ee536a1b 100755 --- a/libraries/gpu/src/gpu/Texture.h +++ b/libraries/gpu/src/gpu/Texture.h @@ -383,7 +383,9 @@ public: static TexturePointer create3D(const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numMips = SINGLE_MIP, const Sampler& sampler = Sampler()); static TexturePointer createCube(const Element& texelFormat, uint16 width, uint16 numMips = 1, const Sampler& sampler = Sampler()); static TexturePointer createRenderBuffer(const Element& texelFormat, uint16 width, uint16 height, uint16 numMips = SINGLE_MIP, const Sampler& sampler = Sampler()); + static TexturePointer createRenderBufferMultisample(const Element& texelFormat, uint16 width, uint16 height, uint16 numSamples, const Sampler& sampler = Sampler()); static TexturePointer createRenderBufferArray(const Element& texelFormat, uint16 width, uint16 height, uint16 numSlices, uint16 numMips = SINGLE_MIP, const Sampler& sampler = Sampler()); + static TexturePointer createRenderBufferMultisampleArray(const Element& texelFormat, uint16 width, uint16 height, uint16 numSlices, uint16 numSamples, const Sampler& sampler = Sampler()); static TexturePointer createStrict(const Element& texelFormat, uint16 width, uint16 height, uint16 numMips = SINGLE_MIP, const Sampler& sampler = Sampler()); static TexturePointer createExternal(const ExternalRecycler& recycler, const Sampler& sampler = Sampler()); @@ -431,6 +433,7 @@ public: uint16 getNumSamples() const { return _numSamples; } // NumSamples can only have certain values based on the hw static uint16 evalNumSamplesUsed(uint16 numSamplesTried); + bool isMultisample() const { return _numSamples > 1; } // max mip is in the range [ 0 if no sub mips, log2(max(width, height, depth))] // It is defined at creation time (immutable) diff --git a/libraries/render-utils/src/RenderForwardTask.cpp b/libraries/render-utils/src/RenderForwardTask.cpp index ffdbc1c4b1..8616214992 100755 --- a/libraries/render-utils/src/RenderForwardTask.cpp +++ b/libraries/render-utils/src/RenderForwardTask.cpp @@ -118,7 +118,7 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend const auto transparentInputs = DrawForward::Inputs(transparents, lightingModel).asVarying(); task.addJob("DrawTransparents", transparentInputs, shapePlumber); - { // Debug the bounds of the rendered items, still look at the zbuffer + /* { // Debug the bounds of the rendered items, still look at the zbuffer task.addJob("DrawMetaBounds", metas); task.addJob("DrawBounds", opaques); @@ -127,7 +127,7 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend task.addJob("DrawZones", zones); const auto debugZoneInputs = DebugZoneLighting::Inputs(deferredFrameTransform, lightFrame, backgroundFrame).asVarying(); task.addJob("DrawZoneStack", debugZoneInputs); - } + }*/ // Lighting Buffer ready for tone mapping // Forward rendering on GLES doesn't support tonemapping to and from the same FBO, so we specify @@ -141,7 +141,7 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend // Disable blit because we do tonemapping and compositing directly to the blit FBO // Blit! - // task.addJob("Blit", framebuffer); + task.addJob("Blit", framebuffer); } void PrepareFramebuffer::run(const RenderContextPointer& renderContext, gpu::FramebufferPointer& framebuffer) { @@ -157,13 +157,18 @@ void PrepareFramebuffer::run(const RenderContextPointer& renderContext, gpu::Fra auto colorFormat = gpu::Element::COLOR_SRGBA_32; auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_POINT); - auto colorTexture = + /* auto colorTexture = gpu::Texture::createRenderBuffer(colorFormat, frameSize.x, frameSize.y, gpu::Texture::SINGLE_MIP, defaultSampler); + _framebuffer->setRenderBuffer(0, colorTexture);*/ + auto colorTexture = + gpu::Texture::createRenderBufferMultisample(colorFormat, frameSize.x, frameSize.y, 16, defaultSampler); _framebuffer->setRenderBuffer(0, colorTexture); - auto depthFormat = gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::DEPTH_STENCIL); // Depth24_Stencil8 texel format - auto depthTexture = + /* auto depthTexture = gpu::Texture::createRenderBuffer(depthFormat, frameSize.x, frameSize.y, gpu::Texture::SINGLE_MIP, defaultSampler); + _framebuffer->setDepthStencilBuffer(depthTexture, depthFormat);*/ + auto depthTexture = + gpu::Texture::createRenderBufferMultisample(depthFormat, frameSize.x, frameSize.y, 16, defaultSampler); _framebuffer->setDepthStencilBuffer(depthTexture, depthFormat); } From a747bf4cbdc56281899e3ef002e888ecbbcb6467 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Sun, 27 Jan 2019 23:48:55 -0800 Subject: [PATCH 02/11] Exploring removing the COmpositing buffer in the display plugin, using srgb for swapchain and debuging from there --- interface/src/graphics/GraphicsEngine.cpp | 1 + .../display-plugins/OpenGLDisplayPlugin.cpp | 27 +++++++++-------- .../src/display-plugins/SrgbToLinear.slf | 29 +++++++++++++++++-- .../display-plugins/hmd/HmdDisplayPlugin.cpp | 4 ++- libraries/gl/src/gl/GLHelpers.cpp | 2 ++ .../render-utils/src/RenderForwardTask.cpp | 16 +++++----- libraries/render-utils/src/toneMapping.slf | 6 ++-- 7 files changed, 60 insertions(+), 25 deletions(-) diff --git a/interface/src/graphics/GraphicsEngine.cpp b/interface/src/graphics/GraphicsEngine.cpp index c2137d3d97..861dfea7f8 100644 --- a/interface/src/graphics/GraphicsEngine.cpp +++ b/interface/src/graphics/GraphicsEngine.cpp @@ -66,6 +66,7 @@ void GraphicsEngine::initializeGPU(GLWidget* glwidget) { } void GraphicsEngine::initializeRender(bool disableDeferred) { + disableDeferred = false; // Set up the render engine render::CullFunctor cullFunctor = LODManager::shouldRender; diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index 5835316efe..f103494094 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -351,14 +351,14 @@ void OpenGLDisplayPlugin::customizeContext() { if ((image.width() > 0) && (image.height() > 0)) { cursorData.texture = gpu::Texture::createStrict( - gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA), + gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::SRGBA), image.width(), image.height(), gpu::Texture::MAX_NUM_MIPS, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)); cursorData.texture->setSource("cursor texture"); auto usage = gpu::Texture::Usage::Builder().withColor().withAlpha(); cursorData.texture->setUsage(usage.build()); - cursorData.texture->setStoredMipFormat(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA)); + cursorData.texture->setStoredMipFormat(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::SRGBA)); cursorData.texture->assignStoredMip(0, image.byteCount(), image.constBits()); cursorData.texture->setAutoGenerateMips(true); } @@ -379,12 +379,13 @@ void OpenGLDisplayPlugin::customizeContext() { { gpu::ShaderPointer program = gpu::Shader::createProgram(shader::gpu::program::DrawTexture); _simplePipeline = gpu::Pipeline::create(program, scissorState); - _hudPipeline = gpu::Pipeline::create(program, blendState); + // _hudPipeline = gpu::Pipeline::create(program, blendState); } { gpu::ShaderPointer program = gpu::Shader::createProgram(shader::display_plugins::program::SrgbToLinear); _presentPipeline = gpu::Pipeline::create(program, scissorState); + _hudPipeline = gpu::Pipeline::create(program, blendState); } { @@ -474,12 +475,13 @@ void OpenGLDisplayPlugin::renderFromTexture(gpu::Batch& batch, const gpu::Textur batch.enableStereo(false); batch.resetViewTransform(); batch.setFramebuffer(fbo); - batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, vec4(0)); +// batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, vec4(0)); batch.setStateScissorRect(scissor); batch.setViewportTransform(viewport); batch.setResourceTexture(0, texture); #ifndef USE_GLES - batch.setPipeline(_presentPipeline); + batch.setPipeline(_simplePipeline); + // batch.setPipeline(_presentPipeline); #else batch.setPipeline(_simplePipeline); #endif @@ -507,7 +509,7 @@ void OpenGLDisplayPlugin::renderFromTexture(gpu::Batch& batch, const gpu::Textur batch.resetViewTransform(); batch.setViewportTransform(copyFboRect); batch.setStateScissorRect(copyFboRect); - batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, {0.0f, 0.0f, 0.0f, 1.0f}); + // batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, {0.0f, 0.0f, 0.0f, 1.0f}); batch.blit(fbo, sourceRect, copyFbo, copyRect); } } @@ -570,7 +572,7 @@ void OpenGLDisplayPlugin::compositePointer() { render([&](gpu::Batch& batch) { batch.enableStereo(false); batch.setProjectionTransform(mat4()); - batch.setFramebuffer(_compositeFramebuffer); + // batch.setFramebuffer(_compositeFramebuffer); batch.setPipeline(_cursorPipeline); batch.setResourceTexture(0, cursorData.texture); batch.resetViewTransform(); @@ -606,7 +608,7 @@ void OpenGLDisplayPlugin::compositeLayers() { { PROFILE_RANGE_EX(render_detail, "compositeScene", 0xff0077ff, (uint64_t)presentCount()) - compositeScene(); + // compositeScene(); } #ifdef HIFI_ENABLE_NSIGHT_DEBUG @@ -620,10 +622,10 @@ void OpenGLDisplayPlugin::compositeLayers() { }); } - { + /* { PROFILE_RANGE_EX(render_detail, "compositeExtra", 0xff0077ff, (uint64_t)presentCount()) compositeExtra(); - } + }*/ // Draw the pointer last so it's on top of everything auto compositorHelper = DependencyManager::get(); @@ -638,7 +640,8 @@ void OpenGLDisplayPlugin::internalPresent() { // Note: _displayTexture must currently be the same size as the display. uvec2 dims = _displayTexture ? uvec2(_displayTexture->getDimensions()) : getSurfacePixels(); auto viewport = ivec4(uvec2(0), dims); - renderFromTexture(batch, _displayTexture ? _displayTexture : _compositeFramebuffer->getRenderBuffer(0), viewport, viewport); + // renderFromTexture(batch, _displayTexture ? _displayTexture : _compositeFramebuffer->getRenderBuffer(0), viewport, viewport); + renderFromTexture(batch, _displayTexture ? _displayTexture : _currentFrame->framebuffer->getRenderBuffer(0), viewport, viewport); }); swapBuffers(); _presentRate.increment(); @@ -847,7 +850,7 @@ OpenGLDisplayPlugin::~OpenGLDisplayPlugin() { void OpenGLDisplayPlugin::updateCompositeFramebuffer() { auto renderSize = glm::uvec2(getRecommendedRenderSize()); 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_SRGBA_32, renderSize.x, renderSize.y)); } } diff --git a/libraries/display-plugins/src/display-plugins/SrgbToLinear.slf b/libraries/display-plugins/src/display-plugins/SrgbToLinear.slf index 8b324c81a5..f9b333b3db 100644 --- a/libraries/display-plugins/src/display-plugins/SrgbToLinear.slf +++ b/libraries/display-plugins/src/display-plugins/SrgbToLinear.slf @@ -17,6 +17,31 @@ vec3 colorToLinearRGB(vec3 srgb) { } void main(void) { - outFragColor.a = 1.0; - outFragColor.rgb = colorToLinearRGB(texture(colorMap, varTexCoord0).rgb); + vec4 fetched = texture(colorMap, varTexCoord0); + //outFragColor = fetched; + outFragColor.a = fetched.a; + outFragColor.rgb = pow(fetched.rgb, vec3(2.2)); + + /* int vSize = 300; + int hSize = 400; + + if (gl_FragCoord.y < vSize) { + finalColor *= pow(2.0, 0.1); + } + else if (gl_FragCoord.y > 2 * vSize) { + finalColor *= pow(2.0, -0.1); + } + else { + finalColor; + } + + if (gl_FragCoord.x 2 * hSize) { + outFragColor.rgb = pow(finalColor, vec3(1.0 / 2.2)); + } + else { + outFragColor.rgb = finalColor; + }*/ + // outFragColor.rgb = sqrt(finalColor); } diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index 321bcc3fd2..0a953f142d 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -260,7 +260,9 @@ void HmdDisplayPlugin::internalPresent() { viewport.z *= 2; } - renderFromTexture(batch, _compositeFramebuffer->getRenderBuffer(0), viewport, scissor, fbo); + // renderFromTexture(batch, _compositeFramebuffer->getRenderBuffer(0), viewport, scissor, fbo); + renderFromTexture(batch, _currentFrame->framebuffer->getRenderBuffer(0), viewport, scissor, fbo); + }); swapBuffers(); diff --git a/libraries/gl/src/gl/GLHelpers.cpp b/libraries/gl/src/gl/GLHelpers.cpp index 15a41c3dc1..8194c6e4fc 100644 --- a/libraries/gl/src/gl/GLHelpers.cpp +++ b/libraries/gl/src/gl/GLHelpers.cpp @@ -99,6 +99,8 @@ const QSurfaceFormat& getDefaultOpenGLSurfaceFormat() { #else format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); #endif + format.setColorSpace(QSurfaceFormat::sRGBColorSpace); + if (gl::Context::enableDebugLogger()) { format.setOption(QSurfaceFormat::DebugContext); } diff --git a/libraries/render-utils/src/RenderForwardTask.cpp b/libraries/render-utils/src/RenderForwardTask.cpp index 8616214992..e6f687df59 100755 --- a/libraries/render-utils/src/RenderForwardTask.cpp +++ b/libraries/render-utils/src/RenderForwardTask.cpp @@ -124,16 +124,16 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend task.addJob("DrawBounds", opaques); task.addJob("DrawTransparentBounds", transparents); - task.addJob("DrawZones", zones); + task.addJob("DrawZones", zones);*/ const auto debugZoneInputs = DebugZoneLighting::Inputs(deferredFrameTransform, lightFrame, backgroundFrame).asVarying(); task.addJob("DrawZoneStack", debugZoneInputs); - }*/ + // } // Lighting Buffer ready for tone mapping // Forward rendering on GLES doesn't support tonemapping to and from the same FBO, so we specify // the output FBO as null, which causes the tonemapping to target the blit framebuffer - const auto toneMappingInputs = ToneMappingDeferred::Inputs(framebuffer, static_cast(nullptr) ).asVarying(); - task.addJob("ToneMapping", toneMappingInputs); + // const auto toneMappingInputs = ToneMappingDeferred::Inputs(framebuffer, static_cast(nullptr) ).asVarying(); + // task.addJob("ToneMapping", toneMappingInputs); // Layered Overlays // Composite the HUD and HUD overlays @@ -154,21 +154,23 @@ void PrepareFramebuffer::run(const RenderContextPointer& renderContext, gpu::Fra if (!_framebuffer) { _framebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("forward")); + + int numSamples = 8; auto colorFormat = gpu::Element::COLOR_SRGBA_32; - auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_POINT); + auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR); /* auto colorTexture = gpu::Texture::createRenderBuffer(colorFormat, frameSize.x, frameSize.y, gpu::Texture::SINGLE_MIP, defaultSampler); _framebuffer->setRenderBuffer(0, colorTexture);*/ auto colorTexture = - gpu::Texture::createRenderBufferMultisample(colorFormat, frameSize.x, frameSize.y, 16, defaultSampler); + gpu::Texture::createRenderBufferMultisample(colorFormat, frameSize.x, frameSize.y, numSamples, defaultSampler); _framebuffer->setRenderBuffer(0, colorTexture); auto depthFormat = gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::DEPTH_STENCIL); // Depth24_Stencil8 texel format /* auto depthTexture = gpu::Texture::createRenderBuffer(depthFormat, frameSize.x, frameSize.y, gpu::Texture::SINGLE_MIP, defaultSampler); _framebuffer->setDepthStencilBuffer(depthTexture, depthFormat);*/ auto depthTexture = - gpu::Texture::createRenderBufferMultisample(depthFormat, frameSize.x, frameSize.y, 16, defaultSampler); + gpu::Texture::createRenderBufferMultisample(depthFormat, frameSize.x, frameSize.y, numSamples, defaultSampler); _framebuffer->setDepthStencilBuffer(depthTexture, depthFormat); } diff --git a/libraries/render-utils/src/toneMapping.slf b/libraries/render-utils/src/toneMapping.slf index 29f618c2f0..cb3e73dd4d 100644 --- a/libraries/render-utils/src/toneMapping.slf +++ b/libraries/render-utils/src/toneMapping.slf @@ -36,8 +36,8 @@ int getToneCurve() { return params._toneCurve_s0_s1_s2.x; } -LAYOUT(binding=RENDER_UTILS_TEXTURE_TM_COLOR) uniform sampler2D colorMap; - +LAYOUT(binding = RENDER_UTILS_TEXTURE_TM_COLOR) uniform sampler2D colorMap; + layout(location=0) in vec2 varTexCoord0; layout(location=0) out vec4 outFragColor; @@ -54,7 +54,7 @@ void main(void) { tonedColor = (x * (6.2 * x + 0.5)) / (x * (6.2 * x + 1.7) + 0.06); } else if (toneCurve == ToneCurveReinhard) { tonedColor = srcColor/(1.0 + srcColor); - tonedColor = pow(tonedColor, vec3(INV_GAMMA_22)); + // tonedColor = pow(tonedColor, vec3(INV_GAMMA_22)); } else if (toneCurve == ToneCurveGamma22) { tonedColor = pow(srcColor, vec3(INV_GAMMA_22)); } // else None toned = src From 84db9f47290a847906acf9734db852d4d30510a8 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Thu, 31 Jan 2019 16:18:47 -0800 Subject: [PATCH 03/11] testing the water... --- interface/src/graphics/GraphicsEngine.cpp | 2 +- libraries/render-utils/src/ToneMappingEffect.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/graphics/GraphicsEngine.cpp b/interface/src/graphics/GraphicsEngine.cpp index 861dfea7f8..fb3c5c3972 100644 --- a/interface/src/graphics/GraphicsEngine.cpp +++ b/interface/src/graphics/GraphicsEngine.cpp @@ -66,7 +66,7 @@ void GraphicsEngine::initializeGPU(GLWidget* glwidget) { } void GraphicsEngine::initializeRender(bool disableDeferred) { - disableDeferred = false; + disableDeferred = true; // Set up the render engine render::CullFunctor cullFunctor = LODManager::shouldRender; diff --git a/libraries/render-utils/src/ToneMappingEffect.h b/libraries/render-utils/src/ToneMappingEffect.h index 69694b13f5..2da5be8d10 100644 --- a/libraries/render-utils/src/ToneMappingEffect.h +++ b/libraries/render-utils/src/ToneMappingEffect.h @@ -51,7 +51,7 @@ private: float _exposure = 0.0f; float _twoPowExposure = 1.0f; glm::vec2 spareA; - int _toneCurve = Gamma22; + int _toneCurve = None; glm::vec3 spareB; Parameters() {} @@ -74,7 +74,7 @@ public: float exposure{ 0.0f }; - int curve{ ToneMappingEffect::Gamma22 }; + int curve{ ToneMappingEffect::None }; signals: void dirty(); }; From b970c31c5c3cde76bebdf5ab69465d186ca23eb7 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Fri, 1 Feb 2019 17:14:13 -0800 Subject: [PATCH 04/11] Correct gamma in oculus, yeah! --- interface/src/graphics/GraphicsEngine.cpp | 2 -- plugins/oculus/src/OculusDisplayPlugin.cpp | 20 +++++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/interface/src/graphics/GraphicsEngine.cpp b/interface/src/graphics/GraphicsEngine.cpp index fb3c5c3972..bff778bd62 100644 --- a/interface/src/graphics/GraphicsEngine.cpp +++ b/interface/src/graphics/GraphicsEngine.cpp @@ -66,8 +66,6 @@ void GraphicsEngine::initializeGPU(GLWidget* glwidget) { } void GraphicsEngine::initializeRender(bool disableDeferred) { - disableDeferred = true; - // Set up the render engine render::CullFunctor cullFunctor = LODManager::shouldRender; _renderEngine->addJob("UpdateScene"); diff --git a/plugins/oculus/src/OculusDisplayPlugin.cpp b/plugins/oculus/src/OculusDisplayPlugin.cpp index a34e647a5e..a34f068665 100644 --- a/plugins/oculus/src/OculusDisplayPlugin.cpp +++ b/plugins/oculus/src/OculusDisplayPlugin.cpp @@ -150,20 +150,26 @@ void OculusDisplayPlugin::hmdPresent() { // Manually bind the texture to the FBO // FIXME we should have a way of wrapping raw GL ids in GPU objects without // taking ownership of the object - auto fbo = getGLBackend()->getFramebufferID(_outputFramebuffer); - glNamedFramebufferTexture(fbo, GL_COLOR_ATTACHMENT0, curTexId, 0); - render([&](gpu::Batch& batch) { + auto srcfbo = getGLBackend()->getFramebufferID(_currentFrame->framebuffer); + auto dstfbo = getGLBackend()->getFramebufferID(_outputFramebuffer); + glNamedFramebufferTexture(dstfbo, GL_COLOR_ATTACHMENT0, curTexId, 0); + auto viewport = ivec4(uvec2(), _outputFramebuffer->getSize()); + /* render([&](gpu::Batch& batch) { batch.enableStereo(false); batch.setFramebuffer(_outputFramebuffer); batch.setViewportTransform(ivec4(uvec2(), _outputFramebuffer->getSize())); batch.setStateScissorRect(ivec4(uvec2(), _outputFramebuffer->getSize())); batch.resetViewTransform(); batch.setProjectionTransform(mat4()); - batch.setPipeline(_presentPipeline); - batch.setResourceTexture(0, _compositeFramebuffer->getRenderBuffer(0)); + // batch.setPipeline(_presentPipeline); + batch.setPipeline(_simplePipeline); + // batch.setResourceTexture(0, _compositeFramebuffer->getRenderBuffer(0)); + batch.setResourceTexture(0, _currentFrame->framebuffer->getRenderBuffer(0)); batch.draw(gpu::TRIANGLE_STRIP, 4); - }); - glNamedFramebufferTexture(fbo, GL_COLOR_ATTACHMENT0, 0, 0); + });*/ + glBlitNamedFramebuffer(srcfbo, dstfbo, viewport.x, viewport.y, viewport.z, viewport.w, viewport.x, viewport.y, + viewport.z, viewport.w, GL_COLOR_BUFFER_BIT, GL_NEAREST); + glNamedFramebufferTexture(dstfbo, GL_COLOR_ATTACHMENT0, 0, 0); } { From d0a044120afc46b21f5d44c253ad7cc2bd004a4a Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Sun, 3 Feb 2019 21:31:19 -0800 Subject: [PATCH 05/11] Adding the sub samples control --- .../render-utils/src/RenderForwardTask.cpp | 8 ++++++-- .../render-utils/src/RenderForwardTask.h | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/libraries/render-utils/src/RenderForwardTask.cpp b/libraries/render-utils/src/RenderForwardTask.cpp index e6f687df59..01da7f73df 100755 --- a/libraries/render-utils/src/RenderForwardTask.cpp +++ b/libraries/render-utils/src/RenderForwardTask.cpp @@ -144,18 +144,22 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend task.addJob("Blit", framebuffer); } +void PrepareFramebuffer::configure(const PrepareFramebuffer::Config& config) { + _numSamples = config.getNumSamples(); +} + void PrepareFramebuffer::run(const RenderContextPointer& renderContext, gpu::FramebufferPointer& framebuffer) { glm::uvec2 frameSize(renderContext->args->_viewport.z, renderContext->args->_viewport.w); // Resizing framebuffers instead of re-building them seems to cause issues with threaded rendering - if (_framebuffer && _framebuffer->getSize() != frameSize) { + if (_framebuffer && (_framebuffer->getSize() != frameSize || _framebuffer->getNumSamples() != _numSamples)) { _framebuffer.reset(); } if (!_framebuffer) { _framebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("forward")); - int numSamples = 8; + int numSamples = _numSamples; auto colorFormat = gpu::Element::COLOR_SRGBA_32; auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR); diff --git a/libraries/render-utils/src/RenderForwardTask.h b/libraries/render-utils/src/RenderForwardTask.h index e6a6008319..909e09452c 100755 --- a/libraries/render-utils/src/RenderForwardTask.h +++ b/libraries/render-utils/src/RenderForwardTask.h @@ -27,16 +27,33 @@ public: void build(JobModel& task, const render::Varying& input, render::Varying& output); }; +class PrepareFramebufferConfig : public render::Job::Config { + Q_OBJECT + Q_PROPERTY(int numSamples WRITE setNumSamples READ getNumSamples NOTIFY dirty) +public: + int getNumSamples() const { return numSamples; } + void setNumSamples(int num) { numSamples = num; emit dirty(); } + +signals: + void dirty(); + +protected: + int numSamples{ 8 }; +}; + class PrepareFramebuffer { public: using Inputs = gpu::FramebufferPointer; - using JobModel = render::Job::ModelO; + using Config = PrepareFramebufferConfig; + using JobModel = render::Job::ModelO; + void configure(const Config& config); void run(const render::RenderContextPointer& renderContext, gpu::FramebufferPointer& framebuffer); private: gpu::FramebufferPointer _framebuffer; + int _numSamples { 8 }; }; class PrepareForward { From 4089f8c5b0b50426ff9dc9ad49d243913db0b715 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 4 Feb 2019 23:45:35 -0800 Subject: [PATCH 06/11] Adding Color filter to the tone mapper --- libraries/render-utils/src/ToneMappingEffect.cpp | 15 ++++++++++----- libraries/render-utils/src/ToneMappingEffect.h | 10 +++++++++- libraries/render-utils/src/toneMapping.slf | 6 +++++- .../utilities/render/deferredLighting.qml | 16 ++++++++++++++++ 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/libraries/render-utils/src/ToneMappingEffect.cpp b/libraries/render-utils/src/ToneMappingEffect.cpp index d192266d7e..c40505917c 100644 --- a/libraries/render-utils/src/ToneMappingEffect.cpp +++ b/libraries/render-utils/src/ToneMappingEffect.cpp @@ -40,6 +40,13 @@ void ToneMappingEffect::setExposure(float exposure) { } } +void ToneMappingEffect::setColorFilter(const glm::vec3& colorFilter) { + auto& params = _parametersBuffer.get(); + if (params._colorFilter != colorFilter) { + _parametersBuffer.edit()._colorFilter = colorFilter; + } +} + void ToneMappingEffect::setToneCurve(ToneCurve curve) { auto& params = _parametersBuffer.get(); if (params._toneCurve != curve) { @@ -62,9 +69,6 @@ void ToneMappingEffect::render(RenderArgs* args, const gpu::TexturePointer& ligh batch.enableStereo(false); batch.setFramebuffer(destinationFramebuffer); - // FIXME: Generate the Luminosity map - //batch.generateTextureMips(lightingBuffer); - batch.setViewportTransform(args->_viewport); batch.setProjectionTransform(glm::mat4()); batch.resetViewTransform(); @@ -79,8 +83,9 @@ void ToneMappingEffect::render(RenderArgs* args, const gpu::TexturePointer& ligh void ToneMappingDeferred::configure(const Config& config) { - _toneMappingEffect.setExposure(config.exposure); - _toneMappingEffect.setToneCurve((ToneMappingEffect::ToneCurve)config.curve); + _toneMappingEffect.setExposure(config.exposure); + _toneMappingEffect.setColorFilter(config.colorFilter); + _toneMappingEffect.setToneCurve((ToneMappingEffect::ToneCurve)config.curve); } void ToneMappingDeferred::run(const render::RenderContextPointer& renderContext, const Inputs& inputs) { diff --git a/libraries/render-utils/src/ToneMappingEffect.h b/libraries/render-utils/src/ToneMappingEffect.h index 2da5be8d10..ae394c4dc3 100644 --- a/libraries/render-utils/src/ToneMappingEffect.h +++ b/libraries/render-utils/src/ToneMappingEffect.h @@ -31,6 +31,9 @@ public: void setExposure(float exposure); float getExposure() const { return _parametersBuffer.get()._exposure; } + void setColorFilter(const glm::vec3& colorFilter); + glm::vec3 getColorFIlter() const { return _parametersBuffer.get()._colorFilter; } + // Different tone curve available enum ToneCurve { None = 0, @@ -51,8 +54,10 @@ private: float _exposure = 0.0f; float _twoPowExposure = 1.0f; glm::vec2 spareA; + glm::vec3 _colorFilter{ 1.0f }; + float spareB; int _toneCurve = None; - glm::vec3 spareB; + glm::vec3 spareC; Parameters() {} }; @@ -65,15 +70,18 @@ private: class ToneMappingConfig : public render::Job::Config { Q_OBJECT Q_PROPERTY(float exposure MEMBER exposure WRITE setExposure); + Q_PROPERTY(glm::vec3 colorFilter MEMBER colorFilter WRITE setColorFilter); Q_PROPERTY(int curve MEMBER curve WRITE setCurve); public: ToneMappingConfig() : render::Job::Config(true) {} void setExposure(float newExposure) { exposure = newExposure; emit dirty(); } + void setColorFilter(const glm::vec3& newColorFilter) { colorFilter = newColorFilter; emit dirty(); } void setCurve(int newCurve) { curve = std::max((int)ToneMappingEffect::None, std::min((int)ToneMappingEffect::Filmic, newCurve)); emit dirty(); } float exposure{ 0.0f }; + glm::vec3 colorFilter { 1.0f }; int curve{ ToneMappingEffect::None }; signals: void dirty(); diff --git a/libraries/render-utils/src/toneMapping.slf b/libraries/render-utils/src/toneMapping.slf index cb3e73dd4d..3b13425816 100644 --- a/libraries/render-utils/src/toneMapping.slf +++ b/libraries/render-utils/src/toneMapping.slf @@ -17,6 +17,7 @@ struct ToneMappingParams { vec4 _exp_2powExp_s0_s1; + vec4 _colorFilter_s0; ivec4 _toneCurve_s0_s1_s2; }; @@ -32,6 +33,9 @@ LAYOUT(binding=RENDER_UTILS_BUFFER_TM_PARAMS) uniform toneMappingParamsBuffer { float getTwoPowExposure() { return params._exp_2powExp_s0_s1.y; } +vec3 getColorFilter() { + return params._colorFilter_s0.xyz; +} int getToneCurve() { return params._toneCurve_s0_s1_s2.x; } @@ -45,7 +49,7 @@ void main(void) { vec4 fragColorRaw = texture(colorMap, varTexCoord0); vec3 fragColor = fragColorRaw.xyz; - vec3 srcColor = fragColor * getTwoPowExposure(); + vec3 srcColor = fragColor * getColorFilter() * getTwoPowExposure(); int toneCurve = getToneCurve(); vec3 tonedColor = srcColor; diff --git a/scripts/developer/utilities/render/deferredLighting.qml b/scripts/developer/utilities/render/deferredLighting.qml index aef533b7a3..8c3e0fce94 100644 --- a/scripts/developer/utilities/render/deferredLighting.qml +++ b/scripts/developer/utilities/render/deferredLighting.qml @@ -14,6 +14,7 @@ import QtQuick.Layouts 1.3 import stylesUit 1.0 import controlsUit 1.0 as HifiControls import "configSlider" +import "../lib/plotperf" Rectangle { HifiConstants { id: hifi;} @@ -123,7 +124,22 @@ Rectangle { anchors.right: parent.right } } + Item { + HifiControls.Label { + text: "Color filter" + anchors.left: parent.left + } + Color { + height: 20 + anchors.right: parent.right + width: parent.width / 2 + _color: render.mainViewTask.getConfig("ToneMapping")["colorFilter"] + onNewColor: { + render.mainViewTask.getConfig("ToneMapping")["colorFilter"] = getXColor() + } + } + } Item { height: childrenRect.height anchors.left: parent.left From b1b6533295ca48b55bd5979c84fd66239452e47e Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 5 Feb 2019 18:01:41 -0800 Subject: [PATCH 07/11] Restore clear --- .../display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index 44110b2c99..ffd51cd61f 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -510,7 +510,7 @@ void OpenGLDisplayPlugin::renderFromTexture(gpu::Batch& batch, const gpu::Textur batch.enableStereo(false); batch.resetViewTransform(); batch.setFramebuffer(fbo); -// batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, vec4(0)); + batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, vec4(0)); batch.setStateScissorRect(scissor); batch.setViewportTransform(viewport); batch.setResourceTexture(0, texture); From 35491bf5b0e074cbb0bd39268ccd39cba3583e95 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Wed, 6 Feb 2019 00:05:17 -0800 Subject: [PATCH 08/11] Multisampling works in 4.1 --- .../gpu-gl-common/src/gpu/gl/GLTexture.cpp | 13 ++++--- .../gpu-gl/src/gpu/gl41/GL41BackendOutput.cpp | 4 +++ .../src/gpu/gl41/GL41BackendTexture.cpp | 28 ++++++++++----- .../render-utils/src/ToneMappingEffect.cpp | 2 +- .../render-utils/src/ToneMappingEffect.h | 6 ++-- .../utilities/lib/plotperf/Color.qml | 1 + .../utilities/render/deferredLighting.qml | 35 +++++-------------- 7 files changed, 46 insertions(+), 43 deletions(-) diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLTexture.cpp b/libraries/gpu-gl-common/src/gpu/gl/GLTexture.cpp index c8d6dbfdf0..082edd47bc 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLTexture.cpp +++ b/libraries/gpu-gl-common/src/gpu/gl/GLTexture.cpp @@ -106,15 +106,20 @@ const std::vector& GLTexture::getFaceTargets(GLenum target) { GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z }; - static const std::vector faceTargets { + static const std::vector face2DTargets { GL_TEXTURE_2D }; - static const std::vector arrayFaceTargets{ + static const std::vector face2DMSTargets{ + GL_TEXTURE_2D_MULTISAMPLE + }; + static const std::vector arrayFaceTargets{ GL_TEXTURE_2D_ARRAY }; switch (target) { case GL_TEXTURE_2D: - return faceTargets; + return face2DTargets; + case GL_TEXTURE_2D_MULTISAMPLE: + return face2DMSTargets; case GL_TEXTURE_2D_ARRAY: return arrayFaceTargets; case GL_TEXTURE_CUBE_MAP: @@ -124,7 +129,7 @@ const std::vector& GLTexture::getFaceTargets(GLenum target) { break; } Q_UNREACHABLE(); - return faceTargets; + return face2DTargets; } GLTexture::GLTexture(const std::weak_ptr& backend, const Texture& texture, GLuint id) : diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendOutput.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendOutput.cpp index 1d512103bd..0f50b0724e 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendOutput.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendOutput.cpp @@ -66,6 +66,8 @@ public: if (gltexture) { if (gltexture->_target == GL_TEXTURE_2D) { glFramebufferTexture2D(GL_FRAMEBUFFER, colorAttachments[unit], GL_TEXTURE_2D, gltexture->_texture, 0); + } else if (gltexture->_target == GL_TEXTURE_2D_MULTISAMPLE) { + glFramebufferTexture2D(GL_FRAMEBUFFER, colorAttachments[unit], GL_TEXTURE_2D_MULTISAMPLE, gltexture->_texture, 0); } else { glFramebufferTextureLayer(GL_FRAMEBUFFER, colorAttachments[unit], gltexture->_texture, 0, b._subresource); @@ -98,6 +100,8 @@ public: if (gltexture) { if (gltexture->_target == GL_TEXTURE_2D) { glFramebufferTexture2D(GL_FRAMEBUFFER, attachement, GL_TEXTURE_2D, gltexture->_texture, 0); + } else if (gltexture->_target == GL_TEXTURE_2D_MULTISAMPLE) { + glFramebufferTexture2D(GL_FRAMEBUFFER, attachement, GL_TEXTURE_2D_MULTISAMPLE, gltexture->_texture, 0); } else { glFramebufferTextureLayer(GL_FRAMEBUFFER, attachement, gltexture->_texture, 0, _gpuObject.getDepthStencilBufferSubresource()); diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index 4068865274..f47211555a 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -216,19 +216,29 @@ void GL41FixedAllocationTexture::allocateStorage() const { const GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(_gpuObject.getTexelFormat()); const auto numMips = _gpuObject.getNumMips(); const auto numSlices = _gpuObject.getNumSlices(); + const auto numSamples = _gpuObject.getNumSamples(); // glTextureStorage2D(_id, mips, texelFormat.internalFormat, dimensions.x, dimensions.y); - for (GLint level = 0; level < numMips; level++) { - Vec3u dimensions = _gpuObject.evalMipDimensions(level); - for (GLenum target : getFaceTargets(_target)) { - if (!_gpuObject.isArray()) { - glTexImage2D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, 0, texelFormat.format, - texelFormat.type, nullptr); - } else { - glTexImage3D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, numSlices, 0, - texelFormat.format, texelFormat.type, nullptr); + if (!_gpuObject.isMultisample()) { + for (GLint level = 0; level < numMips; level++) { + Vec3u dimensions = _gpuObject.evalMipDimensions(level); + for (GLenum target : getFaceTargets(_target)) { + if (!_gpuObject.isArray()) { + glTexImage2D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, 0, texelFormat.format, + texelFormat.type, nullptr); + } else { + glTexImage3D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, numSlices, 0, + texelFormat.format, texelFormat.type, nullptr); + } } } + } else { + const auto dimensions = _gpuObject.getDimensions(); + if (!_gpuObject.isArray()) { + glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, numSamples, texelFormat.internalFormat, dimensions.x, dimensions.y, GL_FALSE); + } else { + glTexImage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, numSamples, texelFormat.internalFormat, dimensions.x, dimensions.y, dimensions.z, GL_FALSE); + } } glTexParameteri(_target, GL_TEXTURE_BASE_LEVEL, 0); diff --git a/libraries/render-utils/src/ToneMappingEffect.cpp b/libraries/render-utils/src/ToneMappingEffect.cpp index c40505917c..c631ae4383 100644 --- a/libraries/render-utils/src/ToneMappingEffect.cpp +++ b/libraries/render-utils/src/ToneMappingEffect.cpp @@ -84,7 +84,7 @@ void ToneMappingEffect::render(RenderArgs* args, const gpu::TexturePointer& ligh void ToneMappingDeferred::configure(const Config& config) { _toneMappingEffect.setExposure(config.exposure); - _toneMappingEffect.setColorFilter(config.colorFilter); + _toneMappingEffect.setColorFilter(toGlm(config.colorFilter)); _toneMappingEffect.setToneCurve((ToneMappingEffect::ToneCurve)config.curve); } diff --git a/libraries/render-utils/src/ToneMappingEffect.h b/libraries/render-utils/src/ToneMappingEffect.h index ae394c4dc3..163805ae91 100644 --- a/libraries/render-utils/src/ToneMappingEffect.h +++ b/libraries/render-utils/src/ToneMappingEffect.h @@ -70,18 +70,18 @@ private: class ToneMappingConfig : public render::Job::Config { Q_OBJECT Q_PROPERTY(float exposure MEMBER exposure WRITE setExposure); - Q_PROPERTY(glm::vec3 colorFilter MEMBER colorFilter WRITE setColorFilter); + Q_PROPERTY(QColor colorFilter MEMBER colorFilter WRITE setColorFilter); Q_PROPERTY(int curve MEMBER curve WRITE setCurve); public: ToneMappingConfig() : render::Job::Config(true) {} void setExposure(float newExposure) { exposure = newExposure; emit dirty(); } - void setColorFilter(const glm::vec3& newColorFilter) { colorFilter = newColorFilter; emit dirty(); } + void setColorFilter(const QColor& newColorFilter) { colorFilter = newColorFilter; emit dirty(); } void setCurve(int newCurve) { curve = std::max((int)ToneMappingEffect::None, std::min((int)ToneMappingEffect::Filmic, newCurve)); emit dirty(); } float exposure{ 0.0f }; - glm::vec3 colorFilter { 1.0f }; + QColor colorFilter { 255, 255, 255 }; int curve{ ToneMappingEffect::None }; signals: void dirty(); diff --git a/scripts/developer/utilities/lib/plotperf/Color.qml b/scripts/developer/utilities/lib/plotperf/Color.qml index 1ad72fe2e6..64a3980947 100644 --- a/scripts/developer/utilities/lib/plotperf/Color.qml +++ b/scripts/developer/utilities/lib/plotperf/Color.qml @@ -23,6 +23,7 @@ Item { height: 24 property var _color: Qt.rgba(1.0, 1.0, 1.0, 1.0 ); + property var _lcolor: Qt.vec4(1.0, 1.0, 1.0, 1.0 ); property var zoneWidth: width / 3; property var hoveredOn: 0.0; property var sliderHeight: height / 2; diff --git a/scripts/developer/utilities/render/deferredLighting.qml b/scripts/developer/utilities/render/deferredLighting.qml index 8c3e0fce94..d3cc7adca3 100644 --- a/scripts/developer/utilities/render/deferredLighting.qml +++ b/scripts/developer/utilities/render/deferredLighting.qml @@ -124,22 +124,6 @@ Rectangle { anchors.right: parent.right } } - Item { - HifiControls.Label { - text: "Color filter" - anchors.left: parent.left - } - - Color { - height: 20 - anchors.right: parent.right - width: parent.width / 2 - _color: render.mainViewTask.getConfig("ToneMapping")["colorFilter"] - onNewColor: { - render.mainViewTask.getConfig("ToneMapping")["colorFilter"] = getXColor() - } - } - } Item { height: childrenRect.height anchors.left: parent.left @@ -150,18 +134,17 @@ Rectangle { anchors.left: parent.left } - HifiControls.ComboBox { + ComboBox { anchors.right: parent.right currentIndex: 1 - model: ListModel { - id: cbItems - ListElement { text: "RGB"; color: "Yellow" } - ListElement { text: "SRGB"; color: "Green" } - ListElement { text: "Reinhard"; color: "Yellow" } - ListElement { text: "Filmic"; color: "White" } - } + model: [ + "RGB", + "SRGB", + "Reinhard", + "Filmic", + ] width: 200 - onCurrentIndexChanged: { render.mainViewTask.getConfig("ToneMapping")["curve"] = currentIndex } + onCurrentIndexChanged: { render.mainViewTask.getConfig("ToneMapping")["curve"] = currentIndex; } } } } @@ -186,7 +169,7 @@ Rectangle { framebuffer.config.mode = mode; } - HifiControls.ComboBox { + ComboBox { anchors.right: parent.right currentIndex: 0 model: ListModel { From 9ad783135cde25eb5d5b49eae73f2c1e6b8975d4 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 11 Feb 2019 19:42:05 -0800 Subject: [PATCH 09/11] Bringing back brownBis to just msaa support --- interface/src/graphics/GraphicsEngine.cpp | 1 + .../display-plugins/OpenGLDisplayPlugin.cpp | 23 ++++++------- .../src/display-plugins/SrgbToLinear.slf | 29 ++-------------- .../display-plugins/hmd/HmdDisplayPlugin.cpp | 4 +-- libraries/gl/src/gl/GLHelpers.cpp | 1 - libraries/gpu/src/gpu/State.h | 1 + .../render-utils/src/RenderForwardTask.cpp | 33 +++++++------------ .../render-utils/src/RenderForwardTask.h | 19 +---------- .../render-utils/src/ToneMappingEffect.cpp | 11 ++----- .../render-utils/src/ToneMappingEffect.h | 14 ++------ libraries/render-utils/src/toneMapping.slf | 10 ++---- plugins/oculus/src/OculusDisplayPlugin.cpp | 19 ++++------- 12 files changed, 43 insertions(+), 122 deletions(-) diff --git a/interface/src/graphics/GraphicsEngine.cpp b/interface/src/graphics/GraphicsEngine.cpp index bff778bd62..c2137d3d97 100644 --- a/interface/src/graphics/GraphicsEngine.cpp +++ b/interface/src/graphics/GraphicsEngine.cpp @@ -66,6 +66,7 @@ void GraphicsEngine::initializeGPU(GLWidget* glwidget) { } void GraphicsEngine::initializeRender(bool disableDeferred) { + // Set up the render engine render::CullFunctor cullFunctor = LODManager::shouldRender; _renderEngine->addJob("UpdateScene"); diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index ffd51cd61f..18d961d7bd 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -354,14 +354,14 @@ void OpenGLDisplayPlugin::customizeContext() { if ((image.width() > 0) && (image.height() > 0)) { cursorData.texture = gpu::Texture::createStrict( - gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::SRGBA), + gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA), image.width(), image.height(), gpu::Texture::MAX_NUM_MIPS, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)); cursorData.texture->setSource("cursor texture"); auto usage = gpu::Texture::Usage::Builder().withColor().withAlpha(); cursorData.texture->setUsage(usage.build()); - cursorData.texture->setStoredMipFormat(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::SRGBA)); + cursorData.texture->setStoredMipFormat(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA)); cursorData.texture->assignStoredMip(0, image.byteCount(), image.constBits()); cursorData.texture->setAutoGenerateMips(true); } @@ -382,13 +382,12 @@ void OpenGLDisplayPlugin::customizeContext() { { gpu::ShaderPointer program = gpu::Shader::createProgram(shader::gpu::program::DrawTexture); _simplePipeline = gpu::Pipeline::create(program, scissorState); - // _hudPipeline = gpu::Pipeline::create(program, blendState); + _hudPipeline = gpu::Pipeline::create(program, blendState); } { gpu::ShaderPointer program = gpu::Shader::createProgram(shader::display_plugins::program::SrgbToLinear); _presentPipeline = gpu::Pipeline::create(program, scissorState); - _hudPipeline = gpu::Pipeline::create(program, blendState); } { @@ -515,8 +514,7 @@ void OpenGLDisplayPlugin::renderFromTexture(gpu::Batch& batch, const gpu::Textur batch.setViewportTransform(viewport); batch.setResourceTexture(0, texture); #ifndef USE_GLES - batch.setPipeline(_simplePipeline); - // batch.setPipeline(_presentPipeline); + batch.setPipeline(_presentPipeline); #else batch.setPipeline(_simplePipeline); #endif @@ -607,7 +605,7 @@ void OpenGLDisplayPlugin::compositePointer() { render([&](gpu::Batch& batch) { batch.enableStereo(false); batch.setProjectionTransform(mat4()); - // batch.setFramebuffer(_compositeFramebuffer); + batch.setFramebuffer(_compositeFramebuffer); batch.setPipeline(_cursorPipeline); batch.setResourceTexture(0, cursorData.texture); batch.resetViewTransform(); @@ -643,7 +641,7 @@ void OpenGLDisplayPlugin::compositeLayers() { { PROFILE_RANGE_EX(render_detail, "compositeScene", 0xff0077ff, (uint64_t)presentCount()) - // compositeScene(); + compositeScene(); } #ifdef HIFI_ENABLE_NSIGHT_DEBUG @@ -657,10 +655,10 @@ void OpenGLDisplayPlugin::compositeLayers() { }); } - /* { + { PROFILE_RANGE_EX(render_detail, "compositeExtra", 0xff0077ff, (uint64_t)presentCount()) compositeExtra(); - }*/ + } // Draw the pointer last so it's on top of everything auto compositorHelper = DependencyManager::get(); @@ -675,8 +673,7 @@ void OpenGLDisplayPlugin::internalPresent() { // Note: _displayTexture must currently be the same size as the display. uvec2 dims = _displayTexture ? uvec2(_displayTexture->getDimensions()) : getSurfacePixels(); auto viewport = ivec4(uvec2(0), dims); - // renderFromTexture(batch, _displayTexture ? _displayTexture : _compositeFramebuffer->getRenderBuffer(0), viewport, viewport); - renderFromTexture(batch, _displayTexture ? _displayTexture : _currentFrame->framebuffer->getRenderBuffer(0), viewport, viewport); + renderFromTexture(batch, _displayTexture ? _displayTexture : _compositeFramebuffer->getRenderBuffer(0), viewport, viewport); }); swapBuffers(); _presentRate.increment(); @@ -885,7 +882,7 @@ OpenGLDisplayPlugin::~OpenGLDisplayPlugin() { void OpenGLDisplayPlugin::updateCompositeFramebuffer() { auto renderSize = glm::uvec2(getRecommendedRenderSize()); if (!_compositeFramebuffer || _compositeFramebuffer->getSize() != renderSize) { - _compositeFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("OpenGLDisplayPlugin::composite", gpu::Element::COLOR_SRGBA_32, renderSize.x, renderSize.y)); + _compositeFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("OpenGLDisplayPlugin::composite", gpu::Element::COLOR_RGBA_32, renderSize.x, renderSize.y)); } } diff --git a/libraries/display-plugins/src/display-plugins/SrgbToLinear.slf b/libraries/display-plugins/src/display-plugins/SrgbToLinear.slf index f9b333b3db..8b324c81a5 100644 --- a/libraries/display-plugins/src/display-plugins/SrgbToLinear.slf +++ b/libraries/display-plugins/src/display-plugins/SrgbToLinear.slf @@ -17,31 +17,6 @@ vec3 colorToLinearRGB(vec3 srgb) { } void main(void) { - vec4 fetched = texture(colorMap, varTexCoord0); - //outFragColor = fetched; - outFragColor.a = fetched.a; - outFragColor.rgb = pow(fetched.rgb, vec3(2.2)); - - /* int vSize = 300; - int hSize = 400; - - if (gl_FragCoord.y < vSize) { - finalColor *= pow(2.0, 0.1); - } - else if (gl_FragCoord.y > 2 * vSize) { - finalColor *= pow(2.0, -0.1); - } - else { - finalColor; - } - - if (gl_FragCoord.x 2 * hSize) { - outFragColor.rgb = pow(finalColor, vec3(1.0 / 2.2)); - } - else { - outFragColor.rgb = finalColor; - }*/ - // outFragColor.rgb = sqrt(finalColor); + outFragColor.a = 1.0; + outFragColor.rgb = colorToLinearRGB(texture(colorMap, varTexCoord0).rgb); } diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index 0a953f142d..321bcc3fd2 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -260,9 +260,7 @@ void HmdDisplayPlugin::internalPresent() { viewport.z *= 2; } - // renderFromTexture(batch, _compositeFramebuffer->getRenderBuffer(0), viewport, scissor, fbo); - renderFromTexture(batch, _currentFrame->framebuffer->getRenderBuffer(0), viewport, scissor, fbo); - + renderFromTexture(batch, _compositeFramebuffer->getRenderBuffer(0), viewport, scissor, fbo); }); swapBuffers(); diff --git a/libraries/gl/src/gl/GLHelpers.cpp b/libraries/gl/src/gl/GLHelpers.cpp index 5f6e305b92..879ea7c5e2 100644 --- a/libraries/gl/src/gl/GLHelpers.cpp +++ b/libraries/gl/src/gl/GLHelpers.cpp @@ -99,7 +99,6 @@ const QSurfaceFormat& getDefaultOpenGLSurfaceFormat() { #else format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); #endif - format.setColorSpace(QSurfaceFormat::sRGBColorSpace); if (gl::Context::enableDebugLogger()) { format.setOption(QSurfaceFormat::DebugContext); diff --git a/libraries/gpu/src/gpu/State.h b/libraries/gpu/src/gpu/State.h index 8354f940c8..abe0cd7731 100755 --- a/libraries/gpu/src/gpu/State.h +++ b/libraries/gpu/src/gpu/State.h @@ -278,6 +278,7 @@ public: FillMode fillMode{ FILL_FACE }; CullMode cullMode{ CULL_NONE }; ColorMask colorWriteMask{ WRITE_ALL }; + Flags flags; }; diff --git a/libraries/render-utils/src/RenderForwardTask.cpp b/libraries/render-utils/src/RenderForwardTask.cpp index 01da7f73df..ffdbc1c4b1 100755 --- a/libraries/render-utils/src/RenderForwardTask.cpp +++ b/libraries/render-utils/src/RenderForwardTask.cpp @@ -118,22 +118,22 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend const auto transparentInputs = DrawForward::Inputs(transparents, lightingModel).asVarying(); task.addJob("DrawTransparents", transparentInputs, shapePlumber); - /* { // Debug the bounds of the rendered items, still look at the zbuffer + { // Debug the bounds of the rendered items, still look at the zbuffer task.addJob("DrawMetaBounds", metas); task.addJob("DrawBounds", opaques); task.addJob("DrawTransparentBounds", transparents); - task.addJob("DrawZones", zones);*/ + task.addJob("DrawZones", zones); const auto debugZoneInputs = DebugZoneLighting::Inputs(deferredFrameTransform, lightFrame, backgroundFrame).asVarying(); task.addJob("DrawZoneStack", debugZoneInputs); - // } + } // Lighting Buffer ready for tone mapping // Forward rendering on GLES doesn't support tonemapping to and from the same FBO, so we specify // the output FBO as null, which causes the tonemapping to target the blit framebuffer - // const auto toneMappingInputs = ToneMappingDeferred::Inputs(framebuffer, static_cast(nullptr) ).asVarying(); - // task.addJob("ToneMapping", toneMappingInputs); + const auto toneMappingInputs = ToneMappingDeferred::Inputs(framebuffer, static_cast(nullptr) ).asVarying(); + task.addJob("ToneMapping", toneMappingInputs); // Layered Overlays // Composite the HUD and HUD overlays @@ -141,40 +141,29 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend // Disable blit because we do tonemapping and compositing directly to the blit FBO // Blit! - task.addJob("Blit", framebuffer); -} - -void PrepareFramebuffer::configure(const PrepareFramebuffer::Config& config) { - _numSamples = config.getNumSamples(); + // task.addJob("Blit", framebuffer); } void PrepareFramebuffer::run(const RenderContextPointer& renderContext, gpu::FramebufferPointer& framebuffer) { glm::uvec2 frameSize(renderContext->args->_viewport.z, renderContext->args->_viewport.w); // Resizing framebuffers instead of re-building them seems to cause issues with threaded rendering - if (_framebuffer && (_framebuffer->getSize() != frameSize || _framebuffer->getNumSamples() != _numSamples)) { + if (_framebuffer && _framebuffer->getSize() != frameSize) { _framebuffer.reset(); } if (!_framebuffer) { _framebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("forward")); - - int numSamples = _numSamples; auto colorFormat = gpu::Element::COLOR_SRGBA_32; - auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR); - /* auto colorTexture = - gpu::Texture::createRenderBuffer(colorFormat, frameSize.x, frameSize.y, gpu::Texture::SINGLE_MIP, defaultSampler); - _framebuffer->setRenderBuffer(0, colorTexture);*/ + auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_POINT); auto colorTexture = - gpu::Texture::createRenderBufferMultisample(colorFormat, frameSize.x, frameSize.y, numSamples, defaultSampler); + gpu::Texture::createRenderBuffer(colorFormat, frameSize.x, frameSize.y, gpu::Texture::SINGLE_MIP, defaultSampler); _framebuffer->setRenderBuffer(0, colorTexture); + auto depthFormat = gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::DEPTH_STENCIL); // Depth24_Stencil8 texel format - /* auto depthTexture = - gpu::Texture::createRenderBuffer(depthFormat, frameSize.x, frameSize.y, gpu::Texture::SINGLE_MIP, defaultSampler); - _framebuffer->setDepthStencilBuffer(depthTexture, depthFormat);*/ auto depthTexture = - gpu::Texture::createRenderBufferMultisample(depthFormat, frameSize.x, frameSize.y, numSamples, defaultSampler); + gpu::Texture::createRenderBuffer(depthFormat, frameSize.x, frameSize.y, gpu::Texture::SINGLE_MIP, defaultSampler); _framebuffer->setDepthStencilBuffer(depthTexture, depthFormat); } diff --git a/libraries/render-utils/src/RenderForwardTask.h b/libraries/render-utils/src/RenderForwardTask.h index 909e09452c..e6a6008319 100755 --- a/libraries/render-utils/src/RenderForwardTask.h +++ b/libraries/render-utils/src/RenderForwardTask.h @@ -27,33 +27,16 @@ public: void build(JobModel& task, const render::Varying& input, render::Varying& output); }; -class PrepareFramebufferConfig : public render::Job::Config { - Q_OBJECT - Q_PROPERTY(int numSamples WRITE setNumSamples READ getNumSamples NOTIFY dirty) -public: - int getNumSamples() const { return numSamples; } - void setNumSamples(int num) { numSamples = num; emit dirty(); } - -signals: - void dirty(); - -protected: - int numSamples{ 8 }; -}; - class PrepareFramebuffer { public: using Inputs = gpu::FramebufferPointer; - using Config = PrepareFramebufferConfig; - using JobModel = render::Job::ModelO; + using JobModel = render::Job::ModelO; - void configure(const Config& config); void run(const render::RenderContextPointer& renderContext, gpu::FramebufferPointer& framebuffer); private: gpu::FramebufferPointer _framebuffer; - int _numSamples { 8 }; }; class PrepareForward { diff --git a/libraries/render-utils/src/ToneMappingEffect.cpp b/libraries/render-utils/src/ToneMappingEffect.cpp index c631ae4383..64a2adb5d4 100644 --- a/libraries/render-utils/src/ToneMappingEffect.cpp +++ b/libraries/render-utils/src/ToneMappingEffect.cpp @@ -40,13 +40,6 @@ void ToneMappingEffect::setExposure(float exposure) { } } -void ToneMappingEffect::setColorFilter(const glm::vec3& colorFilter) { - auto& params = _parametersBuffer.get(); - if (params._colorFilter != colorFilter) { - _parametersBuffer.edit()._colorFilter = colorFilter; - } -} - void ToneMappingEffect::setToneCurve(ToneCurve curve) { auto& params = _parametersBuffer.get(); if (params._toneCurve != curve) { @@ -69,6 +62,9 @@ void ToneMappingEffect::render(RenderArgs* args, const gpu::TexturePointer& ligh batch.enableStereo(false); batch.setFramebuffer(destinationFramebuffer); + // FIXME: Generate the Luminosity map + //batch.generateTextureMips(lightingBuffer); + batch.setViewportTransform(args->_viewport); batch.setProjectionTransform(glm::mat4()); batch.resetViewTransform(); @@ -84,7 +80,6 @@ void ToneMappingEffect::render(RenderArgs* args, const gpu::TexturePointer& ligh void ToneMappingDeferred::configure(const Config& config) { _toneMappingEffect.setExposure(config.exposure); - _toneMappingEffect.setColorFilter(toGlm(config.colorFilter)); _toneMappingEffect.setToneCurve((ToneMappingEffect::ToneCurve)config.curve); } diff --git a/libraries/render-utils/src/ToneMappingEffect.h b/libraries/render-utils/src/ToneMappingEffect.h index 163805ae91..69694b13f5 100644 --- a/libraries/render-utils/src/ToneMappingEffect.h +++ b/libraries/render-utils/src/ToneMappingEffect.h @@ -31,9 +31,6 @@ public: void setExposure(float exposure); float getExposure() const { return _parametersBuffer.get()._exposure; } - void setColorFilter(const glm::vec3& colorFilter); - glm::vec3 getColorFIlter() const { return _parametersBuffer.get()._colorFilter; } - // Different tone curve available enum ToneCurve { None = 0, @@ -54,10 +51,8 @@ private: float _exposure = 0.0f; float _twoPowExposure = 1.0f; glm::vec2 spareA; - glm::vec3 _colorFilter{ 1.0f }; - float spareB; - int _toneCurve = None; - glm::vec3 spareC; + int _toneCurve = Gamma22; + glm::vec3 spareB; Parameters() {} }; @@ -70,19 +65,16 @@ private: class ToneMappingConfig : public render::Job::Config { Q_OBJECT Q_PROPERTY(float exposure MEMBER exposure WRITE setExposure); - Q_PROPERTY(QColor colorFilter MEMBER colorFilter WRITE setColorFilter); Q_PROPERTY(int curve MEMBER curve WRITE setCurve); public: ToneMappingConfig() : render::Job::Config(true) {} void setExposure(float newExposure) { exposure = newExposure; emit dirty(); } - void setColorFilter(const QColor& newColorFilter) { colorFilter = newColorFilter; emit dirty(); } void setCurve(int newCurve) { curve = std::max((int)ToneMappingEffect::None, std::min((int)ToneMappingEffect::Filmic, newCurve)); emit dirty(); } float exposure{ 0.0f }; - QColor colorFilter { 255, 255, 255 }; - int curve{ ToneMappingEffect::None }; + int curve{ ToneMappingEffect::Gamma22 }; signals: void dirty(); }; diff --git a/libraries/render-utils/src/toneMapping.slf b/libraries/render-utils/src/toneMapping.slf index 3b13425816..3fe53d9be1 100644 --- a/libraries/render-utils/src/toneMapping.slf +++ b/libraries/render-utils/src/toneMapping.slf @@ -17,7 +17,6 @@ struct ToneMappingParams { vec4 _exp_2powExp_s0_s1; - vec4 _colorFilter_s0; ivec4 _toneCurve_s0_s1_s2; }; @@ -33,14 +32,11 @@ LAYOUT(binding=RENDER_UTILS_BUFFER_TM_PARAMS) uniform toneMappingParamsBuffer { float getTwoPowExposure() { return params._exp_2powExp_s0_s1.y; } -vec3 getColorFilter() { - return params._colorFilter_s0.xyz; -} int getToneCurve() { return params._toneCurve_s0_s1_s2.x; } -LAYOUT(binding = RENDER_UTILS_TEXTURE_TM_COLOR) uniform sampler2D colorMap; +LAYOUT(binding=RENDER_UTILS_TEXTURE_TM_COLOR) uniform sampler2D colorMap; layout(location=0) in vec2 varTexCoord0; layout(location=0) out vec4 outFragColor; @@ -49,7 +45,7 @@ void main(void) { vec4 fragColorRaw = texture(colorMap, varTexCoord0); vec3 fragColor = fragColorRaw.xyz; - vec3 srcColor = fragColor * getColorFilter() * getTwoPowExposure(); + vec3 srcColor = fragColor * getTwoPowExposure(); int toneCurve = getToneCurve(); vec3 tonedColor = srcColor; @@ -58,7 +54,7 @@ void main(void) { tonedColor = (x * (6.2 * x + 0.5)) / (x * (6.2 * x + 1.7) + 0.06); } else if (toneCurve == ToneCurveReinhard) { tonedColor = srcColor/(1.0 + srcColor); - // tonedColor = pow(tonedColor, vec3(INV_GAMMA_22)); + tonedColor = pow(tonedColor, vec3(INV_GAMMA_22)); } else if (toneCurve == ToneCurveGamma22) { tonedColor = pow(srcColor, vec3(INV_GAMMA_22)); } // else None toned = src diff --git a/plugins/oculus/src/OculusDisplayPlugin.cpp b/plugins/oculus/src/OculusDisplayPlugin.cpp index a34f068665..d3703c348e 100644 --- a/plugins/oculus/src/OculusDisplayPlugin.cpp +++ b/plugins/oculus/src/OculusDisplayPlugin.cpp @@ -150,26 +150,21 @@ void OculusDisplayPlugin::hmdPresent() { // Manually bind the texture to the FBO // FIXME we should have a way of wrapping raw GL ids in GPU objects without // taking ownership of the object - auto srcfbo = getGLBackend()->getFramebufferID(_currentFrame->framebuffer); - auto dstfbo = getGLBackend()->getFramebufferID(_outputFramebuffer); - glNamedFramebufferTexture(dstfbo, GL_COLOR_ATTACHMENT0, curTexId, 0); + auto fbo = getGLBackend()->getFramebufferID(_outputFramebuffer); + glNamedFramebufferTexture(fbo, GL_COLOR_ATTACHMENT0, curTexId, 0); auto viewport = ivec4(uvec2(), _outputFramebuffer->getSize()); - /* render([&](gpu::Batch& batch) { + render([&](gpu::Batch& batch) { batch.enableStereo(false); batch.setFramebuffer(_outputFramebuffer); batch.setViewportTransform(ivec4(uvec2(), _outputFramebuffer->getSize())); batch.setStateScissorRect(ivec4(uvec2(), _outputFramebuffer->getSize())); batch.resetViewTransform(); batch.setProjectionTransform(mat4()); - // batch.setPipeline(_presentPipeline); - batch.setPipeline(_simplePipeline); - // batch.setResourceTexture(0, _compositeFramebuffer->getRenderBuffer(0)); - batch.setResourceTexture(0, _currentFrame->framebuffer->getRenderBuffer(0)); + batch.setPipeline(_presentPipeline); + batch.setResourceTexture(0, _compositeFramebuffer->getRenderBuffer(0)); batch.draw(gpu::TRIANGLE_STRIP, 4); - });*/ - glBlitNamedFramebuffer(srcfbo, dstfbo, viewport.x, viewport.y, viewport.z, viewport.w, viewport.x, viewport.y, - viewport.z, viewport.w, GL_COLOR_BUFFER_BIT, GL_NEAREST); - glNamedFramebufferTexture(dstfbo, GL_COLOR_ATTACHMENT0, 0, 0); + }); + glNamedFramebufferTexture(fbo, GL_COLOR_ATTACHMENT0, 0, 0); } { From afb6c838ebfb5fde0d8a1a95201b9af9ff0d5f35 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 11 Feb 2019 20:13:37 -0800 Subject: [PATCH 10/11] REverting all the changes from the brown branch not used --- .../display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp | 2 +- libraries/gl/src/gl/GLHelpers.cpp | 1 - plugins/oculus/src/OculusDisplayPlugin.cpp | 1 - scripts/developer/utilities/lib/plotperf/Color.qml | 1 - scripts/developer/utilities/render/deferredLighting.qml | 1 - 5 files changed, 1 insertion(+), 5 deletions(-) diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index 18d961d7bd..6c59dbd861 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -542,7 +542,7 @@ void OpenGLDisplayPlugin::renderFromTexture(gpu::Batch& batch, const gpu::Textur batch.resetViewTransform(); batch.setViewportTransform(copyFboRect); batch.setStateScissorRect(copyFboRect); - // batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, {0.0f, 0.0f, 0.0f, 1.0f}); + batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, {0.0f, 0.0f, 0.0f, 1.0f}); batch.blit(fbo, sourceRect, copyFbo, copyRect); } } diff --git a/libraries/gl/src/gl/GLHelpers.cpp b/libraries/gl/src/gl/GLHelpers.cpp index 879ea7c5e2..2c02fdca03 100644 --- a/libraries/gl/src/gl/GLHelpers.cpp +++ b/libraries/gl/src/gl/GLHelpers.cpp @@ -99,7 +99,6 @@ const QSurfaceFormat& getDefaultOpenGLSurfaceFormat() { #else format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); #endif - if (gl::Context::enableDebugLogger()) { format.setOption(QSurfaceFormat::DebugContext); } diff --git a/plugins/oculus/src/OculusDisplayPlugin.cpp b/plugins/oculus/src/OculusDisplayPlugin.cpp index d3703c348e..a34e647a5e 100644 --- a/plugins/oculus/src/OculusDisplayPlugin.cpp +++ b/plugins/oculus/src/OculusDisplayPlugin.cpp @@ -152,7 +152,6 @@ void OculusDisplayPlugin::hmdPresent() { // taking ownership of the object auto fbo = getGLBackend()->getFramebufferID(_outputFramebuffer); glNamedFramebufferTexture(fbo, GL_COLOR_ATTACHMENT0, curTexId, 0); - auto viewport = ivec4(uvec2(), _outputFramebuffer->getSize()); render([&](gpu::Batch& batch) { batch.enableStereo(false); batch.setFramebuffer(_outputFramebuffer); diff --git a/scripts/developer/utilities/lib/plotperf/Color.qml b/scripts/developer/utilities/lib/plotperf/Color.qml index 64a3980947..1ad72fe2e6 100644 --- a/scripts/developer/utilities/lib/plotperf/Color.qml +++ b/scripts/developer/utilities/lib/plotperf/Color.qml @@ -23,7 +23,6 @@ Item { height: 24 property var _color: Qt.rgba(1.0, 1.0, 1.0, 1.0 ); - property var _lcolor: Qt.vec4(1.0, 1.0, 1.0, 1.0 ); property var zoneWidth: width / 3; property var hoveredOn: 0.0; property var sliderHeight: height / 2; diff --git a/scripts/developer/utilities/render/deferredLighting.qml b/scripts/developer/utilities/render/deferredLighting.qml index d3cc7adca3..6d98e96780 100644 --- a/scripts/developer/utilities/render/deferredLighting.qml +++ b/scripts/developer/utilities/render/deferredLighting.qml @@ -14,7 +14,6 @@ import QtQuick.Layouts 1.3 import stylesUit 1.0 import controlsUit 1.0 as HifiControls import "configSlider" -import "../lib/plotperf" Rectangle { HifiConstants { id: hifi;} From 0c2c581c646b8620433752529b8532986a76c1b9 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 11 Feb 2019 22:52:35 -0800 Subject: [PATCH 11/11] Add the gles backend MS texture ad framebuffer support --- .../src/gpu/gles/GLESBackendOutput.cpp | 4 ++ .../src/gpu/gles/GLESBackendTexture.cpp | 44 ++++++++++++------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/libraries/gpu-gles/src/gpu/gles/GLESBackendOutput.cpp b/libraries/gpu-gles/src/gpu/gles/GLESBackendOutput.cpp index 90ce8c853a..36b37083cb 100644 --- a/libraries/gpu-gles/src/gpu/gles/GLESBackendOutput.cpp +++ b/libraries/gpu-gles/src/gpu/gles/GLESBackendOutput.cpp @@ -130,6 +130,8 @@ public: } #endif + } else if (gltexture->_target == GL_TEXTURE_2D_MULTISAMPLE) { + glFramebufferTexture2D(GL_FRAMEBUFFER, colorAttachments[unit], GL_TEXTURE_2D_MULTISAMPLE, gltexture->_texture, 0); } else { glFramebufferTextureLayer(GL_FRAMEBUFFER, colorAttachments[unit], gltexture->_texture, 0, b._subresource); @@ -162,6 +164,8 @@ public: if (gltexture) { if (gltexture->_target == GL_TEXTURE_2D) { glFramebufferTexture2D(GL_FRAMEBUFFER, attachement, GL_TEXTURE_2D, gltexture->_texture, 0); + } else if (gltexture->_target == GL_TEXTURE_2D_MULTISAMPLE) { + glFramebufferTexture2D(GL_FRAMEBUFFER, attachement, GL_TEXTURE_2D_MULTISAMPLE, gltexture->_texture, 0); } else { glFramebufferTextureLayer(GL_FRAMEBUFFER, attachement, gltexture->_texture, 0, _gpuObject.getDepthStencilBufferSubresource()); diff --git a/libraries/gpu-gles/src/gpu/gles/GLESBackendTexture.cpp b/libraries/gpu-gles/src/gpu/gles/GLESBackendTexture.cpp index 23dc271af9..4b2d4d09e6 100644 --- a/libraries/gpu-gles/src/gpu/gles/GLESBackendTexture.cpp +++ b/libraries/gpu-gles/src/gpu/gles/GLESBackendTexture.cpp @@ -272,28 +272,40 @@ void GLESFixedAllocationTexture::allocateStorage() const { const GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(_gpuObject.getTexelFormat()); const auto numMips = _gpuObject.getNumMips(); const auto numSlices = _gpuObject.getNumSlices(); + const auto numSamples = _gpuObject.getNumSamples(); // glTextureStorage2D(_id, mips, texelFormat.internalFormat, dimensions.x, dimensions.y); - for (GLint level = 0; level < numMips; level++) { - Vec3u dimensions = _gpuObject.evalMipDimensions(level); - for (GLenum target : getFaceTargets(_target)) { - if (texelFormat.isCompressed()) { - auto size = getCompressedImageSize(dimensions.x, dimensions.y, texelFormat.internalFormat); - if (!_gpuObject.isArray()) { - glCompressedTexImage2D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, 0, size, nullptr); + if (!_gpuObject.isMultisample()) { + for (GLint level = 0; level < numMips; level++) { + Vec3u dimensions = _gpuObject.evalMipDimensions(level); + for (GLenum target : getFaceTargets(_target)) { + if (texelFormat.isCompressed()) { + auto size = getCompressedImageSize(dimensions.x, dimensions.y, texelFormat.internalFormat); + if (!_gpuObject.isArray()) { + glCompressedTexImage2D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, 0, size, nullptr); + } else { + glCompressedTexImage3D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, numSlices, 0, size * numSlices, nullptr); + } } else { - glCompressedTexImage3D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, numSlices, 0, size * numSlices, nullptr); - } - } else { - if (!_gpuObject.isArray()) { - glTexImage2D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, 0, texelFormat.format, - texelFormat.type, nullptr); - } else { - glTexImage3D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, numSlices, 0, - texelFormat.format, texelFormat.type, nullptr); + if (!_gpuObject.isArray()) { + glTexImage2D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, 0, texelFormat.format, + texelFormat.type, nullptr); + } else { + glTexImage3D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, numSlices, 0, + texelFormat.format, texelFormat.type, nullptr); + } } } } + } else { + const auto dimensions = _gpuObject.getDimensions(); + if (!_gpuObject.isArray()) { + glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, numSamples, + texelFormat.internalFormat, dimensions.x, dimensions.y, + GL_FALSE); + } else { + // NOT SUPPORTED (yet) + } } glTexParameteri(_target, GL_TEXTURE_BASE_LEVEL, 0);