From d2ebaef69e9c057bcd6cf4c0ba5e60dd688b141b Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 15 Dec 2015 18:18:42 -0800 Subject: [PATCH 1/4] Adding a simple manual exposure control to configure the tonemapping and expose it to js. Add a convenient way to access the Job._concept._data with template --- examples/utilities/tools/renderEngineDebug.js | 5 +++ interface/src/Application.cpp | 2 + libraries/gpu/src/gpu/Batch.cpp | 6 +++ libraries/gpu/src/gpu/Batch.h | 4 ++ libraries/gpu/src/gpu/GLBackend.cpp | 1 + libraries/gpu/src/gpu/GLBackend.h | 7 +++- libraries/gpu/src/gpu/GLBackendOutput.cpp | 2 +- libraries/gpu/src/gpu/GLBackendPipeline.cpp | 11 +++++ libraries/gpu/src/gpu/GLBackendTexture.cpp | 37 ++++++++++++++++- .../render-utils/src/DebugDeferredBuffer.cpp | 4 +- .../render-utils/src/FramebufferCache.cpp | 4 +- .../render-utils/src/RenderDeferredTask.cpp | 18 +++++++++ .../render-utils/src/RenderDeferredTask.h | 5 +++ .../render-utils/src/ToneMappingEffect.cpp | 40 ++++++++++++++++--- .../render-utils/src/ToneMappingEffect.h | 8 +++- libraries/render/src/render/DrawTask.h | 17 ++++++++ libraries/render/src/render/Engine.h | 2 + .../src/SceneScriptingInterface.h | 4 ++ 18 files changed, 165 insertions(+), 12 deletions(-) diff --git a/examples/utilities/tools/renderEngineDebug.js b/examples/utilities/tools/renderEngineDebug.js index 60686912e8..2c0dc352b4 100755 --- a/examples/utilities/tools/renderEngineDebug.js +++ b/examples/utilities/tools/renderEngineDebug.js @@ -109,6 +109,11 @@ panel.newCheckbox("Network/Physics status", function(value) { return (value & showNetworkStatusFlag) > 0; } ); +panel.newSlider("Tone Mapping Exposure", -10, 10, + function (value) { Scene.setEngineToneMappingExposure(value); }, + function() { return Scene.getEngineToneMappingExposure(); }, + function (value) { return (value); }); + var tickTackPeriod = 500; function updateCounters() { diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c26c8330f8..c6fa997eae 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3691,6 +3691,8 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se renderContext._occlusionStatus = Menu::getInstance()->isOptionChecked(MenuOption::DebugAmbientOcclusion); renderContext._fxaaStatus = Menu::getInstance()->isOptionChecked(MenuOption::Antialiasing); + renderContext._toneMappingExposure = sceneInterface->getEngineToneMappingExposure(); + renderArgs->_shouldRender = LODManager::shouldRender; renderContext.args = renderArgs; diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp index 14871aafd1..843eb3d3a5 100644 --- a/libraries/gpu/src/gpu/Batch.cpp +++ b/libraries/gpu/src/gpu/Batch.cpp @@ -311,6 +311,12 @@ void Batch::blit(const FramebufferPointer& src, const Vec4i& srcViewport, _params.push_back(dstViewport.w); } +void Batch::generateTextureMipmap(const TexturePointer& texture) { + ADD_COMMAND(generateTextureMipmap); + + _params.push_back(_textures.cache(texture)); +} + void Batch::beginQuery(const QueryPointer& query) { ADD_COMMAND(beginQuery); diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index 2afcc7caa9..122285f5ea 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -211,6 +211,9 @@ public: // with xy and zw the bounding corners of the rect region. void blit(const FramebufferPointer& src, const Vec4i& srcRect, const FramebufferPointer& dst, const Vec4i& dstRect); + // Generate the mipmap for a texture + void generateTextureMipmap(const TexturePointer& texture); + // Query Section void beginQuery(const QueryPointer& query); void endQuery(const QueryPointer& query); @@ -292,6 +295,7 @@ public: COMMAND_setFramebuffer, COMMAND_clearFramebuffer, COMMAND_blit, + COMMAND_generateTextureMipmap, COMMAND_beginQuery, COMMAND_endQuery, diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index d4f3c5c4b3..ff1b207f7c 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -52,6 +52,7 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] = (&::gpu::GLBackend::do_setFramebuffer), (&::gpu::GLBackend::do_clearFramebuffer), (&::gpu::GLBackend::do_blit), + (&::gpu::GLBackend::do_generateTextureMipmap), (&::gpu::GLBackend::do_beginQuery), (&::gpu::GLBackend::do_endQuery), diff --git a/libraries/gpu/src/gpu/GLBackend.h b/libraries/gpu/src/gpu/GLBackend.h index f44fbe6c0d..4733d81cbf 100644 --- a/libraries/gpu/src/gpu/GLBackend.h +++ b/libraries/gpu/src/gpu/GLBackend.h @@ -376,12 +376,16 @@ protected: // Resource Stage void do_setResourceTexture(Batch& batch, size_t paramOffset); - + + // update resource cache and do the gl unbind call with the current gpu::Texture cached at slot s void releaseResourceTexture(uint32_t slot); + void resetResourceStage(); struct ResourceStageState { Textures _textures; + int findEmptyTextureSlot() const; + ResourceStageState(): _textures(MAX_NUM_RESOURCE_TEXTURES, nullptr) {} @@ -432,6 +436,7 @@ protected: void do_setFramebuffer(Batch& batch, size_t paramOffset); void do_clearFramebuffer(Batch& batch, size_t paramOffset); void do_blit(Batch& batch, size_t paramOffset); + void do_generateTextureMipmap(Batch& batch, size_t paramOffset); // Synchronize the state cache of this Backend with the actual real state of the GL Context void syncOutputStateCache(); diff --git a/libraries/gpu/src/gpu/GLBackendOutput.cpp b/libraries/gpu/src/gpu/GLBackendOutput.cpp index 6d8ce7b2c6..5f226141a8 100755 --- a/libraries/gpu/src/gpu/GLBackendOutput.cpp +++ b/libraries/gpu/src/gpu/GLBackendOutput.cpp @@ -361,4 +361,4 @@ void GLBackend::downloadFramebuffer(const FramebufferPointer& srcFramebuffer, co glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); (void) CHECK_GL_ERROR(); -} \ No newline at end of file +} diff --git a/libraries/gpu/src/gpu/GLBackendPipeline.cpp b/libraries/gpu/src/gpu/GLBackendPipeline.cpp index 8601c7512b..8c9647e0f2 100755 --- a/libraries/gpu/src/gpu/GLBackendPipeline.cpp +++ b/libraries/gpu/src/gpu/GLBackendPipeline.cpp @@ -231,6 +231,7 @@ void GLBackend::releaseResourceTexture(uint32_t slot) { } } + void GLBackend::resetResourceStage() { for (uint32_t i = 0; i < _resource._textures.size(); i++) { releaseResourceTexture(i); @@ -268,3 +269,13 @@ void GLBackend::do_setResourceTexture(Batch& batch, size_t paramOffset) { } } +int GLBackend::ResourceStageState::findEmptyTextureSlot() const { + // start from the end of the slots, try to find an empty one that can be used + for (auto i = MAX_NUM_RESOURCE_TEXTURES - 1; i > 0; i--) { + if (!_textures[i]) { + return i; + } + } + return -1; +} + diff --git a/libraries/gpu/src/gpu/GLBackendTexture.cpp b/libraries/gpu/src/gpu/GLBackendTexture.cpp index 73bf02e8c7..eaed50b850 100755 --- a/libraries/gpu/src/gpu/GLBackendTexture.cpp +++ b/libraries/gpu/src/gpu/GLBackendTexture.cpp @@ -404,8 +404,9 @@ GLBackend::GLTexture* GLBackend::syncGPUObject(const Texture& texture) { if (bytes && texture.isAutogenerateMips()) { glGenerateMipmap(GL_TEXTURE_2D); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + } else if (texture.isAutogenerateMips()) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); } - object->_target = GL_TEXTURE_2D; syncSampler(texture.getSampler(), texture.getType(), object); @@ -588,3 +589,37 @@ void GLBackend::syncSampler(const Sampler& sampler, Texture::Type type, GLTextur glTexParameterf(object->_target, GL_TEXTURE_MAX_ANISOTROPY_EXT, sampler.getMaxAnisotropy()); } + + + +void GLBackend::do_generateTextureMipmap(Batch& batch, size_t paramOffset) { + TexturePointer resourceTexture = batch._textures.get(batch._params[paramOffset + 0]._uint); + if (!resourceTexture) { + return; + } + + GLTexture* object = GLBackend::syncGPUObject(*resourceTexture); + if (!object) { + return; + } + + // IN 4.1 we still need to find an available slot + auto freeSlot = _resource.findEmptyTextureSlot(); + auto bindingSlot = (freeSlot < 0 ? 0 : freeSlot); + glActiveTexture(GL_TEXTURE0 + bindingSlot); + glBindTexture(object->_target, object->_texture); + + glGenerateMipmap(object->_target); + + if (freeSlot < 0) { + // If had to use slot 0 then restore state + GLTexture* boundObject = GLBackend::syncGPUObject(*_resource._textures[0]); + if (boundObject) { + glBindTexture(boundObject->_target, boundObject->_texture); + } + } else { + // clean up + glBindTexture(object->_target, 0); + } + (void)CHECK_GL_ERROR(); +} diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index 842729144d..169ae0b58e 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -49,7 +49,7 @@ static const std::string FUNCTIONS_PLACEHOLDER { "/*FUNCTIONS_PLACEHOLDER*/" }; std::string DebugDeferredBuffer::getCode(Modes mode) { switch (mode) { case DiffuseMode: { - QString code = "return vec4(texture(%1, uv).xyz, 1.0);"; + QString code = "return vec4(pow(texture(%1, uv).xyz, vec3(1.0 / 2.2)), 1.0);"; return code.arg(SLOT_NAMES[Diffuse].c_str()).toStdString(); } case AlphaMode: { @@ -73,7 +73,7 @@ std::string DebugDeferredBuffer::getCode(Modes mode) { return code.arg(SLOT_NAMES[Depth].c_str()).toStdString(); } case LightingMode: { - QString code = "return vec4(texture(%1, uv).xyz, 1.0);"; + QString code = "return vec4(pow(texture(%1, uv).xyz, vec3(1.0 / 2.2)), 1.0);"; return code.arg(SLOT_NAMES[Lighting].c_str()).toStdString(); } case CustomMode: diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index 7b8c0f7f35..e64e245806 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -87,9 +87,11 @@ void FramebufferCache::createPrimaryFramebuffer() { auto tex = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width * 0.5, height * 0.5, defaultSampler)); _selfieFramebuffer->setRenderBuffer(0, tex); + auto smoothSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR); + //_lightingTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, width, height, defaultSampler)); //lightingTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC3, gpu::NUINT8, gpu::R11G11B10), width, height, defaultSampler)); - _lightingTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::HALF, gpu::RGBA), width, height, defaultSampler)); + _lightingTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::HALF, gpu::RGBA), width, height, smoothSampler)); _lightingFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); _lightingFramebuffer->setRenderBuffer(0, _lightingTexture); _lightingFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 5f9cb7b575..ef95876f11 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -104,6 +104,7 @@ RenderDeferredTask::RenderDeferredTask() : Task() { // Lighting Buffer ready for tone mapping _jobs.push_back(Job(new ToneMappingDeferred::JobModel("ToneMapping"))); + _toneMappingJobIndex = _jobs.size() - 1; // Debugging Deferred buffer job _jobs.push_back(Job(new DebugDeferredBuffer::JobModel("DebugDeferredBuffer"))); @@ -164,6 +165,8 @@ void RenderDeferredTask::run(const SceneContextPointer& sceneContext, const Rend setAntialiasingStatus(renderContext->_fxaaStatus); + setToneMappingExposure(renderContext->_toneMappingExposure); + renderContext->args->_context->syncCache(); for (auto job : _jobs) { @@ -390,3 +393,18 @@ void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const }); args->_batch = nullptr; } + + +void RenderDeferredTask::setToneMappingExposure(float exposure) { + if (_toneMappingJobIndex >= 0) { + _jobs[_toneMappingJobIndex].edit()._toneMappingEffect.setExposure(exposure); + } +} + +float RenderDeferredTask::getToneMappingExposure() const { + if (_toneMappingJobIndex >= 0) { + _jobs[_toneMappingJobIndex].get()._toneMappingEffect.getExposure(); + } else { + return 0.0f; + } +} diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index 009e6f23b2..ea99c9f12e 100755 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -129,6 +129,11 @@ public: void setAntialiasingStatus(bool draw) { if (_antialiasingJobIndex >= 0) { _jobs[_antialiasingJobIndex].setEnabled(draw); } } bool doAntialiasingStatus() const { if (_antialiasingJobIndex >= 0) { return _jobs[_antialiasingJobIndex].isEnabled(); } else { return false; } } + int _toneMappingJobIndex = -1; + + void setToneMappingExposure(float exposure); + float getToneMappingExposure() const; + virtual void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext); diff --git a/libraries/render-utils/src/ToneMappingEffect.cpp b/libraries/render-utils/src/ToneMappingEffect.cpp index 97248a62d0..54794aa4a0 100644 --- a/libraries/render-utils/src/ToneMappingEffect.cpp +++ b/libraries/render-utils/src/ToneMappingEffect.cpp @@ -20,7 +20,8 @@ ToneMappingEffect::ToneMappingEffect() { - + Parameters parameters; + _parametersBuffer = gpu::BufferView(std::make_shared(sizeof(Parameters), (const gpu::Byte*) ¶meters)); } void ToneMappingEffect::init() { @@ -38,6 +39,16 @@ void ToneMappingEffect::init() { // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // + struct ToneMappingParams { + vec4 _exp_2powExp_s0_s1; + }; + + uniform toneMappingParamsBuffer { + ToneMappingParams params; + }; + float getTwoPowExposure() { + return params._exp_2powExp_s0_s1.y; + } uniform sampler2D colorMap; @@ -45,16 +56,24 @@ void ToneMappingEffect::init() { out vec4 outFragColor; void main(void) { - vec4 fragColor = texture(colorMap, varTexCoord0); + vec4 fragColorRaw = textureLod(colorMap, varTexCoord0, 0); + vec3 fragColor = fragColorRaw.xyz; + +/* vec4 fragColorAverage = textureLod(colorMap, varTexCoord0, 10); + float averageIntensity = length(fragColorAverage.xyz); + + vec3 fragColor = fragColorRaw.xyz / averageIntensity; +*/ + fragColor *= getTwoPowExposure(); + + // if (gl_FragCoord.x > 1000) { // Manually gamma correct from Ligthing BUffer to color buffer // outFragColor.xyz = pow( fragColor.xyz , vec3(1.0 / 2.2) ); - fragColor *= 2.0; // Hardcoded Exposure Adjustment vec3 x = max(vec3(0.0),fragColor.xyz-0.004); vec3 retColor = (x*(6.2*x+.5))/(x*(6.2*x+1.7)+0.06); - // fragColor *= 8; // Hardcoded Exposure Adjustment // fragColor = fragColor/(1.0+fragColor); // vec3 retColor = pow(fragColor.xyz,vec3(1/2.2)); @@ -70,12 +89,19 @@ void ToneMappingEffect::init() { auto blitProgram = gpu::ShaderPointer(gpu::Shader::createProgram(blitVS, blitPS)); //auto blitProgram = gpu::StandardShaderLib::getProgram(gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS, gpu::StandardShaderLib::getDrawTexturePS); - gpu::Shader::makeProgram(*blitProgram); + gpu::Shader::BindingSet slotBindings; + slotBindings.insert(gpu::Shader::Binding(std::string("toneMappingParamsBuffer"), 3)); + gpu::Shader::makeProgram(*blitProgram, slotBindings); auto blitState = std::make_shared(); blitState->setColorWriteMask(true, true, true, true); _blitLightBuffer = gpu::PipelinePointer(gpu::Pipeline::create(blitProgram, blitState)); } +void ToneMappingEffect::setExposure(float exposure) { + _parametersBuffer.edit()._exposure = exposure; + _parametersBuffer.edit()._twoPowExposure = pow(2.0, exposure); +} + void ToneMappingEffect::render(RenderArgs* args) { if (!_blitLightBuffer) { @@ -89,6 +115,9 @@ void ToneMappingEffect::render(RenderArgs* args) { auto lightingBuffer = framebufferCache->getLightingTexture(); auto destFbo = framebufferCache->getPrimaryFramebuffer(); batch.setFramebuffer(destFbo); + + batch.generateTextureMipmap(lightingBuffer); + batch.setViewportTransform(args->_viewport); batch.setProjectionTransform(glm::mat4()); batch.setViewTransform(Transform()); @@ -104,6 +133,7 @@ void ToneMappingEffect::render(RenderArgs* args) { batch.setModelTransform(model); } + batch.setUniformBuffer(3, _parametersBuffer); batch.setResourceTexture(0, lightingBuffer); batch.draw(gpu::TRIANGLE_STRIP, 4); diff --git a/libraries/render-utils/src/ToneMappingEffect.h b/libraries/render-utils/src/ToneMappingEffect.h index 9b07c0f7df..be9664ddd9 100644 --- a/libraries/render-utils/src/ToneMappingEffect.h +++ b/libraries/render-utils/src/ToneMappingEffect.h @@ -27,6 +27,9 @@ public: void render(RenderArgs* args); + void setExposure(float exposure); + float getExposure() const { return _parametersBuffer.get()._exposure; } + private: gpu::PipelinePointer _blitLightBuffer; @@ -34,7 +37,10 @@ private: // Class describing the uniform buffer with all the parameters common to the tone mapping shaders class Parameters { public: - + float _exposure = 0.0f; + float _twoPowExposure = 1.0f; + glm::vec2 spare; + Parameters() {} }; typedef gpu::BufferView UniformBufferView; diff --git a/libraries/render/src/render/DrawTask.h b/libraries/render/src/render/DrawTask.h index 3f628c3a02..52dc427251 100755 --- a/libraries/render/src/render/DrawTask.h +++ b/libraries/render/src/render/DrawTask.h @@ -84,6 +84,23 @@ public: const Varying getInput() const { return _concept->getInput(); } const Varying getOutput() const { return _concept->getOutput(); } + template T& edit() { + auto theConcept = std::dynamic_pointer_cast(_concept); + if (theConcept) { + return theConcept->_data; + } + assert(false); + return T(); + } + template const T& get() const { + auto theConcept = std::dynamic_pointer_cast(_concept); + if (theConcept) { + return theConcept->_data; + } + assert(false); + return T(); + } + void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { PerformanceTimer perfTimer(getName().c_str()); PROFILE_RANGE(getName().c_str()); diff --git a/libraries/render/src/render/Engine.h b/libraries/render/src/render/Engine.h index 26bd6f2154..c219b87f40 100644 --- a/libraries/render/src/render/Engine.h +++ b/libraries/render/src/render/Engine.h @@ -61,6 +61,8 @@ public: bool _occlusionStatus = false; bool _fxaaStatus = false; + float _toneMappingExposure = 0.0; + RenderContext() {} }; typedef std::shared_ptr RenderContextPointer; diff --git a/libraries/script-engine/src/SceneScriptingInterface.h b/libraries/script-engine/src/SceneScriptingInterface.h index 78261dfdc7..875a2a1b8f 100644 --- a/libraries/script-engine/src/SceneScriptingInterface.h +++ b/libraries/script-engine/src/SceneScriptingInterface.h @@ -118,6 +118,9 @@ public: Q_INVOKABLE void setEngineDisplayHitEffect(bool display) { _drawHitEffect = display; } Q_INVOKABLE bool doEngineDisplayHitEffect() { return _drawHitEffect; } + Q_INVOKABLE void setEngineToneMappingExposure(float exposure) { _engineToneMappingExposure = exposure; } + Q_INVOKABLE float getEngineToneMappingExposure() { return _engineToneMappingExposure; } + signals: void shouldRenderAvatarsChanged(bool shouldRenderAvatars); void shouldRenderEntitiesChanged(bool shouldRenderEntities); @@ -154,6 +157,7 @@ protected: bool _drawHitEffect = false; + float _engineToneMappingExposure = 0.0f; }; #endif // hifi_SceneScriptingInterface_h From c2feec16de17b7f91cdb08d70e0759a43d3624e8 Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 15 Dec 2015 18:24:16 -0800 Subject: [PATCH 2/4] Cleaning the code --- libraries/gpu/src/gpu/GLBackendTexture.cpp | 2 -- libraries/render-utils/src/ToneMappingEffect.cpp | 12 +++--------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/libraries/gpu/src/gpu/GLBackendTexture.cpp b/libraries/gpu/src/gpu/GLBackendTexture.cpp index eaed50b850..18b4065b77 100755 --- a/libraries/gpu/src/gpu/GLBackendTexture.cpp +++ b/libraries/gpu/src/gpu/GLBackendTexture.cpp @@ -404,8 +404,6 @@ GLBackend::GLTexture* GLBackend::syncGPUObject(const Texture& texture) { if (bytes && texture.isAutogenerateMips()) { glGenerateMipmap(GL_TEXTURE_2D); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - } else if (texture.isAutogenerateMips()) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); } object->_target = GL_TEXTURE_2D; diff --git a/libraries/render-utils/src/ToneMappingEffect.cpp b/libraries/render-utils/src/ToneMappingEffect.cpp index 54794aa4a0..23d0b3c800 100644 --- a/libraries/render-utils/src/ToneMappingEffect.cpp +++ b/libraries/render-utils/src/ToneMappingEffect.cpp @@ -25,8 +25,6 @@ ToneMappingEffect::ToneMappingEffect() { } void ToneMappingEffect::init() { - //auto VSFS = gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS(); - //auto PSBlit = gpu::StandardShaderLib::getDrawTexturePS(); const char BlitTextureGamma_frag[] = R"SCRIBE(#version 410 core // Generated on Sat Oct 24 09:34:37 2015 // @@ -67,28 +65,24 @@ void ToneMappingEffect::init() { fragColor *= getTwoPowExposure(); - // if (gl_FragCoord.x > 1000) { // Manually gamma correct from Ligthing BUffer to color buffer - // outFragColor.xyz = pow( fragColor.xyz , vec3(1.0 / 2.2) ); + // outFragColor.xyz = pow( fragColor.xyz , vec3(1.0 / 2.2) ); vec3 x = max(vec3(0.0),fragColor.xyz-0.004); vec3 retColor = (x*(6.2*x+.5))/(x*(6.2*x+1.7)+0.06); - // fragColor = fragColor/(1.0+fragColor); - // vec3 retColor = pow(fragColor.xyz,vec3(1/2.2)); + // fragColor = fragColor/(1.0+fragColor); + // vec3 retColor = pow(fragColor.xyz,vec3(1/2.2)); outFragColor = vec4(retColor, 1.0); - // } } )SCRIBE"; auto blitPS = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(BlitTextureGamma_frag))); - //auto blitProgram = gpu::StandardShaderLib::getProgram(gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS, gpu::StandardShaderLib::getDrawTexturePS); auto blitVS = gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS(); auto blitProgram = gpu::ShaderPointer(gpu::Shader::createProgram(blitVS, blitPS)); - //auto blitProgram = gpu::StandardShaderLib::getProgram(gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS, gpu::StandardShaderLib::getDrawTexturePS); gpu::Shader::BindingSet slotBindings; slotBindings.insert(gpu::Shader::Binding(std::string("toneMappingParamsBuffer"), 3)); gpu::Shader::makeProgram(*blitProgram, slotBindings); From a60ef4fb5ad8dc90f14f041c237b799c89690970 Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 15 Dec 2015 18:32:30 -0800 Subject: [PATCH 3/4] Finalize the names --- libraries/gpu/src/gpu/Batch.cpp | 4 ++-- libraries/gpu/src/gpu/Batch.h | 6 +++--- libraries/gpu/src/gpu/GLBackend.cpp | 2 +- libraries/gpu/src/gpu/GLBackend.h | 2 +- libraries/gpu/src/gpu/GLBackendTexture.cpp | 2 +- libraries/render-utils/src/ToneMappingEffect.cpp | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp index 843eb3d3a5..f9c4131a1b 100644 --- a/libraries/gpu/src/gpu/Batch.cpp +++ b/libraries/gpu/src/gpu/Batch.cpp @@ -311,8 +311,8 @@ void Batch::blit(const FramebufferPointer& src, const Vec4i& srcViewport, _params.push_back(dstViewport.w); } -void Batch::generateTextureMipmap(const TexturePointer& texture) { - ADD_COMMAND(generateTextureMipmap); +void Batch::generateTextureMips(const TexturePointer& texture) { + ADD_COMMAND(generateTextureMips); _params.push_back(_textures.cache(texture)); } diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index 122285f5ea..88d28f9d10 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -211,8 +211,8 @@ public: // with xy and zw the bounding corners of the rect region. void blit(const FramebufferPointer& src, const Vec4i& srcRect, const FramebufferPointer& dst, const Vec4i& dstRect); - // Generate the mipmap for a texture - void generateTextureMipmap(const TexturePointer& texture); + // Generate the mips for a texture + void generateTextureMips(const TexturePointer& texture); // Query Section void beginQuery(const QueryPointer& query); @@ -295,7 +295,7 @@ public: COMMAND_setFramebuffer, COMMAND_clearFramebuffer, COMMAND_blit, - COMMAND_generateTextureMipmap, + COMMAND_generateTextureMips, COMMAND_beginQuery, COMMAND_endQuery, diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index ff1b207f7c..a730c06bd9 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -52,7 +52,7 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] = (&::gpu::GLBackend::do_setFramebuffer), (&::gpu::GLBackend::do_clearFramebuffer), (&::gpu::GLBackend::do_blit), - (&::gpu::GLBackend::do_generateTextureMipmap), + (&::gpu::GLBackend::do_generateTextureMips), (&::gpu::GLBackend::do_beginQuery), (&::gpu::GLBackend::do_endQuery), diff --git a/libraries/gpu/src/gpu/GLBackend.h b/libraries/gpu/src/gpu/GLBackend.h index 4733d81cbf..400c9f08f8 100644 --- a/libraries/gpu/src/gpu/GLBackend.h +++ b/libraries/gpu/src/gpu/GLBackend.h @@ -436,7 +436,7 @@ protected: void do_setFramebuffer(Batch& batch, size_t paramOffset); void do_clearFramebuffer(Batch& batch, size_t paramOffset); void do_blit(Batch& batch, size_t paramOffset); - void do_generateTextureMipmap(Batch& batch, size_t paramOffset); + void do_generateTextureMips(Batch& batch, size_t paramOffset); // Synchronize the state cache of this Backend with the actual real state of the GL Context void syncOutputStateCache(); diff --git a/libraries/gpu/src/gpu/GLBackendTexture.cpp b/libraries/gpu/src/gpu/GLBackendTexture.cpp index 18b4065b77..17802ae6ed 100755 --- a/libraries/gpu/src/gpu/GLBackendTexture.cpp +++ b/libraries/gpu/src/gpu/GLBackendTexture.cpp @@ -590,7 +590,7 @@ void GLBackend::syncSampler(const Sampler& sampler, Texture::Type type, GLTextur -void GLBackend::do_generateTextureMipmap(Batch& batch, size_t paramOffset) { +void GLBackend::do_generateTextureMips(Batch& batch, size_t paramOffset) { TexturePointer resourceTexture = batch._textures.get(batch._params[paramOffset + 0]._uint); if (!resourceTexture) { return; diff --git a/libraries/render-utils/src/ToneMappingEffect.cpp b/libraries/render-utils/src/ToneMappingEffect.cpp index 23d0b3c800..22c31a2459 100644 --- a/libraries/render-utils/src/ToneMappingEffect.cpp +++ b/libraries/render-utils/src/ToneMappingEffect.cpp @@ -110,7 +110,7 @@ void ToneMappingEffect::render(RenderArgs* args) { auto destFbo = framebufferCache->getPrimaryFramebuffer(); batch.setFramebuffer(destFbo); - batch.generateTextureMipmap(lightingBuffer); + batch.generateTextureMips(lightingBuffer); batch.setViewportTransform(args->_viewport); batch.setProjectionTransform(glm::mat4()); From 1364329886c27afb05d713c7571b652670dcee8a Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 15 Dec 2015 22:07:06 -0800 Subject: [PATCH 4/4] FIxing the compil bug by checking security of the call with assert and avoiding the compilation error --- libraries/render/src/render/DrawTask.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/libraries/render/src/render/DrawTask.h b/libraries/render/src/render/DrawTask.h index 52dc427251..ab102e32a7 100755 --- a/libraries/render/src/render/DrawTask.h +++ b/libraries/render/src/render/DrawTask.h @@ -86,19 +86,13 @@ public: template T& edit() { auto theConcept = std::dynamic_pointer_cast(_concept); - if (theConcept) { - return theConcept->_data; - } - assert(false); - return T(); + assert(theConcept); + return theConcept->_data; } template const T& get() const { auto theConcept = std::dynamic_pointer_cast(_concept); - if (theConcept) { - return theConcept->_data; - } - assert(false); - return T(); + assert(theConcept); + return theConcept->_data; } void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {