From 762a241fa6b66540d2c196f64d6331cf471888ba Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 2 Dec 2015 18:03:58 -0800 Subject: [PATCH 01/62] Adding specific path for loading lightmaps --- .../src/model-networking/ModelCache.cpp | 3 +- .../src/model-networking/TextureCache.h | 2 +- libraries/model/src/model/TextureMap.cpp | 88 ++++++++++++++++++- libraries/model/src/model/TextureMap.h | 2 + 4 files changed, 91 insertions(+), 4 deletions(-) diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index c7d3523496..ddb6449dc7 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -308,10 +308,9 @@ static NetworkMaterial* buildNetworkMaterial(const FBXMaterial& material, const material._material->setTextureMap(model::MaterialKey::GLOSS_MAP, glossMap); } if (!material.emissiveTexture.filename.isEmpty()) { - networkMaterial->emissiveTexture = textureCache->getTexture(textureBaseUrl.resolved(QUrl(material.emissiveTexture.filename)), EMISSIVE_TEXTURE, material.emissiveTexture.content); + networkMaterial->emissiveTexture = textureCache->getTexture(textureBaseUrl.resolved(QUrl(material.emissiveTexture.filename)), LIGHTMAP_TEXTURE, material.emissiveTexture.content); networkMaterial->emissiveTextureName = material.emissiveTexture.name; - //checkForTexcoordLightmap = true; auto lightmapMap = model::TextureMapPointer(new model::TextureMap()); lightmapMap->setTextureSource(networkMaterial->emissiveTexture->_textureSource); diff --git a/libraries/model-networking/src/model-networking/TextureCache.h b/libraries/model-networking/src/model-networking/TextureCache.h index cc22509631..4171b6c1cb 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.h +++ b/libraries/model-networking/src/model-networking/TextureCache.h @@ -29,7 +29,7 @@ class NetworkTexture; typedef QSharedPointer NetworkTexturePointer; -enum TextureType { DEFAULT_TEXTURE, NORMAL_TEXTURE, BUMP_TEXTURE, SPECULAR_TEXTURE, EMISSIVE_TEXTURE, CUBE_TEXTURE, CUSTOM_TEXTURE }; +enum TextureType { DEFAULT_TEXTURE, NORMAL_TEXTURE, BUMP_TEXTURE, SPECULAR_TEXTURE, EMISSIVE_TEXTURE, CUBE_TEXTURE, LIGHTMAP_TEXTURE, CUSTOM_TEXTURE }; /// Stores cached textures, including render-to-texture targets. class TextureCache : public ResourceCache, public Dependency { diff --git a/libraries/model/src/model/TextureMap.cpp b/libraries/model/src/model/TextureMap.cpp index d443522a6f..453bb17a4b 100755 --- a/libraries/model/src/model/TextureMap.cpp +++ b/libraries/model/src/model/TextureMap.cpp @@ -119,7 +119,7 @@ gpu::Texture* TextureUsage::create2DTextureFromImage(const QImage& srcImage, con if ((image.width() > 0) && (image.height() > 0)) { // bool isLinearRGB = true; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE); - bool isLinearRGB = true; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE); + bool isLinearRGB = false; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE); gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); @@ -520,3 +520,89 @@ gpu::Texture* TextureUsage::createCubeTextureFromImage(const QImage& srcImage, c return theTexture; } + + +gpu::Texture* TextureUsage::createLightmapTextureFromImage(const QImage& srcImage, const std::string& srcImageName) { + QImage image = srcImage; + + int imageArea = image.width() * image.height(); + + int opaquePixels = 0; + int translucentPixels = 0; + //bool isTransparent = false; + int redTotal = 0, greenTotal = 0, blueTotal = 0, alphaTotal = 0; + const int EIGHT_BIT_MAXIMUM = 255; + QColor averageColor(EIGHT_BIT_MAXIMUM, EIGHT_BIT_MAXIMUM, EIGHT_BIT_MAXIMUM); + + if (!image.hasAlphaChannel()) { + if (image.format() != QImage::Format_RGB888) { + image = image.convertToFormat(QImage::Format_RGB888); + } + // int redTotal = 0, greenTotal = 0, blueTotal = 0; + for (int y = 0; y < image.height(); y++) { + for (int x = 0; x < image.width(); x++) { + QRgb rgb = image.pixel(x, y); + redTotal += qRed(rgb); + greenTotal += qGreen(rgb); + blueTotal += qBlue(rgb); + } + } + if (imageArea > 0) { + averageColor.setRgb(redTotal / imageArea, greenTotal / imageArea, blueTotal / imageArea); + } + } else { + if (image.format() != QImage::Format_ARGB32) { + image = image.convertToFormat(QImage::Format_ARGB32); + } + + // check for translucency/false transparency + // int opaquePixels = 0; + // int translucentPixels = 0; + // int redTotal = 0, greenTotal = 0, blueTotal = 0, alphaTotal = 0; + for (int y = 0; y < image.height(); y++) { + for (int x = 0; x < image.width(); x++) { + QRgb rgb = image.pixel(x, y); + redTotal += qRed(rgb); + greenTotal += qGreen(rgb); + blueTotal += qBlue(rgb); + int alpha = qAlpha(rgb); + alphaTotal += alpha; + if (alpha == EIGHT_BIT_MAXIMUM) { + opaquePixels++; + } else if (alpha != 0) { + translucentPixels++; + } + } + } + if (opaquePixels == imageArea) { + qCDebug(modelLog) << "Image with alpha channel is completely opaque:" << QString(srcImageName.c_str()); + image = image.convertToFormat(QImage::Format_RGB888); + } + + averageColor = QColor(redTotal / imageArea, + greenTotal / imageArea, blueTotal / imageArea, alphaTotal / imageArea); + + //isTransparent = (translucentPixels >= imageArea / 2); + } + + gpu::Texture* theTexture = nullptr; + if ((image.width() > 0) && (image.height() > 0)) { + + // bool isLinearRGB = true; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE); + bool isLinearRGB = false; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE); + + gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); + gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); + if (image.hasAlphaChannel()) { + formatGPU = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::RGBA : gpu::SRGBA)); + formatMip = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::BGRA : gpu::SBGRA)); + } + + + theTexture = (gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR))); + theTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits()); + theTexture->autoGenerateMips(-1); + } + + return theTexture; +} diff --git a/libraries/model/src/model/TextureMap.h b/libraries/model/src/model/TextureMap.h index 107ca2e879..6bc5b8228c 100755 --- a/libraries/model/src/model/TextureMap.h +++ b/libraries/model/src/model/TextureMap.h @@ -35,6 +35,8 @@ public: static gpu::Texture* createNormalTextureFromNormalImage(const QImage& image, const std::string& srcImageName); static gpu::Texture* createNormalTextureFromBumpImage(const QImage& image, const std::string& srcImageName); static gpu::Texture* createCubeTextureFromImage(const QImage& image, const std::string& srcImageName); + static gpu::Texture* createLightmapTextureFromImage(const QImage& image, const std::string& srcImageName); + }; From a5475ed14d2089e7e63d5fb294b71da87b6f2658 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 3 Dec 2015 10:41:32 -0800 Subject: [PATCH 02/62] Early try fixing the lighting --- .../render-utils/src/DeferredLighting.slh | 2 +- .../src/DeferredLightingEffect.cpp | 34 ++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/libraries/render-utils/src/DeferredLighting.slh b/libraries/render-utils/src/DeferredLighting.slh index 888742bb18..53ffdee0ca 100755 --- a/libraries/render-utils/src/DeferredLighting.slh +++ b/libraries/render-utils/src/DeferredLighting.slh @@ -33,7 +33,7 @@ vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 sp vec3 schlick = specular * (1.0 - shlickPower5) + vec3(shlickPower5); vec3 reflect = specularPower * schlick; - return vec4(reflect, diffuse); + return vec4(reflect, diffuse * (1 - length(schlick))); } <@endfunc@> diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 57e3129ef8..4370f8279e 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -143,7 +143,39 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { { //auto VSFS = gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS(); //auto PSBlit = gpu::StandardShaderLib::getDrawTexturePS(); - auto blitProgram = gpu::StandardShaderLib::getProgram(gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS, gpu::StandardShaderLib::getDrawTexturePS); + const char BlitTextureGamma_frag[] = R"SCRIBE(#version 410 core + // Generated on Sat Oct 24 09:34:37 2015 + // + // Draw texture 0 fetched at texcoord.xy + // + // Created by Sam Gateau on 6/22/2015 + // Copyright 2015 High Fidelity, Inc. + // + // Distributed under the Apache License, Version 2.0. + // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + // + + + uniform sampler2D colorMap; + + in vec2 varTexCoord0; + out vec4 outFragColor; + + void main(void) { + outFragColor = texture(colorMap, varTexCoord0); + if (gl_FragCoord.x > 1000) { + outFragColor.xyz = pow( outFragColor.xyz , vec3(1.0/2.2) ); + } + } + + )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::makeProgram(*blitProgram); auto blitState = std::make_shared(); blitState->setBlendFunction(true, From 72d393905b36cbf65c7686ee67210c3beaaa1fab Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 3 Dec 2015 16:03:32 -0800 Subject: [PATCH 03/62] Introducing the Lighting Buffer where all the lighting is beeing accumulated, apply a manual gamma correction when copying back into the main color buffer --- .../src/DeferredLightingEffect.cpp | 26 +++++++------------ .../render-utils/src/FramebufferCache.cpp | 22 ++++++++++++++++ libraries/render-utils/src/FramebufferCache.h | 9 ++++++- 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 4370f8279e..371a3d705e 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -163,9 +163,10 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { void main(void) { outFragColor = texture(colorMap, varTexCoord0); - if (gl_FragCoord.x > 1000) { - outFragColor.xyz = pow( outFragColor.xyz , vec3(1.0/2.2) ); - } + // if (gl_FragCoord.x > 1000) { + // Manually gamma correct from Ligthing BUffer to color buffer + outFragColor.xyz = pow( outFragColor.xyz , vec3(1.0 / 2.2) ); + // } } )SCRIBE"; @@ -178,9 +179,6 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { //auto blitProgram = gpu::StandardShaderLib::getProgram(gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS, gpu::StandardShaderLib::getDrawTexturePS); gpu::Shader::makeProgram(*blitProgram); auto blitState = std::make_shared(); - blitState->setBlendFunction(true, - gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, - gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); blitState->setColorWriteMask(true, true, true, false); _blitLightBuffer = gpu::PipelinePointer(gpu::Pipeline::create(blitProgram, blitState)); } @@ -386,8 +384,6 @@ void DeferredLightingEffect::prepare(RenderArgs* args) { }); } -gpu::FramebufferPointer _copyFBO; - void DeferredLightingEffect::render(RenderArgs* args) { gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { @@ -407,13 +403,13 @@ void DeferredLightingEffect::render(RenderArgs* args) { QSize framebufferSize = framebufferCache->getFrameBufferSize(); // binding the first framebuffer - _copyFBO = framebufferCache->getFramebuffer(); - batch.setFramebuffer(_copyFBO); + auto lightingFBO = framebufferCache->getLightingFramebuffer(); + batch.setFramebuffer(lightingFBO); // Clearing it batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); - batch.clearColorFramebuffer(_copyFBO->getBufferMask(), glm::vec4(0.0f, 0.0f, 0.0f, 0.0f), true); + batch.clearColorFramebuffer(lightingFBO->getBufferMask(), glm::vec4(0.0f, 0.0f, 0.0f, 0.0f), true); // BInd the G-Buffer surfaces batch.setResourceTexture(0, framebufferCache->getPrimaryColorTexture()); @@ -718,11 +714,8 @@ void DeferredLightingEffect::copyBack(RenderArgs* args) { batch.enableStereo(false); QSize framebufferSize = framebufferCache->getFrameBufferSize(); - // TODO why doesn't this blit work? It only seems to affect a small area below the rear view mirror. - // auto destFbo = framebufferCache->getPrimaryFramebuffer(); + auto lightingBuffer = framebufferCache->getLightingTexture(); auto destFbo = framebufferCache->getPrimaryFramebufferDepthColor(); - // gpu::Vec4i vp = args->_viewport; - // batch.blit(_copyFBO, vp, framebufferCache->getPrimaryFramebuffer(), vp); batch.setFramebuffer(destFbo); batch.setViewportTransform(args->_viewport); batch.setProjectionTransform(glm::mat4()); @@ -739,12 +732,11 @@ void DeferredLightingEffect::copyBack(RenderArgs* args) { batch.setModelTransform(model); } - batch.setResourceTexture(0, _copyFBO->getRenderBuffer(0)); + batch.setResourceTexture(0, lightingBuffer); batch.draw(gpu::TRIANGLE_STRIP, 4); args->_context->render(batch); }); - framebufferCache->releaseFramebuffer(_copyFBO); } void DeferredLightingEffect::setupTransparent(RenderArgs* args, int lightBufferUnit) { diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index 5907d3fa27..2a8033be0d 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -41,6 +41,8 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { _primarySpecularTexture.reset(); _selfieFramebuffer.reset(); _cachedFramebuffers.clear(); + _lightingTexture.reset(); + _lightingFramebuffer.reset(); } } @@ -74,6 +76,12 @@ void FramebufferCache::createPrimaryFramebuffer() { _selfieFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); auto tex = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width * 0.5, height * 0.5, defaultSampler)); _selfieFramebuffer->setRenderBuffer(0, tex); + + _lightingTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA), width, height, defaultSampler)); + //_lightingTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::SRGBA), width, height, defaultSampler)); + // _lightingTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::HALF, gpu::RGBA), width, height, defaultSampler)); + _lightingFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); + _lightingFramebuffer->setRenderBuffer(0, _lightingTexture); } gpu::FramebufferPointer FramebufferCache::getPrimaryFramebuffer() { @@ -118,6 +126,20 @@ gpu::TexturePointer FramebufferCache::getPrimarySpecularTexture() { return _primarySpecularTexture; } +gpu::FramebufferPointer FramebufferCache::getLightingFramebuffer() { + if (!_lightingFramebuffer) { + createPrimaryFramebuffer(); + } + return _lightingFramebuffer; +} + +gpu::TexturePointer FramebufferCache::getLightingTexture() { + if (!_lightingTexture) { + createPrimaryFramebuffer(); + } + return _lightingTexture; +} + gpu::FramebufferPointer FramebufferCache::getFramebuffer() { if (_cachedFramebuffers.isEmpty()) { _cachedFramebuffers.push_back(gpu::FramebufferPointer(gpu::Framebuffer::create(gpu::Element::COLOR_RGBA_32, _frameBufferSize.width(), _frameBufferSize.height()))); diff --git a/libraries/render-utils/src/FramebufferCache.h b/libraries/render-utils/src/FramebufferCache.h index e9a1bbf8e8..610609e7c9 100644 --- a/libraries/render-utils/src/FramebufferCache.h +++ b/libraries/render-utils/src/FramebufferCache.h @@ -37,6 +37,10 @@ public: gpu::TexturePointer getPrimaryNormalTexture(); gpu::TexturePointer getPrimarySpecularTexture(); + + gpu::TexturePointer getLightingTexture(); + gpu::FramebufferPointer getLightingFramebuffer(); + /// Returns the framebuffer object used to render shadow maps; gpu::FramebufferPointer getShadowFramebuffer(); @@ -63,7 +67,10 @@ private: gpu::TexturePointer _primaryColorTexture; gpu::TexturePointer _primaryNormalTexture; gpu::TexturePointer _primarySpecularTexture; - + + gpu::TexturePointer _lightingTexture; + gpu::FramebufferPointer _lightingFramebuffer; + gpu::FramebufferPointer _shadowFramebuffer; gpu::FramebufferPointer _selfieFramebuffer; From d593b824e94cd384614c275b0cefae9f7939db9b Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 3 Dec 2015 17:26:54 -0800 Subject: [PATCH 04/62] Introducing a true Primary Framebuffer and a different Deferred Framebuffer --- interface/src/Application.cpp | 10 +-- .../src/AmbientOcclusionEffect.cpp | 4 +- .../render-utils/src/AntialiasingEffect.cpp | 4 +- .../src/DeferredLightingEffect.cpp | 10 +-- .../render-utils/src/FramebufferCache.cpp | 76 ++++++++++++------- libraries/render-utils/src/FramebufferCache.h | 20 +++-- .../render-utils/src/RenderDeferredTask.cpp | 16 ++-- 7 files changed, 86 insertions(+), 54 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ef10ad4464..6648a131c4 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -676,9 +676,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : _applicationStateDevice->addInputVariant(QString("ComfortMode"), controller::StateController::ReadLambda([]() -> float { return (float)Menu::getInstance()->isOptionChecked(MenuOption::ComfortMode); })); - _applicationStateDevice->addInputVariant(QString("Grounded"), controller::StateController::ReadLambda([]() -> float { - return (float)qApp->getMyAvatar()->getCharacterController()->onGround(); - })); + _applicationStateDevice->addInputVariant(QString("Grounded"), controller::StateController::ReadLambda([]() -> float { + return (float)qApp->getMyAvatar()->getCharacterController()->onGround(); + })); userInputMapper->registerDevice(_applicationStateDevice); @@ -1347,7 +1347,7 @@ void Application::paintGL() { { PROFILE_RANGE(__FUNCTION__ "/compositor"); PerformanceTimer perfTimer("compositor"); - auto primaryFbo = framebufferCache->getPrimaryFramebuffer(); + auto primaryFbo = framebufferCache->getPrimaryFramebufferDepthColor(); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFbo)); if (displayPlugin->isStereo()) { QRect currentViewport(QPoint(0, 0), QSize(size.width() / 2, size.height())); @@ -1372,7 +1372,7 @@ void Application::paintGL() { { PROFILE_RANGE(__FUNCTION__ "/pluginOutput"); PerformanceTimer perfTimer("pluginOutput"); - auto primaryFbo = framebufferCache->getPrimaryFramebuffer(); + auto primaryFbo = framebufferCache->getPrimaryFramebufferDepthColor(); GLuint finalTexture = gpu::GLBackend::getTextureID(primaryFbo->getRenderBuffer(0)); // Ensure the rendering context commands are completed when rendering GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.cpp b/libraries/render-utils/src/AmbientOcclusionEffect.cpp index 456a6430a7..3d2a5ef43b 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.cpp +++ b/libraries/render-utils/src/AmbientOcclusionEffect.cpp @@ -201,7 +201,7 @@ void AmbientOcclusion::run(const render::SceneContextPointer& sceneContext, cons // Occlusion step getOcclusionPipeline(); batch.setResourceTexture(0, framebufferCache->getPrimaryDepthTexture()); - batch.setResourceTexture(1, framebufferCache->getPrimaryNormalTexture()); + batch.setResourceTexture(1, framebufferCache->getDeferredNormalTexture()); _occlusionBuffer->setRenderBuffer(0, _occlusionTexture); batch.setFramebuffer(_occlusionBuffer); @@ -276,7 +276,7 @@ void AmbientOcclusion::run(const render::SceneContextPointer& sceneContext, cons // Blend step getBlendPipeline(); batch.setResourceTexture(0, _hBlurTexture); - batch.setFramebuffer(framebufferCache->getPrimaryFramebuffer()); + batch.setFramebuffer(framebufferCache->getDeferredFramebuffer()); // Bind the fourth gpu::Pipeline we need - for blending the primary color buffer with blurred occlusion texture batch.setPipeline(getBlendPipeline()); diff --git a/libraries/render-utils/src/AntialiasingEffect.cpp b/libraries/render-utils/src/AntialiasingEffect.cpp index aaef67542f..2abb9f085e 100644 --- a/libraries/render-utils/src/AntialiasingEffect.cpp +++ b/libraries/render-utils/src/AntialiasingEffect.cpp @@ -123,7 +123,7 @@ void Antialiasing::run(const render::SceneContextPointer& sceneContext, const re // FXAA step getAntialiasingPipeline(); - batch.setResourceTexture(0, framebufferCache->getPrimaryColorTexture()); + batch.setResourceTexture(0, framebufferCache->getDeferredColorTexture()); _antialiasingBuffer->setRenderBuffer(0, _antialiasingTexture); batch.setFramebuffer(_antialiasingBuffer); batch.setPipeline(getAntialiasingPipeline()); @@ -153,7 +153,7 @@ void Antialiasing::run(const render::SceneContextPointer& sceneContext, const re // Blend step getBlendPipeline(); batch.setResourceTexture(0, _antialiasingTexture); - batch.setFramebuffer(framebufferCache->getPrimaryFramebuffer()); + batch.setFramebuffer(framebufferCache->getDeferredFramebuffer()); batch.setPipeline(getBlendPipeline()); DependencyManager::get()->renderQuad(batch, bottomLeft, topRight, texCoordTopLeft, texCoordBottomRight, color); diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 371a3d705e..9ade2f5cea 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -374,9 +374,9 @@ void DeferredLightingEffect::prepare(RenderArgs* args) { batch.enableStereo(false); batch.setStateScissorRect(args->_viewport); - auto primaryFbo = DependencyManager::get()->getPrimaryFramebuffer(); + auto deferredFbo = DependencyManager::get()->getDeferredFramebuffer(); - batch.setFramebuffer(primaryFbo); + batch.setFramebuffer(deferredFbo); // clear the normal and specular buffers batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR1, glm::vec4(0.0f, 0.0f, 0.0f, 0.0f), true); const float MAX_SPECULAR_EXPONENT = 128.0f; @@ -412,9 +412,9 @@ void DeferredLightingEffect::render(RenderArgs* args) { batch.clearColorFramebuffer(lightingFBO->getBufferMask(), glm::vec4(0.0f, 0.0f, 0.0f, 0.0f), true); // BInd the G-Buffer surfaces - batch.setResourceTexture(0, framebufferCache->getPrimaryColorTexture()); - batch.setResourceTexture(1, framebufferCache->getPrimaryNormalTexture()); - batch.setResourceTexture(2, framebufferCache->getPrimarySpecularTexture()); + batch.setResourceTexture(0, framebufferCache->getDeferredColorTexture()); + batch.setResourceTexture(1, framebufferCache->getDeferredNormalTexture()); + batch.setResourceTexture(2, framebufferCache->getDeferredSpecularTexture()); batch.setResourceTexture(3, framebufferCache->getPrimaryDepthTexture()); // THe main viewport is assumed to be the mono viewport (or the 2 stereo faces side by side within that viewport) diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index 2a8033be0d..b39b8cc7e5 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -33,12 +33,14 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { //If the size changed, we need to delete our FBOs if (_frameBufferSize != frameBufferSize) { _frameBufferSize = frameBufferSize; - _primaryFramebufferFull.reset(); _primaryFramebufferDepthColor.reset(); _primaryDepthTexture.reset(); _primaryColorTexture.reset(); - _primaryNormalTexture.reset(); - _primarySpecularTexture.reset(); + _deferredFramebuffer.reset(); + _deferredFramebufferDepthColor.reset(); + _deferredColorTexture.reset(); + _deferredNormalTexture.reset(); + _deferredSpecularTexture.reset(); _selfieFramebuffer.reset(); _cachedFramebuffers.clear(); _lightingTexture.reset(); @@ -47,8 +49,9 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { } void FramebufferCache::createPrimaryFramebuffer() { - _primaryFramebufferFull = gpu::FramebufferPointer(gpu::Framebuffer::create()); _primaryFramebufferDepthColor = gpu::FramebufferPointer(gpu::Framebuffer::create()); + _deferredFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); + _deferredFramebufferDepthColor = gpu::FramebufferPointer(gpu::Framebuffer::create()); auto colorFormat = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); auto width = _frameBufferSize.width(); @@ -56,23 +59,30 @@ void FramebufferCache::createPrimaryFramebuffer() { auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_POINT); _primaryColorTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); - _primaryNormalTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); - _primarySpecularTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); - - _primaryFramebufferFull->setRenderBuffer(0, _primaryColorTexture); - _primaryFramebufferFull->setRenderBuffer(1, _primaryNormalTexture); - _primaryFramebufferFull->setRenderBuffer(2, _primarySpecularTexture); _primaryFramebufferDepthColor->setRenderBuffer(0, _primaryColorTexture); + _deferredColorTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); + _deferredNormalTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); + _deferredSpecularTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); + + _deferredFramebuffer->setRenderBuffer(0, _deferredColorTexture); + _deferredFramebuffer->setRenderBuffer(1, _deferredNormalTexture); + _deferredFramebuffer->setRenderBuffer(2, _deferredSpecularTexture); + + _deferredFramebufferDepthColor->setRenderBuffer(0, _deferredColorTexture); + // auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); auto depthFormat = gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::DEPTH_STENCIL); // Depth24_Stencil8 texel format _primaryDepthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height, defaultSampler)); - - _primaryFramebufferFull->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); _primaryFramebufferDepthColor->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); - + + _deferredFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); + + _deferredFramebufferDepthColor->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); + + _selfieFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); auto tex = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width * 0.5, height * 0.5, defaultSampler)); _selfieFramebuffer->setRenderBuffer(0, tex); @@ -84,13 +94,6 @@ void FramebufferCache::createPrimaryFramebuffer() { _lightingFramebuffer->setRenderBuffer(0, _lightingTexture); } -gpu::FramebufferPointer FramebufferCache::getPrimaryFramebuffer() { - if (!_primaryFramebufferFull) { - createPrimaryFramebuffer(); - } - return _primaryFramebufferFull; -} - gpu::FramebufferPointer FramebufferCache::getPrimaryFramebufferDepthColor() { if (!_primaryFramebufferDepthColor) { createPrimaryFramebuffer(); @@ -112,18 +115,39 @@ gpu::TexturePointer FramebufferCache::getPrimaryColorTexture() { return _primaryColorTexture; } -gpu::TexturePointer FramebufferCache::getPrimaryNormalTexture() { - if (!_primaryNormalTexture) { +gpu::FramebufferPointer FramebufferCache::getDeferredFramebuffer() { + if (!_deferredFramebuffer) { createPrimaryFramebuffer(); } - return _primaryNormalTexture; + return _deferredFramebuffer; } -gpu::TexturePointer FramebufferCache::getPrimarySpecularTexture() { - if (!_primarySpecularTexture) { +gpu::FramebufferPointer FramebufferCache::getDeferredFramebufferDepthColor() { + if (!_deferredFramebufferDepthColor) { createPrimaryFramebuffer(); } - return _primarySpecularTexture; + return _deferredFramebufferDepthColor; +} + +gpu::TexturePointer FramebufferCache::getDeferredColorTexture() { + if (!_deferredColorTexture) { + createPrimaryFramebuffer(); + } + return _deferredColorTexture; +} + +gpu::TexturePointer FramebufferCache::getDeferredNormalTexture() { + if (!_deferredNormalTexture) { + createPrimaryFramebuffer(); + } + return _deferredNormalTexture; +} + +gpu::TexturePointer FramebufferCache::getDeferredSpecularTexture() { + if (!_deferredSpecularTexture) { + createPrimaryFramebuffer(); + } + return _deferredSpecularTexture; } gpu::FramebufferPointer FramebufferCache::getLightingFramebuffer() { diff --git a/libraries/render-utils/src/FramebufferCache.h b/libraries/render-utils/src/FramebufferCache.h index 610609e7c9..6633301d0c 100644 --- a/libraries/render-utils/src/FramebufferCache.h +++ b/libraries/render-utils/src/FramebufferCache.h @@ -29,13 +29,17 @@ public: /// Returns a pointer to the primary framebuffer object. This render target includes a depth component, and is /// used for scene rendering. - gpu::FramebufferPointer getPrimaryFramebuffer(); gpu::FramebufferPointer getPrimaryFramebufferDepthColor(); gpu::TexturePointer getPrimaryDepthTexture(); gpu::TexturePointer getPrimaryColorTexture(); - gpu::TexturePointer getPrimaryNormalTexture(); - gpu::TexturePointer getPrimarySpecularTexture(); + + gpu::FramebufferPointer getDeferredFramebuffer(); + gpu::FramebufferPointer getDeferredFramebufferDepthColor(); + + gpu::TexturePointer getDeferredColorTexture(); + gpu::TexturePointer getDeferredNormalTexture(); + gpu::TexturePointer getDeferredSpecularTexture(); gpu::TexturePointer getLightingTexture(); @@ -60,13 +64,17 @@ private: void createPrimaryFramebuffer(); - gpu::FramebufferPointer _primaryFramebufferFull; gpu::FramebufferPointer _primaryFramebufferDepthColor; gpu::TexturePointer _primaryDepthTexture; gpu::TexturePointer _primaryColorTexture; - gpu::TexturePointer _primaryNormalTexture; - gpu::TexturePointer _primarySpecularTexture; + + gpu::FramebufferPointer _deferredFramebuffer; + gpu::FramebufferPointer _deferredFramebufferDepthColor; + + gpu::TexturePointer _deferredColorTexture; + gpu::TexturePointer _deferredNormalTexture; + gpu::TexturePointer _deferredSpecularTexture; gpu::TexturePointer _lightingTexture; gpu::FramebufferPointer _lightingFramebuffer; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index e65018ad3d..bf5f621726 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -38,13 +38,13 @@ void SetupDeferred::run(const SceneContextPointer& sceneContext, const RenderCon RenderArgs* args = renderContext->args; gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { - auto primaryFbo = DependencyManager::get()->getPrimaryFramebufferDepthColor(); + auto deferredFbo = DependencyManager::get()->getDeferredFramebufferDepthColor(); batch.enableStereo(false); batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); - batch.setFramebuffer(primaryFbo); + batch.setFramebuffer(deferredFbo); batch.clearFramebuffer( gpu::Framebuffer::BUFFER_COLOR0 | gpu::Framebuffer::BUFFER_DEPTH | @@ -332,11 +332,11 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren doInBatch(args->_context, [=](gpu::Batch& batch) { args->_batch = &batch; - auto primaryFboColorDepthStencil = DependencyManager::get()->getPrimaryFramebufferDepthColor(); + auto deferredFboColorDepthStencil = DependencyManager::get()->getDeferredFramebufferDepthColor(); batch.enableStereo(false); - batch.setFramebuffer(primaryFboColorDepthStencil); + batch.setFramebuffer(deferredFboColorDepthStencil); batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); @@ -367,12 +367,12 @@ void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const doInBatch(args->_context, [=](gpu::Batch& batch) { args->_batch = &batch; - auto primaryFboColorDepthStencil = DependencyManager::get()->getPrimaryFramebufferDepthColor(); - auto primaryFboFull = DependencyManager::get()->getPrimaryFramebuffer(); + auto deferredFboColorDepthStencil = DependencyManager::get()->getDeferredFramebufferDepthColor(); + auto deferredFboFull = DependencyManager::get()->getDeferredFramebuffer(); batch.enableSkybox(true); - batch.setFramebuffer(primaryFboColorDepthStencil); + batch.setFramebuffer(deferredFboColorDepthStencil); batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); @@ -387,7 +387,7 @@ void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const renderItems(sceneContext, renderContext, inItems); - batch.setFramebuffer(primaryFboFull); + batch.setFramebuffer(deferredFboFull); }); args->_batch = nullptr; From baf93e8a084f03a5a8c2facfb5b803e14da299be Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 3 Dec 2015 15:54:53 -0800 Subject: [PATCH 05/62] Add basic DebugDeferredBuffer job --- .../render-utils/src/DebugDeferredBuffer.cpp | 72 +++++++++++++++++++ .../render-utils/src/DebugDeferredBuffer.h | 29 ++++++++ libraries/render-utils/src/HitEffect.cpp | 1 + libraries/render-utils/src/HitEffect.h | 8 +-- .../render-utils/src/RenderDeferredTask.cpp | 7 +- .../render-utils/src/RenderDeferredTask.h | 4 +- .../src/debug_deferred_buffer.slf | 21 ++++++ .../src/debug_deferred_buffer.slv | 19 +++++ libraries/render-utils/src/hit_effect.slf | 8 +-- 9 files changed, 155 insertions(+), 14 deletions(-) create mode 100644 libraries/render-utils/src/DebugDeferredBuffer.cpp create mode 100644 libraries/render-utils/src/DebugDeferredBuffer.h create mode 100644 libraries/render-utils/src/debug_deferred_buffer.slf create mode 100644 libraries/render-utils/src/debug_deferred_buffer.slv diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp new file mode 100644 index 0000000000..e1c31f943e --- /dev/null +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -0,0 +1,72 @@ +// +// DebugDeferredBuffer.cpp +// libraries/render-utils/src +// +// Created by Clement on 12/3/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "DebugDeferredBuffer.h" + +#include +#include +#include +#include + +#include "GeometryCache.h" + +#include "debug_deferred_buffer_vert.h" +#include "debug_deferred_buffer_frag.h" + +using namespace render; + +const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline() { + if (!_pipeline) { + auto vs = gpu::ShaderPointer(gpu::Shader::createVertex({ debug_deferred_buffer_vert })); + auto ps = gpu::ShaderPointer(gpu::Shader::createPixel({ debug_deferred_buffer_frag })); + auto program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps)); + + + gpu::Shader::BindingSet slotBindings; + gpu::Shader::makeProgram(*program, slotBindings); + + auto state = std::make_shared(); + + state->setDepthTest(false, false, gpu::LESS_EQUAL); + + // Blend on transparent + state->setBlendFunction(true, + gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); + + // Good to go add the brand new pipeline + _pipeline.reset(gpu::Pipeline::create(program, state)); + } + return _pipeline; +} + + +void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { + assert(renderContext->args); + assert(renderContext->args->_viewFrustum); + RenderArgs* args = renderContext->args; + gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { + + glm::mat4 projMat; + Transform viewMat; + args->_viewFrustum->evalProjectionMatrix(projMat); + args->_viewFrustum->evalViewTransform(viewMat); + batch.setProjectionTransform(projMat); + batch.setViewTransform(viewMat); + batch.setModelTransform(Transform()); + + batch.setPipeline(getPipeline()); + + glm::vec4 color(0.0f, 0.0f, 1.0f, 1.0f); + glm::vec2 bottomLeft(0.0f, -1.0f); + glm::vec2 topRight(1.0f, 1.0f); + DependencyManager::get()->renderQuad(batch, bottomLeft, topRight, color); + }); +} \ No newline at end of file diff --git a/libraries/render-utils/src/DebugDeferredBuffer.h b/libraries/render-utils/src/DebugDeferredBuffer.h new file mode 100644 index 0000000000..827a3271f0 --- /dev/null +++ b/libraries/render-utils/src/DebugDeferredBuffer.h @@ -0,0 +1,29 @@ +// +// DebugDeferredBuffer.h +// libraries/render-utils/src +// +// Created by Clement on 12/3/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_DebugDeferredBuffer_h +#define hifi_DebugDeferredBuffer_h + +#include + +class DebugDeferredBuffer { +public: + using JobModel = render::Job::Model; + + void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext); + +private: + const gpu::PipelinePointer& getPipeline(); + + gpu::PipelinePointer _pipeline; +}; + +#endif // hifi_DebugDeferredBuffer_h \ No newline at end of file diff --git a/libraries/render-utils/src/HitEffect.cpp b/libraries/render-utils/src/HitEffect.cpp index 06bd07b456..f33dc5b3b9 100644 --- a/libraries/render-utils/src/HitEffect.cpp +++ b/libraries/render-utils/src/HitEffect.cpp @@ -14,6 +14,7 @@ #include +#include #include #include diff --git a/libraries/render-utils/src/HitEffect.h b/libraries/render-utils/src/HitEffect.h index b560cf5550..0a96a5300d 100644 --- a/libraries/render-utils/src/HitEffect.h +++ b/libraries/render-utils/src/HitEffect.h @@ -9,11 +9,7 @@ #ifndef hifi_hitEffect_h #define hifi_hitEffect_h -#include -#include "render/DrawTask.h" - -class AbstractViewStateInterface; -class ProgramObject; +#include class HitEffect { public: @@ -23,7 +19,7 @@ public: void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext); typedef render::Job::Model JobModel; - const gpu::PipelinePointer& getHitEffectPipeline(); + const gpu::PipelinePointer& getHitEffectPipeline(); private: gpu::PipelinePointer _hitEffectPipeline; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index bf5f621726..43ddd5b7ae 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -18,10 +18,11 @@ #include #include -#include "FramebufferCache.h" +#include "DebugDeferredBuffer.h" #include "DeferredLightingEffect.h" -#include "TextureCache.h" +#include "FramebufferCache.h" #include "HitEffect.h" +#include "TextureCache.h" #include "render/DrawStatus.h" #include "AmbientOcclusionEffect.h" @@ -112,6 +113,8 @@ RenderDeferredTask::RenderDeferredTask() : Task() { _jobs.push_back(Job(new DepthSortItems::JobModel("DepthSortTransparent", _jobs.back().getOutput(), DepthSortItems(false)))); _jobs.push_back(Job(new DrawTransparentDeferred::JobModel("TransparentDeferred", _jobs.back().getOutput()))); + _jobs.push_back(Job(new DebugDeferredBuffer::JobModel("DebugDeferredBuffer"))); + // Grab a texture map representing the different status icons and assign that to the drawStatsuJob auto iconMapPath = PathUtils::resourcesPath() + "icons/statusIconAtlas.svg"; diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index 6daa90b1ed..e75edd20da 100755 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -80,9 +80,9 @@ class DrawOverlay3D { static gpu::PipelinePointer _opaquePipeline; //lazy evaluation hence mutable public: static const gpu::PipelinePointer& getOpaquePipeline(); - + void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext); - + typedef render::Job::Model JobModel; }; diff --git a/libraries/render-utils/src/debug_deferred_buffer.slf b/libraries/render-utils/src/debug_deferred_buffer.slf new file mode 100644 index 0000000000..c33773aa40 --- /dev/null +++ b/libraries/render-utils/src/debug_deferred_buffer.slf @@ -0,0 +1,21 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// debug_deferred_buffer.slf +// fragment shader +// +// Created by Clement on 12/3 +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +<@include DeferredBufferWrite.slh@> + +out vec4 outFragColor; + +void main(void) { + outFragColor = vec4(0.0, 0.0, 1.0, 1.0); +} \ No newline at end of file diff --git a/libraries/render-utils/src/debug_deferred_buffer.slv b/libraries/render-utils/src/debug_deferred_buffer.slv new file mode 100644 index 0000000000..b1b7b18f86 --- /dev/null +++ b/libraries/render-utils/src/debug_deferred_buffer.slv @@ -0,0 +1,19 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// debug_deferred_buffer.slv +// vertex shader +// +// Created by Clement on 12/3 +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +<@include gpu/Inputs.slh@> + +void main(void) { + gl_Position = inPosition; +} \ No newline at end of file diff --git a/libraries/render-utils/src/hit_effect.slf b/libraries/render-utils/src/hit_effect.slf index c059488ba1..cc4484442f 100644 --- a/libraries/render-utils/src/hit_effect.slf +++ b/libraries/render-utils/src/hit_effect.slf @@ -20,8 +20,8 @@ in vec2 varQuadPosition; out vec4 outFragColor; void main(void) { - vec2 center = vec2(0.0, 0.0); - float distFromCenter = distance( vec2(0.0, 0.0), varQuadPosition); - float alpha = mix(0.0, 0.5, pow(distFromCenter,5.)); - outFragColor = vec4(1.0, 0.0, 0.0, alpha); + vec2 center = vec2(0.0, 0.0); + float distFromCenter = distance( vec2(0.0, 0.0), varQuadPosition); + float alpha = mix(0.0, 0.5, pow(distFromCenter,5.)); + outFragColor = vec4(1.0, 0.0, 0.0, alpha); } \ No newline at end of file From c27944ae28532fc14ec6f8886b6966e50314c8bc Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 3 Dec 2015 17:13:41 -0800 Subject: [PATCH 06/62] Simple normal map debug --- examples/utilities/tools/renderEngineDebug.js | 6 ++++++ interface/src/Application.cpp | 4 +++- .../render-utils/src/DebugDeferredBuffer.cpp | 18 ++++++++---------- .../render-utils/src/RenderDeferredTask.cpp | 7 ++++++- .../render-utils/src/RenderDeferredTask.h | 13 ++++++++++--- .../render-utils/src/debug_deferred_buffer.slf | 5 +++-- .../render-utils/src/debug_deferred_buffer.slv | 3 +++ libraries/render/src/render/Engine.h | 1 + .../src/SceneScriptingInterface.h | 8 ++++++-- 9 files changed, 46 insertions(+), 19 deletions(-) diff --git a/examples/utilities/tools/renderEngineDebug.js b/examples/utilities/tools/renderEngineDebug.js index cca97b7184..940eeda02d 100755 --- a/examples/utilities/tools/renderEngineDebug.js +++ b/examples/utilities/tools/renderEngineDebug.js @@ -66,6 +66,12 @@ var overlaysCounter = new CounterWidget(panel, "Overlays", var showDisplayStatusFlag = 1; var showNetworkStatusFlag = 2; +panel.newCheckbox("Debug deferred buffer", + function(value) { Scene.setEngineDisplayDebugDeferredBuffer(value > 0); }, + function() { return Scene.doEngineDisplayDebugDeferredBuffer() > 0; }, + function(value) { return value > 0; } +); + panel.newCheckbox("Display status", function(value) { Scene.setEngineDisplayItemStatus(value ? Scene.doEngineDisplayItemStatus() | showDisplayStatusFlag : diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index cc9a47f793..8fa772e316 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3621,7 +3621,9 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se renderContext._maxDrawnOpaqueItems = sceneInterface->getEngineMaxDrawnOpaqueItems(); renderContext._maxDrawnTransparentItems = sceneInterface->getEngineMaxDrawnTransparentItems(); renderContext._maxDrawnOverlay3DItems = sceneInterface->getEngineMaxDrawnOverlay3DItems(); - + + renderContext._drawDebugDeferredBuffer = sceneInterface->doEngineDisplayDebugDeferredBuffer(); + renderContext._drawItemStatus = sceneInterface->doEngineDisplayItemStatus(); if (Menu::getInstance()->isOptionChecked(MenuOption::PhysicsShowOwned)) { renderContext._drawItemStatus |= render::showNetworkStatusFlag; diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index e1c31f943e..efb78c888c 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -17,6 +17,7 @@ #include #include "GeometryCache.h" +#include "FramebufferCache.h" #include "debug_deferred_buffer_vert.h" #include "debug_deferred_buffer_frag.h" @@ -33,16 +34,8 @@ const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline() { gpu::Shader::BindingSet slotBindings; gpu::Shader::makeProgram(*program, slotBindings); - auto state = std::make_shared(); - - state->setDepthTest(false, false, gpu::LESS_EQUAL); - - // Blend on transparent - state->setBlendFunction(true, - gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); - // Good to go add the brand new pipeline - _pipeline.reset(gpu::Pipeline::create(program, state)); + _pipeline.reset(gpu::Pipeline::create(program, std::make_shared())); } return _pipeline; } @@ -53,6 +46,9 @@ void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const Ren assert(renderContext->args->_viewFrustum); RenderArgs* args = renderContext->args; gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { + auto geometryBuffer = DependencyManager::get(); + auto framebufferCache = DependencyManager::get(); + glm::mat4 projMat; Transform viewMat; @@ -64,9 +60,11 @@ void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const Ren batch.setPipeline(getPipeline()); + batch.setResourceTexture(0, framebufferCache->getPrimaryNormalTexture()); + glm::vec4 color(0.0f, 0.0f, 1.0f, 1.0f); glm::vec2 bottomLeft(0.0f, -1.0f); glm::vec2 topRight(1.0f, 1.0f); - DependencyManager::get()->renderQuad(batch, bottomLeft, topRight, color); + geometryBuffer->renderQuad(batch, bottomLeft, topRight, color); }); } \ No newline at end of file diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 43ddd5b7ae..0f939682c8 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -114,6 +114,8 @@ RenderDeferredTask::RenderDeferredTask() : Task() { _jobs.push_back(Job(new DrawTransparentDeferred::JobModel("TransparentDeferred", _jobs.back().getOutput()))); _jobs.push_back(Job(new DebugDeferredBuffer::JobModel("DebugDeferredBuffer"))); + _jobs.back().setEnabled(false); + _drawDebugDeferredBufferIndex = _jobs.size() - 1; // Grab a texture map representing the different status icons and assign that to the drawStatsuJob auto iconMapPath = PathUtils::resourcesPath() + "icons/statusIconAtlas.svg"; @@ -154,10 +156,13 @@ void RenderDeferredTask::run(const SceneContextPointer& sceneContext, const Rend return; } + // Make sure we turn the deferred buffer debug on/off + setDrawDebugDeferredBuffer(renderContext->_drawDebugDeferredBuffer); + // Make sure we turn the displayItemStatus on/off setDrawItemStatus(renderContext->_drawItemStatus); - //Make sure we display hit effect on screen, as desired from a script + // Make sure we display hit effect on screen, as desired from a script setDrawHitEffect(renderContext->_drawHitEffect); diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index e75edd20da..09a2761926 100755 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -93,16 +93,23 @@ public: ~RenderDeferredTask(); render::Jobs _jobs; - + + int _drawDebugDeferredBufferIndex = -1; int _drawStatusJobIndex = -1; int _drawHitEffectJobIndex = -1; - + + void setDrawDebugDeferredBuffer(int draw) { + if (_drawDebugDeferredBufferIndex >= 0) { + _jobs[_drawDebugDeferredBufferIndex].setEnabled(draw > 0); + } + } + bool doDrawDebugDeferredBuffer() const { if (_drawDebugDeferredBufferIndex >= 0) { return _jobs[_drawDebugDeferredBufferIndex].isEnabled(); } else { return false; } } + void setDrawItemStatus(int draw) { if (_drawStatusJobIndex >= 0) { _jobs[_drawStatusJobIndex].setEnabled(draw > 0); } } - bool doDrawItemStatus() const { if (_drawStatusJobIndex >= 0) { return _jobs[_drawStatusJobIndex].isEnabled(); } else { return false; } } void setDrawHitEffect(bool draw) { if (_drawHitEffectJobIndex >= 0) { _jobs[_drawHitEffectJobIndex].setEnabled(draw); } } diff --git a/libraries/render-utils/src/debug_deferred_buffer.slf b/libraries/render-utils/src/debug_deferred_buffer.slf index c33773aa40..212a51c1ed 100644 --- a/libraries/render-utils/src/debug_deferred_buffer.slf +++ b/libraries/render-utils/src/debug_deferred_buffer.slf @@ -12,10 +12,11 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -<@include DeferredBufferWrite.slh@> +<@include DeferredBuffer.slh@> +in vec2 uv; out vec4 outFragColor; void main(void) { - outFragColor = vec4(0.0, 0.0, 1.0, 1.0); + outFragColor = texture(normalMap, uv); } \ No newline at end of file diff --git a/libraries/render-utils/src/debug_deferred_buffer.slv b/libraries/render-utils/src/debug_deferred_buffer.slv index b1b7b18f86..85ff2b651d 100644 --- a/libraries/render-utils/src/debug_deferred_buffer.slv +++ b/libraries/render-utils/src/debug_deferred_buffer.slv @@ -14,6 +14,9 @@ <@include gpu/Inputs.slh@> +out vec2 uv; + void main(void) { + uv = (inPosition.xy + 1.0) * 0.5; gl_Position = inPosition; } \ No newline at end of file diff --git a/libraries/render/src/render/Engine.h b/libraries/render/src/render/Engine.h index 7c11246cff..ab56d68291 100644 --- a/libraries/render/src/render/Engine.h +++ b/libraries/render/src/render/Engine.h @@ -53,6 +53,7 @@ public: int _numDrawnOverlay3DItems = 0; int _maxDrawnOverlay3DItems = -1; + int _drawDebugDeferredBuffer = 0; int _drawItemStatus = 0; bool _drawHitEffect = false; diff --git a/libraries/script-engine/src/SceneScriptingInterface.h b/libraries/script-engine/src/SceneScriptingInterface.h index 6be0ce44a8..eac35ad5bb 100644 --- a/libraries/script-engine/src/SceneScriptingInterface.h +++ b/libraries/script-engine/src/SceneScriptingInterface.h @@ -106,7 +106,10 @@ public: Q_INVOKABLE int getEngineMaxDrawnTransparentItems() { return _maxDrawnTransparentItems; } Q_INVOKABLE void setEngineMaxDrawnOverlay3DItems(int count) { _maxDrawnOverlay3DItems = count; } Q_INVOKABLE int getEngineMaxDrawnOverlay3DItems() { return _maxDrawnOverlay3DItems; } - + + Q_INVOKABLE void setEngineDisplayDebugDeferredBuffer(int display) { _drawDebugDeferredBuffer = display; } + Q_INVOKABLE int doEngineDisplayDebugDeferredBuffer() { return _drawDebugDeferredBuffer; } + Q_INVOKABLE void setEngineDisplayItemStatus(int display) { _drawItemStatus = display; } Q_INVOKABLE int doEngineDisplayItemStatus() { return _drawItemStatus; } @@ -142,7 +145,8 @@ protected: int _maxDrawnOpaqueItems = -1; int _maxDrawnTransparentItems = -1; int _maxDrawnOverlay3DItems = -1; - + + int _drawDebugDeferredBuffer = 0; int _drawItemStatus = 0; bool _drawHitEffect = false; From ba2e7e1f29df15dd6e8e0551dde243cb01488283 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 4 Dec 2015 11:15:06 -0800 Subject: [PATCH 07/62] Debug diffuse buffer --- libraries/render-utils/src/DebugDeferredBuffer.cpp | 2 +- libraries/render-utils/src/debug_deferred_buffer.slf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index efb78c888c..c71c6ba1a9 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -60,7 +60,7 @@ void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const Ren batch.setPipeline(getPipeline()); - batch.setResourceTexture(0, framebufferCache->getPrimaryNormalTexture()); + batch.setResourceTexture(0, framebufferCache->getDeferredColorTexture()); glm::vec4 color(0.0f, 0.0f, 1.0f, 1.0f); glm::vec2 bottomLeft(0.0f, -1.0f); diff --git a/libraries/render-utils/src/debug_deferred_buffer.slf b/libraries/render-utils/src/debug_deferred_buffer.slf index 212a51c1ed..efb1c25628 100644 --- a/libraries/render-utils/src/debug_deferred_buffer.slf +++ b/libraries/render-utils/src/debug_deferred_buffer.slf @@ -18,5 +18,5 @@ in vec2 uv; out vec4 outFragColor; void main(void) { - outFragColor = texture(normalMap, uv); + outFragColor = texture(diffuseMap, uv); } \ No newline at end of file From 3c18664c57ce86647e3aa40c825b7fa7cbcd5e2f Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 4 Dec 2015 11:47:57 -0800 Subject: [PATCH 08/62] Cleaning all the deferred buffers in the Prepare call --- libraries/render-utils/src/DeferredLightingEffect.cpp | 10 ++++++++++ libraries/render-utils/src/RenderDeferredTask.cpp | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 9ade2f5cea..7ecef1155c 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -372,11 +372,21 @@ void DeferredLightingEffect::addSpotLight(const glm::vec3& position, float radiu void DeferredLightingEffect::prepare(RenderArgs* args) { gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { batch.enableStereo(false); + // batch.setStateScissorRect(args->_viewport); + batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); auto deferredFbo = DependencyManager::get()->getDeferredFramebuffer(); batch.setFramebuffer(deferredFbo); + + // Clear Color, Depth and Stencil + batch.clearFramebuffer( + gpu::Framebuffer::BUFFER_COLOR0 | + gpu::Framebuffer::BUFFER_DEPTH | + gpu::Framebuffer::BUFFER_STENCIL, + vec4(vec3(0), 1), 1.0, 0.0, true); + // clear the normal and specular buffers batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR1, glm::vec4(0.0f, 0.0f, 0.0f, 0.0f), true); const float MAX_SPECULAR_EXPONENT = 128.0f; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index bf5f621726..6237534fee 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -35,7 +35,7 @@ using namespace render; void SetupDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { - RenderArgs* args = renderContext->args; +/* RenderArgs* args = renderContext->args; gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { auto deferredFbo = DependencyManager::get()->getDeferredFramebufferDepthColor(); @@ -51,6 +51,7 @@ void SetupDeferred::run(const SceneContextPointer& sceneContext, const RenderCon gpu::Framebuffer::BUFFER_STENCIL, vec4(vec3(0), 1), 1.0, 0.0, true); }); + */ } void PrepareDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { From ef7ddce2b64d6d33593d5b55f134f10d26f8ab4e Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 4 Dec 2015 16:52:14 -0800 Subject: [PATCH 09/62] Trying to fix the problem of the background not showing correctly --- libraries/model/src/model/Skybox.slf | 3 ++- .../render-utils/src/DeferredBufferWrite.slh | 7 +++---- .../render-utils/src/DeferredLighting.slh | 4 +++- .../src/DeferredLightingEffect.cpp | 5 ++++- .../render-utils/src/RenderDeferredTask.cpp | 21 ------------------- 5 files changed, 12 insertions(+), 28 deletions(-) diff --git a/libraries/model/src/model/Skybox.slf b/libraries/model/src/model/Skybox.slf index 6246bbd9d3..9b642f138e 100755 --- a/libraries/model/src/model/Skybox.slf +++ b/libraries/model/src/model/Skybox.slf @@ -52,7 +52,8 @@ void main(void) { } } - vec3 pixel = pow(color, vec3(1.0/2.2)); // manual Gamma correction + // vec3 pixel = pow(color, vec3(1.0/2.2)); // manual Gamma correction + vec3 pixel = color; _fragColor = vec4(pixel, 0.0); #endif diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index 1c1330f0c0..573146a0af 100755 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -51,7 +51,7 @@ void packDeferredFragment(vec3 normal, float alpha, vec3 diffuse, vec3 specular, discard; } - _fragColor0 = vec4(diffuse.rgb, alpha); + _fragColor0 = vec4(diffuse.rgb, 1.0); // Opaque _fragColor1 = vec4(bestFitNormal(normal), 1.0); _fragColor2 = vec4(specular, shininess / 128.0); } @@ -61,9 +61,8 @@ void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 s discard; } - _fragColor0 = vec4(diffuse.rgb, alpha); - //_fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); - _fragColor1 = vec4(bestFitNormal(normal), 0.5); + _fragColor0 = vec4(diffuse.rgb, 0.5); + _fragColor1 = vec4(bestFitNormal(normal), 1.0); _fragColor2 = vec4(emissive, shininess / 128.0); } diff --git a/libraries/render-utils/src/DeferredLighting.slh b/libraries/render-utils/src/DeferredLighting.slh index 53ffdee0ca..d01b36f553 100755 --- a/libraries/render-utils/src/DeferredLighting.slh +++ b/libraries/render-utils/src/DeferredLighting.slh @@ -33,7 +33,9 @@ vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 sp vec3 schlick = specular * (1.0 - shlickPower5) + vec3(shlickPower5); vec3 reflect = specularPower * schlick; - return vec4(reflect, diffuse * (1 - length(schlick))); + // FIXME: + //return vec4(reflect, diffuse * (1 - length(schlick))); + return vec4(reflect, diffuse); } <@endfunc@> diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 7ecef1155c..7eace8d302 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -179,7 +179,10 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { //auto blitProgram = gpu::StandardShaderLib::getProgram(gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS, gpu::StandardShaderLib::getDrawTexturePS); gpu::Shader::makeProgram(*blitProgram); auto blitState = std::make_shared(); - blitState->setColorWriteMask(true, true, true, false); + /* blitState->setBlendFunction(true, + gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, + gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);*/ + blitState->setColorWriteMask(true, true, true, true); _blitLightBuffer = gpu::PipelinePointer(gpu::Pipeline::create(blitProgram, blitState)); } diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 572a3fd842..a55dcbac89 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -35,25 +35,6 @@ using namespace render; -void SetupDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { -/* RenderArgs* args = renderContext->args; - gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { - - auto deferredFbo = DependencyManager::get()->getDeferredFramebufferDepthColor(); - - batch.enableStereo(false); - batch.setViewportTransform(args->_viewport); - batch.setStateScissorRect(args->_viewport); - - batch.setFramebuffer(deferredFbo); - batch.clearFramebuffer( - gpu::Framebuffer::BUFFER_COLOR0 | - gpu::Framebuffer::BUFFER_DEPTH | - gpu::Framebuffer::BUFFER_STENCIL, - vec4(vec3(0), 1), 1.0, 0.0, true); - }); - */ -} void PrepareDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { DependencyManager::get()->prepare(renderContext->args); @@ -69,8 +50,6 @@ void ResolveDeferred::run(const SceneContextPointer& sceneContext, const RenderC } RenderDeferredTask::RenderDeferredTask() : Task() { - _jobs.push_back(Job(new SetupDeferred::JobModel("SetupFramebuffer"))); - _jobs.push_back(Job(new PrepareDeferred::JobModel("PrepareDeferred"))); _jobs.push_back(Job(new FetchItems::JobModel("FetchOpaque", FetchItems( From 5bfcd4ed91e5b135a0df219b7e86390f290a6809 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 4 Dec 2015 15:51:37 -0800 Subject: [PATCH 10/62] Fix scripted checkbox --- examples/utilities/tools/cookies.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/utilities/tools/cookies.js b/examples/utilities/tools/cookies.js index d9fa999a13..edb0fb4330 100644 --- a/examples/utilities/tools/cookies.js +++ b/examples/utilities/tools/cookies.js @@ -384,10 +384,10 @@ var CHECK_MARK_COLOR = { y: newY }); Overlays.editOverlay(this.checkMark, { - y: newY + y: newY + (0.25 * this.thumbSize) }); Overlays.editOverlay(this.unCheckMark, { - y: newY + y: newY + (0.25 * this.thumbSize) }); }; @@ -399,10 +399,10 @@ var CHECK_MARK_COLOR = { y: this.y }); Overlays.editOverlay(this.checkMark, { - y: this.y + y: this.y + (0.25 * this.thumbSize) }); Overlays.editOverlay(this.unCheckMark, { - y: this.y + y: this.y+ (0.25 * this.thumbSize) }); }; From b45b1cc513ca9ed43a07de1bcfbe4b48d7e0f29c Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 4 Dec 2015 17:43:00 -0800 Subject: [PATCH 11/62] More work on live g-buffer debug --- examples/utilities/tools/renderEngineDebug.js | 20 +++++++--- interface/src/Menu.cpp | 20 ++++++++++ interface/src/Menu.h | 2 + .../src/scripting/MenuScriptingInterface.cpp | 13 +++++++ .../src/scripting/MenuScriptingInterface.h | 4 ++ .../render-utils/src/DebugDeferredBuffer.cpp | 38 +++++++++++++++---- .../render-utils/src/DebugDeferredBuffer.h | 14 ++++++- libraries/render-utils/src/DeferredBuffer.slh | 3 ++ .../src/debug_deferred_buffer.slf | 6 ++- 9 files changed, 103 insertions(+), 17 deletions(-) diff --git a/examples/utilities/tools/renderEngineDebug.js b/examples/utilities/tools/renderEngineDebug.js index 940eeda02d..b300ff2ea8 100755 --- a/examples/utilities/tools/renderEngineDebug.js +++ b/examples/utilities/tools/renderEngineDebug.js @@ -10,6 +10,9 @@ Script.include("cookies.js"); +var MENU = "Developer>Render>Debug Deferred Buffer"; +var ACTIONS = ["Off", "Diffuse", "Normal", "Specular", "Depth", "Lighting"]; + var panel = new Panel(10, 100); function CounterWidget(parentPanel, name, feedGetter, drawGetter, capSetter, capGetter) { @@ -61,17 +64,18 @@ var overlaysCounter = new CounterWidget(panel, "Overlays", function () { return Scene.getEngineMaxDrawnOverlay3DItems(); } ); +function menuItemEvent(menuItem) { + var index = ACTIONS.indexOf(menuItem); + if (index >= 0) { + Scene.setEngineDisplayDebugDeferredBuffer(index); + print(menuItem); + } +} // see libraries/render/src/render/Engine.h var showDisplayStatusFlag = 1; var showNetworkStatusFlag = 2; -panel.newCheckbox("Debug deferred buffer", - function(value) { Scene.setEngineDisplayDebugDeferredBuffer(value > 0); }, - function() { return Scene.doEngineDisplayDebugDeferredBuffer() > 0; }, - function(value) { return value > 0; } -); - panel.newCheckbox("Display status", function(value) { Scene.setEngineDisplayItemStatus(value ? Scene.doEngineDisplayItemStatus() | showDisplayStatusFlag : @@ -101,7 +105,11 @@ Controller.mouseMoveEvent.connect(function panelMouseMoveEvent(event) { return p Controller.mousePressEvent.connect( function panelMousePressEvent(event) { return panel.mousePressEvent(event); }); Controller.mouseReleaseEvent.connect(function(event) { return panel.mouseReleaseEvent(event); }); +Menu.menuItemEvent.connect(menuItemEvent); +Menu.addActionGroup(MENU, ACTIONS, ACTIONS[0]); + function scriptEnding() { panel.destroy(); + Menu.removeActionGroup(MENU); } Script.scriptEnding.connect(scriptEnding); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 86b3987af1..66c1824176 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -985,6 +985,26 @@ bool Menu::menuItemExists(const QString& menu, const QString& menuitem) { return false; }; +void Menu::addActionGroup(const QString& groupName, const QStringList& actionList, const QString& selected) { + auto menu = addMenu(groupName); + + QActionGroup* actionGroup = new QActionGroup(menu); + actionGroup->setExclusive(true); + + auto menuScriptingInterface = MenuScriptingInterface::getInstance(); + for (auto action : actionList) { + auto item = addCheckableActionToQMenuAndActionHash(menu, action, 0, action == selected, + menuScriptingInterface, + SLOT(menuItemTriggered())); + actionGroup->addAction(item); + } + + QMenuBar::repaint(); +} + +void Menu::removeActionGroup(const QString& groupName) { + removeMenu(groupName); +} MenuWrapper::MenuWrapper(QMenu* menu) : _realMenu(menu) { VrMenu::executeOrQueue([=](VrMenu* vrMenu) { diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 3ff0b149f4..49759c8beb 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -100,6 +100,8 @@ public slots: void addMenuItem(const MenuItemProperties& properties); void removeMenuItem(const QString& menuName, const QString& menuitem); bool menuItemExists(const QString& menuName, const QString& menuitem); + void addActionGroup(const QString& groupName, const QStringList& actionList, const QString& selected = QString()); + void removeActionGroup(const QString& groupName); bool isOptionChecked(const QString& menuOption) const; void setIsOptionChecked(const QString& menuOption, bool isChecked); diff --git a/interface/src/scripting/MenuScriptingInterface.cpp b/interface/src/scripting/MenuScriptingInterface.cpp index ff7784b9ae..087d391daa 100644 --- a/interface/src/scripting/MenuScriptingInterface.cpp +++ b/interface/src/scripting/MenuScriptingInterface.cpp @@ -84,6 +84,19 @@ bool MenuScriptingInterface::menuItemExists(const QString& menu, const QString& return result; } +void MenuScriptingInterface::addActionGroup(const QString& groupName, const QStringList& actionList, + const QString& selected) { + QMetaObject::invokeMethod(Menu::getInstance(), "addActionGroup", + Q_ARG(const QString&, groupName), + Q_ARG(const QStringList&, actionList), + Q_ARG(const QString&, selected)); +} + +void MenuScriptingInterface::removeActionGroup(const QString& groupName) { + QMetaObject::invokeMethod(Menu::getInstance(), "removeActionGroup", + Q_ARG(const QString&, groupName)); +} + bool MenuScriptingInterface::isOptionChecked(const QString& menuOption) { bool result; QMetaObject::invokeMethod(Menu::getInstance(), "isOptionChecked", Qt::BlockingQueuedConnection, diff --git a/interface/src/scripting/MenuScriptingInterface.h b/interface/src/scripting/MenuScriptingInterface.h index 5c01318a38..51399c2fa5 100644 --- a/interface/src/scripting/MenuScriptingInterface.h +++ b/interface/src/scripting/MenuScriptingInterface.h @@ -42,6 +42,10 @@ public slots: void removeMenuItem(const QString& menuName, const QString& menuitem); bool menuItemExists(const QString& menuName, const QString& menuitem); + void addActionGroup(const QString& groupName, const QStringList& actionList, + const QString& selected = QString()); + void removeActionGroup(const QString& groupName); + bool isOptionChecked(const QString& menuOption); void setIsOptionChecked(const QString& menuOption, bool isChecked); diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index 5510d9c3fc..3b4e3d2bd5 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -24,20 +24,38 @@ using namespace render; -const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline() { - if (!_pipeline) { +static const std::string PLACEHOLDER { "DEBUG_PLACEHOLDER" }; +static const std::array SLOT_NAMES {{ + "diffuseMap", + "normalMap", + "specularMap", + "depthMap", + "lightingMap" +}}; + +std::string getCode(int slot) { + return std::string("return texture(").append(SLOT_NAMES[slot]).append(", uv);"); +} + +const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(int slot) { + if (!_pipelines[slot]) { + std::string fragmentShader = debug_deferred_buffer_frag; + fragmentShader.replace(fragmentShader.find(PLACEHOLDER), PLACEHOLDER.size(), getCode(slot)); + auto vs = gpu::ShaderPointer(gpu::Shader::createVertex({ debug_deferred_buffer_vert })); - auto ps = gpu::ShaderPointer(gpu::Shader::createPixel({ debug_deferred_buffer_frag })); + auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(fragmentShader)); auto program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps)); - gpu::Shader::BindingSet slotBindings; + for (int slot = 0; slot < NUM_SLOTS; ++slot) { + slotBindings.insert(gpu::Shader::Binding(SLOT_NAMES[slot], slot)); + } gpu::Shader::makeProgram(*program, slotBindings); // Good to go add the brand new pipeline - _pipeline = gpu::Pipeline::create(program, std::make_shared()); + _pipelines[slot] = gpu::Pipeline::create(program, std::make_shared()); } - return _pipeline; + return _pipelines[slot]; } @@ -58,9 +76,13 @@ void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const Ren batch.setViewTransform(viewMat); batch.setModelTransform(Transform()); - batch.setPipeline(getPipeline()); + batch.setPipeline(getPipeline((DebugDeferredBufferSlot)(renderContext->_drawDebugDeferredBuffer - 1))); - batch.setResourceTexture(0, framebufferCache->getDeferredColorTexture()); + batch.setResourceTexture(Diffuse, framebufferCache->getDeferredColorTexture()); + batch.setResourceTexture(Normal, framebufferCache->getDeferredNormalTexture()); + batch.setResourceTexture(Specular, framebufferCache->getDeferredSpecularTexture()); + batch.setResourceTexture(Depth, framebufferCache->getPrimaryDepthTexture()); + batch.setResourceTexture(Lighting, framebufferCache->getLightingTexture()); glm::vec4 color(0.0f, 0.0f, 1.0f, 1.0f); glm::vec2 bottomLeft(0.0f, -1.0f); diff --git a/libraries/render-utils/src/DebugDeferredBuffer.h b/libraries/render-utils/src/DebugDeferredBuffer.h index 827a3271f0..95865cc12a 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.h +++ b/libraries/render-utils/src/DebugDeferredBuffer.h @@ -18,12 +18,22 @@ class DebugDeferredBuffer { public: using JobModel = render::Job::Model; + enum DebugDeferredBufferSlot : int { + Diffuse = 0, + Normal, + Specular, + Depth, + Lighting, + + NUM_SLOTS + }; + void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext); private: - const gpu::PipelinePointer& getPipeline(); + const gpu::PipelinePointer& getPipeline(int slot); - gpu::PipelinePointer _pipeline; + std::array _pipelines; }; #endif // hifi_DebugDeferredBuffer_h \ No newline at end of file diff --git a/libraries/render-utils/src/DeferredBuffer.slh b/libraries/render-utils/src/DeferredBuffer.slh index 275966534a..18606f2525 100755 --- a/libraries/render-utils/src/DeferredBuffer.slh +++ b/libraries/render-utils/src/DeferredBuffer.slh @@ -24,6 +24,9 @@ uniform sampler2D specularMap; // the depth texture uniform sampler2D depthMap; +// the lighting texture +uniform sampler2D lightingMap; + struct DeferredTransform { mat4 projection; diff --git a/libraries/render-utils/src/debug_deferred_buffer.slf b/libraries/render-utils/src/debug_deferred_buffer.slf index efb1c25628..55632eb337 100644 --- a/libraries/render-utils/src/debug_deferred_buffer.slf +++ b/libraries/render-utils/src/debug_deferred_buffer.slf @@ -17,6 +17,10 @@ in vec2 uv; out vec4 outFragColor; +vec4 getFragmentColor() { + DEBUG_PLACEHOLDER +} + void main(void) { - outFragColor = texture(diffuseMap, uv); + outFragColor = getFragmentColor(); } \ No newline at end of file From 41af3778784b537b27f23d8be3090c756d6c2d2a Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 4 Dec 2015 18:33:11 -0800 Subject: [PATCH 12/62] More g-buffer debugging options --- examples/utilities/tools/renderEngineDebug.js | 2 +- .../render-utils/src/DebugDeferredBuffer.cpp | 66 ++++++++++++++++--- .../render-utils/src/DebugDeferredBuffer.h | 28 ++++---- 3 files changed, 73 insertions(+), 23 deletions(-) diff --git a/examples/utilities/tools/renderEngineDebug.js b/examples/utilities/tools/renderEngineDebug.js index b300ff2ea8..ab266620ab 100755 --- a/examples/utilities/tools/renderEngineDebug.js +++ b/examples/utilities/tools/renderEngineDebug.js @@ -11,7 +11,7 @@ Script.include("cookies.js"); var MENU = "Developer>Render>Debug Deferred Buffer"; -var ACTIONS = ["Off", "Diffuse", "Normal", "Specular", "Depth", "Lighting"]; +var ACTIONS = ["Off", "Diffuse", "Alpha", "Specular", "Roughness", "Normal", "Depth", "Lighting", "Custom"]; var panel = new Panel(10, 100); diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index 3b4e3d2bd5..d3879dacf3 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -11,6 +11,8 @@ #include "DebugDeferredBuffer.h" +#include + #include #include #include @@ -24,8 +26,16 @@ using namespace render; -static const std::string PLACEHOLDER { "DEBUG_PLACEHOLDER" }; -static const std::array SLOT_NAMES {{ +enum Slots { + Diffuse = 0, + Normal, + Specular, + Depth, + Lighting, + + NUM_SLOTS +}; +static const std::array SLOT_NAMES {{ "diffuseMap", "normalMap", "specularMap", @@ -33,14 +43,50 @@ static const std::array SLOT_NAMES "lightingMap" }}; -std::string getCode(int slot) { - return std::string("return texture(").append(SLOT_NAMES[slot]).append(", uv);"); +static const std::string PLACEHOLDER { "DEBUG_PLACEHOLDER" }; + +std::string DebugDeferredBuffer::getCode(Modes mode) { + switch (mode) { + case DiffuseMode: { + QString code = "return vec4(texture(%1, uv).xyz, 1.0);"; + return code.arg(SLOT_NAMES[Diffuse].c_str()).toStdString(); + } + case AlphaMode: { + QString code = "return vec4(vec3(texture(%1, uv).a), 1.0);"; + return code.arg(SLOT_NAMES[Diffuse].c_str()).toStdString(); + } + case SpecularMode: { + QString code = "return vec4(texture(%1, uv).xyz, 1.0);"; + return code.arg(SLOT_NAMES[Specular].c_str()).toStdString(); + } + case RoughnessMode: { + QString code = "return vec4(vec3(texture(%1, uv).a), 1.0);"; + return code.arg(SLOT_NAMES[Specular].c_str()).toStdString(); + } + case NormalMode: { + QString code = "return vec4(texture(%1, uv).xyz, 1.0);"; + return code.arg(SLOT_NAMES[Normal].c_str()).toStdString(); + } + case DepthMode: { + QString code = "return vec4(vec3(texture(%1, uv).x), 1.0);"; + return code.arg(SLOT_NAMES[Depth].c_str()).toStdString(); + } + case LightingMode: { + QString code = "return vec4(texture(%1, uv).xyz, 1.0);"; + return code.arg(SLOT_NAMES[Lighting].c_str()).toStdString(); + } + case CustomMode: + return std::string("return vec4(1.0);"); + case NUM_MODES: + Q_UNIMPLEMENTED(); + return std::string("return vec4(1.0);"); + } } -const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(int slot) { - if (!_pipelines[slot]) { +const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(Modes mode) { + if (!_pipelines[mode]) { std::string fragmentShader = debug_deferred_buffer_frag; - fragmentShader.replace(fragmentShader.find(PLACEHOLDER), PLACEHOLDER.size(), getCode(slot)); + fragmentShader.replace(fragmentShader.find(PLACEHOLDER), PLACEHOLDER.size(), getCode(mode)); auto vs = gpu::ShaderPointer(gpu::Shader::createVertex({ debug_deferred_buffer_vert })); auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(fragmentShader)); @@ -53,9 +99,9 @@ const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(int slot) { gpu::Shader::makeProgram(*program, slotBindings); // Good to go add the brand new pipeline - _pipelines[slot] = gpu::Pipeline::create(program, std::make_shared()); + _pipelines[mode] = gpu::Pipeline::create(program, std::make_shared()); } - return _pipelines[slot]; + return _pipelines[mode]; } @@ -76,7 +122,7 @@ void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const Ren batch.setViewTransform(viewMat); batch.setModelTransform(Transform()); - batch.setPipeline(getPipeline((DebugDeferredBufferSlot)(renderContext->_drawDebugDeferredBuffer - 1))); + batch.setPipeline(getPipeline(Modes(renderContext->_drawDebugDeferredBuffer - 1))); batch.setResourceTexture(Diffuse, framebufferCache->getDeferredColorTexture()); batch.setResourceTexture(Normal, framebufferCache->getDeferredNormalTexture()); diff --git a/libraries/render-utils/src/DebugDeferredBuffer.h b/libraries/render-utils/src/DebugDeferredBuffer.h index 95865cc12a..8628d9e21e 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.h +++ b/libraries/render-utils/src/DebugDeferredBuffer.h @@ -18,22 +18,26 @@ class DebugDeferredBuffer { public: using JobModel = render::Job::Model; - enum DebugDeferredBufferSlot : int { - Diffuse = 0, - Normal, - Specular, - Depth, - Lighting, - - NUM_SLOTS - }; - void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext); private: - const gpu::PipelinePointer& getPipeline(int slot); + enum Modes : int { + DiffuseMode = 0, + AlphaMode, + SpecularMode, + RoughnessMode, + NormalMode, + DepthMode, + LightingMode, + CustomMode, + + NUM_MODES + }; - std::array _pipelines; + const gpu::PipelinePointer& getPipeline(Modes mode); + std::string getCode(Modes mode); + + std::array _pipelines; }; #endif // hifi_DebugDeferredBuffer_h \ No newline at end of file From acb9e2774e65494d151ddd1dd91a84722a150d14 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 4 Dec 2015 20:28:38 -0800 Subject: [PATCH 13/62] Basic implementation of debug zone resizing --- examples/utilities/tools/renderEngineDebug.js | 51 +++++++++++++++++-- interface/src/Application.cpp | 3 +- .../render-utils/src/DebugDeferredBuffer.cpp | 14 ++--- .../render-utils/src/RenderDeferredTask.cpp | 2 +- .../render-utils/src/RenderDeferredTask.h | 2 +- .../src/debug_deferred_buffer.slf | 4 +- libraries/render/src/render/Engine.h | 3 +- .../src/SceneScriptingInterface.h | 9 ++-- 8 files changed, 70 insertions(+), 18 deletions(-) diff --git a/examples/utilities/tools/renderEngineDebug.js b/examples/utilities/tools/renderEngineDebug.js index ab266620ab..c37c104498 100755 --- a/examples/utilities/tools/renderEngineDebug.js +++ b/examples/utilities/tools/renderEngineDebug.js @@ -13,6 +13,10 @@ Script.include("cookies.js"); var MENU = "Developer>Render>Debug Deferred Buffer"; var ACTIONS = ["Off", "Diffuse", "Alpha", "Specular", "Roughness", "Normal", "Depth", "Lighting", "Custom"]; +Number.prototype.clamp = function(min, max) { + return Math.min(Math.max(this, min), max); +}; + var panel = new Panel(10, 100); function CounterWidget(parentPanel, name, feedGetter, drawGetter, capSetter, capGetter) { @@ -64,10 +68,23 @@ var overlaysCounter = new CounterWidget(panel, "Overlays", function () { return Scene.getEngineMaxDrawnOverlay3DItems(); } ); +var resizing = false; +Scene.setEngineDeferredDebugSize({ x: 0.0, y: -1.0, z: 1.0, w: 1.0 }); // Reset to default size + +function setEngineDeferredDebugSize(eventX) { + var scaledX = (2.0 * (eventX / Window.innerWidth) - 1.0).clamp(-1.0, 1.0); + Scene.setEngineDeferredDebugSize({ x: scaledX, y: -1.0, z: 1.0, w: 1.0 }); +} +function shouldStartResizing(eventX) { + var x = Math.abs(eventX - Window.innerWidth * (1.0 + Scene.getEngineDeferredDebugSize().x) / 2.0); + var mode = Scene.getEngineDeferredDebugMode(); + return mode !== -1 && x < 20; +} + function menuItemEvent(menuItem) { var index = ACTIONS.indexOf(menuItem); if (index >= 0) { - Scene.setEngineDisplayDebugDeferredBuffer(index); + Scene.setEngineDeferredDebugMode(index - 1); print(menuItem); } } @@ -101,9 +118,33 @@ function updateCounters() { } Script.setInterval(updateCounters, tickTackPeriod); -Controller.mouseMoveEvent.connect(function panelMouseMoveEvent(event) { return panel.mouseMoveEvent(event); }); -Controller.mousePressEvent.connect( function panelMousePressEvent(event) { return panel.mousePressEvent(event); }); -Controller.mouseReleaseEvent.connect(function(event) { return panel.mouseReleaseEvent(event); }); +function mouseMoveEvent(event) { + if (resizing) { + setEngineDeferredDebugSize(event.x); + } else { + panel.mouseMoveEvent(event); + } +} + +function mousePressEvent(event) { + if (shouldStartResizing(event.x)) { + resizing = true; + } else { + panel.mousePressEvent(event); + } +} + +function mouseReleaseEvent(event) { + if (resizing) { + resizing = false; + } else { + panel.mouseReleaseEvent(event); + } +} + +Controller.mouseMoveEvent.connect(mouseMoveEvent); +Controller.mousePressEvent.connect(mousePressEvent); +Controller.mouseReleaseEvent.connect(mouseReleaseEvent); Menu.menuItemEvent.connect(menuItemEvent); Menu.addActionGroup(MENU, ACTIONS, ACTIONS[0]); @@ -111,5 +152,7 @@ Menu.addActionGroup(MENU, ACTIONS, ACTIONS[0]); function scriptEnding() { panel.destroy(); Menu.removeActionGroup(MENU); + Scene.setEngineDeferredDebugMode(-1); + Scene.setEngineDeferredDebugSize({ x: 0.0, y: -1.0, z: 1.0, w: 1.0 }); // Reset to default size } Script.scriptEnding.connect(scriptEnding); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d9fea20ad5..78724862de 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3622,7 +3622,8 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se renderContext._maxDrawnTransparentItems = sceneInterface->getEngineMaxDrawnTransparentItems(); renderContext._maxDrawnOverlay3DItems = sceneInterface->getEngineMaxDrawnOverlay3DItems(); - renderContext._drawDebugDeferredBuffer = sceneInterface->doEngineDisplayDebugDeferredBuffer(); + renderContext._deferredDebugMode = sceneInterface->getEngineDeferredDebugMode(); + renderContext._deferredDebugSize = sceneInterface->getEngineDeferredDebugSize(); renderContext._drawItemStatus = sceneInterface->doEngineDisplayItemStatus(); if (Menu::getInstance()->isOptionChecked(MenuOption::PhysicsShowOwned)) { diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index d3879dacf3..842729144d 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -43,7 +43,8 @@ static const std::array SLOT_NAMES {{ "lightingMap" }}; -static const std::string PLACEHOLDER { "DEBUG_PLACEHOLDER" }; +static const std::string COMPUTE_PLACEHOLDER { "/*COMPUTE_PLACEHOLDER*/" }; // required +static const std::string FUNCTIONS_PLACEHOLDER { "/*FUNCTIONS_PLACEHOLDER*/" }; // optional std::string DebugDeferredBuffer::getCode(Modes mode) { switch (mode) { @@ -86,7 +87,8 @@ std::string DebugDeferredBuffer::getCode(Modes mode) { const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(Modes mode) { if (!_pipelines[mode]) { std::string fragmentShader = debug_deferred_buffer_frag; - fragmentShader.replace(fragmentShader.find(PLACEHOLDER), PLACEHOLDER.size(), getCode(mode)); + fragmentShader.replace(fragmentShader.find(COMPUTE_PLACEHOLDER), COMPUTE_PLACEHOLDER.size(), + getCode(mode)); auto vs = gpu::ShaderPointer(gpu::Shader::createVertex({ debug_deferred_buffer_vert })); auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(fragmentShader)); @@ -122,7 +124,7 @@ void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const Ren batch.setViewTransform(viewMat); batch.setModelTransform(Transform()); - batch.setPipeline(getPipeline(Modes(renderContext->_drawDebugDeferredBuffer - 1))); + batch.setPipeline(getPipeline(Modes(renderContext->_deferredDebugMode))); batch.setResourceTexture(Diffuse, framebufferCache->getDeferredColorTexture()); batch.setResourceTexture(Normal, framebufferCache->getDeferredNormalTexture()); @@ -130,9 +132,9 @@ void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const Ren batch.setResourceTexture(Depth, framebufferCache->getPrimaryDepthTexture()); batch.setResourceTexture(Lighting, framebufferCache->getLightingTexture()); - glm::vec4 color(0.0f, 0.0f, 1.0f, 1.0f); - glm::vec2 bottomLeft(0.0f, -1.0f); - glm::vec2 topRight(1.0f, 1.0f); + glm::vec4 color(1.0f, 1.0f, 1.0f, 1.0f); + glm::vec2 bottomLeft(renderContext->_deferredDebugSize.x, renderContext->_deferredDebugSize.y); + glm::vec2 topRight(renderContext->_deferredDebugSize.z, renderContext->_deferredDebugSize.w); geometryBuffer->renderQuad(batch, bottomLeft, topRight, color); }); } \ No newline at end of file diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 1272e1a131..f04394750b 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -157,7 +157,7 @@ void RenderDeferredTask::run(const SceneContextPointer& sceneContext, const Rend } // Make sure we turn the deferred buffer debug on/off - setDrawDebugDeferredBuffer(renderContext->_drawDebugDeferredBuffer); + setDrawDebugDeferredBuffer(renderContext->_deferredDebugMode); // Make sure we turn the displayItemStatus on/off setDrawItemStatus(renderContext->_drawItemStatus); diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index 09a2761926..f128d186cc 100755 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -100,7 +100,7 @@ public: void setDrawDebugDeferredBuffer(int draw) { if (_drawDebugDeferredBufferIndex >= 0) { - _jobs[_drawDebugDeferredBufferIndex].setEnabled(draw > 0); + _jobs[_drawDebugDeferredBufferIndex].setEnabled(draw >= 0); } } bool doDrawDebugDeferredBuffer() const { if (_drawDebugDeferredBufferIndex >= 0) { return _jobs[_drawDebugDeferredBufferIndex].isEnabled(); } else { return false; } } diff --git a/libraries/render-utils/src/debug_deferred_buffer.slf b/libraries/render-utils/src/debug_deferred_buffer.slf index 55632eb337..d8ff6e71a9 100644 --- a/libraries/render-utils/src/debug_deferred_buffer.slf +++ b/libraries/render-utils/src/debug_deferred_buffer.slf @@ -17,8 +17,10 @@ in vec2 uv; out vec4 outFragColor; +/*FUNCTIONS_PLACEHOLDER*/ + vec4 getFragmentColor() { - DEBUG_PLACEHOLDER + /*COMPUTE_PLACEHOLDER*/ } void main(void) { diff --git a/libraries/render/src/render/Engine.h b/libraries/render/src/render/Engine.h index ab56d68291..26bd6f2154 100644 --- a/libraries/render/src/render/Engine.h +++ b/libraries/render/src/render/Engine.h @@ -53,7 +53,8 @@ public: int _numDrawnOverlay3DItems = 0; int _maxDrawnOverlay3DItems = -1; - int _drawDebugDeferredBuffer = 0; + int _deferredDebugMode = -1; + glm::vec4 _deferredDebugSize { 0.0f, -1.0f, 1.0f, 1.0f }; int _drawItemStatus = 0; bool _drawHitEffect = false; diff --git a/libraries/script-engine/src/SceneScriptingInterface.h b/libraries/script-engine/src/SceneScriptingInterface.h index 583f416576..78261dfdc7 100644 --- a/libraries/script-engine/src/SceneScriptingInterface.h +++ b/libraries/script-engine/src/SceneScriptingInterface.h @@ -107,8 +107,10 @@ public: Q_INVOKABLE void setEngineMaxDrawnOverlay3DItems(int count) { _maxDrawnOverlay3DItems = count; } Q_INVOKABLE int getEngineMaxDrawnOverlay3DItems() { return _maxDrawnOverlay3DItems; } - Q_INVOKABLE void setEngineDisplayDebugDeferredBuffer(int display) { _drawDebugDeferredBuffer = display; } - Q_INVOKABLE int doEngineDisplayDebugDeferredBuffer() { return _drawDebugDeferredBuffer; } + Q_INVOKABLE void setEngineDeferredDebugMode(int mode) { _deferredDebugMode = mode; } + Q_INVOKABLE int getEngineDeferredDebugMode() { return _deferredDebugMode; } + Q_INVOKABLE void setEngineDeferredDebugSize(glm::vec4 size) { _deferredDebugSize = size; } + Q_INVOKABLE glm::vec4 getEngineDeferredDebugSize() { return _deferredDebugSize; } Q_INVOKABLE void setEngineDisplayItemStatus(int display) { _drawItemStatus = display; } Q_INVOKABLE int doEngineDisplayItemStatus() { return _drawItemStatus; } @@ -146,7 +148,8 @@ protected: int _maxDrawnTransparentItems = -1; int _maxDrawnOverlay3DItems = -1; - int _drawDebugDeferredBuffer = 0; + int _deferredDebugMode = -1; + glm::vec4 _deferredDebugSize { 0.0f, -1.0f, 1.0f, 1.0f }; int _drawItemStatus = 0; bool _drawHitEffect = false; From 0603ead972cf4823d8a45bc32b1f0a39ac77bca1 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 4 Dec 2015 20:59:21 -0800 Subject: [PATCH 14/62] Have panels collapsed by default --- examples/utilities/tools/renderEngineDebug.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/utilities/tools/renderEngineDebug.js b/examples/utilities/tools/renderEngineDebug.js index c37c104498..60686912e8 100755 --- a/examples/utilities/tools/renderEngineDebug.js +++ b/examples/utilities/tools/renderEngineDebug.js @@ -156,3 +156,9 @@ function scriptEnding() { Scene.setEngineDeferredDebugSize({ x: 0.0, y: -1.0, z: 1.0, w: 1.0 }); // Reset to default size } Script.scriptEnding.connect(scriptEnding); + + +// Collapse items +panel.mousePressEvent({ x: panel.x, y: panel.items["Overlays"].y}); +panel.mousePressEvent({ x: panel.x, y: panel.items["Transparents"].y}); +panel.mousePressEvent({ x: panel.x, y: panel.items["Opaques"].y}); From a018c51945dc527aa0a1a6ade4bf696a3d7336e9 Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Sun, 6 Dec 2015 23:51:29 -0800 Subject: [PATCH 15/62] Drawing background first in the Lighting buffer then lighting passes with stencil test --- .../src/DeferredLightingEffect.cpp | 46 +++++---------- .../render-utils/src/DeferredLightingEffect.h | 12 ---- .../render-utils/src/FramebufferCache.cpp | 1 + .../render-utils/src/RenderDeferredTask.cpp | 5 +- .../src/directional_ambient_light.slf | 1 - ...onal_ambient_light_cascaded_shadow_map.slf | 57 ------------------ .../directional_ambient_light_shadow_map.slf | 56 ------------------ .../directional_light_cascaded_shadow_map.slf | 59 ------------------- .../src/directional_light_shadow_map.slf | 58 ------------------ ...ional_skybox_light_cascaded_shadow_map.slf | 59 ------------------- .../directional_skybox_light_shadow_map.slf | 58 ------------------ 11 files changed, 18 insertions(+), 394 deletions(-) delete mode 100755 libraries/render-utils/src/directional_ambient_light_cascaded_shadow_map.slf delete mode 100755 libraries/render-utils/src/directional_ambient_light_shadow_map.slf delete mode 100644 libraries/render-utils/src/directional_light_cascaded_shadow_map.slf delete mode 100644 libraries/render-utils/src/directional_light_shadow_map.slf delete mode 100755 libraries/render-utils/src/directional_skybox_light_cascaded_shadow_map.slf delete mode 100755 libraries/render-utils/src/directional_skybox_light_shadow_map.slf diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 82cd0dc00f..af67f6b870 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -34,16 +34,8 @@ #include "deferred_light_spot_vert.h" #include "directional_light_frag.h" -#include "directional_light_shadow_map_frag.h" -#include "directional_light_cascaded_shadow_map_frag.h" - #include "directional_ambient_light_frag.h" -#include "directional_ambient_light_shadow_map_frag.h" -#include "directional_ambient_light_cascaded_shadow_map_frag.h" - #include "directional_skybox_light_frag.h" -#include "directional_skybox_light_shadow_map_frag.h" -#include "directional_skybox_light_cascaded_shadow_map_frag.h" #include "point_light_frag.h" #include "spot_light_frag.h" @@ -51,8 +43,6 @@ static const std::string glowIntensityShaderHandle = "glowIntensity"; struct LightLocations { - int shadowDistances; - int shadowScale; int radius; int ambientSphere; int lightBufferUnit; @@ -107,34 +97,16 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { _viewState = viewState; _directionalLightLocations = std::make_shared(); - _directionalLightShadowMapLocations = std::make_shared(); - _directionalLightCascadedShadowMapLocations = std::make_shared(); _directionalAmbientSphereLightLocations = std::make_shared(); - _directionalAmbientSphereLightShadowMapLocations = std::make_shared(); - _directionalAmbientSphereLightCascadedShadowMapLocations = std::make_shared(); _directionalSkyboxLightLocations = std::make_shared(); - _directionalSkyboxLightShadowMapLocations = std::make_shared(); - _directionalSkyboxLightCascadedShadowMapLocations = std::make_shared(); _pointLightLocations = std::make_shared(); _spotLightLocations = std::make_shared(); loadLightProgram(deferred_light_vert, directional_light_frag, false, _directionalLight, _directionalLightLocations); - loadLightProgram(deferred_light_vert, directional_light_shadow_map_frag, false, _directionalLightShadowMap, - _directionalLightShadowMapLocations); - loadLightProgram(deferred_light_vert, directional_light_cascaded_shadow_map_frag, false, _directionalLightCascadedShadowMap, - _directionalLightCascadedShadowMapLocations); loadLightProgram(deferred_light_vert, directional_ambient_light_frag, false, _directionalAmbientSphereLight, _directionalAmbientSphereLightLocations); - loadLightProgram(deferred_light_vert, directional_ambient_light_shadow_map_frag, false, _directionalAmbientSphereLightShadowMap, - _directionalAmbientSphereLightShadowMapLocations); - loadLightProgram(deferred_light_vert, directional_ambient_light_cascaded_shadow_map_frag, false, _directionalAmbientSphereLightCascadedShadowMap, - _directionalAmbientSphereLightCascadedShadowMapLocations); loadLightProgram(deferred_light_vert, directional_skybox_light_frag, false, _directionalSkyboxLight, _directionalSkyboxLightLocations); - loadLightProgram(deferred_light_vert, directional_skybox_light_shadow_map_frag, false, _directionalSkyboxLightShadowMap, - _directionalSkyboxLightShadowMapLocations); - loadLightProgram(deferred_light_vert, directional_skybox_light_cascaded_shadow_map_frag, false, _directionalSkyboxLightCascadedShadowMap, - _directionalSkyboxLightCascadedShadowMapLocations); loadLightProgram(deferred_light_limited_vert, point_light_frag, true, _pointLight, _pointLightLocations); @@ -379,6 +351,15 @@ void DeferredLightingEffect::prepare(RenderArgs* args) { batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); + // Clear Lighting buffer + auto lightingFbo = DependencyManager::get()->getLightingFramebuffer(); + + batch.setFramebuffer(lightingFbo); + batch.clearFramebuffer( + gpu::Framebuffer::BUFFER_COLOR0, + vec4(vec3(0), 0), 1.0, 0.0, true); + + // Clear deferred auto deferredFbo = DependencyManager::get()->getDeferredFramebuffer(); batch.setFramebuffer(deferredFbo); @@ -422,7 +403,7 @@ void DeferredLightingEffect::render(RenderArgs* args) { // Clearing it batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); - batch.clearColorFramebuffer(lightingFBO->getBufferMask(), glm::vec4(0.0f, 0.0f, 0.0f, 0.0f), true); + // batch.clearColorFramebuffer(lightingFBO->getBufferMask(), glm::vec4(0.0f, 0.0f, 0.0f, 0.0f), true); // BInd the G-Buffer surfaces batch.setResourceTexture(0, framebufferCache->getDeferredColorTexture()); @@ -768,7 +749,6 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo slotBindings.insert(gpu::Shader::Binding(std::string("normalMap"), 1)); slotBindings.insert(gpu::Shader::Binding(std::string("specularMap"), 2)); slotBindings.insert(gpu::Shader::Binding(std::string("depthMap"), 3)); - slotBindings.insert(gpu::Shader::Binding(std::string("shadowMap"), 4)); slotBindings.insert(gpu::Shader::Binding(std::string("skyboxMap"), 5)); const int LIGHT_GPU_SLOT = 3; slotBindings.insert(gpu::Shader::Binding(std::string("lightBuffer"), LIGHT_GPU_SLOT)); @@ -779,8 +759,6 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo gpu::Shader::makeProgram(*program, slotBindings); - locations->shadowDistances = program->getUniforms().findLocation("shadowDistances"); - locations->shadowScale = program->getUniforms().findLocation("shadowScale"); locations->radius = program->getUniforms().findLocation("radius"); locations->ambientSphere = program->getUniforms().findLocation("ambientSphere.L00"); @@ -793,6 +771,10 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo locations->deferredTransformBuffer = program->getBuffers().findLocation("deferredTransformBuffer"); auto state = std::make_shared(); + + // Stencil test all the light passes for objects pixels only, not the background + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + if (lightVolume) { state->setCullMode(gpu::State::CULL_BACK); diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 9c4809a82e..bf5db30310 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -106,24 +106,12 @@ private: gpu::PipelinePointer _directionalSkyboxLight; LightLocationsPtr _directionalSkyboxLightLocations; - gpu::PipelinePointer _directionalSkyboxLightShadowMap; - LightLocationsPtr _directionalSkyboxLightShadowMapLocations; - gpu::PipelinePointer _directionalSkyboxLightCascadedShadowMap; - LightLocationsPtr _directionalSkyboxLightCascadedShadowMapLocations; gpu::PipelinePointer _directionalAmbientSphereLight; LightLocationsPtr _directionalAmbientSphereLightLocations; - gpu::PipelinePointer _directionalAmbientSphereLightShadowMap; - LightLocationsPtr _directionalAmbientSphereLightShadowMapLocations; - gpu::PipelinePointer _directionalAmbientSphereLightCascadedShadowMap; - LightLocationsPtr _directionalAmbientSphereLightCascadedShadowMapLocations; gpu::PipelinePointer _directionalLight; LightLocationsPtr _directionalLightLocations; - gpu::PipelinePointer _directionalLightShadowMap; - LightLocationsPtr _directionalLightShadowMapLocations; - gpu::PipelinePointer _directionalLightCascadedShadowMap; - LightLocationsPtr _directionalLightCascadedShadowMapLocations; gpu::PipelinePointer _pointLight; LightLocationsPtr _pointLightLocations; diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index b39b8cc7e5..2d3884d81d 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -92,6 +92,7 @@ void FramebufferCache::createPrimaryFramebuffer() { // _lightingTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::HALF, gpu::RGBA), width, height, defaultSampler)); _lightingFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); _lightingFramebuffer->setRenderBuffer(0, _lightingTexture); + _lightingFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); } gpu::FramebufferPointer FramebufferCache::getPrimaryFramebufferDepthColor() { diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 90805ca2f8..72ade5315a 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -355,7 +355,8 @@ void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const doInBatch(args->_context, [=](gpu::Batch& batch) { args->_batch = &batch; - auto deferredFboColorDepthStencil = DependencyManager::get()->getDeferredFramebufferDepthColor(); + // auto deferredFboColorDepthStencil = DependencyManager::get()->getDeferredFramebufferDepthColor(); + auto deferredFboColorDepthStencil = DependencyManager::get()->getLightingFramebuffer(); auto deferredFboFull = DependencyManager::get()->getDeferredFramebuffer(); batch.enableSkybox(true); @@ -375,7 +376,7 @@ void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const renderItems(sceneContext, renderContext, inItems); - batch.setFramebuffer(deferredFboFull); + // batch.setFramebuffer(deferredFboFull); }); args->_batch = nullptr; diff --git a/libraries/render-utils/src/directional_ambient_light.slf b/libraries/render-utils/src/directional_ambient_light.slf index 52ecc71a14..ae3b05862e 100755 --- a/libraries/render-utils/src/directional_ambient_light.slf +++ b/libraries/render-utils/src/directional_ambient_light.slf @@ -27,7 +27,6 @@ void main(void) { DeferredTransform deferredTransform = getDeferredTransform(); DeferredFragment frag = unpackDeferredFragment(deferredTransform, _texCoord0); - // Light mapped or not ? if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) { vec3 color = evalLightmappedColor( deferredTransform.viewInverse, diff --git a/libraries/render-utils/src/directional_ambient_light_cascaded_shadow_map.slf b/libraries/render-utils/src/directional_ambient_light_cascaded_shadow_map.slf deleted file mode 100755 index 8b0212636e..0000000000 --- a/libraries/render-utils/src/directional_ambient_light_cascaded_shadow_map.slf +++ /dev/null @@ -1,57 +0,0 @@ -<@include gpu/Config.slh@> -<$VERSION_HEADER$> -// Generated on <$_SCRIBE_DATE$> -// -// directional_light.frag -// fragment shader -// -// Created by Andrzej Kapolka on 9/3/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// Everything about deferred buffer -<@include DeferredBuffer.slh@> - -<@include DeferredGlobalLight.slh@> - -<$declareEvalLightmappedColor()$> -<$declareEvalAmbientSphereGlobalColor()$> - -// Everything about shadow -<@include Shadow.slh@> - -in vec2 _texCoord0; -out vec4 _fragColor; - -void main(void) { - DeferredTransform deferredTransform = getDeferredTransform(); - DeferredFragment frag = unpackDeferredFragment(deferredTransform, _texCoord0); - - // Eval shadow Texcoord and then Attenuation - vec4 shadowTexcoord = evalCascadedShadowTexcoord(frag.position); - float shadowAttenuation = evalShadowAttenuation(shadowTexcoord); - - // Light mapped or not ? - if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) { - vec3 color = evalLightmappedColor( - deferredTransform.viewInverse, - shadowAttenuation, - frag.normal, - frag.diffuse, - frag.specularVal.xyz); - _fragColor = vec4(color, 1.0); - } else { - vec3 color = evalAmbienSphereGlobalColor( - deferredTransform.viewInverse, - shadowAttenuation, - frag.position.xyz, - frag.normal, - frag.diffuse, - frag.specular, - frag.gloss); - _fragColor = vec4(color, frag.normalVal.a); - } -} diff --git a/libraries/render-utils/src/directional_ambient_light_shadow_map.slf b/libraries/render-utils/src/directional_ambient_light_shadow_map.slf deleted file mode 100755 index 97d69f2e63..0000000000 --- a/libraries/render-utils/src/directional_ambient_light_shadow_map.slf +++ /dev/null @@ -1,56 +0,0 @@ -<@include gpu/Config.slh@> -<$VERSION_HEADER$> -// Generated on <$_SCRIBE_DATE$> -// -// directional_light.frag -// fragment shader -// -// Created by Andrzej Kapolka on 9/3/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// Everything about deferred buffer -<@include DeferredBuffer.slh@> - -<@include DeferredGlobalLight.slh@> -<$declareEvalLightmappedColor()$> -<$declareEvalAmbientSphereGlobalColor()$> - -// Everything about shadow -<@include Shadow.slh@> - -in vec2 _texCoord0; -out vec4 _fragColor; - -void main(void) { - DeferredTransform deferredTransform = getDeferredTransform(); - DeferredFragment frag = unpackDeferredFragment(deferredTransform, _texCoord0); - - // Eval shadow Texcoord and then Attenuation - vec4 shadowTexcoord = evalShadowTexcoord(frag.position); - float shadowAttenuation = evalShadowAttenuation(shadowTexcoord); - - // Light mapped or not ? - if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) { - vec3 color = evalLightmappedColor( - deferredTransform.viewInverse, - shadowAttenuation, - frag.normal, - frag.diffuse, - frag.specularVal.xyz); - _fragColor = vec4(color, 1.0); - } else { - vec3 color = evalAmbienSphereGlobalColor( - deferredTransform.viewInverse, - shadowAttenuation, - frag.position.xyz, - frag.normal, - frag.diffuse, - frag.specular, - frag.gloss); - _fragColor = vec4(color, frag.normalVal.a); - } -} diff --git a/libraries/render-utils/src/directional_light_cascaded_shadow_map.slf b/libraries/render-utils/src/directional_light_cascaded_shadow_map.slf deleted file mode 100644 index 4abe8e2e9d..0000000000 --- a/libraries/render-utils/src/directional_light_cascaded_shadow_map.slf +++ /dev/null @@ -1,59 +0,0 @@ -<@include gpu/Config.slh@> -<$VERSION_HEADER$> -// Generated on <$_SCRIBE_DATE$> -// -// directional_light.frag -// fragment shader -// -// Created by Andrzej Kapolka on 9/3/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// Everything about deferred buffer -<@include DeferredBuffer.slh@> - -<@include DeferredGlobalLight.slh@> - -<$declareEvalLightmappedColor()$> -<$declareEvalAmbientGlobalColor()$> - -// Everything about shadow -<@include Shadow.slh@> - -in vec2 _texCoord0; -out vec4 _fragColor; - -void main(void) { - DeferredTransform deferredTransform = getDeferredTransform(); - DeferredFragment frag = unpackDeferredFragment(deferredTransform, _texCoord0); - - - // Eval shadow Texcoord and then Attenuation - vec4 shadowTexcoord = evalCascadedShadowTexcoord(frag.position); - float shadowAttenuation = evalShadowAttenuation(shadowTexcoord); - - // Light mapped or not ? - if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) { - vec3 color = evalLightmappedColor( - deferredTransform.viewInverse, - shadowAttenuation, - frag.normal, - frag.diffuse, - frag.specularVal.xyz); - _fragColor = vec4(color, 1.0); - } else { - vec3 color = evalAmbienGlobalColor( - deferredTransform.viewInverse, - shadowAttenuation, - frag.position.xyz, - frag.normal, - frag.diffuse, - frag.specular, - frag.gloss); - - _fragColor = vec4(color, frag.normalVal.a); - } -} diff --git a/libraries/render-utils/src/directional_light_shadow_map.slf b/libraries/render-utils/src/directional_light_shadow_map.slf deleted file mode 100644 index 4249b2787c..0000000000 --- a/libraries/render-utils/src/directional_light_shadow_map.slf +++ /dev/null @@ -1,58 +0,0 @@ -<@include gpu/Config.slh@> -<$VERSION_HEADER$> -// Generated on <$_SCRIBE_DATE$> -// -// directional_light.frag -// fragment shader -// -// Created by Andrzej Kapolka on 9/3/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// Everything about deferred buffer -<@include DeferredBuffer.slh@> - -<@include DeferredGlobalLight.slh@> - -<$declareEvalLightmappedColor()$> -<$declareEvalAmbientGlobalColor()$> - -// Everything about shadow -<@include Shadow.slh@> - -in vec2 _texCoord0; -out vec4 _fragColor; - -void main(void) { - DeferredTransform deferredTransform = getDeferredTransform(); - DeferredFragment frag = unpackDeferredFragment(deferredTransform, _texCoord0); - - // Eval shadow Texcoord and then Attenuation - vec4 shadowTexcoord = evalShadowTexcoord(frag.position); - float shadowAttenuation = evalShadowAttenuation(shadowTexcoord); - - // Light mapped or not ? - if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) { - vec3 color = evalLightmappedColor( - deferredTransform.viewInverse, - shadowAttenuation, - frag.normal, - frag.diffuse, - frag.specularVal.xyz); - _fragColor = vec4(color, 1.0); - } else { - vec3 color = evalAmbienGlobalColor( - deferredTransform.viewInverse, - shadowAttenuation, - frag.position.xyz, - frag.normal, - frag.diffuse, - frag.specular, - frag.gloss); - - _fragColor = vec4(color, frag.normalVal.a); - } -} diff --git a/libraries/render-utils/src/directional_skybox_light_cascaded_shadow_map.slf b/libraries/render-utils/src/directional_skybox_light_cascaded_shadow_map.slf deleted file mode 100755 index 3c09bf62b6..0000000000 --- a/libraries/render-utils/src/directional_skybox_light_cascaded_shadow_map.slf +++ /dev/null @@ -1,59 +0,0 @@ -<@include gpu/Config.slh@> -<$VERSION_HEADER$> -// Generated on <$_SCRIBE_DATE$> -// -// directional_light.frag -// fragment shader -// -// Created by Sam Gateau on 5/8/2015. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// Everything about deferred buffer -<@include DeferredBuffer.slh@> - -<@include DeferredGlobalLight.slh@> - -<$declareEvalLightmappedColor()$> -<$declareEvalSkyboxGlobalColor()$> - -// Everything about shadow -<@include Shadow.slh@> - -in vec2 _texCoord0; -out vec4 _fragColor; - -void main(void) { - DeferredTransform deferredTransform = getDeferredTransform(); - DeferredFragment frag = unpackDeferredFragment(deferredTransform, _texCoord0); - - // Eval shadow Texcoord and then Attenuation - vec4 shadowTexcoord = evalCascadedShadowTexcoord(frag.position); - float shadowAttenuation = evalShadowAttenuation(shadowTexcoord); - - // Light mapped or not ? - if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) { - vec3 color = evalLightmappedColor( - deferredTransform.viewInverse, - shadowAttenuation, - frag.normal, - frag.diffuse, - frag.specularVal.xyz); - - _fragColor = vec4(color, 1.0); - } else { - vec3 color = evalSkyboxGlobalColor( - deferredTransform.viewInverse, - shadowAttenuation, - frag.position.xyz, - frag.normal, - frag.diffuse, - frag.specular, - frag.gloss); - - _fragColor = vec4(color, frag.normalVal.a); - } -} diff --git a/libraries/render-utils/src/directional_skybox_light_shadow_map.slf b/libraries/render-utils/src/directional_skybox_light_shadow_map.slf deleted file mode 100755 index 6f709f31fa..0000000000 --- a/libraries/render-utils/src/directional_skybox_light_shadow_map.slf +++ /dev/null @@ -1,58 +0,0 @@ -<@include gpu/Config.slh@> -<$VERSION_HEADER$> -// Generated on <$_SCRIBE_DATE$> -// -// directional_light.frag -// fragment shader -// -// Created by Sam Gateau on 5/8/2015. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// Everything about deferred buffer -<@include DeferredBuffer.slh@> - -<@include DeferredGlobalLight.slh@> - -<$declareEvalLightmappedColor()$> -<$declareEvalSkyboxGlobalColor()$> - -// Everything about shadow -<@include Shadow.slh@> - -in vec2 _texCoord0; -out vec4 _fragColor; - -void main(void) { - DeferredTransform deferredTransform = getDeferredTransform(); - DeferredFragment frag = unpackDeferredFragment(deferredTransform, _texCoord0); - - // Eval shadow Texcoord and then Attenuation - vec4 shadowTexcoord = evalShadowTexcoord(frag.position); - float shadowAttenuation = evalShadowAttenuation(shadowTexcoord); - - // Light mapped or not ? - if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) { - vec3 color = evalLightmappedColor( - deferredTransform.viewInverse, - shadowAttenuation, - frag.normal, - frag.diffuse, - frag.specularVal.xyz); - _fragColor = vec4(color, 1.0); - } else { - vec3 color = evalSkyboxGlobalColor( - deferredTransform.viewInverse, - shadowAttenuation, - frag.position.xyz, - frag.normal, - frag.diffuse, - frag.specular, - frag.gloss); - - _fragColor = vec4(color, frag.normalVal.a); - } -} From 01d48b29aaf8ce8ab6558d7c5e8bf4b22ad0e631 Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Mon, 7 Dec 2015 01:03:14 -0800 Subject: [PATCH 16/62] cleaning code and removing cruft --- libraries/render-utils/src/DeferredLightingEffect.cpp | 6 +----- libraries/render-utils/src/RenderDeferredTask.cpp | 8 ++------ 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index af67f6b870..40f6d4c5eb 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -355,9 +355,7 @@ void DeferredLightingEffect::prepare(RenderArgs* args) { auto lightingFbo = DependencyManager::get()->getLightingFramebuffer(); batch.setFramebuffer(lightingFbo); - batch.clearFramebuffer( - gpu::Framebuffer::BUFFER_COLOR0, - vec4(vec3(0), 0), 1.0, 0.0, true); + batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, vec4(vec3(0), 0), true); // Clear deferred auto deferredFbo = DependencyManager::get()->getDeferredFramebuffer(); @@ -400,10 +398,8 @@ void DeferredLightingEffect::render(RenderArgs* args) { auto lightingFBO = framebufferCache->getLightingFramebuffer(); batch.setFramebuffer(lightingFBO); - // Clearing it batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); - // batch.clearColorFramebuffer(lightingFBO->getBufferMask(), glm::vec4(0.0f, 0.0f, 0.0f, 0.0f), true); // BInd the G-Buffer surfaces batch.setResourceTexture(0, framebufferCache->getDeferredColorTexture()); diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 72ade5315a..aeacc95f96 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -355,13 +355,11 @@ void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const doInBatch(args->_context, [=](gpu::Batch& batch) { args->_batch = &batch; - // auto deferredFboColorDepthStencil = DependencyManager::get()->getDeferredFramebufferDepthColor(); - auto deferredFboColorDepthStencil = DependencyManager::get()->getLightingFramebuffer(); - auto deferredFboFull = DependencyManager::get()->getDeferredFramebuffer(); + auto lightingFBO = DependencyManager::get()->getLightingFramebuffer(); batch.enableSkybox(true); - batch.setFramebuffer(deferredFboColorDepthStencil); + batch.setFramebuffer(lightingFBO); batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); @@ -376,8 +374,6 @@ void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const renderItems(sceneContext, renderContext, inItems); - // batch.setFramebuffer(deferredFboFull); - }); args->_batch = nullptr; } From 3595d0d719d22819b4361e8e1a5b75052d6c5ca4 Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Mon, 7 Dec 2015 01:15:10 -0800 Subject: [PATCH 17/62] less commented stuff --- libraries/model/src/model/Skybox.slf | 4 +--- libraries/render-utils/src/DeferredLightingEffect.cpp | 4 ---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/libraries/model/src/model/Skybox.slf b/libraries/model/src/model/Skybox.slf index 9b642f138e..f8a568bcf9 100755 --- a/libraries/model/src/model/Skybox.slf +++ b/libraries/model/src/model/Skybox.slf @@ -52,9 +52,7 @@ void main(void) { } } - // vec3 pixel = pow(color, vec3(1.0/2.2)); // manual Gamma correction - vec3 pixel = color; - _fragColor = vec4(pixel, 0.0); + _fragColor = vec4(color, 0.0); #endif diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 40f6d4c5eb..92009ebf07 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -151,9 +151,6 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { //auto blitProgram = gpu::StandardShaderLib::getProgram(gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS, gpu::StandardShaderLib::getDrawTexturePS); gpu::Shader::makeProgram(*blitProgram); auto blitState = std::make_shared(); - /* blitState->setBlendFunction(true, - gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, - gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);*/ blitState->setColorWriteMask(true, true, true, true); _blitLightBuffer = gpu::PipelinePointer(gpu::Pipeline::create(blitProgram, blitState)); } @@ -347,7 +344,6 @@ void DeferredLightingEffect::addSpotLight(const glm::vec3& position, float radiu void DeferredLightingEffect::prepare(RenderArgs* args) { gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { batch.enableStereo(false); - // batch.setStateScissorRect(args->_viewport); batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); From 7e59d5cc04af8e3f770f9c8fcd41c370015e1f50 Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Mon, 7 Dec 2015 01:27:50 -0800 Subject: [PATCH 18/62] Fixing the failing test for shader compilations (because we removed the shadowing shaders) --- tests/shaders/src/main.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tests/shaders/src/main.cpp b/tests/shaders/src/main.cpp index 52e43e2faa..40686f5639 100644 --- a/tests/shaders/src/main.cpp +++ b/tests/shaders/src/main.cpp @@ -35,16 +35,10 @@ #include "deferred_light_limited_vert.h" #include "directional_light_frag.h" -#include "directional_light_shadow_map_frag.h" -#include "directional_light_cascaded_shadow_map_frag.h" #include "directional_ambient_light_frag.h" -#include "directional_ambient_light_shadow_map_frag.h" -#include "directional_ambient_light_cascaded_shadow_map_frag.h" #include "directional_skybox_light_frag.h" -#include "directional_skybox_light_shadow_map_frag.h" -#include "directional_skybox_light_cascaded_shadow_map_frag.h" #include "point_light_frag.h" #include "spot_light_frag.h" @@ -185,14 +179,8 @@ void QTestWindow::draw() { testShaderBuild(simple_vert, simple_textured_frag); testShaderBuild(simple_vert, simple_textured_emisive_frag); testShaderBuild(deferred_light_vert, directional_light_frag); - testShaderBuild(deferred_light_vert, directional_light_shadow_map_frag); - testShaderBuild(deferred_light_vert, directional_light_cascaded_shadow_map_frag); testShaderBuild(deferred_light_vert, directional_ambient_light_frag); - testShaderBuild(deferred_light_vert, directional_ambient_light_shadow_map_frag); - testShaderBuild(deferred_light_vert, directional_ambient_light_cascaded_shadow_map_frag); testShaderBuild(deferred_light_vert, directional_skybox_light_frag); - testShaderBuild(deferred_light_vert, directional_skybox_light_shadow_map_frag); - testShaderBuild(deferred_light_vert, directional_skybox_light_cascaded_shadow_map_frag); testShaderBuild(deferred_light_limited_vert, point_light_frag); testShaderBuild(deferred_light_limited_vert, spot_light_frag); testShaderBuild(standardTransformPNTC_vert, standardDrawTexture_frag); From 5d207d0c9c82433995f3850327238978a7c26f29 Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 7 Dec 2015 13:19:43 -0800 Subject: [PATCH 19/62] INtroducing the tonemapping job in its separate file and clean DeferredLightingEffect --- .../src/DeferredLightingEffect.cpp | 78 +------------- .../render-utils/src/DeferredLightingEffect.h | 8 +- .../render-utils/src/RenderDeferredTask.cpp | 87 +++++++++------ .../render-utils/src/RenderDeferredTask.h | 8 +- .../render-utils/src/ToneMappingEffect.cpp | 102 ++++++++++++++++++ .../render-utils/src/ToneMappingEffect.h | 46 ++++++++ 6 files changed, 209 insertions(+), 120 deletions(-) create mode 100644 libraries/render-utils/src/ToneMappingEffect.cpp create mode 100644 libraries/render-utils/src/ToneMappingEffect.h diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 92009ebf07..c8996801f1 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -82,7 +82,7 @@ gpu::PipelinePointer DeferredLightingEffect::getPipeline(SimpleProgramKey config return pipeline; } -void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { +void DeferredLightingEffect::init() { auto VS = gpu::Shader::createVertex(std::string(simple_vert)); auto PS = gpu::Shader::createPixel(std::string(simple_textured_frag)); auto PSEmissive = gpu::Shader::createPixel(std::string(simple_textured_emisive_frag)); @@ -95,7 +95,7 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { gpu::Shader::makeProgram(*_simpleShader, slotBindings); gpu::Shader::makeProgram(*_emissiveShader, slotBindings); - _viewState = viewState; + _directionalLightLocations = std::make_shared(); _directionalAmbientSphereLightLocations = std::make_shared(); _directionalSkyboxLightLocations = std::make_shared(); @@ -112,49 +112,6 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { loadLightProgram(deferred_light_limited_vert, point_light_frag, true, _pointLight, _pointLightLocations); loadLightProgram(deferred_light_spot_vert, spot_light_frag, true, _spotLight, _spotLightLocations); - { - //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 - // - // Draw texture 0 fetched at texcoord.xy - // - // Created by Sam Gateau on 6/22/2015 - // Copyright 2015 High Fidelity, Inc. - // - // Distributed under the Apache License, Version 2.0. - // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html - // - - - uniform sampler2D colorMap; - - in vec2 varTexCoord0; - out vec4 outFragColor; - - void main(void) { - outFragColor = texture(colorMap, varTexCoord0); - // if (gl_FragCoord.x > 1000) { - // Manually gamma correct from Ligthing BUffer to color buffer - outFragColor.xyz = pow( outFragColor.xyz , vec3(1.0 / 2.2) ); - // } - } - - )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::makeProgram(*blitProgram); - auto blitState = std::make_shared(); - blitState->setColorWriteMask(true, true, true, true); - _blitLightBuffer = gpu::PipelinePointer(gpu::Pipeline::create(blitProgram, blitState)); - } - // Allocate a global light representing the Global Directional light casting shadow (the sun) and the ambient light _globalLights.push_back(0); _allocatedLights.push_back(std::make_shared()); @@ -694,37 +651,6 @@ void DeferredLightingEffect::render(RenderArgs* args) { } -void DeferredLightingEffect::copyBack(RenderArgs* args) { - auto framebufferCache = DependencyManager::get(); - gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { - batch.enableStereo(false); - QSize framebufferSize = framebufferCache->getFrameBufferSize(); - - auto lightingBuffer = framebufferCache->getLightingTexture(); - auto destFbo = framebufferCache->getPrimaryFramebufferDepthColor(); - batch.setFramebuffer(destFbo); - batch.setViewportTransform(args->_viewport); - batch.setProjectionTransform(glm::mat4()); - batch.setViewTransform(Transform()); - { - float sMin = args->_viewport.x / (float)framebufferSize.width(); - float sWidth = args->_viewport.z / (float)framebufferSize.width(); - float tMin = args->_viewport.y / (float)framebufferSize.height(); - float tHeight = args->_viewport.w / (float)framebufferSize.height(); - Transform model; - batch.setPipeline(_blitLightBuffer); - model.setTranslation(glm::vec3(sMin, tMin, 0.0)); - model.setScale(glm::vec3(sWidth, tHeight, 1.0)); - batch.setModelTransform(model); - } - - batch.setResourceTexture(0, lightingBuffer); - batch.draw(gpu::TRIANGLE_STRIP, 4); - - args->_context->render(batch); - }); -} - void DeferredLightingEffect::setupTransparent(RenderArgs* args, int lightBufferUnit) { auto globalLight = _allocatedLights[_globalLights.front()]; args->_batch->setUniformBuffer(lightBufferUnit, globalLight->getSchemaBuffer()); diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index bf5db30310..efb84f2101 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -21,7 +21,6 @@ #include "model/Stage.h" #include "model/Geometry.h" -class AbstractViewStateInterface; class RenderArgs; class SimpleProgramKey; struct LightLocations; @@ -78,7 +77,6 @@ public: void prepare(RenderArgs* args); void render(RenderArgs* args); - void copyBack(RenderArgs* args); void setupTransparent(RenderArgs* args, int lightBufferUnit); @@ -101,9 +99,7 @@ private: gpu::ShaderPointer _simpleShader; gpu::ShaderPointer _emissiveShader; QHash _simplePrograms; - - gpu::PipelinePointer _blitLightBuffer; - + gpu::PipelinePointer _directionalSkyboxLight; LightLocationsPtr _directionalSkyboxLightLocations; @@ -143,8 +139,6 @@ private: std::vector _globalLights; std::vector _pointLights; std::vector _spotLights; - - AbstractViewStateInterface* _viewState; int _ambientLightMode = 0; model::AtmospherePointer _atmosphere; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index aeacc95f96..c8eefe65ac 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -44,67 +44,85 @@ void RenderDeferred::run(const SceneContextPointer& sceneContext, const RenderCo DependencyManager::get()->render(renderContext->args); } -void ResolveDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { - PerformanceTimer perfTimer("ResolveDeferred"); - DependencyManager::get()->copyBack(renderContext->args); +void ToneMappingDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { + PerformanceTimer perfTimer("ToneMappingDeferred"); + _toneMappingEffect.render(renderContext->args); } RenderDeferredTask::RenderDeferredTask() : Task() { - _jobs.push_back(Job(new PrepareDeferred::JobModel("PrepareDeferred"))); + // CPU only, create the list of renderedOpaques items _jobs.push_back(Job(new FetchItems::JobModel("FetchOpaque", FetchItems( - [] (const RenderContextPointer& context, int count) { - context->_numFeedOpaqueItems = count; - } + [](const RenderContextPointer& context, int count) { + context->_numFeedOpaqueItems = count; + } ) - ))); + ))); _jobs.push_back(Job(new CullItemsOpaque::JobModel("CullOpaque", _jobs.back().getOutput()))); _jobs.push_back(Job(new DepthSortItems::JobModel("DepthSortOpaque", _jobs.back().getOutput()))); auto& renderedOpaques = _jobs.back().getOutput(); - _jobs.push_back(Job(new DrawOpaqueDeferred::JobModel("DrawOpaqueDeferred", _jobs.back().getOutput()))); + // CPU only, create the list of renderedTransparents items + _jobs.push_back(Job(new FetchItems::JobModel("FetchTransparent", + FetchItems( + ItemFilter::Builder::transparentShape().withoutLayered(), + [](const RenderContextPointer& context, int count) { + context->_numFeedTransparentItems = count; + } + ) + ))); + _jobs.push_back(Job(new CullItemsTransparent::JobModel("CullTransparent", _jobs.back().getOutput()))); + _jobs.push_back(Job(new DepthSortItems::JobModel("DepthSortTransparent", _jobs.back().getOutput(), DepthSortItems(false)))); + auto& renderedTransparents = _jobs.back().getOutput(); + + // GPU Jobs: Start preparing the deferred and lighting buffer + _jobs.push_back(Job(new PrepareDeferred::JobModel("PrepareDeferred"))); + + // Render opaque objects in DeferredBuffer + _jobs.push_back(Job(new DrawOpaqueDeferred::JobModel("DrawOpaqueDeferred", renderedOpaques))); + + // Once opaque is all rendered create stencil background _jobs.push_back(Job(new DrawStencilDeferred::JobModel("DrawOpaqueStencil"))); + + // Use Stencil and start drawing background in Lighting buffer _jobs.push_back(Job(new DrawBackgroundDeferred::JobModel("DrawBackgroundDeferred"))); + // Draw Lights just add the lights to the current list of lights to deal with. NOt really gpu job for now. _jobs.push_back(Job(new DrawLight::JobModel("DrawLight"))); - _jobs.push_back(Job(new RenderDeferred::JobModel("RenderDeferred"))); - _jobs.push_back(Job(new ResolveDeferred::JobModel("ResolveDeferred"))); - _jobs.push_back(Job(new AmbientOcclusion::JobModel("AmbientOcclusion"))); + // DeferredBuffer is complete, now let's shade it into the LightingBuffer + _jobs.push_back(Job(new RenderDeferred::JobModel("RenderDeferred"))); + + // AO job, to be revisited + _jobs.push_back(Job(new AmbientOcclusion::JobModel("AmbientOcclusion"))); _jobs.back().setEnabled(false); _occlusionJobIndex = _jobs.size() - 1; + // AA job to be revisited _jobs.push_back(Job(new Antialiasing::JobModel("Antialiasing"))); - _jobs.back().setEnabled(false); _antialiasingJobIndex = _jobs.size() - 1; - _jobs.push_back(Job(new FetchItems::JobModel("FetchTransparent", - FetchItems( - ItemFilter::Builder::transparentShape().withoutLayered(), - [] (const RenderContextPointer& context, int count) { - context->_numFeedTransparentItems = count; - } - ) - ))); - _jobs.push_back(Job(new CullItemsTransparent::JobModel("CullTransparent", _jobs.back().getOutput()))); - - - _jobs.push_back(Job(new DepthSortItems::JobModel("DepthSortTransparent", _jobs.back().getOutput(), DepthSortItems(false)))); - _jobs.push_back(Job(new DrawTransparentDeferred::JobModel("TransparentDeferred", _jobs.back().getOutput()))); + // Render transparent objects forward in LigthingBuffer + _jobs.push_back(Job(new DrawTransparentDeferred::JobModel("TransparentDeferred", renderedTransparents))); + // Lighting Buffer ready for tone mapping + _jobs.push_back(Job(new ToneMappingDeferred::JobModel("ToneMapping"))); + + // Debugging Deferred buffer job _jobs.push_back(Job(new DebugDeferredBuffer::JobModel("DebugDeferredBuffer"))); _jobs.back().setEnabled(false); _drawDebugDeferredBufferIndex = _jobs.size() - 1; - - // Grab a texture map representing the different status icons and assign that to the drawStatsuJob - auto iconMapPath = PathUtils::resourcesPath() + "icons/statusIconAtlas.svg"; - auto statusIconMap = DependencyManager::get()->getImageTexture(iconMapPath); - _jobs.push_back(Job(new render::DrawStatus::JobModel("DrawStatus", renderedOpaques, DrawStatus(statusIconMap)))); - - _jobs.back().setEnabled(false); - _drawStatusJobIndex = _jobs.size() - 1; + // Status icon rendering job + { + // Grab a texture map representing the different status icons and assign that to the drawStatsuJob + auto iconMapPath = PathUtils::resourcesPath() + "icons/statusIconAtlas.svg"; + auto statusIconMap = DependencyManager::get()->getImageTexture(iconMapPath); + _jobs.push_back(Job(new render::DrawStatus::JobModel("DrawStatus", renderedOpaques, DrawStatus(statusIconMap)))); + _jobs.back().setEnabled(false); + _drawStatusJobIndex = _jobs.size() - 1; + } _jobs.push_back(Job(new DrawOverlay3D::JobModel("DrawOverlay3D"))); @@ -112,7 +130,6 @@ RenderDeferredTask::RenderDeferredTask() : Task() { _jobs.back().setEnabled(false); _drawHitEffectJobIndex = _jobs.size() -1; - // Give ourselves 3 frmaes of timer queries _timerQueries.push_back(std::make_shared()); _timerQueries.push_back(std::make_shared()); diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index f128d186cc..009e6f23b2 100755 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -16,6 +16,8 @@ #include "gpu/Pipeline.h" +#include "ToneMappingEffect.h" + class SetupDeferred { public: void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext); @@ -38,11 +40,13 @@ public: typedef render::Job::Model JobModel; }; -class ResolveDeferred { +class ToneMappingDeferred { public: void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext); - typedef render::Job::Model JobModel; + ToneMappingEffect _toneMappingEffect; + + typedef render::Job::Model JobModel; }; class DrawOpaqueDeferred { diff --git a/libraries/render-utils/src/ToneMappingEffect.cpp b/libraries/render-utils/src/ToneMappingEffect.cpp new file mode 100644 index 0000000000..ac5bbc69e5 --- /dev/null +++ b/libraries/render-utils/src/ToneMappingEffect.cpp @@ -0,0 +1,102 @@ +// +// ToneMappingEffect.cpp +// libraries/render-utils/src +// +// Created by Sam Gateau on 12/7/2015. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "ToneMappingEffect.h" + +#include +#include + +#include + +#include "FramebufferCache.h" + + +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 + // + // Draw texture 0 fetched at texcoord.xy + // + // Created by Sam Gateau on 6/22/2015 + // Copyright 2015 High Fidelity, Inc. + // + // Distributed under the Apache License, Version 2.0. + // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + // + + + uniform sampler2D colorMap; + + in vec2 varTexCoord0; + out vec4 outFragColor; + + void main(void) { + outFragColor = texture(colorMap, varTexCoord0); + // if (gl_FragCoord.x > 1000) { + // Manually gamma correct from Ligthing BUffer to color buffer + outFragColor.xyz = pow( outFragColor.xyz , vec3(1.0 / 2.2) ); + // } + } + + )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::makeProgram(*blitProgram); + auto blitState = std::make_shared(); + blitState->setColorWriteMask(true, true, true, true); + _blitLightBuffer = gpu::PipelinePointer(gpu::Pipeline::create(blitProgram, blitState)); +} + + +void ToneMappingEffect::render(RenderArgs* args) { + if (!_blitLightBuffer) { + init(); + } + auto framebufferCache = DependencyManager::get(); + gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { + batch.enableStereo(false); + QSize framebufferSize = framebufferCache->getFrameBufferSize(); + + auto lightingBuffer = framebufferCache->getLightingTexture(); + auto destFbo = framebufferCache->getPrimaryFramebufferDepthColor(); + batch.setFramebuffer(destFbo); + batch.setViewportTransform(args->_viewport); + batch.setProjectionTransform(glm::mat4()); + batch.setViewTransform(Transform()); + { + float sMin = args->_viewport.x / (float)framebufferSize.width(); + float sWidth = args->_viewport.z / (float)framebufferSize.width(); + float tMin = args->_viewport.y / (float)framebufferSize.height(); + float tHeight = args->_viewport.w / (float)framebufferSize.height(); + Transform model; + batch.setPipeline(_blitLightBuffer); + model.setTranslation(glm::vec3(sMin, tMin, 0.0)); + model.setScale(glm::vec3(sWidth, tHeight, 1.0)); + batch.setModelTransform(model); + } + + batch.setResourceTexture(0, lightingBuffer); + batch.draw(gpu::TRIANGLE_STRIP, 4); + + args->_context->render(batch); + }); +} \ No newline at end of file diff --git a/libraries/render-utils/src/ToneMappingEffect.h b/libraries/render-utils/src/ToneMappingEffect.h new file mode 100644 index 0000000000..9b07c0f7df --- /dev/null +++ b/libraries/render-utils/src/ToneMappingEffect.h @@ -0,0 +1,46 @@ +// +// ToneMappingEffect.h +// libraries/render-utils/src +// +// Created by Sam Gateau on 12/7/2015. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_ToneMappingEffect_h +#define hifi_ToneMappingEffect_h + +#include +#include + +#include +#include + +class RenderArgs; + +class ToneMappingEffect { +public: + ToneMappingEffect(); + virtual ~ToneMappingEffect() {} + + void render(RenderArgs* args); + +private: + + gpu::PipelinePointer _blitLightBuffer; + + // Class describing the uniform buffer with all the parameters common to the tone mapping shaders + class Parameters { + public: + + Parameters() {} + }; + typedef gpu::BufferView UniformBufferView; + gpu::BufferView _parametersBuffer; + + void init(); +}; + +#endif // hifi_ToneMappingEffect_h From 9ddc3c27bf7e35ad4f963f949741415ce682bacd Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 7 Dec 2015 13:25:55 -0800 Subject: [PATCH 20/62] compilation errors fixed --- interface/src/Application.cpp | 2 +- libraries/render-utils/src/DeferredLightingEffect.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 78724862de..99519256bf 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2499,7 +2499,7 @@ void Application::init() { _environment.init(); - DependencyManager::get()->init(this); + DependencyManager::get()->init(); DependencyManager::get()->init(); _myCamera.setMode(CAMERA_MODE_FIRST_PERSON); diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index efb84f2101..78b8e924ae 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -33,7 +33,7 @@ public: static const int NORMAL_FITTING_MAP_SLOT = 10; static const int DEFERRED_TRANSFORM_BUFFER_SLOT = 2; - void init(AbstractViewStateInterface* viewState); + void init(); /// Sets up the state necessary to render static untextured geometry with the simple program. gpu::PipelinePointer bindSimpleProgram(gpu::Batch& batch, bool textured = false, bool culled = true, From 9faec326da023116577a45ef0a3792bb2894c875 Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Tue, 8 Dec 2015 08:34:42 -0800 Subject: [PATCH 21/62] CHanging the lighting BUffer format and adding tone mapping --- libraries/gpu/src/gpu/Format.h | 3 + libraries/gpu/src/gpu/GLBackendTexture.cpp | 58 +++++++++++++++++++ libraries/gpu/src/gpu/Texture.h | 2 +- .../input-plugins/ViveControllerManager.cpp | 4 +- .../src/model-networking/TextureCache.cpp | 18 +++--- libraries/model/src/model/TextureMap.cpp | 42 +++++++------- .../src/procedural/ProceduralSkybox.slf | 4 +- .../render-utils/src/DeferredBufferWrite.slh | 2 +- .../src/DeferredLightingEffect.cpp | 1 + .../render-utils/src/FramebufferCache.cpp | 6 +- .../render-utils/src/SkyFromAtmosphere.slf | 3 +- .../render-utils/src/ToneMappingEffect.cpp | 14 ++++- libraries/render-utils/src/text/Font.cpp | 8 +-- libraries/script-engine/src/ScriptEngine.cpp | 2 +- 14 files changed, 120 insertions(+), 47 deletions(-) diff --git a/libraries/gpu/src/gpu/Format.h b/libraries/gpu/src/gpu/Format.h index 3022f47b51..41a95e2578 100644 --- a/libraries/gpu/src/gpu/Format.h +++ b/libraries/gpu/src/gpu/Format.h @@ -160,6 +160,7 @@ enum Semantic { RGB, RGBA, BGRA, + XY, XYZ, XYZW, @@ -176,6 +177,8 @@ enum Semantic { SRGBA, SBGRA, + R11G11B10, + UNIFORM, UNIFORM_BUFFER, SAMPLER, diff --git a/libraries/gpu/src/gpu/GLBackendTexture.cpp b/libraries/gpu/src/gpu/GLBackendTexture.cpp index 71c5a83331..dbf29d6ab3 100755 --- a/libraries/gpu/src/gpu/GLBackendTexture.cpp +++ b/libraries/gpu/src/gpu/GLBackendTexture.cpp @@ -224,6 +224,11 @@ public: case gpu::SRGBA: texel.internalFormat = GL_SRGB; // standard 2.2 gamma correction color break; + case gpu::R11G11B10: { + // the type should be float + texel.internalFormat = GL_R11F_G11F_B10F; + break; + } default: qCDebug(gpulogging) << "Unknown combination of texel format"; } @@ -240,6 +245,59 @@ public: break; case gpu::RGBA: texel.internalFormat = GL_RGBA; + switch (dstFormat.getType()) { + case gpu::UINT32: + texel.format = GL_RGBA_INTEGER; + texel.internalFormat = GL_RGBA32UI; + break; + case gpu::INT32: + texel.format = GL_RGBA_INTEGER; + texel.internalFormat = GL_RGBA32I; + break; + case gpu::FLOAT: + texel.internalFormat = GL_RGBA32F; + break; + case gpu::UINT16: + texel.format = GL_RGBA_INTEGER; + texel.internalFormat = GL_RGBA16UI; + break; + case gpu::INT16: + texel.format = GL_RGBA_INTEGER; + texel.internalFormat = GL_RGBA16I; + break; + case gpu::NUINT16: + texel.format = GL_RGBA; + texel.internalFormat = GL_RGBA16; + break; + case gpu::NINT16: + texel.format = GL_RGBA; + texel.internalFormat = GL_RGBA16_SNORM; + break; + case gpu::HALF: + texel.format = GL_RGBA; + texel.internalFormat = GL_RGBA16F; + break; + case gpu::UINT8: + texel.format = GL_RGBA_INTEGER; + texel.internalFormat = GL_RGBA8UI; + break; + case gpu::INT8: + texel.format = GL_RGBA_INTEGER; + texel.internalFormat = GL_RGBA8I; + break; + case gpu::NUINT8: + texel.format = GL_RGBA; + texel.internalFormat = GL_RGBA8; + break; + case gpu::NINT8: + texel.format = GL_RGBA; + texel.internalFormat = GL_RGBA8_SNORM; + break; + case gpu::NUINT32: + case gpu::NINT32: + case gpu::NUM_TYPES: // quiet compiler + Q_UNREACHABLE(); + } break; case gpu::SRGB: texel.internalFormat = GL_SRGB; diff --git a/libraries/gpu/src/gpu/Texture.h b/libraries/gpu/src/gpu/Texture.h index c3e2809c4b..6e8eb10380 100755 --- a/libraries/gpu/src/gpu/Texture.h +++ b/libraries/gpu/src/gpu/Texture.h @@ -407,7 +407,7 @@ public: TexturePointer _texture = TexturePointer(NULL); uint16 _subresource = 0; - Element _element = Element(gpu::VEC4, gpu::UINT8, gpu::RGBA); + Element _element = Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); TextureView() {}; diff --git a/libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp b/libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp index b315a7a3d9..c26e6e6bf9 100644 --- a/libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp +++ b/libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp @@ -104,8 +104,8 @@ void ViveControllerManager::activate() { // sizeof(vr::RenderModel_Vertex_t), // gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::RAW))); - gpu::Element formatGPU = gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA); - gpu::Element formatMip = gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA); + gpu::Element formatGPU = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); + gpu::Element formatMip = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); _texture = gpu::TexturePointer( gpu::Texture::create2D(formatGPU, model.diffuseTexture.unWidth, model.diffuseTexture.unHeight, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR))); diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index 3e80b6c7aa..ae705faf86 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -85,7 +85,7 @@ const gpu::TexturePointer& TextureCache::getPermutationNormalTexture() { data[i + 2] = ((randvec.z + 1.0f) / 2.0f) * 255.0f; } - _permutationNormalTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC3, gpu::UINT8, gpu::RGB), 256, 2)); + _permutationNormalTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC3, gpu::NUINT8, gpu::RGB), 256, 2)); _permutationNormalTexture->assignStoredMip(0, _blueTexture->getTexelFormat(), sizeof(data), data); } return _permutationNormalTexture; @@ -98,7 +98,7 @@ const unsigned char OPAQUE_BLACK[] = { 0x00, 0x00, 0x00, 0xFF }; const gpu::TexturePointer& TextureCache::getWhiteTexture() { if (!_whiteTexture) { - _whiteTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA), 1, 1)); + _whiteTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, 1, 1)); _whiteTexture->assignStoredMip(0, _whiteTexture->getTexelFormat(), sizeof(OPAQUE_WHITE), OPAQUE_WHITE); } return _whiteTexture; @@ -106,7 +106,7 @@ const gpu::TexturePointer& TextureCache::getWhiteTexture() { const gpu::TexturePointer& TextureCache::getGrayTexture() { if (!_grayTexture) { - _grayTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA), 1, 1)); + _grayTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, 1, 1)); _grayTexture->assignStoredMip(0, _whiteTexture->getTexelFormat(), sizeof(OPAQUE_WHITE), OPAQUE_GRAY); } return _grayTexture; @@ -114,7 +114,7 @@ const gpu::TexturePointer& TextureCache::getGrayTexture() { const gpu::TexturePointer& TextureCache::getBlueTexture() { if (!_blueTexture) { - _blueTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA), 1, 1)); + _blueTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, 1, 1)); _blueTexture->assignStoredMip(0, _blueTexture->getTexelFormat(), sizeof(OPAQUE_BLUE), OPAQUE_BLUE); } return _blueTexture; @@ -122,7 +122,7 @@ const gpu::TexturePointer& TextureCache::getBlueTexture() { const gpu::TexturePointer& TextureCache::getBlackTexture() { if (!_blackTexture) { - _blackTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA), 1, 1)); + _blackTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, 1, 1)); _blackTexture->assignStoredMip(0, _whiteTexture->getTexelFormat(), sizeof(OPAQUE_BLACK), OPAQUE_BLACK); } return _blackTexture; @@ -151,11 +151,11 @@ NetworkTexturePointer TextureCache::getTexture(const QUrl& url, TextureType type /// Returns a texture version of an image file gpu::TexturePointer TextureCache::getImageTexture(const QString& path) { QImage image = QImage(path).mirrored(false, true); - gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::UINT8, gpu::RGB); - gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::UINT8, gpu::RGB); + gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::NUINT8, gpu::RGB); + gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::NUINT8, gpu::RGB); if (image.hasAlphaChannel()) { - formatGPU = gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA); - formatMip = gpu::Element(gpu::VEC4, gpu::UINT8, gpu::BGRA); + formatGPU = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); + formatMip = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::BGRA); } gpu::TexturePointer texture = gpu::TexturePointer( gpu::Texture::create2D(formatGPU, image.width(), image.height(), diff --git a/libraries/model/src/model/TextureMap.cpp b/libraries/model/src/model/TextureMap.cpp index 453bb17a4b..a86c7cdbec 100755 --- a/libraries/model/src/model/TextureMap.cpp +++ b/libraries/model/src/model/TextureMap.cpp @@ -121,11 +121,11 @@ gpu::Texture* TextureUsage::create2DTextureFromImage(const QImage& srcImage, con // bool isLinearRGB = true; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE); bool isLinearRGB = false; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE); - gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); - gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); + gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::NUINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); + gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::NUINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); if (image.hasAlphaChannel()) { - formatGPU = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::RGBA : gpu::SRGBA)); - formatMip = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::BGRA : gpu::SBGRA)); + formatGPU = gpu::Element(gpu::VEC4, gpu::NUINT8, (isLinearRGB ? gpu::RGBA : gpu::SRGBA)); + formatMip = gpu::Element(gpu::VEC4, gpu::NUINT8, (isLinearRGB ? gpu::BGRA : gpu::SBGRA)); } @@ -156,11 +156,11 @@ gpu::Texture* TextureUsage::createNormalTextureFromNormalImage(const QImage& src bool isLinearRGB = true; - gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); - gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); + gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::NUINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); + gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::NUINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); if (image.hasAlphaChannel()) { - formatGPU = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::RGBA : gpu::SRGBA)); - formatMip = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::BGRA : gpu::SBGRA)); + formatGPU = gpu::Element(gpu::VEC4, gpu::NUINT8, (isLinearRGB ? gpu::RGBA : gpu::SRGBA)); + formatMip = gpu::Element(gpu::VEC4, gpu::NUINT8, (isLinearRGB ? gpu::BGRA : gpu::SBGRA)); } theTexture = (gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR))); @@ -246,11 +246,11 @@ gpu::Texture* TextureUsage::createNormalTextureFromBumpImage(const QImage& srcIm // bool isLinearRGB = true; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE); bool isLinearRGB = true; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE); - gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); - gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); + gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::NUINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); + gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::NUINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); if (image.hasAlphaChannel()) { - formatGPU = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::RGBA : gpu::SRGBA)); - formatMip = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::BGRA : gpu::SBGRA)); + formatGPU = gpu::Element(gpu::VEC4, gpu::NUINT8, (isLinearRGB ? gpu::RGBA : gpu::SRGBA)); + formatMip = gpu::Element(gpu::VEC4, gpu::NUINT8, (isLinearRGB ? gpu::BGRA : gpu::SBGRA)); } @@ -368,11 +368,11 @@ gpu::Texture* TextureUsage::createCubeTextureFromImage(const QImage& srcImage, c // bool isLinearRGB = true; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE); bool isLinearRGB = false; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE); - gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); - gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); + gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::NUINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); + gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::NUINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); if (image.hasAlphaChannel()) { - formatGPU = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::RGBA : gpu::SRGBA)); - formatMip = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::BGRA : gpu::SBGRA)); + formatGPU = gpu::Element(gpu::VEC4, gpu::NUINT8, (isLinearRGB ? gpu::RGBA : gpu::SRGBA)); + formatMip = gpu::Element(gpu::VEC4, gpu::NUINT8, (isLinearRGB ? gpu::BGRA : gpu::SBGRA)); } @@ -589,13 +589,13 @@ gpu::Texture* TextureUsage::createLightmapTextureFromImage(const QImage& srcImag if ((image.width() > 0) && (image.height() > 0)) { // bool isLinearRGB = true; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE); - bool isLinearRGB = false; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE); + bool isLinearRGB = true; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE); - gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); - gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); + gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::NUINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); + gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::NUINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); if (image.hasAlphaChannel()) { - formatGPU = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::RGBA : gpu::SRGBA)); - formatMip = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::BGRA : gpu::SBGRA)); + formatGPU = gpu::Element(gpu::VEC4, gpu::NUINT8, (isLinearRGB ? gpu::RGBA : gpu::SRGBA)); + formatMip = gpu::Element(gpu::VEC4, gpu::NUINT8, (isLinearRGB ? gpu::BGRA : gpu::SBGRA)); } diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.slf b/libraries/procedural/src/procedural/ProceduralSkybox.slf index 382801f52d..8705278bee 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.slf +++ b/libraries/procedural/src/procedural/ProceduralSkybox.slf @@ -42,8 +42,8 @@ void main(void) { vec3 coord = normalize(_normal); vec3 texel = texture(cubeMap, coord).rgb; vec3 color = texel * _skybox._color.rgb; - vec3 pixel = pow(color, vec3(1.0/2.2)); // manual Gamma correction - _fragColor = vec4(pixel, 0.0); + // vec3 pixel = pow(color, vec3(1.0/2.2)); // manual Gamma correction + _fragColor = vec4(color, 0.0); #endif diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index 573146a0af..d3a5ff1e31 100755 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -62,7 +62,7 @@ void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 s } _fragColor0 = vec4(diffuse.rgb, 0.5); - _fragColor1 = vec4(bestFitNormal(normal), 1.0); + _fragColor1 = vec4(bestFitNormal(normal), 0.5); _fragColor2 = vec4(emissive, shininess / 128.0); } diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index c8996801f1..f1469a2a03 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -689,6 +689,7 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo locations->deferredTransformBuffer = program->getBuffers().findLocation("deferredTransformBuffer"); auto state = std::make_shared(); + state->setColorWriteMask(true, true, true, false); // Stencil test all the light passes for objects pixels only, not the background state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index 2d3884d81d..83ba8b6950 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -53,7 +53,7 @@ void FramebufferCache::createPrimaryFramebuffer() { _deferredFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); _deferredFramebufferDepthColor = gpu::FramebufferPointer(gpu::Framebuffer::create()); - auto colorFormat = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); + auto colorFormat = gpu::Element::COLOR_RGBA_32; auto width = _frameBufferSize.width(); auto height = _frameBufferSize.height(); @@ -87,8 +87,8 @@ void FramebufferCache::createPrimaryFramebuffer() { auto tex = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width * 0.5, height * 0.5, defaultSampler)); _selfieFramebuffer->setRenderBuffer(0, tex); - _lightingTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA), width, height, defaultSampler)); - //_lightingTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::SRGBA), width, height, defaultSampler)); + //_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)); _lightingFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); _lightingFramebuffer->setRenderBuffer(0, _lightingTexture); diff --git a/libraries/render-utils/src/SkyFromAtmosphere.slf b/libraries/render-utils/src/SkyFromAtmosphere.slf index c2a3635f07..10b39dc210 100755 --- a/libraries/render-utils/src/SkyFromAtmosphere.slf +++ b/libraries/render-utils/src/SkyFromAtmosphere.slf @@ -108,5 +108,6 @@ void main (void) vec3 finalColor = frontColor.rgb + fMiePhase * secondaryFrontColor.rgb; outFragColor.a = finalColor.b; - outFragColor.rgb = pow(finalColor.rgb, vec3(1.0/2.2)); + // outFragColor.rgb = pow(finalColor.rgb, vec3(1.0/2.2)); + outFragColor.rgb = finalColor.rgb; } diff --git a/libraries/render-utils/src/ToneMappingEffect.cpp b/libraries/render-utils/src/ToneMappingEffect.cpp index ac5bbc69e5..ea38884fac 100644 --- a/libraries/render-utils/src/ToneMappingEffect.cpp +++ b/libraries/render-utils/src/ToneMappingEffect.cpp @@ -45,10 +45,20 @@ void ToneMappingEffect::init() { out vec4 outFragColor; void main(void) { - outFragColor = texture(colorMap, varTexCoord0); + vec4 fragColor = texture(colorMap, varTexCoord0); // if (gl_FragCoord.x > 1000) { // Manually gamma correct from Ligthing BUffer to color buffer - outFragColor.xyz = pow( outFragColor.xyz , vec3(1.0 / 2.2) ); + // outFragColor.xyz = pow( fragColor.xyz , vec3(1.0 / 2.2) ); + + fragColor *= 4.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)); + + outFragColor = vec4(retColor, 1.0); // } } diff --git a/libraries/render-utils/src/text/Font.cpp b/libraries/render-utils/src/text/Font.cpp index 5587185ead..43202c29c2 100644 --- a/libraries/render-utils/src/text/Font.cpp +++ b/libraries/render-utils/src/text/Font.cpp @@ -198,11 +198,11 @@ void Font::read(QIODevice& in) { image = image.convertToFormat(QImage::Format_RGBA8888); - gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::UINT8, gpu::RGB); - gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::UINT8, gpu::RGB); + gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::NUINT8, gpu::RGB); + gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::NUINT8, gpu::RGB); if (image.hasAlphaChannel()) { - formatGPU = gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA); - formatMip = gpu::Element(gpu::VEC4, gpu::UINT8, gpu::BGRA); + formatGPU = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); + formatMip = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::BGRA); } _texture = gpu::TexturePointer(gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_POINT_MAG_LINEAR))); diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 73c4b7e22b..d0cdbc48bf 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -82,7 +82,7 @@ void avatarDataFromScriptValue(const QScriptValue &object, AvatarData* &out) { } Q_DECLARE_METATYPE(controller::InputController*) -static int inputControllerPointerId = qRegisterMetaType(); +//static int inputControllerPointerId = qRegisterMetaType(); QScriptValue inputControllerToScriptValue(QScriptEngine *engine, controller::InputController* const &in) { return engine->newQObject(in); From c74bbda663028c8ec621c899396899891931e5f4 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 10 Dec 2015 18:02:02 -0800 Subject: [PATCH 22/62] Nothing fancy --- libraries/render-utils/src/FramebufferCache.cpp | 6 +++--- libraries/render-utils/src/ToneMappingEffect.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index 83ba8b6950..e0ad3dedd2 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -88,9 +88,9 @@ void FramebufferCache::createPrimaryFramebuffer() { _selfieFramebuffer->setRenderBuffer(0, tex); //_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)); - _lightingFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); + //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)); + _lightingFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); _lightingFramebuffer->setRenderBuffer(0, _lightingTexture); _lightingFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); } diff --git a/libraries/render-utils/src/ToneMappingEffect.cpp b/libraries/render-utils/src/ToneMappingEffect.cpp index ea38884fac..1857d76cbf 100644 --- a/libraries/render-utils/src/ToneMappingEffect.cpp +++ b/libraries/render-utils/src/ToneMappingEffect.cpp @@ -50,7 +50,7 @@ void ToneMappingEffect::init() { // Manually gamma correct from Ligthing BUffer to color buffer // outFragColor.xyz = pow( fragColor.xyz , vec3(1.0 / 2.2) ); - fragColor *= 4.0; // Hardcoded Exposure Adjustment + 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); From 2bbd5d86b8f72e092c68aed2a0c7fa8bd88ecb2d Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 15 Dec 2015 09:46:18 -0800 Subject: [PATCH 23/62] cleaning indentation --- .../render-utils/src/RenderDeferredTask.cpp | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index d9b5c1caf6..5f9cb7b575 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -52,25 +52,21 @@ void ToneMappingDeferred::run(const SceneContextPointer& sceneContext, const Ren RenderDeferredTask::RenderDeferredTask() : Task() { // CPU only, create the list of renderedOpaques items _jobs.push_back(Job(new FetchItems::JobModel("FetchOpaque", - FetchItems( - [](const RenderContextPointer& context, int count) { - context->_numFeedOpaqueItems = count; - } - ) - ))); + FetchItems([](const RenderContextPointer& context, int count) { + context->_numFeedOpaqueItems = count; + }) + ))); _jobs.push_back(Job(new CullItemsOpaque::JobModel("CullOpaque", _jobs.back().getOutput()))); _jobs.push_back(Job(new DepthSortItems::JobModel("DepthSortOpaque", _jobs.back().getOutput()))); auto& renderedOpaques = _jobs.back().getOutput(); // CPU only, create the list of renderedTransparents items _jobs.push_back(Job(new FetchItems::JobModel("FetchTransparent", - FetchItems( - ItemFilter::Builder::transparentShape().withoutLayered(), - [](const RenderContextPointer& context, int count) { - context->_numFeedTransparentItems = count; - } - ) - ))); + FetchItems(ItemFilter::Builder::transparentShape().withoutLayered(), + [](const RenderContextPointer& context, int count) { + context->_numFeedTransparentItems = count; + }) + ))); _jobs.push_back(Job(new CullItemsTransparent::JobModel("CullTransparent", _jobs.back().getOutput()))); _jobs.push_back(Job(new DepthSortItems::JobModel("DepthSortTransparent", _jobs.back().getOutput(), DepthSortItems(false)))); auto& renderedTransparents = _jobs.back().getOutput(); From d2ebaef69e9c057bcd6cf4c0ba5e60dd688b141b Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 15 Dec 2015 18:18:42 -0800 Subject: [PATCH 24/62] 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 25/62] 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 26/62] 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 27/62] 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) { From c0faf978f84f4e8b5957234ac35fcd28bf89a735 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 16 Dec 2015 15:21:09 -0800 Subject: [PATCH 28/62] Introducing a setting for the tone curve --- .../render-utils/src/ToneMappingEffect.cpp | 48 ++++++++++++------- .../render-utils/src/ToneMappingEffect.h | 14 +++++- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/libraries/render-utils/src/ToneMappingEffect.cpp b/libraries/render-utils/src/ToneMappingEffect.cpp index 22c31a2459..29e5da6e2a 100644 --- a/libraries/render-utils/src/ToneMappingEffect.cpp +++ b/libraries/render-utils/src/ToneMappingEffect.cpp @@ -36,18 +36,28 @@ void ToneMappingEffect::init() { // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // - + struct ToneMappingParams { vec4 _exp_2powExp_s0_s1; + ivec4 _toneCurve_s0_s1_s2; }; + const float INV_GAMMA_22 = 1.0 / 2.2; + const int ToneCurveNone = 0; + const int ToneCurveGamma22 = 1; + const int ToneCurveReinhard = 2; + const int ToneCurveFilmic = 3; + uniform toneMappingParamsBuffer { ToneMappingParams params; }; float getTwoPowExposure() { return params._exp_2powExp_s0_s1.y; } - + int getToneCurve() { + return params._toneCurve_s0_s1_s2.x; + } + uniform sampler2D colorMap; in vec2 varTexCoord0; @@ -56,25 +66,26 @@ void ToneMappingEffect::init() { void main(void) { vec4 fragColorRaw = textureLod(colorMap, varTexCoord0, 0); vec3 fragColor = fragColorRaw.xyz; - -/* vec4 fragColorAverage = textureLod(colorMap, varTexCoord0, 10); +/* + vec4 fragColorAverage = textureLod(colorMap, varTexCoord0, 10); float averageIntensity = length(fragColorAverage.xyz); - - vec3 fragColor = fragColorRaw.xyz / averageIntensity; + fragColor /= averageIntensity; */ - fragColor *= getTwoPowExposure(); + vec3 srcColor = fragColor * getTwoPowExposure(); + int toneCurve = getToneCurve(); + vec3 tonedColor = srcColor; + if (toneCurve == ToneCurveFilmic) { + vec3 x = max(vec3(0.0), srcColor-0.004); + 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)); + } else if (toneCurve == ToneCurveGamma22) { + tonedColor = pow(srcColor, vec3(INV_GAMMA_22)); + } // else None toned = src - // Manually gamma correct from Ligthing BUffer to color buffer - // 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)); - - outFragColor = vec4(retColor, 1.0); + outFragColor = vec4(tonedColor, 1.0); } )SCRIBE"; @@ -96,6 +107,9 @@ void ToneMappingEffect::setExposure(float exposure) { _parametersBuffer.edit()._twoPowExposure = pow(2.0, exposure); } +void ToneMappingEffect::setToneCurve(ToneCurve curve) { + _parametersBuffer.edit()._toneCurve = curve; +} void ToneMappingEffect::render(RenderArgs* args) { if (!_blitLightBuffer) { diff --git a/libraries/render-utils/src/ToneMappingEffect.h b/libraries/render-utils/src/ToneMappingEffect.h index be9664ddd9..20ee9024cf 100644 --- a/libraries/render-utils/src/ToneMappingEffect.h +++ b/libraries/render-utils/src/ToneMappingEffect.h @@ -30,6 +30,16 @@ public: void setExposure(float exposure); float getExposure() const { return _parametersBuffer.get()._exposure; } + // Different tone curve available + enum ToneCurve { + None = 0, + Gamma22, + Reinhard, + Filmic, + }; + void setToneCurve(ToneCurve curve); + ToneCurve getToneCurve() const { return (ToneCurve)_parametersBuffer.get()._toneCurve; } + private: gpu::PipelinePointer _blitLightBuffer; @@ -39,7 +49,9 @@ private: public: float _exposure = 0.0f; float _twoPowExposure = 1.0f; - glm::vec2 spare; + glm::vec2 spareA; + int _toneCurve = Filmic; + glm::vec3 spareB; Parameters() {} }; From 1b1365fd403bb661e39606df0d2d5930611b7127 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 16 Dec 2015 16:32:53 -0800 Subject: [PATCH 29/62] Exposing the tone curve in the js api --- interface/src/Application.cpp | 1 + .../render-utils/src/RenderDeferredTask.cpp | 18 ++++++++++++- .../render-utils/src/RenderDeferredTask.h | 3 +++ libraries/render/src/render/Engine.h | 1 + .../src/SceneScriptingInterface.cpp | 27 +++++++++++++++++++ .../src/SceneScriptingInterface.h | 7 ++++- 6 files changed, 55 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 9a8373282b..aa0c0fa8c6 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3703,6 +3703,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se renderContext._fxaaStatus = Menu::getInstance()->isOptionChecked(MenuOption::Antialiasing); renderContext._toneMappingExposure = sceneInterface->getEngineToneMappingExposure(); + renderContext._toneMappingToneCurve = sceneInterface->getEngineToneMappingToneCurveValue(); renderArgs->_shouldRender = LODManager::shouldRender; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index ef95876f11..5423d928a7 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -166,6 +166,7 @@ void RenderDeferredTask::run(const SceneContextPointer& sceneContext, const Rend setAntialiasingStatus(renderContext->_fxaaStatus); setToneMappingExposure(renderContext->_toneMappingExposure); + setToneMappingToneCurve(renderContext->_toneMappingToneCurve); renderContext->args->_context->syncCache(); @@ -403,8 +404,23 @@ void RenderDeferredTask::setToneMappingExposure(float exposure) { float RenderDeferredTask::getToneMappingExposure() const { if (_toneMappingJobIndex >= 0) { - _jobs[_toneMappingJobIndex].get()._toneMappingEffect.getExposure(); + return _jobs[_toneMappingJobIndex].get()._toneMappingEffect.getExposure(); } else { return 0.0f; } } + +void RenderDeferredTask::setToneMappingToneCurve(int toneCurve) { + if (_toneMappingJobIndex >= 0) { + _jobs[_toneMappingJobIndex].edit()._toneMappingEffect.setToneCurve((ToneMappingEffect::ToneCurve)toneCurve); + } +} + +int RenderDeferredTask::getToneMappingToneCurve() const { + if (_toneMappingJobIndex >= 0) { + return _jobs[_toneMappingJobIndex].get()._toneMappingEffect.getToneCurve(); + } else { + return 0.0f; + } +} + diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index ea99c9f12e..b84db31a26 100755 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -134,6 +134,9 @@ public: void setToneMappingExposure(float exposure); float getToneMappingExposure() const; + void setToneMappingToneCurve(int toneCurve); + int getToneMappingToneCurve() const; + virtual void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext); diff --git a/libraries/render/src/render/Engine.h b/libraries/render/src/render/Engine.h index c219b87f40..abfef03039 100644 --- a/libraries/render/src/render/Engine.h +++ b/libraries/render/src/render/Engine.h @@ -62,6 +62,7 @@ public: bool _fxaaStatus = false; float _toneMappingExposure = 0.0; + int _toneMappingToneCurve = 3; RenderContext() {} }; diff --git a/libraries/script-engine/src/SceneScriptingInterface.cpp b/libraries/script-engine/src/SceneScriptingInterface.cpp index 59d2765659..3e22a9e929 100644 --- a/libraries/script-engine/src/SceneScriptingInterface.cpp +++ b/libraries/script-engine/src/SceneScriptingInterface.cpp @@ -167,3 +167,30 @@ void SceneScriptingInterface::clearEngineCounters() { _numFeedOverlay3DItems = 0; _numDrawnOverlay3DItems = 0; } + + +void SceneScriptingInterface::setEngineToneMappingToneCurve(const QString& toneCurve) { + if (toneCurve == QString("None")) { + _engineToneMappingToneCurve = 0; + } else if (toneCurve == QString("Gamma22")) { + _engineToneMappingToneCurve = 1; + } else if (toneCurve == QString("Reinhard")) { + _engineToneMappingToneCurve = 2; + } else if (toneCurve == QString("Filmic")) { + _engineToneMappingToneCurve = 3; + } +} +QString SceneScriptingInterface::getEngineToneMappingToneCurve() const { + switch (_engineToneMappingToneCurve) { + case 0: + return QString("None"); + case 1: + return QString("Gamma22"); + case 2: + return QString("Reinhard"); + case 3: + return QString("Filmic"); + default: + return QString("Filmic"); + }; +} \ No newline at end of file diff --git a/libraries/script-engine/src/SceneScriptingInterface.h b/libraries/script-engine/src/SceneScriptingInterface.h index 875a2a1b8f..246f624b08 100644 --- a/libraries/script-engine/src/SceneScriptingInterface.h +++ b/libraries/script-engine/src/SceneScriptingInterface.h @@ -119,7 +119,11 @@ public: Q_INVOKABLE bool doEngineDisplayHitEffect() { return _drawHitEffect; } Q_INVOKABLE void setEngineToneMappingExposure(float exposure) { _engineToneMappingExposure = exposure; } - Q_INVOKABLE float getEngineToneMappingExposure() { return _engineToneMappingExposure; } + Q_INVOKABLE float getEngineToneMappingExposure() const { return _engineToneMappingExposure; } + + Q_INVOKABLE void setEngineToneMappingToneCurve(const QString& curve); + Q_INVOKABLE QString getEngineToneMappingToneCurve() const; + int getEngineToneMappingToneCurveValue() const { return _engineToneMappingToneCurve; } signals: void shouldRenderAvatarsChanged(bool shouldRenderAvatars); @@ -158,6 +162,7 @@ protected: bool _drawHitEffect = false; float _engineToneMappingExposure = 0.0f; + int _engineToneMappingToneCurve = 3; }; #endif // hifi_SceneScriptingInterface_h From 7bc815448e025d677c94a750fb6c184ca9fe94c6 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 16 Dec 2015 18:14:43 -0800 Subject: [PATCH 30/62] The material colors for diffuse and emissive are now gamma corrected by default --- libraries/model/src/model/Material.cpp | 8 ++++---- libraries/model/src/model/Material.h | 27 ++++++++++++++------------ libraries/shared/src/ColorUtils.h | 16 +++++++++++++++ 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/libraries/model/src/model/Material.cpp b/libraries/model/src/model/Material.cpp index c2ff828af3..1d0f6ee5d9 100755 --- a/libraries/model/src/model/Material.cpp +++ b/libraries/model/src/model/Material.cpp @@ -44,9 +44,9 @@ Material& Material::operator= (const Material& material) { Material::~Material() { } -void Material::setDiffuse(const Color& diffuse) { +void Material::setDiffuse(const Color& diffuse, bool isSRGB) { _key.setDiffuse(glm::any(glm::greaterThan(diffuse, Color(0.0f)))); - _schemaBuffer.edit()._diffuse = diffuse; + _schemaBuffer.edit()._diffuse = (isSRGB ? ColorUtils::toLinearVec3(diffuse) : diffuse); } void Material::setMetallic(float metallic) { @@ -54,9 +54,9 @@ void Material::setMetallic(float metallic) { _schemaBuffer.edit()._metallic = glm::vec3(metallic); } -void Material::setEmissive(const Color& emissive) { +void Material::setEmissive(const Color& emissive, bool isSRGB) { _key.setEmissive(glm::any(glm::greaterThan(emissive, Color(0.0f)))); - _schemaBuffer.edit()._emissive = emissive; + _schemaBuffer.edit()._emissive = (isSRGB ? ColorUtils::toLinearVec3(emissive) : emissive); } void Material::setGloss(float gloss) { diff --git a/libraries/model/src/model/Material.h b/libraries/model/src/model/Material.h index b0725d9908..bd1d45c7ed 100755 --- a/libraries/model/src/model/Material.h +++ b/libraries/model/src/model/Material.h @@ -14,7 +14,7 @@ #include #include -#include +#include #include @@ -219,28 +219,31 @@ public: virtual ~Material(); const MaterialKey& getKey() const { return _key; } - - const Color& getEmissive() const { return _schemaBuffer.get()._emissive; } - const Color& getDiffuse() const { return _schemaBuffer.get()._diffuse; } - float getMetallic() const { return _schemaBuffer.get()._metallic.x; } - float getGloss() const { return _schemaBuffer.get()._gloss; } - float getOpacity() const { return _schemaBuffer.get()._opacity; } - void setEmissive(const Color& emissive); - void setDiffuse(const Color& diffuse); + void setEmissive(const Color& emissive, bool isSRGB = true); + const Color& getEmissive(bool SRGB = true) const { return (SRGB ? ColorUtils::toGamma22Vec3(_schemaBuffer.get()._emissive) : _schemaBuffer.get()._emissive); } + + void setDiffuse(const Color& diffuse, bool isSRGB = true); + const Color& getDiffuse(bool SRGB = true) const { return (SRGB ? ColorUtils::toGamma22Vec3(_schemaBuffer.get()._diffuse) : _schemaBuffer.get()._diffuse); } + void setMetallic(float metallic); + float getMetallic() const { return _schemaBuffer.get()._metallic.x; } + void setGloss(float gloss); + float getGloss() const { return _schemaBuffer.get()._gloss; } + void setOpacity(float opacity); + float getOpacity() const { return _schemaBuffer.get()._opacity; } // Schema to access the attribute values of the material class Schema { public: - Color _diffuse{0.5f}; + glm::vec3 _diffuse{ 0.5f }; float _opacity{1.f}; - Color _metallic{0.03f}; + glm::vec3 _metallic{ 0.03f }; float _gloss{0.1f}; - Color _emissive{0.0f}; + glm::vec3 _emissive{ 0.0f }; float _spare0{0.0f}; glm::vec4 _spareVec4{0.0f}; // for alignment beauty, Material size == Mat4x4 diff --git a/libraries/shared/src/ColorUtils.h b/libraries/shared/src/ColorUtils.h index 1ef8420cd7..b47e7c3a98 100644 --- a/libraries/shared/src/ColorUtils.h +++ b/libraries/shared/src/ColorUtils.h @@ -20,6 +20,10 @@ class ColorUtils { public: inline static glm::vec3 toVec3(const xColor& color); + + // Convert from gamma 2.2 space to linear + inline static glm::vec3 toLinearVec3(const glm::vec3& srgb); + inline static glm::vec3 toGamma22Vec3(const glm::vec3& linear); }; inline glm::vec3 ColorUtils::toVec3(const xColor& color) { @@ -27,4 +31,16 @@ inline glm::vec3 ColorUtils::toVec3(const xColor& color) { return glm::vec3(color.red * ONE_OVER_255, color.green * ONE_OVER_255, color.blue * ONE_OVER_255); } +inline glm::vec3 ColorUtils::toLinearVec3(const glm::vec3& srgb) { + const float GAMMA_22 = 2.2f; + // Couldn't find glm::pow(vec3, vec3) ? so did it myself... + return glm::vec3(glm::pow(srgb.x, GAMMA_22), glm::pow(srgb.y, GAMMA_22), glm::pow(srgb.z, GAMMA_22)); +} + +inline glm::vec3 ColorUtils::toGamma22Vec3(const glm::vec3& linear) { + const float INV_GAMMA_22 = 1.0f / 2.2f; + // Couldn't find glm::pow(vec3, vec3) ? so did it myself... + return glm::vec3(glm::pow(linear.x, INV_GAMMA_22), glm::pow(linear.y, INV_GAMMA_22), glm::pow(linear.z, INV_GAMMA_22)); +} + #endif // hifi_ColorUtils_h \ No newline at end of file From 8d4d0d4e9a849f50109d8cb670bed3d2195994c4 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 17 Dec 2015 10:08:40 -0800 Subject: [PATCH 31/62] FIxing the bad returned value per reference --- libraries/model/src/model/Material.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/model/src/model/Material.h b/libraries/model/src/model/Material.h index bd1d45c7ed..cb5a285dba 100755 --- a/libraries/model/src/model/Material.h +++ b/libraries/model/src/model/Material.h @@ -221,10 +221,10 @@ public: const MaterialKey& getKey() const { return _key; } void setEmissive(const Color& emissive, bool isSRGB = true); - const Color& getEmissive(bool SRGB = true) const { return (SRGB ? ColorUtils::toGamma22Vec3(_schemaBuffer.get()._emissive) : _schemaBuffer.get()._emissive); } + Color getEmissive(bool SRGB = true) const { return (SRGB ? ColorUtils::toGamma22Vec3(_schemaBuffer.get()._emissive) : _schemaBuffer.get()._emissive); } void setDiffuse(const Color& diffuse, bool isSRGB = true); - const Color& getDiffuse(bool SRGB = true) const { return (SRGB ? ColorUtils::toGamma22Vec3(_schemaBuffer.get()._diffuse) : _schemaBuffer.get()._diffuse); } + Color getDiffuse(bool SRGB = true) const { return (SRGB ? ColorUtils::toGamma22Vec3(_schemaBuffer.get()._diffuse) : _schemaBuffer.get()._diffuse); } void setMetallic(float metallic); float getMetallic() const { return _schemaBuffer.get()._metallic.x; } From b271542b73b0446e656e016e829adfd2d13c50af Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Mon, 7 Dec 2015 12:06:49 -0800 Subject: [PATCH 32/62] Save DebugMode to setting, restore on script start --- examples/utilities/tools/renderEngineDebug.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/utilities/tools/renderEngineDebug.js b/examples/utilities/tools/renderEngineDebug.js index 2c0dc352b4..5e4eded640 100755 --- a/examples/utilities/tools/renderEngineDebug.js +++ b/examples/utilities/tools/renderEngineDebug.js @@ -1,6 +1,7 @@ // -// SunLightExample.js -// examples +// renderEngineDebug.js +// examples/utilities/tools +// // Sam Gateau // Copyright 2015 High Fidelity, Inc. // @@ -12,6 +13,7 @@ Script.include("cookies.js"); var MENU = "Developer>Render>Debug Deferred Buffer"; var ACTIONS = ["Off", "Diffuse", "Alpha", "Specular", "Roughness", "Normal", "Depth", "Lighting", "Custom"]; +var SETTINGS_KEY = "EngineDebugScript.DebugMode"; Number.prototype.clamp = function(min, max) { return Math.min(Math.max(this, min), max); @@ -69,6 +71,9 @@ var overlaysCounter = new CounterWidget(panel, "Overlays", ); var resizing = false; +var previousMode = Settings.getValue(SETTINGS_KEY, -1); +Menu.addActionGroup(MENU, ACTIONS, ACTIONS[previousMode + 1]); +Scene.setEngineDeferredDebugMode(previousMode); Scene.setEngineDeferredDebugSize({ x: 0.0, y: -1.0, z: 1.0, w: 1.0 }); // Reset to default size function setEngineDeferredDebugSize(eventX) { @@ -152,11 +157,11 @@ Controller.mousePressEvent.connect(mousePressEvent); Controller.mouseReleaseEvent.connect(mouseReleaseEvent); Menu.menuItemEvent.connect(menuItemEvent); -Menu.addActionGroup(MENU, ACTIONS, ACTIONS[0]); function scriptEnding() { panel.destroy(); Menu.removeActionGroup(MENU); + Settings.setValue(SETTINGS_KEY, Scene.getEngineDeferredDebugMode()); Scene.setEngineDeferredDebugMode(-1); Scene.setEngineDeferredDebugSize({ x: 0.0, y: -1.0, z: 1.0, w: 1.0 }); // Reset to default size } From 06d7de7106c4b87e0f5fd83d840a58135acdf3a4 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Mon, 7 Dec 2015 15:16:37 -0800 Subject: [PATCH 33/62] Make Shader interface take more consts --- libraries/gpu/src/gpu/Shader.cpp | 4 ++-- libraries/gpu/src/gpu/Shader.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/gpu/src/gpu/Shader.cpp b/libraries/gpu/src/gpu/Shader.cpp index ddb3a0d755..74b7734618 100755 --- a/libraries/gpu/src/gpu/Shader.cpp +++ b/libraries/gpu/src/gpu/Shader.cpp @@ -23,7 +23,7 @@ Shader::Shader(Type type, const Source& source): { } -Shader::Shader(Type type, Pointer& vertex, Pointer& pixel): +Shader::Shader(Type type, const Pointer& vertex, const Pointer& pixel): _type(type) { _shaders.resize(2); @@ -44,7 +44,7 @@ Shader::Pointer Shader::createPixel(const Source& source) { return Pointer(new Shader(PIXEL, source)); } -Shader::Pointer Shader::createProgram(Pointer& vertexShader, Pointer& pixelShader) { +Shader::Pointer Shader::createProgram(const Pointer& vertexShader, const Pointer& pixelShader) { if (vertexShader && vertexShader->getType() == VERTEX && pixelShader && pixelShader->getType() == PIXEL) { return Pointer(new Shader(PROGRAM, vertexShader, pixelShader)); diff --git a/libraries/gpu/src/gpu/Shader.h b/libraries/gpu/src/gpu/Shader.h index bceb00c71e..b737a42e12 100755 --- a/libraries/gpu/src/gpu/Shader.h +++ b/libraries/gpu/src/gpu/Shader.h @@ -111,7 +111,7 @@ public: static Pointer createVertex(const Source& source); static Pointer createPixel(const Source& source); - static Pointer createProgram(Pointer& vertexShader, Pointer& pixelShader); + static Pointer createProgram(const Pointer& vertexShader, const Pointer& pixelShader); ~Shader(); @@ -157,7 +157,7 @@ public: protected: Shader(Type type, const Source& source); - Shader(Type type, Pointer& vertex, Pointer& pixel); + Shader(Type type, const Pointer& vertex, const Pointer& pixel); Shader(const Shader& shader); // deep copy of the sysmem shader Shader& operator=(const Shader& shader); // deep copy of the sysmem texture From 9d6618c341236d81d12a4153baa09a82fc4beca8 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Mon, 7 Dec 2015 15:17:03 -0800 Subject: [PATCH 34/62] Cleanup DebugDeferredBuffer code --- examples/utilities/tools/renderEngineDebug.js | 1 - .../render-utils/src/DebugDeferredBuffer.cpp | 115 ++++++++---------- .../render-utils/src/DebugDeferredBuffer.h | 10 +- .../src/debug_deferred_buffer.slf | 6 +- 4 files changed, 57 insertions(+), 75 deletions(-) diff --git a/examples/utilities/tools/renderEngineDebug.js b/examples/utilities/tools/renderEngineDebug.js index 5e4eded640..5e89bff53b 100755 --- a/examples/utilities/tools/renderEngineDebug.js +++ b/examples/utilities/tools/renderEngineDebug.js @@ -90,7 +90,6 @@ function menuItemEvent(menuItem) { var index = ACTIONS.indexOf(menuItem); if (index >= 0) { Scene.setEngineDeferredDebugMode(index - 1); - print(menuItem); } } diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index 169ae0b58e..2046a48d4a 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -11,8 +11,6 @@ #include "DebugDeferredBuffer.h" -#include - #include #include #include @@ -31,73 +29,62 @@ enum Slots { Normal, Specular, Depth, - Lighting, - - NUM_SLOTS + Lighting }; -static const std::array SLOT_NAMES {{ - "diffuseMap", - "normalMap", - "specularMap", - "depthMap", - "lightingMap" -}}; -static const std::string COMPUTE_PLACEHOLDER { "/*COMPUTE_PLACEHOLDER*/" }; // required -static const std::string FUNCTIONS_PLACEHOLDER { "/*FUNCTIONS_PLACEHOLDER*/" }; // optional - -std::string DebugDeferredBuffer::getCode(Modes mode) { +std::string DebugDeferredBuffer::getShaderSourceCode(Modes mode) { switch (mode) { - case DiffuseMode: { - 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: { - QString code = "return vec4(vec3(texture(%1, uv).a), 1.0);"; - return code.arg(SLOT_NAMES[Diffuse].c_str()).toStdString(); - } - case SpecularMode: { - QString code = "return vec4(texture(%1, uv).xyz, 1.0);"; - return code.arg(SLOT_NAMES[Specular].c_str()).toStdString(); - } - case RoughnessMode: { - QString code = "return vec4(vec3(texture(%1, uv).a), 1.0);"; - return code.arg(SLOT_NAMES[Specular].c_str()).toStdString(); - } - case NormalMode: { - QString code = "return vec4(texture(%1, uv).xyz, 1.0);"; - return code.arg(SLOT_NAMES[Normal].c_str()).toStdString(); - } - case DepthMode: { - QString code = "return vec4(vec3(texture(%1, uv).x), 1.0);"; - return code.arg(SLOT_NAMES[Depth].c_str()).toStdString(); - } - case LightingMode: { - 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 DiffuseMode: + return "vec4 getFragmentColor() { return vec4(pow(texture(diffuseMap, uv).xyz, vec3(1.0 / 2.2)), 1.0); }"; + case AlphaMode: + return "vec4 getFragmentColor() { return vec4(vec3(texture(diffuseMap, uv).a), 1.0); }"; + case SpecularMode: + return "vec4 getFragmentColor() { return vec4(texture(specularMap, uv).xyz, 1.0); }"; + case RoughnessMode: + return "vec4 getFragmentColor() { return vec4(vec3(texture(specularMap, uv).a), 1.0); }"; + case NormalMode: + return "vec4 getFragmentColor() { return vec4(texture(normalMap, uv).xyz, 1.0); }"; + case DepthMode: + return "vec4 getFragmentColor() { return vec4(vec3(texture(depthMap, uv).x), 1.0); }"; + case LightingMode: + return "vec4 getFragmentColor() { return vec4(pow(texture(lightingMap, uv).xyz, vec3(1.0 / 2.2)), 1.0); }"; case CustomMode: - return std::string("return vec4(1.0);"); - case NUM_MODES: - Q_UNIMPLEMENTED(); - return std::string("return vec4(1.0);"); + return "vec4 getFragmentColor() { return vec4(1.0); }"; } } +bool DebugDeferredBuffer::pipelineNeedsUpdate(Modes mode) const { + if (mode != CustomMode) { + return !_pipelines[mode]; + } + + + + return true; +} + const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(Modes mode) { - if (!_pipelines[mode]) { - std::string fragmentShader = debug_deferred_buffer_frag; - fragmentShader.replace(fragmentShader.find(COMPUTE_PLACEHOLDER), COMPUTE_PLACEHOLDER.size(), - getCode(mode)); + if (pipelineNeedsUpdate(mode)) { + static const std::string VERTEX_SHADER { debug_deferred_buffer_vert }; + static const std::string FRAGMENT_SHADER { debug_deferred_buffer_frag }; + static const std::string SOURCE_PLACEHOLDER { "//SOURCE_PLACEHOLDER" }; + static const auto SOURCE_PLACEHOLDER_INDEX = FRAGMENT_SHADER.find(SOURCE_PLACEHOLDER); + Q_ASSERT_X(SOURCE_PLACEHOLDER_INDEX != std::string::npos, Q_FUNC_INFO, "Could not find source placeholder"); - auto vs = gpu::ShaderPointer(gpu::Shader::createVertex({ debug_deferred_buffer_vert })); - auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(fragmentShader)); - auto program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps)); + auto bakedFragmentShader = FRAGMENT_SHADER; + bakedFragmentShader.replace(SOURCE_PLACEHOLDER_INDEX, SOURCE_PLACEHOLDER.size(), + getShaderSourceCode(mode)); + + const auto vs = gpu::Shader::createVertex(VERTEX_SHADER); + const auto ps = gpu::Shader::createPixel(bakedFragmentShader); + const auto program = gpu::Shader::createProgram(vs, ps); gpu::Shader::BindingSet slotBindings; - for (int slot = 0; slot < NUM_SLOTS; ++slot) { - slotBindings.insert(gpu::Shader::Binding(SLOT_NAMES[slot], slot)); - } + slotBindings.insert(gpu::Shader::Binding("diffuseMap", Diffuse)); + slotBindings.insert(gpu::Shader::Binding("normalMap", Normal)); + slotBindings.insert(gpu::Shader::Binding("specularMap", Specular)); + slotBindings.insert(gpu::Shader::Binding("depthMap", Depth)); + slotBindings.insert(gpu::Shader::Binding("lightingMap", Lighting)); gpu::Shader::makeProgram(*program, slotBindings); // Good to go add the brand new pipeline @@ -110,10 +97,10 @@ const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(Modes mode) { void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { assert(renderContext->args); assert(renderContext->args->_viewFrustum); - RenderArgs* args = renderContext->args; + const RenderArgs* args = renderContext->args; gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { - auto geometryBuffer = DependencyManager::get(); - auto framebufferCache = DependencyManager::get(); + const auto geometryBuffer = DependencyManager::get(); + const auto framebufferCache = DependencyManager::get(); glm::mat4 projMat; @@ -132,9 +119,9 @@ void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const Ren batch.setResourceTexture(Depth, framebufferCache->getPrimaryDepthTexture()); batch.setResourceTexture(Lighting, framebufferCache->getLightingTexture()); - glm::vec4 color(1.0f, 1.0f, 1.0f, 1.0f); - glm::vec2 bottomLeft(renderContext->_deferredDebugSize.x, renderContext->_deferredDebugSize.y); - glm::vec2 topRight(renderContext->_deferredDebugSize.z, renderContext->_deferredDebugSize.w); + const glm::vec4 color(1.0f, 1.0f, 1.0f, 1.0f); + const glm::vec2 bottomLeft(renderContext->_deferredDebugSize.x, renderContext->_deferredDebugSize.y); + const glm::vec2 topRight(renderContext->_deferredDebugSize.z, renderContext->_deferredDebugSize.w); geometryBuffer->renderQuad(batch, bottomLeft, topRight, color); }); } \ No newline at end of file diff --git a/libraries/render-utils/src/DebugDeferredBuffer.h b/libraries/render-utils/src/DebugDeferredBuffer.h index 8628d9e21e..144a72571c 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.h +++ b/libraries/render-utils/src/DebugDeferredBuffer.h @@ -21,7 +21,7 @@ public: void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext); private: - enum Modes : int { + enum Modes : uint8_t { DiffuseMode = 0, AlphaMode, SpecularMode, @@ -29,15 +29,15 @@ private: NormalMode, DepthMode, LightingMode, - CustomMode, - NUM_MODES + CustomMode // Needs to stay last }; + bool pipelineNeedsUpdate(Modes mode) const; const gpu::PipelinePointer& getPipeline(Modes mode); - std::string getCode(Modes mode); + std::string getShaderSourceCode(Modes mode); - std::array _pipelines; + std::array _pipelines; }; #endif // hifi_DebugDeferredBuffer_h \ No newline at end of file diff --git a/libraries/render-utils/src/debug_deferred_buffer.slf b/libraries/render-utils/src/debug_deferred_buffer.slf index d8ff6e71a9..375972cdc3 100644 --- a/libraries/render-utils/src/debug_deferred_buffer.slf +++ b/libraries/render-utils/src/debug_deferred_buffer.slf @@ -17,11 +17,7 @@ in vec2 uv; out vec4 outFragColor; -/*FUNCTIONS_PLACEHOLDER*/ - -vec4 getFragmentColor() { - /*COMPUTE_PLACEHOLDER*/ -} +//SOURCE_PLACEHOLDER void main(void) { outFragColor = getFragmentColor(); From d8a389ff925f795ad364e7e1f425b0784af65955 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 16 Dec 2015 17:20:51 -0800 Subject: [PATCH 35/62] First cut at custom pipelines --- libraries/render-utils/src/DebugDeferredBuffer.cpp | 14 +++++++++++--- libraries/render-utils/src/DebugDeferredBuffer.h | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index 2046a48d4a..7dbeddd07a 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -11,6 +11,8 @@ #include "DebugDeferredBuffer.h" +#include + #include #include #include @@ -32,6 +34,14 @@ enum Slots { Lighting }; +static std::string getFileContent(std::string fileName, std::string defaultContent = std::string()) { + QFile customFile(QString::fromStdString(fileName)); + if (customFile.open(QIODevice::ReadOnly)) { + return customFile.readAll().toStdString(); + } + return defaultContent; +} + std::string DebugDeferredBuffer::getShaderSourceCode(Modes mode) { switch (mode) { case DiffuseMode: @@ -49,7 +59,7 @@ std::string DebugDeferredBuffer::getShaderSourceCode(Modes mode) { case LightingMode: return "vec4 getFragmentColor() { return vec4(pow(texture(lightingMap, uv).xyz, vec3(1.0 / 2.2)), 1.0); }"; case CustomMode: - return "vec4 getFragmentColor() { return vec4(1.0); }"; + return getFileContent(CUSTOM_FILE, "vec4 getFragmentColor() { return vec4(1.0); }"); } } @@ -58,8 +68,6 @@ bool DebugDeferredBuffer::pipelineNeedsUpdate(Modes mode) const { return !_pipelines[mode]; } - - return true; } diff --git a/libraries/render-utils/src/DebugDeferredBuffer.h b/libraries/render-utils/src/DebugDeferredBuffer.h index 144a72571c..a0df42c05a 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.h +++ b/libraries/render-utils/src/DebugDeferredBuffer.h @@ -33,6 +33,8 @@ private: CustomMode // Needs to stay last }; + const std::string CUSTOM_FILE { "/Users/clement/Desktop/custom.slh" }; + bool pipelineNeedsUpdate(Modes mode) const; const gpu::PipelinePointer& getPipeline(Modes mode); std::string getShaderSourceCode(Modes mode); From f41ca9fc50752913984400514cc15aab32f692d5 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 17 Dec 2015 15:13:09 -0800 Subject: [PATCH 36/62] More custom debug work --- .../render-utils/src/DebugDeferredBuffer.cpp | 115 +++++++++++++++--- .../render-utils/src/DebugDeferredBuffer.h | 21 +++- 2 files changed, 111 insertions(+), 25 deletions(-) diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index 7dbeddd07a..6bdfbb57ff 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -34,56 +34,119 @@ enum Slots { Lighting }; +static const std::string DEEFAULT_DIFFUSE_SHADER { + "vec4 getFragmentColor() {" + " return vec4(pow(texture(diffuseMap, uv).xyz, vec3(1.0 / 2.2)), 1.0);" + " }" +}; +static const std::string DEEFAULT_ALPHA_SHADER { + "vec4 getFragmentColor() {" + " return vec4(vec3(texture(diffuseMap, uv).a), 1.0);" + " }" +}; +static const std::string DEEFAULT_SPECULAR_SHADER { + "vec4 getFragmentColor() {" + " return vec4(texture(specularMap, uv).xyz, 1.0);" + " }" +}; +static const std::string DEEFAULT_ROUGHNESS_SHADER { + "vec4 getFragmentColor() {" + " return vec4(vec3(texture(specularMap, uv).a), 1.0);" + " }" +}; +static const std::string DEEFAULT_NORMAL_SHADER { + "vec4 getFragmentColor() {" + " return vec4(texture(normalMap, uv).xyz, 1.0);" + " }" +}; +static const std::string DEEFAULT_DEPTH_SHADER { + "vec4 getFragmentColor() {" + " return vec4(vec3(texture(depthMap, uv).x), 1.0);" + " }" +}; +static const std::string DEEFAULT_LIGHTING_SHADER { + "vec4 getFragmentColor() {" + " return vec4(pow(texture(lightingMap, uv).xyz, vec3(1.0 / 2.2)), 1.0);" + " }" +}; +static const std::string DEEFAULT_CUSTOM_SHADER { + "vec4 getFragmentColor() {" + " return vec4(1.0, 0.0, 0.0, 1.0);" + " }" +}; + static std::string getFileContent(std::string fileName, std::string defaultContent = std::string()) { - QFile customFile(QString::fromStdString(fileName)); + QFile customFile(QUrl(QString::fromStdString(fileName)).toLocalFile()); if (customFile.open(QIODevice::ReadOnly)) { return customFile.readAll().toStdString(); } + qWarning() << "DebugDeferredBuffer::getFileContent(): Could not open" + << QUrl(QString::fromStdString(fileName)).toLocalFile(); return defaultContent; } -std::string DebugDeferredBuffer::getShaderSourceCode(Modes mode) { +#include // TODO REMOVE: Temporary until UI +DebugDeferredBuffer::DebugDeferredBuffer() { + // TODO REMOVE: Temporary until UI + static const auto DESKTOP_PATH = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); + static const auto CUSTOM_FILE = "file://" + DESKTOP_PATH.toStdString() + "/custom.slh"; + CustomPipeline pipeline; + pipeline.info = QFileInfo(DESKTOP_PATH + "/custom.slh"); + _customPipelines.emplace(CUSTOM_FILE, pipeline); +} + +std::string DebugDeferredBuffer::getShaderSourceCode(Modes mode, std::string customFile) { switch (mode) { case DiffuseMode: - return "vec4 getFragmentColor() { return vec4(pow(texture(diffuseMap, uv).xyz, vec3(1.0 / 2.2)), 1.0); }"; + return DEEFAULT_DIFFUSE_SHADER; case AlphaMode: - return "vec4 getFragmentColor() { return vec4(vec3(texture(diffuseMap, uv).a), 1.0); }"; + return DEEFAULT_ALPHA_SHADER; case SpecularMode: - return "vec4 getFragmentColor() { return vec4(texture(specularMap, uv).xyz, 1.0); }"; + return DEEFAULT_SPECULAR_SHADER; case RoughnessMode: - return "vec4 getFragmentColor() { return vec4(vec3(texture(specularMap, uv).a), 1.0); }"; + return DEEFAULT_ROUGHNESS_SHADER; case NormalMode: - return "vec4 getFragmentColor() { return vec4(texture(normalMap, uv).xyz, 1.0); }"; + return DEEFAULT_NORMAL_SHADER; case DepthMode: - return "vec4 getFragmentColor() { return vec4(vec3(texture(depthMap, uv).x), 1.0); }"; + return DEEFAULT_DEPTH_SHADER; case LightingMode: - return "vec4 getFragmentColor() { return vec4(pow(texture(lightingMap, uv).xyz, vec3(1.0 / 2.2)), 1.0); }"; + return DEEFAULT_LIGHTING_SHADER; case CustomMode: - return getFileContent(CUSTOM_FILE, "vec4 getFragmentColor() { return vec4(1.0); }"); + return getFileContent(customFile, DEEFAULT_CUSTOM_SHADER); } } -bool DebugDeferredBuffer::pipelineNeedsUpdate(Modes mode) const { +bool DebugDeferredBuffer::pipelineNeedsUpdate(Modes mode, std::string customFile) const { if (mode != CustomMode) { return !_pipelines[mode]; } + auto it = _customPipelines.find(customFile); + if (it != _customPipelines.end() && it->second.pipeline) { + auto& info = it->second.info; + + auto lastModified = info.lastModified(); + info.refresh(); + return lastModified != info.lastModified(); + } + return true; } -const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(Modes mode) { - if (pipelineNeedsUpdate(mode)) { +const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(Modes mode, std::string customFile) { + if (pipelineNeedsUpdate(mode, customFile)) { static const std::string VERTEX_SHADER { debug_deferred_buffer_vert }; static const std::string FRAGMENT_SHADER { debug_deferred_buffer_frag }; static const std::string SOURCE_PLACEHOLDER { "//SOURCE_PLACEHOLDER" }; static const auto SOURCE_PLACEHOLDER_INDEX = FRAGMENT_SHADER.find(SOURCE_PLACEHOLDER); - Q_ASSERT_X(SOURCE_PLACEHOLDER_INDEX != std::string::npos, Q_FUNC_INFO, "Could not find source placeholder"); + Q_ASSERT_X(SOURCE_PLACEHOLDER_INDEX != std::string::npos, Q_FUNC_INFO, + "Could not find source placeholder"); auto bakedFragmentShader = FRAGMENT_SHADER; bakedFragmentShader.replace(SOURCE_PLACEHOLDER_INDEX, SOURCE_PLACEHOLDER.size(), - getShaderSourceCode(mode)); + getShaderSourceCode(mode, customFile)); - const auto vs = gpu::Shader::createVertex(VERTEX_SHADER); + static const auto vs = gpu::Shader::createVertex(VERTEX_SHADER); const auto ps = gpu::Shader::createPixel(bakedFragmentShader); const auto program = gpu::Shader::createProgram(vs, ps); @@ -95,10 +158,21 @@ const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(Modes mode) { slotBindings.insert(gpu::Shader::Binding("lightingMap", Lighting)); gpu::Shader::makeProgram(*program, slotBindings); + auto pipeline = gpu::Pipeline::create(program, std::make_shared()); + // Good to go add the brand new pipeline - _pipelines[mode] = gpu::Pipeline::create(program, std::make_shared()); + if (mode != CustomMode) { + _pipelines[mode] = pipeline; + } else { + _customPipelines[customFile].pipeline = pipeline; + } + } + + if (mode != CustomMode) { + return _pipelines[mode]; + } else { + return _customPipelines[customFile].pipeline; } - return _pipelines[mode]; } @@ -118,8 +192,11 @@ void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const Ren batch.setProjectionTransform(projMat); batch.setViewTransform(viewMat); batch.setModelTransform(Transform()); + + // TODO REMOVE: Temporary until UI + auto first = _customPipelines.begin()->first; - batch.setPipeline(getPipeline(Modes(renderContext->_deferredDebugMode))); + batch.setPipeline(getPipeline(Modes(renderContext->_deferredDebugMode), first)); batch.setResourceTexture(Diffuse, framebufferCache->getDeferredColorTexture()); batch.setResourceTexture(Normal, framebufferCache->getDeferredNormalTexture()); diff --git a/libraries/render-utils/src/DebugDeferredBuffer.h b/libraries/render-utils/src/DebugDeferredBuffer.h index a0df42c05a..682888b2af 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.h +++ b/libraries/render-utils/src/DebugDeferredBuffer.h @@ -12,12 +12,16 @@ #ifndef hifi_DebugDeferredBuffer_h #define hifi_DebugDeferredBuffer_h +#include + #include class DebugDeferredBuffer { public: using JobModel = render::Job::Model; + DebugDeferredBuffer(); + void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext); private: @@ -32,14 +36,19 @@ private: CustomMode // Needs to stay last }; + struct CustomPipeline { + gpu::PipelinePointer pipeline; + mutable QFileInfo info; + }; + using StandardPipelines = std::array; + using CustomPipelines = std::unordered_map; - const std::string CUSTOM_FILE { "/Users/clement/Desktop/custom.slh" }; + bool pipelineNeedsUpdate(Modes mode, std::string customFile = std::string()) const; + const gpu::PipelinePointer& getPipeline(Modes mode, std::string customFile = std::string()); + std::string getShaderSourceCode(Modes mode, std::string customFile = std::string()); - bool pipelineNeedsUpdate(Modes mode) const; - const gpu::PipelinePointer& getPipeline(Modes mode); - std::string getShaderSourceCode(Modes mode); - - std::array _pipelines; + StandardPipelines _pipelines; + CustomPipelines _customPipelines; }; #endif // hifi_DebugDeferredBuffer_h \ No newline at end of file From c0a675dd9e49a137669ba189c1ad44441c4ebdc5 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 17 Dec 2015 16:02:49 -0800 Subject: [PATCH 37/62] Fix msvc warning --- libraries/render-utils/src/DebugDeferredBuffer.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index 6bdfbb57ff..3458712106 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -114,6 +114,8 @@ std::string DebugDeferredBuffer::getShaderSourceCode(Modes mode, std::string cus case CustomMode: return getFileContent(customFile, DEEFAULT_CUSTOM_SHADER); } + Q_UNREACHABLE(); + return std::string(); } bool DebugDeferredBuffer::pipelineNeedsUpdate(Modes mode, std::string customFile) const { From 78b805a19a50a286a446f252dc3bd84db1f8e1ee Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 17 Dec 2015 16:06:55 -0800 Subject: [PATCH 38/62] Fix file shader file lookup on windows --- libraries/render-utils/src/DebugDeferredBuffer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index 3458712106..d61b131844 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -76,12 +76,12 @@ static const std::string DEEFAULT_CUSTOM_SHADER { }; static std::string getFileContent(std::string fileName, std::string defaultContent = std::string()) { - QFile customFile(QUrl(QString::fromStdString(fileName)).toLocalFile()); + QFile customFile(QString::fromStdString(fileName)); if (customFile.open(QIODevice::ReadOnly)) { return customFile.readAll().toStdString(); } qWarning() << "DebugDeferredBuffer::getFileContent(): Could not open" - << QUrl(QString::fromStdString(fileName)).toLocalFile(); + << QString::fromStdString(fileName); return defaultContent; } @@ -89,9 +89,9 @@ static std::string getFileContent(std::string fileName, std::string defaultConte DebugDeferredBuffer::DebugDeferredBuffer() { // TODO REMOVE: Temporary until UI static const auto DESKTOP_PATH = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); - static const auto CUSTOM_FILE = "file://" + DESKTOP_PATH.toStdString() + "/custom.slh"; + static const auto CUSTOM_FILE = DESKTOP_PATH.toStdString() + "/custom.slh"; CustomPipeline pipeline; - pipeline.info = QFileInfo(DESKTOP_PATH + "/custom.slh"); + pipeline.info = QFileInfo(QString::fromStdString(CUSTOM_FILE)); _customPipelines.emplace(CUSTOM_FILE, pipeline); } From 32bb8f020cc88c606951a77e16e47273c673a227 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 17 Dec 2015 17:40:35 -0800 Subject: [PATCH 39/62] FIxing the diffuse contribution bug maybe --- .../render-utils/src/DeferredGlobalLight.slh | 6 +++--- .../render-utils/src/DeferredLighting.slh | 20 ++++++------------- libraries/render-utils/src/point_light.slf | 2 +- libraries/render-utils/src/spot_light.slf | 2 +- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index 983b8002f7..11e157a50c 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -83,7 +83,7 @@ vec3 evalAmbienGlobalColor(mat4 invViewMat, float shadowAttenuation, vec3 positi vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, specular, gloss); - color += vec3(diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light); + color += vec3(diffuse * shading.w + shading.rgb) * shadowAttenuation * getLightColor(light) * getLightIntensity(light); return color; } @@ -106,7 +106,7 @@ vec3 evalAmbienSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, vec3 vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, specular, gloss); - color += vec3(diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light); + color += vec3(diffuse * shading.w + shading.rgb) * shadowAttenuation * getLightColor(light) * getLightIntensity(light); return color; } @@ -129,7 +129,7 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, vec3 positi vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, specular, gloss); - color += vec3(diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light); + color += vec3(diffuse * shading.w + shading.rgb) * shadowAttenuation * getLightColor(light) * getLightIntensity(light); return color; } diff --git a/libraries/render-utils/src/DeferredLighting.slh b/libraries/render-utils/src/DeferredLighting.slh index d01b36f553..f4863bbadf 100755 --- a/libraries/render-utils/src/DeferredLighting.slh +++ b/libraries/render-utils/src/DeferredLighting.slh @@ -23,19 +23,16 @@ vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 sp // Specular Lighting depends on the half vector and the gloss vec3 halfDir = normalize(fragEyeDir + fragLightDir); - // float specularPower = pow(facingLight * max(0.0, dot(halfDir, fragNormal)), gloss * 128.0); float specularPower = pow(max(0.0, dot(halfDir, fragNormal)), gloss * 128.0); specularPower *= (gloss * 128.0 * 0.125 + 0.25); float shlickPower = (1.0 - dot(fragLightDir,halfDir)); float shlickPower2 = shlickPower * shlickPower; float shlickPower5 = shlickPower2 * shlickPower2 * shlickPower; - vec3 schlick = specular * (1.0 - shlickPower5) + vec3(shlickPower5); - vec3 reflect = specularPower * schlick; + vec3 fresnel = specular * (1.0 - shlickPower5) + vec3(shlickPower5); + vec3 reflect = specularPower * fresnel * diffuse; - // FIXME: - //return vec4(reflect, diffuse * (1 - length(schlick))); - return vec4(reflect, diffuse); + return vec4(reflect, diffuse * (1 - fresnel.x))); } <@endfunc@> @@ -51,7 +48,7 @@ vec4 evalBlinnShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 vec3 halfDir = normalize(fragEyeDir + fragLightDir); float specularPower = pow(facingLight * max(0.0, dot(halfDir, fragNormal)), gloss * 128.0); - vec3 reflect = specularPower * specular; + vec3 reflect = specularPower * specular * diffuse; return vec4(reflect, diffuse); } @@ -61,14 +58,9 @@ vec4 evalBlinnShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 <$declareEvalPBRShading()$> - +// Return xyz the specular/reflection component and w the diffuse component vec4 evalFragShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 specular, float gloss) { - - /*if (gl_FragCoord.x > 1000) { - return evalBlinnShading(fragNormal, fragLightDir, fragEyeDir, specular, gloss); - } else {*/ - return evalPBRShading(fragNormal, fragLightDir, fragEyeDir, specular, gloss); - //} + return evalPBRShading(fragNormal, fragLightDir, fragEyeDir, specular, gloss); } <@endif@> diff --git a/libraries/render-utils/src/point_light.slf b/libraries/render-utils/src/point_light.slf index e9045e18c5..716a39aee9 100644 --- a/libraries/render-utils/src/point_light.slf +++ b/libraries/render-utils/src/point_light.slf @@ -66,7 +66,7 @@ void main(void) { float radialAttenuation = evalLightAttenuation(light, fragLightDistance); // Final Lighting color - vec3 fragColor = shading.w * (frag.diffuse + shading.xyz); + vec3 fragColor = (shading.w * frag.diffuse + shading.xyz); _fragColor = vec4(fragColor * radialAttenuation * getLightColor(light) * getLightIntensity(light), 0.0); if (getLightShowContour(light) > 0.0) { diff --git a/libraries/render-utils/src/spot_light.slf b/libraries/render-utils/src/spot_light.slf index 73b081260e..d7a20fc5e5 100644 --- a/libraries/render-utils/src/spot_light.slf +++ b/libraries/render-utils/src/spot_light.slf @@ -73,7 +73,7 @@ void main(void) { float angularAttenuation = evalLightSpotAttenuation(light, cosSpotAngle); // Final Lighting color - vec3 fragColor = shading.w * (frag.diffuse + shading.xyz); + vec3 fragColor = (shading.w * frag.diffuse + shading.xyz); _fragColor = vec4(fragColor * angularAttenuation * radialAttenuation * getLightColor(light) * getLightIntensity(light), 0.0); if (getLightShowContour(light) > 0.0) { From c891bcb8cdc26a4cc265b13f59b897065b079191 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 17 Dec 2015 17:44:40 -0800 Subject: [PATCH 40/62] FIxing the diffuse contribution bug maybe --- libraries/render-utils/src/DeferredLighting.slh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render-utils/src/DeferredLighting.slh b/libraries/render-utils/src/DeferredLighting.slh index f4863bbadf..cf03861c2f 100755 --- a/libraries/render-utils/src/DeferredLighting.slh +++ b/libraries/render-utils/src/DeferredLighting.slh @@ -32,7 +32,7 @@ vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 sp vec3 fresnel = specular * (1.0 - shlickPower5) + vec3(shlickPower5); vec3 reflect = specularPower * fresnel * diffuse; - return vec4(reflect, diffuse * (1 - fresnel.x))); + return vec4(reflect, diffuse * (1 - fresnel.x)); } <@endfunc@> From 919a4b6728d950226a0be472bb193efd2aa9d5c6 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 17 Dec 2015 16:03:18 -0800 Subject: [PATCH 41/62] Split global JS Scene into Render --- interface/src/Application.cpp | 58 +++------- .../render-utils/src/RenderDeferredTask.cpp | 74 ++++++------ .../src/RenderScriptingInterface.cpp | 41 +++++++ .../src/RenderScriptingInterface.h | 95 +++++++++++++++ libraries/render/src/render/Engine.cpp | 10 ++ libraries/render/src/render/Engine.h | 87 ++++++++++---- .../src/SceneScriptingInterface.cpp | 95 +++------------ .../src/SceneScriptingInterface.h | 109 ++---------------- libraries/script-engine/src/ScriptEngine.cpp | 1 - 9 files changed, 293 insertions(+), 277 deletions(-) create mode 100644 libraries/render-utils/src/RenderScriptingInterface.cpp create mode 100644 libraries/render-utils/src/RenderScriptingInterface.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 21648f9118..fedc64174f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -89,6 +89,7 @@ #include #include #include +#include #include #include #include @@ -341,6 +342,7 @@ bool setupEssentials(int& argc, char** argv) { #endif DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); @@ -3674,40 +3676,22 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se // For now every frame pass the renderContext { PerformanceTimer perfTimer("EngineRun"); - render::RenderContext renderContext; - - auto sceneInterface = DependencyManager::get(); - - renderContext._cullOpaque = sceneInterface->doEngineCullOpaque(); - renderContext._sortOpaque = sceneInterface->doEngineSortOpaque(); - renderContext._renderOpaque = sceneInterface->doEngineRenderOpaque(); - renderContext._cullTransparent = sceneInterface->doEngineCullTransparent(); - renderContext._sortTransparent = sceneInterface->doEngineSortTransparent(); - renderContext._renderTransparent = sceneInterface->doEngineRenderTransparent(); - - renderContext._maxDrawnOpaqueItems = sceneInterface->getEngineMaxDrawnOpaqueItems(); - renderContext._maxDrawnTransparentItems = sceneInterface->getEngineMaxDrawnTransparentItems(); - renderContext._maxDrawnOverlay3DItems = sceneInterface->getEngineMaxDrawnOverlay3DItems(); - - renderContext._deferredDebugMode = sceneInterface->getEngineDeferredDebugMode(); - renderContext._deferredDebugSize = sceneInterface->getEngineDeferredDebugSize(); - - renderContext._drawItemStatus = sceneInterface->doEngineDisplayItemStatus(); - if (Menu::getInstance()->isOptionChecked(MenuOption::PhysicsShowOwned)) { - renderContext._drawItemStatus |= render::showNetworkStatusFlag; - } - renderContext._drawHitEffect = sceneInterface->doEngineDisplayHitEffect(); - - renderContext._occlusionStatus = Menu::getInstance()->isOptionChecked(MenuOption::DebugAmbientOcclusion); - renderContext._fxaaStatus = Menu::getInstance()->isOptionChecked(MenuOption::Antialiasing); - - renderContext._toneMappingExposure = sceneInterface->getEngineToneMappingExposure(); - renderContext._toneMappingToneCurve = sceneInterface->getEngineToneMappingToneCurveValue(); renderArgs->_shouldRender = LODManager::shouldRender; - - renderContext.args = renderArgs; renderArgs->_viewFrustum = getDisplayViewFrustum(); + + auto renderInterface = DependencyManager::get(); + auto renderItemsMeta = renderInterface->getItemsMeta(); + auto renderTone = renderInterface->getTone(); + int drawStatus = renderInterface->getDrawStatus(); + bool drawHitEffect = renderInterface->getDrawHitEffect(); + + bool occlusionStatus = Menu::getInstance()->isOptionChecked(MenuOption::DebugAmbientOcclusion); + bool antialiasingStatus = Menu::getInstance()->isOptionChecked(MenuOption::Antialiasing); + bool showOwnedStatus = Menu::getInstance()->isOptionChecked(MenuOption::PhysicsShowOwned); + + render::RenderContext renderContext{renderArgs, renderItemsMeta, renderTone}; + renderContext.setOptions(drawStatus, drawHitEffect, occlusionStatus, antialiasingStatus, showOwnedStatus); _renderEngine->setRenderContext(renderContext); // Before the deferred pass, let's try to use the render engine @@ -3715,15 +3699,8 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se _renderEngine->run(); myAvatar->endRenderRun(); - auto engineRC = _renderEngine->getRenderContext(); - sceneInterface->setEngineFeedOpaqueItems(engineRC->_numFeedOpaqueItems); - sceneInterface->setEngineDrawnOpaqueItems(engineRC->_numDrawnOpaqueItems); - - sceneInterface->setEngineFeedTransparentItems(engineRC->_numFeedTransparentItems); - sceneInterface->setEngineDrawnTransparentItems(engineRC->_numDrawnTransparentItems); - - sceneInterface->setEngineFeedOverlay3DItems(engineRC->_numFeedOverlay3DItems); - sceneInterface->setEngineDrawnOverlay3DItems(engineRC->_numDrawnOverlay3DItems); + auto engineContext = _renderEngine->getRenderContext(); + renderInterface->setItemCounts(engineContext->getItemsMeta()); } activeRenderingThread = nullptr; @@ -4177,6 +4154,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri scriptEngine->registerFunction("HMD", "getHUDLookAtPosition3D", HMDScriptingInterface::getHUDLookAtPosition3D, 0); scriptEngine->registerGlobalObject("Scene", DependencyManager::get().data()); + scriptEngine->registerGlobalObject("Render", DependencyManager::get().data()); scriptEngine->registerGlobalObject("ScriptDiscoveryService", this->getRunningScriptsWidget()); } diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 5423d928a7..820f2b86bb 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -37,23 +37,24 @@ using namespace render; void PrepareDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { - DependencyManager::get()->prepare(renderContext->args); + DependencyManager::get()->prepare(renderContext->getArgs()); } void RenderDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { - DependencyManager::get()->render(renderContext->args); + DependencyManager::get()->render(renderContext->getArgs()); } void ToneMappingDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { PerformanceTimer perfTimer("ToneMappingDeferred"); - _toneMappingEffect.render(renderContext->args); + _toneMappingEffect.render(renderContext->getArgs()); } RenderDeferredTask::RenderDeferredTask() : Task() { // CPU only, create the list of renderedOpaques items _jobs.push_back(Job(new FetchItems::JobModel("FetchOpaque", FetchItems([](const RenderContextPointer& context, int count) { - context->_numFeedOpaqueItems = count; + context->getItemsMeta()._opaque._numFeed = count; + auto& opaque = context->getItemsMeta()._opaque; }) ))); _jobs.push_back(Job(new CullItemsOpaque::JobModel("CullOpaque", _jobs.back().getOutput()))); @@ -64,7 +65,7 @@ RenderDeferredTask::RenderDeferredTask() : Task() { _jobs.push_back(Job(new FetchItems::JobModel("FetchTransparent", FetchItems(ItemFilter::Builder::transparentShape().withoutLayered(), [](const RenderContextPointer& context, int count) { - context->_numFeedTransparentItems = count; + context->getItemsMeta()._transparent._numFeed = count; }) ))); _jobs.push_back(Job(new CullItemsTransparent::JobModel("CullTransparent", _jobs.back().getOutput()))); @@ -146,7 +147,7 @@ void RenderDeferredTask::run(const SceneContextPointer& sceneContext, const Rend // Is it possible that we render without a viewFrustum ? - if (!(renderContext->args && renderContext->args->_viewFrustum)) { + if (!(renderContext->getArgs() && renderContext->getArgs()->_viewFrustum)) { return; } @@ -154,21 +155,21 @@ void RenderDeferredTask::run(const SceneContextPointer& sceneContext, const Rend setDrawDebugDeferredBuffer(renderContext->_deferredDebugMode); // Make sure we turn the displayItemStatus on/off - setDrawItemStatus(renderContext->_drawItemStatus); + setDrawItemStatus(renderContext->getDrawStatus()); // Make sure we display hit effect on screen, as desired from a script - setDrawHitEffect(renderContext->_drawHitEffect); + setDrawHitEffect(renderContext->getDrawHitEffect()); // TODO: turn on/off AO through menu item - setOcclusionStatus(renderContext->_occlusionStatus); + setOcclusionStatus(renderContext->getOcclusionStatus()); - setAntialiasingStatus(renderContext->_fxaaStatus); + setAntialiasingStatus(renderContext->getFxaaStatus()); - setToneMappingExposure(renderContext->_toneMappingExposure); - setToneMappingToneCurve(renderContext->_toneMappingToneCurve); + setToneMappingExposure(renderContext->getTone()._exposure); + setToneMappingToneCurve(renderContext->getTone()._toneCurve); - renderContext->args->_context->syncCache(); + renderContext->getArgs()->_context->syncCache(); for (auto job : _jobs) { job.run(sceneContext, renderContext); @@ -177,16 +178,17 @@ void RenderDeferredTask::run(const SceneContextPointer& sceneContext, const Rend }; void DrawOpaqueDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems) { - assert(renderContext->args); - assert(renderContext->args->_viewFrustum); + assert(renderContext->getArgs()); + assert(renderContext->getArgs()->_viewFrustum); - RenderArgs* args = renderContext->args; + RenderArgs* args = renderContext->getArgs(); gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); args->_batch = &batch; - renderContext->_numDrawnOpaqueItems = (int)inItems.size(); + auto& opaque = renderContext->getItemsMeta()._opaque; + opaque._numDrawn = (int)inItems.size(); glm::mat4 projMat; Transform viewMat; @@ -200,22 +202,23 @@ void DrawOpaqueDeferred::run(const SceneContextPointer& sceneContext, const Rend const float OPAQUE_ALPHA_THRESHOLD = 0.5f; args->_alphaThreshold = OPAQUE_ALPHA_THRESHOLD; } - renderItems(sceneContext, renderContext, inItems, renderContext->_maxDrawnOpaqueItems); + renderItems(sceneContext, renderContext, inItems, opaque._maxDrawn); args->_batch = nullptr; }); } void DrawTransparentDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems) { - assert(renderContext->args); - assert(renderContext->args->_viewFrustum); + assert(renderContext->getArgs()); + assert(renderContext->getArgs()->_viewFrustum); - RenderArgs* args = renderContext->args; + RenderArgs* args = renderContext->getArgs(); gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); args->_batch = &batch; - renderContext->_numDrawnTransparentItems = (int)inItems.size(); + auto& transparent = renderContext->getItemsMeta()._transparent; + transparent._numDrawn = (int)inItems.size(); glm::mat4 projMat; Transform viewMat; @@ -228,7 +231,7 @@ void DrawTransparentDeferred::run(const SceneContextPointer& sceneContext, const const float TRANSPARENT_ALPHA_THRESHOLD = 0.0f; args->_alphaThreshold = TRANSPARENT_ALPHA_THRESHOLD; - renderItems(sceneContext, renderContext, inItems, renderContext->_maxDrawnTransparentItems); + renderItems(sceneContext, renderContext, inItems, transparent._maxDrawn); args->_batch = nullptr; }); } @@ -251,8 +254,8 @@ const gpu::PipelinePointer& DrawOverlay3D::getOpaquePipeline() { } void DrawOverlay3D::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { - assert(renderContext->args); - assert(renderContext->args->_viewFrustum); + assert(renderContext->getArgs()); + assert(renderContext->getArgs()->_viewFrustum); // render backgrounds auto& scene = sceneContext->_scene; @@ -267,11 +270,12 @@ void DrawOverlay3D::run(const SceneContextPointer& sceneContext, const RenderCon inItems.emplace_back(id); } } - renderContext->_numFeedOverlay3DItems = (int)inItems.size(); - renderContext->_numDrawnOverlay3DItems = (int)inItems.size(); + auto& overlay3D = renderContext->getItemsMeta()._overlay3D; + overlay3D._numFeed = (int)inItems.size(); + overlay3D._numDrawn = (int)inItems.size(); if (!inItems.empty()) { - RenderArgs* args = renderContext->args; + RenderArgs* args = renderContext->getArgs(); // Clear the framebuffer without stereo // Needs to be distinct from the other batch because using the clear call @@ -300,7 +304,7 @@ void DrawOverlay3D::run(const SceneContextPointer& sceneContext, const RenderCon batch.setPipeline(getOpaquePipeline()); batch.setResourceTexture(0, args->_whiteTexture); - renderItems(sceneContext, renderContext, inItems, renderContext->_maxDrawnOverlay3DItems); + renderItems(sceneContext, renderContext, inItems, renderContext->getItemsMeta()._overlay3D._maxDrawn); }); args->_batch = nullptr; args->_whiteTexture.reset(); @@ -329,11 +333,11 @@ const gpu::PipelinePointer& DrawStencilDeferred::getOpaquePipeline() { } void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { - assert(renderContext->args); - assert(renderContext->args->_viewFrustum); + assert(renderContext->getArgs()); + assert(renderContext->getArgs()->_viewFrustum); // from the touched pixel generate the stencil buffer - RenderArgs* args = renderContext->args; + RenderArgs* args = renderContext->getArgs(); doInBatch(args->_context, [=](gpu::Batch& batch) { args->_batch = &batch; @@ -355,8 +359,8 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren } void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { - assert(renderContext->args); - assert(renderContext->args->_viewFrustum); + assert(renderContext->getArgs()); + assert(renderContext->getArgs()->_viewFrustum); // render backgrounds auto& scene = sceneContext->_scene; @@ -368,7 +372,7 @@ void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const for (auto id : items) { inItems.emplace_back(id); } - RenderArgs* args = renderContext->args; + RenderArgs* args = renderContext->getArgs(); doInBatch(args->_context, [=](gpu::Batch& batch) { args->_batch = &batch; diff --git a/libraries/render-utils/src/RenderScriptingInterface.cpp b/libraries/render-utils/src/RenderScriptingInterface.cpp new file mode 100644 index 0000000000..3b283e3058 --- /dev/null +++ b/libraries/render-utils/src/RenderScriptingInterface.cpp @@ -0,0 +1,41 @@ +// +// RenderScriptingInterface.cpp +// libraries/render-utils +// +// Created by Zach Pomerantz on 12/16/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "RenderScriptingInterface.h" + +RenderScriptingInterface::RenderScriptingInterface() {}; + +void RenderScriptingInterface::setEngineToneMappingToneCurve(const QString& toneCurve) { + if (toneCurve == QString("None")) { + _tone._toneCurve = 0; + } else if (toneCurve == QString("Gamma22")) { + _tone._toneCurve = 1; + } else if (toneCurve == QString("Reinhard")) { + _tone._toneCurve = 2; + } else if (toneCurve == QString("Filmic")) { + _tone._toneCurve = 3; + } +} + +QString RenderScriptingInterface::getEngineToneMappingToneCurve() const { + switch (_tone._toneCurve) { + case 0: + return QString("None"); + case 1: + return QString("Gamma22"); + case 2: + return QString("Reinhard"); + case 3: + return QString("Filmic"); + default: + return QString("Filmic"); + }; +} \ No newline at end of file diff --git a/libraries/render-utils/src/RenderScriptingInterface.h b/libraries/render-utils/src/RenderScriptingInterface.h new file mode 100644 index 0000000000..ec3b5be669 --- /dev/null +++ b/libraries/render-utils/src/RenderScriptingInterface.h @@ -0,0 +1,95 @@ +// +// RenderScriptingInterface.h +// libraries/render-utils +// +// Created by Zach Pomerantz on 12/16/15. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_RenderScriptingInterface_h +#define hifi_RenderScriptingInterface_h + +#include // QObject +#include // Dependency + +#include "render/Engine.h" + +class RenderScriptingInterface : public QObject, public Dependency { + Q_OBJECT + SINGLETON_DEPENDENCY + + public: + Q_INVOKABLE void setEngineRenderOpaque(bool renderOpaque) { _items._opaque._render = renderOpaque; }; + Q_INVOKABLE bool doEngineRenderOpaque() const { return _items._opaque._render; } + Q_INVOKABLE void setEngineRenderTransparent(bool renderTransparent) { _items._transparent._render = renderTransparent; }; + Q_INVOKABLE bool doEngineRenderTransparent() const { return _items._transparent._render; } + + Q_INVOKABLE void setEngineCullOpaque(bool cullOpaque) { _items._opaque._cull = cullOpaque; }; + Q_INVOKABLE bool doEngineCullOpaque() const { return _items._opaque._cull; } + Q_INVOKABLE void setEngineCullTransparent(bool cullTransparent) { _items._transparent._cull = cullTransparent; }; + Q_INVOKABLE bool doEngineCullTransparent() const { return _items._transparent._cull; } + + Q_INVOKABLE void setEngineSortOpaque(bool sortOpaque) { _items._opaque._sort = sortOpaque; }; + Q_INVOKABLE bool doEngineSortOpaque() const { return _items._opaque._sort; } + Q_INVOKABLE void setEngineSortTransparent(bool sortTransparent) { _items._transparent._sort = sortTransparent; }; + Q_INVOKABLE bool doEngineSortTransparent() const { return _items._transparent._sort; } + + Q_INVOKABLE int getEngineNumDrawnOpaqueItems() { return _items._opaque._numDrawn; } + Q_INVOKABLE int getEngineNumDrawnTransparentItems() { return _items._transparent._numDrawn; } + Q_INVOKABLE int getEngineNumDrawnOverlay3DItems() { return _items._overlay3D._numDrawn; } + + Q_INVOKABLE int getEngineNumFeedOpaqueItems() { return _items._opaque._numFeed; } + Q_INVOKABLE int getEngineNumFeedTransparentItems() { return _items._transparent._numFeed; } + Q_INVOKABLE int getEngineNumFeedOverlay3DItems() { return _items._overlay3D._numFeed; } + + Q_INVOKABLE void setEngineMaxDrawnOpaqueItems(int count) { _items._opaque._maxDrawn = count; } + Q_INVOKABLE int getEngineMaxDrawnOpaqueItems() { return _items._opaque._maxDrawn; } + Q_INVOKABLE void setEngineMaxDrawnTransparentItems(int count) { _items._transparent._maxDrawn = count; } + Q_INVOKABLE int getEngineMaxDrawnTransparentItems() { return _items._transparent._maxDrawn; } + Q_INVOKABLE void setEngineMaxDrawnOverlay3DItems(int count) { _items._overlay3D._maxDrawn = count; } + Q_INVOKABLE int getEngineMaxDrawnOverlay3DItems() { return _items._overlay3D._maxDrawn; } + + Q_INVOKABLE void setEngineDeferredDebugMode(int mode) { _deferredDebugMode = mode; } + Q_INVOKABLE int getEngineDeferredDebugMode() { return _deferredDebugMode; } + Q_INVOKABLE void setEngineDeferredDebugSize(glm::vec4 size) { _deferredDebugSize = size; } + Q_INVOKABLE glm::vec4 getEngineDeferredDebugSize() { return _deferredDebugSize; } + + Q_INVOKABLE void setEngineDisplayItemStatus(int display) { _drawStatus = display; } + Q_INVOKABLE int doEngineDisplayItemStatus() { return _drawStatus; } + + Q_INVOKABLE void setEngineDisplayHitEffect(bool display) { _drawHitEffect = display; } + Q_INVOKABLE bool doEngineDisplayHitEffect() { return _drawHitEffect; } + + Q_INVOKABLE void setEngineToneMappingExposure(float exposure) { _tone._exposure = exposure; } + Q_INVOKABLE float getEngineToneMappingExposure() const { return _tone._exposure; } + + Q_INVOKABLE void setEngineToneMappingToneCurve(const QString& curve); + Q_INVOKABLE QString getEngineToneMappingToneCurve() const; + int getEngineToneMappingToneCurveValue() const { return _tone._toneCurve; } + + inline int getDrawStatus() { return _drawStatus; } + inline bool getDrawHitEffect() { return _drawHitEffect; } + inline const render::RenderContext::ItemsMeta& getItemsMeta() { return _items; } + inline const render::RenderContext::Tone& getTone() { return _tone; } + void setItemCounts(const render::RenderContext::ItemsMeta& items) { _items.setCounts(items); }; + +protected: + RenderScriptingInterface(); + ~RenderScriptingInterface() {}; + + render::RenderContext::ItemsMeta _items; + render::RenderContext::Tone _tone; + + // Options + int _drawStatus = 0; + bool _drawHitEffect = false; + + // Debugging + int _deferredDebugMode = -1; + glm::vec4 _deferredDebugSize { 0.0f, -1.0f, 1.0f, 1.0f }; +}; + +#endif // hifi_RenderScriptingInterface_h diff --git a/libraries/render/src/render/Engine.cpp b/libraries/render/src/render/Engine.cpp index 86f35eb831..0cf09e0ca4 100644 --- a/libraries/render/src/render/Engine.cpp +++ b/libraries/render/src/render/Engine.cpp @@ -13,6 +13,16 @@ #include "DrawTask.h" using namespace render; +void RenderContext::setOptions(int drawStatus, bool drawHitEffect, bool occlusion, bool fxaa, bool showOwned) { + _drawStatus = drawStatus; + _occlusionStatus = occlusion; + _fxaaStatus = fxaa; + _drawHitEffect = drawHitEffect; + + if (showOwned) { + _drawStatus |= render::showNetworkStatusFlag; + } +}; Engine::Engine() : _sceneContext(std::make_shared()), diff --git a/libraries/render/src/render/Engine.h b/libraries/render/src/render/Engine.h index abfef03039..dcfe28a444 100644 --- a/libraries/render/src/render/Engine.h +++ b/libraries/render/src/render/Engine.h @@ -23,7 +23,7 @@ public: SceneContext() {} }; -typedef std::shared_ptr SceneContextPointer; +using SceneContextPointer = std::shared_ptr; // see examples/utilities/tools/renderEngineDebug.js const int showDisplayStatusFlag = 1; @@ -32,43 +32,80 @@ const int showNetworkStatusFlag = 2; class RenderContext { public: - RenderArgs* args; + struct ItemsMeta { + inline void setCounts(const ItemsMeta& items) { + _opaque.setCounts(items._opaque); + _transparent.setCounts(items._transparent); + _overlay3D.setCounts(items._overlay3D); + }; - bool _cullOpaque = true; - bool _sortOpaque = true; - bool _renderOpaque = true; - bool _cullTransparent = true; - bool _sortTransparent = true; - bool _renderTransparent = true; + struct Counter { + Counter() {}; + Counter(const Counter& counter) { + _numFeed = _numDrawn = 0; + _maxDrawn = counter._maxDrawn; + }; - int _numFeedOpaqueItems = 0; - int _numDrawnOpaqueItems = 0; - int _maxDrawnOpaqueItems = -1; + inline void setCounts(const Counter& counter) { + _numFeed = counter._numFeed; + _numDrawn = counter._numDrawn; + }; + + int _numFeed = 0; + int _numDrawn = 0; + int _maxDrawn = -1; + }; + + struct State : public Counter { + bool _render = true; + bool _cull = true; + bool _sort = true; + + Counter _counter{}; + }; + + // TODO: Store state/counter in a map instead of manually enumerated members + State _opaque{}; + State _transparent{}; + Counter _overlay3D{}; + }; + + struct Tone { + int _toneCurve = 3; + float _exposure = 0.0; + }; - int _numFeedTransparentItems = 0; - int _numDrawnTransparentItems = 0; - int _maxDrawnTransparentItems = -1; + RenderContext(RenderArgs* args, ItemsMeta items, Tone tone) : _args{args}, _items{items}, _tone{tone} {}; + RenderContext() : RenderContext(nullptr, {}, {}) {}; - int _numFeedOverlay3DItems = 0; - int _numDrawnOverlay3DItems = 0; - int _maxDrawnOverlay3DItems = -1; + inline RenderArgs* getArgs() { return _args; } + inline int getDrawStatus() { return _drawStatus; } + inline bool getDrawHitEffect() { return _drawHitEffect; } + inline bool getOcclusionStatus() { return _occlusionStatus; } + inline bool getFxaaStatus() { return _fxaaStatus; } + inline ItemsMeta& getItemsMeta() { return _items; } + inline Tone& getTone() { return _tone; } + void setOptions(int drawStatus, bool drawHitEffect, bool occlusion, bool fxaa, bool showOwned); + // Debugging int _deferredDebugMode = -1; glm::vec4 _deferredDebugSize { 0.0f, -1.0f, 1.0f, 1.0f }; - int _drawItemStatus = 0; - bool _drawHitEffect = false; +protected: + RenderArgs* _args; + + // Options + int _drawStatus = 0; // bitflag + bool _drawHitEffect = false; bool _occlusionStatus = false; bool _fxaaStatus = false; - float _toneMappingExposure = 0.0; - int _toneMappingToneCurve = 3; - - RenderContext() {} + ItemsMeta _items; + Tone _tone; }; typedef std::shared_ptr RenderContextPointer; -// THe base class for a task that runs on the SceneContext +// The base class for a task that runs on the SceneContext class Task { public: Task() {} @@ -81,7 +118,7 @@ protected: typedef std::shared_ptr TaskPointer; typedef std::vector Tasks; -// The root of the takss, the Engine, should not be known from the Tasks, +// The root of the tasks, the Engine, should not be known from the Tasks, // The SceneContext is what navigates from the engine down to the Tasks class Engine { public: diff --git a/libraries/script-engine/src/SceneScriptingInterface.cpp b/libraries/script-engine/src/SceneScriptingInterface.cpp index 3e22a9e929..39bceba9d9 100644 --- a/libraries/script-engine/src/SceneScriptingInterface.cpp +++ b/libraries/script-engine/src/SceneScriptingInterface.cpp @@ -1,6 +1,6 @@ // // SceneScriptingInterface.cpp -// interface/src/scripting +// libraries/script-engine // // Created by Sam Gateau on 2/24/15. // Copyright 2014 High Fidelity, Inc. @@ -11,16 +11,27 @@ #include "SceneScriptingInterface.h" -#include - - #include SceneScriptingInterface::SceneScriptingInterface() { - // Let's make sure the sunSkyStage is using a proceduralSKybox + // Let's make sure the sunSkyStage is using a proceduralSkybox _skyStage->setSkybox(model::SkyboxPointer(new ProceduralSkybox())); } +void SceneScriptingInterface::setShouldRenderAvatars(bool shouldRenderAvatars) { + if (shouldRenderAvatars != _shouldRenderAvatars) { + _shouldRenderAvatars = shouldRenderAvatars; + emit shouldRenderAvatarsChanged(_shouldRenderAvatars); + } +} + +void SceneScriptingInterface::setShouldRenderEntities(bool shouldRenderEntities) { + if (shouldRenderEntities != _shouldRenderEntities) { + _shouldRenderEntities = shouldRenderEntities; + emit shouldRenderEntitiesChanged(_shouldRenderEntities); + } +} + void SceneScriptingInterface::setStageOrientation(const glm::quat& orientation) { _skyStage->setOriginOrientation(orientation); } @@ -120,77 +131,3 @@ QString SceneScriptingInterface::getBackgroundMode() const { model::SunSkyStagePointer SceneScriptingInterface::getSkyStage() const { return _skyStage; } - -void SceneScriptingInterface::setShouldRenderAvatars(bool shouldRenderAvatars) { - if (shouldRenderAvatars != _shouldRenderAvatars) { - _shouldRenderAvatars = shouldRenderAvatars; - emit shouldRenderAvatarsChanged(_shouldRenderAvatars); - } -} - -void SceneScriptingInterface::setShouldRenderEntities(bool shouldRenderEntities) { - if (shouldRenderEntities != _shouldRenderEntities) { - _shouldRenderEntities = shouldRenderEntities; - emit shouldRenderEntitiesChanged(_shouldRenderEntities); - } -} - -void SceneScriptingInterface::setEngineRenderOpaque(bool renderOpaque) { - _engineRenderOpaque = renderOpaque; -} - -void SceneScriptingInterface::setEngineRenderTransparent(bool renderTransparent) { - _engineRenderTransparent = renderTransparent; -} - -void SceneScriptingInterface::setEngineCullOpaque(bool cullOpaque) { - _engineCullOpaque = cullOpaque; -} - -void SceneScriptingInterface::setEngineCullTransparent(bool cullTransparent) { - _engineCullTransparent = cullTransparent; -} - -void SceneScriptingInterface::setEngineSortOpaque(bool sortOpaque) { - _engineSortOpaque = sortOpaque; -} - -void SceneScriptingInterface::setEngineSortTransparent(bool sortTransparent) { - _engineSortOpaque = sortTransparent; -} - -void SceneScriptingInterface::clearEngineCounters() { - _numFeedOpaqueItems = 0; - _numDrawnOpaqueItems = 0; - _numFeedTransparentItems = 0; - _numDrawnTransparentItems = 0; - _numFeedOverlay3DItems = 0; - _numDrawnOverlay3DItems = 0; -} - - -void SceneScriptingInterface::setEngineToneMappingToneCurve(const QString& toneCurve) { - if (toneCurve == QString("None")) { - _engineToneMappingToneCurve = 0; - } else if (toneCurve == QString("Gamma22")) { - _engineToneMappingToneCurve = 1; - } else if (toneCurve == QString("Reinhard")) { - _engineToneMappingToneCurve = 2; - } else if (toneCurve == QString("Filmic")) { - _engineToneMappingToneCurve = 3; - } -} -QString SceneScriptingInterface::getEngineToneMappingToneCurve() const { - switch (_engineToneMappingToneCurve) { - case 0: - return QString("None"); - case 1: - return QString("Gamma22"); - case 2: - return QString("Reinhard"); - case 3: - return QString("Filmic"); - default: - return QString("Filmic"); - }; -} \ No newline at end of file diff --git a/libraries/script-engine/src/SceneScriptingInterface.h b/libraries/script-engine/src/SceneScriptingInterface.h index 246f624b08..abc4ee68a9 100644 --- a/libraries/script-engine/src/SceneScriptingInterface.h +++ b/libraries/script-engine/src/SceneScriptingInterface.h @@ -1,6 +1,6 @@ // // SceneScriptingInterface.h -// interface/src/scripting +// libraries/script-engine // // Created by Sam Gateau on 2/24/15. // Copyright 2014 High Fidelity, Inc. @@ -12,9 +12,8 @@ #ifndef hifi_SceneScriptingInterface_h #define hifi_SceneScriptingInterface_h -#include - -#include +#include // QObject +#include // Dependency #include "model/Stage.h" @@ -22,10 +21,16 @@ class SceneScriptingInterface : public QObject, public Dependency { Q_OBJECT SINGLETON_DEPENDENCY +public: Q_PROPERTY(bool shouldRenderAvatars READ shouldRenderAvatars WRITE setShouldRenderAvatars) Q_PROPERTY(bool shouldRenderEntities READ shouldRenderEntities WRITE setShouldRenderEntities) -public: + Q_INVOKABLE void setShouldRenderAvatars(bool shouldRenderAvatars); + Q_INVOKABLE bool shouldRenderAvatars() const { return _shouldRenderAvatars; } + + Q_INVOKABLE void setShouldRenderEntities(bool shouldRenderEntities); + Q_INVOKABLE bool shouldRenderEntities() const { return _shouldRenderEntities; } + Q_INVOKABLE void setStageOrientation(const glm::quat& orientation); Q_INVOKABLE void setStageLocation(float longitude, float latitude, float altitude); @@ -43,7 +48,6 @@ public: Q_INVOKABLE void setStageSunModelEnable(bool isEnabled); Q_INVOKABLE bool isStageSunModelEnabled() const; - Q_INVOKABLE void setKeyLightColor(const glm::vec3& color); Q_INVOKABLE glm::vec3 getKeyLightColor() const; Q_INVOKABLE void setKeyLightIntensity(float intensity); @@ -61,108 +65,19 @@ public: Q_INVOKABLE QString getBackgroundMode() const; model::SunSkyStagePointer getSkyStage() const; - - Q_INVOKABLE void setShouldRenderAvatars(bool shouldRenderAvatars); - Q_INVOKABLE bool shouldRenderAvatars() const { return _shouldRenderAvatars; } - - Q_INVOKABLE void setShouldRenderEntities(bool shouldRenderEntities); - Q_INVOKABLE bool shouldRenderEntities() const { return _shouldRenderEntities; } - - - // Controlling the rendering engine - Q_INVOKABLE void setEngineRenderOpaque(bool renderOpaque); - Q_INVOKABLE bool doEngineRenderOpaque() const { return _engineRenderOpaque; } - Q_INVOKABLE void setEngineRenderTransparent(bool renderTransparent); - Q_INVOKABLE bool doEngineRenderTransparent() const { return _engineRenderTransparent; } - - Q_INVOKABLE void setEngineCullOpaque(bool cullOpaque); - Q_INVOKABLE bool doEngineCullOpaque() const { return _engineCullOpaque; } - Q_INVOKABLE void setEngineCullTransparent(bool cullTransparent); - Q_INVOKABLE bool doEngineCullTransparent() const { return _engineCullTransparent; } - - Q_INVOKABLE void setEngineSortOpaque(bool sortOpaque); - Q_INVOKABLE bool doEngineSortOpaque() const { return _engineSortOpaque; } - Q_INVOKABLE void setEngineSortTransparent(bool sortTransparent); - Q_INVOKABLE bool doEngineSortTransparent() const { return _engineSortTransparent; } - - void clearEngineCounters(); - void setEngineDrawnOpaqueItems(int count) { _numDrawnOpaqueItems = count; } - Q_INVOKABLE int getEngineNumDrawnOpaqueItems() { return _numDrawnOpaqueItems; } - void setEngineDrawnTransparentItems(int count) { _numDrawnTransparentItems = count; } - Q_INVOKABLE int getEngineNumDrawnTransparentItems() { return _numDrawnTransparentItems; } - void setEngineDrawnOverlay3DItems(int count) { _numDrawnOverlay3DItems = count; } - Q_INVOKABLE int getEngineNumDrawnOverlay3DItems() { return _numDrawnOverlay3DItems; } - - void setEngineFeedOpaqueItems(int count) { _numFeedOpaqueItems = count; } - Q_INVOKABLE int getEngineNumFeedOpaqueItems() { return _numFeedOpaqueItems; } - void setEngineFeedTransparentItems(int count) { _numFeedTransparentItems = count; } - Q_INVOKABLE int getEngineNumFeedTransparentItems() { return _numFeedTransparentItems; } - void setEngineFeedOverlay3DItems(int count) { _numFeedOverlay3DItems = count; } - Q_INVOKABLE int getEngineNumFeedOverlay3DItems() { return _numFeedOverlay3DItems; } - - Q_INVOKABLE void setEngineMaxDrawnOpaqueItems(int count) { _maxDrawnOpaqueItems = count; } - Q_INVOKABLE int getEngineMaxDrawnOpaqueItems() { return _maxDrawnOpaqueItems; } - Q_INVOKABLE void setEngineMaxDrawnTransparentItems(int count) { _maxDrawnTransparentItems = count; } - Q_INVOKABLE int getEngineMaxDrawnTransparentItems() { return _maxDrawnTransparentItems; } - Q_INVOKABLE void setEngineMaxDrawnOverlay3DItems(int count) { _maxDrawnOverlay3DItems = count; } - Q_INVOKABLE int getEngineMaxDrawnOverlay3DItems() { return _maxDrawnOverlay3DItems; } - - Q_INVOKABLE void setEngineDeferredDebugMode(int mode) { _deferredDebugMode = mode; } - Q_INVOKABLE int getEngineDeferredDebugMode() { return _deferredDebugMode; } - Q_INVOKABLE void setEngineDeferredDebugSize(glm::vec4 size) { _deferredDebugSize = size; } - Q_INVOKABLE glm::vec4 getEngineDeferredDebugSize() { return _deferredDebugSize; } - - Q_INVOKABLE void setEngineDisplayItemStatus(int display) { _drawItemStatus = display; } - Q_INVOKABLE int doEngineDisplayItemStatus() { return _drawItemStatus; } - - 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() const { return _engineToneMappingExposure; } - - Q_INVOKABLE void setEngineToneMappingToneCurve(const QString& curve); - Q_INVOKABLE QString getEngineToneMappingToneCurve() const; - int getEngineToneMappingToneCurveValue() const { return _engineToneMappingToneCurve; } signals: void shouldRenderAvatarsChanged(bool shouldRenderAvatars); void shouldRenderEntitiesChanged(bool shouldRenderEntities); + protected: SceneScriptingInterface(); ~SceneScriptingInterface() {}; model::SunSkyStagePointer _skyStage = std::make_shared(); - + bool _shouldRenderAvatars = true; bool _shouldRenderEntities = true; - - bool _engineRenderOpaque = true; - bool _engineRenderTransparent = true; - bool _engineCullOpaque = true; - bool _engineCullTransparent = true; - bool _engineSortOpaque = true; - bool _engineSortTransparent = true; - - int _numFeedOpaqueItems = 0; - int _numDrawnOpaqueItems = 0; - int _numFeedTransparentItems = 0; - int _numDrawnTransparentItems = 0; - int _numFeedOverlay3DItems = 0; - int _numDrawnOverlay3DItems = 0; - - int _maxDrawnOpaqueItems = -1; - int _maxDrawnTransparentItems = -1; - int _maxDrawnOverlay3DItems = -1; - - int _deferredDebugMode = -1; - glm::vec4 _deferredDebugSize { 0.0f, -1.0f, 1.0f, 1.0f }; - int _drawItemStatus = 0; - - bool _drawHitEffect = false; - - float _engineToneMappingExposure = 0.0f; - int _engineToneMappingToneCurve = 3; }; #endif // hifi_SceneScriptingInterface_h diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index ded3db11e9..ef448e93f0 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -46,7 +46,6 @@ #include "XMLHttpRequestClass.h" #include "WebSocketClass.h" -#include "SceneScriptingInterface.h" #include "RecordingScriptingInterface.h" #include "MIDIEvent.h" From cdcb2d565d0dc6e6966ba505d0f16db4733c0d3d Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 17 Dec 2015 17:51:07 -0800 Subject: [PATCH 42/62] Use new RenderContext accessors for rendering --- .../src/AmbientOcclusionEffect.cpp | 6 ++-- .../render-utils/src/AntialiasingEffect.cpp | 8 ++--- .../render-utils/src/DebugDeferredBuffer.cpp | 8 ++--- libraries/render-utils/src/HitEffect.cpp | 6 ++-- libraries/render/src/render/DrawStatus.cpp | 10 +++--- libraries/render/src/render/DrawTask.cpp | 36 +++++++++---------- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.cpp b/libraries/render-utils/src/AmbientOcclusionEffect.cpp index 1b631aed9c..c32bf2654d 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.cpp +++ b/libraries/render-utils/src/AmbientOcclusionEffect.cpp @@ -175,10 +175,10 @@ const gpu::PipelinePointer& AmbientOcclusion::getBlendPipeline() { } void AmbientOcclusion::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext) { - assert(renderContext->args); - assert(renderContext->args->_viewFrustum); + assert(renderContext->getArgs()); + assert(renderContext->getArgs()->_viewFrustum); - RenderArgs* args = renderContext->args; + RenderArgs* args = renderContext->getArgs(); gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { auto framebufferCache = DependencyManager::get(); QSize framebufferSize = framebufferCache->getFrameBufferSize(); diff --git a/libraries/render-utils/src/AntialiasingEffect.cpp b/libraries/render-utils/src/AntialiasingEffect.cpp index fb59f37941..3acc88f953 100644 --- a/libraries/render-utils/src/AntialiasingEffect.cpp +++ b/libraries/render-utils/src/AntialiasingEffect.cpp @@ -93,14 +93,14 @@ const gpu::PipelinePointer& Antialiasing::getBlendPipeline() { } void Antialiasing::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext) { - assert(renderContext->args); - assert(renderContext->args->_viewFrustum); + assert(renderContext->getArgs()); + assert(renderContext->getArgs()->_viewFrustum); - if (renderContext->args->_renderMode == RenderArgs::MIRROR_RENDER_MODE) { + if (renderContext->getArgs()->_renderMode == RenderArgs::MIRROR_RENDER_MODE) { return; } - RenderArgs* args = renderContext->args; + RenderArgs* args = renderContext->getArgs(); gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { batch.enableStereo(false); diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index d61b131844..23150a1779 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -179,9 +179,9 @@ const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(Modes mode, std::st void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { - assert(renderContext->args); - assert(renderContext->args->_viewFrustum); - const RenderArgs* args = renderContext->args; + assert(renderContext->getArgs()); + assert(renderContext->getArgs()->_viewFrustum); + RenderArgs* args = renderContext->getArgs(); gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { const auto geometryBuffer = DependencyManager::get(); const auto framebufferCache = DependencyManager::get(); @@ -211,4 +211,4 @@ void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const Ren const glm::vec2 topRight(renderContext->_deferredDebugSize.z, renderContext->_deferredDebugSize.w); geometryBuffer->renderQuad(batch, bottomLeft, topRight, color); }); -} \ No newline at end of file +} diff --git a/libraries/render-utils/src/HitEffect.cpp b/libraries/render-utils/src/HitEffect.cpp index 32915aea0e..bf65eaf059 100644 --- a/libraries/render-utils/src/HitEffect.cpp +++ b/libraries/render-utils/src/HitEffect.cpp @@ -61,9 +61,9 @@ const gpu::PipelinePointer& HitEffect::getHitEffectPipeline() { } void HitEffect::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext) { - assert(renderContext->args); - assert(renderContext->args->_viewFrustum); - RenderArgs* args = renderContext->args; + assert(renderContext->getArgs()); + assert(renderContext->getArgs()->_viewFrustum); + RenderArgs* args = renderContext->getArgs(); gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { glm::mat4 projMat; diff --git a/libraries/render/src/render/DrawStatus.cpp b/libraries/render/src/render/DrawStatus.cpp index 3f37ce378b..fa177bd0d4 100644 --- a/libraries/render/src/render/DrawStatus.cpp +++ b/libraries/render/src/render/DrawStatus.cpp @@ -97,9 +97,9 @@ const gpu::TexturePointer DrawStatus::getStatusIconMap() const { void DrawStatus::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems) { - assert(renderContext->args); - assert(renderContext->args->_viewFrustum); - RenderArgs* args = renderContext->args; + assert(renderContext->getArgs()); + assert(renderContext->getArgs()->_viewFrustum); + RenderArgs* args = renderContext->getArgs(); auto& scene = sceneContext->_scene; const int NUM_STATUS_VEC4_PER_ITEM = 2; const int VEC4_LENGTH = 4; @@ -179,7 +179,7 @@ void DrawStatus::run(const SceneContextPointer& sceneContext, const unsigned int VEC3_ADRESS_OFFSET = 3; - if ((renderContext->_drawItemStatus & showDisplayStatusFlag) > 0) { + if ((renderContext->getDrawStatus() & showDisplayStatusFlag) > 0) { for (int i = 0; i < nbItems; i++) { batch._glUniform3fv(_drawItemBoundPosLoc, 1, (const float*) (itemAABox + i)); batch._glUniform3fv(_drawItemBoundDimLoc, 1, ((const float*) (itemAABox + i)) + VEC3_ADRESS_OFFSET); @@ -192,7 +192,7 @@ void DrawStatus::run(const SceneContextPointer& sceneContext, batch.setPipeline(getDrawItemStatusPipeline()); - if ((renderContext->_drawItemStatus & showNetworkStatusFlag) > 0) { + if ((renderContext->getDrawStatus() & showNetworkStatusFlag) > 0) { for (int i = 0; i < nbItems; i++) { batch._glUniform3fv(_drawItemStatusPosLoc, 1, (const float*) (itemAABox + i)); batch._glUniform3fv(_drawItemStatusDimLoc, 1, ((const float*) (itemAABox + i)) + VEC3_ADRESS_OFFSET); diff --git a/libraries/render/src/render/DrawTask.cpp b/libraries/render/src/render/DrawTask.cpp index c0e50037e0..44ba57143f 100755 --- a/libraries/render/src/render/DrawTask.cpp +++ b/libraries/render/src/render/DrawTask.cpp @@ -37,7 +37,7 @@ void DrawSceneTask::run(const SceneContextPointer& sceneContext, const RenderCon // Is it possible that we render without a viewFrustum ? - if (!(renderContext->args && renderContext->args->_viewFrustum)) { + if (!(renderContext->getArgs() && renderContext->getArgs()->_viewFrustum)) { return; } @@ -54,11 +54,11 @@ Job::~Job() { void render::cullItems(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems, ItemIDsBounds& outItems) { - assert(renderContext->args); - assert(renderContext->args->_viewFrustum); + assert(renderContext->getArgs()); + assert(renderContext->getArgs()->_viewFrustum); - RenderArgs* args = renderContext->args; - auto renderDetails = renderContext->args->_details._item; + RenderArgs* args = renderContext->getArgs(); + auto renderDetails = renderContext->getArgs()->_details._item; renderDetails->_considered += inItems.size(); @@ -115,7 +115,7 @@ void CullItems::run(const SceneContextPointer& sceneContext, const RenderContext outItems.clear(); outItems.reserve(inItems.size()); - RenderArgs* args = renderContext->args; + RenderArgs* args = renderContext->getArgs(); args->_details.pointTo(RenderDetails::OTHER_ITEM); cullItems(sceneContext, renderContext, inItems, outItems); } @@ -124,7 +124,7 @@ void CullItemsOpaque::run(const SceneContextPointer& sceneContext, const RenderC outItems.clear(); outItems.reserve(inItems.size()); - RenderArgs* args = renderContext->args; + RenderArgs* args = renderContext->getArgs(); args->_details.pointTo(RenderDetails::OPAQUE_ITEM); cullItems(sceneContext, renderContext, inItems, outItems); } @@ -133,7 +133,7 @@ void CullItemsTransparent::run(const SceneContextPointer& sceneContext, const Re outItems.clear(); outItems.reserve(inItems.size()); - RenderArgs* args = renderContext->args; + RenderArgs* args = renderContext->getArgs(); args->_details.pointTo(RenderDetails::TRANSLUCENT_ITEM); cullItems(sceneContext, renderContext, inItems, outItems); } @@ -163,11 +163,11 @@ struct BackToFrontSort { }; void render::depthSortItems(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, bool frontToBack, const ItemIDsBounds& inItems, ItemIDsBounds& outItems) { - assert(renderContext->args); - assert(renderContext->args->_viewFrustum); + assert(renderContext->getArgs()); + assert(renderContext->getArgs()->_viewFrustum); auto& scene = sceneContext->_scene; - RenderArgs* args = renderContext->args; + RenderArgs* args = renderContext->getArgs(); // Allocate and simply copy @@ -211,7 +211,7 @@ void DepthSortItems::run(const SceneContextPointer& sceneContext, const RenderCo void render::renderItems(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems, int maxDrawnItems) { auto& scene = sceneContext->_scene; - RenderArgs* args = renderContext->args; + RenderArgs* args = renderContext->getArgs(); // render if ((maxDrawnItems < 0) || (maxDrawnItems > (int) inItems.size())) { for (auto itemDetails : inItems) { @@ -236,8 +236,8 @@ void render::renderItems(const SceneContextPointer& sceneContext, const RenderCo } void DrawLight::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { - assert(renderContext->args); - assert(renderContext->args->_viewFrustum); + assert(renderContext->getArgs()); + assert(renderContext->getArgs()->_viewFrustum); // render lights auto& scene = sceneContext->_scene; @@ -253,7 +253,7 @@ void DrawLight::run(const SceneContextPointer& sceneContext, const RenderContext ItemIDsBounds culledItems; culledItems.reserve(inItems.size()); - RenderArgs* args = renderContext->args; + RenderArgs* args = renderContext->getArgs(); args->_details.pointTo(RenderDetails::OTHER_ITEM); cullItems(sceneContext, renderContext, inItems, culledItems); @@ -265,8 +265,8 @@ void DrawLight::run(const SceneContextPointer& sceneContext, const RenderContext } void DrawBackground::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { - assert(renderContext->args); - assert(renderContext->args->_viewFrustum); + assert(renderContext->getArgs()); + assert(renderContext->getArgs()->_viewFrustum); // render backgrounds auto& scene = sceneContext->_scene; @@ -278,7 +278,7 @@ void DrawBackground::run(const SceneContextPointer& sceneContext, const RenderCo for (auto id : items) { inItems.emplace_back(id); } - RenderArgs* args = renderContext->args; + RenderArgs* args = renderContext->getArgs(); doInBatch(args->_context, [=](gpu::Batch& batch) { args->_batch = &batch; batch.enableSkybox(true); From de9e03a3794ac7a6567e498b23930440756500e3 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 18 Dec 2015 10:54:04 -0800 Subject: [PATCH 43/62] remove qxmpp external --- cmake/externals/qxmpp/CMakeLists.txt | 77 ---------------------------- 1 file changed, 77 deletions(-) delete mode 100644 cmake/externals/qxmpp/CMakeLists.txt diff --git a/cmake/externals/qxmpp/CMakeLists.txt b/cmake/externals/qxmpp/CMakeLists.txt deleted file mode 100644 index 600aa7b2ff..0000000000 --- a/cmake/externals/qxmpp/CMakeLists.txt +++ /dev/null @@ -1,77 +0,0 @@ -set(EXTERNAL_NAME qxmpp) - -# we need to find qmake inside QT_DIR -find_program(QMAKE_COMMAND NAME qmake PATHS ${QT_DIR}/bin $ENV{QTTOOLDIR} NO_DEFAULT_PATH) - -if (NOT QMAKE_COMMAND) - message(FATAL_ERROR "Could not find qmake. Qxmpp cannot be compiled without qmake.") -endif () - -if (ANDROID) - set(ANDROID_CMAKE_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" "-DANDROID_NATIVE_API_LEVEL=19") -endif () - -if (WIN32) - find_program(PLATFORM_BUILD_COMMAND nmake PATHS "C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin") - - if (NOT PLATFORM_BUILD_COMMAND) - message(FATAL_ERROR "You asked CMake to grap QXmpp and build it, but nmake was not found. Please make sure the folder containing nmake.exe is in your PATH.") - endif () -else () - find_program(PLATFORM_BUILD_COMMAND make) -endif () - -include(ExternalProject) -ExternalProject_Add( - ${EXTERNAL_NAME} - URL http://qxmpp.googlecode.com/files/qxmpp-0.7.6.tar.gz - URL_MD5 ee45a97313306ded2ff0f6618a3ed1e1 - BUILD_IN_SOURCE 1 - PATCH_COMMAND patch -p2 -t -N --verbose < ${CMAKE_CURRENT_SOURCE_DIR}/qxmpp.patch - CONFIGURE_COMMAND ${QMAKE_COMMAND} PREFIX= - BUILD_COMMAND ${PLATFORM_BUILD_COMMAND} - INSTALL_COMMAND ${PLATFORM_BUILD_COMMAND} install - LOG_DOWNLOAD 1 - LOG_CONFIGURE 1 - LOG_BUILD 1 -) - -# Hide this external target (for ide users) -set_target_properties(${EXTERNAL_NAME} PROPERTIES FOLDER "hidden/externals") - -ExternalProject_Get_Property(${EXTERNAL_NAME} INSTALL_DIR) - -if (CMAKE_GENERATOR STREQUAL Xcode) - find_program(DITTO_COMMAND ditto) - - ExternalProject_Add_Step( - ${EXTERNAL_NAME} - copy-from-xcode-install - COMMENT "Copying from /tmp/hifi.dst${INSTALL_DIR} to move install to proper location" - COMMAND ${DITTO_COMMAND} /tmp/hifi.dst${INSTALL_DIR} ${INSTALL_DIR} - DEPENDEES install - LOG 1 - ) -endif () - -string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) -set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${INSTALL_DIR}/include CACHE FILEPATH "Path to Qxmpp include directory") - -set(_LIB_DIR ${INSTALL_DIR}/lib) - -if (WIN32) - set(_LIB_EXT "0.lib") - - set(${EXTERNAL_NAME_UPPER}_DLL_PATH ${_LIB_DIR} CACHE PATH "Location of QXmpp DLL") -else () - if (APPLE) - set(_LIB_EXT ".dylib") - else () - set(_LIB_EXT ".so") - endif () - - set(_LIB_PREFIX "lib") -endif () - -set(${EXTERNAL_NAME_UPPER}_LIBRARY_RELEASE ${_LIB_DIR}/${_LIB_PREFIX}qxmpp${_LIB_EXT} CACHE FILEPATH "Path to QXmpp release library") -set(${EXTERNAL_NAME_UPPER}_LIBRARY_DEBUG "" CACHE FILEPATH "Path to QXmpp debug library") From d057239023dcabd7b734e0268a2c3410ef2c23c4 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Fri, 18 Dec 2015 11:48:40 -0800 Subject: [PATCH 44/62] Rename RenderContext::ItemsMeta to ItemsConfig --- interface/src/Application.cpp | 6 +++--- libraries/render-utils/src/RenderDeferredTask.cpp | 14 +++++++------- .../render-utils/src/RenderScriptingInterface.h | 6 +++--- libraries/render/src/render/Engine.h | 10 +++++----- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index fedc64174f..3cd185db0a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3681,7 +3681,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se renderArgs->_viewFrustum = getDisplayViewFrustum(); auto renderInterface = DependencyManager::get(); - auto renderItemsMeta = renderInterface->getItemsMeta(); + auto renderItemsConfig = renderInterface->getItemsConfig(); auto renderTone = renderInterface->getTone(); int drawStatus = renderInterface->getDrawStatus(); bool drawHitEffect = renderInterface->getDrawHitEffect(); @@ -3690,7 +3690,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se bool antialiasingStatus = Menu::getInstance()->isOptionChecked(MenuOption::Antialiasing); bool showOwnedStatus = Menu::getInstance()->isOptionChecked(MenuOption::PhysicsShowOwned); - render::RenderContext renderContext{renderArgs, renderItemsMeta, renderTone}; + render::RenderContext renderContext{renderArgs, renderItemsConfig, renderTone}; renderContext.setOptions(drawStatus, drawHitEffect, occlusionStatus, antialiasingStatus, showOwnedStatus); _renderEngine->setRenderContext(renderContext); @@ -3700,7 +3700,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se myAvatar->endRenderRun(); auto engineContext = _renderEngine->getRenderContext(); - renderInterface->setItemCounts(engineContext->getItemsMeta()); + renderInterface->setItemCounts(engineContext->getItemsConfig()); } activeRenderingThread = nullptr; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 820f2b86bb..2594c9503e 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -53,8 +53,8 @@ RenderDeferredTask::RenderDeferredTask() : Task() { // CPU only, create the list of renderedOpaques items _jobs.push_back(Job(new FetchItems::JobModel("FetchOpaque", FetchItems([](const RenderContextPointer& context, int count) { - context->getItemsMeta()._opaque._numFeed = count; - auto& opaque = context->getItemsMeta()._opaque; + context->getItemsConfig()._opaque._numFeed = count; + auto& opaque = context->getItemsConfig()._opaque; }) ))); _jobs.push_back(Job(new CullItemsOpaque::JobModel("CullOpaque", _jobs.back().getOutput()))); @@ -65,7 +65,7 @@ RenderDeferredTask::RenderDeferredTask() : Task() { _jobs.push_back(Job(new FetchItems::JobModel("FetchTransparent", FetchItems(ItemFilter::Builder::transparentShape().withoutLayered(), [](const RenderContextPointer& context, int count) { - context->getItemsMeta()._transparent._numFeed = count; + context->getItemsConfig()._transparent._numFeed = count; }) ))); _jobs.push_back(Job(new CullItemsTransparent::JobModel("CullTransparent", _jobs.back().getOutput()))); @@ -187,7 +187,7 @@ void DrawOpaqueDeferred::run(const SceneContextPointer& sceneContext, const Rend batch.setStateScissorRect(args->_viewport); args->_batch = &batch; - auto& opaque = renderContext->getItemsMeta()._opaque; + auto& opaque = renderContext->getItemsConfig()._opaque; opaque._numDrawn = (int)inItems.size(); glm::mat4 projMat; @@ -217,7 +217,7 @@ void DrawTransparentDeferred::run(const SceneContextPointer& sceneContext, const batch.setStateScissorRect(args->_viewport); args->_batch = &batch; - auto& transparent = renderContext->getItemsMeta()._transparent; + auto& transparent = renderContext->getItemsConfig()._transparent; transparent._numDrawn = (int)inItems.size(); glm::mat4 projMat; @@ -270,7 +270,7 @@ void DrawOverlay3D::run(const SceneContextPointer& sceneContext, const RenderCon inItems.emplace_back(id); } } - auto& overlay3D = renderContext->getItemsMeta()._overlay3D; + auto& overlay3D = renderContext->getItemsConfig()._overlay3D; overlay3D._numFeed = (int)inItems.size(); overlay3D._numDrawn = (int)inItems.size(); @@ -304,7 +304,7 @@ void DrawOverlay3D::run(const SceneContextPointer& sceneContext, const RenderCon batch.setPipeline(getOpaquePipeline()); batch.setResourceTexture(0, args->_whiteTexture); - renderItems(sceneContext, renderContext, inItems, renderContext->getItemsMeta()._overlay3D._maxDrawn); + renderItems(sceneContext, renderContext, inItems, renderContext->getItemsConfig()._overlay3D._maxDrawn); }); args->_batch = nullptr; args->_whiteTexture.reset(); diff --git a/libraries/render-utils/src/RenderScriptingInterface.h b/libraries/render-utils/src/RenderScriptingInterface.h index ec3b5be669..8e33d7b929 100644 --- a/libraries/render-utils/src/RenderScriptingInterface.h +++ b/libraries/render-utils/src/RenderScriptingInterface.h @@ -72,15 +72,15 @@ class RenderScriptingInterface : public QObject, public Dependency { inline int getDrawStatus() { return _drawStatus; } inline bool getDrawHitEffect() { return _drawHitEffect; } - inline const render::RenderContext::ItemsMeta& getItemsMeta() { return _items; } + inline const render::RenderContext::ItemsConfig& getItemsConfig() { return _items; } inline const render::RenderContext::Tone& getTone() { return _tone; } - void setItemCounts(const render::RenderContext::ItemsMeta& items) { _items.setCounts(items); }; + void setItemCounts(const render::RenderContext::ItemsConfig& items) { _items.setCounts(items); }; protected: RenderScriptingInterface(); ~RenderScriptingInterface() {}; - render::RenderContext::ItemsMeta _items; + render::RenderContext::ItemsConfig _items; render::RenderContext::Tone _tone; // Options diff --git a/libraries/render/src/render/Engine.h b/libraries/render/src/render/Engine.h index dcfe28a444..3b1bad45e7 100644 --- a/libraries/render/src/render/Engine.h +++ b/libraries/render/src/render/Engine.h @@ -32,8 +32,8 @@ const int showNetworkStatusFlag = 2; class RenderContext { public: - struct ItemsMeta { - inline void setCounts(const ItemsMeta& items) { + struct ItemsConfig { + inline void setCounts(const ItemsConfig& items) { _opaque.setCounts(items._opaque); _transparent.setCounts(items._transparent); _overlay3D.setCounts(items._overlay3D); @@ -75,7 +75,7 @@ public: float _exposure = 0.0; }; - RenderContext(RenderArgs* args, ItemsMeta items, Tone tone) : _args{args}, _items{items}, _tone{tone} {}; + RenderContext(RenderArgs* args, ItemsConfig items, Tone tone) : _args{args}, _items{items}, _tone{tone} {}; RenderContext() : RenderContext(nullptr, {}, {}) {}; inline RenderArgs* getArgs() { return _args; } @@ -83,7 +83,7 @@ public: inline bool getDrawHitEffect() { return _drawHitEffect; } inline bool getOcclusionStatus() { return _occlusionStatus; } inline bool getFxaaStatus() { return _fxaaStatus; } - inline ItemsMeta& getItemsMeta() { return _items; } + inline ItemsConfig& getItemsConfig() { return _items; } inline Tone& getTone() { return _tone; } void setOptions(int drawStatus, bool drawHitEffect, bool occlusion, bool fxaa, bool showOwned); @@ -100,7 +100,7 @@ protected: bool _occlusionStatus = false; bool _fxaaStatus = false; - ItemsMeta _items; + ItemsConfig _items; Tone _tone; }; typedef std::shared_ptr RenderContextPointer; From 674bfa4f370780cb892aa5b85c71d8dd8385b7f3 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Fri, 18 Dec 2015 12:04:21 -0800 Subject: [PATCH 45/62] Replace RenderContext substructs with subclasses --- .../render-utils/src/RenderDeferredTask.cpp | 30 +++++----- .../src/RenderScriptingInterface.cpp | 10 ++-- .../src/RenderScriptingInterface.h | 54 +++++++++--------- libraries/render/src/render/Engine.h | 56 ++++++++++--------- 4 files changed, 77 insertions(+), 73 deletions(-) diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 2594c9503e..ddfb6bc7a3 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -53,8 +53,8 @@ RenderDeferredTask::RenderDeferredTask() : Task() { // CPU only, create the list of renderedOpaques items _jobs.push_back(Job(new FetchItems::JobModel("FetchOpaque", FetchItems([](const RenderContextPointer& context, int count) { - context->getItemsConfig()._opaque._numFeed = count; - auto& opaque = context->getItemsConfig()._opaque; + context->getItemsConfig().opaque.numFeed = count; + auto& opaque = context->getItemsConfig().opaque; }) ))); _jobs.push_back(Job(new CullItemsOpaque::JobModel("CullOpaque", _jobs.back().getOutput()))); @@ -65,7 +65,7 @@ RenderDeferredTask::RenderDeferredTask() : Task() { _jobs.push_back(Job(new FetchItems::JobModel("FetchTransparent", FetchItems(ItemFilter::Builder::transparentShape().withoutLayered(), [](const RenderContextPointer& context, int count) { - context->getItemsConfig()._transparent._numFeed = count; + context->getItemsConfig().transparent.numFeed = count; }) ))); _jobs.push_back(Job(new CullItemsTransparent::JobModel("CullTransparent", _jobs.back().getOutput()))); @@ -166,8 +166,8 @@ void RenderDeferredTask::run(const SceneContextPointer& sceneContext, const Rend setAntialiasingStatus(renderContext->getFxaaStatus()); - setToneMappingExposure(renderContext->getTone()._exposure); - setToneMappingToneCurve(renderContext->getTone()._toneCurve); + setToneMappingExposure(renderContext->getTone().exposure); + setToneMappingToneCurve(renderContext->getTone().toneCurve); renderContext->getArgs()->_context->syncCache(); @@ -187,8 +187,8 @@ void DrawOpaqueDeferred::run(const SceneContextPointer& sceneContext, const Rend batch.setStateScissorRect(args->_viewport); args->_batch = &batch; - auto& opaque = renderContext->getItemsConfig()._opaque; - opaque._numDrawn = (int)inItems.size(); + auto& opaque = renderContext->getItemsConfig().opaque; + opaque.numDrawn = (int)inItems.size(); glm::mat4 projMat; Transform viewMat; @@ -202,7 +202,7 @@ void DrawOpaqueDeferred::run(const SceneContextPointer& sceneContext, const Rend const float OPAQUE_ALPHA_THRESHOLD = 0.5f; args->_alphaThreshold = OPAQUE_ALPHA_THRESHOLD; } - renderItems(sceneContext, renderContext, inItems, opaque._maxDrawn); + renderItems(sceneContext, renderContext, inItems, opaque.maxDrawn); args->_batch = nullptr; }); } @@ -217,8 +217,8 @@ void DrawTransparentDeferred::run(const SceneContextPointer& sceneContext, const batch.setStateScissorRect(args->_viewport); args->_batch = &batch; - auto& transparent = renderContext->getItemsConfig()._transparent; - transparent._numDrawn = (int)inItems.size(); + auto& transparent = renderContext->getItemsConfig().transparent; + transparent.numDrawn = (int)inItems.size(); glm::mat4 projMat; Transform viewMat; @@ -231,7 +231,7 @@ void DrawTransparentDeferred::run(const SceneContextPointer& sceneContext, const const float TRANSPARENT_ALPHA_THRESHOLD = 0.0f; args->_alphaThreshold = TRANSPARENT_ALPHA_THRESHOLD; - renderItems(sceneContext, renderContext, inItems, transparent._maxDrawn); + renderItems(sceneContext, renderContext, inItems, transparent.maxDrawn); args->_batch = nullptr; }); } @@ -270,9 +270,9 @@ void DrawOverlay3D::run(const SceneContextPointer& sceneContext, const RenderCon inItems.emplace_back(id); } } - auto& overlay3D = renderContext->getItemsConfig()._overlay3D; - overlay3D._numFeed = (int)inItems.size(); - overlay3D._numDrawn = (int)inItems.size(); + auto& overlay3D = renderContext->getItemsConfig().overlay3D; + overlay3D.numFeed = (int)inItems.size(); + overlay3D.numDrawn = (int)inItems.size(); if (!inItems.empty()) { RenderArgs* args = renderContext->getArgs(); @@ -304,7 +304,7 @@ void DrawOverlay3D::run(const SceneContextPointer& sceneContext, const RenderCon batch.setPipeline(getOpaquePipeline()); batch.setResourceTexture(0, args->_whiteTexture); - renderItems(sceneContext, renderContext, inItems, renderContext->getItemsConfig()._overlay3D._maxDrawn); + renderItems(sceneContext, renderContext, inItems, renderContext->getItemsConfig().overlay3D.maxDrawn); }); args->_batch = nullptr; args->_whiteTexture.reset(); diff --git a/libraries/render-utils/src/RenderScriptingInterface.cpp b/libraries/render-utils/src/RenderScriptingInterface.cpp index 3b283e3058..71ca929cfd 100644 --- a/libraries/render-utils/src/RenderScriptingInterface.cpp +++ b/libraries/render-utils/src/RenderScriptingInterface.cpp @@ -15,18 +15,18 @@ RenderScriptingInterface::RenderScriptingInterface() {}; void RenderScriptingInterface::setEngineToneMappingToneCurve(const QString& toneCurve) { if (toneCurve == QString("None")) { - _tone._toneCurve = 0; + _tone.toneCurve = 0; } else if (toneCurve == QString("Gamma22")) { - _tone._toneCurve = 1; + _tone.toneCurve = 1; } else if (toneCurve == QString("Reinhard")) { - _tone._toneCurve = 2; + _tone.toneCurve = 2; } else if (toneCurve == QString("Filmic")) { - _tone._toneCurve = 3; + _tone.toneCurve = 3; } } QString RenderScriptingInterface::getEngineToneMappingToneCurve() const { - switch (_tone._toneCurve) { + switch (_tone.toneCurve) { case 0: return QString("None"); case 1: diff --git a/libraries/render-utils/src/RenderScriptingInterface.h b/libraries/render-utils/src/RenderScriptingInterface.h index 8e33d7b929..49926864df 100644 --- a/libraries/render-utils/src/RenderScriptingInterface.h +++ b/libraries/render-utils/src/RenderScriptingInterface.h @@ -22,35 +22,35 @@ class RenderScriptingInterface : public QObject, public Dependency { SINGLETON_DEPENDENCY public: - Q_INVOKABLE void setEngineRenderOpaque(bool renderOpaque) { _items._opaque._render = renderOpaque; }; - Q_INVOKABLE bool doEngineRenderOpaque() const { return _items._opaque._render; } - Q_INVOKABLE void setEngineRenderTransparent(bool renderTransparent) { _items._transparent._render = renderTransparent; }; - Q_INVOKABLE bool doEngineRenderTransparent() const { return _items._transparent._render; } + Q_INVOKABLE void setEngineRenderOpaque(bool renderOpaque) { _items.opaque.render = renderOpaque; }; + Q_INVOKABLE bool doEngineRenderOpaque() const { return _items.opaque.render; } + Q_INVOKABLE void setEngineRenderTransparent(bool renderTransparent) { _items.transparent.render = renderTransparent; }; + Q_INVOKABLE bool doEngineRenderTransparent() const { return _items.transparent.render; } - Q_INVOKABLE void setEngineCullOpaque(bool cullOpaque) { _items._opaque._cull = cullOpaque; }; - Q_INVOKABLE bool doEngineCullOpaque() const { return _items._opaque._cull; } - Q_INVOKABLE void setEngineCullTransparent(bool cullTransparent) { _items._transparent._cull = cullTransparent; }; - Q_INVOKABLE bool doEngineCullTransparent() const { return _items._transparent._cull; } + Q_INVOKABLE void setEngineCullOpaque(bool cullOpaque) { _items.opaque.cull = cullOpaque; }; + Q_INVOKABLE bool doEngineCullOpaque() const { return _items.opaque.cull; } + Q_INVOKABLE void setEngineCullTransparent(bool cullTransparent) { _items.transparent.cull = cullTransparent; }; + Q_INVOKABLE bool doEngineCullTransparent() const { return _items.transparent.cull; } - Q_INVOKABLE void setEngineSortOpaque(bool sortOpaque) { _items._opaque._sort = sortOpaque; }; - Q_INVOKABLE bool doEngineSortOpaque() const { return _items._opaque._sort; } - Q_INVOKABLE void setEngineSortTransparent(bool sortTransparent) { _items._transparent._sort = sortTransparent; }; - Q_INVOKABLE bool doEngineSortTransparent() const { return _items._transparent._sort; } + Q_INVOKABLE void setEngineSortOpaque(bool sortOpaque) { _items.opaque.sort = sortOpaque; }; + Q_INVOKABLE bool doEngineSortOpaque() const { return _items.opaque.sort; } + Q_INVOKABLE void setEngineSortTransparent(bool sortTransparent) { _items.transparent.sort = sortTransparent; }; + Q_INVOKABLE bool doEngineSortTransparent() const { return _items.transparent.sort; } - Q_INVOKABLE int getEngineNumDrawnOpaqueItems() { return _items._opaque._numDrawn; } - Q_INVOKABLE int getEngineNumDrawnTransparentItems() { return _items._transparent._numDrawn; } - Q_INVOKABLE int getEngineNumDrawnOverlay3DItems() { return _items._overlay3D._numDrawn; } + Q_INVOKABLE int getEngineNumDrawnOpaqueItems() { return _items.opaque.numDrawn; } + Q_INVOKABLE int getEngineNumDrawnTransparentItems() { return _items.transparent.numDrawn; } + Q_INVOKABLE int getEngineNumDrawnOverlay3DItems() { return _items.overlay3D.numDrawn; } - Q_INVOKABLE int getEngineNumFeedOpaqueItems() { return _items._opaque._numFeed; } - Q_INVOKABLE int getEngineNumFeedTransparentItems() { return _items._transparent._numFeed; } - Q_INVOKABLE int getEngineNumFeedOverlay3DItems() { return _items._overlay3D._numFeed; } + Q_INVOKABLE int getEngineNumFeedOpaqueItems() { return _items.opaque.numFeed; } + Q_INVOKABLE int getEngineNumFeedTransparentItems() { return _items.transparent.numFeed; } + Q_INVOKABLE int getEngineNumFeedOverlay3DItems() { return _items.overlay3D.numFeed; } - Q_INVOKABLE void setEngineMaxDrawnOpaqueItems(int count) { _items._opaque._maxDrawn = count; } - Q_INVOKABLE int getEngineMaxDrawnOpaqueItems() { return _items._opaque._maxDrawn; } - Q_INVOKABLE void setEngineMaxDrawnTransparentItems(int count) { _items._transparent._maxDrawn = count; } - Q_INVOKABLE int getEngineMaxDrawnTransparentItems() { return _items._transparent._maxDrawn; } - Q_INVOKABLE void setEngineMaxDrawnOverlay3DItems(int count) { _items._overlay3D._maxDrawn = count; } - Q_INVOKABLE int getEngineMaxDrawnOverlay3DItems() { return _items._overlay3D._maxDrawn; } + Q_INVOKABLE void setEngineMaxDrawnOpaqueItems(int count) { _items.opaque.maxDrawn = count; } + Q_INVOKABLE int getEngineMaxDrawnOpaqueItems() { return _items.opaque.maxDrawn; } + Q_INVOKABLE void setEngineMaxDrawnTransparentItems(int count) { _items.transparent.maxDrawn = count; } + Q_INVOKABLE int getEngineMaxDrawnTransparentItems() { return _items.transparent.maxDrawn; } + Q_INVOKABLE void setEngineMaxDrawnOverlay3DItems(int count) { _items.overlay3D.maxDrawn = count; } + Q_INVOKABLE int getEngineMaxDrawnOverlay3DItems() { return _items.overlay3D.maxDrawn; } Q_INVOKABLE void setEngineDeferredDebugMode(int mode) { _deferredDebugMode = mode; } Q_INVOKABLE int getEngineDeferredDebugMode() { return _deferredDebugMode; } @@ -63,12 +63,12 @@ class RenderScriptingInterface : public QObject, public Dependency { Q_INVOKABLE void setEngineDisplayHitEffect(bool display) { _drawHitEffect = display; } Q_INVOKABLE bool doEngineDisplayHitEffect() { return _drawHitEffect; } - Q_INVOKABLE void setEngineToneMappingExposure(float exposure) { _tone._exposure = exposure; } - Q_INVOKABLE float getEngineToneMappingExposure() const { return _tone._exposure; } + Q_INVOKABLE void setEngineToneMappingExposure(float exposure) { _tone.exposure = exposure; } + Q_INVOKABLE float getEngineToneMappingExposure() const { return _tone.exposure; } Q_INVOKABLE void setEngineToneMappingToneCurve(const QString& curve); Q_INVOKABLE QString getEngineToneMappingToneCurve() const; - int getEngineToneMappingToneCurveValue() const { return _tone._toneCurve; } + int getEngineToneMappingToneCurveValue() const { return _tone.toneCurve; } inline int getDrawStatus() { return _drawStatus; } inline bool getDrawHitEffect() { return _drawHitEffect; } diff --git a/libraries/render/src/render/Engine.h b/libraries/render/src/render/Engine.h index 3b1bad45e7..40196e320e 100644 --- a/libraries/render/src/render/Engine.h +++ b/libraries/render/src/render/Engine.h @@ -32,59 +32,63 @@ const int showNetworkStatusFlag = 2; class RenderContext { public: - struct ItemsConfig { + class ItemsConfig { + public: inline void setCounts(const ItemsConfig& items) { - _opaque.setCounts(items._opaque); - _transparent.setCounts(items._transparent); - _overlay3D.setCounts(items._overlay3D); + opaque.setCounts(items.opaque); + transparent.setCounts(items.transparent); + overlay3D.setCounts(items.overlay3D); }; - struct Counter { + class Counter { + public: Counter() {}; Counter(const Counter& counter) { - _numFeed = _numDrawn = 0; - _maxDrawn = counter._maxDrawn; + numFeed = numDrawn = 0; + maxDrawn = counter.maxDrawn; }; inline void setCounts(const Counter& counter) { - _numFeed = counter._numFeed; - _numDrawn = counter._numDrawn; + numFeed = counter.numFeed; + numDrawn = counter.numDrawn; }; - int _numFeed = 0; - int _numDrawn = 0; - int _maxDrawn = -1; + int numFeed = 0; + int numDrawn = 0; + int maxDrawn = -1; }; - struct State : public Counter { - bool _render = true; - bool _cull = true; - bool _sort = true; + class State : public Counter { + public: + bool render = true; + bool cull = true; + bool sort = true; - Counter _counter{}; + Counter counter{}; }; - // TODO: Store state/counter in a map instead of manually enumerated members - State _opaque{}; - State _transparent{}; - Counter _overlay3D{}; + // TODO: If member count increases, store counters in a map instead of multiple members + State opaque{}; + State transparent{}; + Counter overlay3D{}; }; - struct Tone { - int _toneCurve = 3; - float _exposure = 0.0; + class Tone { + public: + int toneCurve = 3; + float exposure = 0.0; }; RenderContext(RenderArgs* args, ItemsConfig items, Tone tone) : _args{args}, _items{items}, _tone{tone} {}; RenderContext() : RenderContext(nullptr, {}, {}) {}; inline RenderArgs* getArgs() { return _args; } + inline ItemsConfig& getItemsConfig() { return _items; } + inline Tone& getTone() { return _tone; } inline int getDrawStatus() { return _drawStatus; } inline bool getDrawHitEffect() { return _drawHitEffect; } inline bool getOcclusionStatus() { return _occlusionStatus; } inline bool getFxaaStatus() { return _fxaaStatus; } - inline ItemsConfig& getItemsConfig() { return _items; } - inline Tone& getTone() { return _tone; } void setOptions(int drawStatus, bool drawHitEffect, bool occlusion, bool fxaa, bool showOwned); // Debugging From 3014b3bd5ba410659c09bbee1bb3f1c2c5d00f81 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 18 Dec 2015 12:50:21 -0800 Subject: [PATCH 46/62] Adding Gamma correction to all the Color coming for the attribute stream if used as color --- .../entities-renderer/src/paintStroke.slv | 4 +- libraries/gpu/src/gpu/Color.slh | 52 +++++++++++++++++++ libraries/render-utils/src/animdebugdraw.slv | 5 +- libraries/render-utils/src/model.slv | 8 ++- libraries/render-utils/src/model_lightmap.slv | 6 +-- .../src/model_lightmap_normal_map.slv | 6 +-- .../render-utils/src/model_normal_map.slv | 5 +- libraries/render-utils/src/overlay3D.slv | 5 +- libraries/render-utils/src/simple.slv | 5 +- libraries/render-utils/src/skin_model.slv | 5 +- .../src/skin_model_normal_map.slv | 5 +- .../src/standardTransformPNTC.slv | 5 +- libraries/render-utils/src/stars.slv | 5 +- 13 files changed, 79 insertions(+), 37 deletions(-) create mode 100644 libraries/gpu/src/gpu/Color.slh diff --git a/libraries/entities-renderer/src/paintStroke.slv b/libraries/entities-renderer/src/paintStroke.slv index 7d7523deb9..c7dd112bcc 100644 --- a/libraries/entities-renderer/src/paintStroke.slv +++ b/libraries/entities-renderer/src/paintStroke.slv @@ -13,8 +13,8 @@ // <@include gpu/Inputs.slh@> +<@include gpu/Color.slh@> <@include gpu/Transform.slh@> - <$declareStandardTransform()$> // the interpolated normal @@ -30,7 +30,7 @@ void main(void) { varTexcoord = inTexCoord0.st; // pass along the diffuse color - varColor = inColor; + varColor = colorToLinearRGBA(inColor); // standard transform TransformCamera cam = getTransformCamera(); diff --git a/libraries/gpu/src/gpu/Color.slh b/libraries/gpu/src/gpu/Color.slh new file mode 100644 index 0000000000..f633e6e2d4 --- /dev/null +++ b/libraries/gpu/src/gpu/Color.slh @@ -0,0 +1,52 @@ + +<@if not GPU_COLOR_SLH@> +<@def GPU_COLOR_SLH@> + 0.04045 + // constants: + // T = 0.04045 + // A = 1 / 1.055 = 0.94786729857 + // B = 0.055 * A = 0.05213270142 + // C = 1 / 12.92 = 0.0773993808 + // G = 2.4 + const float T = 0.04045; + const float A = 0.947867; + const float B = 0.052132; + const float C = 0.077399; + const float G = 2.4; + + if (cs > T) { + return pow((cs * A + B), G); + } else { + return cs * C; + } +} + +vec3 colorToLinear(vec3 srgb) { + return vec3(colorComponentToLinear(srgb.x), colorComponentToLinear(srgb.y), colorComponentToLinear(srgb.z)); +} +!> + +vec3 colorToLinearRGB(vec3 srgb) { + const float GAMMA_22 = 2.2; + return pow(srgb, vec3(GAMMA_22)); +} + +vec4 colorToLinearRGBA(vec4 srgba) { + return vec4(colorToLinearRGB(srgba.xyz), srgba.w); +} + +<@endif@> \ No newline at end of file diff --git a/libraries/render-utils/src/animdebugdraw.slv b/libraries/render-utils/src/animdebugdraw.slv index f3117714b0..3cb356c055 100644 --- a/libraries/render-utils/src/animdebugdraw.slv +++ b/libraries/render-utils/src/animdebugdraw.slv @@ -9,16 +9,15 @@ // <@include gpu/Inputs.slh@> - +<@include gpu/Color.slh@> <@include gpu/Transform.slh@> - <$declareStandardTransform()$> out vec4 _color; void main(void) { // pass along the diffuse color - _color = inColor.rgba; + _color = colorToLinearRGBA(inColor.rgba); TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); diff --git a/libraries/render-utils/src/model.slv b/libraries/render-utils/src/model.slv index 6d56833de1..47de20a5d9 100755 --- a/libraries/render-utils/src/model.slv +++ b/libraries/render-utils/src/model.slv @@ -12,9 +12,8 @@ // <@include gpu/Inputs.slh@> - +<@include gpu/Color.slh@> <@include gpu/Transform.slh@> - <$declareStandardTransform()$> const int MAX_TEXCOORDS = 2; @@ -27,9 +26,8 @@ out vec3 _color; out vec2 _texCoord0; void main(void) { - - // pass along the diffuse color - _color = inColor.xyz; + // pass along the diffuse color in linear space + _color = colorToLinearRGB(inColor.xyz); // and the texture coordinates _texCoord0 = (texcoordMatrices[0] * vec4(inTexCoord0.st, 0.0, 1.0)).st; diff --git a/libraries/render-utils/src/model_lightmap.slv b/libraries/render-utils/src/model_lightmap.slv index 7742896228..eacc91245c 100755 --- a/libraries/render-utils/src/model_lightmap.slv +++ b/libraries/render-utils/src/model_lightmap.slv @@ -13,9 +13,8 @@ // <@include gpu/Inputs.slh@> - +<@include gpu/Color.slh@> <@include gpu/Transform.slh@> - <$declareStandardTransform()$> const int MAX_TEXCOORDS = 2; @@ -29,7 +28,8 @@ out vec3 _normal; out vec3 _color; void main(void) { - _color = inColor.xyz; + // pass along the diffuse color in linear space + _color = colorToLinearRGB(inColor.xyz); // and the texture coordinates _texCoord0 = (texcoordMatrices[0] * vec4(inTexCoord0.st, 0.0, 1.0)).st; diff --git a/libraries/render-utils/src/model_lightmap_normal_map.slv b/libraries/render-utils/src/model_lightmap_normal_map.slv index f63030301f..6046a67e10 100755 --- a/libraries/render-utils/src/model_lightmap_normal_map.slv +++ b/libraries/render-utils/src/model_lightmap_normal_map.slv @@ -13,9 +13,8 @@ // <@include gpu/Inputs.slh@> - +<@include gpu/Color.slh@> <@include gpu/Transform.slh@> - <$declareStandardTransform()$> const int MAX_TEXCOORDS = 2; @@ -30,7 +29,8 @@ out vec3 _tangent; out vec3 _color; void main(void) { - _color = inColor.xyz; + // pass along the diffuse color in linear space + _color = colorToLinearRGB(inColor.xyz); // and the texture coordinates _texCoord0 = (texcoordMatrices[0] * vec4(inTexCoord0.st, 0.0, 1.0)).st; diff --git a/libraries/render-utils/src/model_normal_map.slv b/libraries/render-utils/src/model_normal_map.slv index e989c1c294..5ed4e37278 100755 --- a/libraries/render-utils/src/model_normal_map.slv +++ b/libraries/render-utils/src/model_normal_map.slv @@ -13,9 +13,8 @@ // <@include gpu/Inputs.slh@> - +<@include gpu/Color.slh@> <@include gpu/Transform.slh@> - <$declareStandardTransform()$> const int MAX_TEXCOORDS = 2; @@ -30,7 +29,7 @@ out vec3 _color; void main(void) { // pass along the diffuse color - _color = inColor.rgb; + _color = colorToLinearRGB(inColor.xyz); // and the texture coordinates _texCoord0 = (texcoordMatrices[0] * vec4(inTexCoord0.xy, 0.0, 1.0)).st; diff --git a/libraries/render-utils/src/overlay3D.slv b/libraries/render-utils/src/overlay3D.slv index a57f02d854..74416f0c1f 100644 --- a/libraries/render-utils/src/overlay3D.slv +++ b/libraries/render-utils/src/overlay3D.slv @@ -11,9 +11,8 @@ // <@include gpu/Inputs.slh@> - +<@include gpu/Color.slh@> <@include gpu/Transform.slh@> - <$declareStandardTransform()$> out vec2 varTexcoord; @@ -30,7 +29,7 @@ void main(void) { varTexcoord = inTexCoord0.xy; // pass along the color - varColor = inColor; + varColor = colorToLinearRGBA(inColor); // standard transform TransformCamera cam = getTransformCamera(); diff --git a/libraries/render-utils/src/simple.slv b/libraries/render-utils/src/simple.slv index 823654ec27..59b16cf0e5 100644 --- a/libraries/render-utils/src/simple.slv +++ b/libraries/render-utils/src/simple.slv @@ -13,9 +13,8 @@ // <@include gpu/Inputs.slh@> - +<@include gpu/Color.slh@> <@include gpu/Transform.slh@> - <$declareStandardTransform()$> uniform bool Instanced = false; @@ -28,7 +27,7 @@ out vec2 _texCoord0; out vec4 _position; void main(void) { - _color = inColor.rgb; + _color = colorToLinearRGB(inColor.rgb); _texCoord0 = inTexCoord0.st; _position = inPosition; _modelNormal = inNormal.xyz; diff --git a/libraries/render-utils/src/skin_model.slv b/libraries/render-utils/src/skin_model.slv index cba419dd4d..8ab475e1fd 100755 --- a/libraries/render-utils/src/skin_model.slv +++ b/libraries/render-utils/src/skin_model.slv @@ -13,9 +13,8 @@ // <@include gpu/Inputs.slh@> - +<@include gpu/Color.slh@> <@include gpu/Transform.slh@> - <$declareStandardTransform()$> <@include Skinning.slh@> @@ -34,7 +33,7 @@ void main(void) { skinPositionNormal(inSkinClusterIndex, inSkinClusterWeight, inPosition, inNormal.xyz, position, interpolatedNormal); // pass along the diffuse color - _color = inColor.rgb; + _color = colorToLinearRGB(inColor.rgb); // and the texture coordinates _texCoord0 = (texcoordMatrices[0] * vec4(inTexCoord0.st, 0.0, 1.0)).st; diff --git a/libraries/render-utils/src/skin_model_normal_map.slv b/libraries/render-utils/src/skin_model_normal_map.slv index 5dfe5ba957..cec93a024e 100755 --- a/libraries/render-utils/src/skin_model_normal_map.slv +++ b/libraries/render-utils/src/skin_model_normal_map.slv @@ -13,9 +13,8 @@ // <@include gpu/Inputs.slh@> - +<@include gpu/Color.slh@> <@include gpu/Transform.slh@> - <$declareStandardTransform()$> <@include Skinning.slh@> @@ -36,7 +35,7 @@ void main(void) { skinPositionNormalTangent(inSkinClusterIndex, inSkinClusterWeight, inPosition, inNormal.xyz, inTangent.xyz, position, interpolatedNormal.xyz, interpolatedTangent.xyz); // pass along the diffuse color - _color = inColor.rgb; + _color = colorToLinearRGB(inColor.rgb); // and the texture coordinates _texCoord0 = (texcoordMatrices[0] * vec4(inTexCoord0.st, 0.0, 1.0)).st; diff --git a/libraries/render-utils/src/standardTransformPNTC.slv b/libraries/render-utils/src/standardTransformPNTC.slv index 340dfd9c8e..f7e72b6997 100644 --- a/libraries/render-utils/src/standardTransformPNTC.slv +++ b/libraries/render-utils/src/standardTransformPNTC.slv @@ -13,9 +13,8 @@ // <@include gpu/Inputs.slh@> - +<@include gpu/Color.slh@> <@include gpu/Transform.slh@> - <$declareStandardTransform()$> out vec3 varPosition; @@ -25,7 +24,7 @@ out vec4 varColor; void main(void) { varTexCoord0 = inTexCoord0.st; - varColor = inColor; + varColor = colorToLinearRGBA(inColor); // standard transform TransformCamera cam = getTransformCamera(); diff --git a/libraries/render-utils/src/stars.slv b/libraries/render-utils/src/stars.slv index b9ad736d5e..d00bb8b7dd 100644 --- a/libraries/render-utils/src/stars.slv +++ b/libraries/render-utils/src/stars.slv @@ -13,9 +13,8 @@ // <@include gpu/Inputs.slh@> - +<@include gpu/Color.slh@> <@include gpu/Transform.slh@> - <$declareStandardTransform()$> // TODO we need to get the viewport resolution and FOV passed to us so we can modify the point size @@ -26,7 +25,7 @@ out vec4 varColor; out float varSize; void main(void) { - varColor = inColor.rgba; + varColor = colorToLinearRGBA(inColor); // standard transform TransformCamera cam = getTransformCamera(); From 2c2b794683104c4c53fef39c26b5877c51465464 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Fri, 18 Dec 2015 13:16:05 -0800 Subject: [PATCH 47/62] Stop modelMesh render if pipeline is not found --- libraries/render-utils/src/MeshPartPayload.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/render-utils/src/MeshPartPayload.cpp b/libraries/render-utils/src/MeshPartPayload.cpp index 2d8d7b598b..2fae09a158 100644 --- a/libraries/render-utils/src/MeshPartPayload.cpp +++ b/libraries/render-utils/src/MeshPartPayload.cpp @@ -470,6 +470,9 @@ void ModelMeshPartPayload::render(RenderArgs* args) const { ModelRender::pickPrograms(batch, mode, translucentMesh, alphaThreshold, hasLightmap, hasTangents, hasSpecular, isSkinned, wireframe, args, locations); + if (!locations) { // the pipeline could not be found + return; + } // Bind the model transform and the skinCLusterMatrices if needed bindTransform(batch, locations); From 0492bb1c6dd5473d309121d8467d4159f52ee133 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 18 Dec 2015 13:50:28 -0800 Subject: [PATCH 48/62] Final cleans and tests using R11G11B10 for lighting buffer --- libraries/render-utils/src/FramebufferCache.cpp | 5 +++-- libraries/render-utils/src/ToneMappingEffect.cpp | 11 ++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index e64e245806..9f3d4ba0fe 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -89,9 +89,10 @@ void FramebufferCache::createPrimaryFramebuffer() { auto smoothSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR); + // FIXME: Decide on the proper one, let s stick to R11G11B10 for now //_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, smoothSampler)); + _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)); _lightingFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); _lightingFramebuffer->setRenderBuffer(0, _lightingTexture); _lightingFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); diff --git a/libraries/render-utils/src/ToneMappingEffect.cpp b/libraries/render-utils/src/ToneMappingEffect.cpp index 29e5da6e2a..a00a66fe69 100644 --- a/libraries/render-utils/src/ToneMappingEffect.cpp +++ b/libraries/render-utils/src/ToneMappingEffect.cpp @@ -64,13 +64,9 @@ void ToneMappingEffect::init() { out vec4 outFragColor; void main(void) { - vec4 fragColorRaw = textureLod(colorMap, varTexCoord0, 0); + vec4 fragColorRaw = texture(colorMap, varTexCoord0); vec3 fragColor = fragColorRaw.xyz; -/* - vec4 fragColorAverage = textureLod(colorMap, varTexCoord0, 10); - float averageIntensity = length(fragColorAverage.xyz); - fragColor /= averageIntensity; -*/ + vec3 srcColor = fragColor * getTwoPowExposure(); int toneCurve = getToneCurve(); @@ -124,7 +120,8 @@ void ToneMappingEffect::render(RenderArgs* args) { auto destFbo = framebufferCache->getPrimaryFramebuffer(); batch.setFramebuffer(destFbo); - batch.generateTextureMips(lightingBuffer); + // FIXME: Generate the Luminosity map + //batch.generateTextureMips(lightingBuffer); batch.setViewportTransform(args->_viewport); batch.setProjectionTransform(glm::mat4()); From f24800cf10181b3cb89a21d9df9f982739f8ea37 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 18 Dec 2015 15:35:01 -0800 Subject: [PATCH 49/62] Change the default tone curve to jusimple gamma correct and fix the renaming in the renderENgineDebug script --- examples/utilities/tools/renderEngineDebug.js | 62 +++++++++---------- libraries/render/src/render/Engine.h | 2 +- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/examples/utilities/tools/renderEngineDebug.js b/examples/utilities/tools/renderEngineDebug.js index 5e89bff53b..9412f57ca4 100755 --- a/examples/utilities/tools/renderEngineDebug.js +++ b/examples/utilities/tools/renderEngineDebug.js @@ -50,46 +50,46 @@ function CounterWidget(parentPanel, name, feedGetter, drawGetter, capSetter, cap }; var opaquesCounter = new CounterWidget(panel, "Opaques", - function () { return Scene.getEngineNumFeedOpaqueItems(); }, - function () { return Scene.getEngineNumDrawnOpaqueItems(); }, - function(value) { Scene.setEngineMaxDrawnOpaqueItems(value); }, - function () { return Scene.getEngineMaxDrawnOpaqueItems(); } + function () { return Render.getEngineNumFeedOpaqueItems(); }, + function () { return Render.getEngineNumDrawnOpaqueItems(); }, + function(value) { Render.setEngineMaxDrawnOpaqueItems(value); }, + function () { return Render.getEngineMaxDrawnOpaqueItems(); } ); var transparentsCounter = new CounterWidget(panel, "Transparents", - function () { return Scene.getEngineNumFeedTransparentItems(); }, - function () { return Scene.getEngineNumDrawnTransparentItems(); }, - function(value) { Scene.setEngineMaxDrawnTransparentItems(value); }, - function () { return Scene.getEngineMaxDrawnTransparentItems(); } + function () { return Render.getEngineNumFeedTransparentItems(); }, + function () { return Render.getEngineNumDrawnTransparentItems(); }, + function(value) { Render.setEngineMaxDrawnTransparentItems(value); }, + function () { return Render.getEngineMaxDrawnTransparentItems(); } ); var overlaysCounter = new CounterWidget(panel, "Overlays", - function () { return Scene.getEngineNumFeedOverlay3DItems(); }, - function () { return Scene.getEngineNumDrawnOverlay3DItems(); }, - function(value) { Scene.setEngineMaxDrawnOverlay3DItems(value); }, - function () { return Scene.getEngineMaxDrawnOverlay3DItems(); } + function () { return Render.getEngineNumFeedOverlay3DItems(); }, + function () { return Render.getEngineNumDrawnOverlay3DItems(); }, + function(value) { Render.setEngineMaxDrawnOverlay3DItems(value); }, + function () { return Render.getEngineMaxDrawnOverlay3DItems(); } ); var resizing = false; var previousMode = Settings.getValue(SETTINGS_KEY, -1); Menu.addActionGroup(MENU, ACTIONS, ACTIONS[previousMode + 1]); -Scene.setEngineDeferredDebugMode(previousMode); -Scene.setEngineDeferredDebugSize({ x: 0.0, y: -1.0, z: 1.0, w: 1.0 }); // Reset to default size +Render.setEngineDeferredDebugMode(previousMode); +Render.setEngineDeferredDebugSize({ x: 0.0, y: -1.0, z: 1.0, w: 1.0 }); // Reset to default size function setEngineDeferredDebugSize(eventX) { var scaledX = (2.0 * (eventX / Window.innerWidth) - 1.0).clamp(-1.0, 1.0); - Scene.setEngineDeferredDebugSize({ x: scaledX, y: -1.0, z: 1.0, w: 1.0 }); + Render.setEngineDeferredDebugSize({ x: scaledX, y: -1.0, z: 1.0, w: 1.0 }); } function shouldStartResizing(eventX) { - var x = Math.abs(eventX - Window.innerWidth * (1.0 + Scene.getEngineDeferredDebugSize().x) / 2.0); - var mode = Scene.getEngineDeferredDebugMode(); + var x = Math.abs(eventX - Window.innerWidth * (1.0 + Render.getEngineDeferredDebugSize().x) / 2.0); + var mode = Render.getEngineDeferredDebugMode(); return mode !== -1 && x < 20; } function menuItemEvent(menuItem) { var index = ACTIONS.indexOf(menuItem); if (index >= 0) { - Scene.setEngineDeferredDebugMode(index - 1); + Render.setEngineDeferredDebugMode(index - 1); } } @@ -98,24 +98,24 @@ var showDisplayStatusFlag = 1; var showNetworkStatusFlag = 2; panel.newCheckbox("Display status", - function(value) { Scene.setEngineDisplayItemStatus(value ? - Scene.doEngineDisplayItemStatus() | showDisplayStatusFlag : - Scene.doEngineDisplayItemStatus() & ~showDisplayStatusFlag); }, - function() { return (Scene.doEngineDisplayItemStatus() & showDisplayStatusFlag) > 0; }, + function(value) { Render.setEngineDisplayItemStatus(value ? + Render.doEngineDisplayItemStatus() | showDisplayStatusFlag : + Render.doEngineDisplayItemStatus() & ~showDisplayStatusFlag); }, + function() { return (Render.doEngineDisplayItemStatus() & showDisplayStatusFlag) > 0; }, function(value) { return (value & showDisplayStatusFlag) > 0; } ); panel.newCheckbox("Network/Physics status", - function(value) { Scene.setEngineDisplayItemStatus(value ? - Scene.doEngineDisplayItemStatus() | showNetworkStatusFlag : - Scene.doEngineDisplayItemStatus() & ~showNetworkStatusFlag); }, - function() { return (Scene.doEngineDisplayItemStatus() & showNetworkStatusFlag) > 0; }, + function(value) { Render.setEngineDisplayItemStatus(value ? + Render.doEngineDisplayItemStatus() | showNetworkStatusFlag : + Render.doEngineDisplayItemStatus() & ~showNetworkStatusFlag); }, + function() { return (Render.doEngineDisplayItemStatus() & showNetworkStatusFlag) > 0; }, function(value) { return (value & showNetworkStatusFlag) > 0; } ); panel.newSlider("Tone Mapping Exposure", -10, 10, - function (value) { Scene.setEngineToneMappingExposure(value); }, - function() { return Scene.getEngineToneMappingExposure(); }, + function (value) { Render.setEngineToneMappingExposure(value); }, + function() { return Render.getEngineToneMappingExposure(); }, function (value) { return (value); }); var tickTackPeriod = 500; @@ -160,9 +160,9 @@ Menu.menuItemEvent.connect(menuItemEvent); function scriptEnding() { panel.destroy(); Menu.removeActionGroup(MENU); - Settings.setValue(SETTINGS_KEY, Scene.getEngineDeferredDebugMode()); - Scene.setEngineDeferredDebugMode(-1); - Scene.setEngineDeferredDebugSize({ x: 0.0, y: -1.0, z: 1.0, w: 1.0 }); // Reset to default size + Settings.setValue(SETTINGS_KEY, Render.getEngineDeferredDebugMode()); + Render.setEngineDeferredDebugMode(-1); + Render.setEngineDeferredDebugSize({ x: 0.0, y: -1.0, z: 1.0, w: 1.0 }); // Reset to default size } Script.scriptEnding.connect(scriptEnding); diff --git a/libraries/render/src/render/Engine.h b/libraries/render/src/render/Engine.h index 40196e320e..542db9b3ae 100644 --- a/libraries/render/src/render/Engine.h +++ b/libraries/render/src/render/Engine.h @@ -75,7 +75,7 @@ public: class Tone { public: - int toneCurve = 3; + int toneCurve = 1; // Means just Gamma 2.2 correction float exposure = 0.0; }; From aef748b894041d5745dfcf76e20a7a5524bbe5fa Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 21 Dec 2015 10:40:29 -0800 Subject: [PATCH 50/62] Adding linear color in Particule system --- .../src/RenderableParticleEffectEntityItem.cpp | 8 ++++---- libraries/entities-renderer/src/untextured_particle.slv | 5 ++--- libraries/entities/src/ParticleEffectEntityItem.h | 6 ++++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp index 4abd8dbafd..379d1cc4a3 100644 --- a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp @@ -223,10 +223,10 @@ void RenderableParticleEffectEntityItem::updateRenderItem() { particleUniforms.radius.middle = getParticleRadius(); particleUniforms.radius.finish = getRadiusFinish(); particleUniforms.radius.spread = getRadiusSpread(); - particleUniforms.color.start = toGlm(getColorStart(), getAlphaStart()); - particleUniforms.color.middle = toGlm(getXColor(), getAlpha()); - particleUniforms.color.finish = toGlm(getColorFinish(), getAlphaFinish()); - particleUniforms.color.spread = toGlm(getColorSpread(), getAlphaSpread()); + particleUniforms.color.start = glm::vec4(getColorStartRGB(), getAlphaStart()); + particleUniforms.color.middle = glm::vec4(getColorRGB(), getAlpha()); + particleUniforms.color.finish = glm::vec4(getColorFinishRGB(), getAlphaFinish()); + particleUniforms.color.spread = glm::vec4(getColorSpreadRGB(), getAlphaSpread()); particleUniforms.lifespan = getLifespan(); // Build particle primitives diff --git a/libraries/entities-renderer/src/untextured_particle.slv b/libraries/entities-renderer/src/untextured_particle.slv index 3d1d99c0dc..ab0ea15219 100644 --- a/libraries/entities-renderer/src/untextured_particle.slv +++ b/libraries/entities-renderer/src/untextured_particle.slv @@ -9,16 +9,15 @@ // <@include gpu/Inputs.slh@> - +<@include gpu/Color.slh@> <@include gpu/Transform.slh@> - <$declareStandardTransform()$> out vec4 _color; void main(void) { // pass along the diffuse color - _color = inColor; + _color = colorToLinearRGBA(inColor); TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); diff --git a/libraries/entities/src/ParticleEffectEntityItem.h b/libraries/entities/src/ParticleEffectEntityItem.h index c35a45baeb..cae9340b6d 100644 --- a/libraries/entities/src/ParticleEffectEntityItem.h +++ b/libraries/entities/src/ParticleEffectEntityItem.h @@ -15,6 +15,8 @@ #include "EntityItem.h" +#include "ColorUtils.h" + class ParticleEffectEntityItem : public EntityItem { public: ALLOW_INSTANTIATION // This class can be instantiated @@ -47,6 +49,7 @@ public: const rgbColor& getColor() const { return _color; } xColor getXColor() const { xColor color = { _color[RED_INDEX], _color[GREEN_INDEX], _color[BLUE_INDEX] }; return color; } + glm::vec3 getColorRGB() const { return ColorUtils::toLinearVec3(toGlm(getXColor())); } static const xColor DEFAULT_COLOR; void setColor(const rgbColor& value) { memcpy(_color, value, sizeof(_color)); } @@ -59,14 +62,17 @@ public: bool _isColorStartInitialized = false; void setColorStart(const xColor& colorStart) { _colorStart = colorStart; _isColorStartInitialized = true; } xColor getColorStart() const { return _isColorStartInitialized ? _colorStart : getXColor(); } + glm::vec3 getColorStartRGB() const { return _isColorStartInitialized ? ColorUtils::toLinearVec3(toGlm(_colorStart)) : getColorRGB(); } bool _isColorFinishInitialized = false; void setColorFinish(const xColor& colorFinish) { _colorFinish = colorFinish; _isColorFinishInitialized = true; } xColor getColorFinish() const { return _isColorFinishInitialized ? _colorFinish : getXColor(); } + glm::vec3 getColorFinishRGB() const { return _isColorStartInitialized ? ColorUtils::toLinearVec3(toGlm(_colorFinish)) : getColorRGB(); } static const xColor DEFAULT_COLOR_SPREAD; void setColorSpread(const xColor& colorSpread) { _colorSpread = colorSpread; } xColor getColorSpread() const { return _colorSpread; } + glm::vec3 getColorSpreadRGB() const { return ColorUtils::toLinearVec3(toGlm(_colorSpread)); } static const float MAXIMUM_ALPHA; static const float MINIMUM_ALPHA; From 6ef77bc46aeab1fb17186855271fd16284da9102 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 17 Dec 2015 15:46:44 -0800 Subject: [PATCH 51/62] Support the marketplace in QML --- examples/edit.js | 47 ++++++++++++------- interface/resources/qml/QmlWebWindow.qml | 16 ++++--- interface/src/Application.cpp | 2 +- interface/src/Application.h | 7 +-- libraries/networking/src/AbstractUriHandler.h | 19 ++++++++ libraries/octree/src/Octree.cpp | 2 +- libraries/ui/src/QmlWebWindowClass.cpp | 43 +++++++++++++++-- 7 files changed, 105 insertions(+), 31 deletions(-) create mode 100644 libraries/networking/src/AbstractUriHandler.h diff --git a/examples/edit.js b/examples/edit.js index 59b6ae3e7d..074b43c8c1 100644 --- a/examples/edit.js +++ b/examples/edit.js @@ -140,9 +140,33 @@ var importingSVOTextOverlay = Overlays.addOverlay("text", { }); var MARKETPLACE_URL = "https://metaverse.highfidelity.com/marketplace"; -var marketplaceWindow = new WebWindow('Marketplace', MARKETPLACE_URL, 900, 700, false); +var marketplaceWindow = new OverlayWebWindow('Marketplace', "about:blank", 900, 700, false); marketplaceWindow.setVisible(false); +function showMarketplace(marketplaceID) { + var url = MARKETPLACE_URL; + if (marketplaceID) { + url = url + "/items/" + marketplaceID; + } + print("setting marketplace URL to " + url); + marketplaceWindow.setURL(url); + marketplaceWindow.setVisible(true); + marketplaceWindow.raise(); +} + +function hideMarketplace() { + marketplaceWindow.setVisible(false); + marketplaceWindow.setURL("about:blank"); +} + +function toggleMarketplace() { + if (marketplaceWindow.visible) { + hideMarketplace(); + } else { + showMarketplace(); + } +} + var toolBar = (function() { var that = {}, toolBar, @@ -413,12 +437,9 @@ var toolBar = (function() { newModelButtonDown = true; return true; } + if (browseMarketplaceButton === toolBar.clicked(clickedOverlay)) { - if (marketplaceWindow.url != MARKETPLACE_URL) { - marketplaceWindow.setURL(MARKETPLACE_URL); - } - marketplaceWindow.setVisible(true); - marketplaceWindow.raise(); + toggleMarketplace(); return true; } @@ -1336,6 +1357,7 @@ function getPositionToCreateEntity() { } function importSVO(importURL) { + print("Import URL requested: " + importURL) if (!Entities.canAdjustLocks()) { Window.alert(INSUFFICIENT_PERMISSIONS_IMPORT_ERROR_MSG); return; @@ -1574,11 +1596,7 @@ PropertiesTool = function(opts) { pushCommandForSelections(); selectionManager._update(); } else if (data.type == "showMarketplace") { - if (marketplaceWindow.url != data.url) { - marketplaceWindow.setURL(data.url); - } - marketplaceWindow.setVisible(true); - marketplaceWindow.raise(); + showMarketplace(); } else if (data.type == "action") { if (data.action == "moveSelectionToGrid") { if (selectionManager.hasSelection()) { @@ -1859,12 +1877,7 @@ var propertyMenu = PopupMenu(); propertyMenu.onSelectMenuItem = function(name) { if (propertyMenu.marketplaceID) { - var url = MARKETPLACE_URL + "/items/" + propertyMenu.marketplaceID; - if (marketplaceWindow.url != url) { - marketplaceWindow.setURL(url); - } - marketplaceWindow.setVisible(true); - marketplaceWindow.raise(); + showMarketplace(propertyMenu.marketplaceID); } }; diff --git a/interface/resources/qml/QmlWebWindow.qml b/interface/resources/qml/QmlWebWindow.qml index 3eb01aa9ba..029d50519a 100644 --- a/interface/resources/qml/QmlWebWindow.qml +++ b/interface/resources/qml/QmlWebWindow.qml @@ -13,12 +13,18 @@ VrDialog { HifiConstants { id: hifi } title: "WebWindow" resizable: true + // Don't destroy on close... otherwise the JS/C++ will have a dangling pointer + destroyOnCloseButton: false contentImplicitWidth: clientArea.implicitWidth contentImplicitHeight: clientArea.implicitHeight backgroundColor: "#7f000000" property url source: "about:blank" signal navigating(string url) + function stop() { + webview.stop(); + } + Component.onCompleted: { enabled = true @@ -26,18 +32,14 @@ VrDialog { webview.javaScriptConsoleMessage.connect(function(level, message, lineNumber, sourceID) { console.log("Web Window JS message: " + sourceID + " " + lineNumber + " " + message); }); - webview.loadingChanged.connect(handleWebviewLoading) } function handleWebviewLoading(loadRequest) { - var HIFI_URL_PATTERN = /^hifi:\/\//; if (WebEngineView.LoadStartedStatus == loadRequest.status) { var newUrl = loadRequest.url.toString(); - if (newUrl.match(HIFI_URL_PATTERN)) { - root.navigating(newUrl); - } + root.navigating(newUrl) } } @@ -55,8 +57,10 @@ VrDialog { url: root.source anchors.fill: parent profile: WebEngineProfile { + id: webviewProfile httpUserAgent: "Mozilla/5.0 (HighFidelityInterface)" - } + storageName: "qmlWebEngine" + } } } // item } // dialog diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e22b3913d0..7f27d97416 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4215,7 +4215,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri scriptEngine->registerGlobalObject("ScriptDiscoveryService", this->getRunningScriptsWidget()); } -bool Application::canAcceptURL(const QString& urlString) { +bool Application::canAcceptURL(const QString& urlString) const { QUrl url(urlString); if (urlString.startsWith(HIFI_URL_SCHEME)) { return true; diff --git a/interface/src/Application.h b/interface/src/Application.h index a665e925a9..0953aedd8c 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -38,6 +38,7 @@ #include #include #include +#include #include "avatar/AvatarUpdate.h" #include "avatar/MyAvatar.h" @@ -88,7 +89,7 @@ class Application; #endif #define qApp (static_cast(QCoreApplication::instance())) -class Application : public QApplication, public AbstractViewStateInterface, public AbstractScriptingServicesInterface { +class Application : public QApplication, public AbstractViewStateInterface, public AbstractScriptingServicesInterface, public AbstractUriHandler { Q_OBJECT // TODO? Get rid of those @@ -219,8 +220,8 @@ public: QString getScriptsLocation(); void setScriptsLocation(const QString& scriptsLocation); - bool canAcceptURL(const QString& url); - bool acceptURL(const QString& url, bool defaultUpload = false); + virtual bool canAcceptURL(const QString& url) const override; + virtual bool acceptURL(const QString& url, bool defaultUpload = false) override; void setMaxOctreePacketsPerSecond(int maxOctreePPS); int getMaxOctreePacketsPerSecond(); diff --git a/libraries/networking/src/AbstractUriHandler.h b/libraries/networking/src/AbstractUriHandler.h new file mode 100644 index 0000000000..3d6ed472ec --- /dev/null +++ b/libraries/networking/src/AbstractUriHandler.h @@ -0,0 +1,19 @@ +// +// Created by Bradley Austin Davis on 2015/12/17 +// Copyright 2013-2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#pragma once +#ifndef hifi_network_AbstractUriHandler_h +#define hifi_network_AbstractUriHandler_h + +class AbstractUriHandler { +public: + virtual bool canAcceptURL(const QString& url) const = 0; + virtual bool acceptURL(const QString& url, bool defaultUpload = false) = 0; +}; + +#endif diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index 636d1a9a1a..652089ebb1 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -1867,7 +1867,7 @@ bool Octree::readJSONFromStream(unsigned long streamLength, QDataStream& inputSt QByteArray jsonBuffer; char* rawData = new char[READ_JSON_BUFFER_SIZE]; - while (true) { + while (!inputStream.atEnd()) { int got = inputStream.readRawData(rawData, READ_JSON_BUFFER_SIZE - 1); if (got < 0) { qCritical() << "error while reading from json stream"; diff --git a/libraries/ui/src/QmlWebWindowClass.cpp b/libraries/ui/src/QmlWebWindowClass.cpp index d5cdc1fde9..68a45a5bff 100644 --- a/libraries/ui/src/QmlWebWindowClass.cpp +++ b/libraries/ui/src/QmlWebWindowClass.cpp @@ -10,7 +10,10 @@ #include +#include #include +#include +#include #include #include @@ -22,6 +25,7 @@ #include #include +#include #include #include @@ -88,7 +92,7 @@ QScriptValue QmlWebWindowClass::constructor(QScriptContext* context, QScriptEngi QmlWebWindowClass* retVal { nullptr }; const QString title = context->argument(0).toString(); QString url = context->argument(1).toString(); - if (!url.startsWith("http") && !url.startsWith("file://")) { + if (!url.startsWith("http") && !url.startsWith("file://") && !url.startsWith("about:")) { url = QUrl::fromLocalFile(url).toString(); } const int width = std::max(100, std::min(1280, context->argument(2).toInt32()));; @@ -119,7 +123,23 @@ QmlWebWindowClass::QmlWebWindowClass(QObject* qmlWindow) } void QmlWebWindowClass::handleNavigation(const QString& url) { - DependencyManager::get()->handleLookupString(url); + bool handled = false; + + if (url.contains(HIFI_URL_PATTERN)) { + DependencyManager::get()->handleLookupString(url); + handled = true; + } else { + static auto handler = dynamic_cast(qApp); + if (handler) { + if (handler->canAcceptURL(url)) { + handled = handler->acceptURL(url); + } + } + } + + if (handled) { + QMetaObject::invokeMethod(_qmlWindow, "stop", Qt::AutoConnection); + } } void QmlWebWindowClass::setVisible(bool visible) { @@ -202,6 +222,7 @@ QString QmlWebWindowClass::getURL() const { QMetaObject::invokeMethod(const_cast(this), "getURL", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QString, result)); return result; } + return _qmlWindow->property(URL_PROPERTY).toString(); } @@ -209,7 +230,23 @@ void QmlWebWindowClass::setURL(const QString& urlString) { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "setURL", Qt::QueuedConnection, Q_ARG(QString, urlString)); } - _qmlWindow->setProperty(URL_PROPERTY, urlString); + + static const QString ACCESS_TOKEN_PARAMETER = "access_token"; + static const QString ALLOWED_HOST = "metaverse.highfidelity.com"; + + QUrl url(urlString); + qDebug() << "Url: " << urlString; + qDebug() << "Host: " << url.host(); + if (url.host() == ALLOWED_HOST) { + QUrlQuery query(url); + if (query.allQueryItemValues(ACCESS_TOKEN_PARAMETER).empty()) { + AccountManager& accountManager = AccountManager::getInstance(); + query.addQueryItem(ACCESS_TOKEN_PARAMETER, accountManager.getAccountInfo().getAccessToken().token); + url.setQuery(query.query()); + qDebug() << "New URL " << url; + } + } + _qmlWindow->setProperty(URL_PROPERTY, url.toString()); } From ae124ebede205b3caa81905f676af44aae90cc6f Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 21 Dec 2015 12:00:30 -0800 Subject: [PATCH 52/62] Tuning the proedural shader support to work with the current default: gamma corrected emissive --- libraries/procedural/src/procedural/ProceduralSkybox.slf | 3 ++- libraries/render-utils/src/RenderDeferredTask.cpp | 1 - libraries/render-utils/src/ToneMappingEffect.cpp | 2 -- libraries/render-utils/src/simple.slf | 2 ++ 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.slf b/libraries/procedural/src/procedural/ProceduralSkybox.slf index 8705278bee..7ad6f6b5a1 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.slf +++ b/libraries/procedural/src/procedural/ProceduralSkybox.slf @@ -35,6 +35,8 @@ void main(void) { #ifdef PROCEDURAL vec3 color = getSkyboxColor(); + // Procedural Shaders are expected to be Gamma corrected so let's bring back the RGB in linear space for the rest of the pipeline + color = pow(color, vec3(2.2)); _fragColor = vec4(color, 0.0); #else @@ -42,7 +44,6 @@ void main(void) { vec3 coord = normalize(_normal); vec3 texel = texture(cubeMap, coord).rgb; vec3 color = texel * _skybox._color.rgb; - // vec3 pixel = pow(color, vec3(1.0/2.2)); // manual Gamma correction _fragColor = vec4(color, 0.0); #endif diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index ddfb6bc7a3..7fced1bdf3 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -54,7 +54,6 @@ RenderDeferredTask::RenderDeferredTask() : Task() { _jobs.push_back(Job(new FetchItems::JobModel("FetchOpaque", FetchItems([](const RenderContextPointer& context, int count) { context->getItemsConfig().opaque.numFeed = count; - auto& opaque = context->getItemsConfig().opaque; }) ))); _jobs.push_back(Job(new CullItemsOpaque::JobModel("CullOpaque", _jobs.back().getOutput()))); diff --git a/libraries/render-utils/src/ToneMappingEffect.cpp b/libraries/render-utils/src/ToneMappingEffect.cpp index a00a66fe69..2583719424 100644 --- a/libraries/render-utils/src/ToneMappingEffect.cpp +++ b/libraries/render-utils/src/ToneMappingEffect.cpp @@ -141,7 +141,5 @@ void ToneMappingEffect::render(RenderArgs* args) { batch.setUniformBuffer(3, _parametersBuffer); batch.setResourceTexture(0, lightingBuffer); batch.draw(gpu::TRIANGLE_STRIP, 4); - - args->_context->render(batch); }); } \ No newline at end of file diff --git a/libraries/render-utils/src/simple.slf b/libraries/render-utils/src/simple.slf index 576acf9340..8c93ee564e 100644 --- a/libraries/render-utils/src/simple.slf +++ b/libraries/render-utils/src/simple.slf @@ -40,6 +40,8 @@ void main(void) { #ifdef PROCEDURAL_V1 specular = getProceduralColor().rgb; + // Procedural Shaders are expected to be Gamma corrected so let's bring back the RGB in linear space for the rest of the pipeline + specular = pow(specular, vec3(2.2)); emissiveAmount = 1.0; #else emissiveAmount = getProceduralColors(diffuse, specular, shininess); From 4f54b85c9208fb2d64c5cf76dcbbd6e1057d39ed Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 21 Dec 2015 12:05:19 -0800 Subject: [PATCH 53/62] Remove warnings --- libraries/render-utils/src/RenderDeferredTask.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 7fced1bdf3..4dcda425a1 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -104,12 +104,12 @@ RenderDeferredTask::RenderDeferredTask() : Task() { // Lighting Buffer ready for tone mapping _jobs.push_back(Job(new ToneMappingDeferred::JobModel("ToneMapping"))); - _toneMappingJobIndex = _jobs.size() - 1; + _toneMappingJobIndex = (int)_jobs.size() - 1; // Debugging Deferred buffer job _jobs.push_back(Job(new DebugDeferredBuffer::JobModel("DebugDeferredBuffer"))); _jobs.back().setEnabled(false); - _drawDebugDeferredBufferIndex = _jobs.size() - 1; + _drawDebugDeferredBufferIndex = (int)_jobs.size() - 1; // Status icon rendering job { @@ -118,7 +118,7 @@ RenderDeferredTask::RenderDeferredTask() : Task() { auto statusIconMap = DependencyManager::get()->getImageTexture(iconMapPath); _jobs.push_back(Job(new render::DrawStatus::JobModel("DrawStatus", renderedOpaques, DrawStatus(statusIconMap)))); _jobs.back().setEnabled(false); - _drawStatusJobIndex = _jobs.size() - 1; + _drawStatusJobIndex = (int)_jobs.size() - 1; } _jobs.push_back(Job(new DrawOverlay3D::JobModel("DrawOverlay3D"))); From 5a86f0c23fbe4f1e3c64cfe3bec987f76ea650dd Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 21 Dec 2015 12:12:13 -0800 Subject: [PATCH 54/62] Nest JS props in SceneScriptingInterface --- .../src/EntityTreeRenderer.cpp | 61 ++--- libraries/model/src/model/Stage.cpp | 15 ++ libraries/model/src/model/Stage.h | 3 + .../src/SceneScriptingInterface.cpp | 211 ++++++++++-------- .../src/SceneScriptingInterface.h | 155 +++++++++---- 5 files changed, 279 insertions(+), 166 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index e3618d0e2a..996a8f3e1d 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -256,33 +256,38 @@ void EntityTreeRenderer::forceRecheckEntities() { void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr zone) { QSharedPointer scene = DependencyManager::get(); + auto sceneStage = scene->getStage(); + auto sceneKeyLight = sceneStage->getKeyLight(); + auto sceneLocation = sceneStage->getLocation(); + auto sceneTime = sceneStage->getTime(); + if (zone) { if (!_hasPreviousZone) { - _previousKeyLightColor = scene->getKeyLightColor(); - _previousKeyLightIntensity = scene->getKeyLightIntensity(); - _previousKeyLightAmbientIntensity = scene->getKeyLightAmbientIntensity(); - _previousKeyLightDirection = scene->getKeyLightDirection(); - _previousStageSunModelEnabled = scene->isStageSunModelEnabled(); - _previousStageLongitude = scene->getStageLocationLongitude(); - _previousStageLatitude = scene->getStageLocationLatitude(); - _previousStageAltitude = scene->getStageLocationAltitude(); - _previousStageHour = scene->getStageDayTime(); - _previousStageDay = scene->getStageYearTime(); + _previousKeyLightColor = sceneKeyLight->getColor(); + _previousKeyLightIntensity = sceneKeyLight->getIntensity(); + _previousKeyLightAmbientIntensity = sceneKeyLight->getAmbientIntensity(); + _previousKeyLightDirection = sceneKeyLight->getDirection(); + _previousStageSunModelEnabled = sceneStage->isSunModelEnabled(); + _previousStageLongitude = sceneLocation->getLongitude(); + _previousStageLatitude = sceneLocation->getLatitude(); + _previousStageAltitude = sceneLocation->getAltitude(); + _previousStageHour = sceneTime->getHour(); + _previousStageDay = sceneTime->getDay(); _hasPreviousZone = true; } - scene->setKeyLightColor(ColorUtils::toVec3(zone->getKeyLightProperties().getColor())); - scene->setKeyLightIntensity(zone->getKeyLightProperties().getIntensity()); - scene->setKeyLightAmbientIntensity(zone->getKeyLightProperties().getAmbientIntensity()); - scene->setKeyLightDirection(zone->getKeyLightProperties().getDirection()); - scene->setStageSunModelEnable(zone->getStageProperties().getSunModelEnabled()); - scene->setStageLocation(zone->getStageProperties().getLongitude(), zone->getStageProperties().getLatitude(), + sceneKeyLight->setColor(ColorUtils::toVec3(zone->getKeyLightProperties().getColor())); + sceneKeyLight->setIntensity(zone->getKeyLightProperties().getIntensity()); + sceneKeyLight->setAmbientIntensity(zone->getKeyLightProperties().getAmbientIntensity()); + sceneKeyLight->setDirection(zone->getKeyLightProperties().getDirection()); + sceneStage->setSunModelEnable(zone->getStageProperties().getSunModelEnabled()); + sceneStage->setLocation(zone->getStageProperties().getLongitude(), zone->getStageProperties().getLatitude(), zone->getStageProperties().getAltitude()); - scene->setStageDayTime(zone->getStageProperties().calculateHour()); - scene->setStageYearTime(zone->getStageProperties().calculateDay()); + sceneTime->setHour(zone->getStageProperties().calculateHour()); + sceneTime->setDay(zone->getStageProperties().calculateDay()); if (zone->getBackgroundMode() == BACKGROUND_MODE_ATMOSPHERE) { EnvironmentData data = zone->getEnvironmentData(); - glm::vec3 keyLightDirection = scene->getKeyLightDirection(); + glm::vec3 keyLightDirection = sceneKeyLight->getDirection(); glm::vec3 inverseKeyLightDirection = keyLightDirection * -1.0f; // NOTE: is this right? It seems like the "sun" should be based on the center of the @@ -293,7 +298,7 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptrgetKeyLightIntensity() * KEY_LIGHT_INTENSITY_TO_SUN_BRIGHTNESS_RATIO; + float sunBrightness = sceneKeyLight->getIntensity() * KEY_LIGHT_INTENSITY_TO_SUN_BRIGHTNESS_RATIO; data.setSunBrightness(sunBrightness); _viewState->overrideEnvironmentData(data); @@ -339,15 +344,15 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptrsetKeyLightColor(_previousKeyLightColor); - scene->setKeyLightIntensity(_previousKeyLightIntensity); - scene->setKeyLightAmbientIntensity(_previousKeyLightAmbientIntensity); - scene->setKeyLightDirection(_previousKeyLightDirection); - scene->setStageSunModelEnable(_previousStageSunModelEnabled); - scene->setStageLocation(_previousStageLongitude, _previousStageLatitude, + sceneKeyLight->setColor(_previousKeyLightColor); + sceneKeyLight->setIntensity(_previousKeyLightIntensity); + sceneKeyLight->setAmbientIntensity(_previousKeyLightAmbientIntensity); + sceneKeyLight->setDirection(_previousKeyLightDirection); + sceneStage->setSunModelEnable(_previousStageSunModelEnabled); + sceneStage->setLocation(_previousStageLongitude, _previousStageLatitude, _previousStageAltitude); - scene->setStageDayTime(_previousStageHour); - scene->setStageYearTime(_previousStageDay); + sceneTime->setHour(_previousStageHour); + sceneTime->setDay(_previousStageDay); _hasPreviousZone = false; } _viewState->endOverrideEnvironmentData(); diff --git a/libraries/model/src/model/Stage.cpp b/libraries/model/src/model/Stage.cpp index 67f0262b61..47d3ba3063 100644 --- a/libraries/model/src/model/Stage.cpp +++ b/libraries/model/src/model/Stage.cpp @@ -225,6 +225,21 @@ void SunSkyStage::setOriginOrientation(const Quat& orientation) { invalidate(); } +void SunSkyStage::setOriginLongitude(float longitude) { + _earthSunModel.setLongitude(longitude); + invalidate(); +} + +void SunSkyStage::setOriginLatitude(float latitude) { + _earthSunModel.setLatitude(latitude); + invalidate(); +} + +void SunSkyStage::setOriginSurfaceAltitude(float altitude) { + _earthSunModel.setAltitude(altitude); + invalidate(); +} + void SunSkyStage::setOriginLocation(float longitude, float latitude, float altitude) { _earthSunModel.setLongitude(longitude); _earthSunModel.setLatitude(latitude); diff --git a/libraries/model/src/model/Stage.h b/libraries/model/src/model/Stage.h index 978c308ac6..bf586b6b55 100644 --- a/libraries/model/src/model/Stage.h +++ b/libraries/model/src/model/Stage.h @@ -184,6 +184,9 @@ public: const Quat& getOriginOrientation() const { return _earthSunModel.getSurfaceOrientation(); } // Location used to define the sun & sky is a longitude and latitude [rad] and a earth surface altitude [km] + void setOriginLatitude(float latitude); + void setOriginLongitude(float longitude); + void setOriginSurfaceAltitude(float surfaceAltitude); void setOriginLocation(float longitude, float latitude, float surfaceAltitude); float getOriginLatitude() const { return _earthSunModel.getLatitude(); } float getOriginLongitude() const { return _earthSunModel.getLongitude(); } diff --git a/libraries/script-engine/src/SceneScriptingInterface.cpp b/libraries/script-engine/src/SceneScriptingInterface.cpp index 39bceba9d9..e3d16912f4 100644 --- a/libraries/script-engine/src/SceneScriptingInterface.cpp +++ b/libraries/script-engine/src/SceneScriptingInterface.cpp @@ -13,7 +13,118 @@ #include -SceneScriptingInterface::SceneScriptingInterface() { +float SceneScripting::Location::getLongitude() const { + return _skyStage->getOriginLongitude(); +} + +float SceneScripting::Location::getLatitude() const { + return _skyStage->getOriginLatitude(); +} + +float SceneScripting::Location::getAltitude() const { + return _skyStage->getOriginSurfaceAltitude(); +} + +void SceneScripting::Location::setLongitude(float longitude) { + _skyStage->setOriginLongitude(longitude); +} + +void SceneScripting::Location::setLatitude(float latitude) { + _skyStage->setOriginLatitude(latitude); +} + +void SceneScripting::Location::setAltitude(float altitude) { + _skyStage->setOriginSurfaceAltitude(altitude); +} + +void SceneScripting::Time::setHour(float hour) { + _skyStage->setDayTime(hour); +} + +float SceneScripting::Time::getHour() const { + return _skyStage->getDayTime(); +} + +void SceneScripting::Time::setDay(int day) { + _skyStage->setYearTime(day); +} + +int SceneScripting::Time::getDay() const { + return _skyStage->getYearTime(); +} + +glm::vec3 SceneScripting::KeyLight::getColor() const { + return _skyStage->getSunColor(); +} + +void SceneScripting::KeyLight::setColor(const glm::vec3& color) { + _skyStage->setSunColor(color); +} + +float SceneScripting::KeyLight::getIntensity() const { + return _skyStage->getSunIntensity(); +} + +void SceneScripting::KeyLight::setIntensity(float intensity) { + _skyStage->setSunIntensity(intensity); +} + +float SceneScripting::KeyLight::getAmbientIntensity() const { + return _skyStage->getSunAmbientIntensity(); +} + +void SceneScripting::KeyLight::setAmbientIntensity(float intensity) { + _skyStage->setSunAmbientIntensity(intensity); +} + +glm::vec3 SceneScripting::KeyLight::getDirection() const { + return _skyStage->getSunDirection(); +} + +void SceneScripting::KeyLight::setDirection(const glm::vec3& direction) { + _skyStage->setSunDirection(direction); +} + +void SceneScripting::Stage::setOrientation(const glm::quat& orientation) const { + _skyStage->setOriginOrientation(orientation); +} + +void SceneScripting::Stage::setLocation(float longitude, float latitude, float altitude) { + _skyStage->setOriginLocation(longitude, latitude, altitude); +} + +void SceneScripting::Stage::setSunModelEnable(bool isEnabled) { + _skyStage->setSunModelEnable(isEnabled); +} + +bool SceneScripting::Stage::isSunModelEnabled() const { + return _skyStage->isSunModelEnabled(); +} + +void SceneScripting::Stage::setBackgroundMode(const QString& mode) { + if (mode == QString("inherit")) { + _skyStage->setBackgroundMode(model::SunSkyStage::NO_BACKGROUND); + } else if (mode == QString("atmosphere")) { + _skyStage->setBackgroundMode(model::SunSkyStage::SKY_DOME); + } else if (mode == QString("skybox")) { + _skyStage->setBackgroundMode(model::SunSkyStage::SKY_BOX); + } +} + +QString SceneScripting::Stage::getBackgroundMode() const { + switch (_skyStage->getBackgroundMode()) { + case model::SunSkyStage::NO_BACKGROUND: + return QString("inherit"); + case model::SunSkyStage::SKY_DOME: + return QString("atmosphere"); + case model::SunSkyStage::SKY_BOX: + return QString("skybox"); + default: + return QString("inherit"); + }; +} + +SceneScriptingInterface::SceneScriptingInterface() : _stage{ std::make_unique(_skyStage) } { // Let's make sure the sunSkyStage is using a proceduralSkybox _skyStage->setSkybox(model::SkyboxPointer(new ProceduralSkybox())); } @@ -32,102 +143,6 @@ void SceneScriptingInterface::setShouldRenderEntities(bool shouldRenderEntities) } } -void SceneScriptingInterface::setStageOrientation(const glm::quat& orientation) { - _skyStage->setOriginOrientation(orientation); -} -void SceneScriptingInterface::setStageLocation(float longitude, float latitude, float altitude) { - _skyStage->setOriginLocation(longitude, latitude, altitude); -} - -float SceneScriptingInterface::getStageLocationLongitude() const { - return _skyStage->getOriginLongitude(); -} -float SceneScriptingInterface::getStageLocationLatitude() const { - return _skyStage->getOriginLatitude(); -} -float SceneScriptingInterface::getStageLocationAltitude() const { - return _skyStage->getOriginSurfaceAltitude(); -} - -void SceneScriptingInterface::setStageDayTime(float hour) { - _skyStage->setDayTime(hour); -} - -float SceneScriptingInterface::getStageDayTime() const { - return _skyStage->getDayTime(); -} - -void SceneScriptingInterface::setStageYearTime(int day) { - _skyStage->setYearTime(day); -} - -int SceneScriptingInterface::getStageYearTime() const { - return _skyStage->getYearTime(); -} - -void SceneScriptingInterface::setKeyLightColor(const glm::vec3& color) { - _skyStage->setSunColor(color); -} - -glm::vec3 SceneScriptingInterface::getKeyLightColor() const { - return _skyStage->getSunColor(); -} - -void SceneScriptingInterface::setKeyLightIntensity(float intensity) { - _skyStage->setSunIntensity(intensity); -} - -float SceneScriptingInterface::getKeyLightIntensity() const { - return _skyStage->getSunIntensity(); -} - -void SceneScriptingInterface::setKeyLightAmbientIntensity(float intensity) { - _skyStage->setSunAmbientIntensity(intensity); -} - -float SceneScriptingInterface::getKeyLightAmbientIntensity() const { - return _skyStage->getSunAmbientIntensity(); -} - -void SceneScriptingInterface::setKeyLightDirection(const glm::vec3& direction) { - _skyStage->setSunDirection(direction); -} - -glm::vec3 SceneScriptingInterface::getKeyLightDirection() const { - return _skyStage->getSunDirection(); -} - -void SceneScriptingInterface::setStageSunModelEnable(bool isEnabled) { - _skyStage->setSunModelEnable(isEnabled); -} - -bool SceneScriptingInterface::isStageSunModelEnabled() const { - return _skyStage->isSunModelEnabled(); -} - -void SceneScriptingInterface::setBackgroundMode(const QString& mode) { - if (mode == QString("inherit")) { - _skyStage->setBackgroundMode(model::SunSkyStage::NO_BACKGROUND); - } else if (mode == QString("atmosphere")) { - _skyStage->setBackgroundMode(model::SunSkyStage::SKY_DOME); - } else if (mode == QString("skybox")) { - _skyStage->setBackgroundMode(model::SunSkyStage::SKY_BOX); - } -} - -QString SceneScriptingInterface::getBackgroundMode() const { - switch (_skyStage->getBackgroundMode()) { - case model::SunSkyStage::NO_BACKGROUND: - return QString("inherit"); - case model::SunSkyStage::SKY_DOME: - return QString("atmosphere"); - case model::SunSkyStage::SKY_BOX: - return QString("skybox"); - default: - return QString("inherit"); - }; -} - model::SunSkyStagePointer SceneScriptingInterface::getSkyStage() const { return _skyStage; -} +} \ No newline at end of file diff --git a/libraries/script-engine/src/SceneScriptingInterface.h b/libraries/script-engine/src/SceneScriptingInterface.h index abc4ee68a9..da107b3126 100644 --- a/libraries/script-engine/src/SceneScriptingInterface.h +++ b/libraries/script-engine/src/SceneScriptingInterface.h @@ -17,6 +17,112 @@ #include "model/Stage.h" +// TODO: if QT moc ever supports nested classes, subclass these to the interface instead of namespacing +namespace SceneScripting { + class Location : public QObject { + Q_OBJECT + + public: + Location(model::SunSkyStagePointer skyStage) : _skyStage{ skyStage } {} + + Q_PROPERTY(float longitude READ getLongitude WRITE setLongitude) + Q_PROPERTY(float latitude READ getLatitude WRITE setLatitude) + Q_PROPERTY(float altitude READ getAltitude WRITE setAltitude) + + float getLongitude() const; + float getLatitude() const; + float getAltitude() const; + void setLongitude(float longitude); + void setLatitude(float latitude); + void setAltitude(float altitude); + + protected: + model::SunSkyStagePointer _skyStage; + }; + using LocationPointer = std::unique_ptr; + + class Time : public QObject { + Q_OBJECT + + public: + Time(model::SunSkyStagePointer skyStage) : _skyStage{ skyStage } {} + + Q_PROPERTY(float hour READ getHour WRITE setHour) + Q_PROPERTY(int day READ getDay WRITE setDay) + + float getHour() const; + void setHour(float hour); + int getDay() const; + void setDay(int day); + + protected: + model::SunSkyStagePointer _skyStage; + }; + using TimePointer = std::unique_ptr