From d14ce8a9fe833b5ffc4b64a584b10e073e687fe1 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Tue, 2 Feb 2016 17:29:23 -0800 Subject: [PATCH 01/26] Pass an explicit pipeline to render.*Instance calls --- libraries/gpu/src/gpu/Batch.h | 2 + libraries/render-utils/src/GeometryCache.cpp | 86 +++++++++++-------- libraries/render-utils/src/GeometryCache.h | 49 +++++++---- .../render-utils/src/RenderPipelines.cpp | 22 ++--- libraries/render/src/render/DrawTask.cpp | 1 + libraries/render/src/render/ShapePipeline.cpp | 5 ++ libraries/render/src/render/ShapePipeline.h | 4 + tests/gpu-test/src/main.cpp | 1 + 8 files changed, 103 insertions(+), 67 deletions(-) diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index a2ee57759f..6b8816d50a 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -73,10 +73,12 @@ public: BufferPointers buffers; Function function; DrawCallInfoBuffer drawCallInfos; + Pipeline::Pointer pipeline; size_t count() const { return drawCallInfos.size(); } void process(Batch& batch) { + batch.setPipeline(pipeline); if (function) { function(batch, *this); } diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index aa82232524..7e34fff2cd 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -494,10 +494,22 @@ gpu::Stream::FormatPointer& getInstancedSolidStreamFormat() { return INSTANCED_SOLID_STREAM_FORMAT; } +render::ShapePipelinePointer GeometryCache::_simplePipeline; + GeometryCache::GeometryCache() : _nextID(0) { buildShapes(); + GeometryCache::_simplePipeline = + std::make_shared(getSimplePipeline(), nullptr, + [](const render::ShapePipeline&, gpu::Batch& batch) { + // Set the defaults needed for a simple program + batch.setResourceTexture(render::ShapePipeline::Slot::DIFFUSE_MAP, + DependencyManager::get()->getWhiteTexture()); + batch.setResourceTexture(render::ShapePipeline::Slot::NORMAL_FITTING_MAP, + DependencyManager::get()->getNormalFittingTexture()); + } + ); } GeometryCache::~GeometryCache() { @@ -1781,7 +1793,23 @@ inline bool operator==(const SimpleProgramKey& a, const SimpleProgramKey& b) { return a.getRaw() == b.getRaw(); } -gpu::PipelinePointer GeometryCache::getPipeline(SimpleProgramKey config) { +void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool culled, bool emissive, bool depthBiased) { + batch.setPipeline(getSimplePipeline(textured, culled, emissive, depthBiased)); + + // If not textured, set a default diffuse map + if (!textured) { + batch.setResourceTexture(render::ShapePipeline::Slot::DIFFUSE_MAP, + DependencyManager::get()->getWhiteTexture()); + } + // Set a default normal map + batch.setResourceTexture(render::ShapePipeline::Slot::NORMAL_FITTING_MAP, + DependencyManager::get()->getNormalFittingTexture()); +} + +gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool culled, bool emissive, bool depthBiased) { + SimpleProgramKey config{textured, culled, emissive, depthBiased}; + + // Compile the shaders static std::once_flag once; std::call_once(once, [&]() { auto VS = gpu::Shader::createVertex(std::string(simple_vert)); @@ -1796,13 +1824,14 @@ gpu::PipelinePointer GeometryCache::getPipeline(SimpleProgramKey config) { gpu::Shader::makeProgram(*_simpleShader, slotBindings); gpu::Shader::makeProgram(*_emissiveShader, slotBindings); }); - - + + // If the pipeline already exists, return it auto it = _simplePrograms.find(config); if (it != _simplePrograms.end()) { return it.value(); } - + + // If the pipeline did not exist, make it auto state = std::make_shared(); if (config.isCulled()) { state->setCullMode(gpu::State::CULL_BACK); @@ -1815,33 +1844,15 @@ gpu::PipelinePointer GeometryCache::getPipeline(SimpleProgramKey config) { state->setDepthBiasSlopeScale(1.0f); } state->setBlendFunction(false, - gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, - gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); - + gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, + gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); + gpu::ShaderPointer program = (config.isEmissive()) ? _emissiveShader : _simpleShader; gpu::PipelinePointer pipeline = gpu::Pipeline::create(program, state); _simplePrograms.insert(config, pipeline); return pipeline; } -gpu::PipelinePointer GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool culled, - bool emissive, bool depthBias) { - SimpleProgramKey config{textured, culled, emissive, depthBias}; - gpu::PipelinePointer pipeline = getPipeline(config); - batch.setPipeline(pipeline); - - gpu::ShaderPointer program = (config.isEmissive()) ? _emissiveShader : _simpleShader; - - if (!config.isTextured()) { - // If it is not textured, bind white texture and keep using textured pipeline - batch.setResourceTexture(0, DependencyManager::get()->getWhiteTexture()); - } - - batch.setResourceTexture(render::ShapePipeline::Slot::NORMAL_FITTING_MAP, - DependencyManager::get()->getNormalFittingTexture()); - return pipeline; -} - uint32_t toCompactColor(const glm::vec4& color) { uint32_t compactColor = ((int(color.x * 255.0f) & 0xFF)) | ((int(color.y * 255.0f) & 0xFF) << 8) | @@ -1853,30 +1864,30 @@ uint32_t toCompactColor(const glm::vec4& color) { static const size_t INSTANCE_COLOR_BUFFER = 0; template -void renderInstances(const std::string& name, gpu::Batch& batch, const glm::vec4& color, F f) { +void renderInstances(const std::string& name, gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline, F f) { { gpu::BufferPointer instanceColorBuffer = batch.getNamedBuffer(name, INSTANCE_COLOR_BUFFER); auto compactColor = toCompactColor(color); instanceColorBuffer->append(compactColor); } - batch.setupNamedCalls(name, [f](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { - DependencyManager::get()->bindSimpleProgram(batch); + batch.setupNamedCalls(name, [f, pipeline](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { + batch.setPipeline(pipeline->get(batch)); f(batch, data); }); } -void GeometryCache::renderSolidSphereInstance(gpu::Batch& batch, const glm::vec4& color) { +void GeometryCache::renderSolidSphereInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { static const std::string INSTANCE_NAME = __FUNCTION__; - renderInstances(INSTANCE_NAME, batch, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { + renderInstances(INSTANCE_NAME, batch, color, pipeline, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { DependencyManager::get()->renderShapeInstances(batch, GeometryCache::Sphere, data.count(), data.buffers[INSTANCE_COLOR_BUFFER]); }); } -void GeometryCache::renderWireSphereInstance(gpu::Batch& batch, const glm::vec4& color) { +void GeometryCache::renderWireSphereInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { static const std::string INSTANCE_NAME = __FUNCTION__; - renderInstances(INSTANCE_NAME, batch, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { + renderInstances(INSTANCE_NAME, batch, color, pipeline, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { DependencyManager::get()->renderWireShapeInstances(batch, GeometryCache::Sphere, data.count(), data.buffers[INSTANCE_COLOR_BUFFER]); }); @@ -1886,12 +1897,12 @@ void GeometryCache::renderWireSphereInstance(gpu::Batch& batch, const glm::vec4& // available shape types, both solid and wireframes //#define DEBUG_SHAPES -void GeometryCache::renderSolidCubeInstance(gpu::Batch& batch, const glm::vec4& color) { +void GeometryCache::renderSolidCubeInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { static const std::string INSTANCE_NAME = __FUNCTION__; #ifdef DEBUG_SHAPES static auto startTime = usecTimestampNow(); - renderInstances(INSTANCE_NAME, batch, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { + renderInstances(INSTANCE_NAME, batch, color, pipeline, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { auto usecs = usecTimestampNow(); usecs -= startTime; @@ -1924,18 +1935,17 @@ void GeometryCache::renderSolidCubeInstance(gpu::Batch& batch, const glm::vec4& } }); #else - renderInstances(INSTANCE_NAME, batch, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { + renderInstances(INSTANCE_NAME, batch, color, pipeline, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { DependencyManager::get()->renderCubeInstances(batch, data.count(), data.buffers[INSTANCE_COLOR_BUFFER]); }); #endif } -void GeometryCache::renderWireCubeInstance(gpu::Batch& batch, const glm::vec4& color) { +void GeometryCache::renderWireCubeInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { static const std::string INSTANCE_NAME = __FUNCTION__; - renderInstances(INSTANCE_NAME, batch, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { + renderInstances(INSTANCE_NAME, batch, color, pipeline, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { DependencyManager::get()->renderWireCubeInstances(batch, data.count(), data.buffers[INSTANCE_COLOR_BUFFER]); }); } - diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 81b8dfb325..5de08ea717 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -150,31 +150,44 @@ public: static const int UNKNOWN_ID; - /// Sets up the state necessary to render static untextured geometry with the simple program. - gpu::PipelinePointer bindSimpleProgram(gpu::Batch& batch, bool textured = false, bool culled = true, - bool emissive = false, bool depthBias = false); + // Bind the pipeline and get the state to render static geometry + void bindSimpleProgram(gpu::Batch& batch, bool textured = false, bool culled = true, + bool emissive = false, bool depthBias = false); + // Get the pipeline to render static geometry + gpu::PipelinePointer getSimplePipeline(bool textured = false, bool culled = true, + bool emissive = false, bool depthBias = false); + render::ShapePipelinePointer getShapePipeline() { return GeometryCache::_simplePipeline; } - void renderSolidSphereInstance(gpu::Batch& batch, const glm::vec4& color); - void renderSolidSphereInstance(gpu::Batch& batch, const glm::vec3& color) { - renderSolidSphereInstance(batch, glm::vec4(color, 1.0)); + // Static geometry + void renderSolidSphereInstance(gpu::Batch& batch, const glm::vec4& color, + const render::ShapePipelinePointer& pipeline = _simplePipeline); + void renderSolidSphereInstance(gpu::Batch& batch, const glm::vec3& color, + const render::ShapePipelinePointer& pipeline = _simplePipeline) { + renderSolidSphereInstance(batch, glm::vec4(color, 1.0), pipeline); } - void renderWireSphereInstance(gpu::Batch& batch, const glm::vec4& color); - void renderWireSphereInstance(gpu::Batch& batch, const glm::vec3& color) { - renderWireSphereInstance(batch, glm::vec4(color, 1.0)); + void renderWireSphereInstance(gpu::Batch& batch, const glm::vec4& color, + const render::ShapePipelinePointer& pipeline = _simplePipeline); + void renderWireSphereInstance(gpu::Batch& batch, const glm::vec3& color, + const render::ShapePipelinePointer& pipeline = _simplePipeline) { + renderWireSphereInstance(batch, glm::vec4(color, 1.0), pipeline); } - void renderSolidCubeInstance(gpu::Batch& batch, const glm::vec4& color); - void renderSolidCubeInstance(gpu::Batch& batch, const glm::vec3& color) { - renderSolidCubeInstance(batch, glm::vec4(color, 1.0)); + void renderSolidCubeInstance(gpu::Batch& batch, const glm::vec4& color, + const render::ShapePipelinePointer& pipeline = _simplePipeline); + void renderSolidCubeInstance(gpu::Batch& batch, const glm::vec3& color, + const render::ShapePipelinePointer& pipeline = _simplePipeline) { + renderSolidCubeInstance(batch, glm::vec4(color, 1.0), pipeline); } - void renderWireCubeInstance(gpu::Batch& batch, const glm::vec4& color); - void renderWireCubeInstance(gpu::Batch& batch, const glm::vec3& color) { - renderWireCubeInstance(batch, glm::vec4(color, 1.0)); + void renderWireCubeInstance(gpu::Batch& batch, const glm::vec4& color, + const render::ShapePipelinePointer& pipeline = _simplePipeline); + void renderWireCubeInstance(gpu::Batch& batch, const glm::vec3& color, + const render::ShapePipelinePointer& pipeline = _simplePipeline) { + renderWireCubeInstance(batch, glm::vec4(color, 1.0), pipeline); } - + // Dynamic geometry void renderShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& colorBuffer); void renderWireShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& colorBuffer); void renderShape(gpu::Batch& batch, Shape shape); @@ -364,11 +377,9 @@ private: QHash > _networkGeometry; - - gpu::PipelinePointer getPipeline(SimpleProgramKey config); - gpu::ShaderPointer _simpleShader; gpu::ShaderPointer _emissiveShader; + static render::ShapePipelinePointer _simplePipeline; QHash _simplePrograms; }; diff --git a/libraries/render-utils/src/RenderPipelines.cpp b/libraries/render-utils/src/RenderPipelines.cpp index d2e880aea3..2dfe5d8828 100644 --- a/libraries/render-utils/src/RenderPipelines.cpp +++ b/libraries/render-utils/src/RenderPipelines.cpp @@ -58,6 +58,15 @@ void initStencilPipeline(gpu::PipelinePointer& pipeline) { pipeline = gpu::Pipeline::create(program, state); } +void batchSetter(const ShapePipeline& pipeline, gpu::Batch& batch) { + // Set a default diffuse map + batch.setResourceTexture(render::ShapePipeline::Slot::DIFFUSE_MAP, + DependencyManager::get()->getWhiteTexture()); + // Set a default normal map + batch.setResourceTexture(render::ShapePipeline::Slot::NORMAL_FITTING_MAP, + DependencyManager::get()->getNormalFittingTexture()); +} + void initOverlay3DPipelines(ShapePlumber& plumber) { auto vs = gpu::Shader::createVertex(std::string(overlay3D_vert)); auto ps = gpu::Shader::createPixel(std::string(overlay3D_frag)); @@ -67,14 +76,7 @@ void initOverlay3DPipelines(ShapePlumber& plumber) { opaqueState->setDepthTest(false); opaqueState->setBlendFunction(false); - plumber.addPipeline(ShapeKey::Filter::Builder().withOpaque(), program, opaqueState); -} - -void pipelineBatchSetter(const ShapePipeline& pipeline, gpu::Batch& batch) { - if (pipeline.locations->normalFittingMapUnit > -1) { - batch.setResourceTexture(pipeline.locations->normalFittingMapUnit, - DependencyManager::get()->getNormalFittingTexture()); - } + plumber.addPipeline(ShapeKey::Filter::Builder().withOpaque(), program, opaqueState, &batchSetter); } void initDeferredPipelines(render::ShapePlumber& plumber) { @@ -97,7 +99,7 @@ void initDeferredPipelines(render::ShapePlumber& plumber) { gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); ShaderPointer program = gpu::Shader::createProgram(vertexShader, pixelShader); - plumber.addPipeline(key, program, state, &pipelineBatchSetter); + plumber.addPipeline(key, program, state, &batchSetter); // Add a wireframe version if (!key.isWireFrame()) { @@ -106,7 +108,7 @@ void initDeferredPipelines(render::ShapePlumber& plumber) { wireFrameState->setFillMode(gpu::State::FILL_LINE); - plumber.addPipeline(wireFrameKey, program, wireFrameState, &pipelineBatchSetter); + plumber.addPipeline(wireFrameKey, program, wireFrameState, &batchSetter); } }; diff --git a/libraries/render/src/render/DrawTask.cpp b/libraries/render/src/render/DrawTask.cpp index 455a420355..bb31792c4b 100755 --- a/libraries/render/src/render/DrawTask.cpp +++ b/libraries/render/src/render/DrawTask.cpp @@ -143,6 +143,7 @@ void renderShape(RenderArgs* args, const ShapePlumberPointer& shapeContext, cons if (args->_pipeline) { item.render(args); } + args->_pipeline = nullptr; } else if (key.hasOwnPipeline()) { item.render(args); } else { diff --git a/libraries/render/src/render/ShapePipeline.cpp b/libraries/render/src/render/ShapePipeline.cpp index c83f16c456..d6f3c86540 100644 --- a/libraries/render/src/render/ShapePipeline.cpp +++ b/libraries/render/src/render/ShapePipeline.cpp @@ -22,6 +22,11 @@ ShapeKey::Filter::Builder::Builder() { _mask.set(INVALID); } +gpu::PipelinePointer ShapePipeline::get(gpu::Batch& batch) { + batchSetter(*this, batch); + return this->pipeline; +} + void ShapePlumber::addPipelineHelper(const Filter& filter, ShapeKey key, int bit, const PipelinePointer& pipeline) { // Iterate over all keys if (bit < (int)ShapeKey::FlagBit::NUM_FLAGS) { diff --git a/libraries/render/src/render/ShapePipeline.h b/libraries/render/src/render/ShapePipeline.h index 1a6837efa3..6ea9ea1c72 100644 --- a/libraries/render/src/render/ShapePipeline.h +++ b/libraries/render/src/render/ShapePipeline.h @@ -209,6 +209,10 @@ public: ShapePipeline(gpu::PipelinePointer pipeline, LocationsPointer locations, BatchSetter batchSetter) : pipeline(pipeline), locations(locations), batchSetter(batchSetter) {} + // Normally, a pipeline is accessed thorugh pickPipeline. If it needs to be accessed manually, + // this method preps the pipeline with defaults set by its batchSetter and returns only the gpu::Pipeline. + gpu::PipelinePointer get(gpu::Batch& batch); + gpu::PipelinePointer pipeline; std::shared_ptr locations; diff --git a/tests/gpu-test/src/main.cpp b/tests/gpu-test/src/main.cpp index b1ca3d0448..87ce2d7622 100644 --- a/tests/gpu-test/src/main.cpp +++ b/tests/gpu-test/src/main.cpp @@ -239,6 +239,7 @@ public: } } + auto pipeline = geometryCache->getSimplePipeline(); for (auto& transform : transforms) { batch.setModelTransform(transform); batch.setupNamedCalls(GRID_INSTANCE, [=](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { From a790b098924513747710c28ef16c5c824d1c7126 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 3 Feb 2016 11:34:18 -0800 Subject: [PATCH 02/26] Supply normals to GeometryCache draw calls --- libraries/render-utils/src/GeometryCache.cpp | 126 ++++++++++++++----- 1 file changed, 95 insertions(+), 31 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 7e34fff2cd..3d0b68abeb 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -477,6 +477,7 @@ void GeometryCache::buildShapes() { gpu::Stream::FormatPointer& getSolidStreamFormat() { if (!SOLID_STREAM_FORMAT) { + const int VERTEX_NORMAL_OFFSET = POSITION_ELEMENT.getSize(); SOLID_STREAM_FORMAT = std::make_shared(); // 1 for everyone SOLID_STREAM_FORMAT->setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, POSITION_ELEMENT); SOLID_STREAM_FORMAT->setAttribute(gpu::Stream::NORMAL, gpu::Stream::NORMAL, NORMAL_ELEMENT); @@ -486,6 +487,7 @@ gpu::Stream::FormatPointer& getSolidStreamFormat() { gpu::Stream::FormatPointer& getInstancedSolidStreamFormat() { if (!INSTANCED_SOLID_STREAM_FORMAT) { + const int VERTEX_NORMAL_OFFSET = POSITION_ELEMENT.getSize(); INSTANCED_SOLID_STREAM_FORMAT = std::make_shared(); // 1 for everyone INSTANCED_SOLID_STREAM_FORMAT->setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, POSITION_ELEMENT); INSTANCED_SOLID_STREAM_FORMAT->setAttribute(gpu::Stream::NORMAL, gpu::Stream::NORMAL, NORMAL_ELEMENT); @@ -768,7 +770,9 @@ void GeometryCache::updateVertices(int id, const QVector& points, con #endif // def WANT_DEBUG } - const int FLOATS_PER_VERTEX = 2; + const int FLOATS_PER_VERTEX = 2 + 3; // vertices + normals + const int NUM_POS_COORDS = 2; + const int VERTEX_NORMAL_OFFSET = NUM_POS_COORDS * sizeof(float); details.isCreated = true; details.vertices = points.size(); details.vertexSize = FLOATS_PER_VERTEX; @@ -784,6 +788,7 @@ void GeometryCache::updateVertices(int id, const QVector& points, con details.stream = stream; details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::NORMAL, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), VERTEX_NORMAL_OFFSET); details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA)); details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); @@ -803,9 +808,13 @@ void GeometryCache::updateVertices(int id, const QVector& points, con int* colorData = new int[details.vertices]; int* colorDataAt = colorData; + const glm::vec3 NORMAL(0.0f, 0.0f, 1.0f); foreach (const glm::vec2& point, points) { *(vertex++) = point.x; *(vertex++) = point.y; + *(vertex++) = NORMAL.x; + *(vertex++) = NORMAL.y; + *(vertex++) = NORMAL.z; *(colorDataAt++) = compactColor; } @@ -829,7 +838,9 @@ void GeometryCache::updateVertices(int id, const QVector& points, con #endif // def WANT_DEBUG } - const int FLOATS_PER_VERTEX = 3; + const int FLOATS_PER_VERTEX = 3 + 3; // vertices + normals + const int NUM_POS_COORDS = 3; + const int VERTEX_NORMAL_OFFSET = NUM_POS_COORDS * sizeof(float); details.isCreated = true; details.vertices = points.size(); details.vertexSize = FLOATS_PER_VERTEX; @@ -845,6 +856,7 @@ void GeometryCache::updateVertices(int id, const QVector& points, con details.stream = stream; details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::NORMAL, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), VERTEX_NORMAL_OFFSET); details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA)); details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); @@ -864,10 +876,14 @@ void GeometryCache::updateVertices(int id, const QVector& points, con int* colorData = new int[details.vertices]; int* colorDataAt = colorData; + const glm::vec3 NORMAL(0.0f, 0.0f, 1.0f); foreach (const glm::vec3& point, points) { *(vertex++) = point.x; *(vertex++) = point.y; *(vertex++) = point.z; + *(vertex++) = NORMAL.x; + *(vertex++) = NORMAL.y; + *(vertex++) = NORMAL.z; *(colorDataAt++) = compactColor; } @@ -892,7 +908,11 @@ void GeometryCache::updateVertices(int id, const QVector& points, con #endif // def WANT_DEBUG } - const int FLOATS_PER_VERTEX = 5; + const int FLOATS_PER_VERTEX = 3 + 3 + 2; // vertices + normals + tex coords + const int NUM_POS_COORDS = 3; + const int NUM_NORMAL_COORDS = 3; + const int VERTEX_NORMAL_OFFSET = NUM_POS_COORDS * sizeof(float); + const int VERTEX_TEX_OFFSET = VERTEX_NORMAL_OFFSET + NUM_NORMAL_COORDS * sizeof(float); details.isCreated = true; details.vertices = points.size(); details.vertexSize = FLOATS_PER_VERTEX; @@ -908,7 +928,8 @@ void GeometryCache::updateVertices(int id, const QVector& points, con details.stream = stream; details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0); - details.streamFormat->setAttribute(gpu::Stream::TEXCOORD, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::UV), 3 * sizeof(float)); + details.streamFormat->setAttribute(gpu::Stream::NORMAL, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), VERTEX_NORMAL_OFFSET); + details.streamFormat->setAttribute(gpu::Stream::TEXCOORD, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::UV), VERTEX_TEX_OFFSET); details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA)); details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); @@ -930,12 +951,16 @@ void GeometryCache::updateVertices(int id, const QVector& points, con int* colorData = new int[details.vertices]; int* colorDataAt = colorData; + const glm::vec3 NORMAL(0.0f, 0.0f, 1.0f); for (int i = 0; i < points.size(); i++) { glm::vec3 point = points[i]; glm::vec2 texCoord = texCoords[i]; *(vertex++) = point.x; *(vertex++) = point.y; *(vertex++) = point.z; + *(vertex++) = NORMAL.x; + *(vertex++) = NORMAL.y; + *(vertex++) = NORMAL.z; *(vertex++) = texCoord.x; *(vertex++) = texCoord.y; @@ -1085,8 +1110,10 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, co #endif // def WANT_DEBUG } - const int FLOATS_PER_VERTEX = 2; // vertices + const int FLOATS_PER_VERTEX = 2 + 3; // vertices + normals const int VERTICES = 4; // 1 quad = 4 vertices + const int NUM_POS_COORDS = 2; + const int VERTEX_NORMAL_OFFSET = NUM_POS_COORDS * sizeof(float); if (!details.isCreated) { @@ -1105,17 +1132,19 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, co details.stream = stream; details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::NORMAL, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), VERTEX_NORMAL_OFFSET); details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA)); details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride); + const glm::vec3 NORMAL(0.0f, 0.0f, 1.0f); float vertexBuffer[VERTICES * FLOATS_PER_VERTEX] = { - minCorner.x, minCorner.y, - maxCorner.x, minCorner.y, - minCorner.x, maxCorner.y, - maxCorner.x, maxCorner.y, + minCorner.x, minCorner.y, NORMAL.x, NORMAL.y, NORMAL.z, + maxCorner.x, minCorner.y, NORMAL.x, NORMAL.y, NORMAL.z, + minCorner.x, maxCorner.y, NORMAL.x, NORMAL.y, NORMAL.z, + maxCorner.x, maxCorner.y, NORMAL.x, NORMAL.y, NORMAL.z, }; const int NUM_COLOR_SCALARS_PER_QUAD = 4; @@ -1170,10 +1199,12 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, co #endif // def WANT_DEBUG } - const int FLOATS_PER_VERTEX = 2 * 2; // text coords & vertices + const int FLOATS_PER_VERTEX = 2 + 3 + 2; // vertices + normals + tex coords const int VERTICES = 4; // 1 quad = 4 vertices const int NUM_POS_COORDS = 2; - const int VERTEX_TEXCOORD_OFFSET = NUM_POS_COORDS * sizeof(float); + const int NUM_NORMAL_COORDS = 3; + const int VERTEX_NORMAL_OFFSET = NUM_POS_COORDS * sizeof(float); + const int VERTEX_TEXCOORD_OFFSET = VERTEX_NORMAL_OFFSET + NUM_NORMAL_COORDS * sizeof(float); if (!details.isCreated) { @@ -1193,7 +1224,9 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, co details.streamFormat = streamFormat; details.stream = stream; + // zzmp: fix the normal across all renderQuad details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::NORMAL, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), VERTEX_NORMAL_OFFSET); details.streamFormat->setAttribute(gpu::Stream::TEXCOORD, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::UV), VERTEX_TEXCOORD_OFFSET); details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA)); @@ -1201,11 +1234,12 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, co details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride); + const glm::vec3 NORMAL(0.0f, 0.0f, 1.0f); float vertexBuffer[VERTICES * FLOATS_PER_VERTEX] = { - minCorner.x, minCorner.y, texCoordMinCorner.x, texCoordMinCorner.y, - maxCorner.x, minCorner.y, texCoordMaxCorner.x, texCoordMinCorner.y, - minCorner.x, maxCorner.y, texCoordMinCorner.x, texCoordMaxCorner.y, - maxCorner.x, maxCorner.y, texCoordMaxCorner.x, texCoordMaxCorner.y, + minCorner.x, minCorner.y, NORMAL.x, NORMAL.y, NORMAL.z, texCoordMinCorner.x, texCoordMinCorner.y, + maxCorner.x, minCorner.y, NORMAL.x, NORMAL.y, NORMAL.z, texCoordMaxCorner.x, texCoordMinCorner.y, + minCorner.x, maxCorner.y, NORMAL.x, NORMAL.y, NORMAL.z, texCoordMinCorner.x, texCoordMaxCorner.y, + maxCorner.x, maxCorner.y, NORMAL.x, NORMAL.y, NORMAL.z, texCoordMaxCorner.x, texCoordMaxCorner.y, }; @@ -1247,8 +1281,10 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec3& minCorner, co #endif // def WANT_DEBUG } - const int FLOATS_PER_VERTEX = 3; // vertices + const int FLOATS_PER_VERTEX = 3 + 3; // vertices + normals const int VERTICES = 4; // 1 quad = 4 vertices + const int NUM_POS_COORDS = 3; + const int VERTEX_NORMAL_OFFSET = NUM_POS_COORDS * sizeof(float); if (!details.isCreated) { @@ -1269,17 +1305,19 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec3& minCorner, co details.stream = stream; details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::NORMAL, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), VERTEX_NORMAL_OFFSET); details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA)); details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride); + const glm::vec3 NORMAL(0.0f, 0.0f, 1.0f); float vertexBuffer[VERTICES * FLOATS_PER_VERTEX] = { - minCorner.x, minCorner.y, minCorner.z, - maxCorner.x, minCorner.y, minCorner.z, - minCorner.x, maxCorner.y, maxCorner.z, - maxCorner.x, maxCorner.y, maxCorner.z, + minCorner.x, minCorner.y, minCorner.z, NORMAL.x, NORMAL.y, NORMAL.z, + maxCorner.x, minCorner.y, minCorner.z, NORMAL.x, NORMAL.y, NORMAL.z, + minCorner.x, maxCorner.y, maxCorner.z, NORMAL.x, NORMAL.y, NORMAL.z, + maxCorner.x, maxCorner.y, maxCorner.z, NORMAL.x, NORMAL.y, NORMAL.z, }; const int NUM_COLOR_SCALARS_PER_QUAD = 4; @@ -1339,10 +1377,13 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec3& topLeft, cons #endif // def WANT_DEBUG } - const int FLOATS_PER_VERTEX = 3 + 2; // 3d vertices + text coords + const int FLOATS_PER_VERTEX = 3 + 3 + 2; // vertices + normals + tex coords const int VERTICES = 4; // 1 quad = 4 vertices const int NUM_POS_COORDS = 3; - const int VERTEX_TEXCOORD_OFFSET = NUM_POS_COORDS * sizeof(float); + const int NUM_NORMAL_COORDS = 3; + const int VERTEX_NORMAL_OFFSET = NUM_POS_COORDS * sizeof(float); + const int VERTEX_TEXCOORD_OFFSET = VERTEX_NORMAL_OFFSET + NUM_NORMAL_COORDS * sizeof(float); + if (!details.isCreated) { @@ -1361,6 +1402,7 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec3& topLeft, cons details.stream = stream; details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::NORMAL, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), VERTEX_NORMAL_OFFSET); details.streamFormat->setAttribute(gpu::Stream::TEXCOORD, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::UV), VERTEX_TEXCOORD_OFFSET); details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA)); @@ -1368,12 +1410,13 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec3& topLeft, cons details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride); + const glm::vec3 NORMAL(0.0f, 0.0f, 1.0f); float vertexBuffer[VERTICES * FLOATS_PER_VERTEX] = { - bottomLeft.x, bottomLeft.y, bottomLeft.z, texCoordBottomLeft.x, texCoordBottomLeft.y, - bottomRight.x, bottomRight.y, bottomRight.z, texCoordBottomRight.x, texCoordBottomRight.y, - topLeft.x, topLeft.y, topLeft.z, texCoordTopLeft.x, texCoordTopLeft.y, - topRight.x, topRight.y, topRight.z, texCoordTopRight.x, texCoordTopRight.y, - }; + bottomLeft.x, bottomLeft.y, bottomLeft.z, NORMAL.x, NORMAL.y, NORMAL.z, texCoordBottomLeft.x, texCoordBottomLeft.y, + bottomRight.x, bottomRight.y, bottomRight.z, NORMAL.x, NORMAL.y, NORMAL.z, texCoordBottomRight.x, texCoordBottomRight.y, + topLeft.x, topLeft.y, topLeft.z, NORMAL.x, NORMAL.y, NORMAL.z, texCoordTopLeft.x, texCoordTopLeft.y, + topRight.x, topRight.y, topRight.z, NORMAL.x, NORMAL.y, NORMAL.z, texCoordTopRight.x, texCoordTopRight.y, + }; const int NUM_COLOR_SCALARS_PER_QUAD = 4; int compactColor = ((int(color.x * 255.0f) & 0xFF)) | @@ -1426,7 +1469,9 @@ void GeometryCache::renderDashedLine(gpu::Batch& batch, const glm::vec3& start, glm::vec3 dashVector = segmentVector / SEGMENT_LENGTH * dash_length; glm::vec3 gapVector = segmentVector / SEGMENT_LENGTH * gap_length; - const int FLOATS_PER_VERTEX = 3; + const int FLOATS_PER_VERTEX = 3 + 3; // vertices + normals + const int NUM_POS_COORDS = 3; + const int VERTEX_NORMAL_OFFSET = NUM_POS_COORDS * sizeof(float); details.vertices = (segmentCountFloor + 1) * 2; details.vertexSize = FLOATS_PER_VERTEX; details.isCreated = true; @@ -1442,6 +1487,7 @@ void GeometryCache::renderDashedLine(gpu::Batch& batch, const glm::vec3& start, details.stream = stream; details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::NORMAL, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), VERTEX_NORMAL_OFFSET); details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA)); details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); @@ -1453,10 +1499,14 @@ void GeometryCache::renderDashedLine(gpu::Batch& batch, const glm::vec3& start, float* vertexData = new float[details.vertices * FLOATS_PER_VERTEX]; float* vertex = vertexData; + const glm::vec3 NORMAL(1.0f, 0.0f, 0.0f); glm::vec3 point = start; *(vertex++) = point.x; *(vertex++) = point.y; *(vertex++) = point.z; + *(vertex++) = NORMAL.x; + *(vertex++) = NORMAL.y; + *(vertex++) = NORMAL.z; *(colorDataAt++) = compactColor; for (int i = 0; i < segmentCountFloor; i++) { @@ -1464,17 +1514,26 @@ void GeometryCache::renderDashedLine(gpu::Batch& batch, const glm::vec3& start, *(vertex++) = point.x; *(vertex++) = point.y; *(vertex++) = point.z; + *(vertex++) = NORMAL.x; + *(vertex++) = NORMAL.y; + *(vertex++) = NORMAL.z; *(colorDataAt++) = compactColor; point += gapVector; *(vertex++) = point.x; *(vertex++) = point.y; *(vertex++) = point.z; + *(vertex++) = NORMAL.x; + *(vertex++) = NORMAL.y; + *(vertex++) = NORMAL.z; *(colorDataAt++) = compactColor; } *(vertex++) = end.x; *(vertex++) = end.y; *(vertex++) = end.z; + *(vertex++) = NORMAL.x; + *(vertex++) = NORMAL.y; + *(vertex++) = NORMAL.z; *(colorDataAt++) = compactColor; details.verticesBuffer->append(sizeof(float) * FLOATS_PER_VERTEX * details.vertices, (gpu::Byte*) vertexData); @@ -1581,7 +1640,9 @@ void GeometryCache::renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm #endif // def WANT_DEBUG } - const int FLOATS_PER_VERTEX = 3; + const int FLOATS_PER_VERTEX = 3 + 3; // vertices + normals + const int NUM_POS_COORDS = 3; + const int VERTEX_NORMAL_OFFSET = NUM_POS_COORDS * sizeof(float); const int vertices = 2; if (!details.isCreated) { @@ -1600,13 +1661,16 @@ void GeometryCache::renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm details.stream = stream; details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::NORMAL, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), VERTEX_NORMAL_OFFSET); details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA)); details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride); - - float vertexBuffer[vertices * FLOATS_PER_VERTEX] = { p1.x, p1.y, p1.z, p2.x, p2.y, p2.z }; + const glm::vec3 NORMAL(1.0f, 0.0f, 0.0f); + float vertexBuffer[vertices * FLOATS_PER_VERTEX] = { + p1.x, p1.y, p1.z, NORMAL.x, NORMAL.y, NORMAL.z, + p2.x, p2.y, p2.z, NORMAL.x, NORMAL.y, NORMAL.z}; const int NUM_COLOR_SCALARS = 2; int colors[NUM_COLOR_SCALARS] = { compactColor1, compactColor2 }; From 127f9694f6fac5fe7e4e0905cc4b5f3a0faadcfd Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Tue, 2 Feb 2016 19:28:44 -0800 Subject: [PATCH 03/26] Fix ordering of batchSetter in pickPipeline --- libraries/render/src/render/ShapePipeline.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/render/src/render/ShapePipeline.cpp b/libraries/render/src/render/ShapePipeline.cpp index d6f3c86540..9108d31757 100644 --- a/libraries/render/src/render/ShapePipeline.cpp +++ b/libraries/render/src/render/ShapePipeline.cpp @@ -95,13 +95,13 @@ const ShapePipelinePointer ShapePlumber::pickPipeline(RenderArgs* args, const Ke PipelinePointer shapePipeline(pipelineIterator->second); auto& batch = args->_batch; + // Setup the one pipeline (to rule them all) + batch->setPipeline(shapePipeline->pipeline); + // Run the pipeline's BatchSetter on the passed in batch if (shapePipeline->batchSetter) { shapePipeline->batchSetter(*shapePipeline, *batch); } - // Setup the one pipeline (to rule them all) - batch->setPipeline(shapePipeline->pipeline); - return shapePipeline; } From 9af7dc9c3e22a8b8f57f1018e633c8b61b8e705d Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 1 Feb 2016 19:48:55 -0800 Subject: [PATCH 04/26] Add layering to text renderer --- libraries/render-utils/src/TextRenderer3D.cpp | 4 ++-- libraries/render-utils/src/TextRenderer3D.h | 2 +- libraries/render-utils/src/text/Font.cpp | 8 ++++++-- libraries/render-utils/src/text/Font.h | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libraries/render-utils/src/TextRenderer3D.cpp b/libraries/render-utils/src/TextRenderer3D.cpp index 6d10ed7069..81e9378815 100644 --- a/libraries/render-utils/src/TextRenderer3D.cpp +++ b/libraries/render-utils/src/TextRenderer3D.cpp @@ -72,12 +72,12 @@ float TextRenderer3D::getFontSize() const { } void TextRenderer3D::draw(gpu::Batch& batch, float x, float y, const QString& str, const glm::vec4& color, - const glm::vec2& bounds) { + const glm::vec2& bounds, bool layered) { // The font does all the OpenGL work if (_font) { // Cache color so that the pointer stays valid. _color = color; - _font->drawString(batch, x, y, str, &_color, _effectType, bounds); + _font->drawString(batch, x, y, str, &_color, _effectType, bounds, layered); } } diff --git a/libraries/render-utils/src/TextRenderer3D.h b/libraries/render-utils/src/TextRenderer3D.h index ea230016f2..9d48ca1a6c 100644 --- a/libraries/render-utils/src/TextRenderer3D.h +++ b/libraries/render-utils/src/TextRenderer3D.h @@ -40,7 +40,7 @@ public: float getFontSize() const; // Pixel size void draw(gpu::Batch& batch, float x, float y, const QString& str, const glm::vec4& color = glm::vec4(1.0f), - const glm::vec2& bounds = glm::vec2(-1.0f)); + const glm::vec2& bounds = glm::vec2(-1.0f), bool layered = false); private: TextRenderer3D(const char* family, float pointSize, int weight = -1, bool italic = false, diff --git a/libraries/render-utils/src/text/Font.cpp b/libraries/render-utils/src/text/Font.cpp index 43202c29c2..2e86d09fe0 100644 --- a/libraries/render-utils/src/text/Font.cpp +++ b/libraries/render-utils/src/text/Font.cpp @@ -234,6 +234,10 @@ void Font::setupGPU() { gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); _pipeline = gpu::Pipeline::create(program, state); + + auto layeredState = std::make_shared(state->getValues()); + layeredState->setDepthTest(false); + _layeredPipeline = gpu::Pipeline::create(program, layeredState); } // Sanity checks @@ -336,7 +340,7 @@ void Font::rebuildVertices(float x, float y, const QString& str, const glm::vec2 } void Font::drawString(gpu::Batch& batch, float x, float y, const QString& str, const glm::vec4* color, - EffectType effectType, const glm::vec2& bounds) { + EffectType effectType, const glm::vec2& bounds, bool layered) { if (str == "") { return; } @@ -347,7 +351,7 @@ void Font::drawString(gpu::Batch& batch, float x, float y, const QString& str, c setupGPU(); - batch.setPipeline(_pipeline); + batch.setPipeline(layered ? _layeredPipeline : _pipeline); batch.setResourceTexture(_fontLoc, _texture); batch._glUniform1i(_outlineLoc, (effectType == OUTLINE_EFFECT)); batch._glUniform4fv(_colorLoc, 1, (const float*)color); diff --git a/libraries/render-utils/src/text/Font.h b/libraries/render-utils/src/text/Font.h index e10360d45f..351bc63163 100644 --- a/libraries/render-utils/src/text/Font.h +++ b/libraries/render-utils/src/text/Font.h @@ -27,7 +27,7 @@ public: // Render string to batch void drawString(gpu::Batch& batch, float x, float y, const QString& str, const glm::vec4* color, EffectType effectType, - const glm::vec2& bound); + const glm::vec2& bound, bool layered = false); static Font* load(QIODevice& fontFile); static Font* load(const QString& family); @@ -61,6 +61,7 @@ private: // gpu structures gpu::PipelinePointer _pipeline; + gpu::PipelinePointer _layeredPipeline; gpu::TexturePointer _texture; gpu::Stream::FormatPointer _format; gpu::BufferPointer _verticesBuffer; From 60f3ee5a1823337951fc347b0d81207ca7696362 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 3 Feb 2016 15:07:46 -0800 Subject: [PATCH 05/26] Initialize Volume3dOverlay to a valid scale --- interface/src/ui/overlays/Volume3DOverlay.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/ui/overlays/Volume3DOverlay.h b/interface/src/ui/overlays/Volume3DOverlay.h index 1608e99b35..5756b6549a 100644 --- a/interface/src/ui/overlays/Volume3DOverlay.h +++ b/interface/src/ui/overlays/Volume3DOverlay.h @@ -34,7 +34,7 @@ public: protected: // Centered local bounding box - AABox _localBoundingBox; + AABox _localBoundingBox{ vec3(0.0f), 1.0f }; }; From 399fe95dc926ee2d8a55c546bbbc8f6a5adea523 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 3 Feb 2016 14:14:56 -0800 Subject: [PATCH 06/26] Update overlay/emissive shaders --- libraries/render-utils/src/model.slv | 2 + libraries/render-utils/src/model_emissive.slf | 38 +++++++++++ .../render-utils/src/model_translucent.slf | 41 +++--------- .../src/model_translucent_emissive.slf | 33 ++++++++++ libraries/render-utils/src/overlay3D.slf | 58 +++++++++++++--- libraries/render-utils/src/overlay3D.slv | 23 +++---- .../render-utils/src/overlay3D_emissive.slf | 29 ++++++++ .../src/overlay3D_translucent.slf | 66 +++++++++++++++++++ .../src/overlay3D_translucent_emissive.slf | 27 ++++++++ 9 files changed, 262 insertions(+), 55 deletions(-) create mode 100644 libraries/render-utils/src/model_emissive.slf create mode 100644 libraries/render-utils/src/model_translucent_emissive.slf create mode 100644 libraries/render-utils/src/overlay3D_emissive.slf create mode 100644 libraries/render-utils/src/overlay3D_translucent.slf create mode 100644 libraries/render-utils/src/overlay3D_translucent_emissive.slf diff --git a/libraries/render-utils/src/model.slv b/libraries/render-utils/src/model.slv index 47de20a5d9..d2f45ec66a 100755 --- a/libraries/render-utils/src/model.slv +++ b/libraries/render-utils/src/model.slv @@ -23,11 +23,13 @@ uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; out vec4 _position; out vec3 _normal; out vec3 _color; +out float _alpha; out vec2 _texCoord0; void main(void) { // pass along the diffuse color in linear space _color = colorToLinearRGB(inColor.xyz); + _alpha = inColor.w; // and the texture coordinates _texCoord0 = (texcoordMatrices[0] * vec4(inTexCoord0.st, 0.0, 1.0)).st; diff --git a/libraries/render-utils/src/model_emissive.slf b/libraries/render-utils/src/model_emissive.slf new file mode 100644 index 0000000000..25239691cd --- /dev/null +++ b/libraries/render-utils/src/model_emissive.slf @@ -0,0 +1,38 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_emissive.frag +// fragment shader +// +// Created by Zach Pomerantz on 2/3/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 +// + +<@include DeferredBufferWrite.slh@> +<@include model/Material.slh@> + +uniform sampler2D diffuseMap; + +in vec2 _texCoord0; +in vec3 _normal; +in vec3 _color; +in float _alpha; + +void main(void) { + vec4 texel = texture(diffuseMap, _texCoord0); + + Material mat = getMaterial(); + vec3 fragColor = getMaterialDiffuse(mat) * texel.rgb * _color; + + packDeferredFragmentLightmap( + normalize(_normal), + texel.a, + vec3(1.0), + getMaterialSpecular(mat), + getMaterialShininess(mat), + fragColor); +} diff --git a/libraries/render-utils/src/model_translucent.slf b/libraries/render-utils/src/model_translucent.slf index 1a17258408..42476ccc9a 100755 --- a/libraries/render-utils/src/model_translucent.slf +++ b/libraries/render-utils/src/model_translucent.slf @@ -19,32 +19,9 @@ <@include gpu/Transform.slh@> <$declareStandardCameraTransform()$> - // Everything about light <@include model/Light.slh@> -// The view Matrix -//uniform mat4 invViewMat; - -vec4 evalNormalColor(vec3 dir, float opacity) { - bool isX = (abs(dir.x) > 0.99); - bool isY = (abs(dir.y) > 0.99); - bool isZ = (abs(dir.z) > 0.99); - if (isX || isY || isZ) { - bool negX = (dir.x < -0.995); - bool negY = (dir.y < -0.995); - bool negZ = (dir.z < -0.995); - - if (negX || negY || negZ) { - return vec4(float(isX), float(isY), float(isZ), 0.2); - } else { - return vec4(float(isX), float(isY), float(isZ), 1.0); - } - } - - return vec4(0.5 * dir + vec3(0.5), opacity); -} - vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 diffuse, vec3 specular, float gloss, float opacity) { // Need the light now @@ -62,10 +39,7 @@ vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 d color += vec3(opacity * diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light); - //return vec4(color, opacity); return vec4(color, opacity); - //return vec4(diffuse.rgb, opacity); - //return evalNormalColor(fragEyeDir, opacity); } // the diffuse texture @@ -75,6 +49,7 @@ in vec4 _position; in vec2 _texCoord0; in vec3 _normal; in vec3 _color; +in float _alpha; out vec4 _fragColor; @@ -86,16 +61,16 @@ void main(void) { Material mat = getMaterial(); vec3 fragNormal = normalize(_normal); - float fragOpacity = getMaterialOpacity(mat) * diffuse.a; + float fragOpacity = getMaterialOpacity(mat) * diffuse.a * _alpha; vec3 fragDiffuse = getMaterialDiffuse(mat) * diffuse.rgb * _color; vec3 fragSpecular = getMaterialSpecular(mat); float fragGloss = getMaterialShininess(mat); _fragColor = evalGlobalColor(1.0, - fragPosition, - fragNormal, - fragDiffuse, - fragSpecular, - fragGloss, - fragOpacity); + fragPosition, + fragNormal, + fragDiffuse, + fragSpecular, + fragGloss, + fragOpacity); } diff --git a/libraries/render-utils/src/model_translucent_emissive.slf b/libraries/render-utils/src/model_translucent_emissive.slf new file mode 100644 index 0000000000..a2c7186f6f --- /dev/null +++ b/libraries/render-utils/src/model_translucent_emissive.slf @@ -0,0 +1,33 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_translucent_emissive.frag +// fragment shader +// +// Created by Zach Pomerantz on 2/3/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 +// + +<@include model/Material.slh@> + +uniform sampler2D diffuseMap; + +in vec2 _texCoord0; +in vec3 _color; +in float _alpha; + +out vec4 _fragColor; + +void main(void) { + vec4 diffuse = texture(diffuseMap, _texCoord0); + + Material mat = getMaterial(); + vec3 fragColor = getMaterialDiffuse(mat) * diffuse.rgb * _color; + float fragOpacity = getMaterialOpacity(mat) * diffuse.a * _alpha; + + _fragColor = vec4(fragColor, fragOpacity); +} diff --git a/libraries/render-utils/src/overlay3D.slf b/libraries/render-utils/src/overlay3D.slf index 7b8a8d85f4..9c37055f55 100644 --- a/libraries/render-utils/src/overlay3D.slf +++ b/libraries/render-utils/src/overlay3D.slf @@ -1,7 +1,7 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> -// model.frag +// overlay3D.slf // fragment shader // // Created by Sam Gateau on 6/16/15. @@ -11,20 +11,60 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -uniform sampler2D diffuseMap; +<@include DeferredLighting.slh@> +<@include model/Light.slh@> -in vec2 varTexcoord; +<@include gpu/Transform.slh@> +<$declareStandardCameraTransform()$> -in vec3 varEyeNormal; +vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 diffuse, vec3 specular, float gloss, float opacity) { -in vec4 varColor; -out vec4 outFragColor; + // Need the light now + Light light = getLight(); + TransformCamera cam = getTransformCamera(); + vec3 fragNormal; + <$transformEyeToWorldDir(cam, normal, fragNormal)$> + vec3 fragEyeVectorView = normalize(-position); + vec3 fragEyeDir; + <$transformEyeToWorldDir(cam, fragEyeVectorView, fragEyeDir)$> + vec3 color = opacity * diffuse.rgb * getLightColor(light) * getLightAmbientIntensity(light); + + vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, specular, gloss); + color += vec3(opacity * diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light); + + return vec4(color, opacity); +} + +uniform sampler2D originalTexture; + +in vec2 _texCoord0; +in vec4 _position; +in vec3 _normal; +in vec3 _color; +in float _alpha; + +out vec4 _fragColor; void main(void) { - vec4 diffuse = texture(diffuseMap, varTexcoord.st); - if (diffuse.a < 0.5) { + vec4 diffuse = texture(originalTexture, _texCoord0); + + vec3 fragPosition = _position.xyz; + vec3 fragNormal = normalize(_normal); + vec3 fragDiffuse = diffuse.rgb * _color; + vec3 fragSpecular = vec3(0.1); + float fragGloss = 10; + float fragOpacity = diffuse.a; + + if (fragOpacity <= 0.1) { discard; } - outFragColor = vec4(varColor * diffuse); + + _fragColor = evalGlobalColor(1.0, + fragPosition, + fragNormal, + fragDiffuse, + fragSpecular, + fragGloss, + fragOpacity); } diff --git a/libraries/render-utils/src/overlay3D.slv b/libraries/render-utils/src/overlay3D.slv index 74416f0c1f..d23f9c5c88 100644 --- a/libraries/render-utils/src/overlay3D.slv +++ b/libraries/render-utils/src/overlay3D.slv @@ -15,25 +15,22 @@ <@include gpu/Transform.slh@> <$declareStandardTransform()$> -out vec2 varTexcoord; +out vec2 _texCoord0; -// interpolated eye position -out vec4 varEyePosition; +out vec4 _position; +out vec3 _normal; -// the interpolated normal -out vec3 varEyeNormal; - -out vec4 varColor; +out vec3 _color; +out float _alpha; void main(void) { - varTexcoord = inTexCoord0.xy; - - // pass along the color - varColor = colorToLinearRGBA(inColor); + _texCoord0 = inTexCoord0.xy; + _color = colorToLinearRGB(inColor.xyz); + _alpha = inColor.w; // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); - <$transformModelToEyeAndClipPos(cam, obj, inPosition, varEyePosition, gl_Position)$> - <$transformModelToEyeDir(cam, obj, inNormal.xyz, varEyeNormal.xyz)$> + <$transformModelToEyeAndClipPos(cam, obj, inPosition, _position, gl_Position)$> + <$transformModelToEyeDir(cam, obj, inNormal.xyz, _normal.xyz)$> } diff --git a/libraries/render-utils/src/overlay3D_emissive.slf b/libraries/render-utils/src/overlay3D_emissive.slf new file mode 100644 index 0000000000..840ccb69f0 --- /dev/null +++ b/libraries/render-utils/src/overlay3D_emissive.slf @@ -0,0 +1,29 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// overlay3D_emissive.frag +// fragment shader +// +// Created by Zach Pomerantz on 2/2/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 +// + +uniform sampler2D originalTexture; + +in vec2 _texCoord0; +in vec3 _color; + +out vec4 _fragColor; + +void main(void) { + vec4 diffuse = texture(originalTexture, _texCoord0); + + if (diffuse.a <= 0.1) { + discard; + } + _fragColor = vec4(diffuse.rgb * _color, diffuse.a); +} diff --git a/libraries/render-utils/src/overlay3D_translucent.slf b/libraries/render-utils/src/overlay3D_translucent.slf new file mode 100644 index 0000000000..96637687c1 --- /dev/null +++ b/libraries/render-utils/src/overlay3D_translucent.slf @@ -0,0 +1,66 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// overlay3D_translucent.slf +// fragment shader +// +// Created by Sam Gateau on 6/16/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +<@include DeferredLighting.slh@> +<@include model/Light.slh@> + +<@include gpu/Transform.slh@> +<$declareStandardCameraTransform()$> + +vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 diffuse, vec3 specular, float gloss, float opacity) { + + // Need the light now + Light light = getLight(); + TransformCamera cam = getTransformCamera(); + vec3 fragNormal; + <$transformEyeToWorldDir(cam, normal, fragNormal)$> + vec3 fragEyeVectorView = normalize(-position); + vec3 fragEyeDir; + <$transformEyeToWorldDir(cam, fragEyeVectorView, fragEyeDir)$> + + vec3 color = opacity * diffuse.rgb * getLightColor(light) * getLightAmbientIntensity(light); + + vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, specular, gloss); + color += vec3(opacity * diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light); + + return vec4(color, opacity); +} + +uniform sampler2D originalTexture; + +in vec2 _texCoord0; +in vec4 _position; +in vec3 _normal; +in vec3 _color; +in float _alpha; + +out vec4 _fragColor; + +void main(void) { + vec4 diffuse = texture(originalTexture, _texCoord0); + + vec3 fragPosition = _position.xyz; + vec3 fragNormal = normalize(_normal); + vec3 fragDiffuse = diffuse.rgb * _color; + vec3 fragSpecular = vec3(0.1); + float fragGloss = 10; + float fragOpacity = diffuse.a * _alpha; + + _fragColor = evalGlobalColor(1.0, + fragPosition, + fragNormal, + fragDiffuse, + fragSpecular, + fragGloss, + fragOpacity); +} diff --git a/libraries/render-utils/src/overlay3D_translucent_emissive.slf b/libraries/render-utils/src/overlay3D_translucent_emissive.slf new file mode 100644 index 0000000000..bcfec7d588 --- /dev/null +++ b/libraries/render-utils/src/overlay3D_translucent_emissive.slf @@ -0,0 +1,27 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// overlay3D_translucent_emissive.frag +// fragment shader +// +// Created by Zach Pomerantz on 2/2/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 +// + +uniform sampler2D originalTexture; + +in vec2 _texCoord0; +in vec3 _color; +in float _alpha; + +out vec4 _fragColor; + +void main(void) { + vec4 diffuse = texture(originalTexture, _texCoord0); + + _fragColor = vec4(diffuse.rgb * _color, diffuse.a * _alpha); +} From 8d0f82fa6aa381622d92edf3702ddd0b73902a38 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 28 Jan 2016 12:57:13 -0800 Subject: [PATCH 07/26] Split DrawOverlay3D to Transparent/Opaque --- interface/src/ui/overlays/OverlaysPayload.cpp | 11 +++++++---- libraries/render-utils/src/RenderDeferredTask.cpp | 8 ++++---- libraries/render-utils/src/RenderDeferredTask.h | 6 ++---- libraries/render-utils/src/RenderPipelines.cpp | 8 ++++++++ 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/interface/src/ui/overlays/OverlaysPayload.cpp b/interface/src/ui/overlays/OverlaysPayload.cpp index 753106fa0a..aa257e1c23 100644 --- a/interface/src/ui/overlays/OverlaysPayload.cpp +++ b/interface/src/ui/overlays/OverlaysPayload.cpp @@ -35,15 +35,18 @@ namespace render { template <> const ItemKey payloadGetKey(const Overlay::Pointer& overlay) { + auto builder = ItemKey::Builder().withTypeShape(); if (overlay->is3D() && !std::dynamic_pointer_cast(overlay)->getDrawOnHUD()) { if (std::dynamic_pointer_cast(overlay)->getDrawInFront()) { - return ItemKey::Builder().withTypeShape().withLayered().build(); - } else { - return ItemKey::Builder::opaqueShape(); + builder.withLayered(); + } + if (overlay->getAlpha() != 1.0f) { + builder.withTransparent(); } } else { - return ItemKey::Builder().withTypeShape().withViewSpace().build(); + builder.withViewSpace(); } + return builder.build(); } template <> const Item::Bound payloadGetBound(const Overlay::Pointer& overlay) { return overlay->getBounds(); diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index e21b8ce799..d3aeb23a50 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -104,7 +104,8 @@ RenderDeferredTask::RenderDeferredTask(CullFunctor cullFunctor) { addJob("DrawStatus", opaques, DrawStatus(statusIconMap)); } - addJob("DrawOverlay3D"); + addJob("DrawOverlay3DOpaque", ItemFilter::Builder::opaqueShape().withLayered()); + addJob("DrawOverlay3DTransparent", ItemFilter::Builder::transparentShape().withLayered()); addJob("HitEffect"); @@ -156,7 +157,7 @@ void DrawDeferred::run(const SceneContextPointer& sceneContext, const RenderCont }); } -DrawOverlay3D::DrawOverlay3D() : _shapePlumber{ std::make_shared() } { +DrawOverlay3D::DrawOverlay3D(ItemFilter filter) : _filter{ filter }, _shapePlumber{ std::make_shared() } { initOverlay3DPipelines(*_shapePlumber); } @@ -166,7 +167,7 @@ void DrawOverlay3D::run(const SceneContextPointer& sceneContext, const RenderCon // render backgrounds auto& scene = sceneContext->_scene; - auto& items = scene->getMasterBucket().at(ItemFilter::Builder::opaqueShape().withLayered()); + auto& items = scene->getMasterBucket().at(_filter); auto config = std::static_pointer_cast(renderContext->jobConfig); @@ -179,7 +180,6 @@ void DrawOverlay3D::run(const SceneContextPointer& sceneContext, const RenderCon } } config->numItems = (int)inItems.size(); - config->numDrawn = (int)inItems.size(); if (!inItems.empty()) { RenderArgs* args = renderContext->args; diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index 0be2e0e808..87a4cce9ee 100755 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -87,14 +87,11 @@ public: class DrawOverlay3DConfig : public render::Job::Config { Q_OBJECT Q_PROPERTY(int numItems READ getNumItems) - Q_PROPERTY(int numDrawn READ getNumDrawn) Q_PROPERTY(int maxDrawn MEMBER maxDrawn NOTIFY dirty) public: int getNumItems() { return numItems; } - int getNumDrawn() { return numDrawn; } int numItems{ 0 }; - int numDrawn{ 0 }; int maxDrawn{ -1 }; signals: void dirty(); @@ -105,13 +102,14 @@ public: using Config = DrawOverlay3DConfig; using JobModel = render::Job::Model; - DrawOverlay3D(); + DrawOverlay3D(render::ItemFilter filter); void configure(const Config& config) { _maxDrawn = config.maxDrawn; } void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext); protected: render::ShapePlumberPointer _shapePlumber; + render::ItemFilter _filter; int _maxDrawn; // initialized by Config }; diff --git a/libraries/render-utils/src/RenderPipelines.cpp b/libraries/render-utils/src/RenderPipelines.cpp index 2dfe5d8828..0b3b6f7e7c 100644 --- a/libraries/render-utils/src/RenderPipelines.cpp +++ b/libraries/render-utils/src/RenderPipelines.cpp @@ -76,7 +76,15 @@ void initOverlay3DPipelines(ShapePlumber& plumber) { opaqueState->setDepthTest(false); opaqueState->setBlendFunction(false); + auto transparentState = std::make_shared(); + transparentState->setDepthTest(false); + transparentState->setBlendFunction(true, + gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, + gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); + + plumber.addPipeline(ShapeKey::Filter::Builder().withOpaque(), program, opaqueState, &batchSetter); + plumber.addPipeline(ShapeKey::Filter::Builder().withTranslucent(), program, transparentState, &batchSetter); } void initDeferredPipelines(render::ShapePlumber& plumber) { From 666213b7a849a7ac72125f5cc7cd7461f489e5cd Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Tue, 2 Feb 2016 10:12:03 -0800 Subject: [PATCH 08/26] Add CULL, DEPTH_BIAS to ShapeKey --- .../render-utils/src/RenderPipelines.cpp | 141 +++++++++--------- libraries/render/src/render/ShapePipeline.h | 42 ++++-- 2 files changed, 98 insertions(+), 85 deletions(-) diff --git a/libraries/render-utils/src/RenderPipelines.cpp b/libraries/render-utils/src/RenderPipelines.cpp index 0b3b6f7e7c..3935b26b44 100644 --- a/libraries/render-utils/src/RenderPipelines.cpp +++ b/libraries/render-utils/src/RenderPipelines.cpp @@ -72,19 +72,29 @@ void initOverlay3DPipelines(ShapePlumber& plumber) { auto ps = gpu::Shader::createPixel(std::string(overlay3D_frag)); auto program = gpu::Shader::createProgram(vs, ps); - auto opaqueState = std::make_shared(); - opaqueState->setDepthTest(false); - opaqueState->setBlendFunction(false); + for (int i = 0; i < 8; i++) { + bool isCulled = (i & 1); + bool isBiased = (i & 2); + bool isOpaque = (i & 4); - auto transparentState = std::make_shared(); - transparentState->setDepthTest(false); - transparentState->setBlendFunction(true, - gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, - gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); + auto state = std::make_shared(); + state->setDepthTest(false); + state->setCullMode(isCulled ? gpu::State::CULL_BACK : gpu::State::CULL_NONE); + if (isBiased) { + state->setDepthBias(1.0f); + state->setDepthBiasSlopeScale(1.0f); + } + state->setBlendFunction(!isOpaque, + gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, + gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); + ShapeKey::Filter::Builder builder; + isCulled ? builder.withCull() : builder.withoutCull(); + isBiased ? builder.withDepthBias() : builder.withoutDepthBias(); + isOpaque ? builder.withOpaque() : builder.withTranslucent(); - plumber.addPipeline(ShapeKey::Filter::Builder().withOpaque(), program, opaqueState, &batchSetter); - plumber.addPipeline(ShapeKey::Filter::Builder().withTranslucent(), program, transparentState, &batchSetter); + plumber.addPipeline(builder.build(), program, state, &batchSetter); + } } void initDeferredPipelines(render::ShapePlumber& plumber) { @@ -92,31 +102,42 @@ void initDeferredPipelines(render::ShapePlumber& plumber) { using ShaderPointer = gpu::ShaderPointer; auto addPipeline = [&plumber](const Key& key, const ShaderPointer& vertexShader, const ShaderPointer& pixelShader) { - auto state = std::make_shared(); - - // Cull backface - state->setCullMode(gpu::State::CULL_BACK); - - // Z test depends on transparency - state->setDepthTest(true, !key.isTranslucent(), gpu::LESS_EQUAL); - - // Blend if transparent - state->setBlendFunction(key.isTranslucent(), - // For transparency, keep the highlight intensity - gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, - gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); + // These keyvalues' pipelines will be added by this lamdba in addition to the key passed + assert(!key.isWireFrame()); + assert(!key.isDepthBiased()); + assert(key.isCulled()); ShaderPointer program = gpu::Shader::createProgram(vertexShader, pixelShader); - plumber.addPipeline(key, program, state, &batchSetter); - // Add a wireframe version - if (!key.isWireFrame()) { - auto wireFrameKey = Key::Builder(key).withWireframe(); - auto wireFrameState = std::make_shared(state->getValues()); + for (int i = 0; i < 8; i++) { + bool isCulled = (i & 1); + bool isBiased = (i & 2); + bool isWireframed = (i & 4); - wireFrameState->setFillMode(gpu::State::FILL_LINE); + ShapeKey::Builder builder(key); + auto state = std::make_shared(); - plumber.addPipeline(wireFrameKey, program, wireFrameState, &batchSetter); + // Depth test depends on transparency + state->setDepthTest(true, !key.isTranslucent(), gpu::LESS_EQUAL); + state->setBlendFunction(key.isTranslucent(), + gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, + gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); + + if (!isCulled) { + builder.withNoCull(); + } + state->setCullMode(isCulled ? gpu::State::CULL_BACK : gpu::State::CULL_NONE); + if (isWireframed) { + builder.withWireframe(); + state->setFillMode(gpu::State::FILL_LINE); + } + if (isBiased) { + builder.withDepthBias(); + state->setDepthBias(1.0f); + state->setDepthBiasSlopeScale(1.0f); + } + + plumber.addPipeline(builder.build(), program, state, &batchSetter); } }; @@ -142,101 +163,79 @@ void initDeferredPipelines(render::ShapePlumber& plumber) { auto modelLightmapSpecularMapPixel = gpu::Shader::createPixel(std::string(model_lightmap_specular_map_frag)); auto modelLightmapNormalSpecularMapPixel = gpu::Shader::createPixel(std::string(model_lightmap_normal_specular_map_frag)); - // Fill the pipelineLib + // Opaques addPipeline( Key::Builder(), modelVertex, modelPixel); - addPipeline( Key::Builder().withTangents(), modelNormalMapVertex, modelNormalMapPixel); - addPipeline( Key::Builder().withSpecular(), modelVertex, modelSpecularMapPixel); - addPipeline( Key::Builder().withTangents().withSpecular(), modelNormalMapVertex, modelNormalSpecularMapPixel); - - + // Translucents addPipeline( Key::Builder().withTranslucent(), modelVertex, modelTranslucentPixel); - // FIXME Ignore lightmap for translucents meshpart addPipeline( + Key::Builder().withTranslucent().withTangents(), + modelNormalMapVertex, modelTranslucentPixel); + addPipeline( + Key::Builder().withTranslucent().withSpecular(), + modelVertex, modelTranslucentPixel); + addPipeline( + Key::Builder().withTranslucent().withTangents().withSpecular(), + modelNormalMapVertex, modelTranslucentPixel); + addPipeline( + // FIXME: Ignore lightmap for translucents meshpart Key::Builder().withTranslucent().withLightmap(), modelVertex, modelTranslucentPixel); - - addPipeline( - Key::Builder().withTangents().withTranslucent(), - modelNormalMapVertex, modelTranslucentPixel); - - addPipeline( - Key::Builder().withSpecular().withTranslucent(), - modelVertex, modelTranslucentPixel); - - addPipeline( - Key::Builder().withTangents().withSpecular().withTranslucent(), - modelNormalMapVertex, modelTranslucentPixel); - - + // Lightmapped addPipeline( Key::Builder().withLightmap(), modelLightmapVertex, modelLightmapPixel); - addPipeline( Key::Builder().withLightmap().withTangents(), modelLightmapNormalMapVertex, modelLightmapNormalMapPixel); - addPipeline( Key::Builder().withLightmap().withSpecular(), modelLightmapVertex, modelLightmapSpecularMapPixel); - addPipeline( Key::Builder().withLightmap().withTangents().withSpecular(), modelLightmapNormalMapVertex, modelLightmapNormalSpecularMapPixel); - - + // Skinned addPipeline( Key::Builder().withSkinned(), skinModelVertex, modelPixel); - addPipeline( Key::Builder().withSkinned().withTangents(), skinModelNormalMapVertex, modelNormalMapPixel); - addPipeline( Key::Builder().withSkinned().withSpecular(), skinModelVertex, modelSpecularMapPixel); - addPipeline( Key::Builder().withSkinned().withTangents().withSpecular(), skinModelNormalMapVertex, modelNormalSpecularMapPixel); - - + // Skinned and Translucent addPipeline( Key::Builder().withSkinned().withTranslucent(), skinModelVertex, modelTranslucentPixel); - addPipeline( - Key::Builder().withSkinned().withTangents().withTranslucent(), + Key::Builder().withSkinned().withTranslucent().withTangents(), skinModelNormalMapVertex, modelTranslucentPixel); - addPipeline( - Key::Builder().withSkinned().withSpecular().withTranslucent(), + Key::Builder().withSkinned().withTranslucent().withSpecular(), skinModelVertex, modelTranslucentPixel); - addPipeline( - Key::Builder().withSkinned().withTangents().withSpecular().withTranslucent(), + Key::Builder().withSkinned().withTranslucent().withTangents().withSpecular(), skinModelNormalMapVertex, modelTranslucentPixel); - - + // Depth-only addPipeline( Key::Builder().withDepthOnly(), modelShadowVertex, modelShadowPixel); - - addPipeline( Key::Builder().withSkinned().withDepthOnly(), skinModelShadowVertex, modelShadowPixel); diff --git a/libraries/render/src/render/ShapePipeline.h b/libraries/render/src/render/ShapePipeline.h index 6ea9ea1c72..8993fcfcc8 100644 --- a/libraries/render/src/render/ShapePipeline.h +++ b/libraries/render/src/render/ShapePipeline.h @@ -28,7 +28,9 @@ public: SKINNED, STEREO, DEPTH_ONLY, + DEPTH_BIAS, WIREFRAME, + CULL, OWN_PIPELINE, INVALID, @@ -39,12 +41,12 @@ public: Flags _flags; - ShapeKey() : _flags{0} {} + ShapeKey() : _flags{0} { _flags.set(CULL); } ShapeKey(const Flags& flags) : _flags{flags} {} class Builder { public: - Builder() {} + Builder() { _flags.set(CULL); } Builder(ShapeKey key) : _flags{key._flags} {} ShapeKey build() const { return ShapeKey{_flags}; } @@ -57,7 +59,9 @@ public: Builder& withSkinned() { _flags.set(SKINNED); return (*this); } Builder& withStereo() { _flags.set(STEREO); return (*this); } Builder& withDepthOnly() { _flags.set(DEPTH_ONLY); return (*this); } + Builder& withDepthBias() { _flags.set(DEPTH_BIAS); return (*this); } Builder& withWireframe() { _flags.set(WIREFRAME); return (*this); } + Builder& withNoCull() { _flags.reset(CULL); return (*this); } Builder& withOwnPipeline() { _flags.set(OWN_PIPELINE); return (*this); } Builder& invalidate() { _flags.set(INVALID); return (*this); } @@ -107,9 +111,15 @@ public: Builder& withDepthOnly() { _flags.set(DEPTH_ONLY); _mask.set(DEPTH_ONLY); return (*this); } Builder& withoutDepthOnly() { _flags.reset(DEPTH_ONLY); _mask.set(DEPTH_ONLY); return (*this); } + Builder& withDepthBias() { _flags.set(DEPTH_BIAS); _mask.set(DEPTH_BIAS); return (*this); } + Builder& withoutDepthBias() { _flags.reset(DEPTH_BIAS); _mask.set(DEPTH_BIAS); return (*this); } + Builder& withWireframe() { _flags.set(WIREFRAME); _mask.set(WIREFRAME); return (*this); } Builder& withoutWireframe() { _flags.reset(WIREFRAME); _mask.set(WIREFRAME); return (*this); } + Builder& withCull() { _flags.set(CULL); _mask.set(CULL); return (*this); } + Builder& withoutCull() { _flags.reset(CULL); _mask.set(CULL); return (*this); } + protected: friend class Filter; Flags _flags{0}; @@ -130,7 +140,9 @@ public: bool isSkinned() const { return _flags[SKINNED]; } bool isStereo() const { return _flags[STEREO]; } bool isDepthOnly() const { return _flags[DEPTH_ONLY]; } + bool isDepthBiased() const { return _flags[DEPTH_BIAS]; } bool isWireFrame() const { return _flags[WIREFRAME]; } + bool isCulled() const { return _flags[CULL]; } bool hasOwnPipeline() const { return _flags[OWN_PIPELINE]; } bool isValid() const { return !_flags[INVALID]; } @@ -150,21 +162,23 @@ public: }; }; -inline QDebug operator<<(QDebug debug, const ShapeKey& renderKey) { - if (renderKey.isValid()) { - if (renderKey.hasOwnPipeline()) { +inline QDebug operator<<(QDebug debug, const ShapeKey& key) { + if (key.isValid()) { + if (key.hasOwnPipeline()) { debug << "[ShapeKey: OWN_PIPELINE]"; } else { debug << "[ShapeKey:" - << "hasLightmap:" << renderKey.hasLightmap() - << "hasTangents:" << renderKey.hasTangents() - << "hasSpecular:" << renderKey.hasSpecular() - << "hasEmissive:" << renderKey.hasEmissive() - << "isTranslucent:" << renderKey.isTranslucent() - << "isSkinned:" << renderKey.isSkinned() - << "isStereo:" << renderKey.isStereo() - << "isDepthOnly:" << renderKey.isDepthOnly() - << "isWireFrame:" << renderKey.isWireFrame() + << "hasLightmap:" << key.hasLightmap() + << "hasTangents:" << key.hasTangents() + << "hasSpecular:" << key.hasSpecular() + << "hasEmissive:" << key.hasEmissive() + << "isTranslucent:" << key.isTranslucent() + << "isSkinned:" << key.isSkinned() + << "isStereo:" << key.isStereo() + << "isDepthOnly:" << key.isDepthOnly() + << "isDepthBiased:" << key.isDepthBiased() + << "isWireFrame:" << key.isWireFrame() + << "isCulled:" << key.isCulled() << "]"; } } else { From 65ddb944d2ae063b44b6d4f46c4951699be731b1 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 3 Feb 2016 11:33:45 -0800 Subject: [PATCH 09/26] Add defaults/light/shaders to plumber --- .../src/DeferredLightingEffect.cpp | 5 +- .../render-utils/src/DeferredLightingEffect.h | 2 +- .../render-utils/src/MeshPartPayload.cpp | 14 ---- .../render-utils/src/RenderPipelines.cpp | 76 ++++++++++++++++--- 4 files changed, 71 insertions(+), 26 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index f81ac2efd1..11c5031b95 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -511,9 +511,10 @@ void DeferredLightingEffect::render(const render::RenderContextPointer& renderCo } } -void DeferredLightingEffect::setupTransparent(RenderArgs* args, int lightBufferUnit) { +void DeferredLightingEffect::setupTransparent(gpu::Batch& batch, int lightBufferUnit) { + PerformanceTimer perfTimer("DLE->setupTransparent()"); auto globalLight = _allocatedLights[_globalLights.front()]; - args->_batch->setUniformBuffer(lightBufferUnit, globalLight->getSchemaBuffer()); + batch.setUniformBuffer(lightBufferUnit, globalLight->getSchemaBuffer()); } static void loadLightProgram(const char* vertSource, const char* fragSource, bool lightVolume, gpu::PipelinePointer& pipeline, LightLocationsPtr& locations) { diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index ee4eeb445e..c3970dfc96 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -46,7 +46,7 @@ public: void prepare(RenderArgs* args); void render(const render::RenderContextPointer& renderContext); - void setupTransparent(RenderArgs* args, int lightBufferUnit); + void setupTransparent(gpu::Batch& batch, int lightBufferUnit); // update global lighting void setAmbientLightMode(int preset); diff --git a/libraries/render-utils/src/MeshPartPayload.cpp b/libraries/render-utils/src/MeshPartPayload.cpp index d5ee1434bb..dfa306e209 100644 --- a/libraries/render-utils/src/MeshPartPayload.cpp +++ b/libraries/render-utils/src/MeshPartPayload.cpp @@ -239,13 +239,6 @@ void MeshPartPayload::render(RenderArgs* args) const { // apply material properties bindMaterial(batch, locations); - - // TODO: We should be able to do that just in the renderTransparentJob - if (key.isTranslucent() && locations->lightBufferUnit >= 0) { - PerformanceTimer perfTimer("DLE->setupTransparent()"); - - DependencyManager::get()->setupTransparent(args, locations->lightBufferUnit); - } if (args) { args->_details._materialSwitches++; } @@ -517,13 +510,6 @@ void ModelMeshPartPayload::render(RenderArgs* args) const { // apply material properties bindMaterial(batch, locations); - - // TODO: We should be able to do that just in the renderTransparentJob - if (key.isTranslucent() && locations->lightBufferUnit >= 0) { - PerformanceTimer perfTimer("DLE->setupTransparent()"); - - DependencyManager::get()->setupTransparent(args, locations->lightBufferUnit); - } if (args) { args->_details._materialSwitches++; } diff --git a/libraries/render-utils/src/RenderPipelines.cpp b/libraries/render-utils/src/RenderPipelines.cpp index 3935b26b44..48c7ee4f9b 100644 --- a/libraries/render-utils/src/RenderPipelines.cpp +++ b/libraries/render-utils/src/RenderPipelines.cpp @@ -13,6 +13,7 @@ #include #include +#include "DeferredLightingEffect.h" #include "TextureCache.h" #include "render/DrawTask.h" @@ -26,6 +27,7 @@ #include "skin_model_normal_map_vert.h" #include "model_frag.h" +#include "model_emissive_frag.h" #include "model_shadow_frag.h" #include "model_normal_map_frag.h" #include "model_normal_specular_map_frag.h" @@ -35,9 +37,13 @@ #include "model_lightmap_normal_specular_map_frag.h" #include "model_lightmap_specular_map_frag.h" #include "model_translucent_frag.h" +#include "model_translucent_emissive_frag.h" #include "overlay3D_vert.h" #include "overlay3D_frag.h" +#include "overlay3D_translucent_frag.h" +#include "overlay3D_emissive_frag.h" +#include "overlay3D_translucent_emissive_frag.h" #include "drawOpaqueStencil_frag.h" @@ -58,6 +64,15 @@ void initStencilPipeline(gpu::PipelinePointer& pipeline) { pipeline = gpu::Pipeline::create(program, state); } +gpu::BufferView getDefaultMaterialBuffer() { + model::Material::Schema schema; + schema._diffuse = vec3(1.0f); + schema._opacity = 1.0f; + schema._metallic = vec3(0.1f); + schema._gloss = 10.0f; + return gpu::BufferView(std::make_shared(sizeof(model::Material::Schema), (const gpu::Byte*) &schema)); +} + void batchSetter(const ShapePipeline& pipeline, gpu::Batch& batch) { // Set a default diffuse map batch.setResourceTexture(render::ShapePipeline::Slot::DIFFUSE_MAP, @@ -65,12 +80,37 @@ void batchSetter(const ShapePipeline& pipeline, gpu::Batch& batch) { // Set a default normal map batch.setResourceTexture(render::ShapePipeline::Slot::NORMAL_FITTING_MAP, DependencyManager::get()->getNormalFittingTexture()); + // Set default coordinates + if (pipeline.locations->texcoordMatrices >= 0) { + static const glm::mat4 TEX_COORDS[2]; + batch._glUniformMatrix4fv(pipeline.locations->texcoordMatrices, 2, false, (const float*)&TEX_COORDS); + } + // Set a default material + if (pipeline.locations->materialBufferUnit >= 0) { + static const gpu::BufferView OPAQUE_SCHEMA_BUFFER = getDefaultMaterialBuffer(); + batch.setUniformBuffer(ShapePipeline::Slot::MATERIAL_GPU, OPAQUE_SCHEMA_BUFFER); + } +} + +void lightBatchSetter(const ShapePipeline& pipeline, gpu::Batch& batch) { + batchSetter(pipeline, batch); + // Set the light + if (pipeline.locations->lightBufferUnit >= 0) { + DependencyManager::get()->setupTransparent(batch, pipeline.locations->lightBufferUnit); + } } void initOverlay3DPipelines(ShapePlumber& plumber) { - auto vs = gpu::Shader::createVertex(std::string(overlay3D_vert)); - auto ps = gpu::Shader::createPixel(std::string(overlay3D_frag)); - auto program = gpu::Shader::createProgram(vs, ps); + auto vertex = gpu::Shader::createVertex(std::string(overlay3D_vert)); + auto pixel = gpu::Shader::createPixel(std::string(overlay3D_frag)); + auto pixelTranslucent = gpu::Shader::createPixel(std::string(overlay3D_translucent_frag)); + auto pixelEmissive = gpu::Shader::createPixel(std::string(overlay3D_emissive_frag)); + auto pixelTranslucentEmissive = gpu::Shader::createPixel(std::string(overlay3D_translucent_emissive_frag)); + + auto opaqueProgram = gpu::Shader::createProgram(vertex, pixel); + auto translucentProgram = gpu::Shader::createProgram(vertex, pixelTranslucent); + auto emissiveOpaqueProgram = gpu::Shader::createProgram(vertex, pixelEmissive); + auto emissiveTranslucentProgram = gpu::Shader::createProgram(vertex, pixelTranslucentEmissive); for (int i = 0; i < 8; i++) { bool isCulled = (i & 1); @@ -84,16 +124,25 @@ void initOverlay3DPipelines(ShapePlumber& plumber) { state->setDepthBias(1.0f); state->setDepthBiasSlopeScale(1.0f); } - state->setBlendFunction(!isOpaque, - gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, - gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); + if (isOpaque) { + // Soft edges + state->setBlendFunction(true, + gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); + } else { + state->setBlendFunction(true, + gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, + gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); + } ShapeKey::Filter::Builder builder; isCulled ? builder.withCull() : builder.withoutCull(); isBiased ? builder.withDepthBias() : builder.withoutDepthBias(); isOpaque ? builder.withOpaque() : builder.withTranslucent(); - plumber.addPipeline(builder.build(), program, state, &batchSetter); + auto simpleProgram = isOpaque ? opaqueProgram : translucentProgram; + auto emissiveProgram = isOpaque ? emissiveOpaqueProgram : emissiveTranslucentProgram; + plumber.addPipeline(builder.withoutEmissive().build(), simpleProgram, state, &lightBatchSetter); + plumber.addPipeline(builder.withEmissive().build(), emissiveProgram, state, &batchSetter); } } @@ -137,7 +186,8 @@ void initDeferredPipelines(render::ShapePlumber& plumber) { state->setDepthBiasSlopeScale(1.0f); } - plumber.addPipeline(builder.build(), program, state, &batchSetter); + plumber.addPipeline(builder.build(), program, state, + key.isTranslucent() ? &lightBatchSetter : &batchSetter); } }; @@ -153,20 +203,26 @@ void initDeferredPipelines(render::ShapePlumber& plumber) { // Pixel shaders auto modelPixel = gpu::Shader::createPixel(std::string(model_frag)); + auto modelEmissivePixel = gpu::Shader::createPixel(std::string(model_emissive_frag)); auto modelNormalMapPixel = gpu::Shader::createPixel(std::string(model_normal_map_frag)); auto modelSpecularMapPixel = gpu::Shader::createPixel(std::string(model_specular_map_frag)); auto modelNormalSpecularMapPixel = gpu::Shader::createPixel(std::string(model_normal_specular_map_frag)); auto modelTranslucentPixel = gpu::Shader::createPixel(std::string(model_translucent_frag)); + auto modelTranslucentEmissivePixel = gpu::Shader::createPixel(std::string(model_translucent_emissive_frag)); auto modelShadowPixel = gpu::Shader::createPixel(std::string(model_shadow_frag)); auto modelLightmapPixel = gpu::Shader::createPixel(std::string(model_lightmap_frag)); auto modelLightmapNormalMapPixel = gpu::Shader::createPixel(std::string(model_lightmap_normal_map_frag)); auto modelLightmapSpecularMapPixel = gpu::Shader::createPixel(std::string(model_lightmap_specular_map_frag)); auto modelLightmapNormalSpecularMapPixel = gpu::Shader::createPixel(std::string(model_lightmap_normal_specular_map_frag)); + // TODO: Refactor this to use a filter // Opaques addPipeline( Key::Builder(), modelVertex, modelPixel); + addPipeline( + Key::Builder().withEmissive(), + modelVertex, modelEmissivePixel); addPipeline( Key::Builder().withTangents(), modelNormalMapVertex, modelNormalMapPixel); @@ -180,6 +236,9 @@ void initDeferredPipelines(render::ShapePlumber& plumber) { addPipeline( Key::Builder().withTranslucent(), modelVertex, modelTranslucentPixel); + addPipeline( + Key::Builder().withTranslucent().withEmissive(), + modelVertex, modelTranslucentEmissivePixel); addPipeline( Key::Builder().withTranslucent().withTangents(), modelNormalMapVertex, modelTranslucentPixel); @@ -240,4 +299,3 @@ void initDeferredPipelines(render::ShapePlumber& plumber) { Key::Builder().withSkinned().withDepthOnly(), skinModelShadowVertex, modelShadowPixel); } - From 53bd595b776f9903f9fc47d2de2a101bc6826b1a Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 3 Feb 2016 16:27:34 -0800 Subject: [PATCH 10/26] Update all appropriate overlays to use plumber --- interface/src/ui/overlays/Circle3DOverlay.cpp | 9 ++++- interface/src/ui/overlays/Circle3DOverlay.h | 1 + interface/src/ui/overlays/Cube3DOverlay.cpp | 33 ++++++++++--------- interface/src/ui/overlays/Cube3DOverlay.h | 1 + interface/src/ui/overlays/Grid3DOverlay.cpp | 8 +++++ interface/src/ui/overlays/Grid3DOverlay.h | 1 + interface/src/ui/overlays/Image3DOverlay.cpp | 12 ++++++- interface/src/ui/overlays/Image3DOverlay.h | 2 ++ interface/src/ui/overlays/Line3DOverlay.cpp | 9 ++++- interface/src/ui/overlays/Line3DOverlay.h | 1 + interface/src/ui/overlays/Overlay.h | 3 ++ interface/src/ui/overlays/OverlaysPayload.cpp | 3 ++ .../src/ui/overlays/Rectangle3DOverlay.cpp | 8 +++++ .../src/ui/overlays/Rectangle3DOverlay.h | 1 + interface/src/ui/overlays/Sphere3DOverlay.cpp | 19 +++++++++-- interface/src/ui/overlays/Sphere3DOverlay.h | 1 + interface/src/ui/overlays/Text3DOverlay.cpp | 18 ++++++++-- interface/src/ui/overlays/Text3DOverlay.h | 3 +- interface/src/ui/overlays/Web3DOverlay.cpp | 9 ++++- interface/src/ui/overlays/Web3DOverlay.h | 1 + 20 files changed, 117 insertions(+), 26 deletions(-) diff --git a/interface/src/ui/overlays/Circle3DOverlay.cpp b/interface/src/ui/overlays/Circle3DOverlay.cpp index bbb9addc3d..698d3680e1 100644 --- a/interface/src/ui/overlays/Circle3DOverlay.cpp +++ b/interface/src/ui/overlays/Circle3DOverlay.cpp @@ -105,7 +105,6 @@ void Circle3DOverlay::render(RenderArgs* args) { auto transform = _transform; transform.postScale(glm::vec3(getDimensions(), 1.0f)); batch.setModelTransform(transform); - DependencyManager::get()->bindSimpleProgram(batch, false, false); // for our overlay, is solid means we draw a ring between the inner and outer radius of the circle, otherwise // we just draw a line... @@ -278,6 +277,14 @@ void Circle3DOverlay::render(RenderArgs* args) { } } +const render::ShapeKey Circle3DOverlay::getShapeKey() { + auto builder = render::ShapeKey::Builder().withNoCull(); + if (getAlpha() != 1.0f) { + builder.withTranslucent(); + } + return builder.build(); +} + void Circle3DOverlay::setProperties(const QScriptValue &properties) { Planar3DOverlay::setProperties(properties); diff --git a/interface/src/ui/overlays/Circle3DOverlay.h b/interface/src/ui/overlays/Circle3DOverlay.h index d03dc2ee2a..6c6ab965d0 100644 --- a/interface/src/ui/overlays/Circle3DOverlay.h +++ b/interface/src/ui/overlays/Circle3DOverlay.h @@ -25,6 +25,7 @@ public: Circle3DOverlay(const Circle3DOverlay* circle3DOverlay); virtual void render(RenderArgs* args); + virtual const render::ShapeKey Circle3DOverlay::getShapeKey() override; virtual void setProperties(const QScriptValue& properties); virtual QScriptValue getProperty(const QString& property); diff --git a/interface/src/ui/overlays/Cube3DOverlay.cpp b/interface/src/ui/overlays/Cube3DOverlay.cpp index e291882161..8ba29bd336 100644 --- a/interface/src/ui/overlays/Cube3DOverlay.cpp +++ b/interface/src/ui/overlays/Cube3DOverlay.cpp @@ -46,22 +46,17 @@ void Cube3DOverlay::render(RenderArgs* args) { Transform transform; transform.setTranslation(position); transform.setRotation(rotation); - if (_isSolid) { - // if (_borderSize > 0) { - // // Draw a cube at a larger size behind the main cube, creating - // // a border effect. - // // Disable writing to the depth mask so that the "border" cube will not - // // occlude the main cube. This means the border could be covered by - // // overlays that are further back and drawn later, but this is good - // // enough for the use-case. - // transform.setScale(dimensions * _borderSize); - // batch->setModelTransform(transform); - // DependencyManager::get()->renderSolidCube(*batch, 1.0f, glm::vec4(1.0f, 1.0f, 1.0f, alpha)); - // } + auto geometryCache = DependencyManager::get(); + auto pipeline = args->_pipeline; + if (!pipeline) { + pipeline = geometryCache->getShapePipeline(); + } + + if (_isSolid) { transform.setScale(dimensions); batch->setModelTransform(transform); - DependencyManager::get()->renderSolidCubeInstance(*batch, cubeColor); + geometryCache->renderSolidCubeInstance(*batch, cubeColor, pipeline); } else { if (getIsDashedLine()) { @@ -79,8 +74,6 @@ void Cube3DOverlay::render(RenderArgs* args) { glm::vec3 topLeftFar(-halfDimensions.x, halfDimensions.y, halfDimensions.z); glm::vec3 topRightFar(halfDimensions.x, halfDimensions.y, halfDimensions.z); - auto geometryCache = DependencyManager::get(); - geometryCache->renderDashedLine(*batch, bottomLeftNear, bottomRightNear, cubeColor); geometryCache->renderDashedLine(*batch, bottomRightNear, bottomRightFar, cubeColor); geometryCache->renderDashedLine(*batch, bottomRightFar, bottomLeftFar, cubeColor); @@ -99,12 +92,20 @@ void Cube3DOverlay::render(RenderArgs* args) { } else { transform.setScale(dimensions); batch->setModelTransform(transform); - DependencyManager::get()->renderWireCubeInstance(*batch, cubeColor); + geometryCache->renderWireCubeInstance(*batch, cubeColor, pipeline); } } } } +const render::ShapeKey Cube3DOverlay::getShapeKey() { + auto builder = render::ShapeKey::Builder(); + if (getAlpha() != 1.0f) { + builder.withTranslucent(); + } + return builder.build(); +} + Cube3DOverlay* Cube3DOverlay::createClone() const { return new Cube3DOverlay(this); } diff --git a/interface/src/ui/overlays/Cube3DOverlay.h b/interface/src/ui/overlays/Cube3DOverlay.h index 6f9026a091..1ef667ff4a 100644 --- a/interface/src/ui/overlays/Cube3DOverlay.h +++ b/interface/src/ui/overlays/Cube3DOverlay.h @@ -24,6 +24,7 @@ public: Cube3DOverlay(const Cube3DOverlay* cube3DOverlay); virtual void render(RenderArgs* args); + virtual const render::ShapeKey Cube3DOverlay::getShapeKey() override; virtual Cube3DOverlay* createClone() const; diff --git a/interface/src/ui/overlays/Grid3DOverlay.cpp b/interface/src/ui/overlays/Grid3DOverlay.cpp index bfb0d1d9df..fca6a3796a 100644 --- a/interface/src/ui/overlays/Grid3DOverlay.cpp +++ b/interface/src/ui/overlays/Grid3DOverlay.cpp @@ -93,6 +93,14 @@ void Grid3DOverlay::render(RenderArgs* args) { } } +const render::ShapeKey Grid3DOverlay::getShapeKey() { + auto builder = render::ShapeKey::Builder(); + if (getAlpha() != 1.0f) { + builder.withTranslucent(); + } + return builder.build(); +} + void Grid3DOverlay::setProperties(const QScriptValue& properties) { Planar3DOverlay::setProperties(properties); diff --git a/interface/src/ui/overlays/Grid3DOverlay.h b/interface/src/ui/overlays/Grid3DOverlay.h index 5fb3852905..e254ad88fe 100644 --- a/interface/src/ui/overlays/Grid3DOverlay.h +++ b/interface/src/ui/overlays/Grid3DOverlay.h @@ -25,6 +25,7 @@ public: Grid3DOverlay(const Grid3DOverlay* grid3DOverlay); virtual void render(RenderArgs* args); + virtual const render::ShapeKey Grid3DOverlay::getShapeKey() override; virtual void setProperties(const QScriptValue& properties); virtual QScriptValue getProperty(const QString& property); diff --git a/interface/src/ui/overlays/Image3DOverlay.cpp b/interface/src/ui/overlays/Image3DOverlay.cpp index 8ce8bf7a5f..379560e2a5 100644 --- a/interface/src/ui/overlays/Image3DOverlay.cpp +++ b/interface/src/ui/overlays/Image3DOverlay.cpp @@ -95,7 +95,6 @@ void Image3DOverlay::render(RenderArgs* args) { batch->setModelTransform(transform); batch->setResourceTexture(0, _texture->getGPUTexture()); - DependencyManager::get()->bindSimpleProgram(*batch, true, false, _emissive, true); DependencyManager::get()->renderQuad( *batch, topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, glm::vec4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha) @@ -104,6 +103,17 @@ void Image3DOverlay::render(RenderArgs* args) { batch->setResourceTexture(0, args->_whiteTexture); // restore default white color after me } +const render::ShapeKey Image3DOverlay::getShapeKey() { + auto builder = render::ShapeKey::Builder().withNoCull().withDepthBias(); + if (_emissive) { + builder.withEmissive(); + } + if (getAlpha() != 1.0f) { + builder.withTranslucent(); + } + return builder.build(); +} + void Image3DOverlay::setProperties(const QScriptValue &properties) { Billboard3DOverlay::setProperties(properties); diff --git a/interface/src/ui/overlays/Image3DOverlay.h b/interface/src/ui/overlays/Image3DOverlay.h index f2cc3789ee..9ec4f7e29c 100644 --- a/interface/src/ui/overlays/Image3DOverlay.h +++ b/interface/src/ui/overlays/Image3DOverlay.h @@ -31,6 +31,8 @@ public: virtual void update(float deltatime); + virtual const render::ShapeKey Image3DOverlay::getShapeKey() override; + // setters void setURL(const QString& url); void setClipFromSource(const QRect& bounds) { _fromImage = bounds; } diff --git a/interface/src/ui/overlays/Line3DOverlay.cpp b/interface/src/ui/overlays/Line3DOverlay.cpp index ed97b95de0..c0a1c9e282 100644 --- a/interface/src/ui/overlays/Line3DOverlay.cpp +++ b/interface/src/ui/overlays/Line3DOverlay.cpp @@ -53,7 +53,6 @@ void Line3DOverlay::render(RenderArgs* args) { auto batch = args->_batch; if (batch) { batch->setModelTransform(_transform); - DependencyManager::get()->bindSimpleProgram(*batch); if (getIsDashedLine()) { // TODO: add support for color to renderDashedLine() @@ -64,6 +63,14 @@ void Line3DOverlay::render(RenderArgs* args) { } } +const render::ShapeKey Line3DOverlay::getShapeKey() { + auto builder = render::ShapeKey::Builder(); + if (getAlpha() != 1.0f) { + builder.withTranslucent(); + } + return builder.build(); +} + void Line3DOverlay::setProperties(const QScriptValue& properties) { Base3DOverlay::setProperties(properties); diff --git a/interface/src/ui/overlays/Line3DOverlay.h b/interface/src/ui/overlays/Line3DOverlay.h index 05812709dc..361f83e3b0 100644 --- a/interface/src/ui/overlays/Line3DOverlay.h +++ b/interface/src/ui/overlays/Line3DOverlay.h @@ -24,6 +24,7 @@ public: Line3DOverlay(const Line3DOverlay* line3DOverlay); ~Line3DOverlay(); virtual void render(RenderArgs* args); + virtual const render::ShapeKey Line3DOverlay::getShapeKey() override; virtual AABox getBounds() const; // getters diff --git a/interface/src/ui/overlays/Overlay.h b/interface/src/ui/overlays/Overlay.h index 4d3b5ae36f..2343e434ca 100644 --- a/interface/src/ui/overlays/Overlay.h +++ b/interface/src/ui/overlays/Overlay.h @@ -44,6 +44,8 @@ public: virtual bool addToScene(Overlay::Pointer overlay, std::shared_ptr scene, render::PendingChanges& pendingChanges); virtual void removeFromScene(Overlay::Pointer overlay, std::shared_ptr scene, render::PendingChanges& pendingChanges); + virtual const render::ShapeKey getShapeKey() { return render::ShapeKey::Builder::ownPipeline(); } + // getters virtual QString getType() const = 0; virtual bool is3D() const = 0; @@ -119,6 +121,7 @@ namespace render { template <> const Item::Bound payloadGetBound(const Overlay::Pointer& overlay); template <> int payloadGetLayer(const Overlay::Pointer& overlay); template <> void payloadRender(const Overlay::Pointer& overlay, RenderArgs* args); + template <> const ShapeKey shapeGetShapeKey(const Overlay::Pointer& overlay); } diff --git a/interface/src/ui/overlays/OverlaysPayload.cpp b/interface/src/ui/overlays/OverlaysPayload.cpp index aa257e1c23..bf625503c0 100644 --- a/interface/src/ui/overlays/OverlaysPayload.cpp +++ b/interface/src/ui/overlays/OverlaysPayload.cpp @@ -83,4 +83,7 @@ namespace render { } } } + template <> const ShapeKey shapeGetShapeKey(const Overlay::Pointer& overlay) { + return overlay->getShapeKey(); + } } diff --git a/interface/src/ui/overlays/Rectangle3DOverlay.cpp b/interface/src/ui/overlays/Rectangle3DOverlay.cpp index 64c5e4c819..cee924c44c 100644 --- a/interface/src/ui/overlays/Rectangle3DOverlay.cpp +++ b/interface/src/ui/overlays/Rectangle3DOverlay.cpp @@ -88,6 +88,14 @@ void Rectangle3DOverlay::render(RenderArgs* args) { } } +const render::ShapeKey Rectangle3DOverlay::getShapeKey() { + auto builder = render::ShapeKey::Builder(); + if (getAlpha() != 1.0f) { + builder.withTranslucent(); + } + return builder.build(); +} + void Rectangle3DOverlay::setProperties(const QScriptValue &properties) { Planar3DOverlay::setProperties(properties); } diff --git a/interface/src/ui/overlays/Rectangle3DOverlay.h b/interface/src/ui/overlays/Rectangle3DOverlay.h index e5eba8bce8..d2a40a899b 100644 --- a/interface/src/ui/overlays/Rectangle3DOverlay.h +++ b/interface/src/ui/overlays/Rectangle3DOverlay.h @@ -24,6 +24,7 @@ public: Rectangle3DOverlay(const Rectangle3DOverlay* rectangle3DOverlay); ~Rectangle3DOverlay(); virtual void render(RenderArgs* args); + virtual const render::ShapeKey Rectangle3DOverlay::getShapeKey() override; virtual void setProperties(const QScriptValue& properties); virtual Rectangle3DOverlay* createClone() const; diff --git a/interface/src/ui/overlays/Sphere3DOverlay.cpp b/interface/src/ui/overlays/Sphere3DOverlay.cpp index dcd1460ff4..d50f2f7285 100644 --- a/interface/src/ui/overlays/Sphere3DOverlay.cpp +++ b/interface/src/ui/overlays/Sphere3DOverlay.cpp @@ -42,14 +42,29 @@ void Sphere3DOverlay::render(RenderArgs* args) { Transform transform = _transform; transform.postScale(getDimensions() * SPHERE_OVERLAY_SCALE); batch->setModelTransform(transform); + + auto geometryCache = DependencyManager::get(); + auto pipeline = args->_pipeline; + if (!pipeline) { + pipeline = geometryCache->getShapePipeline(); + } + if (_isSolid) { - DependencyManager::get()->renderSolidSphereInstance(*batch, sphereColor); + geometryCache->renderSolidSphereInstance(*batch, sphereColor, pipeline); } else { - DependencyManager::get()->renderWireSphereInstance(*batch, sphereColor); + geometryCache->renderWireSphereInstance(*batch, sphereColor, pipeline); } } } +const render::ShapeKey Sphere3DOverlay::getShapeKey() { + auto builder = render::ShapeKey::Builder(); + if (getAlpha() != 1.0f) { + builder.withTranslucent(); + } + return builder.build(); +} + Sphere3DOverlay* Sphere3DOverlay::createClone() const { return new Sphere3DOverlay(this); } diff --git a/interface/src/ui/overlays/Sphere3DOverlay.h b/interface/src/ui/overlays/Sphere3DOverlay.h index d371077502..ff8dfab778 100644 --- a/interface/src/ui/overlays/Sphere3DOverlay.h +++ b/interface/src/ui/overlays/Sphere3DOverlay.h @@ -24,6 +24,7 @@ public: Sphere3DOverlay(const Sphere3DOverlay* Sphere3DOverlay); virtual void render(RenderArgs* args); + virtual const render::ShapeKey Sphere3DOverlay::getShapeKey() override; virtual Sphere3DOverlay* createClone() const; }; diff --git a/interface/src/ui/overlays/Text3DOverlay.cpp b/interface/src/ui/overlays/Text3DOverlay.cpp index 2e5110951d..c8ffa5243d 100644 --- a/interface/src/ui/overlays/Text3DOverlay.cpp +++ b/interface/src/ui/overlays/Text3DOverlay.cpp @@ -8,8 +8,10 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // + #include "Text3DOverlay.h" +#include #include #include #include @@ -34,6 +36,7 @@ Text3DOverlay::Text3DOverlay() : _bottomMargin(DEFAULT_MARGIN) { _textRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE); + _alpha = _backgroundAlpha; } Text3DOverlay::Text3DOverlay(const Text3DOverlay* text3DOverlay) : @@ -47,7 +50,8 @@ Text3DOverlay::Text3DOverlay(const Text3DOverlay* text3DOverlay) : _rightMargin(text3DOverlay->_rightMargin), _bottomMargin(text3DOverlay->_bottomMargin) { - _textRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE); + _textRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE); + _alpha = _backgroundAlpha; } Text3DOverlay::~Text3DOverlay() { @@ -100,7 +104,6 @@ void Text3DOverlay::render(RenderArgs* args) { glm::vec3 topLeft(-halfDimensions.x, -halfDimensions.y, SLIGHTLY_BEHIND); glm::vec3 bottomRight(halfDimensions.x, halfDimensions.y, SLIGHTLY_BEHIND); - DependencyManager::get()->bindSimpleProgram(batch, false, true, false, true); DependencyManager::get()->renderQuad(batch, topLeft, bottomRight, quadColor); // Same font properties as textSize() @@ -120,7 +123,15 @@ void Text3DOverlay::render(RenderArgs* args) { glm::vec4 textColor = { _color.red / MAX_COLOR, _color.green / MAX_COLOR, _color.blue / MAX_COLOR, getAlpha() }; - _textRenderer->draw(batch, 0, 0, _text, textColor); + _textRenderer->draw(batch, 0, 0, _text, textColor, glm::vec2(-1.0f), getDrawInFront()); +} + +const render::ShapeKey Text3DOverlay::getShapeKey() { + auto builder = render::ShapeKey::Builder(); + if (getAlpha() != 1.0f) { + builder.withTranslucent(); + } + return builder.build(); } void Text3DOverlay::setProperties(const QScriptValue& properties) { @@ -145,6 +156,7 @@ void Text3DOverlay::setProperties(const QScriptValue& properties) { if (properties.property("backgroundAlpha").isValid()) { _backgroundAlpha = properties.property("backgroundAlpha").toVariant().toFloat(); + _alpha = _backgroundAlpha; } if (properties.property("lineHeight").isValid()) { diff --git a/interface/src/ui/overlays/Text3DOverlay.h b/interface/src/ui/overlays/Text3DOverlay.h index 5bd87e766a..f8ca134aa9 100644 --- a/interface/src/ui/overlays/Text3DOverlay.h +++ b/interface/src/ui/overlays/Text3DOverlay.h @@ -31,6 +31,8 @@ public: virtual void update(float deltatime); + virtual const render::ShapeKey getShapeKey() override; + // getters const QString& getText() const { return _text; } float getLineHeight() const { return _lineHeight; } @@ -72,5 +74,4 @@ private: float _bottomMargin; }; - #endif // hifi_Text3DOverlay_h diff --git a/interface/src/ui/overlays/Web3DOverlay.cpp b/interface/src/ui/overlays/Web3DOverlay.cpp index 1ec502139b..24f70a233f 100644 --- a/interface/src/ui/overlays/Web3DOverlay.cpp +++ b/interface/src/ui/overlays/Web3DOverlay.cpp @@ -101,11 +101,18 @@ void Web3DOverlay::render(RenderArgs* args) { } batch.setModelTransform(transform); - DependencyManager::get()->bindSimpleProgram(batch, true, false, false, true); DependencyManager::get()->renderQuad(batch, halfSize * -1.0f, halfSize, vec2(0), vec2(1), color); batch.setResourceTexture(0, args->_whiteTexture); // restore default white color after me } +const render::ShapeKey Web3DOverlay::getShapeKey() { + auto builder = render::ShapeKey::Builder().withNoCull().withDepthBias(); + if (getAlpha() != 1.0f) { + builder.withTranslucent(); + } + return builder.build(); +} + void Web3DOverlay::setProperties(const QScriptValue &properties) { Billboard3DOverlay::setProperties(properties); diff --git a/interface/src/ui/overlays/Web3DOverlay.h b/interface/src/ui/overlays/Web3DOverlay.h index bab2a1b55a..ef1c44108f 100644 --- a/interface/src/ui/overlays/Web3DOverlay.h +++ b/interface/src/ui/overlays/Web3DOverlay.h @@ -25,6 +25,7 @@ public: virtual ~Web3DOverlay(); virtual void render(RenderArgs* args); + virtual const render::ShapeKey Web3DOverlay::getShapeKey() override; virtual void update(float deltatime); From 3fceaba2fe06f7740fb645997bf07f1aef75e873 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 4 Feb 2016 10:01:34 -0800 Subject: [PATCH 11/26] Remove extra qualifications to getShapeKey from overlay headers --- interface/src/ui/overlays/Circle3DOverlay.h | 2 +- interface/src/ui/overlays/Cube3DOverlay.h | 2 +- interface/src/ui/overlays/Grid3DOverlay.h | 2 +- interface/src/ui/overlays/Image3DOverlay.h | 2 +- interface/src/ui/overlays/Line3DOverlay.h | 2 +- interface/src/ui/overlays/Rectangle3DOverlay.h | 2 +- interface/src/ui/overlays/Sphere3DOverlay.h | 2 +- interface/src/ui/overlays/Web3DOverlay.h | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/interface/src/ui/overlays/Circle3DOverlay.h b/interface/src/ui/overlays/Circle3DOverlay.h index 6c6ab965d0..7050da3368 100644 --- a/interface/src/ui/overlays/Circle3DOverlay.h +++ b/interface/src/ui/overlays/Circle3DOverlay.h @@ -25,7 +25,7 @@ public: Circle3DOverlay(const Circle3DOverlay* circle3DOverlay); virtual void render(RenderArgs* args); - virtual const render::ShapeKey Circle3DOverlay::getShapeKey() override; + virtual const render::ShapeKey getShapeKey() override; virtual void setProperties(const QScriptValue& properties); virtual QScriptValue getProperty(const QString& property); diff --git a/interface/src/ui/overlays/Cube3DOverlay.h b/interface/src/ui/overlays/Cube3DOverlay.h index 1ef667ff4a..30b6646362 100644 --- a/interface/src/ui/overlays/Cube3DOverlay.h +++ b/interface/src/ui/overlays/Cube3DOverlay.h @@ -24,7 +24,7 @@ public: Cube3DOverlay(const Cube3DOverlay* cube3DOverlay); virtual void render(RenderArgs* args); - virtual const render::ShapeKey Cube3DOverlay::getShapeKey() override; + virtual const render::ShapeKey getShapeKey() override; virtual Cube3DOverlay* createClone() const; diff --git a/interface/src/ui/overlays/Grid3DOverlay.h b/interface/src/ui/overlays/Grid3DOverlay.h index e254ad88fe..f9744f3954 100644 --- a/interface/src/ui/overlays/Grid3DOverlay.h +++ b/interface/src/ui/overlays/Grid3DOverlay.h @@ -25,7 +25,7 @@ public: Grid3DOverlay(const Grid3DOverlay* grid3DOverlay); virtual void render(RenderArgs* args); - virtual const render::ShapeKey Grid3DOverlay::getShapeKey() override; + virtual const render::ShapeKey getShapeKey() override; virtual void setProperties(const QScriptValue& properties); virtual QScriptValue getProperty(const QString& property); diff --git a/interface/src/ui/overlays/Image3DOverlay.h b/interface/src/ui/overlays/Image3DOverlay.h index 9ec4f7e29c..0b0b245872 100644 --- a/interface/src/ui/overlays/Image3DOverlay.h +++ b/interface/src/ui/overlays/Image3DOverlay.h @@ -31,7 +31,7 @@ public: virtual void update(float deltatime); - virtual const render::ShapeKey Image3DOverlay::getShapeKey() override; + virtual const render::ShapeKey getShapeKey() override; // setters void setURL(const QString& url); diff --git a/interface/src/ui/overlays/Line3DOverlay.h b/interface/src/ui/overlays/Line3DOverlay.h index 361f83e3b0..b40ff78231 100644 --- a/interface/src/ui/overlays/Line3DOverlay.h +++ b/interface/src/ui/overlays/Line3DOverlay.h @@ -24,7 +24,7 @@ public: Line3DOverlay(const Line3DOverlay* line3DOverlay); ~Line3DOverlay(); virtual void render(RenderArgs* args); - virtual const render::ShapeKey Line3DOverlay::getShapeKey() override; + virtual const render::ShapeKey getShapeKey() override; virtual AABox getBounds() const; // getters diff --git a/interface/src/ui/overlays/Rectangle3DOverlay.h b/interface/src/ui/overlays/Rectangle3DOverlay.h index d2a40a899b..cde4ad2f53 100644 --- a/interface/src/ui/overlays/Rectangle3DOverlay.h +++ b/interface/src/ui/overlays/Rectangle3DOverlay.h @@ -24,7 +24,7 @@ public: Rectangle3DOverlay(const Rectangle3DOverlay* rectangle3DOverlay); ~Rectangle3DOverlay(); virtual void render(RenderArgs* args); - virtual const render::ShapeKey Rectangle3DOverlay::getShapeKey() override; + virtual const render::ShapeKey getShapeKey() override; virtual void setProperties(const QScriptValue& properties); virtual Rectangle3DOverlay* createClone() const; diff --git a/interface/src/ui/overlays/Sphere3DOverlay.h b/interface/src/ui/overlays/Sphere3DOverlay.h index ff8dfab778..ec2efa9f04 100644 --- a/interface/src/ui/overlays/Sphere3DOverlay.h +++ b/interface/src/ui/overlays/Sphere3DOverlay.h @@ -24,7 +24,7 @@ public: Sphere3DOverlay(const Sphere3DOverlay* Sphere3DOverlay); virtual void render(RenderArgs* args); - virtual const render::ShapeKey Sphere3DOverlay::getShapeKey() override; + virtual const render::ShapeKey getShapeKey() override; virtual Sphere3DOverlay* createClone() const; }; diff --git a/interface/src/ui/overlays/Web3DOverlay.h b/interface/src/ui/overlays/Web3DOverlay.h index ef1c44108f..b1715dff46 100644 --- a/interface/src/ui/overlays/Web3DOverlay.h +++ b/interface/src/ui/overlays/Web3DOverlay.h @@ -25,7 +25,7 @@ public: virtual ~Web3DOverlay(); virtual void render(RenderArgs* args); - virtual const render::ShapeKey Web3DOverlay::getShapeKey() override; + virtual const render::ShapeKey getShapeKey() override; virtual void update(float deltatime); From 0c31c072a35f26a208eef669089a672973fd026e Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 4 Feb 2016 10:03:35 -0800 Subject: [PATCH 12/26] Fix -Wreorder for DrawOverlay3D ctor --- libraries/render-utils/src/RenderDeferredTask.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index 87a4cce9ee..5d97de3905 100755 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -108,8 +108,8 @@ public: void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext); protected: - render::ShapePlumberPointer _shapePlumber; render::ItemFilter _filter; + render::ShapePlumberPointer _shapePlumber; int _maxDrawn; // initialized by Config }; From 9e7e6be5497f697f32b373ddb4ce7747fd4effd7 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 4 Feb 2016 10:06:07 -0800 Subject: [PATCH 13/26] Fix -Wunused-variable for MeshPart ShapeKeys --- libraries/render-utils/src/MeshPartPayload.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libraries/render-utils/src/MeshPartPayload.cpp b/libraries/render-utils/src/MeshPartPayload.cpp index dfa306e209..c0003219a0 100644 --- a/libraries/render-utils/src/MeshPartPayload.cpp +++ b/libraries/render-utils/src/MeshPartPayload.cpp @@ -225,8 +225,6 @@ void MeshPartPayload::render(RenderArgs* args) const { gpu::Batch& batch = *(args->_batch); - ShapeKey key = getShapeKey(); - auto locations = args->_pipeline->locations; assert(locations); @@ -468,8 +466,7 @@ void ModelMeshPartPayload::render(RenderArgs* args) const { gpu::Batch& batch = *(args->_batch); - ShapeKey key = getShapeKey(); - if (!key.isValid()) { + if (!getShapeKey().isValid()) { return; } From cb06d4a9e451ed62671a62f13d648fc59478179f Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 4 Feb 2016 10:13:35 -0800 Subject: [PATCH 14/26] Fix -Wunused-variable for geometry solid stream formats --- libraries/render-utils/src/GeometryCache.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 3d0b68abeb..c63d24973f 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -477,7 +477,6 @@ void GeometryCache::buildShapes() { gpu::Stream::FormatPointer& getSolidStreamFormat() { if (!SOLID_STREAM_FORMAT) { - const int VERTEX_NORMAL_OFFSET = POSITION_ELEMENT.getSize(); SOLID_STREAM_FORMAT = std::make_shared(); // 1 for everyone SOLID_STREAM_FORMAT->setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, POSITION_ELEMENT); SOLID_STREAM_FORMAT->setAttribute(gpu::Stream::NORMAL, gpu::Stream::NORMAL, NORMAL_ELEMENT); @@ -487,7 +486,6 @@ gpu::Stream::FormatPointer& getSolidStreamFormat() { gpu::Stream::FormatPointer& getInstancedSolidStreamFormat() { if (!INSTANCED_SOLID_STREAM_FORMAT) { - const int VERTEX_NORMAL_OFFSET = POSITION_ELEMENT.getSize(); INSTANCED_SOLID_STREAM_FORMAT = std::make_shared(); // 1 for everyone INSTANCED_SOLID_STREAM_FORMAT->setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, POSITION_ELEMENT); INSTANCED_SOLID_STREAM_FORMAT->setAttribute(gpu::Stream::NORMAL, gpu::Stream::NORMAL, NORMAL_ELEMENT); From f0797d8ea0408b69aaac88dbae8e2acfb61967da Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 4 Feb 2016 15:32:28 -0800 Subject: [PATCH 15/26] Move instanced pipeline setup to lambda from batch --- libraries/gpu/src/gpu/Batch.h | 2 -- libraries/render-utils/src/GeometryCache.cpp | 11 +++++++---- libraries/render/src/render/ShapePipeline.cpp | 5 ----- libraries/render/src/render/ShapePipeline.h | 6 +++--- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index 6b8816d50a..a2ee57759f 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -73,12 +73,10 @@ public: BufferPointers buffers; Function function; DrawCallInfoBuffer drawCallInfos; - Pipeline::Pointer pipeline; size_t count() const { return drawCallInfos.size(); } void process(Batch& batch) { - batch.setPipeline(pipeline); if (function) { function(batch, *this); } diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index c63d24973f..f943ee6d00 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1925,16 +1925,19 @@ uint32_t toCompactColor(const glm::vec4& color) { static const size_t INSTANCE_COLOR_BUFFER = 0; -template -void renderInstances(const std::string& name, gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline, F f) { +void renderInstances(const std::string& name, gpu::Batch& batch, const glm::vec4& color, + const render::ShapePipelinePointer& pipeline, gpu::Batch::NamedBatchData::Function f) { + // Add color to named buffer { gpu::BufferPointer instanceColorBuffer = batch.getNamedBuffer(name, INSTANCE_COLOR_BUFFER); auto compactColor = toCompactColor(color); instanceColorBuffer->append(compactColor); } - + + // Add call to named buffer batch.setupNamedCalls(name, [f, pipeline](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { - batch.setPipeline(pipeline->get(batch)); + batch.setPipeline(pipeline->pipeline); + pipeline->prepare(batch); f(batch, data); }); } diff --git a/libraries/render/src/render/ShapePipeline.cpp b/libraries/render/src/render/ShapePipeline.cpp index 9108d31757..588b02a316 100644 --- a/libraries/render/src/render/ShapePipeline.cpp +++ b/libraries/render/src/render/ShapePipeline.cpp @@ -22,11 +22,6 @@ ShapeKey::Filter::Builder::Builder() { _mask.set(INVALID); } -gpu::PipelinePointer ShapePipeline::get(gpu::Batch& batch) { - batchSetter(*this, batch); - return this->pipeline; -} - void ShapePlumber::addPipelineHelper(const Filter& filter, ShapeKey key, int bit, const PipelinePointer& pipeline) { // Iterate over all keys if (bit < (int)ShapeKey::FlagBit::NUM_FLAGS) { diff --git a/libraries/render/src/render/ShapePipeline.h b/libraries/render/src/render/ShapePipeline.h index 8993fcfcc8..d35f3a500a 100644 --- a/libraries/render/src/render/ShapePipeline.h +++ b/libraries/render/src/render/ShapePipeline.h @@ -223,9 +223,9 @@ public: ShapePipeline(gpu::PipelinePointer pipeline, LocationsPointer locations, BatchSetter batchSetter) : pipeline(pipeline), locations(locations), batchSetter(batchSetter) {} - // Normally, a pipeline is accessed thorugh pickPipeline. If it needs to be accessed manually, - // this method preps the pipeline with defaults set by its batchSetter and returns only the gpu::Pipeline. - gpu::PipelinePointer get(gpu::Batch& batch); + // Normally, a pipeline is accessed thorugh pickPipeline. If it needs to be set manually, + // after calling setPipeline this method should be called to prepare the pipeline with default buffers. + void prepare(gpu::Batch& batch) { batchSetter(*this, batch); } gpu::PipelinePointer pipeline; std::shared_ptr locations; From 44d297e7e24674ce5034b6ccb993aed37df4a906 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 4 Feb 2016 15:32:47 -0800 Subject: [PATCH 16/26] Differentiate named calls by pipeline --- libraries/render-utils/src/GeometryCache.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index f943ee6d00..0545dd3053 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1927,15 +1927,18 @@ static const size_t INSTANCE_COLOR_BUFFER = 0; void renderInstances(const std::string& name, gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline, gpu::Batch::NamedBatchData::Function f) { + // Add pipeline to name + std::string instanceName = name + std::to_string(std::hash()(pipeline)); + // Add color to named buffer { - gpu::BufferPointer instanceColorBuffer = batch.getNamedBuffer(name, INSTANCE_COLOR_BUFFER); + gpu::BufferPointer instanceColorBuffer = batch.getNamedBuffer(instanceName, INSTANCE_COLOR_BUFFER); auto compactColor = toCompactColor(color); instanceColorBuffer->append(compactColor); } // Add call to named buffer - batch.setupNamedCalls(name, [f, pipeline](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { + batch.setupNamedCalls(instanceName, [f, pipeline](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { batch.setPipeline(pipeline->pipeline); pipeline->prepare(batch); f(batch, data); From a4cea0a307c34c5596b5fe8ecc066c67c26bda06 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 4 Feb 2016 16:21:56 -0800 Subject: [PATCH 17/26] Conform model/overlay shaders --- libraries/render-utils/src/model.slv | 9 +++------ .../render-utils/src/model_translucent.slf | 17 ++++++----------- libraries/render-utils/src/overlay3D.slv | 12 ++++++------ 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/libraries/render-utils/src/model.slv b/libraries/render-utils/src/model.slv index d2f45ec66a..0507f1c6c5 100755 --- a/libraries/render-utils/src/model.slv +++ b/libraries/render-utils/src/model.slv @@ -1,7 +1,7 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> -// model.vert +// model.slv // vertex shader // // Created by Andrzej Kapolka on 10/14/13. @@ -17,21 +17,18 @@ <$declareStandardTransform()$> const int MAX_TEXCOORDS = 2; - uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; -out vec4 _position; -out vec3 _normal; out vec3 _color; out float _alpha; out vec2 _texCoord0; +out vec4 _position; +out vec3 _normal; void main(void) { - // pass along the diffuse color in linear space _color = colorToLinearRGB(inColor.xyz); _alpha = inColor.w; - // and the texture coordinates _texCoord0 = (texcoordMatrices[0] * vec4(inTexCoord0.st, 0.0, 1.0)).st; // standard transform diff --git a/libraries/render-utils/src/model_translucent.slf b/libraries/render-utils/src/model_translucent.slf index 42476ccc9a..75a18dec75 100755 --- a/libraries/render-utils/src/model_translucent.slf +++ b/libraries/render-utils/src/model_translucent.slf @@ -11,17 +11,15 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // + <@include model/Material.slh@> -// Everything about global lighting - <@include DeferredLighting.slh@> +<@include model/Light.slh@> + <@include gpu/Transform.slh@> <$declareStandardCameraTransform()$> -// Everything about light -<@include model/Light.slh@> - vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 diffuse, vec3 specular, float gloss, float opacity) { // Need the light now @@ -42,11 +40,10 @@ vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 d return vec4(color, opacity); } -// the diffuse texture uniform sampler2D diffuseMap; -in vec4 _position; in vec2 _texCoord0; +in vec4 _position; in vec3 _normal; in vec3 _color; in float _alpha; @@ -54,17 +51,15 @@ in float _alpha; out vec4 _fragColor; void main(void) { - vec3 fragPosition = _position.xyz; - - // Fetch diffuse map vec4 diffuse = texture(diffuseMap, _texCoord0); Material mat = getMaterial(); + vec3 fragPosition = _position.xyz; vec3 fragNormal = normalize(_normal); - float fragOpacity = getMaterialOpacity(mat) * diffuse.a * _alpha; vec3 fragDiffuse = getMaterialDiffuse(mat) * diffuse.rgb * _color; vec3 fragSpecular = getMaterialSpecular(mat); float fragGloss = getMaterialShininess(mat); + float fragOpacity = getMaterialOpacity(mat) * diffuse.a * _alpha; _fragColor = evalGlobalColor(1.0, fragPosition, diff --git a/libraries/render-utils/src/overlay3D.slv b/libraries/render-utils/src/overlay3D.slv index d23f9c5c88..d39e5a2f01 100644 --- a/libraries/render-utils/src/overlay3D.slv +++ b/libraries/render-utils/src/overlay3D.slv @@ -2,6 +2,7 @@ <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // overlay3D.slv +// vertex shader // // Created by Sam Gateau on 6/16/15. // Copyright 2015 High Fidelity, Inc. @@ -15,22 +16,21 @@ <@include gpu/Transform.slh@> <$declareStandardTransform()$> +out vec3 _color; +out float _alpha; out vec2 _texCoord0; - out vec4 _position; out vec3 _normal; -out vec3 _color; -out float _alpha; - void main(void) { - _texCoord0 = inTexCoord0.xy; _color = colorToLinearRGB(inColor.xyz); _alpha = inColor.w; + _texCoord0 = inTexCoord0.st; + // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); <$transformModelToEyeAndClipPos(cam, obj, inPosition, _position, gl_Position)$> - <$transformModelToEyeDir(cam, obj, inNormal.xyz, _normal.xyz)$> + <$transformModelToEyeDir(cam, obj, inNormal.xyz, _normal)$> } From aa50d1e98e97f0a3688825581676df320d130c57 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 4 Feb 2016 17:51:23 -0800 Subject: [PATCH 18/26] Add factor and shading to overlay/translucent light shaders --- libraries/render-utils/src/model_translucent.slf | 4 ++-- libraries/render-utils/src/overlay3D.slf | 5 +++-- libraries/render-utils/src/overlay3D_translucent.slf | 6 ++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/libraries/render-utils/src/model_translucent.slf b/libraries/render-utils/src/model_translucent.slf index 75a18dec75..c6f745ed0f 100755 --- a/libraries/render-utils/src/model_translucent.slf +++ b/libraries/render-utils/src/model_translucent.slf @@ -35,7 +35,7 @@ vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 d vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, specular, gloss); - color += vec3(opacity * diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light); + color += vec3(diffuse * shading.w * opacity + shading.rgb) * shadowAttenuation * getLightColor(light) * getLightIntensity(light); return vec4(color, opacity); } @@ -58,7 +58,7 @@ void main(void) { vec3 fragNormal = normalize(_normal); vec3 fragDiffuse = getMaterialDiffuse(mat) * diffuse.rgb * _color; vec3 fragSpecular = getMaterialSpecular(mat); - float fragGloss = getMaterialShininess(mat); + float fragGloss = getMaterialShininess(mat) / 128; float fragOpacity = getMaterialOpacity(mat) * diffuse.a * _alpha; _fragColor = evalGlobalColor(1.0, diff --git a/libraries/render-utils/src/overlay3D.slf b/libraries/render-utils/src/overlay3D.slf index 9c37055f55..d859806643 100644 --- a/libraries/render-utils/src/overlay3D.slf +++ b/libraries/render-utils/src/overlay3D.slf @@ -31,7 +31,8 @@ vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 d vec3 color = opacity * diffuse.rgb * getLightColor(light) * getLightAmbientIntensity(light); vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, specular, gloss); - color += vec3(opacity * diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light); + + color += vec3(diffuse * shading.w * opacity + shading.rgb) * shadowAttenuation * getLightColor(light) * getLightIntensity(light); return vec4(color, opacity); } @@ -53,7 +54,7 @@ void main(void) { vec3 fragNormal = normalize(_normal); vec3 fragDiffuse = diffuse.rgb * _color; vec3 fragSpecular = vec3(0.1); - float fragGloss = 10; + float fragGloss = 10.0 / 128.0; float fragOpacity = diffuse.a; if (fragOpacity <= 0.1) { diff --git a/libraries/render-utils/src/overlay3D_translucent.slf b/libraries/render-utils/src/overlay3D_translucent.slf index 96637687c1..9d66b9e57f 100644 --- a/libraries/render-utils/src/overlay3D_translucent.slf +++ b/libraries/render-utils/src/overlay3D_translucent.slf @@ -1,6 +1,7 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> +// // overlay3D_translucent.slf // fragment shader // @@ -31,7 +32,8 @@ vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 d vec3 color = opacity * diffuse.rgb * getLightColor(light) * getLightAmbientIntensity(light); vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, specular, gloss); - color += vec3(opacity * diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light); + + color += vec3(diffuse * shading.w * opacity + shading.rgb) * shadowAttenuation * getLightColor(light) * getLightIntensity(light); return vec4(color, opacity); } @@ -53,7 +55,7 @@ void main(void) { vec3 fragNormal = normalize(_normal); vec3 fragDiffuse = diffuse.rgb * _color; vec3 fragSpecular = vec3(0.1); - float fragGloss = 10; + float fragGloss = 10.0 / 128.0; float fragOpacity = diffuse.a * _alpha; _fragColor = evalGlobalColor(1.0, From a1ed29e6f81eb8aa8f85df24c2148dc1d1a3e54c Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Fri, 5 Feb 2016 10:53:01 -0800 Subject: [PATCH 19/26] Rename setupTransparent->setupBatch --- libraries/render-utils/src/DeferredLightingEffect.cpp | 4 ++-- libraries/render-utils/src/DeferredLightingEffect.h | 2 +- libraries/render-utils/src/RenderPipelines.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 11c5031b95..003c309740 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -511,8 +511,8 @@ void DeferredLightingEffect::render(const render::RenderContextPointer& renderCo } } -void DeferredLightingEffect::setupTransparent(gpu::Batch& batch, int lightBufferUnit) { - PerformanceTimer perfTimer("DLE->setupTransparent()"); +void DeferredLightingEffect::setupBatch(gpu::Batch& batch, int lightBufferUnit) { + PerformanceTimer perfTimer("DLE->setupBatch()"); auto globalLight = _allocatedLights[_globalLights.front()]; batch.setUniformBuffer(lightBufferUnit, globalLight->getSchemaBuffer()); } diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index c3970dfc96..6ef5794d95 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -46,7 +46,7 @@ public: void prepare(RenderArgs* args); void render(const render::RenderContextPointer& renderContext); - void setupTransparent(gpu::Batch& batch, int lightBufferUnit); + void setupBatch(gpu::Batch& batch, int lightBufferUnit); // update global lighting void setAmbientLightMode(int preset); diff --git a/libraries/render-utils/src/RenderPipelines.cpp b/libraries/render-utils/src/RenderPipelines.cpp index 48c7ee4f9b..8404854e28 100644 --- a/libraries/render-utils/src/RenderPipelines.cpp +++ b/libraries/render-utils/src/RenderPipelines.cpp @@ -96,7 +96,7 @@ void lightBatchSetter(const ShapePipeline& pipeline, gpu::Batch& batch) { batchSetter(pipeline, batch); // Set the light if (pipeline.locations->lightBufferUnit >= 0) { - DependencyManager::get()->setupTransparent(batch, pipeline.locations->lightBufferUnit); + DependencyManager::get()->setupBatch(batch, pipeline.locations->lightBufferUnit); } } From b0a9c299edb52c8d4e3eae4509a8883fe39fb02e Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Fri, 5 Feb 2016 11:18:42 -0800 Subject: [PATCH 20/26] Add tone mapping to overlay shaders --- libraries/render-utils/src/overlay3D.slf | 5 ++++- libraries/render-utils/src/overlay3D_translucent.slf | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libraries/render-utils/src/overlay3D.slf b/libraries/render-utils/src/overlay3D.slf index d859806643..66a48e95f4 100644 --- a/libraries/render-utils/src/overlay3D.slf +++ b/libraries/render-utils/src/overlay3D.slf @@ -61,11 +61,14 @@ void main(void) { discard; } - _fragColor = evalGlobalColor(1.0, + vec4 color = evalGlobalColor(1.0, fragPosition, fragNormal, fragDiffuse, fragSpecular, fragGloss, fragOpacity); + + // Apply standard tone mapping + _fragColor = vec4(pow(color.xyz, vec3(1.0 / 2.2)), color.w); } diff --git a/libraries/render-utils/src/overlay3D_translucent.slf b/libraries/render-utils/src/overlay3D_translucent.slf index 9d66b9e57f..dcc15ba25b 100644 --- a/libraries/render-utils/src/overlay3D_translucent.slf +++ b/libraries/render-utils/src/overlay3D_translucent.slf @@ -58,11 +58,14 @@ void main(void) { float fragGloss = 10.0 / 128.0; float fragOpacity = diffuse.a * _alpha; - _fragColor = evalGlobalColor(1.0, + vec4 color = evalGlobalColor(1.0, fragPosition, fragNormal, fragDiffuse, fragSpecular, fragGloss, fragOpacity); + + // Apply standard tone mapping + _fragColor = vec4(pow(color.xyz, vec3(1.0 / 2.2)), color.w); } From d9132f397316c07c7148ec845fda870e6fcfb950 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Fri, 5 Feb 2016 11:22:45 -0800 Subject: [PATCH 21/26] Clean up geometry instanced calls --- libraries/render-utils/src/GeometryCache.cpp | 51 ++++++-------------- libraries/render-utils/src/GeometryCache.h | 11 ++--- 2 files changed, 19 insertions(+), 43 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 0545dd3053..ed6b8f2f5b 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -548,14 +548,6 @@ void GeometryCache::renderWireShapeInstances(gpu::Batch& batch, Shape shape, siz _shapes[shape].drawWireInstances(batch, count); } -void GeometryCache::renderCubeInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer colorBuffer) { - renderShapeInstances(batch, Cube, count, colorBuffer); -} - -void GeometryCache::renderWireCubeInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer colorBuffer) { - renderWireShapeInstances(batch, Cube, count, colorBuffer); -} - void GeometryCache::renderCube(gpu::Batch& batch) { renderShape(batch, Cube); } @@ -564,10 +556,6 @@ void GeometryCache::renderWireCube(gpu::Batch& batch) { renderWireShape(batch, Cube); } -void GeometryCache::renderSphereInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer colorBuffer) { - renderShapeInstances(batch, Sphere, count, colorBuffer); -} - void GeometryCache::renderSphere(gpu::Batch& batch) { renderShape(batch, Sphere); } @@ -1925,8 +1913,8 @@ uint32_t toCompactColor(const glm::vec4& color) { static const size_t INSTANCE_COLOR_BUFFER = 0; -void renderInstances(const std::string& name, gpu::Batch& batch, const glm::vec4& color, - const render::ShapePipelinePointer& pipeline, gpu::Batch::NamedBatchData::Function f) { +void renderInstances(const std::string& name, gpu::Batch& batch, const glm::vec4& color, bool isWire, + const render::ShapePipelinePointer& pipeline, GeometryCache::Shape shape) { // Add pipeline to name std::string instanceName = name + std::to_string(std::hash()(pipeline)); @@ -1938,27 +1926,26 @@ void renderInstances(const std::string& name, gpu::Batch& batch, const glm::vec4 } // Add call to named buffer - batch.setupNamedCalls(instanceName, [f, pipeline](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { + batch.setupNamedCalls(instanceName, [isWire, pipeline, shape](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { batch.setPipeline(pipeline->pipeline); pipeline->prepare(batch); - f(batch, data); + + if (isWire) { + DependencyManager::get()->renderWireShapeInstances(batch, shape, data.count(), data.buffers[INSTANCE_COLOR_BUFFER]); + } else { + DependencyManager::get()->renderShapeInstances(batch, shape, data.count(), data.buffers[INSTANCE_COLOR_BUFFER]); + } }); } void GeometryCache::renderSolidSphereInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { static const std::string INSTANCE_NAME = __FUNCTION__; - renderInstances(INSTANCE_NAME, batch, color, pipeline, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { - DependencyManager::get()->renderShapeInstances(batch, GeometryCache::Sphere, data.count(), - data.buffers[INSTANCE_COLOR_BUFFER]); - }); + renderInstances(INSTANCE_NAME, batch, color, false, pipeline, GeometryCache::Sphere); } void GeometryCache::renderWireSphereInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { static const std::string INSTANCE_NAME = __FUNCTION__; - renderInstances(INSTANCE_NAME, batch, color, pipeline, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { - DependencyManager::get()->renderWireShapeInstances(batch, GeometryCache::Sphere, data.count(), - data.buffers[INSTANCE_COLOR_BUFFER]); - }); + renderInstances(INSTANCE_NAME, batch, color, true, pipeline, GeometryCache::Sphere); } // Enable this in a debug build to cause 'box' entities to iterate through all the @@ -1995,25 +1982,17 @@ void GeometryCache::renderSolidCubeInstance(gpu::Batch& batch, const glm::vec4& // For the first half second for a given shape, show the wireframe, for the second half, show the solid. if (fractionalSeconds > 0.5f) { - DependencyManager::get()->renderShapeInstances(batch, shape, data.count(), - data.buffers[INSTANCE_COLOR_BUFFER]); + renderInstances(INSTANCE_NAME, batch, color, true, pipeline, shape); } else { - DependencyManager::get()->renderWireShapeInstances(batch, shape, data.count(), - data.buffers[INSTANCE_COLOR_BUFFER]); + renderInstances(INSTANCE_NAME, batch, color, false, pipeline, shape); } }); #else - renderInstances(INSTANCE_NAME, batch, color, pipeline, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { - DependencyManager::get()->renderCubeInstances(batch, data.count(), - data.buffers[INSTANCE_COLOR_BUFFER]); - }); + renderInstances(INSTANCE_NAME, batch, color, false, pipeline, GeometryCache::Cube); #endif } void GeometryCache::renderWireCubeInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { static const std::string INSTANCE_NAME = __FUNCTION__; - renderInstances(INSTANCE_NAME, batch, color, pipeline, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { - DependencyManager::get()->renderWireCubeInstances(batch, data.count(), - data.buffers[INSTANCE_COLOR_BUFFER]); - }); + renderInstances(INSTANCE_NAME, batch, color, true, pipeline, GeometryCache::Cube); } diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 5de08ea717..1f434d1a5d 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -158,7 +158,10 @@ public: bool emissive = false, bool depthBias = false); render::ShapePipelinePointer getShapePipeline() { return GeometryCache::_simplePipeline; } - // Static geometry + // Static (instanced) geometry + void renderShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& colorBuffer); + void renderWireShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& colorBuffer); + void renderSolidSphereInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline = _simplePipeline); void renderSolidSphereInstance(gpu::Batch& batch, const glm::vec3& color, @@ -188,20 +191,14 @@ public: } // Dynamic geometry - void renderShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& colorBuffer); - void renderWireShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& colorBuffer); void renderShape(gpu::Batch& batch, Shape shape); void renderWireShape(gpu::Batch& batch, Shape shape); size_t getShapeTriangleCount(Shape shape); - void renderCubeInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer colorBuffer); - void renderWireCubeInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer colorBuffer); void renderCube(gpu::Batch& batch); void renderWireCube(gpu::Batch& batch); size_t getCubeTriangleCount(); - void renderSphereInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer colorBuffer); - void renderWireSphereInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer colorBuffer); void renderSphere(gpu::Batch& batch); void renderWireSphere(gpu::Batch& batch); size_t getSphereTriangleCount(); From 1d2acbe47e700a0c780d8e82e45ea6a14441174a Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 8 Feb 2016 13:28:14 -0800 Subject: [PATCH 22/26] Bring GeometryCache render*Instance up to standard --- libraries/render-utils/src/GeometryCache.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 1f434d1a5d..32cdec56bf 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -166,28 +166,28 @@ public: const render::ShapePipelinePointer& pipeline = _simplePipeline); void renderSolidSphereInstance(gpu::Batch& batch, const glm::vec3& color, const render::ShapePipelinePointer& pipeline = _simplePipeline) { - renderSolidSphereInstance(batch, glm::vec4(color, 1.0), pipeline); + renderSolidSphereInstance(batch, glm::vec4(color, 1.0f), pipeline); } void renderWireSphereInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline = _simplePipeline); void renderWireSphereInstance(gpu::Batch& batch, const glm::vec3& color, const render::ShapePipelinePointer& pipeline = _simplePipeline) { - renderWireSphereInstance(batch, glm::vec4(color, 1.0), pipeline); + renderWireSphereInstance(batch, glm::vec4(color, 1.0f), pipeline); } void renderSolidCubeInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline = _simplePipeline); void renderSolidCubeInstance(gpu::Batch& batch, const glm::vec3& color, const render::ShapePipelinePointer& pipeline = _simplePipeline) { - renderSolidCubeInstance(batch, glm::vec4(color, 1.0), pipeline); + renderSolidCubeInstance(batch, glm::vec4(color, 1.0f), pipeline); } void renderWireCubeInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline = _simplePipeline); void renderWireCubeInstance(gpu::Batch& batch, const glm::vec3& color, const render::ShapePipelinePointer& pipeline = _simplePipeline) { - renderWireCubeInstance(batch, glm::vec4(color, 1.0), pipeline); + renderWireCubeInstance(batch, glm::vec4(color, 1.0f), pipeline); } // Dynamic geometry From 9e5df79279aa83831908d5346575fe7596eddbb3 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 8 Feb 2016 13:31:12 -0800 Subject: [PATCH 23/26] Add tone-mapping to overlay emissive shader --- libraries/render-utils/src/overlay3D_emissive.slf | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/render-utils/src/overlay3D_emissive.slf b/libraries/render-utils/src/overlay3D_emissive.slf index 840ccb69f0..ad689baf91 100644 --- a/libraries/render-utils/src/overlay3D_emissive.slf +++ b/libraries/render-utils/src/overlay3D_emissive.slf @@ -25,5 +25,8 @@ void main(void) { if (diffuse.a <= 0.1) { discard; } - _fragColor = vec4(diffuse.rgb * _color, diffuse.a); + vec4 color = vec4(diffuse.rgb * _color, diffuse.a); + + // Apply standard tone mapping + _fragColor = vec4(pow(color.xyz, vec3(1.0 / 2.2)), color.w); } From a7bafed61b968a6ad9f9c83b9604e68ba69295b9 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 8 Feb 2016 13:44:42 -0800 Subject: [PATCH 24/26] Change ShapeKey::CULL to NO_CULL_FACE --- interface/src/ui/overlays/Circle3DOverlay.cpp | 2 +- interface/src/ui/overlays/Image3DOverlay.cpp | 2 +- interface/src/ui/overlays/Web3DOverlay.cpp | 2 +- libraries/render-utils/src/RenderPipelines.cpp | 6 +++--- libraries/render/src/render/ShapePipeline.h | 16 ++++++++-------- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/interface/src/ui/overlays/Circle3DOverlay.cpp b/interface/src/ui/overlays/Circle3DOverlay.cpp index 698d3680e1..252aacef43 100644 --- a/interface/src/ui/overlays/Circle3DOverlay.cpp +++ b/interface/src/ui/overlays/Circle3DOverlay.cpp @@ -278,7 +278,7 @@ void Circle3DOverlay::render(RenderArgs* args) { } const render::ShapeKey Circle3DOverlay::getShapeKey() { - auto builder = render::ShapeKey::Builder().withNoCull(); + auto builder = render::ShapeKey::Builder().withoutCullFace(); if (getAlpha() != 1.0f) { builder.withTranslucent(); } diff --git a/interface/src/ui/overlays/Image3DOverlay.cpp b/interface/src/ui/overlays/Image3DOverlay.cpp index 379560e2a5..66f7143e83 100644 --- a/interface/src/ui/overlays/Image3DOverlay.cpp +++ b/interface/src/ui/overlays/Image3DOverlay.cpp @@ -104,7 +104,7 @@ void Image3DOverlay::render(RenderArgs* args) { } const render::ShapeKey Image3DOverlay::getShapeKey() { - auto builder = render::ShapeKey::Builder().withNoCull().withDepthBias(); + auto builder = render::ShapeKey::Builder().withoutCullFace().withDepthBias(); if (_emissive) { builder.withEmissive(); } diff --git a/interface/src/ui/overlays/Web3DOverlay.cpp b/interface/src/ui/overlays/Web3DOverlay.cpp index 24f70a233f..7ceff81dd2 100644 --- a/interface/src/ui/overlays/Web3DOverlay.cpp +++ b/interface/src/ui/overlays/Web3DOverlay.cpp @@ -106,7 +106,7 @@ void Web3DOverlay::render(RenderArgs* args) { } const render::ShapeKey Web3DOverlay::getShapeKey() { - auto builder = render::ShapeKey::Builder().withNoCull().withDepthBias(); + auto builder = render::ShapeKey::Builder().withoutCullFace().withDepthBias(); if (getAlpha() != 1.0f) { builder.withTranslucent(); } diff --git a/libraries/render-utils/src/RenderPipelines.cpp b/libraries/render-utils/src/RenderPipelines.cpp index 8404854e28..fce9ce1c28 100644 --- a/libraries/render-utils/src/RenderPipelines.cpp +++ b/libraries/render-utils/src/RenderPipelines.cpp @@ -135,7 +135,7 @@ void initOverlay3DPipelines(ShapePlumber& plumber) { } ShapeKey::Filter::Builder builder; - isCulled ? builder.withCull() : builder.withoutCull(); + isCulled ? builder.withCullFace() : builder.withoutCullFace(); isBiased ? builder.withDepthBias() : builder.withoutDepthBias(); isOpaque ? builder.withOpaque() : builder.withTranslucent(); @@ -154,7 +154,7 @@ void initDeferredPipelines(render::ShapePlumber& plumber) { // These keyvalues' pipelines will be added by this lamdba in addition to the key passed assert(!key.isWireFrame()); assert(!key.isDepthBiased()); - assert(key.isCulled()); + assert(key.isCullFace()); ShaderPointer program = gpu::Shader::createProgram(vertexShader, pixelShader); @@ -173,7 +173,7 @@ void initDeferredPipelines(render::ShapePlumber& plumber) { gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); if (!isCulled) { - builder.withNoCull(); + builder.withoutCullFace(); } state->setCullMode(isCulled ? gpu::State::CULL_BACK : gpu::State::CULL_NONE); if (isWireframed) { diff --git a/libraries/render/src/render/ShapePipeline.h b/libraries/render/src/render/ShapePipeline.h index d35f3a500a..9b538395a0 100644 --- a/libraries/render/src/render/ShapePipeline.h +++ b/libraries/render/src/render/ShapePipeline.h @@ -30,7 +30,7 @@ public: DEPTH_ONLY, DEPTH_BIAS, WIREFRAME, - CULL, + NO_CULL_FACE, OWN_PIPELINE, INVALID, @@ -41,12 +41,12 @@ public: Flags _flags; - ShapeKey() : _flags{0} { _flags.set(CULL); } + ShapeKey() : _flags{ 0 } {} ShapeKey(const Flags& flags) : _flags{flags} {} class Builder { public: - Builder() { _flags.set(CULL); } + Builder() {} Builder(ShapeKey key) : _flags{key._flags} {} ShapeKey build() const { return ShapeKey{_flags}; } @@ -61,7 +61,7 @@ public: Builder& withDepthOnly() { _flags.set(DEPTH_ONLY); return (*this); } Builder& withDepthBias() { _flags.set(DEPTH_BIAS); return (*this); } Builder& withWireframe() { _flags.set(WIREFRAME); return (*this); } - Builder& withNoCull() { _flags.reset(CULL); return (*this); } + Builder& withoutCullFace() { _flags.reset(NO_CULL_FACE); return (*this); } Builder& withOwnPipeline() { _flags.set(OWN_PIPELINE); return (*this); } Builder& invalidate() { _flags.set(INVALID); return (*this); } @@ -117,8 +117,8 @@ public: Builder& withWireframe() { _flags.set(WIREFRAME); _mask.set(WIREFRAME); return (*this); } Builder& withoutWireframe() { _flags.reset(WIREFRAME); _mask.set(WIREFRAME); return (*this); } - Builder& withCull() { _flags.set(CULL); _mask.set(CULL); return (*this); } - Builder& withoutCull() { _flags.reset(CULL); _mask.set(CULL); return (*this); } + Builder& withCullFace() { _flags.reset(NO_CULL_FACE); _mask.set(NO_CULL_FACE); return (*this); } + Builder& withoutCullFace() { _flags.set(NO_CULL_FACE); _mask.set(NO_CULL_FACE); return (*this); } protected: friend class Filter; @@ -142,7 +142,7 @@ public: bool isDepthOnly() const { return _flags[DEPTH_ONLY]; } bool isDepthBiased() const { return _flags[DEPTH_BIAS]; } bool isWireFrame() const { return _flags[WIREFRAME]; } - bool isCulled() const { return _flags[CULL]; } + bool isCullFace() const { return !_flags[NO_CULL_FACE]; } bool hasOwnPipeline() const { return _flags[OWN_PIPELINE]; } bool isValid() const { return !_flags[INVALID]; } @@ -178,7 +178,7 @@ inline QDebug operator<<(QDebug debug, const ShapeKey& key) { << "isDepthOnly:" << key.isDepthOnly() << "isDepthBiased:" << key.isDepthBiased() << "isWireFrame:" << key.isWireFrame() - << "isCulled:" << key.isCulled() + << "isCullFace:" << key.isCullFace() << "]"; } } else { From 281ba3c3eac89f35e7e9f9b5be842023399e11a3 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 8 Feb 2016 16:14:03 -0800 Subject: [PATCH 25/26] Fix ShapeKey::withoutCullFace to set, not reset --- libraries/render/src/render/ShapePipeline.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render/src/render/ShapePipeline.h b/libraries/render/src/render/ShapePipeline.h index 9b538395a0..ef2020f062 100644 --- a/libraries/render/src/render/ShapePipeline.h +++ b/libraries/render/src/render/ShapePipeline.h @@ -61,7 +61,7 @@ public: Builder& withDepthOnly() { _flags.set(DEPTH_ONLY); return (*this); } Builder& withDepthBias() { _flags.set(DEPTH_BIAS); return (*this); } Builder& withWireframe() { _flags.set(WIREFRAME); return (*this); } - Builder& withoutCullFace() { _flags.reset(NO_CULL_FACE); return (*this); } + Builder& withoutCullFace() { _flags.set(NO_CULL_FACE); return (*this); } Builder& withOwnPipeline() { _flags.set(OWN_PIPELINE); return (*this); } Builder& invalidate() { _flags.set(INVALID); return (*this); } From 63d87550b1a7f003822345834632c5486a3613bc Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 8 Feb 2016 17:05:55 -0800 Subject: [PATCH 26/26] Guard batchSetter invocation for ShapePipelines --- libraries/render/src/render/ShapePipeline.cpp | 6 ++++++ libraries/render/src/render/ShapePipeline.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/render/src/render/ShapePipeline.cpp b/libraries/render/src/render/ShapePipeline.cpp index 588b02a316..b77c9c3451 100644 --- a/libraries/render/src/render/ShapePipeline.cpp +++ b/libraries/render/src/render/ShapePipeline.cpp @@ -17,6 +17,12 @@ using namespace render; +void ShapePipeline::prepare(gpu::Batch& batch) { + if (batchSetter) { + batchSetter(*this, batch); + } +} + ShapeKey::Filter::Builder::Builder() { _mask.set(OWN_PIPELINE); _mask.set(INVALID); diff --git a/libraries/render/src/render/ShapePipeline.h b/libraries/render/src/render/ShapePipeline.h index ef2020f062..4fd1dc22c5 100644 --- a/libraries/render/src/render/ShapePipeline.h +++ b/libraries/render/src/render/ShapePipeline.h @@ -225,7 +225,7 @@ public: // Normally, a pipeline is accessed thorugh pickPipeline. If it needs to be set manually, // after calling setPipeline this method should be called to prepare the pipeline with default buffers. - void prepare(gpu::Batch& batch) { batchSetter(*this, batch); } + void prepare(gpu::Batch& batch); gpu::PipelinePointer pipeline; std::shared_ptr locations;