From 5e8cad683e168d64f81f1e3498d9623d1f6ad064 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 30 Oct 2015 09:15:42 -0700 Subject: [PATCH 01/55] Playing with the gamma correction --- libraries/gpu/src/gpu/GLBackendOutput.cpp | 1 + libraries/model/src/model/TextureMap.cpp | 2 +- .../src/DeferredLightingEffect.cpp | 37 +++++++++++++++++-- .../render-utils/src/FramebufferCache.cpp | 22 +++++++++++ libraries/render-utils/src/FramebufferCache.h | 7 ++++ .../src/directional_skybox_light.slf | 3 ++ 6 files changed, 68 insertions(+), 4 deletions(-) diff --git a/libraries/gpu/src/gpu/GLBackendOutput.cpp b/libraries/gpu/src/gpu/GLBackendOutput.cpp index 2bcd7e31d8..3ada131266 100755 --- a/libraries/gpu/src/gpu/GLBackendOutput.cpp +++ b/libraries/gpu/src/gpu/GLBackendOutput.cpp @@ -194,6 +194,7 @@ void GLBackend::resetOutputStage() { _output._drawFBO = 0; glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); } + // glEnable(GL_FRAMEBUFFER_SRGB); } void GLBackend::do_setFramebuffer(Batch& batch, uint32 paramOffset) { diff --git a/libraries/model/src/model/TextureMap.cpp b/libraries/model/src/model/TextureMap.cpp index d443522a6f..fc8f42351c 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)); diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 57e3129ef8..977c4caea8 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -143,7 +143,37 @@ 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)); gpu::Shader::makeProgram(*blitProgram); auto blitState = std::make_shared(); blitState->setBlendFunction(true, @@ -375,7 +405,8 @@ void DeferredLightingEffect::render(RenderArgs* args) { QSize framebufferSize = framebufferCache->getFrameBufferSize(); // binding the first framebuffer - _copyFBO = framebufferCache->getFramebuffer(); + // _copyFBO = framebufferCache->getFramebuffer(); + _copyFBO = framebufferCache->getBeautyFramebuffer(); batch.setFramebuffer(_copyFBO); // Clearing it @@ -712,7 +743,7 @@ void DeferredLightingEffect::copyBack(RenderArgs* args) { args->_context->render(batch); }); - framebufferCache->releaseFramebuffer(_copyFBO); + // 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..59cc4eae66 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(); + _beautyTexture.reset(); + _beautyFramebuffer.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); + + + _beautyTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA), width, height, defaultSampler)); +// _beautyTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::SRGBA), width, height, defaultSampler)); + _beautyFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); + _beautyFramebuffer->setRenderBuffer(0, _beautyTexture); } gpu::FramebufferPointer FramebufferCache::getPrimaryFramebuffer() { @@ -118,6 +126,20 @@ gpu::TexturePointer FramebufferCache::getPrimarySpecularTexture() { return _primarySpecularTexture; } +gpu::FramebufferPointer FramebufferCache::getBeautyFramebuffer() { + if (!_beautyFramebuffer) { + createPrimaryFramebuffer(); + } + return _beautyFramebuffer; +} + +gpu::TexturePointer FramebufferCache::getBeautyTexture() { + if (!_beautyTexture) { + createPrimaryFramebuffer(); + } + return _beautyTexture; +} + 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..3fcfd54a6f 100644 --- a/libraries/render-utils/src/FramebufferCache.h +++ b/libraries/render-utils/src/FramebufferCache.h @@ -37,6 +37,9 @@ public: gpu::TexturePointer getPrimaryNormalTexture(); gpu::TexturePointer getPrimarySpecularTexture(); + gpu::TexturePointer getBeautyTexture(); + gpu::FramebufferPointer getBeautyFramebuffer(); + /// Returns the framebuffer object used to render shadow maps; gpu::FramebufferPointer getShadowFramebuffer(); @@ -64,6 +67,10 @@ private: gpu::TexturePointer _primaryNormalTexture; gpu::TexturePointer _primarySpecularTexture; + + gpu::TexturePointer _beautyTexture; + gpu::FramebufferPointer _beautyFramebuffer; + gpu::FramebufferPointer _shadowFramebuffer; gpu::FramebufferPointer _selfieFramebuffer; diff --git a/libraries/render-utils/src/directional_skybox_light.slf b/libraries/render-utils/src/directional_skybox_light.slf index ca3efef047..6c4c8bf4ef 100755 --- a/libraries/render-utils/src/directional_skybox_light.slf +++ b/libraries/render-utils/src/directional_skybox_light.slf @@ -48,4 +48,7 @@ void main(void) { _fragColor = vec4(color, frag.normalVal.a); } + if (gl_FragCoord.y > 500) { + _fragColor.xyz = pow(_fragColor.xyz, vec3(2.2)); + } } From ba56519354ded68afb666be18ecff96c1ebe91e7 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 16 Nov 2015 21:41:13 -0800 Subject: [PATCH 02/55] something happens --- libraries/gpu/src/gpu/GLBackendOutput.cpp | 2 +- libraries/gpu/src/gpu/GLBackendTexture.cpp | 79 +++++++++++++++++++ libraries/model/src/model/Material.h | 2 +- .../src/DeferredLightingEffect.cpp | 8 +- .../render-utils/src/FramebufferCache.cpp | 25 +++--- libraries/render-utils/src/FramebufferCache.h | 8 +- .../src/directional_ambient_light.slf | 4 + 7 files changed, 106 insertions(+), 22 deletions(-) diff --git a/libraries/gpu/src/gpu/GLBackendOutput.cpp b/libraries/gpu/src/gpu/GLBackendOutput.cpp index 3ada131266..93f2b998bb 100755 --- a/libraries/gpu/src/gpu/GLBackendOutput.cpp +++ b/libraries/gpu/src/gpu/GLBackendOutput.cpp @@ -194,7 +194,7 @@ void GLBackend::resetOutputStage() { _output._drawFBO = 0; glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); } - // glEnable(GL_FRAMEBUFFER_SRGB); + glEnable(GL_FRAMEBUFFER_SRGB); } void GLBackend::do_setFramebuffer(Batch& batch, uint32 paramOffset) { diff --git a/libraries/gpu/src/gpu/GLBackendTexture.cpp b/libraries/gpu/src/gpu/GLBackendTexture.cpp index 71c5a83331..3a2323b8cc 100755 --- a/libraries/gpu/src/gpu/GLBackendTexture.cpp +++ b/libraries/gpu/src/gpu/GLBackendTexture.cpp @@ -117,6 +117,45 @@ public: break; case gpu::RGBA: texel.internalFormat = GL_RGBA; + switch (dstFormat.getType()) { + case gpu::UINT32: + case gpu::NUINT32: { + texel.internalFormat = GL_RGBA32UI; + break; + } + case gpu::INT32: + case gpu::NINT32: { + texel.internalFormat = GL_RGBA32I; + break; + } + case gpu::FLOAT: { + texel.internalFormat = GL_RGBA32F; + break; + } + case gpu::UINT16: + case gpu::NUINT16: { + texel.internalFormat = GL_RGBA16UI; + break; + } + case gpu::INT16: + case gpu::NINT16: { + texel.internalFormat = GL_RGBA16I; + break; + } + case gpu::HALF: { + texel.internalFormat = GL_RGBA16F; + break; + } + case gpu::UINT8: + case gpu::INT8: + case gpu::NUINT8: + case gpu::NINT8: { + break; + } + case gpu::NUM_TYPES: { // quiet compiler + Q_UNREACHABLE(); + } + } break; case gpu::SRGB: texel.internalFormat = GL_SRGB; @@ -240,6 +279,46 @@ public: break; case gpu::RGBA: texel.internalFormat = GL_RGBA; + switch (dstFormat.getType()) { + case gpu::UINT32: + case gpu::NUINT32: { + texel.internalFormat = GL_RGBA32UI; + break; + } + case gpu::INT32: + case gpu::NINT32: { + texel.internalFormat = GL_RGBA32I; + break; + } + case gpu::FLOAT: { + texel.internalFormat = GL_RGBA32F; + break; + } + case gpu::UINT16: + case gpu::NUINT16: { + texel.internalFormat = GL_RGBA16UI; + break; + } + case gpu::INT16: + case gpu::NINT16: { + texel.internalFormat = GL_RGBA16I; + break; + } + case gpu::HALF: { + texel.internalFormat = GL_RGBA16F; + break; + } + case gpu::UINT8: + case gpu::INT8: + case gpu::NUINT8: + case gpu::NINT8: { + break; + } + case gpu::NUM_TYPES: { // quiet compiler + Q_UNREACHABLE(); + } + } + break; case gpu::SRGB: texel.internalFormat = GL_SRGB; diff --git a/libraries/model/src/model/Material.h b/libraries/model/src/model/Material.h index b0725d9908..b1780e9e8a 100755 --- a/libraries/model/src/model/Material.h +++ b/libraries/model/src/model/Material.h @@ -242,7 +242,7 @@ public: float _gloss{0.1f}; Color _emissive{0.0f}; float _spare0{0.0f}; - glm::vec4 _spareVec4{0.0f}; // for alignment beauty, Material size == Mat4x4 + glm::vec4 _spareVec4{0.0f}; // for alignment lighting, Material size == Mat4x4 Schema() {} }; diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 977c4caea8..597e1daedc 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -370,7 +370,7 @@ void DeferredLightingEffect::addSpotLight(const glm::vec3& position, float radiu } void DeferredLightingEffect::prepare(RenderArgs* args) { - gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { + gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { batch.enableStereo(false); batch.setStateScissorRect(args->_viewport); @@ -387,7 +387,7 @@ void DeferredLightingEffect::prepare(RenderArgs* args) { gpu::FramebufferPointer _copyFBO; void DeferredLightingEffect::render(RenderArgs* args) { - gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { + gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { // Allocate the parameters buffer used by all the deferred shaders if (!_deferredTransformBuffer[0]._buffer) { @@ -406,7 +406,7 @@ void DeferredLightingEffect::render(RenderArgs* args) { // binding the first framebuffer // _copyFBO = framebufferCache->getFramebuffer(); - _copyFBO = framebufferCache->getBeautyFramebuffer(); + _copyFBO = framebufferCache->getLightingFramebuffer(); batch.setFramebuffer(_copyFBO); // Clearing it @@ -713,7 +713,7 @@ void DeferredLightingEffect::render(RenderArgs* args) { void DeferredLightingEffect::copyBack(RenderArgs* args) { auto framebufferCache = DependencyManager::get(); - gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { + gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { batch.enableStereo(false); QSize framebufferSize = framebufferCache->getFrameBufferSize(); diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index 59cc4eae66..3faee3cc09 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -41,8 +41,8 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { _primarySpecularTexture.reset(); _selfieFramebuffer.reset(); _cachedFramebuffers.clear(); - _beautyTexture.reset(); - _beautyFramebuffer.reset(); + _lightingTexture.reset(); + _lightingFramebuffer.reset(); } } @@ -78,10 +78,11 @@ void FramebufferCache::createPrimaryFramebuffer() { _selfieFramebuffer->setRenderBuffer(0, tex); - _beautyTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA), width, height, defaultSampler)); -// _beautyTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::SRGBA), width, height, defaultSampler)); - _beautyFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); - _beautyFramebuffer->setRenderBuffer(0, _beautyTexture); + // _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() { @@ -126,18 +127,18 @@ gpu::TexturePointer FramebufferCache::getPrimarySpecularTexture() { return _primarySpecularTexture; } -gpu::FramebufferPointer FramebufferCache::getBeautyFramebuffer() { - if (!_beautyFramebuffer) { +gpu::FramebufferPointer FramebufferCache::getLightingFramebuffer() { + if (!_lightingFramebuffer) { createPrimaryFramebuffer(); } - return _beautyFramebuffer; + return _lightingFramebuffer; } -gpu::TexturePointer FramebufferCache::getBeautyTexture() { - if (!_beautyTexture) { +gpu::TexturePointer FramebufferCache::getLightingTexture() { + if (!_lightingTexture) { createPrimaryFramebuffer(); } - return _beautyTexture; + return _lightingTexture; } gpu::FramebufferPointer FramebufferCache::getFramebuffer() { diff --git a/libraries/render-utils/src/FramebufferCache.h b/libraries/render-utils/src/FramebufferCache.h index 3fcfd54a6f..ba7496cf49 100644 --- a/libraries/render-utils/src/FramebufferCache.h +++ b/libraries/render-utils/src/FramebufferCache.h @@ -37,8 +37,8 @@ public: gpu::TexturePointer getPrimaryNormalTexture(); gpu::TexturePointer getPrimarySpecularTexture(); - gpu::TexturePointer getBeautyTexture(); - gpu::FramebufferPointer getBeautyFramebuffer(); + gpu::TexturePointer getLightingTexture(); + gpu::FramebufferPointer getLightingFramebuffer(); /// Returns the framebuffer object used to render shadow maps; gpu::FramebufferPointer getShadowFramebuffer(); @@ -68,8 +68,8 @@ private: gpu::TexturePointer _primarySpecularTexture; - gpu::TexturePointer _beautyTexture; - gpu::FramebufferPointer _beautyFramebuffer; + gpu::TexturePointer _lightingTexture; + gpu::FramebufferPointer _lightingFramebuffer; gpu::FramebufferPointer _shadowFramebuffer; diff --git a/libraries/render-utils/src/directional_ambient_light.slf b/libraries/render-utils/src/directional_ambient_light.slf index 52ecc71a14..b83f06ee12 100755 --- a/libraries/render-utils/src/directional_ambient_light.slf +++ b/libraries/render-utils/src/directional_ambient_light.slf @@ -47,4 +47,8 @@ void main(void) { frag.gloss); _fragColor = vec4(color, frag.normalVal.a); } + + if (gl_FragCoord.y > 500) { + _fragColor.xyz = pow(_fragColor.xyz, vec3(2.2)); + } } From d1847136b8c18272e808846d9d4306953387cacf Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 2 Dec 2015 16:15:03 -0800 Subject: [PATCH 03/55] Clean up --- libraries/model/src/model/Material.h | 2 +- libraries/render-utils/src/DeferredLightingEffect.cpp | 4 ++-- libraries/render-utils/src/FramebufferCache.cpp | 4 ++-- libraries/script-engine/src/ScriptEngine.cpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/model/src/model/Material.h b/libraries/model/src/model/Material.h index b1780e9e8a..b0725d9908 100755 --- a/libraries/model/src/model/Material.h +++ b/libraries/model/src/model/Material.h @@ -242,7 +242,7 @@ public: float _gloss{0.1f}; Color _emissive{0.0f}; float _spare0{0.0f}; - glm::vec4 _spareVec4{0.0f}; // for alignment lighting, Material size == Mat4x4 + glm::vec4 _spareVec4{0.0f}; // for alignment beauty, Material size == Mat4x4 Schema() {} }; diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 597e1daedc..30d83c489b 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -370,7 +370,7 @@ void DeferredLightingEffect::addSpotLight(const glm::vec3& position, float radiu } void DeferredLightingEffect::prepare(RenderArgs* args) { - gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { + gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { batch.enableStereo(false); batch.setStateScissorRect(args->_viewport); @@ -387,7 +387,7 @@ void DeferredLightingEffect::prepare(RenderArgs* args) { gpu::FramebufferPointer _copyFBO; void DeferredLightingEffect::render(RenderArgs* args) { - gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { + gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { // Allocate the parameters buffer used by all the deferred shaders if (!_deferredTransformBuffer[0]._buffer) { diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index 3faee3cc09..cf8b20dc36 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -78,8 +78,8 @@ void FramebufferCache::createPrimaryFramebuffer() { _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::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); diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 49009a3ad2..c40634af37 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 4fcf207a6a6b96858c9c99b687129fa115c2c7c0 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 2 Dec 2015 16:49:39 -0800 Subject: [PATCH 04/55] Back pedaling? --- libraries/render-utils/src/DeferredLightingEffect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 30d83c489b..d7d434be97 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -713,7 +713,7 @@ void DeferredLightingEffect::render(RenderArgs* args) { void DeferredLightingEffect::copyBack(RenderArgs* args) { auto framebufferCache = DependencyManager::get(); - gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { + gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { batch.enableStereo(false); QSize framebufferSize = framebufferCache->getFrameBufferSize(); From 8903a61c6e73a92620c433d1abfe973bdd164778 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 9 Mar 2016 10:24:46 -0800 Subject: [PATCH 05/55] basic shader --- .../rapidUniformChangeTest.fs | 26 +++++++++++ .../rapidUniformChangeTest.js | 44 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 examples/tests/rapidUniformChange/rapidUniformChangeTest.fs create mode 100644 examples/tests/rapidUniformChange/rapidUniformChangeTest.js diff --git a/examples/tests/rapidUniformChange/rapidUniformChangeTest.fs b/examples/tests/rapidUniformChange/rapidUniformChangeTest.fs new file mode 100644 index 0000000000..31ba437003 --- /dev/null +++ b/examples/tests/rapidUniformChange/rapidUniformChangeTest.fs @@ -0,0 +1,26 @@ + +// +// rapidUniformChangeTest.fs +// examples/homeContent/plant +// +// Created by Eric Levin on 3/9/16. +// Copyright 2016 High Fidelity, Inc. +// +// This fragment shader is designed to test the rapid changing of a uniform +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + + +uniform float red = 0.1; + + +void mainImage(out vec4 fragColor, in vec2 fragCoord) { + fragColor = vec4(red, 0.0, 1.0, 1.0); +} +vec4 getProceduralColor() { + vec4 result; + vec2 position = _position.xz; + position += 0.5; + mainImage(result, position * iWorldScale.xz); + return result; +} \ No newline at end of file diff --git a/examples/tests/rapidUniformChange/rapidUniformChangeTest.js b/examples/tests/rapidUniformChange/rapidUniformChangeTest.js new file mode 100644 index 0000000000..d8d2d16e9b --- /dev/null +++ b/examples/tests/rapidUniformChange/rapidUniformChangeTest.js @@ -0,0 +1,44 @@ + +// rapidUniformChangeTest.js +// examples +// +// Created by Eric Levin on 3/9/2016. +// Copyright 2016 High Fidelity, Inc. +// This test creates a primitive with a fragment shader and rapidly updates its uniform values +// For the test to pass, the uniform should update at rate of update loop without the client crashing +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var orientation = Camera.getOrientation(); +orientation = Quat.safeEulerAngles(orientation); +orientation.x = 0; +orientation = Quat.fromVec3Degrees(orientation); +var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(orientation))); + +var SHADER_URL = "file:///C:/Users/Eric/hifi/examples/tests/rapidUniformChange/rapidUniformChangeTest.fs"; + +var testEntity = Entities.addEntity({ + type: "Box", + dimensions: { + x: 0.5, + y: 0.5, + z: 0.5 + }, + position: center, + userData: JSON.stringify({ + ProceduralEntity: { + shaderUrl: SHADER_URL, + uniforms: { + red: 0.5 + } + } + }) +}); + +Script.scriptEnding.connect(cleanup); + +function cleanup() { + Entities.deleteEntity(testEntity); +} From 1a09c5d19f92b486c8be7d82d37d78a86c6b19c7 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 9 Mar 2016 10:33:18 -0800 Subject: [PATCH 06/55] test script for uniform change --- .../rapidUniformChangeTest.js | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/examples/tests/rapidUniformChange/rapidUniformChangeTest.js b/examples/tests/rapidUniformChange/rapidUniformChangeTest.js index d8d2d16e9b..cbd5ce4969 100644 --- a/examples/tests/rapidUniformChange/rapidUniformChangeTest.js +++ b/examples/tests/rapidUniformChange/rapidUniformChangeTest.js @@ -1,4 +1,3 @@ - // rapidUniformChangeTest.js // examples // @@ -19,6 +18,15 @@ var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(orientat var SHADER_URL = "file:///C:/Users/Eric/hifi/examples/tests/rapidUniformChange/rapidUniformChangeTest.fs"; + +var userData = { + ProceduralEntity: { + shaderUrl: SHADER_URL, + uniforms: { + red: 0.0 + } + } +} var testEntity = Entities.addEntity({ type: "Box", dimensions: { @@ -27,18 +35,23 @@ var testEntity = Entities.addEntity({ z: 0.5 }, position: center, - userData: JSON.stringify({ - ProceduralEntity: { - shaderUrl: SHADER_URL, - uniforms: { - red: 0.5 - } - } - }) + userData: JSON.stringify(userData) }); + +var currentTime = 0; + +function update(deltaTime) { + var red = (Math.sin(currentTime) + 1) / 2; + userData.ProceduralEntity.uniforms.red = red; + Entities.editEntity(testEntity, {userData: JSON.stringify(userData)}); + currentTime += deltaTime; +} + +Script.update.connect(update); + Script.scriptEnding.connect(cleanup); function cleanup() { Entities.deleteEntity(testEntity); -} +} \ No newline at end of file From 170dd418f84d9c2668fd957997dffda64805ccd4 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 9 Mar 2016 10:35:11 -0800 Subject: [PATCH 07/55] chaged shader link --- examples/tests/rapidUniformChange/rapidUniformChangeTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tests/rapidUniformChange/rapidUniformChangeTest.js b/examples/tests/rapidUniformChange/rapidUniformChangeTest.js index cbd5ce4969..626ffebf8a 100644 --- a/examples/tests/rapidUniformChange/rapidUniformChangeTest.js +++ b/examples/tests/rapidUniformChange/rapidUniformChangeTest.js @@ -16,7 +16,7 @@ orientation.x = 0; orientation = Quat.fromVec3Degrees(orientation); var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(orientation))); -var SHADER_URL = "file:///C:/Users/Eric/hifi/examples/tests/rapidUniformChange/rapidUniformChangeTest.fs"; +var SHADER_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/rapidUniformChangeTest.fs"; var userData = { From 4af37668047ab36ae95ff2f563293e7e97a8719a Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 9 Mar 2016 14:28:26 -0800 Subject: [PATCH 08/55] Don't reset sensors when initializing or changing display plugins. This should fix the issue with the Oculus starting up with the UI aligned to the HMD on your desk, rather then the configured default sitting pose. --- interface/src/Application.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 660e597752..654e58c170 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -69,6 +69,7 @@ #include #include #include +#include #include #include #include @@ -3287,6 +3288,14 @@ void Application::update(float deltaTime) { // update sensorToWorldMatrix for rendering camera. myAvatar->updateSensorToWorldMatrix(); + + // AJT: TODO: make this a menu item. + const bool DRAW_SENSOR_TO_WORLD_MATRIX = true; + if (DRAW_SENSOR_TO_WORLD_MATRIX) { + // draw the origin of the room in world space. + glm::mat4 m = myAvatar->getSensorToWorldMatrix(); + DebugDraw::getInstance().addMarker("room", glmExtractRotation(m), extractTranslation(m), glm::vec4(1)); + } } @@ -4811,7 +4820,7 @@ void Application::updateDisplayMode() { } } emit activeDisplayPluginChanged(); - resetSensors(); + Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin"); } From 5df616be37406f5385ec5f58965501c55438dcd2 Mon Sep 17 00:00:00 2001 From: Anthony Thibault Date: Wed, 9 Mar 2016 16:24:08 -0800 Subject: [PATCH 09/55] OpenVR: More usable UI Sphere overlay location Also, added a debug option to display SensorToWorld matrix in Developer > Avatar menu. --- interface/src/Application.cpp | 8 -------- interface/src/Menu.cpp | 2 ++ interface/src/Menu.h | 1 + interface/src/avatar/MyAvatar.cpp | 12 ++++++++++++ interface/src/avatar/MyAvatar.h | 2 ++ plugins/openvr/src/OpenVrDisplayPlugin.cpp | 17 ++++++++++++++++- 6 files changed, 33 insertions(+), 9 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 654e58c170..d575160f99 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3288,14 +3288,6 @@ void Application::update(float deltaTime) { // update sensorToWorldMatrix for rendering camera. myAvatar->updateSensorToWorldMatrix(); - - // AJT: TODO: make this a menu item. - const bool DRAW_SENSOR_TO_WORLD_MATRIX = true; - if (DRAW_SENSOR_TO_WORLD_MATRIX) { - // draw the origin of the room in world space. - glm::mat4 m = myAvatar->getSensorToWorldMatrix(); - DebugDraw::getInstance().addMarker("room", glmExtractRotation(m), extractTranslation(m), glm::vec4(1)); - } } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index d605516380..919ee0f3c3 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -471,6 +471,8 @@ Menu::Menu() { avatar, SLOT(setUseAnimPreAndPostRotations(bool))); addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::EnableInverseKinematics, 0, true, avatar, SLOT(setEnableInverseKinematics(bool))); + addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::RenderSensorToWorldMatrix, 0, false, + avatar, SLOT(setEnableDebugDrawSensorToWorldMatrix(bool))); addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::KeyboardMotorControl, Qt::CTRL | Qt::SHIFT | Qt::Key_K, true, avatar, SLOT(updateMotionBehaviorFromMenu()), diff --git a/interface/src/Menu.h b/interface/src/Menu.h index fb00416af0..8ffd7efb36 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -144,6 +144,7 @@ namespace MenuOption { const QString RenderResolutionHalf = "1/2"; const QString RenderResolutionThird = "1/3"; const QString RenderResolutionQuarter = "1/4"; + const QString RenderSensorToWorldMatrix = "Show SensorToWorld Matrix"; const QString ResetAvatarSize = "Reset Avatar Size"; const QString ResetSensors = "Reset Sensors"; const QString RunningScripts = "Running Scripts..."; diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 397627434f..a5b69f2be6 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -442,6 +442,10 @@ void MyAvatar::updateSensorToWorldMatrix() { _sensorToWorldMatrix = desiredMat * glm::inverse(_bodySensorMatrix); lateUpdatePalms(); + + if (_enableDebugDrawSensorToWorldMatrix) { + DebugDraw::getInstance().addMarker("sensorToWorldMatrix", glmExtractRotation(_sensorToWorldMatrix), extractTranslation(_sensorToWorldMatrix), glm::vec4(1)); + } } // Update avatar head rotation with sensor data @@ -695,6 +699,14 @@ void MyAvatar::setEnableDebugDrawPosition(bool isEnabled) { } } +void MyAvatar::setEnableDebugDrawSensorToWorldMatrix(bool isEnabled) { + _enableDebugDrawSensorToWorldMatrix = isEnabled; + + if (!isEnabled) { + DebugDraw::getInstance().removeMarker("sensorToWorldMatrix"); + } +} + void MyAvatar::setEnableMeshVisible(bool isEnabled) { render::ScenePointer scene = qApp->getMain3DScene(); _skeletonModel.setVisibleInScene(isEnabled, scene); diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 731cba8153..8e5c1796b1 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -267,6 +267,7 @@ public slots: void setEnableDebugDrawDefaultPose(bool isEnabled); void setEnableDebugDrawAnimPose(bool isEnabled); void setEnableDebugDrawPosition(bool isEnabled); + void setEnableDebugDrawSensorToWorldMatrix(bool isEnabled); bool getEnableMeshVisible() const { return _skeletonModel.isVisible(); } void setEnableMeshVisible(bool isEnabled); void setUseAnimPreAndPostRotations(bool isEnabled); @@ -429,6 +430,7 @@ private: bool _enableDebugDrawDefaultPose { false }; bool _enableDebugDrawAnimPose { false }; + bool _enableDebugDrawSensorToWorldMatrix { false }; AudioListenerMode _audioListenerMode; glm::vec3 _customListenPosition; diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index e5708572f6..57a896dd4d 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -68,6 +68,21 @@ void OpenVrDisplayPlugin::activate() { _compositor = vr::VRCompositor(); Q_ASSERT(_compositor); HmdDisplayPlugin::activate(); + + // set up default sensor space such that the UI overlay will align with the front of the room. + auto chaperone = vr::VRChaperone(); + if (chaperone) { + float const UI_RADIUS = 1.0f; + float const UI_HEIGHT = 1.6f; + float const UI_Z_OFFSET = 0.5; + + float xSize, zSize; + chaperone->GetPlayAreaSize(&xSize, &zSize); + glm::vec3 uiPos(0.0f, UI_HEIGHT, 0.5f * zSize - UI_RADIUS + UI_Z_OFFSET); + _sensorResetMat = glm::inverse(createMatFromQuatAndPos(Quaternions::Y_180, uiPos)); + } else { + qDebug() << "OpenVR: error could not get chaperone pointer"; + } } void OpenVrDisplayPlugin::deactivate() { @@ -115,7 +130,7 @@ glm::mat4 OpenVrDisplayPlugin::getHeadPose(uint32_t frameIndex) const { #endif vr::TrackedDevicePose_t predictedTrackedDevicePose[vr::k_unMaxTrackedDeviceCount]; - _system->GetDeviceToAbsoluteTrackingPose(vr::TrackingUniverseSeated, predictedSecondsFromNow, predictedTrackedDevicePose, vr::k_unMaxTrackedDeviceCount); + _system->GetDeviceToAbsoluteTrackingPose(vr::TrackingUniverseStanding, predictedSecondsFromNow, predictedTrackedDevicePose, vr::k_unMaxTrackedDeviceCount); // copy and process predictedTrackedDevicePoses for (int i = 0; i < vr::k_unMaxTrackedDeviceCount; i++) { From 40fbe2d1e5dd8b36db967babe346be57bde4dbf3 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 9 Mar 2016 17:33:07 -0800 Subject: [PATCH 10/55] Reuse procedurals on entities --- .../entities-renderer/src/RenderableBoxEntityItem.cpp | 7 ++++--- .../entities-renderer/src/RenderableSphereEntityItem.cpp | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp index 671043813e..58d9b6b391 100644 --- a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp @@ -31,7 +31,9 @@ EntityItemPointer RenderableBoxEntityItem::factory(const EntityItemID& entityID, void RenderableBoxEntityItem::setUserData(const QString& value) { if (value != getUserData()) { BoxEntityItem::setUserData(value); - _procedural.reset(); + if (_procedural) { + _procedural->parse(value); + } } } @@ -40,7 +42,6 @@ void RenderableBoxEntityItem::render(RenderArgs* args) { Q_ASSERT(getType() == EntityTypes::Box); Q_ASSERT(args->_batch); - if (!_procedural) { _procedural.reset(new Procedural(this->getUserData())); _procedural->_vertexSource = simple_vert; @@ -62,7 +63,7 @@ void RenderableBoxEntityItem::render(RenderArgs* args) { } batch.setModelTransform(transToCenter); // we want to include the scale as well - if (_procedural && _procedural->ready()) { + if (_procedural->ready()) { _procedural->prepare(batch, getPosition(), getDimensions()); auto color = _procedural->getColor(cubeColor); batch._glColor4f(color.r, color.g, color.b, color.a); diff --git a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp index b5867fb1ee..78ff77ce89 100644 --- a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp @@ -36,7 +36,9 @@ EntityItemPointer RenderableSphereEntityItem::factory(const EntityItemID& entity void RenderableSphereEntityItem::setUserData(const QString& value) { if (value != getUserData()) { SphereEntityItem::setUserData(value); - _procedural.reset(); + if (_procedural) { + _procedural->parse(value); + } } } From 5f1b8805cf76d9b7ef96341ac58a8a49e9a4c3df Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 9 Mar 2016 17:37:51 -0800 Subject: [PATCH 11/55] Removed unnecessary include --- interface/src/Application.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 426efbd914..66662a7500 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -69,7 +69,6 @@ #include #include #include -#include #include #include #include From d89d89fd0894404189f48db3cc42e0bf5874f691 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 9 Mar 2016 18:35:03 -0800 Subject: [PATCH 12/55] Add all entities and skybox --- .../rapidUniformChangeTest.js | 58 +++++++++++++------ 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/examples/tests/rapidUniformChange/rapidUniformChangeTest.js b/examples/tests/rapidUniformChange/rapidUniformChangeTest.js index 626ffebf8a..108b7d76af 100644 --- a/examples/tests/rapidUniformChange/rapidUniformChangeTest.js +++ b/examples/tests/rapidUniformChange/rapidUniformChangeTest.js @@ -3,8 +3,13 @@ // // Created by Eric Levin on 3/9/2016. // Copyright 2016 High Fidelity, Inc. -// This test creates a primitive with a fragment shader and rapidly updates its uniform values -// For the test to pass, the uniform should update at rate of update loop without the client crashing +// +// This test creates primitives with fragment shaders and rapidly updates its uniforms, as well as a skybox. +// For the test to pass: +// - The primitives (cube and sphere) should update at rate of update loop, cycling through red values. +// - The skymap should do the same, although its periodicity may be different. +// +// Under the hood, the primitives are driven by a uniform, while the skymap is driven by a timer. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -14,28 +19,38 @@ var orientation = Camera.getOrientation(); orientation = Quat.safeEulerAngles(orientation); orientation.x = 0; orientation = Quat.fromVec3Degrees(orientation); -var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(orientation))); + +var centerUp = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(orientation))); +centerUp.y += 0.5; +var centerDown = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(orientation))); +centerDown.y -= 0.5; var SHADER_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/rapidUniformChangeTest.fs"; - var userData = { ProceduralEntity: { shaderUrl: SHADER_URL, - uniforms: { - red: 0.0 - } + uniforms: { red: 0.0 } } } -var testEntity = Entities.addEntity({ +var edit = JSON.stringify(userData); +var testBox = Entities.addEntity({ type: "Box", - dimensions: { - x: 0.5, - y: 0.5, - z: 0.5 - }, - position: center, - userData: JSON.stringify(userData) + dimensions: { x: 0.5, y: 0.5, z: 0.5 }, + position: centerUp, + userData: edit +}); +var testSphere = Entities.addEntity({ + type: "Sphere", + dimensions: { x: 0.5, y: 0.5, z: 0.5 }, + position: centerDown, + userData: edit +}); +var testZone = Entities.addEntity({ + type: "Zone", + dimensions: { x: 3, y: 3, z: 3 }, + position: MyAvatar.position, + userData: edit }); @@ -44,7 +59,11 @@ var currentTime = 0; function update(deltaTime) { var red = (Math.sin(currentTime) + 1) / 2; userData.ProceduralEntity.uniforms.red = red; - Entities.editEntity(testEntity, {userData: JSON.stringify(userData)}); + edit = { userData: JSON.stringify(userData) }; + Entities.editEntity(testBox, edit); + Entities.editEntity(testSphere, edit); + Entities.editEntity(testZone, edit); + currentTime += deltaTime; } @@ -53,5 +72,8 @@ Script.update.connect(update); Script.scriptEnding.connect(cleanup); function cleanup() { - Entities.deleteEntity(testEntity); -} \ No newline at end of file + Entities.deleteEntity(testBox); + Entities.deleteEntity(testSphere); + Entities.deleteEntity(testZone); +} + From 42d27557a11ed30db5c1869c87c72fabce0cae1b Mon Sep 17 00:00:00 2001 From: Anthony Thibault Date: Wed, 9 Mar 2016 18:42:03 -0800 Subject: [PATCH 13/55] OpenVR: remove 180 y rotation for UI bounds. Turns out the room I was using was misconfigured. --- plugins/openvr/src/OpenVrDisplayPlugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index 57a896dd4d..83c834161b 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -79,7 +79,7 @@ void OpenVrDisplayPlugin::activate() { float xSize, zSize; chaperone->GetPlayAreaSize(&xSize, &zSize); glm::vec3 uiPos(0.0f, UI_HEIGHT, 0.5f * zSize - UI_RADIUS + UI_Z_OFFSET); - _sensorResetMat = glm::inverse(createMatFromQuatAndPos(Quaternions::Y_180, uiPos)); + _sensorResetMat = glm::inverse(createMatFromQuatAndPos(glm::quat(), uiPos)); } else { qDebug() << "OpenVR: error could not get chaperone pointer"; } From 3cd0f0d237c0655c7cb45263c5bb20bde2c93f9f Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 9 Mar 2016 18:35:15 -0800 Subject: [PATCH 14/55] Drive skybox off of timer --- .../rapidUniformChangeTest.js | 42 ++++++++++++------- .../tests/rapidProceduralChange/timerTest.fs | 21 ++++++++++ .../uniformTest.fs} | 15 +++---- 3 files changed, 55 insertions(+), 23 deletions(-) rename examples/tests/{rapidUniformChange => rapidProceduralChange}/rapidUniformChangeTest.js (61%) create mode 100644 examples/tests/rapidProceduralChange/timerTest.fs rename examples/tests/{rapidUniformChange/rapidUniformChangeTest.fs => rapidProceduralChange/uniformTest.fs} (85%) diff --git a/examples/tests/rapidUniformChange/rapidUniformChangeTest.js b/examples/tests/rapidProceduralChange/rapidUniformChangeTest.js similarity index 61% rename from examples/tests/rapidUniformChange/rapidUniformChangeTest.js rename to examples/tests/rapidProceduralChange/rapidUniformChangeTest.js index 108b7d76af..5652574756 100644 --- a/examples/tests/rapidUniformChange/rapidUniformChangeTest.js +++ b/examples/tests/rapidProceduralChange/rapidUniformChangeTest.js @@ -1,5 +1,5 @@ -// rapidUniformChangeTest.js -// examples +// rapidProceduralChangeTest.js +// examples/tests/rapidProceduralChange // // Created by Eric Levin on 3/9/2016. // Copyright 2016 High Fidelity, Inc. @@ -25,32 +25,40 @@ centerUp.y += 0.5; var centerDown = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(orientation))); centerDown.y -= 0.5; -var SHADER_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/rapidUniformChangeTest.fs"; +var ENTITY_SHADER_URL = "file:///C:/Users/User/Code/hifi-master/examples/tests/rapidUniformChange/uniformTest.fs"; +var SKYBOX_SHADER_URL = "file:///C:/Users/User/Code/hifi-master/examples/tests/rapidUniformChange/timerTest.fs"; -var userData = { +var entityData = { ProceduralEntity: { - shaderUrl: SHADER_URL, + shaderUrl: ENTITY_SHADER_URL, uniforms: { red: 0.0 } } -} -var edit = JSON.stringify(userData); +}; +var skyboxData = { + ProceduralEntity: { + shaderUrl: SKYBOX_SHADER_URL, + uniforms: { red: 0.0 } + } +}; var testBox = Entities.addEntity({ type: "Box", dimensions: { x: 0.5, y: 0.5, z: 0.5 }, position: centerUp, - userData: edit + userData: JSON.stringify(entityData) }); var testSphere = Entities.addEntity({ type: "Sphere", dimensions: { x: 0.5, y: 0.5, z: 0.5 }, position: centerDown, - userData: edit + userData: JSON.stringify(entityData) }); var testZone = Entities.addEntity({ type: "Zone", - dimensions: { x: 3, y: 3, z: 3 }, + dimensions: { x: 50, y: 50, z: 50 }, position: MyAvatar.position, - userData: edit + userData: JSON.stringify(skyboxData), + backgroundMode: "skybox", + skybox: { url: "http://kyoub.googlecode.com/svn/trunk/KYouB/textures/skybox_test.png" } }); @@ -58,11 +66,13 @@ var currentTime = 0; function update(deltaTime) { var red = (Math.sin(currentTime) + 1) / 2; - userData.ProceduralEntity.uniforms.red = red; - edit = { userData: JSON.stringify(userData) }; - Entities.editEntity(testBox, edit); - Entities.editEntity(testSphere, edit); - Entities.editEntity(testZone, edit); + entityData.ProceduralEntity.uniforms.red = red; + skyboxData.ProceduralEntity.uniforms.red = red; + entityEdit = { userData: JSON.stringify(entityData) }; + skyboxEdit = { userData: JSON.stringify(skyboxData) }; + Entities.editEntity(testBox, entityEdit); + Entities.editEntity(testSphere, entityEdit); + Entities.editEntity(testZone, skyboxEdit); currentTime += deltaTime; } diff --git a/examples/tests/rapidProceduralChange/timerTest.fs b/examples/tests/rapidProceduralChange/timerTest.fs new file mode 100644 index 0000000000..e0fcf9d1d6 --- /dev/null +++ b/examples/tests/rapidProceduralChange/timerTest.fs @@ -0,0 +1,21 @@ +// +// timerTest.fs +// examples/tests/rapidProceduralChange +// +// Created by Eric Levin on 3/9/16. +// Copyright 2016 High Fidelity, Inc. +// +// This fragment shader is designed to test the rapid changing of a uniform on the timer. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + + +uniform float red; + +vec3 getSkyboxColor() { + float blue = red; + blue = (cos(iGlobalTime) + 1) / 2; + return vec3(1.0, 0.0, blue); +} + diff --git a/examples/tests/rapidUniformChange/rapidUniformChangeTest.fs b/examples/tests/rapidProceduralChange/uniformTest.fs similarity index 85% rename from examples/tests/rapidUniformChange/rapidUniformChangeTest.fs rename to examples/tests/rapidProceduralChange/uniformTest.fs index 31ba437003..fe0ad6a1ea 100644 --- a/examples/tests/rapidUniformChange/rapidUniformChangeTest.fs +++ b/examples/tests/rapidProceduralChange/uniformTest.fs @@ -1,26 +1,27 @@ - // -// rapidUniformChangeTest.fs -// examples/homeContent/plant +// uniformTest.fs +// examples/tests/rapidProceduralChange // // Created by Eric Levin on 3/9/16. // Copyright 2016 High Fidelity, Inc. // -// This fragment shader is designed to test the rapid changing of a uniform +// This fragment shader is designed to test the rapid changing of a uniform. +// // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -uniform float red = 0.1; - +uniform float red; void mainImage(out vec4 fragColor, in vec2 fragCoord) { fragColor = vec4(red, 0.0, 1.0, 1.0); } + vec4 getProceduralColor() { vec4 result; vec2 position = _position.xz; position += 0.5; mainImage(result, position * iWorldScale.xz); return result; -} \ No newline at end of file +} + From 4022474b48e1eef6c267b79ae65a95b4135f05ae Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 9 Mar 2016 17:33:19 -0800 Subject: [PATCH 15/55] Constrain procedural updates to render thread --- .../procedural/src/procedural/Procedural.cpp | 153 +++++++++++------- .../procedural/src/procedural/Procedural.h | 46 ++++-- 2 files changed, 132 insertions(+), 67 deletions(-) diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index b1e4bd53ed..f7c4a783aa 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -69,74 +69,108 @@ Procedural::Procedural(const QString& userDataJson) { } void Procedural::parse(const QString& userDataJson) { - _enabled = false; auto proceduralData = getProceduralData(userDataJson); - if (proceduralData.isObject()) { - parse(proceduralData.toObject()); - } + // Instead of parsing, prep for a parse on the rendering thread + // This will be called by Procedural::ready + _proceduralData = proceduralData.toObject(); + _proceduralDataDirty = true; } -void Procedural::parse(const QJsonObject& proceduralData) { - // grab the version number - { - auto version = proceduralData[VERSION_KEY]; - if (version.isDouble()) { - _version = (uint8_t)(floor(version.toDouble())); - } +bool Procedural::parseVersion(const QJsonValue& version) { + if (version.isDouble()) { + _version = (uint8_t)(floor(version.toDouble())); + } else { + // All unversioned shaders default to V1 + _version = 1; + } + return (_version == 1 || _version == 2); +} + +bool Procedural::parseUrl(const QUrl& shaderUrl) { + if (!shaderUrl.isValid()) { + qWarning() << "Invalid shader URL: " << shaderUrl; + return false; } - // Get the path to the shader - { - QString shaderUrl = proceduralData[URL_KEY].toString(); - shaderUrl = ResourceManager::normalizeURL(shaderUrl); - _shaderUrl = QUrl(shaderUrl); - if (!_shaderUrl.isValid()) { - qWarning() << "Invalid shader URL: " << shaderUrl; - return; - } - - if (_shaderUrl.isLocalFile()) { - _shaderPath = _shaderUrl.toLocalFile(); - qDebug() << "Shader path: " << _shaderPath; - if (!QFile(_shaderPath).exists()) { - return; - } - } else { - qDebug() << "Shader url: " << _shaderUrl; - _networkShader = ShaderCache::instance().getShader(_shaderUrl); - } + if (_shaderUrl == shaderUrl) { + return true; } - // Grab any custom uniforms - { - auto uniforms = proceduralData[UNIFORMS_KEY]; - if (uniforms.isObject()) { - _parsedUniforms = uniforms.toObject(); + _shaderUrl = shaderUrl; + + if (_shaderUrl.isLocalFile()) { + _shaderPath = _shaderUrl.toLocalFile(); + qDebug() << "Shader path: " << _shaderPath; + if (!QFile(_shaderPath).exists()) { + return false;; } + } else { + qDebug() << "Shader url: " << _shaderUrl; + _networkShader = ShaderCache::instance().getShader(_shaderUrl); } - // Grab any textures - { - auto channels = proceduralData[CHANNELS_KEY]; - if (channels.isArray()) { - auto textureCache = DependencyManager::get(); - _parsedChannels = channels.toArray(); - size_t channelCount = std::min(MAX_PROCEDURAL_TEXTURE_CHANNELS, (size_t)_parsedChannels.size()); - for (size_t i = 0; i < channelCount; ++i) { - QString url = _parsedChannels.at((int)i).toString(); - _channels[i] = textureCache->getTexture(QUrl(url)); - } - } + return true; +} + +bool Procedural::parseUniforms(const QJsonObject& uniforms) { + if (_parsedUniforms != uniforms) { + _parsedUniforms = uniforms; + _uniformsDirty = true; + } + + return true; +} + +bool Procedural::parseTextures(const QJsonArray& channels) { + if (_parsedChannels != channels) { + _parsedChannels = channels; + + auto textureCache = DependencyManager::get(); + size_t channelCount = std::min(MAX_PROCEDURAL_TEXTURE_CHANNELS, (size_t)_parsedChannels.size()); + for (size_t i = 0; i < channelCount; ++i) { + QString url = _parsedChannels.at((int)i).toString(); + _channels[i] = textureCache->getTexture(QUrl(url)); + } + + _channelsDirty = true; + } + + return true; +} + +void Procedural::parse(QJsonObject proceduralData) { + _enabled = false; + + if (proceduralData.isEmpty()) { + return; + } + + auto version = proceduralData[VERSION_KEY]; + auto shaderUrl = proceduralData[URL_KEY].toString(); + shaderUrl = ResourceManager::normalizeURL(shaderUrl); + auto uniforms = proceduralData[UNIFORMS_KEY].toObject(); + auto channels = proceduralData[CHANNELS_KEY].toArray(); + + if (parseVersion(proceduralData[VERSION_KEY]) && + parseUrl(shaderUrl) && + parseUniforms(uniforms) && + parseTextures(channels)) { + _enabled = true; } - _enabled = true; } bool Procedural::ready() { + // Load any changes to the procedural + if (_proceduralDataDirty) { + parse(_proceduralData); + _proceduralDataDirty = false; + } + if (!_enabled) { return false; } - // Do we have a network or local shader + // Do we have a network or local shader, and if so, is it loaded? if (_shaderPath.isEmpty() && (!_networkShader || !_networkShader->isLoaded())) { return false; } @@ -160,15 +194,14 @@ void Procedural::prepare(gpu::Batch& batch, const glm::vec3& position, const glm QFile file(_shaderPath); file.open(QIODevice::ReadOnly); _shaderSource = QTextStream(&file).readAll(); - _pipelineDirty = true; + _shaderDirty = true; _shaderModified = lastModified; } } else if (_networkShader && _networkShader->isLoaded()) { _shaderSource = _networkShader->_source; } - if (!_pipeline || _pipelineDirty) { - _pipelineDirty = true; + if (!_pipeline || _shaderDirty) { if (!_vertexShader) { _vertexShader = gpu::Shader::createVertex(_vertexSource); } @@ -214,11 +247,15 @@ void Procedural::prepare(gpu::Batch& batch, const glm::vec3& position, const glm batch.setPipeline(_pipeline); - if (_pipelineDirty) { - _pipelineDirty = false; + if (_shaderDirty || _uniformsDirty) { setupUniforms(); } + if (_shaderDirty || _uniformsDirty || _channelsDirty) { + setupChannels(_shaderDirty || _uniformsDirty); + } + + _shaderDirty = _uniformsDirty = _channelsDirty = false; for (auto lambda : _uniforms) { lambda(batch); @@ -359,8 +396,14 @@ void Procedural::setupUniforms() { batch._glUniform(_standardUniformSlots[POSITION], _entityPosition); }); } +} +void Procedural::setupChannels(bool shouldCreate) { if (gpu::Shader::INVALID_LOCATION != _standardUniformSlots[CHANNEL_RESOLUTION]) { + if (!shouldCreate) { + // Instead of modifying the last element, just remove and recreate it. + _uniforms.pop_back(); + } _uniforms.push_back([=](gpu::Batch& batch) { vec3 channelSizes[MAX_PROCEDURAL_TEXTURE_CHANNELS]; for (size_t i = 0; i < MAX_PROCEDURAL_TEXTURE_CHANNELS; ++i) { diff --git a/libraries/procedural/src/procedural/Procedural.h b/libraries/procedural/src/procedural/Procedural.h index 1b02fbd435..41493664b1 100644 --- a/libraries/procedural/src/procedural/Procedural.h +++ b/libraries/procedural/src/procedural/Procedural.h @@ -28,27 +28,24 @@ const size_t MAX_PROCEDURAL_TEXTURE_CHANNELS{ 4 }; // FIXME better encapsulation // FIXME better mechanism for extending to things rendered using shaders other than simple.slv struct Procedural { +public: static QJsonValue getProceduralData(const QString& proceduralJson); Procedural(const QString& userDataJson); void parse(const QString& userDataJson); - void parse(const QJsonObject&); + bool ready(); void prepare(gpu::Batch& batch, const glm::vec3& position, const glm::vec3& size); - void setupUniforms(); + glm::vec4 getColor(const glm::vec4& entityColor); - bool _enabled{ false }; - uint8_t _version{ 1 }; + bool _enabled { false }; + uint8_t _version { 1 }; std::string _vertexSource; std::string _fragmentSource; - QString _shaderSource; - QString _shaderPath; - QUrl _shaderUrl; - quint64 _shaderModified{ 0 }; - bool _pipelineDirty{ true }; + gpu::StatePointer _state; enum StandardUniforms { DATE, @@ -60,23 +57,48 @@ struct Procedural { NUM_STANDARD_UNIFORMS }; - int32_t _standardUniformSlots[NUM_STANDARD_UNIFORMS]; - +protected: + // Procedural metadata uint64_t _start{ 0 }; int32_t _frameCount{ 0 }; + + // Rendering object descriptions, from userData + QJsonObject _proceduralData; + QString _shaderSource; + QString _shaderPath; + QUrl _shaderUrl; + quint64 _shaderModified { 0 }; NetworkShaderPointer _networkShader; QJsonObject _parsedUniforms; QJsonArray _parsedChannels; + bool _proceduralDataDirty { true }; + bool _shaderDirty { true }; + bool _uniformsDirty { true }; + bool _channelsDirty { true }; + // Rendering objects UniformLambdas _uniforms; + int32_t _standardUniformSlots[NUM_STANDARD_UNIFORMS]; NetworkTexturePointer _channels[MAX_PROCEDURAL_TEXTURE_CHANNELS]; gpu::PipelinePointer _pipeline; gpu::ShaderPointer _vertexShader; gpu::ShaderPointer _fragmentShader; gpu::ShaderPointer _shader; - gpu::StatePointer _state; + + // Entity metadata glm::vec3 _entityDimensions; glm::vec3 _entityPosition; + +private: + // This should only be called from the render thread, as it shares data with Procedural::prepare + void parse(QJsonObject); + bool parseVersion(const QJsonValue& version); + bool parseUrl(const QUrl& url); + bool parseUniforms(const QJsonObject& uniforms); + bool parseTextures(const QJsonArray& channels); + + void setupUniforms(); + void setupChannels(bool shouldCreate); }; #endif From 74e1d322215e67244ea22823565758fcb2aa19b6 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 9 Mar 2016 17:48:24 -0800 Subject: [PATCH 16/55] Reuse procedural on skybox --- .../src/EntityTreeRenderer.cpp | 7 +----- .../procedural/src/procedural/Procedural.cpp | 3 +++ .../procedural/src/procedural/Procedural.h | 7 +++--- .../src/procedural/ProceduralSkybox.cpp | 23 ++++++++----------- .../src/procedural/ProceduralSkybox.h | 6 ++--- 5 files changed, 19 insertions(+), 27 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 44c3146b41..421213151a 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -341,12 +341,7 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptrgetUserData()) { userData = zone->getUserData(); - auto procedural = std::make_shared(userData); - if (procedural->_enabled) { - skybox->setProcedural(procedural); - } else { - skybox->setProcedural(ProceduralPointer()); - } + skybox->setProcedural(userData); } if (zone->getSkyboxProperties().getURL().isEmpty()) { skybox->setCubemap(gpu::TexturePointer()); diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index f7c4a783aa..cc9e5841ed 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -62,6 +62,9 @@ QJsonValue Procedural::getProceduralData(const QString& proceduralJson) { return doc.object()[PROCEDURAL_USER_DATA_KEY]; } +Procedural::Procedural() { + _state = std::make_shared(); +} Procedural::Procedural(const QString& userDataJson) { parse(userDataJson); diff --git a/libraries/procedural/src/procedural/Procedural.h b/libraries/procedural/src/procedural/Procedural.h index 41493664b1..0d602eab4f 100644 --- a/libraries/procedural/src/procedural/Procedural.h +++ b/libraries/procedural/src/procedural/Procedural.h @@ -31,6 +31,7 @@ struct Procedural { public: static QJsonValue getProceduralData(const QString& proceduralJson); + Procedural(); Procedural(const QString& userDataJson); void parse(const QString& userDataJson); @@ -39,7 +40,6 @@ public: glm::vec4 getColor(const glm::vec4& entityColor); - bool _enabled { false }; uint8_t _version { 1 }; std::string _vertexSource; @@ -59,8 +59,9 @@ public: protected: // Procedural metadata - uint64_t _start{ 0 }; - int32_t _frameCount{ 0 }; + bool _enabled { false }; + uint64_t _start { 0 }; + int32_t _frameCount { 0 }; // Rendering object descriptions, from userData QJsonObject _proceduralData; diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.cpp b/libraries/procedural/src/procedural/ProceduralSkybox.cpp index 167d49cbaf..f3ee08dd7a 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.cpp +++ b/libraries/procedural/src/procedural/ProceduralSkybox.cpp @@ -19,6 +19,10 @@ #include "ProceduralSkybox_frag.h" ProceduralSkybox::ProceduralSkybox() : model::Skybox() { + _procedural._vertexSource = ProceduralSkybox_vert; + _procedural._fragmentSource = ProceduralSkybox_frag; + // Adjust the pipeline state for background using the stencil test + _procedural._state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); } ProceduralSkybox::ProceduralSkybox(const ProceduralSkybox& skybox) : @@ -27,14 +31,8 @@ ProceduralSkybox::ProceduralSkybox(const ProceduralSkybox& skybox) : } -void ProceduralSkybox::setProcedural(const ProceduralPointer& procedural) { - _procedural = procedural; - if (_procedural) { - _procedural->_vertexSource = ProceduralSkybox_vert; - _procedural->_fragmentSource = ProceduralSkybox_frag; - // Adjust the pipeline state for background using the stencil test - _procedural->_state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); - } +void ProceduralSkybox::setProcedural(const QString& userData) { + _procedural.parse(userData); } void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& frustum) const { @@ -42,12 +40,10 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& frustum) con } void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const ProceduralSkybox& skybox) { - if (!(skybox._procedural)) { + if (!(skybox._procedural.ready())) { skybox.updateDataBuffer(); Skybox::render(batch, viewFrustum, skybox); - } - - if (skybox._procedural && skybox._procedural->_enabled && skybox._procedural->ready()) { + } else { gpu::TexturePointer skymap = skybox.getCubemap(); // FIXME: skymap->isDefined may not be threadsafe assert(skymap && skymap->isDefined()); @@ -62,8 +58,7 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, batch.setModelTransform(Transform()); // only for Mac batch.setResourceTexture(0, skybox.getCubemap()); - skybox._procedural->prepare(batch, glm::vec3(0), glm::vec3(1)); + skybox._procedural.prepare(batch, glm::vec3(0), glm::vec3(1)); batch.draw(gpu::TRIANGLE_STRIP, 4); } } - diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.h b/libraries/procedural/src/procedural/ProceduralSkybox.h index 057a1ccc74..37cc2baaaf 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.h +++ b/libraries/procedural/src/procedural/ProceduralSkybox.h @@ -17,8 +17,6 @@ #include "Procedural.h" -typedef std::shared_ptr ProceduralPointer; - class ProceduralSkybox: public model::Skybox { public: ProceduralSkybox(); @@ -26,13 +24,13 @@ public: ProceduralSkybox& operator= (const ProceduralSkybox& skybox); virtual ~ProceduralSkybox() {}; - void setProcedural(const ProceduralPointer& procedural); + void setProcedural(const QString& userData); virtual void render(gpu::Batch& batch, const ViewFrustum& frustum) const; static void render(gpu::Batch& batch, const ViewFrustum& frustum, const ProceduralSkybox& skybox); protected: - ProceduralPointer _procedural; + mutable Procedural _procedural; }; typedef std::shared_ptr< ProceduralSkybox > ProceduralSkyboxPointer; From f6276615f7a597af245173204d28c00572bf6a77 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 10 Mar 2016 09:31:05 -0800 Subject: [PATCH 17/55] Trying to fix the bound out of the octree volume problem --- libraries/render/src/render/SpatialTree.cpp | 4 ++-- libraries/render/src/render/SpatialTree.h | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/libraries/render/src/render/SpatialTree.cpp b/libraries/render/src/render/SpatialTree.cpp index b09b6f4778..c6689cb5a7 100644 --- a/libraries/render/src/render/SpatialTree.cpp +++ b/libraries/render/src/render/SpatialTree.cpp @@ -554,11 +554,11 @@ int ItemSpatialTree::selectCells(CellSelection& selection, const ViewFrustum& fr FrustumSelector selector; for (int i = 0; i < ViewFrustum::NUM_PLANES; i++) { ::Plane octPlane; - octPlane.setNormalAndPoint(worldPlanes[i].getNormal(), evalCoordf(worldPlanes[i].getPoint(), ROOT_DEPTH)); + octPlane.setNormalAndPoint(worldPlanes[i].getNormal(), evalCoordNoClampf(worldPlanes[i].getPoint(), ROOT_DEPTH)); selector.frustum[i] = Coord4f(octPlane.getNormal(), octPlane.getDCoefficient()); } - selector.eyePos = evalCoordf(frustum.getPosition(), ROOT_DEPTH); + selector.eyePos = evalCoordNoClampf(frustum.getPosition(), ROOT_DEPTH); selector.setAngle(glm::radians(lodAngle)); return Octree::select(selection, selector); diff --git a/libraries/render/src/render/SpatialTree.h b/libraries/render/src/render/SpatialTree.h index a5dbb29544..36ded44cfb 100644 --- a/libraries/render/src/render/SpatialTree.h +++ b/libraries/render/src/render/SpatialTree.h @@ -117,7 +117,6 @@ namespace render { return depth; } - class Location { void assertValid() { assert((pos.x >= 0) && (pos.y >= 0) && (pos.z >= 0)); @@ -157,6 +156,7 @@ namespace render { // Eval the location best fitting the specified range static Location evalFromRange(const Coord3& minCoord, const Coord3& maxCoord, Depth rangeDepth = MAX_DEPTH); + // Eval the intersection test against a frustum enum Intersection { Outside = 0, @@ -398,12 +398,25 @@ namespace render { return getOrigin() + glm::vec3(coord) * cellWidth; } + + // Clamp a position expressed in a depth space to make sure it is in the valid space for that Depth + glm::vec3 clampRelPosToTreeRange(const glm::vec3& pos) const { + return glm::vec3( + std::min(std::max(pos.x, 0.0f), _size), + std::min(std::max(pos.y, 0.0f), _size), + std::min(std::max(pos.z, 0.0f), _size)); + } Coord3 evalCoord(const glm::vec3& pos, Depth depth = Octree::METRIC_COORD_DEPTH) const { - auto npos = (pos - getOrigin()); + auto npos = clampRelPosToTreeRange((pos - getOrigin())); + return Coord3(npos * getInvCellWidth(depth)); // Truncate fractional part } Coord3f evalCoordf(const glm::vec3& pos, Depth depth = Octree::METRIC_COORD_DEPTH) const { - auto npos = (pos - getOrigin()); + auto npos = clampRelPosToTreeRange((pos - getOrigin())); + return Coord3f(npos * getInvCellWidth(depth)); + } + Coord3f evalCoordNoClampf(const glm::vec3& pos, Depth depth = Octree::METRIC_COORD_DEPTH) const { + auto npos = ((pos - getOrigin())); return Coord3f(npos * getInvCellWidth(depth)); } @@ -412,6 +425,8 @@ namespace render { float cellWidth = getCellWidth(loc.depth); return AABox(evalPos(loc.pos, cellWidth), cellWidth); } + + Location evalLocation(const AABox& bound) const { return Location::evalFromRange(evalCoord(bound.getMinimumPoint()), evalCoord(bound.getMaximumPoint())); } From 153f7fc3aa9088fffdcc22b3524a0877da9aa996 Mon Sep 17 00:00:00 2001 From: Anthony Thibault Date: Thu, 10 Mar 2016 09:45:47 -0800 Subject: [PATCH 18/55] OpenVR: adjusted translation of UI sphere overlay --- plugins/openvr/src/OpenVrDisplayPlugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index 83c834161b..b86a7f9ebc 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -78,7 +78,7 @@ void OpenVrDisplayPlugin::activate() { float xSize, zSize; chaperone->GetPlayAreaSize(&xSize, &zSize); - glm::vec3 uiPos(0.0f, UI_HEIGHT, 0.5f * zSize - UI_RADIUS + UI_Z_OFFSET); + glm::vec3 uiPos(0.0f, UI_HEIGHT, UI_RADIUS - (0.5f * zSize) - UI_Z_OFFSET); _sensorResetMat = glm::inverse(createMatFromQuatAndPos(glm::quat(), uiPos)); } else { qDebug() << "OpenVR: error could not get chaperone pointer"; From 1640314076cf29cf6f51b28499322dc0c9743201 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 10:12:22 -0800 Subject: [PATCH 19/55] Use one procedural for skybox (avoid copies) --- libraries/entities-renderer/src/EntityTreeRenderer.cpp | 2 +- .../procedural/src/procedural/ProceduralSkybox.cpp | 10 ---------- libraries/procedural/src/procedural/ProceduralSkybox.h | 4 +--- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 421213151a..5cf1b1548a 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -341,7 +341,7 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptrgetUserData()) { userData = zone->getUserData(); - skybox->setProcedural(userData); + skybox->parse(userData); } if (zone->getSkyboxProperties().getURL().isEmpty()) { skybox->setCubemap(gpu::TexturePointer()); diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.cpp b/libraries/procedural/src/procedural/ProceduralSkybox.cpp index f3ee08dd7a..9c311acb3d 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.cpp +++ b/libraries/procedural/src/procedural/ProceduralSkybox.cpp @@ -25,16 +25,6 @@ ProceduralSkybox::ProceduralSkybox() : model::Skybox() { _procedural._state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); } -ProceduralSkybox::ProceduralSkybox(const ProceduralSkybox& skybox) : - model::Skybox(skybox), - _procedural(skybox._procedural) { - -} - -void ProceduralSkybox::setProcedural(const QString& userData) { - _procedural.parse(userData); -} - void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& frustum) const { ProceduralSkybox::render(batch, frustum, (*this)); } diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.h b/libraries/procedural/src/procedural/ProceduralSkybox.h index 37cc2baaaf..e817ce271d 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.h +++ b/libraries/procedural/src/procedural/ProceduralSkybox.h @@ -20,11 +20,9 @@ class ProceduralSkybox: public model::Skybox { public: ProceduralSkybox(); - ProceduralSkybox(const ProceduralSkybox& skybox); - ProceduralSkybox& operator= (const ProceduralSkybox& skybox); virtual ~ProceduralSkybox() {}; - void setProcedural(const QString& userData); + void parse(const QString& userData) { _procedural.parse(userData); } virtual void render(gpu::Batch& batch, const ViewFrustum& frustum) const; static void render(gpu::Batch& batch, const ViewFrustum& frustum, const ProceduralSkybox& skybox); From 9b89e46e65eb4b80d13d2cfbaadc4f36e123c924 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 10:12:55 -0800 Subject: [PATCH 20/55] Make procedural userData thread-safe --- libraries/procedural/src/procedural/Procedural.cpp | 2 ++ libraries/procedural/src/procedural/Procedural.h | 1 + 2 files changed, 3 insertions(+) diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index cc9e5841ed..6cf9f05372 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -75,6 +75,7 @@ void Procedural::parse(const QString& userDataJson) { auto proceduralData = getProceduralData(userDataJson); // Instead of parsing, prep for a parse on the rendering thread // This will be called by Procedural::ready + std::lock_guard lock(_proceduralDataMutex); _proceduralData = proceduralData.toObject(); _proceduralDataDirty = true; } @@ -165,6 +166,7 @@ void Procedural::parse(QJsonObject proceduralData) { bool Procedural::ready() { // Load any changes to the procedural if (_proceduralDataDirty) { + std::lock_guard lock(_proceduralDataMutex); parse(_proceduralData); _proceduralDataDirty = false; } diff --git a/libraries/procedural/src/procedural/Procedural.h b/libraries/procedural/src/procedural/Procedural.h index 0d602eab4f..75872ca2bc 100644 --- a/libraries/procedural/src/procedural/Procedural.h +++ b/libraries/procedural/src/procedural/Procedural.h @@ -65,6 +65,7 @@ protected: // Rendering object descriptions, from userData QJsonObject _proceduralData; + std::mutex _proceduralDataMutex; QString _shaderSource; QString _shaderPath; QUrl _shaderUrl; From f37049059e8f5a559d242ba9a5a8674ffcbd38d1 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 10:19:52 -0800 Subject: [PATCH 21/55] Finish name changes for rapidProceduralChange --- ...rapidUniformChangeTest.js => rapidProceduralChangeTest.js} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename examples/tests/rapidProceduralChange/{rapidUniformChangeTest.js => rapidProceduralChangeTest.js} (96%) diff --git a/examples/tests/rapidProceduralChange/rapidUniformChangeTest.js b/examples/tests/rapidProceduralChange/rapidProceduralChangeTest.js similarity index 96% rename from examples/tests/rapidProceduralChange/rapidUniformChangeTest.js rename to examples/tests/rapidProceduralChange/rapidProceduralChangeTest.js index 5652574756..5ec71330b8 100644 --- a/examples/tests/rapidProceduralChange/rapidUniformChangeTest.js +++ b/examples/tests/rapidProceduralChange/rapidProceduralChangeTest.js @@ -25,8 +25,8 @@ centerUp.y += 0.5; var centerDown = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(orientation))); centerDown.y -= 0.5; -var ENTITY_SHADER_URL = "file:///C:/Users/User/Code/hifi-master/examples/tests/rapidUniformChange/uniformTest.fs"; -var SKYBOX_SHADER_URL = "file:///C:/Users/User/Code/hifi-master/examples/tests/rapidUniformChange/timerTest.fs"; +var ENTITY_SHADER_URL = "file:///C:/Users/User/Code/hifi-master/examples/tests/rapidProceduralChange/uniformTest.fs"; +var SKYBOX_SHADER_URL = "file:///C:/Users/User/Code/hifi-master/examples/tests/rapidProceduralChange/timerTest.fs"; var entityData = { ProceduralEntity: { From 64042327eca3e3bff21b4ca17c937d30b6e555f1 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 11:08:15 -0800 Subject: [PATCH 22/55] Use version tmp var --- libraries/procedural/src/procedural/Procedural.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index 6cf9f05372..9670b66676 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -155,7 +155,7 @@ void Procedural::parse(QJsonObject proceduralData) { auto uniforms = proceduralData[UNIFORMS_KEY].toObject(); auto channels = proceduralData[CHANNELS_KEY].toArray(); - if (parseVersion(proceduralData[VERSION_KEY]) && + if (parseVersion(version) && parseUrl(shaderUrl) && parseUniforms(uniforms) && parseTextures(channels)) { From 2af4dd90e19a86eb5b958cf30e4e95c5b376d4bf Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 10 Mar 2016 11:40:09 -0800 Subject: [PATCH 23/55] updated shader links to be s3 --- .../tests/rapidProceduralChange/rapidProceduralChangeTest.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/tests/rapidProceduralChange/rapidProceduralChangeTest.js b/examples/tests/rapidProceduralChange/rapidProceduralChangeTest.js index 5ec71330b8..0d1bfd57ac 100644 --- a/examples/tests/rapidProceduralChange/rapidProceduralChangeTest.js +++ b/examples/tests/rapidProceduralChange/rapidProceduralChangeTest.js @@ -25,8 +25,8 @@ centerUp.y += 0.5; var centerDown = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(orientation))); centerDown.y -= 0.5; -var ENTITY_SHADER_URL = "file:///C:/Users/User/Code/hifi-master/examples/tests/rapidProceduralChange/uniformTest.fs"; -var SKYBOX_SHADER_URL = "file:///C:/Users/User/Code/hifi-master/examples/tests/rapidProceduralChange/timerTest.fs"; +var ENTITY_SHADER_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/uniformTest.fs"; +var SKYBOX_SHADER_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/timerTest.fs"; var entityData = { ProceduralEntity: { From 8fe926e5351ef70ba082ff6431f287082a72aa19 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 10 Mar 2016 11:41:12 -0800 Subject: [PATCH 24/55] added print statements --- .../tests/rapidProceduralChange/rapidProceduralChangeTest.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/tests/rapidProceduralChange/rapidProceduralChangeTest.js b/examples/tests/rapidProceduralChange/rapidProceduralChangeTest.js index 0d1bfd57ac..46c510951d 100644 --- a/examples/tests/rapidProceduralChange/rapidProceduralChangeTest.js +++ b/examples/tests/rapidProceduralChange/rapidProceduralChangeTest.js @@ -40,6 +40,8 @@ var skyboxData = { uniforms: { red: 0.0 } } }; + +print("ABOUT TO ADD ENTITY"); var testBox = Entities.addEntity({ type: "Box", dimensions: { x: 0.5, y: 0.5, z: 0.5 }, @@ -70,6 +72,8 @@ function update(deltaTime) { skyboxData.ProceduralEntity.uniforms.red = red; entityEdit = { userData: JSON.stringify(entityData) }; skyboxEdit = { userData: JSON.stringify(skyboxData) }; + + print("ABOUT TO EDIT ENTITIES"); Entities.editEntity(testBox, entityEdit); Entities.editEntity(testSphere, entityEdit); Entities.editEntity(testZone, skyboxEdit); From d615e2e83b68e59c9d538fa31ff9f78c030096e9 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Tue, 1 Mar 2016 17:46:53 -0800 Subject: [PATCH 25/55] Avoid redundant zone updates --- .../entities-renderer/src/EntityTreeRenderer.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 44c3146b41..dc59d40e82 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -158,6 +158,8 @@ void EntityTreeRenderer::update() { } bool EntityTreeRenderer::checkEnterLeaveEntities() { + bool didUpdate = false; + if (_tree && !_shuttingDown) { glm::vec3 avatarPosition = _viewState->getAvatarPosition(); @@ -172,6 +174,7 @@ bool EntityTreeRenderer::checkEnterLeaveEntities() { std::static_pointer_cast(_tree)->findEntities(avatarPosition, radius, foundEntities); // Whenever you're in an intersection between zones, we will always choose the smallest zone. + auto oldBestZone = _bestZone; _bestZone = nullptr; // NOTE: Is this what we want? _bestZoneVolume = std::numeric_limits::max(); @@ -204,7 +207,10 @@ bool EntityTreeRenderer::checkEnterLeaveEntities() { } } - applyZonePropertiesToScene(_bestZone); + if (_bestZone != oldBestZone) { + applyZonePropertiesToScene(_bestZone); + didUpdate = true; + } }); // Note: at this point we don't need to worry about the tree being locked, because we only deal with @@ -228,11 +234,9 @@ bool EntityTreeRenderer::checkEnterLeaveEntities() { } _currentEntitiesInside = entitiesContainingAvatar; _lastAvatarPosition = avatarPosition; - - return true; } } - return false; + return didUpdate; } void EntityTreeRenderer::leaveAllEntities() { From 1e925d7bd87b3cea6faa155cb2c1c9b4b55cbd7d Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Tue, 1 Mar 2016 18:53:46 -0800 Subject: [PATCH 26/55] Fetch unspecified textures on a delay This fixes an abort caused by the assertion in ResourceCache::getResource: assert(delayLoad). --- .../model-networking/src/model-networking/TextureCache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index a2cd3284ef..58a82d5f11 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -146,7 +146,7 @@ public: NetworkTexturePointer TextureCache::getTexture(const QUrl& url, TextureType type, const QByteArray& content) { TextureExtra extra = { type, content }; - return ResourceCache::getResource(url, QUrl(), false, &extra).staticCast(); + return ResourceCache::getResource(url, QUrl(), content.isEmpty(), &extra).staticCast(); } /// Returns a texture version of an image file From 5ba96cb07c5390173345c0533e0a00ee1fe71dad Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 10 Mar 2016 12:47:31 -0800 Subject: [PATCH 27/55] removed print statements --- .../tests/rapidProceduralChange/rapidProceduralChangeTest.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/tests/rapidProceduralChange/rapidProceduralChangeTest.js b/examples/tests/rapidProceduralChange/rapidProceduralChangeTest.js index 46c510951d..6897a1b70f 100644 --- a/examples/tests/rapidProceduralChange/rapidProceduralChangeTest.js +++ b/examples/tests/rapidProceduralChange/rapidProceduralChangeTest.js @@ -41,7 +41,6 @@ var skyboxData = { } }; -print("ABOUT TO ADD ENTITY"); var testBox = Entities.addEntity({ type: "Box", dimensions: { x: 0.5, y: 0.5, z: 0.5 }, @@ -73,7 +72,6 @@ function update(deltaTime) { entityEdit = { userData: JSON.stringify(entityData) }; skyboxEdit = { userData: JSON.stringify(skyboxData) }; - print("ABOUT TO EDIT ENTITIES"); Entities.editEntity(testBox, entityEdit); Entities.editEntity(testSphere, entityEdit); Entities.editEntity(testZone, skyboxEdit); From d7d351fc636830135d92d17d80c550b7798c2a8d Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 12:50:52 -0800 Subject: [PATCH 28/55] Guard against unloaded env cubemaps --- .../src/EntityTreeRenderer.cpp | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index dc59d40e82..28a89162ba 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -140,8 +140,8 @@ void EntityTreeRenderer::update() { // If we haven't already updated and previously attempted to load a texture, // check if the texture loaded and apply it if (!updated && ( - (_pendingSkyboxTexture && _skyboxTexture && _skyboxTexture->isLoaded()) || - (_pendingAmbientTexture && _ambientTexture && _ambientTexture->isLoaded()))) { + (_pendingSkyboxTexture && (!_skyboxTexture || _skyboxTexture->isLoaded())) || + (_pendingAmbientTexture && (!_ambientTexture && _ambientTexture->isLoaded())))) { applyZonePropertiesToScene(_bestZone); } @@ -326,15 +326,19 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptrgetTexture(zone->getKeyLightProperties().getAmbientURL(), CUBE_TEXTURE); - if (_ambientTexture && _ambientTexture->isLoaded() && _ambientTexture->getGPUTexture()) { + _pendingAmbientTexture = true; + + if (_ambientTexture && _ambientTexture->isLoaded()) { _pendingAmbientTexture = false; - if (_ambientTexture->getGPUTexture()->getIrradiance()) { - sceneKeyLight->setAmbientSphere(_ambientTexture->getGPUTexture()->getIrradiance()); - sceneKeyLight->setAmbientMap(_ambientTexture->getGPUTexture()); + + auto texture = _ambientTexture->getGPUTexture(); + if (texture) { + sceneKeyLight->setAmbientSphere(texture->getIrradiance()); + sceneKeyLight->setAmbientMap(texture); isAmbientTextureSet = true; + } else { + qCDebug(entitiesrenderer) << "Failed to load ambient texture:" << zone->getKeyLightProperties().getAmbientURL(); } - } else { - _pendingAmbientTexture = true; } } @@ -353,24 +357,27 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptrgetSkyboxProperties().getURL().isEmpty()) { - skybox->setCubemap(gpu::TexturePointer()); + skybox->setCubemap(nullptr); _pendingSkyboxTexture = false; _skyboxTexture.clear(); } else { // Update the Texture of the Skybox with the one pointed by this zone _skyboxTexture = textureCache->getTexture(zone->getSkyboxProperties().getURL(), CUBE_TEXTURE); + _pendingSkyboxTexture = true; + + if (_skyboxTexture && _skyboxTexture->isLoaded()) { + _pendingSkyboxTexture = false; - if (_skyboxTexture && _skyboxTexture->isLoaded() && _skyboxTexture->getGPUTexture()) { auto texture = _skyboxTexture->getGPUTexture(); skybox->setCubemap(texture); - _pendingSkyboxTexture = false; - if (!isAmbientTextureSet && texture->getIrradiance()) { + if (!isAmbientTextureSet) { sceneKeyLight->setAmbientSphere(texture->getIrradiance()); sceneKeyLight->setAmbientMap(texture); isAmbientTextureSet = true; } } else { - _pendingSkyboxTexture = true; + skybox->setCubemap(nullptr); + qCDebug(entitiesrenderer) << "Failed to load skybox:" << zone->getSkyboxProperties().getURL(); } } From b627a17ce911974bcb72ebeb7c24fc5c10abbf5a Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 12:58:49 -0800 Subject: [PATCH 29/55] Allow px/color skybox without tex --- interface/src/Application.cpp | 9 ++-- .../src/model-networking/TextureCache.h | 2 - libraries/model/src/model/Skybox.cpp | 49 +++++++------------ libraries/model/src/model/Skybox.h | 13 +++-- libraries/model/src/model/Skybox.slf | 36 ++++---------- .../src/procedural/ProceduralSkybox.cpp | 17 ++----- 6 files changed, 42 insertions(+), 84 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4ae63f817a..5dae5fc4c6 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3757,19 +3757,19 @@ namespace render { switch (backgroundMode) { case model::SunSkyStage::SKY_BOX: { auto skybox = skyStage->getSkybox(); - if (skybox && skybox->getCubemap() && skybox->getCubemap()->isDefined()) { + if (skybox) { PerformanceTimer perfTimer("skybox"); skybox->render(batch, *(args->_viewFrustum)); break; } - // If no skybox texture is available, render the SKY_DOME while it loads } - // fall through to next case + + // Fall through: if no skybox is available, render the SKY_DOME case model::SunSkyStage::SKY_DOME: { if (Menu::getInstance()->isOptionChecked(MenuOption::Stars)) { PerformanceTimer perfTimer("stars"); PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), - "Application::payloadRender() ... stars..."); + "Application::payloadRender() ... My god, it's full of stars..."); // should be the first rendering pass - w/o depth buffer / lighting static const float alpha = 1.0f; @@ -3777,6 +3777,7 @@ namespace render { } } break; + case model::SunSkyStage::NO_BACKGROUND: default: // this line intentionally left blank diff --git a/libraries/model-networking/src/model-networking/TextureCache.h b/libraries/model-networking/src/model-networking/TextureCache.h index 72a09a8b3f..6fb0cc3177 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.h +++ b/libraries/model-networking/src/model-networking/TextureCache.h @@ -101,8 +101,6 @@ private: /// A simple object wrapper for an OpenGL texture. class Texture { public: - friend class TextureCache; - gpu::TexturePointer getGPUTexture() const { return _textureSource->getGPUTexture(); } gpu::TextureSourcePointer _textureSource; }; diff --git a/libraries/model/src/model/Skybox.cpp b/libraries/model/src/model/Skybox.cpp index 476ac2fa08..0f9d3ca4de 100755 --- a/libraries/model/src/model/Skybox.cpp +++ b/libraries/model/src/model/Skybox.cpp @@ -21,54 +21,39 @@ using namespace model; Skybox::Skybox() { - Data data; - _dataBuffer = gpu::BufferView(std::make_shared(sizeof(Data), (const gpu::Byte*) &data)); - -/* // PLease create a default engineer skybox - _cubemap.reset( gpu::Texture::createCube(gpu::Element::COLOR_RGBA_32, 1)); - unsigned char texels[] = { - 255, 0, 0, 255, - 0, 255, 255, 255, - 0, 0, 255, 255, - 255, 255, 0, 255, - 0, 255, 0, 255, - 255, 0, 255, 255, - }; - _cubemap->assignStoredMip(0, gpu::Element::COLOR_RGBA_32, sizeof(texels), texels);*/ + Schema schema; + _schemaBuffer = gpu::BufferView(std::make_shared(sizeof(Schema), (const gpu::Byte*) &schema)); } void Skybox::setColor(const Color& color) { - _dataBuffer.edit()._color = color; + _schemaBuffer.edit()._color = color; } void Skybox::setCubemap(const gpu::TexturePointer& cubemap) { _cubemap = cubemap; } - -void Skybox::updateDataBuffer() const { +void Skybox::updateSchemaBuffer() const { auto blend = 0.0f; if (getCubemap() && getCubemap()->isDefined()) { - blend = 1.0f; + blend = 0.5f; + // If pitch black neutralize the color if (glm::all(glm::equal(getColor(), glm::vec3(0.0f)))) { - blend = 2.0f; + blend = 1.0f; } } - if (blend != _dataBuffer.get()._blend) { - _dataBuffer.edit()._blend = blend; + if (blend != _schemaBuffer.get()._blend) { + _schemaBuffer.edit()._blend = blend; } } - - void Skybox::render(gpu::Batch& batch, const ViewFrustum& frustum) const { - updateDataBuffer(); + updateSchemaBuffer(); Skybox::render(batch, frustum, (*this)); } - void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Skybox& skybox) { // Create the static shared elements used to render the skybox static gpu::BufferPointer theConstants; @@ -98,10 +83,6 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky // Render - gpu::TexturePointer skymap = skybox.getCubemap(); - // FIXME: skymap->isDefined may not be threadsafe - assert(skymap && skymap->isDefined()); - glm::mat4 projMat; viewFrustum.evalProjectionMatrix(projMat); @@ -112,11 +93,15 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky batch.setModelTransform(Transform()); // only for Mac batch.setPipeline(thePipeline); - batch.setUniformBuffer(SKYBOX_CONSTANTS_SLOT, skybox._dataBuffer); - batch.setResourceTexture(SKYBOX_SKYMAP_SLOT, skymap); + batch.setUniformBuffer(SKYBOX_CONSTANTS_SLOT, skybox._schemaBuffer); + + gpu::TexturePointer skymap = skybox.getCubemap(); + // FIXME: skymap->isDefined may not be threadsafe + if (skymap && skymap->isDefined()) { + batch.setResourceTexture(SKYBOX_SKYMAP_SLOT, skymap); + } batch.draw(gpu::TRIANGLE_STRIP, 4); batch.setResourceTexture(SKYBOX_SKYMAP_SLOT, nullptr); } - diff --git a/libraries/model/src/model/Skybox.h b/libraries/model/src/model/Skybox.h index 14ba9fa005..7382ffabdd 100755 --- a/libraries/model/src/model/Skybox.h +++ b/libraries/model/src/model/Skybox.h @@ -30,28 +30,27 @@ public: virtual ~Skybox() {}; void setColor(const Color& color); - const Color getColor() const { return _dataBuffer.get()._color; } + const Color getColor() const { return _schemaBuffer.get()._color; } void setCubemap(const gpu::TexturePointer& cubemap); const gpu::TexturePointer& getCubemap() const { return _cubemap; } virtual void render(gpu::Batch& batch, const ViewFrustum& frustum) const; - static void render(gpu::Batch& batch, const ViewFrustum& frustum, const Skybox& skybox); protected: gpu::TexturePointer _cubemap; - class Data { + class Schema { public: - glm::vec3 _color{ 1.0f, 1.0f, 1.0f }; - float _blend = 1.0f; + glm::vec3 _color { 1.0f, 1.0f, 1.0f }; + float _blend { 0.0f }; }; - mutable gpu::BufferView _dataBuffer; + mutable gpu::BufferView _schemaBuffer; - void updateDataBuffer() const; + void updateSchemaBuffer() const; }; typedef std::shared_ptr< Skybox > SkyboxPointer; diff --git a/libraries/model/src/model/Skybox.slf b/libraries/model/src/model/Skybox.slf index f8a568bcf9..93f68e3406 100755 --- a/libraries/model/src/model/Skybox.slf +++ b/libraries/model/src/model/Skybox.slf @@ -14,7 +14,8 @@ uniform samplerCube cubeMap; struct Skybox { - vec4 _color; + vec3 _color; + float _blend; }; uniform skyboxBuffer { @@ -24,36 +25,17 @@ uniform skyboxBuffer { in vec3 _normal; out vec4 _fragColor; -//PROCEDURAL_COMMON_BLOCK - -#line 1001 -//PROCEDURAL_BLOCK - -#line 2033 void main(void) { - -#ifdef PROCEDURAL - - vec3 color = getSkyboxColor(); - _fragColor = vec4(color, 0.0); - -#else - vec3 coord = normalize(_normal); + vec3 color = _skybox._color; - // Skybox color or blend with skymap - vec3 color = _skybox._color.rgb; - if (_skybox._color.a > 0.0) { - vec3 texel = texture(cubeMap, coord).rgb; - if (_skybox._color.a < 2.0) { - color *= texel; - } else { - color = texel; + // blend is only set if there is a cubemap + if (_skybox._blend > 0.0) { + color = texture(cubeMap, coord).rgb; + if (_skybox._blend < 1.0) { + color *= _skybox._color; } - } + } _fragColor = vec4(color, 0.0); - -#endif - } diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.cpp b/libraries/procedural/src/procedural/ProceduralSkybox.cpp index 167d49cbaf..95deaa4dc5 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.cpp +++ b/libraries/procedural/src/procedural/ProceduralSkybox.cpp @@ -38,20 +38,15 @@ void ProceduralSkybox::setProcedural(const ProceduralPointer& procedural) { } void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& frustum) const { - ProceduralSkybox::render(batch, frustum, (*this)); + if (_procedural) { + ProceduralSkybox::render(batch, frustum, (*this)); + } else { + Skybox::render(batch, frustum); + } } void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const ProceduralSkybox& skybox) { - if (!(skybox._procedural)) { - skybox.updateDataBuffer(); - Skybox::render(batch, viewFrustum, skybox); - } - if (skybox._procedural && skybox._procedural->_enabled && skybox._procedural->ready()) { - gpu::TexturePointer skymap = skybox.getCubemap(); - // FIXME: skymap->isDefined may not be threadsafe - assert(skymap && skymap->isDefined()); - glm::mat4 projMat; viewFrustum.evalProjectionMatrix(projMat); @@ -60,10 +55,8 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, batch.setProjectionTransform(projMat); batch.setViewTransform(viewTransform); batch.setModelTransform(Transform()); // only for Mac - batch.setResourceTexture(0, skybox.getCubemap()); skybox._procedural->prepare(batch, glm::vec3(0), glm::vec3(1)); batch.draw(gpu::TRIANGLE_STRIP, 4); } } - From 6d11dd465ca50b2a7fffaf00b3da4dee5c0753a2 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Thu, 10 Mar 2016 13:12:09 -0800 Subject: [PATCH 30/55] Application: reset avatar on displayMode change but not HMD sensor. --- interface/src/Application.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 66662a7500..795145ca5c 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4857,6 +4857,9 @@ void Application::updateDisplayMode() { } emit activeDisplayPluginChanged(); + // reset the avatar, to set head and hand palms back to a resonable default pose. + getMyAvatar()->reset(false); + Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin"); } From 1e96c9e2cac06a6cc0809a5ccef248003a302809 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 10 Mar 2016 14:03:37 -0800 Subject: [PATCH 31/55] Merging back with master --- libraries/render-utils/src/directional_ambient_light.slf | 4 ---- libraries/render-utils/src/directional_skybox_light.slf | 3 --- 2 files changed, 7 deletions(-) diff --git a/libraries/render-utils/src/directional_ambient_light.slf b/libraries/render-utils/src/directional_ambient_light.slf index 34040025a4..e1ec0d3ef0 100755 --- a/libraries/render-utils/src/directional_ambient_light.slf +++ b/libraries/render-utils/src/directional_ambient_light.slf @@ -49,8 +49,4 @@ void main(void) { frag.roughness); _fragColor = vec4(color, frag.normalVal.a); } - - if (gl_FragCoord.y > 500) { - _fragColor.xyz = pow(_fragColor.xyz, vec3(2.2)); - } } diff --git a/libraries/render-utils/src/directional_skybox_light.slf b/libraries/render-utils/src/directional_skybox_light.slf index 373cbd2442..9e24a5f585 100755 --- a/libraries/render-utils/src/directional_skybox_light.slf +++ b/libraries/render-utils/src/directional_skybox_light.slf @@ -51,7 +51,4 @@ void main(void) { _fragColor = vec4(color, frag.normalVal.a); } - if (gl_FragCoord.y > 500) { - _fragColor.xyz = pow(_fragColor.xyz, vec3(2.2)); - } } From f97c7b00defbe9c8333e82e53d8ad5fce61ca4d6 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 10 Mar 2016 14:06:07 -0800 Subject: [PATCH 32/55] Removing old modifications --- libraries/gpu/src/gpu/GLBackendOutput.cpp | 1 - libraries/gpu/src/gpu/GLBackendTexture.cpp | 39 ---------------------- 2 files changed, 40 deletions(-) diff --git a/libraries/gpu/src/gpu/GLBackendOutput.cpp b/libraries/gpu/src/gpu/GLBackendOutput.cpp index 26754ba652..37a10e670b 100755 --- a/libraries/gpu/src/gpu/GLBackendOutput.cpp +++ b/libraries/gpu/src/gpu/GLBackendOutput.cpp @@ -209,7 +209,6 @@ void GLBackend::resetOutputStage() { _output._drawFBO = 0; glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); } - glEnable(GL_FRAMEBUFFER_SRGB); } void GLBackend::do_setFramebuffer(Batch& batch, size_t paramOffset) { diff --git a/libraries/gpu/src/gpu/GLBackendTexture.cpp b/libraries/gpu/src/gpu/GLBackendTexture.cpp index 5cf3b50f64..a70904a4bf 100755 --- a/libraries/gpu/src/gpu/GLBackendTexture.cpp +++ b/libraries/gpu/src/gpu/GLBackendTexture.cpp @@ -117,45 +117,6 @@ public: break; case gpu::RGBA: texel.internalFormat = GL_RGBA; - switch (dstFormat.getType()) { - case gpu::UINT32: - case gpu::NUINT32: { - texel.internalFormat = GL_RGBA32UI; - break; - } - case gpu::INT32: - case gpu::NINT32: { - texel.internalFormat = GL_RGBA32I; - break; - } - case gpu::FLOAT: { - texel.internalFormat = GL_RGBA32F; - break; - } - case gpu::UINT16: - case gpu::NUINT16: { - texel.internalFormat = GL_RGBA16UI; - break; - } - case gpu::INT16: - case gpu::NINT16: { - texel.internalFormat = GL_RGBA16I; - break; - } - case gpu::HALF: { - texel.internalFormat = GL_RGBA16F; - break; - } - case gpu::UINT8: - case gpu::INT8: - case gpu::NUINT8: - case gpu::NINT8: { - break; - } - case gpu::NUM_TYPES: { // quiet compiler - Q_UNREACHABLE(); - } - } break; case gpu::SRGB: texel.internalFormat = GL_SRGB; From ad7d5679323ddc93e2e2c9486de894d012491336 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 10 Mar 2016 14:09:34 -0800 Subject: [PATCH 33/55] Fixing the overlay renderItem access issue --- interface/src/ui/overlays/Base3DOverlay.cpp | 19 ++++++++++++++++++- interface/src/ui/overlays/Overlays.cpp | 13 ------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/interface/src/ui/overlays/Base3DOverlay.cpp b/interface/src/ui/overlays/Base3DOverlay.cpp index 0cba089256..94533137ad 100644 --- a/interface/src/ui/overlays/Base3DOverlay.cpp +++ b/interface/src/ui/overlays/Base3DOverlay.cpp @@ -13,6 +13,7 @@ #include #include +#include "Application.h" const float DEFAULT_LINE_WIDTH = 1.0f; @@ -38,15 +39,17 @@ Base3DOverlay::Base3DOverlay(const Base3DOverlay* base3DOverlay) : _drawInFront(base3DOverlay->_drawInFront) { } - void Base3DOverlay::setProperties(const QVariantMap& properties) { Overlay::setProperties(properties); + bool needRenderItemUpdate = false; + auto drawInFront = properties["drawInFront"]; if (drawInFront.isValid()) { bool value = drawInFront.toBool(); setDrawInFront(value); + needRenderItemUpdate = true; } auto position = properties["position"]; @@ -60,16 +63,19 @@ void Base3DOverlay::setProperties(const QVariantMap& properties) { } if (position.isValid()) { setPosition(vec3FromVariant(position)); + needRenderItemUpdate = true; } if (properties["lineWidth"].isValid()) { setLineWidth(properties["lineWidth"].toFloat()); + needRenderItemUpdate = true; } auto rotation = properties["rotation"]; if (rotation.isValid()) { setRotation(quatFromVariant(rotation)); + needRenderItemUpdate = true; } if (properties["isSolid"].isValid()) { @@ -100,6 +106,17 @@ void Base3DOverlay::setProperties(const QVariantMap& properties) { if (properties["ignoreRayIntersection"].isValid()) { setIgnoreRayIntersection(properties["ignoreRayIntersection"].toBool()); } + + // Communicate changes to the renderItem if needed + if (needRenderItemUpdate) { + auto itemID = getRenderItemID(); + if (render::Item::isValidID(itemID)) { + render::ScenePointer scene = qApp->getMain3DScene(); + render::PendingChanges pendingChanges; + pendingChanges.updateItem(itemID); + scene->enqueuePendingChanges(pendingChanges); + } + } } QVariant Base3DOverlay::getProperty(const QString& property) { diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index f003b0316e..1179fbaa50 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -233,19 +233,6 @@ bool Overlays::editOverlay(unsigned int id, const QVariant& properties) { if (thisOverlay) { thisOverlay->setProperties(properties.toMap()); - if (thisOverlay->is3D()) { - auto itemID = thisOverlay->getRenderItemID(); - if (render::Item::isValidID(itemID)) { - render::ScenePointer scene = qApp->getMain3DScene(); - const render::Item& item = scene->getItem(itemID); - if (item.getKey() != render::payloadGetKey(thisOverlay)) { - render::PendingChanges pendingChanges; - pendingChanges.updateItem(itemID); - scene->enqueuePendingChanges(pendingChanges); - } - } - } - return true; } return false; From 3944a7f297a822537fa26277bd808a38ac103a06 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 10 Mar 2016 15:03:20 -0800 Subject: [PATCH 34/55] Exposing thread safe number of allocated items for a ascene --- libraries/render/src/render/Scene.cpp | 13 +++++++++++++ libraries/render/src/render/Scene.h | 13 ++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/libraries/render/src/render/Scene.cpp b/libraries/render/src/render/Scene.cpp index 0cdd736fee..feaf8562d7 100644 --- a/libraries/render/src/render/Scene.cpp +++ b/libraries/render/src/render/Scene.cpp @@ -48,6 +48,10 @@ ItemID Scene::allocateID() { return _IDAllocator.fetch_add(1); } +bool Scene::isAllocatedID(const ItemID& id) { + return Item::isValidID(id) && (id < _numAllocatedItems.load()); +} + /// Enqueue change batch to the scene void Scene::enqueuePendingChanges(const PendingChanges& pendingChanges) { _changeQueueMutex.lock(); @@ -79,8 +83,17 @@ void Scene::processPendingChangesQueue() { } // Now we know for sure that we have enough items in the array to // capture anything coming from the pendingChanges + + // resets and potential NEW items resetItems(consolidatedPendingChanges._resetItems, consolidatedPendingChanges._resetPayloads); + + // Update the numItemsAtomic counter AFTER the reset changes went through + _numAllocatedItems.exchange(maxID); + + // updates updateItems(consolidatedPendingChanges._updatedItems, consolidatedPendingChanges._updateFunctors); + + // removes removeItems(consolidatedPendingChanges._removedItems); // ready to go back to rendering activities diff --git a/libraries/render/src/render/Scene.h b/libraries/render/src/render/Scene.h index 40c0baca60..b2eac380ad 100644 --- a/libraries/render/src/render/Scene.h +++ b/libraries/render/src/render/Scene.h @@ -60,19 +60,25 @@ public: // This call is thread safe, can be called from anywhere to allocate a new ID ItemID allocateID(); + // Check that the ID is valid and allocated for this scene, this a threadsafe call + bool isAllocatedID(const ItemID& id); + + // THis is the total number of allocated items, this a threadsafe call + size_t getNumItems() const { return _numAllocatedItems.load(); } + // Enqueue change batch to the scene void enqueuePendingChanges(const PendingChanges& pendingChanges); // Process the penging changes equeued void processPendingChangesQueue(); + // This next call are NOT threadsafe, you have to call them from the correct thread to avoid any potential issues + // Access a particular item form its ID // WARNING, There is No check on the validity of the ID, so this could return a bad Item const Item& getItem(const ItemID& id) const { return _items[id]; } - size_t getNumItems() const { return _items.size(); } - - // Access the spatialized items + // Access the spatialized items const ItemSpatialTree& getSpatialTree() const { return _masterSpatialTree; } // Access non-spatialized items (overlays, backgrounds) @@ -81,6 +87,7 @@ public: protected: // Thread safe elements that can be accessed from anywhere std::atomic _IDAllocator{ 1 }; // first valid itemID will be One + std::atomic _numAllocatedItems{ 1 }; // num of allocated items, matching the _items.size() std::mutex _changeQueueMutex; PendingChangesQueue _changeQueue; From fb68c09941d551999432cdb9d591693fefdff7f8 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 10 Mar 2016 15:10:34 -0800 Subject: [PATCH 35/55] Before merging upstream --- interface/src/ui/overlays/Base3DOverlay.cpp | 19 +++++++++++++++++++ interface/src/ui/overlays/Overlays.cpp | 13 ------------- libraries/render/src/render/Scene.cpp | 7 +++++++ libraries/render/src/render/Scene.h | 5 +++++ libraries/render/src/render/SpatialTree.h | 6 +++--- 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/interface/src/ui/overlays/Base3DOverlay.cpp b/interface/src/ui/overlays/Base3DOverlay.cpp index 0cba089256..1f5e257444 100644 --- a/interface/src/ui/overlays/Base3DOverlay.cpp +++ b/interface/src/ui/overlays/Base3DOverlay.cpp @@ -11,6 +11,7 @@ #include "Base3DOverlay.h" +#include "Application.h" #include #include @@ -42,11 +43,14 @@ Base3DOverlay::Base3DOverlay(const Base3DOverlay* base3DOverlay) : void Base3DOverlay::setProperties(const QVariantMap& properties) { Overlay::setProperties(properties); + bool needRenderItemUpdate = false; + auto drawInFront = properties["drawInFront"]; if (drawInFront.isValid()) { bool value = drawInFront.toBool(); setDrawInFront(value); + needRenderItemUpdate = true; } auto position = properties["position"]; @@ -60,16 +64,19 @@ void Base3DOverlay::setProperties(const QVariantMap& properties) { } if (position.isValid()) { setPosition(vec3FromVariant(position)); + needRenderItemUpdate = true; } if (properties["lineWidth"].isValid()) { setLineWidth(properties["lineWidth"].toFloat()); + needRenderItemUpdate = true; } auto rotation = properties["rotation"]; if (rotation.isValid()) { setRotation(quatFromVariant(rotation)); + needRenderItemUpdate = true; } if (properties["isSolid"].isValid()) { @@ -100,6 +107,18 @@ void Base3DOverlay::setProperties(const QVariantMap& properties) { if (properties["ignoreRayIntersection"].isValid()) { setIgnoreRayIntersection(properties["ignoreRayIntersection"].toBool()); } + + + + if (needRenderItemUpdate) { + auto itemID = getRenderItemID(); + if (render::Item::isValidID(itemID)) { + render::ScenePointer scene = qApp->getMain3DScene(); + render::PendingChanges pendingChanges; + pendingChanges.updateItem(itemID); + scene->enqueuePendingChanges(pendingChanges); + } + } } QVariant Base3DOverlay::getProperty(const QString& property) { diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index f003b0316e..1179fbaa50 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -233,19 +233,6 @@ bool Overlays::editOverlay(unsigned int id, const QVariant& properties) { if (thisOverlay) { thisOverlay->setProperties(properties.toMap()); - if (thisOverlay->is3D()) { - auto itemID = thisOverlay->getRenderItemID(); - if (render::Item::isValidID(itemID)) { - render::ScenePointer scene = qApp->getMain3DScene(); - const render::Item& item = scene->getItem(itemID); - if (item.getKey() != render::payloadGetKey(thisOverlay)) { - render::PendingChanges pendingChanges; - pendingChanges.updateItem(itemID); - scene->enqueuePendingChanges(pendingChanges); - } - } - } - return true; } return false; diff --git a/libraries/render/src/render/Scene.cpp b/libraries/render/src/render/Scene.cpp index 0cdd736fee..19fc58211b 100644 --- a/libraries/render/src/render/Scene.cpp +++ b/libraries/render/src/render/Scene.cpp @@ -48,6 +48,10 @@ ItemID Scene::allocateID() { return _IDAllocator.fetch_add(1); } +bool Scene::isAllocatedID(const ItemID& id) { + return Item::isValidID(id) && (id < _numAllocatedItems.load()); +} + /// Enqueue change batch to the scene void Scene::enqueuePendingChanges(const PendingChanges& pendingChanges) { _changeQueueMutex.lock(); @@ -83,6 +87,9 @@ void Scene::processPendingChangesQueue() { updateItems(consolidatedPendingChanges._updatedItems, consolidatedPendingChanges._updateFunctors); removeItems(consolidatedPendingChanges._removedItems); + // Update the numItemsAtomic counter AFTER the pending changes went through + _numAllocatedItems.exchange(maxID); + // ready to go back to rendering activities _itemsMutex.unlock(); } diff --git a/libraries/render/src/render/Scene.h b/libraries/render/src/render/Scene.h index 40c0baca60..3e4372b1a7 100644 --- a/libraries/render/src/render/Scene.h +++ b/libraries/render/src/render/Scene.h @@ -60,6 +60,9 @@ public: // This call is thread safe, can be called from anywhere to allocate a new ID ItemID allocateID(); + // Check that the ID is valid and allocated for this scene, this a threadsafe call + bool isAllocatedID(const ItemID& id); + // Enqueue change batch to the scene void enqueuePendingChanges(const PendingChanges& pendingChanges); @@ -81,6 +84,8 @@ public: protected: // Thread safe elements that can be accessed from anywhere std::atomic _IDAllocator{ 1 }; // first valid itemID will be One + std::atomic _numAllocatedItems{ 1 }; // num of allocated items, matching the _items.size() + std::mutex _changeQueueMutex; PendingChangesQueue _changeQueue; diff --git a/libraries/render/src/render/SpatialTree.h b/libraries/render/src/render/SpatialTree.h index 36ded44cfb..a941fc6f38 100644 --- a/libraries/render/src/render/SpatialTree.h +++ b/libraries/render/src/render/SpatialTree.h @@ -402,9 +402,9 @@ namespace render { // Clamp a position expressed in a depth space to make sure it is in the valid space for that Depth glm::vec3 clampRelPosToTreeRange(const glm::vec3& pos) const { return glm::vec3( - std::min(std::max(pos.x, 0.0f), _size), - std::min(std::max(pos.y, 0.0f), _size), - std::min(std::max(pos.z, 0.0f), _size)); + std::min(std::max(pos.x, 1.0f), _size - 1.0f), + std::min(std::max(pos.y, 1.0f), _size - 1.0f), + std::min(std::max(pos.z, 1.0f), _size - 1.0f)); } Coord3 evalCoord(const glm::vec3& pos, Depth depth = Octree::METRIC_COORD_DEPTH) const { auto npos = clampRelPosToTreeRange((pos - getOrigin())); From c0880a570ec64d579ed4617f5fefb0c79cc88d36 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Thu, 10 Mar 2016 15:15:46 -0800 Subject: [PATCH 36/55] Stats: fix for avatar velocity stat being stuck at 0.1 --- interface/src/ui/Stats.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index c711560b53..ac47c55eca 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -164,7 +164,7 @@ void Stats::updateStats(bool force) { MyAvatar* myAvatar = avatarManager->getMyAvatar(); glm::vec3 avatarPos = myAvatar->getPosition(); STAT_UPDATE(position, QVector3D(avatarPos.x, avatarPos.y, avatarPos.z)); - STAT_UPDATE_FLOAT(speed, glm::length(myAvatar->getVelocity()), 0.1f); + STAT_UPDATE_FLOAT(speed, glm::length(myAvatar->getVelocity()), 0.01f); STAT_UPDATE_FLOAT(yaw, myAvatar->getBodyYaw(), 0.1f); if (_expanded || force) { SharedNodePointer avatarMixer = nodeList->soloNodeOfType(NodeType::AvatarMixer); From 505ae71e30fa4c571f690b6af1fb8f7819e93e4d Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 15:22:19 -0800 Subject: [PATCH 37/55] Pass px userData by const ref --- libraries/procedural/src/procedural/Procedural.cpp | 2 +- libraries/procedural/src/procedural/Procedural.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index 9670b66676..11df332c5c 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -142,7 +142,7 @@ bool Procedural::parseTextures(const QJsonArray& channels) { return true; } -void Procedural::parse(QJsonObject proceduralData) { +void Procedural::parse(const QJsonObject& proceduralData) { _enabled = false; if (proceduralData.isEmpty()) { diff --git a/libraries/procedural/src/procedural/Procedural.h b/libraries/procedural/src/procedural/Procedural.h index 75872ca2bc..cac3f782e4 100644 --- a/libraries/procedural/src/procedural/Procedural.h +++ b/libraries/procedural/src/procedural/Procedural.h @@ -93,7 +93,7 @@ protected: private: // This should only be called from the render thread, as it shares data with Procedural::prepare - void parse(QJsonObject); + void parse(const QJsonObject&); bool parseVersion(const QJsonValue& version); bool parseUrl(const QUrl& url); bool parseUniforms(const QJsonObject& uniforms); From e452020126b9759cda97f001fd51f94467799146 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 10 Mar 2016 11:41:25 -0800 Subject: [PATCH 38/55] Better threaded handling of QML overlays --- interface/src/ui/overlays/QmlOverlay.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/interface/src/ui/overlays/QmlOverlay.cpp b/interface/src/ui/overlays/QmlOverlay.cpp index 27d03b5e09..eb909de993 100644 --- a/interface/src/ui/overlays/QmlOverlay.cpp +++ b/interface/src/ui/overlays/QmlOverlay.cpp @@ -51,27 +51,24 @@ void QmlOverlay::buildQmlElement(const QUrl& url) { } QmlOverlay::~QmlOverlay() { - if (_qmlElement) { - _qmlElement->deleteLater(); - _qmlElement = nullptr; - } + _qmlElement.reset(); } void QmlOverlay::setProperties(const QVariantMap& properties) { Overlay2D::setProperties(properties); auto bounds = _bounds; - std::weak_ptr weakQmlElement; - DependencyManager::get()->executeOnUiThread([=] { + std::weak_ptr weakQmlElement = _qmlElement; + DependencyManager::get()->executeOnUiThread([weakQmlElement, bounds, properties] { // check to see if qmlElement still exists auto qmlElement = weakQmlElement.lock(); if (qmlElement) { - _qmlElement->setX(bounds.left()); - _qmlElement->setY(bounds.top()); - _qmlElement->setWidth(bounds.width()); - _qmlElement->setHeight(bounds.height()); + qmlElement->setX(bounds.left()); + qmlElement->setY(bounds.top()); + qmlElement->setWidth(bounds.width()); + qmlElement->setHeight(bounds.height()); + QMetaObject::invokeMethod(qmlElement.get(), "updatePropertiesFromScript", Qt::DirectConnection, Q_ARG(QVariant, properties)); } }); - QMetaObject::invokeMethod(_qmlElement.get(), "updatePropertiesFromScript", Q_ARG(QVariant, properties)); } void QmlOverlay::render(RenderArgs* args) { From a88f22fa3c33795a3e193fb4294c9ef932f67f41 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 10 Mar 2016 15:58:04 -0800 Subject: [PATCH 39/55] Removing white spaces --- libraries/render/src/render/Scene.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render/src/render/Scene.h b/libraries/render/src/render/Scene.h index b2eac380ad..b7cfc367b8 100644 --- a/libraries/render/src/render/Scene.h +++ b/libraries/render/src/render/Scene.h @@ -78,7 +78,7 @@ public: // WARNING, There is No check on the validity of the ID, so this could return a bad Item const Item& getItem(const ItemID& id) const { return _items[id]; } - // Access the spatialized items + // Access the spatialized items const ItemSpatialTree& getSpatialTree() const { return _masterSpatialTree; } // Access non-spatialized items (overlays, backgrounds) From ff3061123479dc91ca0ac9ed09259cfba500f3af Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Thu, 10 Mar 2016 16:07:49 -0800 Subject: [PATCH 40/55] first cut at getting overlays to toggle again --- .../src/display-plugins/CompositorHelper.cpp | 38 ++++++++++++++++++- .../src/display-plugins/CompositorHelper.h | 5 +++ .../display-plugins/OpenGLDisplayPlugin.cpp | 28 ++++++++++++++ .../src/display-plugins/OpenGLDisplayPlugin.h | 1 + .../display-plugins/hmd/HmdDisplayPlugin.cpp | 31 ++++++++++++++- libraries/gl/src/gl/OglplusHelpers.cpp | 3 +- 6 files changed, 102 insertions(+), 4 deletions(-) diff --git a/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp b/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp index f6e9d8dbbc..c013cf07af 100644 --- a/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp +++ b/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -414,13 +415,45 @@ void CompositorHelper::updateTooltips() { } static const float FADE_DURATION = 500.0f; +static const float FADE_IN_ALPHA = 1.0f; +static const float FADE_OUT_ALPHA = 0.0f; + +void CompositorHelper::startFadeFailsafe(float endValue) { + return; + + qDebug() << __FUNCTION__; + _fadeStarted = usecTimestampNow(); + _fadeFailsafeEndValue = endValue; + + const int SLIGHT_DELAY = 10; + QTimer::singleShot(FADE_DURATION + SLIGHT_DELAY, [this]{ + checkFadeFailsafe(); + }); +} + +void CompositorHelper::checkFadeFailsafe() { + return; + + qDebug() << __FUNCTION__; + auto elapsedInFade = usecTimestampNow() - _fadeStarted; + if (elapsedInFade > FADE_DURATION) { + setAlpha(_fadeFailsafeEndValue); + } +} + void CompositorHelper::fadeIn() { _fadeInAlpha = true; _alphaPropertyAnimation->setDuration(FADE_DURATION); _alphaPropertyAnimation->setStartValue(_alpha); - _alphaPropertyAnimation->setEndValue(1.0f); + _alphaPropertyAnimation->setEndValue(FADE_IN_ALPHA); _alphaPropertyAnimation->start(); + + // Sometimes, this "QPropertyAnimation" fails to complete the animation, and we end up with a partially faded + // state. So we will also have this fail-safe, where we record the timestamp of the fadeRequest, and the target + // value of the fade, and if after that time we still haven't faded all the way, we will kick it to the final + // fade value + startFadeFailsafe(FADE_IN_ALPHA); } void CompositorHelper::fadeOut() { @@ -428,8 +461,9 @@ void CompositorHelper::fadeOut() { _alphaPropertyAnimation->setDuration(FADE_DURATION); _alphaPropertyAnimation->setStartValue(_alpha); - _alphaPropertyAnimation->setEndValue(0.0f); + _alphaPropertyAnimation->setEndValue(FADE_OUT_ALPHA); _alphaPropertyAnimation->start(); + startFadeFailsafe(FADE_OUT_ALPHA); } void CompositorHelper::toggle() { diff --git a/libraries/display-plugins/src/display-plugins/CompositorHelper.h b/libraries/display-plugins/src/display-plugins/CompositorHelper.h index 55364be85b..44c769c965 100644 --- a/libraries/display-plugins/src/display-plugins/CompositorHelper.h +++ b/libraries/display-plugins/src/display-plugins/CompositorHelper.h @@ -145,6 +145,11 @@ private: float _fadeInAlpha { true }; float _oculusUIRadius { 1.0f }; + quint64 _fadeStarted { 0.0f }; + float _fadeFailsafeEndValue { 1.0f }; + void checkFadeFailsafe(); + void startFadeFailsafe(float endValue); + int _reticleQuad; int _previousBorderWidth { -1 }; diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index 7af97678a7..4ef2648e10 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -296,6 +296,9 @@ void OpenGLDisplayPlugin::customizeContext() { if (uniform.Name() == "mvp") { _mvpUniform = uniform.Index(); } + if (uniform.Name() == "alpha") { + _alphaUniform = uniform.Index(); + } uniforms.Next(); } @@ -406,6 +409,20 @@ void OpenGLDisplayPlugin::updateFramerate() { void OpenGLDisplayPlugin::compositeOverlay() { using namespace oglplus; + + + // set the alpha + auto compositorHelper = DependencyManager::get(); + auto overlayAlpha = compositorHelper->getAlpha(); + + qDebug() << __FUNCTION__ << "overlayAlpha:" << overlayAlpha; + + if (overlayAlpha <= 0.0f) { + //return; // don't render the overlay at all. + qDebug() << "would bail early..."; + } + Uniform(*_program, _alphaUniform).Set(overlayAlpha); + // Overlay draw if (isStereo()) { Uniform(*_program, _mvpUniform).Set(mat4()); @@ -423,6 +440,17 @@ void OpenGLDisplayPlugin::compositeOverlay() { void OpenGLDisplayPlugin::compositePointer() { using namespace oglplus; auto compositorHelper = DependencyManager::get(); + + // set the alpha + auto overlayAlpha = compositorHelper->getAlpha(); + if (overlayAlpha <= 0.0f) { + //return; // don't render the overlay at all. + qDebug() << "would bail early..."; + } + qDebug() << __FUNCTION__ << "overlayAlpha:" << overlayAlpha; + Uniform(*_program, _alphaUniform).Set(overlayAlpha); + + Uniform(*_program, _mvpUniform).Set(compositorHelper->getReticleTransform(glm::mat4())); if (isStereo()) { for_each_eye([&](Eye eye) { diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h index 576d6d8eff..ace866a946 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h @@ -86,6 +86,7 @@ protected: ProgramPtr _program; int32_t _mvpUniform { -1 }; + int32_t _alphaUniform { -1 }; ShapeWrapperPtr _plane; mutable Mutex _mutex; diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index 92bfef0dc8..8427141e24 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -62,6 +62,20 @@ void HmdDisplayPlugin::uncustomizeContext() { void HmdDisplayPlugin::compositeOverlay() { using namespace oglplus; + + // set the alpha + auto compositorHelper = DependencyManager::get(); + auto overlayAlpha = compositorHelper->getAlpha(); + + qDebug() << __FUNCTION__ << "overlayAlpha:" << overlayAlpha; + + if (overlayAlpha <= 0.0f) { + //return; // don't render the overlay at all. + qDebug() << "would bail early..."; + } + Uniform(*_program, _alphaUniform).Set(overlayAlpha); + + _sphereSection->Use(); for_each_eye([&](Eye eye) { eyeViewport(eye); @@ -73,13 +87,28 @@ void HmdDisplayPlugin::compositeOverlay() { } void HmdDisplayPlugin::compositePointer() { + using namespace oglplus; + //Mouse Pointer + auto compositorHelper = DependencyManager::get(); + // set the alpha + auto overlayAlpha = compositorHelper->getAlpha(); + + qDebug() << __FUNCTION__ << "overlayAlpha:" << overlayAlpha; + + if (overlayAlpha <= 0.0f) { + //return; // don't render the overlay at all. + qDebug() << "would bail early..."; + } + qDebug() << __FUNCTION__ << "overlayAlpha:" << overlayAlpha; + Uniform(*_program, _alphaUniform).Set(1.0f); + + _plane->Use(); // Reconstruct the headpose from the eye poses auto headPosition = (vec3(_currentRenderEyePoses[Left][3]) + vec3(_currentRenderEyePoses[Right][3])) / 2.0f; for_each_eye([&](Eye eye) { - using namespace oglplus; eyeViewport(eye); auto reticleTransform = compositorHelper->getReticleTransform(_currentRenderEyePoses[eye], headPosition); auto mvp = _eyeProjections[eye] * reticleTransform; diff --git a/libraries/gl/src/gl/OglplusHelpers.cpp b/libraries/gl/src/gl/OglplusHelpers.cpp index a579f061b7..d583e6de6c 100644 --- a/libraries/gl/src/gl/OglplusHelpers.cpp +++ b/libraries/gl/src/gl/OglplusHelpers.cpp @@ -33,13 +33,14 @@ static const char * SIMPLE_TEXTURED_FS = R"FS(#version 410 core #pragma line __LINE__ uniform sampler2D sampler; +uniform float alpha = 1.0; in vec2 vTexCoord; out vec4 FragColor; void main() { - FragColor = texture(sampler, vTexCoord); + FragColor = texture(sampler, vTexCoord) * alpha; } )FS"; From 0c12c6ef90e9be1ddc5af25d90168e6afc4ee97d Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Thu, 10 Mar 2016 16:14:56 -0800 Subject: [PATCH 41/55] dont be an idiot --- .../src/display-plugins/OpenGLDisplayPlugin.cpp | 2 ++ .../src/display-plugins/hmd/HmdDisplayPlugin.cpp | 12 ++++++------ libraries/gl/src/gl/OglplusHelpers.cpp | 3 ++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index 4ef2648e10..ea96eeae7e 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -435,6 +435,7 @@ void OpenGLDisplayPlugin::compositeOverlay() { Uniform(*_program, _mvpUniform).Set(mat4()); drawUnitQuad(); } + Uniform(*_program, _alphaUniform).Set(1.0); } void OpenGLDisplayPlugin::compositePointer() { @@ -461,6 +462,7 @@ void OpenGLDisplayPlugin::compositePointer() { drawUnitQuad(); } Uniform(*_program, _mvpUniform).Set(mat4()); + Uniform(*_program, _alphaUniform).Set(1.0); } void OpenGLDisplayPlugin::compositeLayers() { diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index 8427141e24..d4865d8ada 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -84,6 +84,7 @@ void HmdDisplayPlugin::compositeOverlay() { Uniform(*_program, _mvpUniform).Set(mvp); _sphereSection->Draw(); }); + Uniform(*_program, _alphaUniform).Set(1.0); } void HmdDisplayPlugin::compositePointer() { @@ -92,17 +93,15 @@ void HmdDisplayPlugin::compositePointer() { //Mouse Pointer auto compositorHelper = DependencyManager::get(); + // set the alpha auto overlayAlpha = compositorHelper->getAlpha(); - - qDebug() << __FUNCTION__ << "overlayAlpha:" << overlayAlpha; - if (overlayAlpha <= 0.0f) { - //return; // don't render the overlay at all. - qDebug() << "would bail early..."; + //return; // don't render the overlay at all. + qDebug() << "would bail early..."; } qDebug() << __FUNCTION__ << "overlayAlpha:" << overlayAlpha; - Uniform(*_program, _alphaUniform).Set(1.0f); + Uniform(*_program, _alphaUniform).Set(overlayAlpha); _plane->Use(); @@ -115,6 +114,7 @@ void HmdDisplayPlugin::compositePointer() { Uniform(*_program, _mvpUniform).Set(mvp); _plane->Draw(); }); + Uniform(*_program, _alphaUniform).Set(1.0); } void HmdDisplayPlugin::internalPresent() { diff --git a/libraries/gl/src/gl/OglplusHelpers.cpp b/libraries/gl/src/gl/OglplusHelpers.cpp index d583e6de6c..1dd7068448 100644 --- a/libraries/gl/src/gl/OglplusHelpers.cpp +++ b/libraries/gl/src/gl/OglplusHelpers.cpp @@ -40,7 +40,8 @@ out vec4 FragColor; void main() { - FragColor = texture(sampler, vTexCoord) * alpha; + FragColor = texture(sampler, vTexCoord); + FragColor.a *= alpha; } )FS"; From 9842689ec075945a69b29433e3826d6faa293a09 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Thu, 10 Mar 2016 16:19:52 -0800 Subject: [PATCH 42/55] remove noise and return early --- .../src/display-plugins/OpenGLDisplayPlugin.cpp | 10 ++-------- .../src/display-plugins/hmd/HmdDisplayPlugin.cpp | 9 ++------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index ea96eeae7e..3a111f7fc8 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -415,11 +415,8 @@ void OpenGLDisplayPlugin::compositeOverlay() { auto compositorHelper = DependencyManager::get(); auto overlayAlpha = compositorHelper->getAlpha(); - qDebug() << __FUNCTION__ << "overlayAlpha:" << overlayAlpha; - if (overlayAlpha <= 0.0f) { - //return; // don't render the overlay at all. - qDebug() << "would bail early..."; + return; // don't render the overlay at all. } Uniform(*_program, _alphaUniform).Set(overlayAlpha); @@ -445,13 +442,10 @@ void OpenGLDisplayPlugin::compositePointer() { // set the alpha auto overlayAlpha = compositorHelper->getAlpha(); if (overlayAlpha <= 0.0f) { - //return; // don't render the overlay at all. - qDebug() << "would bail early..."; + return; // don't render the overlay at all. } - qDebug() << __FUNCTION__ << "overlayAlpha:" << overlayAlpha; Uniform(*_program, _alphaUniform).Set(overlayAlpha); - Uniform(*_program, _mvpUniform).Set(compositorHelper->getReticleTransform(glm::mat4())); if (isStereo()) { for_each_eye([&](Eye eye) { diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index d4865d8ada..a053452c9b 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -67,11 +67,8 @@ void HmdDisplayPlugin::compositeOverlay() { auto compositorHelper = DependencyManager::get(); auto overlayAlpha = compositorHelper->getAlpha(); - qDebug() << __FUNCTION__ << "overlayAlpha:" << overlayAlpha; - if (overlayAlpha <= 0.0f) { - //return; // don't render the overlay at all. - qDebug() << "would bail early..."; + return; // don't render the overlay at all. } Uniform(*_program, _alphaUniform).Set(overlayAlpha); @@ -97,10 +94,8 @@ void HmdDisplayPlugin::compositePointer() { // set the alpha auto overlayAlpha = compositorHelper->getAlpha(); if (overlayAlpha <= 0.0f) { - //return; // don't render the overlay at all. - qDebug() << "would bail early..."; + return; // don't render the overlay at all. } - qDebug() << __FUNCTION__ << "overlayAlpha:" << overlayAlpha; Uniform(*_program, _alphaUniform).Set(overlayAlpha); From 387c156ce33f305607d01221da71c14ce7de0018 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Thu, 10 Mar 2016 16:24:30 -0800 Subject: [PATCH 43/55] add failsafe for fade, so it can't endup between start and end property value --- .../src/display-plugins/CompositorHelper.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp b/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp index c013cf07af..860ed6ba37 100644 --- a/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp +++ b/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp @@ -419,9 +419,6 @@ static const float FADE_IN_ALPHA = 1.0f; static const float FADE_OUT_ALPHA = 0.0f; void CompositorHelper::startFadeFailsafe(float endValue) { - return; - - qDebug() << __FUNCTION__; _fadeStarted = usecTimestampNow(); _fadeFailsafeEndValue = endValue; @@ -432,9 +429,6 @@ void CompositorHelper::startFadeFailsafe(float endValue) { } void CompositorHelper::checkFadeFailsafe() { - return; - - qDebug() << __FUNCTION__; auto elapsedInFade = usecTimestampNow() - _fadeStarted; if (elapsedInFade > FADE_DURATION) { setAlpha(_fadeFailsafeEndValue); From 92c47fdc8ba54f8798d97aa62aefdf1b4dae5a4b Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Thu, 10 Mar 2016 16:44:59 -0800 Subject: [PATCH 44/55] fix build buster, CR feedback --- .../src/display-plugins/CompositorHelper.h | 2 +- .../display-plugins/OpenGLDisplayPlugin.cpp | 57 +++++++++-------- .../display-plugins/hmd/HmdDisplayPlugin.cpp | 62 +++++++++---------- 3 files changed, 58 insertions(+), 63 deletions(-) diff --git a/libraries/display-plugins/src/display-plugins/CompositorHelper.h b/libraries/display-plugins/src/display-plugins/CompositorHelper.h index 44c769c965..ebc0171752 100644 --- a/libraries/display-plugins/src/display-plugins/CompositorHelper.h +++ b/libraries/display-plugins/src/display-plugins/CompositorHelper.h @@ -145,7 +145,7 @@ private: float _fadeInAlpha { true }; float _oculusUIRadius { 1.0f }; - quint64 _fadeStarted { 0.0f }; + quint64 _fadeStarted { 0 }; float _fadeFailsafeEndValue { 1.0f }; void checkFadeFailsafe(); void startFadeFailsafe(float endValue); diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index 3a111f7fc8..1c175b778c 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -410,27 +410,26 @@ void OpenGLDisplayPlugin::updateFramerate() { void OpenGLDisplayPlugin::compositeOverlay() { using namespace oglplus; - - // set the alpha auto compositorHelper = DependencyManager::get(); + + // check the alpha auto overlayAlpha = compositorHelper->getAlpha(); + if (overlayAlpha > 0.0f) { + // set the alpha + Uniform(*_program, _alphaUniform).Set(overlayAlpha); - if (overlayAlpha <= 0.0f) { - return; // don't render the overlay at all. - } - Uniform(*_program, _alphaUniform).Set(overlayAlpha); - - // Overlay draw - if (isStereo()) { - Uniform(*_program, _mvpUniform).Set(mat4()); - for_each_eye([&](Eye eye) { - eyeViewport(eye); - drawUnitQuad(); - }); - } else { // Overlay draw - Uniform(*_program, _mvpUniform).Set(mat4()); - drawUnitQuad(); + if (isStereo()) { + Uniform(*_program, _mvpUniform).Set(mat4()); + for_each_eye([&](Eye eye) { + eyeViewport(eye); + drawUnitQuad(); + }); + } else { + // Overlay draw + Uniform(*_program, _mvpUniform).Set(mat4()); + drawUnitQuad(); + } } Uniform(*_program, _alphaUniform).Set(1.0); } @@ -439,21 +438,21 @@ void OpenGLDisplayPlugin::compositePointer() { using namespace oglplus; auto compositorHelper = DependencyManager::get(); - // set the alpha + // check the alpha auto overlayAlpha = compositorHelper->getAlpha(); - if (overlayAlpha <= 0.0f) { - return; // don't render the overlay at all. - } - Uniform(*_program, _alphaUniform).Set(overlayAlpha); + if (overlayAlpha > 0.0f) { + // set the alpha + Uniform(*_program, _alphaUniform).Set(overlayAlpha); - Uniform(*_program, _mvpUniform).Set(compositorHelper->getReticleTransform(glm::mat4())); - if (isStereo()) { - for_each_eye([&](Eye eye) { - eyeViewport(eye); + Uniform(*_program, _mvpUniform).Set(compositorHelper->getReticleTransform(glm::mat4())); + if (isStereo()) { + for_each_eye([&](Eye eye) { + eyeViewport(eye); + drawUnitQuad(); + }); + } else { drawUnitQuad(); - }); - } else { - drawUnitQuad(); + } } Uniform(*_program, _mvpUniform).Set(mat4()); Uniform(*_program, _alphaUniform).Set(1.0); diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index a053452c9b..e3d92d5761 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -62,53 +62,49 @@ void HmdDisplayPlugin::uncustomizeContext() { void HmdDisplayPlugin::compositeOverlay() { using namespace oglplus; - - // set the alpha auto compositorHelper = DependencyManager::get(); + + // check the alpha auto overlayAlpha = compositorHelper->getAlpha(); + if (overlayAlpha > 0.0f) { + // set the alpha + Uniform(*_program, _alphaUniform).Set(overlayAlpha); - if (overlayAlpha <= 0.0f) { - return; // don't render the overlay at all. + _sphereSection->Use(); + for_each_eye([&](Eye eye) { + eyeViewport(eye); + auto modelView = glm::inverse(_currentRenderEyePoses[eye]); // *glm::translate(mat4(), vec3(0, 0, -1)); + auto mvp = _eyeProjections[eye] * modelView; + Uniform(*_program, _mvpUniform).Set(mvp); + _sphereSection->Draw(); + }); } - Uniform(*_program, _alphaUniform).Set(overlayAlpha); - - - _sphereSection->Use(); - for_each_eye([&](Eye eye) { - eyeViewport(eye); - auto modelView = glm::inverse(_currentRenderEyePoses[eye]); // *glm::translate(mat4(), vec3(0, 0, -1)); - auto mvp = _eyeProjections[eye] * modelView; - Uniform(*_program, _mvpUniform).Set(mvp); - _sphereSection->Draw(); - }); Uniform(*_program, _alphaUniform).Set(1.0); } void HmdDisplayPlugin::compositePointer() { using namespace oglplus; - //Mouse Pointer - auto compositorHelper = DependencyManager::get(); - // set the alpha + // check the alpha auto overlayAlpha = compositorHelper->getAlpha(); - if (overlayAlpha <= 0.0f) { - return; // don't render the overlay at all. + if (overlayAlpha > 0.0f) { + // set the alpha + Uniform(*_program, _alphaUniform).Set(overlayAlpha); + + // Mouse pointer + _plane->Use(); + // Reconstruct the headpose from the eye poses + auto headPosition = (vec3(_currentRenderEyePoses[Left][3]) + vec3(_currentRenderEyePoses[Right][3])) / 2.0f; + for_each_eye([&](Eye eye) { + eyeViewport(eye); + auto reticleTransform = compositorHelper->getReticleTransform(_currentRenderEyePoses[eye], headPosition); + auto mvp = _eyeProjections[eye] * reticleTransform; + Uniform(*_program, _mvpUniform).Set(mvp); + _plane->Draw(); + }); } - Uniform(*_program, _alphaUniform).Set(overlayAlpha); - - - _plane->Use(); - // Reconstruct the headpose from the eye poses - auto headPosition = (vec3(_currentRenderEyePoses[Left][3]) + vec3(_currentRenderEyePoses[Right][3])) / 2.0f; - for_each_eye([&](Eye eye) { - eyeViewport(eye); - auto reticleTransform = compositorHelper->getReticleTransform(_currentRenderEyePoses[eye], headPosition); - auto mvp = _eyeProjections[eye] * reticleTransform; - Uniform(*_program, _mvpUniform).Set(mvp); - _plane->Draw(); - }); Uniform(*_program, _alphaUniform).Set(1.0); } From 11867aa71ddd900e72a07131b96423e6e493fe8a Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 20:03:31 -0800 Subject: [PATCH 45/55] Compile shaders to their own folders --- cmake/macros/AutoScribeShader.cmake | 6 + cmake/macros/LinkHifiLibraries.cmake | 10 +- interface/src/Stars.cpp | 8 +- .../src/RenderableBoxEntityItem.cpp | 4 +- .../src/RenderableSphereEntityItem.cpp | 4 +- tests/shaders/src/main.cpp | 118 +++++++++--------- 6 files changed, 72 insertions(+), 78 deletions(-) diff --git a/cmake/macros/AutoScribeShader.cmake b/cmake/macros/AutoScribeShader.cmake index 6dc4899d29..29a53e7737 100755 --- a/cmake/macros/AutoScribeShader.cmake +++ b/cmake/macros/AutoScribeShader.cmake @@ -46,6 +46,9 @@ function(AUTOSCRIBE_SHADER SHADER_FILE) set(SHADER_TARGET ${SHADER_TARGET}_frag.h) endif() + # Put shaders in an isolated place + set(SHADER_TARGET "shaders/${TARGET_NAME}/${SHADER_TARGET}") + # Target dependant Custom rule on the SHADER_FILE if (APPLE) set(GLPROFILE MAC_GL) @@ -105,4 +108,7 @@ macro(AUTOSCRIBE_SHADER_LIB) list(APPEND AUTOSCRIBE_SHADER_LIB_SRC ${SHADER_SOURCE_FILES}) list(APPEND AUTOSCRIBE_SHADER_LIB_SRC ${AUTOSCRIBE_SHADER_SRC}) + # Link library shaders, if they exist + include_directories("${CMAKE_CURRENT_BINARY_DIR}/shaders/${TARGET_NAME}") + endmacro() diff --git a/cmake/macros/LinkHifiLibraries.cmake b/cmake/macros/LinkHifiLibraries.cmake index ed37256b10..3767dc7131 100644 --- a/cmake/macros/LinkHifiLibraries.cmake +++ b/cmake/macros/LinkHifiLibraries.cmake @@ -19,20 +19,14 @@ macro(LINK_HIFI_LIBRARIES) endif () include_directories("${HIFI_LIBRARY_DIR}/${HIFI_LIBRARY}/src") + include_directories("${CMAKE_BINARY_DIR}/libraries/${HIFI_LIBRARY}/shaders") add_dependencies(${TARGET_NAME} ${HIFI_LIBRARY}) # link the actual library - it is static so don't bubble it up target_link_libraries(${TARGET_NAME} ${HIFI_LIBRARY}) - - # ask the library what its include dependencies are and link them - get_target_property(LINKED_TARGET_DEPENDENCY_INCLUDES ${HIFI_LIBRARY} DEPENDENCY_INCLUDES) - - if(LINKED_TARGET_DEPENDENCY_INCLUDES) - list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES ${LINKED_TARGET_DEPENDENCY_INCLUDES}) - endif() endforeach() setup_memory_debugger() -endmacro(LINK_HIFI_LIBRARIES) \ No newline at end of file +endmacro(LINK_HIFI_LIBRARIES) diff --git a/interface/src/Stars.cpp b/interface/src/Stars.cpp index 3305cc4f3b..a0283f0efd 100644 --- a/interface/src/Stars.cpp +++ b/interface/src/Stars.cpp @@ -22,11 +22,11 @@ #include #include -#include -#include +#include +#include -#include -#include +#include +#include //static const float TILT = 0.23f; static const float TILT = 0.0f; diff --git a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp index 671043813e..e53b77a4dc 100644 --- a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp @@ -19,8 +19,8 @@ #include #include -#include "../render-utils/simple_vert.h" -#include "../render-utils/simple_frag.h" +#include +#include EntityItemPointer RenderableBoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { EntityItemPointer entity{ new RenderableBoxEntityItem(entityID) }; diff --git a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp index b5867fb1ee..135e29cc48 100644 --- a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp @@ -19,8 +19,8 @@ #include #include -#include "../render-utils/simple_vert.h" -#include "../render-utils/simple_frag.h" +#include +#include // Sphere entities should fit inside a cube entity of the same size, so a sphere that has dimensions 1x1x1 // is a half unit sphere. However, the geometry cache renders a UNIT sphere, so we need to scale down. diff --git a/tests/shaders/src/main.cpp b/tests/shaders/src/main.cpp index ddc7ad6540..82c5583f53 100644 --- a/tests/shaders/src/main.cpp +++ b/tests/shaders/src/main.cpp @@ -23,83 +23,77 @@ #include #include -#include "../model/Skybox_vert.h" -#include "../model/Skybox_frag.h" +#include +#include +#include +#include -#include "simple_vert.h" -#include "simple_frag.h" -#include "simple_textured_frag.h" -#include "simple_textured_emisive_frag.h" +#include +#include -#include "deferred_light_vert.h" -#include "deferred_light_limited_vert.h" +#include +#include +#include -#include "directional_light_frag.h" +#include +#include -#include "directional_ambient_light_frag.h" +#include +#include -#include "directional_skybox_light_frag.h" +#include +#include +#include +#include +#include +#include +#include +#include -#include "point_light_frag.h" -#include "spot_light_frag.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include "standardTransformPNTC_vert.h" -#include "standardDrawTexture_frag.h" +#include +#include +#include +#include -#include "model_vert.h" -#include "model_shadow_vert.h" -#include "model_normal_map_vert.h" -#include "model_lightmap_vert.h" -#include "model_lightmap_normal_map_vert.h" -#include "skin_model_vert.h" -#include "skin_model_shadow_vert.h" -#include "skin_model_normal_map_vert.h" +#include +#include -#include "model_frag.h" -#include "model_shadow_frag.h" -#include "model_normal_map_frag.h" -#include "model_normal_specular_map_frag.h" -#include "model_specular_map_frag.h" -#include "model_lightmap_frag.h" -#include "model_lightmap_normal_map_frag.h" -#include "model_lightmap_normal_specular_map_frag.h" -#include "model_lightmap_specular_map_frag.h" -#include "model_translucent_frag.h" +#include +#include -#include "untextured_particle_frag.h" -#include "untextured_particle_vert.h" -#include "textured_particle_frag.h" -#include "textured_particle_vert.h" +#include +#include +#include +#include +#include -#include "hit_effect_vert.h" -#include "hit_effect_frag.h" +#include +#include +#include +#include +#include +#include -#include "overlay3D_vert.h" -#include "overlay3D_frag.h" +#include +#include -#include "Skybox_vert.h" -#include "Skybox_frag.h" +#include +#include -#include "stars_vert.h" -#include "stars_frag.h" -#include "starsGrid_frag.h" - -#include "DrawTransformUnitQuad_vert.h" -#include "DrawTexcoordRectTransformUnitQuad_vert.h" -#include "DrawViewportQuadTransformTexcoord_vert.h" -#include "DrawTexture_frag.h" -#include "DrawTextureOpaque_frag.h" -#include "DrawColoredTexture_frag.h" - -#include "sdf_text3D_vert.h" -#include "sdf_text3D_frag.h" - -#include "paintStroke_vert.h" -#include "paintStroke_frag.h" - -#include "polyvox_vert.h" -#include "polyvox_frag.h" +#include +#include // Create a simple OpenGL window that renders text in various ways class QTestWindow : public QWindow { From 243fbf82993adcd85a83dcdcbd71bfb860e8e9b9 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 20:37:24 -0800 Subject: [PATCH 46/55] Specify and create shaders folder --- cmake/macros/AutoScribeShader.cmake | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cmake/macros/AutoScribeShader.cmake b/cmake/macros/AutoScribeShader.cmake index 29a53e7737..f51455e9d4 100755 --- a/cmake/macros/AutoScribeShader.cmake +++ b/cmake/macros/AutoScribeShader.cmake @@ -46,8 +46,7 @@ function(AUTOSCRIBE_SHADER SHADER_FILE) set(SHADER_TARGET ${SHADER_TARGET}_frag.h) endif() - # Put shaders in an isolated place - set(SHADER_TARGET "shaders/${TARGET_NAME}/${SHADER_TARGET}") + set(SHADER_TARGET "${SHADERS_DIR}/${SHADER_TARGET}") # Target dependant Custom rule on the SHADER_FILE if (APPLE) @@ -90,10 +89,14 @@ macro(AUTOSCRIBE_SHADER_LIB) file(GLOB_RECURSE SHADER_INCLUDE_FILES src/*.slh) file(GLOB_RECURSE SHADER_SOURCE_FILES src/*.slv src/*.slf) + #make the shader folder + set(SHADERS_DIR "${CMAKE_CURRENT_BINARY_DIR}/shaders/${TARGET_NAME}") + file(MAKE_DIRECTORY ${SHADERS_DIR}) + #message(${SHADER_INCLUDE_FILES}) foreach(SHADER_FILE ${SHADER_SOURCE_FILES}) AUTOSCRIBE_SHADER(${SHADER_FILE} ${SHADER_INCLUDE_FILES}) - file(TO_CMAKE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${AUTOSCRIBE_SHADER_RETURN}" AUTOSCRIBE_GENERATED_FILE) + file(TO_CMAKE_PATH "${AUTOSCRIBE_SHADER_RETURN}" AUTOSCRIBE_GENERATED_FILE) list(APPEND AUTOSCRIBE_SHADER_SRC ${AUTOSCRIBE_GENERATED_FILE}) endforeach() #message(${AUTOSCRIBE_SHADER_SRC}) @@ -109,6 +112,6 @@ macro(AUTOSCRIBE_SHADER_LIB) list(APPEND AUTOSCRIBE_SHADER_LIB_SRC ${AUTOSCRIBE_SHADER_SRC}) # Link library shaders, if they exist - include_directories("${CMAKE_CURRENT_BINARY_DIR}/shaders/${TARGET_NAME}") + include_directories("${SHADERS_DIR}") endmacro() From 4eca43027a1d935354a2075be5ca78a26a556516 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 21:05:36 -0800 Subject: [PATCH 47/55] Add texture, color to px skybox --- libraries/model/src/model/Skybox.cpp | 35 ++++++++-------- libraries/model/src/model/Skybox.h | 12 ++++-- libraries/model/src/model/Skybox.slf | 41 ------------------- .../src/model/skybox.slf} | 16 +++++--- .../src/model/{Skybox.slv => skybox.slv} | 0 .../procedural/src/procedural/Procedural.h | 1 + .../src/procedural/ProceduralSkybox.cpp | 14 ++++--- .../src/procedural/ProceduralSkybox.slv | 39 ------------------ 8 files changed, 47 insertions(+), 111 deletions(-) delete mode 100755 libraries/model/src/model/Skybox.slf rename libraries/{procedural/src/procedural/ProceduralSkybox.slf => model/src/model/skybox.slf} (76%) mode change 100644 => 100755 rename libraries/model/src/model/{Skybox.slv => skybox.slv} (100%) delete mode 100644 libraries/procedural/src/procedural/ProceduralSkybox.slv diff --git a/libraries/model/src/model/Skybox.cpp b/libraries/model/src/model/Skybox.cpp index 0f9d3ca4de..aff4361338 100755 --- a/libraries/model/src/model/Skybox.cpp +++ b/libraries/model/src/model/Skybox.cpp @@ -15,8 +15,8 @@ #include #include -#include "Skybox_vert.h" -#include "Skybox_frag.h" +#include "skybox_vert.h" +#include "skybox_frag.h" using namespace model; @@ -26,7 +26,7 @@ Skybox::Skybox() { } void Skybox::setColor(const Color& color) { - _schemaBuffer.edit()._color = color; + _schemaBuffer.edit().color = color; } void Skybox::setCubemap(const gpu::TexturePointer& cubemap) { @@ -44,8 +44,18 @@ void Skybox::updateSchemaBuffer() const { } } - if (blend != _schemaBuffer.get()._blend) { - _schemaBuffer.edit()._blend = blend; + if (blend != _schemaBuffer.get().blend) { + _schemaBuffer.edit().blend = blend; + } +} + +void Skybox::prepare(gpu::Batch& batch, int textureSlot, int bufferSlot) const { + batch.setUniformBuffer(bufferSlot, _schemaBuffer); + + gpu::TexturePointer skymap = getCubemap(); + // FIXME: skymap->isDefined may not be threadsafe + if (skymap && skymap->isDefined()) { + batch.setResourceTexture(textureSlot, skymap); } } @@ -58,13 +68,11 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky // Create the static shared elements used to render the skybox static gpu::BufferPointer theConstants; static gpu::PipelinePointer thePipeline; - const int SKYBOX_SKYMAP_SLOT = 0; - const int SKYBOX_CONSTANTS_SLOT = 0; static std::once_flag once; std::call_once(once, [&] { { - auto skyVS = gpu::Shader::createVertex(std::string(Skybox_vert)); - auto skyFS = gpu::Shader::createPixel(std::string(Skybox_frag)); + auto skyVS = gpu::Shader::createVertex(std::string(skybox_vert)); + auto skyFS = gpu::Shader::createPixel(std::string(skybox_frag)); auto skyShader = gpu::Shader::createProgram(skyVS, skyFS); gpu::Shader::BindingSet bindings; @@ -93,14 +101,7 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky batch.setModelTransform(Transform()); // only for Mac batch.setPipeline(thePipeline); - batch.setUniformBuffer(SKYBOX_CONSTANTS_SLOT, skybox._schemaBuffer); - - gpu::TexturePointer skymap = skybox.getCubemap(); - // FIXME: skymap->isDefined may not be threadsafe - if (skymap && skymap->isDefined()) { - batch.setResourceTexture(SKYBOX_SKYMAP_SLOT, skymap); - } - + skybox.prepare(batch); batch.draw(gpu::TRIANGLE_STRIP, 4); batch.setResourceTexture(SKYBOX_SKYMAP_SLOT, nullptr); diff --git a/libraries/model/src/model/Skybox.h b/libraries/model/src/model/Skybox.h index 7382ffabdd..e9e7ee8b26 100755 --- a/libraries/model/src/model/Skybox.h +++ b/libraries/model/src/model/Skybox.h @@ -30,29 +30,33 @@ public: virtual ~Skybox() {}; void setColor(const Color& color); - const Color getColor() const { return _schemaBuffer.get()._color; } + const Color getColor() const { return _schemaBuffer.get().color; } void setCubemap(const gpu::TexturePointer& cubemap); const gpu::TexturePointer& getCubemap() const { return _cubemap; } + void prepare(gpu::Batch& batch, int textureSlot = SKYBOX_SKYMAP_SLOT, int bufferSlot = SKYBOX_CONSTANTS_SLOT) const; virtual void render(gpu::Batch& batch, const ViewFrustum& frustum) const; static void render(gpu::Batch& batch, const ViewFrustum& frustum, const Skybox& skybox); protected: + static const int SKYBOX_SKYMAP_SLOT { 0 }; + static const int SKYBOX_CONSTANTS_SLOT { 0 }; + gpu::TexturePointer _cubemap; class Schema { public: - glm::vec3 _color { 1.0f, 1.0f, 1.0f }; - float _blend { 0.0f }; + glm::vec3 color { 1.0f, 1.0f, 1.0f }; + float blend { 0.0f }; }; mutable gpu::BufferView _schemaBuffer; void updateSchemaBuffer() const; }; -typedef std::shared_ptr< Skybox > SkyboxPointer; +typedef std::shared_ptr SkyboxPointer; }; diff --git a/libraries/model/src/model/Skybox.slf b/libraries/model/src/model/Skybox.slf deleted file mode 100755 index 93f68e3406..0000000000 --- a/libraries/model/src/model/Skybox.slf +++ /dev/null @@ -1,41 +0,0 @@ -<@include gpu/Config.slh@> -<$VERSION_HEADER$> -// Generated on <$_SCRIBE_DATE$> -// skybox.frag -// fragment shader -// -// Created by Sam Gateau on 5/5/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 samplerCube cubeMap; - -struct Skybox { - vec3 _color; - float _blend; -}; - -uniform skyboxBuffer { - Skybox _skybox; -}; - -in vec3 _normal; -out vec4 _fragColor; - -void main(void) { - vec3 coord = normalize(_normal); - vec3 color = _skybox._color; - - // blend is only set if there is a cubemap - if (_skybox._blend > 0.0) { - color = texture(cubeMap, coord).rgb; - if (_skybox._blend < 1.0) { - color *= _skybox._color; - } - } - - _fragColor = vec4(color, 0.0); -} diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.slf b/libraries/model/src/model/skybox.slf old mode 100644 new mode 100755 similarity index 76% rename from libraries/procedural/src/procedural/ProceduralSkybox.slf rename to libraries/model/src/model/skybox.slf index 7ad6f6b5a1..6eb3cf3963 --- a/libraries/procedural/src/procedural/ProceduralSkybox.slf +++ b/libraries/model/src/model/skybox.slf @@ -14,11 +14,11 @@ uniform samplerCube cubeMap; struct Skybox { - vec4 _color; + vec4 color; }; uniform skyboxBuffer { - Skybox _skybox; + Skybox skybox; }; in vec3 _normal; @@ -40,10 +40,16 @@ void main(void) { _fragColor = vec4(color, 0.0); #else - vec3 coord = normalize(_normal); - vec3 texel = texture(cubeMap, coord).rgb; - vec3 color = texel * _skybox._color.rgb; + vec3 color = skybox.color.rgb; + + // blend is only set if there is a cubemap + if (skybox.color.a > 0.0) { + color = texture(cubeMap, coord).rgb; + if (skybox.color.a < 1.0) { + color *= skybox.color.rgb; + } + } _fragColor = vec4(color, 0.0); #endif diff --git a/libraries/model/src/model/Skybox.slv b/libraries/model/src/model/skybox.slv similarity index 100% rename from libraries/model/src/model/Skybox.slv rename to libraries/model/src/model/skybox.slv diff --git a/libraries/procedural/src/procedural/Procedural.h b/libraries/procedural/src/procedural/Procedural.h index 1b02fbd435..0d3ab63773 100644 --- a/libraries/procedural/src/procedural/Procedural.h +++ b/libraries/procedural/src/procedural/Procedural.h @@ -35,6 +35,7 @@ struct Procedural { void parse(const QJsonObject&); bool ready(); void prepare(gpu::Batch& batch, const glm::vec3& position, const glm::vec3& size); + const gpu::ShaderPointer& getShader() const { return _shader; } void setupUniforms(); glm::vec4 getColor(const glm::vec4& entityColor); diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.cpp b/libraries/procedural/src/procedural/ProceduralSkybox.cpp index 95deaa4dc5..cf57dbb574 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.cpp +++ b/libraries/procedural/src/procedural/ProceduralSkybox.cpp @@ -15,8 +15,8 @@ #include #include -#include "ProceduralSkybox_vert.h" -#include "ProceduralSkybox_frag.h" +#include +#include ProceduralSkybox::ProceduralSkybox() : model::Skybox() { } @@ -30,8 +30,8 @@ ProceduralSkybox::ProceduralSkybox(const ProceduralSkybox& skybox) : void ProceduralSkybox::setProcedural(const ProceduralPointer& procedural) { _procedural = procedural; if (_procedural) { - _procedural->_vertexSource = ProceduralSkybox_vert; - _procedural->_fragmentSource = ProceduralSkybox_frag; + _procedural->_vertexSource = skybox_vert; + _procedural->_fragmentSource = skybox_frag; // Adjust the pipeline state for background using the stencil test _procedural->_state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); } @@ -56,7 +56,11 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, batch.setViewTransform(viewTransform); batch.setModelTransform(Transform()); // only for Mac - skybox._procedural->prepare(batch, glm::vec3(0), glm::vec3(1)); + const auto& procedural = skybox._procedural; + procedural->prepare(batch, glm::vec3(0), glm::vec3(1)); + auto textureSlot = procedural->getShader()->getTextures().findLocation("cubeMap"); + auto bufferSlot = procedural->getShader()->getBuffers().findLocation("skyboxBuffer"); + skybox.prepare(batch, textureSlot, bufferSlot); batch.draw(gpu::TRIANGLE_STRIP, 4); } } diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.slv b/libraries/procedural/src/procedural/ProceduralSkybox.slv deleted file mode 100644 index 810afb1033..0000000000 --- a/libraries/procedural/src/procedural/ProceduralSkybox.slv +++ /dev/null @@ -1,39 +0,0 @@ -<@include gpu/Config.slh@> -<$VERSION_HEADER$> -// Generated on <$_SCRIBE_DATE$> -// skybox.vert -// vertex shader -// -// Created by Sam Gateau on 5/5/2015. -// Copyright 2015 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -<@include gpu/Transform.slh@> - -<$declareStandardTransform()$> - -out vec3 _normal; - -void main(void) { - const float depth = 0.0; - const vec4 UNIT_QUAD[4] = vec4[4]( - vec4(-1.0, -1.0, depth, 1.0), - vec4(1.0, -1.0, depth, 1.0), - vec4(-1.0, 1.0, depth, 1.0), - vec4(1.0, 1.0, depth, 1.0) - ); - vec4 inPosition = UNIT_QUAD[gl_VertexID]; - - // standard transform - TransformCamera cam = getTransformCamera(); - vec3 clipDir = vec3(inPosition.xy, 0.0); - vec3 eyeDir; - <$transformClipToEyeDir(cam, clipDir, eyeDir)$> - <$transformEyeToWorldDir(cam, eyeDir, _normal)$> - - // Position is supposed to come in clip space - gl_Position = vec4(inPosition.xy, 0.0, 1.0); -} \ No newline at end of file From aa884d9e3b4f56d9f417764c4e6f6f5c247fa0a4 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 10 Mar 2016 22:45:44 -0800 Subject: [PATCH 48/55] spatial --- examples/html/entityProperties.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index 7c229075fd..1101a08acb 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -1237,7 +1237,7 @@
- +
From 25607709a5e829cad234e79d71b2314f70c4438e Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 21:44:43 -0800 Subject: [PATCH 49/55] Add test for skybox --- examples/tests/skybox/px.fs | 18 ++++++ examples/tests/skybox/px_rgba.fs | 20 +++++++ examples/tests/skybox/px_tex.fs | 22 ++++++++ examples/tests/skybox/px_tex_rgba.fs | 24 ++++++++ examples/tests/skybox/skyboxTest.js | 83 ++++++++++++++++++++++++++++ 5 files changed, 167 insertions(+) create mode 100644 examples/tests/skybox/px.fs create mode 100644 examples/tests/skybox/px_rgba.fs create mode 100644 examples/tests/skybox/px_tex.fs create mode 100644 examples/tests/skybox/px_tex_rgba.fs create mode 100644 examples/tests/skybox/skyboxTest.js diff --git a/examples/tests/skybox/px.fs b/examples/tests/skybox/px.fs new file mode 100644 index 0000000000..8b6bdc0e5c --- /dev/null +++ b/examples/tests/skybox/px.fs @@ -0,0 +1,18 @@ +// +// px.fs +// examples/tests/skybox +// +// Created by Zach Pomerantz on 3/10/2016 +// Copyright 2016 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 + + +vec3 getSkyboxColor() { + float red = (cos(iGlobalTime) + 1) / 2; + vec3 color = vec3(red, 1.0, 1.0); + + return color; +} + diff --git a/examples/tests/skybox/px_rgba.fs b/examples/tests/skybox/px_rgba.fs new file mode 100644 index 0000000000..59bac7d963 --- /dev/null +++ b/examples/tests/skybox/px_rgba.fs @@ -0,0 +1,20 @@ +// +// px_rgba.fs +// examples/tests/skybox +// +// Created by Zach Pomerantz on 3/10/2016 +// Copyright 2016 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 + + +vec3 getSkyboxColor() { + float red = (cos(iGlobalTime) + 1) / 2; + vec3 color = vec3(red, 1.0, 1.0); + + color *= skybox.color.rgb; + + return color; +} + diff --git a/examples/tests/skybox/px_tex.fs b/examples/tests/skybox/px_tex.fs new file mode 100644 index 0000000000..9d9da7ba10 --- /dev/null +++ b/examples/tests/skybox/px_tex.fs @@ -0,0 +1,22 @@ +// +// px_rgba.fs +// examples/tests/skybox +// +// Created by Zach Pomerantz on 3/10/2016 +// Copyright 2016 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 + + +vec3 getSkyboxColor() { + float red = (cos(iGlobalTime) + 1) / 2; + vec3 color = vec3(red, 1.0, 1.0); + + vec3 coord = normalize(_normal); + vec3 texel = texture(cubeMap, coord).rgb; + color *= texel; + + return color; +} + diff --git a/examples/tests/skybox/px_tex_rgba.fs b/examples/tests/skybox/px_tex_rgba.fs new file mode 100644 index 0000000000..d44a32e33e --- /dev/null +++ b/examples/tests/skybox/px_tex_rgba.fs @@ -0,0 +1,24 @@ +// +// px_rgba.fs +// examples/tests/skybox +// +// Created by Zach Pomerantz on 3/10/2016 +// Copyright 2016 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 + + +vec3 getSkyboxColor() { + float red = (cos(iGlobalTime) + 1) / 2; + vec3 color = vec3(red, 1.0, 1.0); + + vec3 coord = normalize(_normal); + vec3 texel = texture(cubeMap, coord).rgb; + color *= texel; + + color *= skybox.color.rgb; + + return color; +} + diff --git a/examples/tests/skybox/skyboxTest.js b/examples/tests/skybox/skyboxTest.js new file mode 100644 index 0000000000..76d80ab153 --- /dev/null +++ b/examples/tests/skybox/skyboxTest.js @@ -0,0 +1,83 @@ +// skyboxTest.js +// examples/tests/skybox +// +// Created by Zach Pomerantz on 3/10/2016. +// Copyright 2016 High Fidelity, Inc. +// +// This test cycles through different variations on the skybox with a mouseclick. +// For the test to pass, you should observe the following cycle: +// - Procedural skybox (no texture, no color) +// - Procedural skybox (no texture, with color) +// - Procedural skybox (with texture, no color) +// - Procedural skybox (with texture, with color) +// - Color skybox (no texture) +// - Color skybox (with texture) +// - Texture skybox (no color) +// +// As you run the test, descriptions of the expected rendered skybox will appear as overlays. +// +// NOTE: This does not test uniforms/textures applied to a procedural shader through userData. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var PX_URL = Script.resolvePath('px.fs'); +var PX_RGBA_URL = Script.resolvePath('px_rgba.fs'); +var PX_TEX_URL = Script.resolvePath('px_tex.fs'); +var PX_TEX_RGBA_URL = Script.resolvePath('px_tex_rgba.fs'); + +var TEX_URL = 'https://hifi-public.s3.amazonaws.com/alan/Playa/Skies/Test-Sky_out.png'; +var NO_TEX = ''; + +var COLOR = { red: 255, green: 0, blue: 255 }; +var NO_COLOR = { red: 0, green: 0, blue: 0 }; + +var data = { ProceduralEntity: { shaderUrl: PX_URL } }; + +var zone = Entities.addEntity({ + type: 'Zone', + dimensions: { x: 50, y: 50, z: 50 }, + position: MyAvatar.position, + backgroundMode: 'skybox' +}); +var text = Overlays.addOverlay('text', { + text: 'Click this box to advance tests; note that red value cycling means white->light blue', + x: Window.innerWidth / 2 - 250, y: Window.innerHeight / 2 - 25, + width: 500, height: 50 +}); + +print('Zone:', zone); +print('Text:', text); + +var edits = [ + ['Red value should cycle', getEdit(PX_URL, NO_TEX, NO_COLOR)], + ['Red value should cycle, no green', getEdit(PX_RGBA_URL, NO_TEX, COLOR)], + ['Red value should cycle, each face tinted differently', getEdit(PX_TEX_URL, TEX_URL, NO_COLOR)], + ['Red value should cycle, each face tinted differently, no green', getEdit(PX_TEX_RGBA_URL, TEX_URL, COLOR)], + ['No green', getEdit(null, NO_TEX, COLOR)], + ['Each face colored differently, no green', getEdit(null, TEX_URL, COLOR)], + ['Each face colored differently', getEdit(null, TEX_URL, NO_COLOR)], +]; + +Controller.mousePressEvent.connect(function(e) { if (Overlays.getOverlayAtPoint(e) === text) next(); }); + +Script.scriptEnding.connect(function() { + Overlays.deleteOverlay(text); + Entities.deleteEntity(zone); +}); + +var i = 0; +function next() { + var edit = edits[i]; + Overlays.editOverlay(text, { text: edit[0] }); + Entities.editEntity(zone, edit[1]); + i++; + i %= edits.length; +} + +function getEdit(px, url, color) { + return { userData: px ? getUserData(px) : '', backgroundMode: 'skybox', skybox: { url: url, color: color } } +} +function getUserData(px) { return JSON.stringify({ ProceduralEntity: { shaderUrl: px } }); } + From 4dad797e2044304208fff625179118ab04621b7e Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 22:52:44 -0800 Subject: [PATCH 50/55] Only add buffer/tex to skymap if asked for --- libraries/model/src/model/Skybox.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libraries/model/src/model/Skybox.cpp b/libraries/model/src/model/Skybox.cpp index aff4361338..cb3fb43630 100755 --- a/libraries/model/src/model/Skybox.cpp +++ b/libraries/model/src/model/Skybox.cpp @@ -50,12 +50,16 @@ void Skybox::updateSchemaBuffer() const { } void Skybox::prepare(gpu::Batch& batch, int textureSlot, int bufferSlot) const { - batch.setUniformBuffer(bufferSlot, _schemaBuffer); + if (bufferSlot > -1) { + batch.setUniformBuffer(bufferSlot, _schemaBuffer); + } - gpu::TexturePointer skymap = getCubemap(); - // FIXME: skymap->isDefined may not be threadsafe - if (skymap && skymap->isDefined()) { - batch.setResourceTexture(textureSlot, skymap); + if (textureSlot > -1) { + gpu::TexturePointer skymap = getCubemap(); + // FIXME: skymap->isDefined may not be threadsafe + if (skymap && skymap->isDefined()) { + batch.setResourceTexture(textureSlot, skymap); + } } } From 27884b26e9091c6ac9b1c14312aab9e4b47633a9 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 22:53:07 -0800 Subject: [PATCH 51/55] Mark px shaders dirty on change --- libraries/procedural/src/procedural/Procedural.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index 11df332c5c..922d466d42 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -101,6 +101,7 @@ bool Procedural::parseUrl(const QUrl& shaderUrl) { } _shaderUrl = shaderUrl; + _shaderDirty = true; if (_shaderUrl.isLocalFile()) { _shaderPath = _shaderUrl.toLocalFile(); @@ -230,7 +231,10 @@ void Procedural::prepare(gpu::Batch& batch, const glm::vec3& position, const glm if (replaceIndex != std::string::npos) { fragmentShaderSource.replace(replaceIndex, PROCEDURAL_BLOCK.size(), _shaderSource.toLocal8Bit().data()); } - //qDebug() << "FragmentShader:\n" << fragmentShaderSource.c_str(); + + // Leave this here for debugging + // qDebug() << "FragmentShader:\n" << fragmentShaderSource.c_str(); + _fragmentShader = gpu::Shader::createPixel(fragmentShaderSource); _shader = gpu::Shader::createProgram(_vertexShader, _fragmentShader); From 2508b1412680aedffa7b0deb17d8e34ebe4e2fed Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 22:53:21 -0800 Subject: [PATCH 52/55] Workaround for scribe not scrubbing #else --- libraries/model/src/model/skybox.slf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/model/src/model/skybox.slf b/libraries/model/src/model/skybox.slf index 6eb3cf3963..7b25e36af7 100755 --- a/libraries/model/src/model/skybox.slf +++ b/libraries/model/src/model/skybox.slf @@ -39,6 +39,9 @@ void main(void) { color = pow(color, vec3(2.2)); _fragColor = vec4(color, 0.0); + // FIXME: scribe does not yet scrub out else statements + return; + #else vec3 coord = normalize(_normal); vec3 color = skybox.color.rgb; From 755efd1840ddac2b516706f6fd3943c9951537d1 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 23:03:03 -0800 Subject: [PATCH 53/55] Update test shaders --- tests/shaders/src/main.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/shaders/src/main.cpp b/tests/shaders/src/main.cpp index 82c5583f53..2bc957b2d1 100644 --- a/tests/shaders/src/main.cpp +++ b/tests/shaders/src/main.cpp @@ -72,8 +72,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -157,7 +157,7 @@ void QTestWindow::draw() { testShaderBuild(DrawTransformUnitQuad_vert, DrawTextureOpaque_frag); testShaderBuild(DrawTransformUnitQuad_vert, DrawColoredTexture_frag); - testShaderBuild(Skybox_vert, Skybox_frag); + testShaderBuild(skybox_vert, skybox_frag); testShaderBuild(simple_vert, simple_frag); testShaderBuild(simple_vert, simple_textured_frag); testShaderBuild(simple_vert, simple_textured_emisive_frag); @@ -203,8 +203,6 @@ void QTestWindow::draw() { testShaderBuild(overlay3D_vert, overlay3D_frag); - testShaderBuild(Skybox_vert, Skybox_frag); - testShaderBuild(paintStroke_vert,paintStroke_frag); testShaderBuild(polyvox_vert, polyvox_frag); From 729890342e5139304d2b4ddcdf2e13542ef5f045 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 11 Mar 2016 00:27:56 -0800 Subject: [PATCH 54/55] Fixing the linux warning for unused variable --- libraries/render/src/render/SpatialTree.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/render/src/render/SpatialTree.cpp b/libraries/render/src/render/SpatialTree.cpp index 484ec69e14..1bb3538521 100644 --- a/libraries/render/src/render/SpatialTree.cpp +++ b/libraries/render/src/render/SpatialTree.cpp @@ -422,7 +422,6 @@ int Octree::select(CellSelection& selection, const FrustumSelector& selector) co Index cellID = ROOT_CELL; auto cell = getConcreteCell(cellID); - auto cellLocation = cell.getlocation(); int numSelectedsIn = (int)selection.size(); // Always include the root cell partially containing potentially outer objects From 8281e1bc8ffabe4637494af132065d302b335220 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 11 Mar 2016 00:32:29 -0800 Subject: [PATCH 55/55] Obvioously, Austin was right, too many application.h... --- interface/src/ui/overlays/Base3DOverlay.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/ui/overlays/Base3DOverlay.cpp b/interface/src/ui/overlays/Base3DOverlay.cpp index 6f3ed55201..94533137ad 100644 --- a/interface/src/ui/overlays/Base3DOverlay.cpp +++ b/interface/src/ui/overlays/Base3DOverlay.cpp @@ -11,7 +11,6 @@ #include "Base3DOverlay.h" -#include "Application.h" #include #include #include "Application.h"