From b627a17ce911974bcb72ebeb7c24fc5c10abbf5a Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 12:58:49 -0800 Subject: [PATCH] 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); } } -