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); } {