From 8559ed6260f04c61d22eac76d9057e20b8d3b900 Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 30 May 2017 16:37:10 -0700 Subject: [PATCH 01/12] Starting to add the stencil mask for hmd --- .../src/gpu/DrawTransformVertexPosition.slv | 28 ++++++++ libraries/gpu/src/gpu/DrawWhite.slf | 18 +++++ libraries/gpu/src/gpu/StandardShaderLib.cpp | 17 +++++ libraries/gpu/src/gpu/StandardShaderLib.h | 8 +++ libraries/model/src/model/Geometry.cpp | 38 ++++++++++ libraries/model/src/model/Geometry.h | 6 ++ .../src/DeferredLightingEffect.cpp | 10 +-- .../render-utils/src/RenderDeferredTask.cpp | 69 +++++++++++++++++++ .../render-utils/src/RenderDeferredTask.h | 16 +++++ 9 files changed, 205 insertions(+), 5 deletions(-) create mode 100644 libraries/gpu/src/gpu/DrawTransformVertexPosition.slv create mode 100644 libraries/gpu/src/gpu/DrawWhite.slf diff --git a/libraries/gpu/src/gpu/DrawTransformVertexPosition.slv b/libraries/gpu/src/gpu/DrawTransformVertexPosition.slv new file mode 100644 index 0000000000..cf66a615f5 --- /dev/null +++ b/libraries/gpu/src/gpu/DrawTransformVertexPosition.slv @@ -0,0 +1,28 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// Draw and transform the fed vertex position with the standard MVP stack +// Output the clip position +// +// Created by Sam Gateau on 5/30/2017 +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +<@include gpu/Transform.slh@> + +<$declareStandardTransform()$> + +layout(location = 0) in vec4 inPosition; + +out vec3 varWorldPos; + +void main(void) { + // standard transform + TransformCamera cam = getTransformCamera(); + TransformObject obj = getTransformObject(); + <$transformModelToClipPos(cam, obj, inPosition, gl_Position)$> +} diff --git a/libraries/gpu/src/gpu/DrawWhite.slf b/libraries/gpu/src/gpu/DrawWhite.slf new file mode 100644 index 0000000000..bdecc0c5c5 --- /dev/null +++ b/libraries/gpu/src/gpu/DrawWhite.slf @@ -0,0 +1,18 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// Draw white +// +// Created by Sam Gateau on 5/30/2017 +// Copyright 2017 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 +// + +out vec4 outFragColor; + +void main(void) { + outFragColor = vec4(1.0); +} diff --git a/libraries/gpu/src/gpu/StandardShaderLib.cpp b/libraries/gpu/src/gpu/StandardShaderLib.cpp index 81500347fd..cc92719a06 100755 --- a/libraries/gpu/src/gpu/StandardShaderLib.cpp +++ b/libraries/gpu/src/gpu/StandardShaderLib.cpp @@ -16,6 +16,8 @@ #include "DrawTransformUnitQuad_vert.h" #include "DrawTexcoordRectTransformUnitQuad_vert.h" #include "DrawViewportQuadTransformTexcoord_vert.h" +#include "DrawTransformVertexPosition_vert.h" +#include "DrawWhite_frag.h" #include "DrawTexture_frag.h" #include "DrawTextureOpaque_frag.h" #include "DrawColoredTexture_frag.h" @@ -26,6 +28,8 @@ ShaderPointer StandardShaderLib::_drawUnitQuadTexcoordVS; ShaderPointer StandardShaderLib::_drawTransformUnitQuadVS; ShaderPointer StandardShaderLib::_drawTexcoordRectTransformUnitQuadVS; ShaderPointer StandardShaderLib::_drawViewportQuadTransformTexcoordVS; +ShaderPointer StandardShaderLib::_drawTransformVertexPositionVS; +ShaderPointer StandardShaderLib::_drawWhitePS; ShaderPointer StandardShaderLib::_drawTexturePS; ShaderPointer StandardShaderLib::_drawTextureOpaquePS; ShaderPointer StandardShaderLib::_drawColoredTexturePS; @@ -84,6 +88,19 @@ ShaderPointer StandardShaderLib::getDrawViewportQuadTransformTexcoordVS() { } return _drawViewportQuadTransformTexcoordVS; } +ShaderPointer StandardShaderLib::getDrawTransformVertexPositionVS() { + if (!_drawTransformVertexPositionVS) { + _drawTransformVertexPositionVS = gpu::Shader::createVertex(std::string(DrawTransformVertexPosition_vert)); + } + return _drawTransformVertexPositionVS; +} + +ShaderPointer StandardShaderLib::getDrawWhitePS() { + if (!_drawWhitePS) { + _drawWhitePS = gpu::Shader::createPixel(std::string(DrawWhite_frag)); + } + return _drawWhitePS; +} ShaderPointer StandardShaderLib::getDrawTexturePS() { if (!_drawTexturePS) { diff --git a/libraries/gpu/src/gpu/StandardShaderLib.h b/libraries/gpu/src/gpu/StandardShaderLib.h index 12ea9045c2..677ad8c7a1 100755 --- a/libraries/gpu/src/gpu/StandardShaderLib.h +++ b/libraries/gpu/src/gpu/StandardShaderLib.h @@ -37,6 +37,11 @@ public: // Shader draws the unit quad in the full viewport clipPos = ([(-1,-1),(1,1)]) and transform the texcoord = [(0,0),(1,1)] by the model transform. static ShaderPointer getDrawViewportQuadTransformTexcoordVS(); + // Shader draw the fed vertex position and transform it by the full model transform stack (Model, View, Proj). + // simply output the world pos and the clip pos to the next stage + static ShaderPointer getDrawTransformVertexPositionVS(); + + static ShaderPointer getDrawWhitePS(); static ShaderPointer getDrawTexturePS(); static ShaderPointer getDrawTextureOpaquePS(); static ShaderPointer getDrawColoredTexturePS(); @@ -51,6 +56,9 @@ protected: static ShaderPointer _drawTransformUnitQuadVS; static ShaderPointer _drawTexcoordRectTransformUnitQuadVS; static ShaderPointer _drawViewportQuadTransformTexcoordVS; + static ShaderPointer _drawTransformVertexPositionVS; + + static ShaderPointer _drawWhitePS; static ShaderPointer _drawTexturePS; static ShaderPointer _drawTextureOpaquePS; static ShaderPointer _drawColoredTexturePS; diff --git a/libraries/model/src/model/Geometry.cpp b/libraries/model/src/model/Geometry.cpp index 16608ab63e..2525491460 100755 --- a/libraries/model/src/model/Geometry.cpp +++ b/libraries/model/src/model/Geometry.cpp @@ -241,6 +241,42 @@ void Mesh::forEach(std::function vertexFunc, } } +MeshPointer Mesh::createIndexedTriangles_P3F(uint32_t numVertices, uint32_t numIndices, const glm::vec3* vertices, const uint32_t* indices) { + MeshPointer mesh; + if (numVertices == 0) { return mesh; } + if (numIndices < 3) { return mesh; } + + mesh = std::make_shared(); + + // Vertex buffer + mesh->setVertexBuffer(gpu::BufferView(new gpu::Buffer(numVertices * sizeof(glm::vec3), (gpu::Byte*) vertices), gpu::Element::VEC3F_XYZ)); + + // trim down the indices to shorts if possible + if (numIndices < std::numeric_limits::max()) { + Indices16 shortIndicesVector; + int16_t* shortIndices = nullptr; + if (indices) { + shortIndicesVector.resize(numIndices); + for (int i = 0; i < numIndices; i++) { + shortIndicesVector[i] = indices[i]; + } + shortIndices = shortIndicesVector.data(); + } + + mesh->setIndexBuffer(gpu::BufferView(new gpu::Buffer(numIndices * sizeof(uint16_t), (gpu::Byte*) shortIndices), gpu::Element::INDEX_UINT16)); + } else { + + mesh->setIndexBuffer(gpu::BufferView(new gpu::Buffer(numIndices * sizeof(uint32_t), (gpu::Byte*) indices), gpu::Element::INDEX_INT32)); + } + + + std::vector parts; + parts.push_back(model::Mesh::Part(0, numIndices, 0, model::Mesh::TRIANGLES)); + mesh->setPartBuffer(gpu::BufferView(new gpu::Buffer(parts.size() * sizeof(model::Mesh::Part), (gpu::Byte*) parts.data()), gpu::Element::PART_DRAWCALL)); + + return mesh; +} + Geometry::Geometry() { } @@ -256,3 +292,5 @@ Geometry::~Geometry() { void Geometry::setMesh(const MeshPointer& mesh) { _mesh = mesh; } + + diff --git a/libraries/model/src/model/Geometry.h b/libraries/model/src/model/Geometry.h index 7ba3e83407..2375944f04 100755 --- a/libraries/model/src/model/Geometry.h +++ b/libraries/model/src/model/Geometry.h @@ -65,6 +65,9 @@ public: const gpu::BufferStream& getVertexStream() const { return _vertexStream; } // Index Buffer + using Indices16 = std::vector; + using Indices32 = std::vector; + void setIndexBuffer(const BufferView& buffer); const BufferView& getIndexBuffer() const { return _indexBuffer; } size_t getNumIndices() const { return _indexBuffer.getNumElements(); } @@ -127,6 +130,9 @@ public: std::function normalFunc, std::function indexFunc); + + static MeshPointer createIndexedTriangles_P3F(uint32_t numVertices, uint32_t numTriangles, const glm::vec3* vertices = nullptr, const uint32_t* indices = nullptr); + protected: gpu::Stream::FormatPointer _vertexFormat; diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index e1042912aa..9d839d6ee1 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -160,11 +160,11 @@ void DeferredLightingEffect::init() { lp->setAmbientIntensity(0.5f); - lp->setAmbientMap(_defaultSkyboxAmbientTexture); - auto irradianceSH = _defaultSkyboxAmbientTexture->getIrradiance(); - if (irradianceSH) { - lp->setAmbientSphere((*irradianceSH)); - } + lp->setAmbientMap(_defaultSkyboxAmbientTexture); + auto irradianceSH = _defaultSkyboxAmbientTexture->getIrradiance(); + if (irradianceSH) { + lp->setAmbientSphere((*irradianceSH)); + } } void DeferredLightingEffect::setupKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit) { diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index b844da8bbe..60fd6e2f64 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -85,12 +85,15 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto deferredFramebuffer = prepareDeferredOutputs.getN(0); const auto lightingFramebuffer = prepareDeferredOutputs.getN(1); + // draw a stencil mask in hidden regions of the frmaebuffer. + // Render opaque objects in DeferredBuffer const auto opaqueInputs = DrawStateSortDeferred::Inputs(opaques, lightingModel).hasVarying(); task.addJob("DrawOpaqueDeferred", opaqueInputs, shapePlumber); // Once opaque is all rendered create stencil background task.addJob("DrawOpaqueStencil", deferredFramebuffer); + task.addJob("PrepareStencil", primaryFramebuffer); task.addJob("OpaqueRangeTimer", opaqueRangeTimer); @@ -469,6 +472,71 @@ void DrawBackgroundDeferred::run(const RenderContextPointer& renderContext, cons // std::static_pointer_cast(renderContext->jobConfig)->gpuTime = _gpuTimer.getAverage(); } +gpu::PipelinePointer PrepareStencil::getDrawStencilPipeline() { + if (!_drawStencilPipeline) { + const gpu::int8 STENCIL_OPAQUE = 1; + auto vs = gpu::StandardShaderLib::getDrawTransformVertexPositionVS(); + auto ps = gpu::StandardShaderLib::getDrawWhitePS(); + auto program = gpu::Shader::createProgram(vs, ps); + gpu::Shader::makeProgram((*program)); + + auto state = std::make_shared(); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_KEEP)); + state->setColorWriteMask(0); + + _drawStencilPipeline = gpu::Pipeline::create(program, state); + } + return _drawStencilPipeline; +} + +model::MeshPointer PrepareStencil::getMesh() { + if (!_mesh) { + + std::vector vertices { + { -1.0f, -1.0f, 0.0f }, { -1.0f, 0.0f, 0.0f }, + { -1.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, + { 1.0f, 1.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, + { 1.0f, -1.0f, 0.0f }, { 0.0f, -1.0f, 0.0f } }; + + std::vector indices { 0, 7, 1, 1, 3, 2, 3, 5, 4, 5, 7, 6 }; + + _mesh = model::Mesh::createIndexedTriangles_P3F((uint32_t) vertices.size(), (uint32_t) indices.size(), vertices.data(), indices.data()); + + } + return _mesh; +} + + +void PrepareStencil::run(const RenderContextPointer& renderContext, const gpu::FramebufferPointer& srcFramebuffer) { + assert(renderContext->args); + assert(renderContext->args->_context); + + RenderArgs* args = renderContext->args; + doInBatch(args->_context, [&](gpu::Batch& batch) { + args->_batch = &batch; + + batch.setViewportTransform(args->_viewport); + batch.setStateScissorRect(args->_viewport); + + batch.resetViewTransform(); + batch.setModelTransform(Transform()); + glm::mat4 proj; + batch.setProjectionTransform(proj); + + batch.setPipeline(getDrawStencilPipeline()); + + auto mesh = getMesh(); + batch.setIndexBuffer(gpu::UINT32, (mesh->getIndexBuffer()._buffer), 0); + batch.setInputFormat((mesh->getVertexFormat())); + batch.setInputStream(0, mesh->getVertexStream()); + + // Draw + auto part = mesh->getPartBuffer().get(0); + batch.drawIndexed(gpu::TRIANGLES, part._numIndices, part._startIndex); + }); + args->_batch = nullptr; +} + void Blit::run(const RenderContextPointer& renderContext, const gpu::FramebufferPointer& srcFramebuffer) { assert(renderContext->args); assert(renderContext->args->_context); @@ -538,3 +606,4 @@ void Blit::run(const RenderContextPointer& renderContext, const gpu::Framebuffer } }); } + diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index 12ecd5ecaf..bba1b26404 100644 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -13,6 +13,7 @@ #define hifi_RenderDeferredTask_h #include +#include #include #include "LightingModel.h" @@ -185,6 +186,21 @@ protected: bool _opaquePass{ true }; }; +class PrepareStencil { +public: + using JobModel = render::Job::ModelI; + + void run(const render::RenderContextPointer& renderContext, const gpu::FramebufferPointer& dstFramebuffer); +private: + gpu::PipelinePointer _drawStencilPipeline; + gpu::PipelinePointer getDrawStencilPipeline(); + + model::MeshPointer _mesh; + model::MeshPointer getMesh(); + +}; + + class Blit { public: using JobModel = render::Job::ModelI; From 32c5dac66af66ebfd805890d3206531c60854d5a Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Wed, 31 May 2017 00:55:28 -0700 Subject: [PATCH 02/12] Big cleanup of unecessary shaders and legacy from deferred lighting, and messing around with the stencil --- libraries/gpu/src/gpu/DrawVertexPosition.slv | 19 +++ libraries/gpu/src/gpu/StandardShaderLib.cpp | 10 ++ libraries/gpu/src/gpu/StandardShaderLib.h | 3 + .../src/DeferredLightingEffect.cpp | 66 +--------- .../render-utils/src/DeferredLightingEffect.h | 11 -- .../render-utils/src/RenderDeferredTask.cpp | 25 ++-- .../render-utils/src/RenderDeferredTask.h | 3 + .../render-utils/src/RenderPipelines.cpp | 1 + .../render-utils/src/directional_light.slf | 47 ------- .../src/directional_light_shadow.slf | 49 -------- libraries/render-utils/src/point_light.slf | 85 ------------- libraries/render-utils/src/spot_light.slf | 115 ------------------ 12 files changed, 49 insertions(+), 385 deletions(-) create mode 100644 libraries/gpu/src/gpu/DrawVertexPosition.slv delete mode 100644 libraries/render-utils/src/directional_light.slf delete mode 100644 libraries/render-utils/src/directional_light_shadow.slf delete mode 100644 libraries/render-utils/src/point_light.slf delete mode 100644 libraries/render-utils/src/spot_light.slf diff --git a/libraries/gpu/src/gpu/DrawVertexPosition.slv b/libraries/gpu/src/gpu/DrawVertexPosition.slv new file mode 100644 index 0000000000..b12280d577 --- /dev/null +++ b/libraries/gpu/src/gpu/DrawVertexPosition.slv @@ -0,0 +1,19 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// Draw the fed vertex position, pass straight as clip pos +// Output the clip position +// +// Created by Sam Gateau on 5/30/2017 +// Copyright 2017 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 +// + +layout(location = 0) in vec4 inPosition; + +void main(void) { + gl_Position = inPosition; +} diff --git a/libraries/gpu/src/gpu/StandardShaderLib.cpp b/libraries/gpu/src/gpu/StandardShaderLib.cpp index cc92719a06..36ad548cfa 100755 --- a/libraries/gpu/src/gpu/StandardShaderLib.cpp +++ b/libraries/gpu/src/gpu/StandardShaderLib.cpp @@ -16,6 +16,7 @@ #include "DrawTransformUnitQuad_vert.h" #include "DrawTexcoordRectTransformUnitQuad_vert.h" #include "DrawViewportQuadTransformTexcoord_vert.h" +#include "DrawVertexPosition_vert.h" #include "DrawTransformVertexPosition_vert.h" #include "DrawWhite_frag.h" #include "DrawTexture_frag.h" @@ -28,6 +29,7 @@ ShaderPointer StandardShaderLib::_drawUnitQuadTexcoordVS; ShaderPointer StandardShaderLib::_drawTransformUnitQuadVS; ShaderPointer StandardShaderLib::_drawTexcoordRectTransformUnitQuadVS; ShaderPointer StandardShaderLib::_drawViewportQuadTransformTexcoordVS; +ShaderPointer StandardShaderLib::_drawVertexPositionVS; ShaderPointer StandardShaderLib::_drawTransformVertexPositionVS; ShaderPointer StandardShaderLib::_drawWhitePS; ShaderPointer StandardShaderLib::_drawTexturePS; @@ -88,6 +90,14 @@ ShaderPointer StandardShaderLib::getDrawViewportQuadTransformTexcoordVS() { } return _drawViewportQuadTransformTexcoordVS; } + +ShaderPointer StandardShaderLib::getDrawVertexPositionVS() { + if (!_drawVertexPositionVS) { + _drawVertexPositionVS = gpu::Shader::createVertex(std::string(DrawVertexPosition_vert)); + } + return _drawVertexPositionVS; +} + ShaderPointer StandardShaderLib::getDrawTransformVertexPositionVS() { if (!_drawTransformVertexPositionVS) { _drawTransformVertexPositionVS = gpu::Shader::createVertex(std::string(DrawTransformVertexPosition_vert)); diff --git a/libraries/gpu/src/gpu/StandardShaderLib.h b/libraries/gpu/src/gpu/StandardShaderLib.h index 677ad8c7a1..485e5bbbf9 100755 --- a/libraries/gpu/src/gpu/StandardShaderLib.h +++ b/libraries/gpu/src/gpu/StandardShaderLib.h @@ -39,6 +39,7 @@ public: // Shader draw the fed vertex position and transform it by the full model transform stack (Model, View, Proj). // simply output the world pos and the clip pos to the next stage + static ShaderPointer getDrawVertexPositionVS(); static ShaderPointer getDrawTransformVertexPositionVS(); static ShaderPointer getDrawWhitePS(); @@ -56,6 +57,8 @@ protected: static ShaderPointer _drawTransformUnitQuadVS; static ShaderPointer _drawTexcoordRectTransformUnitQuadVS; static ShaderPointer _drawViewportQuadTransformTexcoordVS; + + static ShaderPointer _drawVertexPositionVS; static ShaderPointer _drawTransformVertexPositionVS; static ShaderPointer _drawWhitePS; diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 9d839d6ee1..025274e66d 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -27,18 +27,15 @@ #include "deferred_light_point_vert.h" #include "deferred_light_spot_vert.h" -#include "directional_light_frag.h" #include "directional_ambient_light_frag.h" #include "directional_skybox_light_frag.h" -#include "directional_light_shadow_frag.h" #include "directional_ambient_light_shadow_frag.h" #include "directional_skybox_light_shadow_frag.h" #include "local_lights_shading_frag.h" #include "local_lights_drawOutline_frag.h" -#include "point_light_frag.h" -#include "spot_light_frag.h" + using namespace render; @@ -82,48 +79,26 @@ enum DeferredShader_BufferSlot { }; static void loadLightProgram(const char* vertSource, const char* fragSource, bool lightVolume, gpu::PipelinePointer& program, LightLocationsPtr& locations); -static void loadLightVolumeProgram(const char* vertSource, const char* fragSource, bool front, gpu::PipelinePointer& program, LightLocationsPtr& locations); - -const char no_light_frag[] = -R"SCRIBE( -out vec4 _fragColor; - -void main(void) { - _fragColor = vec4(1.0, 1.0, 1.0, 1.0); -} -)SCRIBE" -; void DeferredLightingEffect::init() { - _directionalLightLocations = std::make_shared(); _directionalAmbientSphereLightLocations = std::make_shared(); _directionalSkyboxLightLocations = std::make_shared(); - _directionalLightShadowLocations = std::make_shared(); _directionalAmbientSphereLightShadowLocations = std::make_shared(); _directionalSkyboxLightShadowLocations = std::make_shared(); _localLightLocations = std::make_shared(); _localLightOutlineLocations = std::make_shared(); - _pointLightLocations = std::make_shared(); - _spotLightLocations = std::make_shared(); - loadLightProgram(deferred_light_vert, directional_light_frag, false, _directionalLight, _directionalLightLocations); loadLightProgram(deferred_light_vert, directional_ambient_light_frag, false, _directionalAmbientSphereLight, _directionalAmbientSphereLightLocations); loadLightProgram(deferred_light_vert, directional_skybox_light_frag, false, _directionalSkyboxLight, _directionalSkyboxLightLocations); - loadLightProgram(deferred_light_vert, directional_light_shadow_frag, false, _directionalLightShadow, _directionalLightShadowLocations); loadLightProgram(deferred_light_vert, directional_ambient_light_shadow_frag, false, _directionalAmbientSphereLightShadow, _directionalAmbientSphereLightShadowLocations); loadLightProgram(deferred_light_vert, directional_skybox_light_shadow_frag, false, _directionalSkyboxLightShadow, _directionalSkyboxLightShadowLocations); loadLightProgram(deferred_light_vert, local_lights_shading_frag, true, _localLight, _localLightLocations); loadLightProgram(deferred_light_vert, local_lights_drawOutline_frag, true, _localLightOutline, _localLightOutlineLocations); - loadLightVolumeProgram(deferred_light_point_vert, no_light_frag, false, _pointLightBack, _pointLightLocations); - loadLightVolumeProgram(deferred_light_point_vert, no_light_frag, true, _pointLightFront, _pointLightLocations); - loadLightVolumeProgram(deferred_light_spot_vert, no_light_frag, false, _spotLightBack, _spotLightLocations); - loadLightVolumeProgram(deferred_light_spot_vert, no_light_frag, true, _spotLightFront, _spotLightLocations); - // Light Stage and clusters _lightStage = std::make_shared(); @@ -290,39 +265,6 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo } - -static void loadLightVolumeProgram(const char* vertSource, const char* fragSource, bool front, gpu::PipelinePointer& pipeline, LightLocationsPtr& locations) { - gpu::ShaderPointer program = makeLightProgram(vertSource, fragSource, locations); - - auto state = std::make_shared(); - - // Stencil test all the light passes for objects pixels only, not the background - - if (front) { - state->setCullMode(gpu::State::CULL_BACK); - state->setDepthTest(true, false, gpu::LESS_EQUAL); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_DECR, gpu::State::STENCIL_OP_KEEP)); - - // state->setDepthClampEnable(true); - // TODO: We should use DepthClamp and avoid changing geometry for inside /outside cases - // additive blending - // state->setBlendFunction(true, gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::ONE); - - //state->setColorWriteMask(true, true, true, false); - state->setColorWriteMask(false, false, false, false); - } else { - state->setCullMode(gpu::State::CULL_FRONT); - state->setDepthTest(true, false, gpu::LESS_EQUAL); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_INCR, gpu::State::STENCIL_OP_KEEP)); - // additive blending - // state->setBlendFunction(true, gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::ONE); - // state->setColorWriteMask(true, true, true, false); - state->setColorWriteMask(false, false, false, false); - } - pipeline = gpu::Pipeline::create(program, state); - -} - void DeferredLightingEffect::setGlobalLight(const model::LightPointer& light) { /* auto globalLight = _allocatedLights.front(); globalLight->setDirection(light->getDirection()); @@ -535,7 +477,7 @@ void PrepareDeferred::run(const RenderContextPointer& renderContext, const Input gpu::Framebuffer::BUFFER_COLOR0 | gpu::Framebuffer::BUFFER_COLOR1 | gpu::Framebuffer::BUFFER_COLOR2 | gpu::Framebuffer::BUFFER_COLOR3 | gpu::Framebuffer::BUFFER_DEPTH | gpu::Framebuffer::BUFFER_STENCIL, - vec4(vec3(0), 0), 1.0, 0.0, true); + vec4(vec3(0), 0), 1.0, 0, true); // For the rest of the rendering, bind the lighting model batch.setUniformBuffer(LIGHTING_MODEL_BUFFER_SLOT, lightingModel->getParametersBuffer()); @@ -619,8 +561,8 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, batch.setResourceTexture(SHADOW_MAP_UNIT, globalShadow->map); } - auto& program = deferredLightingEffect->_shadowMapEnabled ? deferredLightingEffect->_directionalLightShadow : deferredLightingEffect->_directionalLight; - LightLocationsPtr locations = deferredLightingEffect->_shadowMapEnabled ? deferredLightingEffect->_directionalLightShadowLocations : deferredLightingEffect->_directionalLightLocations; + auto& program = deferredLightingEffect->_directionalSkyboxLight; + LightLocationsPtr locations = deferredLightingEffect->_directionalSkyboxLightLocations; const auto& keyLight = deferredLightingEffect->_allocatedLights[deferredLightingEffect->_globalLights.front()]; // Setup the global directional pass pipeline diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 2f4f9901c3..c171973216 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -82,32 +82,21 @@ private: gpu::PipelinePointer _directionalSkyboxLight; gpu::PipelinePointer _directionalAmbientSphereLight; - gpu::PipelinePointer _directionalLight; gpu::PipelinePointer _directionalSkyboxLightShadow; gpu::PipelinePointer _directionalAmbientSphereLightShadow; - gpu::PipelinePointer _directionalLightShadow; gpu::PipelinePointer _localLight; gpu::PipelinePointer _localLightOutline; - gpu::PipelinePointer _pointLightBack; - gpu::PipelinePointer _pointLightFront; - gpu::PipelinePointer _spotLightBack; - gpu::PipelinePointer _spotLightFront; - LightLocationsPtr _directionalSkyboxLightLocations; LightLocationsPtr _directionalAmbientSphereLightLocations; - LightLocationsPtr _directionalLightLocations; LightLocationsPtr _directionalSkyboxLightShadowLocations; LightLocationsPtr _directionalAmbientSphereLightShadowLocations; - LightLocationsPtr _directionalLightShadowLocations; LightLocationsPtr _localLightLocations; LightLocationsPtr _localLightOutlineLocations; - LightLocationsPtr _pointLightLocations; - LightLocationsPtr _spotLightLocations; using Lights = std::vector; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 60fd6e2f64..0fbe35025d 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -85,7 +85,8 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto deferredFramebuffer = prepareDeferredOutputs.getN(0); const auto lightingFramebuffer = prepareDeferredOutputs.getN(1); - // draw a stencil mask in hidden regions of the frmaebuffer. + // draw a stencil mask in hidden regions of the framebuffer. + task.addJob("PrepareStencil", primaryFramebuffer); // Render opaque objects in DeferredBuffer const auto opaqueInputs = DrawStateSortDeferred::Inputs(opaques, lightingModel).hasVarying(); @@ -93,7 +94,6 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren // Once opaque is all rendered create stencil background task.addJob("DrawOpaqueStencil", deferredFramebuffer); - task.addJob("PrepareStencil", primaryFramebuffer); task.addJob("OpaqueRangeTimer", opaqueRangeTimer); @@ -401,7 +401,7 @@ gpu::PipelinePointer DrawStencilDeferred::getOpaquePipeline() { auto state = std::make_shared(); state->setDepthTest(true, false, gpu::LESS_EQUAL); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(STENCIL_OPAQUE, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_KEEP)); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(STENCIL_OPAQUE, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); state->setColorWriteMask(0); _opaquePipeline = gpu::Pipeline::create(program, state); @@ -410,6 +410,7 @@ gpu::PipelinePointer DrawStencilDeferred::getOpaquePipeline() { } void DrawStencilDeferred::run(const RenderContextPointer& renderContext, const DeferredFramebufferPointer& deferredFramebuffer) { + // return; assert(renderContext->args); assert(renderContext->args->hasViewFrustum()); @@ -474,15 +475,14 @@ void DrawBackgroundDeferred::run(const RenderContextPointer& renderContext, cons gpu::PipelinePointer PrepareStencil::getDrawStencilPipeline() { if (!_drawStencilPipeline) { - const gpu::int8 STENCIL_OPAQUE = 1; - auto vs = gpu::StandardShaderLib::getDrawTransformVertexPositionVS(); + auto vs = gpu::StandardShaderLib::getDrawVertexPositionVS(); auto ps = gpu::StandardShaderLib::getDrawWhitePS(); auto program = gpu::Shader::createProgram(vs, ps); gpu::Shader::makeProgram((*program)); auto state = std::make_shared(); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_KEEP)); - state->setColorWriteMask(0); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(STENCIL_MASK, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE)); + // state->setColorWriteMask(0); _drawStencilPipeline = gpu::Pipeline::create(program, state); } @@ -499,9 +499,7 @@ model::MeshPointer PrepareStencil::getMesh() { { 1.0f, -1.0f, 0.0f }, { 0.0f, -1.0f, 0.0f } }; std::vector indices { 0, 7, 1, 1, 3, 2, 3, 5, 4, 5, 7, 6 }; - _mesh = model::Mesh::createIndexedTriangles_P3F((uint32_t) vertices.size(), (uint32_t) indices.size(), vertices.data(), indices.data()); - } return _mesh; } @@ -514,19 +512,14 @@ void PrepareStencil::run(const RenderContextPointer& renderContext, const gpu::F RenderArgs* args = renderContext->args; doInBatch(args->_context, [&](gpu::Batch& batch) { args->_batch = &batch; + batch.enableStereo(false); batch.setViewportTransform(args->_viewport); - batch.setStateScissorRect(args->_viewport); - - batch.resetViewTransform(); - batch.setModelTransform(Transform()); - glm::mat4 proj; - batch.setProjectionTransform(proj); batch.setPipeline(getDrawStencilPipeline()); auto mesh = getMesh(); - batch.setIndexBuffer(gpu::UINT32, (mesh->getIndexBuffer()._buffer), 0); + batch.setIndexBuffer(mesh->getIndexBuffer()); batch.setInputFormat((mesh->getVertexFormat())); batch.setInputStream(0, mesh->getVertexStream()); diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index bba1b26404..c978a5f9a3 100644 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -191,6 +191,9 @@ public: using JobModel = render::Job::ModelI; void run(const render::RenderContextPointer& renderContext, const gpu::FramebufferPointer& dstFramebuffer); + + static const gpu::int8 STENCIL_MASK = 64; + private: gpu::PipelinePointer _drawStencilPipeline; gpu::PipelinePointer getDrawStencilPipeline(); diff --git a/libraries/render-utils/src/RenderPipelines.cpp b/libraries/render-utils/src/RenderPipelines.cpp index da264cbf7d..c83e5c5f34 100644 --- a/libraries/render-utils/src/RenderPipelines.cpp +++ b/libraries/render-utils/src/RenderPipelines.cpp @@ -330,6 +330,7 @@ void addPlumberPipeline(ShapePlumber& plumber, bool isWireframed = (i & 4); auto state = std::make_shared(); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::GREATER, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_INCR_SAT)); // Depth test depends on transparency state->setDepthTest(true, !key.isTranslucent(), gpu::LESS_EQUAL); diff --git a/libraries/render-utils/src/directional_light.slf b/libraries/render-utils/src/directional_light.slf deleted file mode 100644 index cda03b0779..0000000000 --- a/libraries/render-utils/src/directional_light.slf +++ /dev/null @@ -1,47 +0,0 @@ -<@include gpu/Config.slh@> -<$VERSION_HEADER$> -// Generated on <$_SCRIBE_DATE$> -// -// directional_light.frag -// fragment shader -// -// Created by Andrzej Kapolka on 9/3/14. -// Copyright 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 DeferredBufferRead.slh@> -<@include DeferredGlobalLight.slh@> - -<$declareEvalLightmappedColor()$> -<$declareEvalAmbientGlobalColor()$> - -in vec2 _texCoord0; -out vec4 _fragColor; - -void main(void) { - DeferredFrameTransform deferredTransform = getDeferredFrameTransform(); - DeferredFragment frag = unpackDeferredFragment(deferredTransform, _texCoord0); - - float shadowAttenuation = 1.0; - - if (frag.mode == FRAG_MODE_UNLIT) { - discard; - } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { - discard; - } else { - vec3 color = evalAmbientGlobalColor( - getViewInverse(), - shadowAttenuation, - frag.obscurance, - frag.position.xyz, - frag.normal, - frag.albedo, - frag.fresnel, - frag.metallic, - frag.roughness); - _fragColor = vec4(color, 1.0); - } -} diff --git a/libraries/render-utils/src/directional_light_shadow.slf b/libraries/render-utils/src/directional_light_shadow.slf deleted file mode 100644 index 7f98330f84..0000000000 --- a/libraries/render-utils/src/directional_light_shadow.slf +++ /dev/null @@ -1,49 +0,0 @@ -<@include gpu/Config.slh@> -<$VERSION_HEADER$> -// Generated on <$_SCRIBE_DATE$> -// -// directional_light_shadow.frag -// fragment shader -// -// Created by Zach Pomerantz on 1/18/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 Shadow.slh@> -<@include DeferredBufferRead.slh@> -<@include DeferredGlobalLight.slh@> - -<$declareEvalLightmappedColor()$> -<$declareEvalAmbientGlobalColor()$> - -in vec2 _texCoord0; -out vec4 _fragColor; - -void main(void) { - DeferredFrameTransform deferredTransform = getDeferredFrameTransform(); - DeferredFragment frag = unpackDeferredFragment(deferredTransform, _texCoord0); - - vec4 worldPos = getViewInverse() * vec4(frag.position.xyz, 1.0); - float shadowAttenuation = evalShadowAttenuation(worldPos); - - if (frag.mode == FRAG_MODE_UNLIT) { - discard; - } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { - discard; - } else { - vec3 color = evalAmbientGlobalColor( - getViewInverse(), - shadowAttenuation, - frag.obscurance, - frag.position.xyz, - frag.normal, - frag.albedo, - frag.fresnel, - frag.metallic, - frag.roughness); - _fragColor = vec4(color, 1.0); - } -} diff --git a/libraries/render-utils/src/point_light.slf b/libraries/render-utils/src/point_light.slf deleted file mode 100644 index e646db5069..0000000000 --- a/libraries/render-utils/src/point_light.slf +++ /dev/null @@ -1,85 +0,0 @@ -<@include gpu/Config.slh@> -<$VERSION_HEADER$> -// Generated on <$_SCRIBE_DATE$> -// -// point_light.frag -// fragment shader -// -// Created by Sam Gateau on 9/18/15. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - - -<$declareDeferredCurvature()$> - -// Everything about light -<@include model/Light.slh@> -<$declareLightBuffer()$> - -<@include LightingModel.slh@> - -<@include LightPoint.slh@> -<$declareLightingPoint(supportScattering)$> - - -uniform vec4 texcoordFrameTransform; - -in vec4 _texCoord0;!> -out vec4 _fragColor; - -void main(void) { - _fragColor = vec4(1.0, 1.0, 1.0, 1.0); - - -} diff --git a/libraries/render-utils/src/spot_light.slf b/libraries/render-utils/src/spot_light.slf deleted file mode 100644 index 4cacff86c4..0000000000 --- a/libraries/render-utils/src/spot_light.slf +++ /dev/null @@ -1,115 +0,0 @@ -<@include gpu/Config.slh@> -<$VERSION_HEADER$> -// Generated on <$_SCRIBE_DATE$> -// -// spot_light.frag -// fragment shader -// -// Created by Sam Gateau on 9/18/15. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// Everything about deferred buffer - - -<$declareDeferredCurvature()$> - -// Everything about light -<@include model/Light.slh@> -<$declareLightBuffer(256)$> -uniform lightIndexBuffer { - int lightIndex[256]; -}; -<@include LightingModel.slh@> - -<@include LightPoint.slh@> -<$declareLightingPoint(supportScattering)$> -<@include LightSpot.slh@> -<$declareLightingSpot(supportScattering)$> - -//uniform vec4 texcoordFrameTransform; -!> - - -//in vec4 _texCoord0; -//flat in int instanceID; -out vec4 _fragColor; - -void main(void) { - _fragColor = vec4(1.0, 1.0, 1.0, 1.0); - -// DeferredFrameTransform deferredTransform = getDeferredFrameTransform(); - - // Grab the fragment data from the uv - //vec2 texCoord = _texCoord0.st;/* / _texCoord0.q; - /*texCoord *= texcoordFrameTransform.zw; - texCoord += texcoordFrameTransform.xy;*/ - /* - vec4 fragPosition = unpackDeferredPositionFromZeye(texCoord); - DeferredFragment frag = unpackDeferredFragmentNoPosition(texCoord); - - if (frag.mode == FRAG_MODE_UNLIT) { - discard; - } - - - // frag.depthVal = depthValue; - frag.position = fragPosition; - - vec4 midNormalCurvature; - vec4 lowNormalCurvature; - if (frag.mode == FRAG_MODE_SCATTERING) { - unpackMidLowNormalCurvature(texCoord, midNormalCurvature, lowNormalCurvature); - } - - // Frag pos in world - mat4 invViewMat = getViewInverse(); - vec4 fragPos = invViewMat * fragPosition; - - // Frag to eye vec - vec4 fragEyeVector = invViewMat * vec4(-frag.position.xyz, 0.0); - vec3 fragEyeDir = normalize(fragEyeVector.xyz); - - int numLights = lightIndex[0]; - for (int i = 0; i < numLights; i++) { - // Need the light now - Light light = getLight(lightIndex[i + 1]); - bool isSpot = light_isSpot(light); - // Clip againgst the light volume and Make the Light vector going from fragment to light center in world space - vec4 fragLightVecLen2; - vec4 fragLightDirLen; - float cosSpotAngle; - if (isSpot) { - if (!clipFragToLightVolumeSpot(light, fragPos.xyz, fragLightVecLen2, fragLightDirLen, cosSpotAngle)) { - continue; - } - } else { - if (!clipFragToLightVolumePoint(light, fragPos.xyz, fragLightVecLen2)) { - continue; - } - } - - vec3 diffuse; - vec3 specular; - - if (isSpot) { - evalLightingSpot(diffuse, specular, light, - fragLightDirLen.xyzw, cosSpotAngle, fragEyeDir, frag.normal, frag.roughness, - frag.metallic, frag.fresnel, frag.albedo, 1.0, - frag.scattering, midNormalCurvature, lowNormalCurvature); - } else { - evalLightingPoint(diffuse, specular, light, - fragLightVecLen2.xyz, fragEyeDir, frag.normal, frag.roughness, - frag.metallic, frag.fresnel, frag.albedo, 1.0, - frag.scattering, midNormalCurvature, lowNormalCurvature); - } - - _fragColor.rgb += diffuse; - _fragColor.rgb += specular; - } - */ -} - From 82d348a2efd87c39d321592ce7d66c184c5c4af1 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 31 May 2017 16:46:20 -0700 Subject: [PATCH 03/12] Stencil rejection is working, and more cleaning --- libraries/gpu/src/gpu/StandardShaderLib.cpp | 13 +- libraries/gpu/src/gpu/StandardShaderLib.h | 4 + libraries/model/src/model/Skybox.cpp | 2 +- .../src/procedural/ProceduralSkybox.cpp | 2 +- .../src/DeferredLightingEffect.cpp | 6 +- .../render-utils/src/RenderDeferredTask.cpp | 145 +----------------- .../render-utils/src/RenderDeferredTask.h | 48 ------ .../render-utils/src/RenderPipelines.cpp | 2 +- .../render-utils/src/StencilMaskPass.cpp | 123 +++++++++++++++ libraries/render-utils/src/StencilMaskPass.h | 50 ++++++ .../render-utils/src/SurfaceGeometryPass.cpp | 4 +- .../render-utils/src/drawOpaqueStencil.slf | 16 -- 12 files changed, 198 insertions(+), 217 deletions(-) create mode 100644 libraries/render-utils/src/StencilMaskPass.cpp create mode 100644 libraries/render-utils/src/StencilMaskPass.h delete mode 100644 libraries/render-utils/src/drawOpaqueStencil.slf diff --git a/libraries/gpu/src/gpu/StandardShaderLib.cpp b/libraries/gpu/src/gpu/StandardShaderLib.cpp index 36ad548cfa..756070ff68 100755 --- a/libraries/gpu/src/gpu/StandardShaderLib.cpp +++ b/libraries/gpu/src/gpu/StandardShaderLib.cpp @@ -18,6 +18,9 @@ #include "DrawViewportQuadTransformTexcoord_vert.h" #include "DrawVertexPosition_vert.h" #include "DrawTransformVertexPosition_vert.h" + +const char DrawNada_frag[] = "void main(void) {}"; // DrawNada is really simple... + #include "DrawWhite_frag.h" #include "DrawTexture_frag.h" #include "DrawTextureOpaque_frag.h" @@ -31,6 +34,7 @@ ShaderPointer StandardShaderLib::_drawTexcoordRectTransformUnitQuadVS; ShaderPointer StandardShaderLib::_drawViewportQuadTransformTexcoordVS; ShaderPointer StandardShaderLib::_drawVertexPositionVS; ShaderPointer StandardShaderLib::_drawTransformVertexPositionVS; +ShaderPointer StandardShaderLib::_drawNadaPS; ShaderPointer StandardShaderLib::_drawWhitePS; ShaderPointer StandardShaderLib::_drawTexturePS; ShaderPointer StandardShaderLib::_drawTextureOpaquePS; @@ -105,6 +109,13 @@ ShaderPointer StandardShaderLib::getDrawTransformVertexPositionVS() { return _drawTransformVertexPositionVS; } +ShaderPointer StandardShaderLib::getDrawNadaPS() { + if (!_drawNadaPS) { + _drawNadaPS = gpu::Shader::createPixel(std::string(DrawNada_frag)); + } + return _drawNadaPS; +} + ShaderPointer StandardShaderLib::getDrawWhitePS() { if (!_drawWhitePS) { _drawWhitePS = gpu::Shader::createPixel(std::string(DrawWhite_frag)); @@ -126,8 +137,6 @@ ShaderPointer StandardShaderLib::getDrawTextureOpaquePS() { return _drawTextureOpaquePS; } - - ShaderPointer StandardShaderLib::getDrawColoredTexturePS() { if (!_drawColoredTexturePS) { _drawColoredTexturePS = gpu::Shader::createPixel(std::string(DrawColoredTexture_frag)); diff --git a/libraries/gpu/src/gpu/StandardShaderLib.h b/libraries/gpu/src/gpu/StandardShaderLib.h index 485e5bbbf9..a21d4dea9a 100755 --- a/libraries/gpu/src/gpu/StandardShaderLib.h +++ b/libraries/gpu/src/gpu/StandardShaderLib.h @@ -42,6 +42,9 @@ public: static ShaderPointer getDrawVertexPositionVS(); static ShaderPointer getDrawTransformVertexPositionVS(); + // PShader does nothing, no really nothing, but still needed for defining a program triggering rasterization + static ShaderPointer getDrawNadaPS(); + static ShaderPointer getDrawWhitePS(); static ShaderPointer getDrawTexturePS(); static ShaderPointer getDrawTextureOpaquePS(); @@ -61,6 +64,7 @@ protected: static ShaderPointer _drawVertexPositionVS; static ShaderPointer _drawTransformVertexPositionVS; + static ShaderPointer _drawNadaPS; static ShaderPointer _drawWhitePS; static ShaderPointer _drawTexturePS; static ShaderPointer _drawTextureOpaquePS; diff --git a/libraries/model/src/model/Skybox.cpp b/libraries/model/src/model/Skybox.cpp index 4901a3c61b..d327593573 100755 --- a/libraries/model/src/model/Skybox.cpp +++ b/libraries/model/src/model/Skybox.cpp @@ -97,7 +97,7 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky } auto skyState = std::make_shared(); - skyState->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + skyState->setStencilTest(true, 0xFF, gpu::State::StencilTest(1, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); thePipeline = gpu::Pipeline::create(skyShader, skyState); } diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.cpp b/libraries/procedural/src/procedural/ProceduralSkybox.cpp index 0275a875ec..f5feb434fa 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.cpp +++ b/libraries/procedural/src/procedural/ProceduralSkybox.cpp @@ -23,7 +23,7 @@ ProceduralSkybox::ProceduralSkybox() : model::Skybox() { _procedural._fragmentSource = skybox_frag; // Adjust the pipeline state for background using the stencil test _procedural.setDoesFade(false); - _procedural._opaqueState->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + _procedural._opaqueState->setStencilTest(true, 0xFF, gpu::State::StencilTest(1, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); } bool ProceduralSkybox::empty() { diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 025274e66d..04255fbb87 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -242,7 +242,7 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo state->setColorWriteMask(true, true, true, false); if (lightVolume) { - state->setStencilTest(true, 0x00, gpu::State::StencilTest(1, 0xFF, gpu::LESS_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + state->setStencilTest(true, 0x00, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); state->setCullMode(gpu::State::CULL_BACK); // state->setCullMode(gpu::State::CULL_FRONT); @@ -255,7 +255,7 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo } else { // Stencil test all the light passes for objects pixels only, not the background - state->setStencilTest(true, 0x00, gpu::State::StencilTest(0, 0x01, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + state->setStencilTest(true, 0x00, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); state->setCullMode(gpu::State::CULL_BACK); // additive blending @@ -477,7 +477,7 @@ void PrepareDeferred::run(const RenderContextPointer& renderContext, const Input gpu::Framebuffer::BUFFER_COLOR0 | gpu::Framebuffer::BUFFER_COLOR1 | gpu::Framebuffer::BUFFER_COLOR2 | gpu::Framebuffer::BUFFER_COLOR3 | gpu::Framebuffer::BUFFER_DEPTH | gpu::Framebuffer::BUFFER_STENCIL, - vec4(vec3(0), 0), 1.0, 0, true); + vec4(vec3(0), 0), 1.0, 1, true); // For the rest of the rendering, bind the lighting model batch.setUniformBuffer(LIGHTING_MODEL_BUFFER_SLOT, lightingModel->getParametersBuffer()); diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 0fbe35025d..89b4b72944 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -27,6 +27,7 @@ #include #include "LightingModel.h" +#include "StencilMaskPass.h" #include "DebugDeferredBuffer.h" #include "DeferredFramebuffer.h" #include "DeferredLightingEffect.h" @@ -43,8 +44,6 @@ #include -#include "drawOpaqueStencil_frag.h" - using namespace render; extern void initOverlay3DPipelines(render::ShapePlumber& plumber); @@ -93,7 +92,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren task.addJob("DrawOpaqueDeferred", opaqueInputs, shapePlumber); // Once opaque is all rendered create stencil background - task.addJob("DrawOpaqueStencil", deferredFramebuffer); + task.addJob("DrawOpaqueStencil", primaryFramebuffer); task.addJob("OpaqueRangeTimer", opaqueRangeTimer); @@ -390,146 +389,6 @@ void DrawOverlay3D::run(const RenderContextPointer& renderContext, const Inputs& } } - -gpu::PipelinePointer DrawStencilDeferred::getOpaquePipeline() { - if (!_opaquePipeline) { - const gpu::int8 STENCIL_OPAQUE = 1; - auto vs = gpu::StandardShaderLib::getDrawUnitQuadTexcoordVS(); - auto ps = gpu::Shader::createPixel(std::string(drawOpaqueStencil_frag)); - auto program = gpu::Shader::createProgram(vs, ps); - gpu::Shader::makeProgram((*program)); - - auto state = std::make_shared(); - state->setDepthTest(true, false, gpu::LESS_EQUAL); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(STENCIL_OPAQUE, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); - state->setColorWriteMask(0); - - _opaquePipeline = gpu::Pipeline::create(program, state); - } - return _opaquePipeline; -} - -void DrawStencilDeferred::run(const RenderContextPointer& renderContext, const DeferredFramebufferPointer& deferredFramebuffer) { - // return; - assert(renderContext->args); - assert(renderContext->args->hasViewFrustum()); - - // from the touched pixel generate the stencil buffer - RenderArgs* args = renderContext->args; - doInBatch(args->_context, [&](gpu::Batch& batch) { - args->_batch = &batch; - - auto deferredFboColorDepthStencil = deferredFramebuffer->getDeferredFramebufferDepthColor(); - - - batch.enableStereo(false); - - batch.setFramebuffer(deferredFboColorDepthStencil); - batch.setViewportTransform(args->_viewport); - batch.setStateScissorRect(args->_viewport); - - batch.setPipeline(getOpaquePipeline()); - - batch.draw(gpu::TRIANGLE_STRIP, 4); - batch.setResourceTexture(0, nullptr); - - }); - args->_batch = nullptr; -} - -void DrawBackgroundDeferred::run(const RenderContextPointer& renderContext, const Inputs& inputs) { - assert(renderContext->args); - assert(renderContext->args->hasViewFrustum()); - - const auto& inItems = inputs.get0(); - const auto& lightingModel = inputs.get1(); - if (!lightingModel->isBackgroundEnabled()) { - return; - } - - RenderArgs* args = renderContext->args; - doInBatch(args->_context, [&](gpu::Batch& batch) { - args->_batch = &batch; - // _gpuTimer.begin(batch); - - batch.enableSkybox(true); - - batch.setViewportTransform(args->_viewport); - batch.setStateScissorRect(args->_viewport); - - glm::mat4 projMat; - Transform viewMat; - args->getViewFrustum().evalProjectionMatrix(projMat); - args->getViewFrustum().evalViewTransform(viewMat); - - batch.setProjectionTransform(projMat); - batch.setViewTransform(viewMat); - - renderItems(renderContext, inItems); - // _gpuTimer.end(batch); - }); - args->_batch = nullptr; - - // std::static_pointer_cast(renderContext->jobConfig)->gpuTime = _gpuTimer.getAverage(); -} - -gpu::PipelinePointer PrepareStencil::getDrawStencilPipeline() { - if (!_drawStencilPipeline) { - auto vs = gpu::StandardShaderLib::getDrawVertexPositionVS(); - auto ps = gpu::StandardShaderLib::getDrawWhitePS(); - auto program = gpu::Shader::createProgram(vs, ps); - gpu::Shader::makeProgram((*program)); - - auto state = std::make_shared(); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(STENCIL_MASK, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE)); - // state->setColorWriteMask(0); - - _drawStencilPipeline = gpu::Pipeline::create(program, state); - } - return _drawStencilPipeline; -} - -model::MeshPointer PrepareStencil::getMesh() { - if (!_mesh) { - - std::vector vertices { - { -1.0f, -1.0f, 0.0f }, { -1.0f, 0.0f, 0.0f }, - { -1.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, - { 1.0f, 1.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, - { 1.0f, -1.0f, 0.0f }, { 0.0f, -1.0f, 0.0f } }; - - std::vector indices { 0, 7, 1, 1, 3, 2, 3, 5, 4, 5, 7, 6 }; - _mesh = model::Mesh::createIndexedTriangles_P3F((uint32_t) vertices.size(), (uint32_t) indices.size(), vertices.data(), indices.data()); - } - return _mesh; -} - - -void PrepareStencil::run(const RenderContextPointer& renderContext, const gpu::FramebufferPointer& srcFramebuffer) { - assert(renderContext->args); - assert(renderContext->args->_context); - - RenderArgs* args = renderContext->args; - doInBatch(args->_context, [&](gpu::Batch& batch) { - args->_batch = &batch; - batch.enableStereo(false); - - batch.setViewportTransform(args->_viewport); - - batch.setPipeline(getDrawStencilPipeline()); - - auto mesh = getMesh(); - batch.setIndexBuffer(mesh->getIndexBuffer()); - batch.setInputFormat((mesh->getVertexFormat())); - batch.setInputStream(0, mesh->getVertexStream()); - - // Draw - auto part = mesh->getPartBuffer().get(0); - batch.drawIndexed(gpu::TRIANGLES, part._numIndices, part._startIndex); - }); - args->_batch = nullptr; -} - void Blit::run(const RenderContextPointer& renderContext, const gpu::FramebufferPointer& srcFramebuffer) { assert(renderContext->args); assert(renderContext->args->_context); diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index c978a5f9a3..fd7c5eb23b 100644 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -13,7 +13,6 @@ #define hifi_RenderDeferredTask_h #include -#include #include #include "LightingModel.h" @@ -121,35 +120,6 @@ protected: bool _stateSort; }; -class DeferredFramebuffer; -class DrawStencilDeferred { -public: - using JobModel = render::Job::ModelI>; - - void run(const render::RenderContextPointer& renderContext, const std::shared_ptr& deferredFramebuffer); - -protected: - gpu::PipelinePointer _opaquePipeline; - - gpu::PipelinePointer getOpaquePipeline(); -}; - -using DrawBackgroundDeferredConfig = render::GPUJobConfig; - -class DrawBackgroundDeferred { -public: - using Inputs = render::VaryingSet2 ; - - using Config = DrawBackgroundDeferredConfig; - using JobModel = render::Job::ModelI; - - void configure(const Config& config) {} - void run(const render::RenderContextPointer& renderContext, const Inputs& inputs); - -protected: - gpu::RangeTimerPointer _gpuTimer; -}; - class DrawOverlay3DConfig : public render::Job::Config { Q_OBJECT Q_PROPERTY(int numDrawn READ getNumDrawn NOTIFY numDrawnChanged) @@ -186,24 +156,6 @@ protected: bool _opaquePass{ true }; }; -class PrepareStencil { -public: - using JobModel = render::Job::ModelI; - - void run(const render::RenderContextPointer& renderContext, const gpu::FramebufferPointer& dstFramebuffer); - - static const gpu::int8 STENCIL_MASK = 64; - -private: - gpu::PipelinePointer _drawStencilPipeline; - gpu::PipelinePointer getDrawStencilPipeline(); - - model::MeshPointer _mesh; - model::MeshPointer getMesh(); - -}; - - class Blit { public: using JobModel = render::Job::ModelI; diff --git a/libraries/render-utils/src/RenderPipelines.cpp b/libraries/render-utils/src/RenderPipelines.cpp index c83e5c5f34..9ca9187df8 100644 --- a/libraries/render-utils/src/RenderPipelines.cpp +++ b/libraries/render-utils/src/RenderPipelines.cpp @@ -330,7 +330,7 @@ void addPlumberPipeline(ShapePlumber& plumber, bool isWireframed = (i & 4); auto state = std::make_shared(); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::GREATER, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_INCR_SAT)); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(2, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_ZERO)); // Depth test depends on transparency state->setDepthTest(true, !key.isTranslucent(), gpu::LESS_EQUAL); diff --git a/libraries/render-utils/src/StencilMaskPass.cpp b/libraries/render-utils/src/StencilMaskPass.cpp new file mode 100644 index 0000000000..612324a79b --- /dev/null +++ b/libraries/render-utils/src/StencilMaskPass.cpp @@ -0,0 +1,123 @@ +// +// StencilMaskPass.cpp +// render-utils/src/ +// +// Created by Sam Gateau on 5/31/17. +// 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 "StencilMaskPass.h" + +#include +#include +#include + + +#include + + +using namespace render; + +gpu::PipelinePointer DrawStencilDeferred::getOpaquePipeline() { + if (!_opaquePipeline) { + const gpu::int8 STENCIL_OPAQUE = 0; + auto vs = gpu::StandardShaderLib::getDrawUnitQuadTexcoordVS(); + auto ps = gpu::StandardShaderLib::getDrawNadaPS(); + auto program = gpu::Shader::createProgram(vs, ps); + gpu::Shader::makeProgram((*program)); + + auto state = std::make_shared(); + state->setDepthTest(true, false, gpu::LESS_EQUAL); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(STENCIL_OPAQUE, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + state->setColorWriteMask(0); + + _opaquePipeline = gpu::Pipeline::create(program, state); + } + return _opaquePipeline; +} + +void DrawStencilDeferred::run(const RenderContextPointer& renderContext, const gpu::FramebufferPointer& deferredFramebuffer) { + return; + assert(renderContext->args); + assert(renderContext->args->hasViewFrustum()); + + // from the touched pixel generate the stencil buffer + RenderArgs* args = renderContext->args; + doInBatch(args->_context, [&](gpu::Batch& batch) { + args->_batch = &batch; + + batch.enableStereo(false); + + // batch.setFramebuffer(deferredFramebuffer); + batch.setViewportTransform(args->_viewport); + batch.setStateScissorRect(args->_viewport); + + batch.setPipeline(getOpaquePipeline()); + + batch.draw(gpu::TRIANGLE_STRIP, 4); + batch.setResourceTexture(0, nullptr); + + }); + args->_batch = nullptr; +} + +gpu::PipelinePointer PrepareStencil::getDrawStencilPipeline() { + if (!_drawStencilPipeline) { + auto vs = gpu::StandardShaderLib::getDrawVertexPositionVS(); + auto ps = gpu::StandardShaderLib::getDrawWhitePS(); + auto program = gpu::Shader::createProgram(vs, ps); + gpu::Shader::makeProgram((*program)); + + auto state = std::make_shared(); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(2, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE)); + // state->setColorWriteMask(0); + + _drawStencilPipeline = gpu::Pipeline::create(program, state); + } + return _drawStencilPipeline; +} + +model::MeshPointer PrepareStencil::getMesh() { + if (!_mesh) { + + std::vector vertices { + { -1.0f, -1.0f, 0.0f }, { -1.0f, 0.0f, 0.0f }, + { -1.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, + { 1.0f, 1.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, + { 1.0f, -1.0f, 0.0f }, { 0.0f, -1.0f, 0.0f } }; + + std::vector indices { 0, 7, 1, 1, 3, 2, 3, 5, 4, 5, 7, 6 }; + _mesh = model::Mesh::createIndexedTriangles_P3F((uint32_t) vertices.size(), (uint32_t) indices.size(), vertices.data(), indices.data()); + } + return _mesh; +} + + +void PrepareStencil::run(const RenderContextPointer& renderContext, const gpu::FramebufferPointer& srcFramebuffer) { + assert(renderContext->args); + assert(renderContext->args->_context); + + RenderArgs* args = renderContext->args; + doInBatch(args->_context, [&](gpu::Batch& batch) { + args->_batch = &batch; + batch.enableStereo(false); + + batch.setViewportTransform(args->_viewport); + + batch.setPipeline(getDrawStencilPipeline()); + + auto mesh = getMesh(); + batch.setIndexBuffer(mesh->getIndexBuffer()); + batch.setInputFormat((mesh->getVertexFormat())); + batch.setInputStream(0, mesh->getVertexStream()); + + // Draw + auto part = mesh->getPartBuffer().get(0); + batch.drawIndexed(gpu::TRIANGLES, part._numIndices, part._startIndex); + }); + args->_batch = nullptr; +} + diff --git a/libraries/render-utils/src/StencilMaskPass.h b/libraries/render-utils/src/StencilMaskPass.h new file mode 100644 index 0000000000..bf21602462 --- /dev/null +++ b/libraries/render-utils/src/StencilMaskPass.h @@ -0,0 +1,50 @@ +// +// StencilMaskPass.h +// render-utils/src/ +// +// Created by Sam Gateau on 5/31/17. +// Copyright 20154 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#pragma once +#ifndef hifi_StencilMaskPass_h +#define hifi_StencilMaskPass_h + +#include +#include +#include + + +class DrawStencilDeferred { +public: + using JobModel = render::Job::ModelI; + + void run(const render::RenderContextPointer& renderContext, const gpu::FramebufferPointer& deferredFramebuffer); + +protected: + gpu::PipelinePointer _opaquePipeline; + + gpu::PipelinePointer getOpaquePipeline(); +}; + +class PrepareStencil { +public: + using JobModel = render::Job::ModelI; + + void run(const render::RenderContextPointer& renderContext, const gpu::FramebufferPointer& dstFramebuffer); + + static const gpu::int8 STENCIL_MASK = 64; + +private: + gpu::PipelinePointer _drawStencilPipeline; + gpu::PipelinePointer getDrawStencilPipeline(); + + model::MeshPointer _mesh; + model::MeshPointer getMesh(); + +}; + + +#endif // hifi_StencilMaskPass_h diff --git a/libraries/render-utils/src/SurfaceGeometryPass.cpp b/libraries/render-utils/src/SurfaceGeometryPass.cpp index ef50960b7d..746c25daa5 100644 --- a/libraries/render-utils/src/SurfaceGeometryPass.cpp +++ b/libraries/render-utils/src/SurfaceGeometryPass.cpp @@ -224,7 +224,7 @@ const gpu::PipelinePointer& LinearDepthPass::getLinearDepthPipeline() { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); // Stencil test the curvature pass for objects pixels only, not the background - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); state->setColorWriteMask(true, false, false, false); @@ -554,7 +554,7 @@ const gpu::PipelinePointer& SurfaceGeometryPass::getCurvaturePipeline() { #ifdef USE_STENCIL_TEST // Stencil test the curvature pass for objects pixels only, not the background - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); #endif // Good to go add the brand new pipeline _curvaturePipeline = gpu::Pipeline::create(program, state); diff --git a/libraries/render-utils/src/drawOpaqueStencil.slf b/libraries/render-utils/src/drawOpaqueStencil.slf deleted file mode 100644 index 43e9c5c27a..0000000000 --- a/libraries/render-utils/src/drawOpaqueStencil.slf +++ /dev/null @@ -1,16 +0,0 @@ -<@include gpu/Config.slh@> -<$VERSION_HEADER$> -// Generated on <$_SCRIBE_DATE$> -// -// drawOpaqueStencil.frag -// fragment shader -// -// Created by Sam Gateau on 9/29/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 -// - -void main(void) { -} From b528c2fc60a70f9532644a11dbcc7eee8c74f851 Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Wed, 31 May 2017 19:33:14 -0700 Subject: [PATCH 04/12] Merged --- libraries/render-utils/src/DeferredLightingEffect.cpp | 5 +++-- libraries/render-utils/src/RenderPipelines.cpp | 3 ++- libraries/render-utils/src/StencilMaskPass.cpp | 7 +++---- libraries/render-utils/src/StencilMaskPass.h | 4 +++- libraries/render-utils/src/SurfaceGeometryPass.cpp | 6 +++--- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 04255fbb87..9f28240065 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -18,6 +18,7 @@ #include #include +#include "StencilMaskPass.h" #include "AbstractViewStateInterface.h" #include "GeometryCache.h" #include "TextureCache.h" @@ -242,7 +243,7 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo state->setColorWriteMask(true, true, true, false); if (lightVolume) { - state->setStencilTest(true, 0x00, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + state->setStencilTest(true, 0x00, gpu::State::StencilTest(PrepareStencil::STENCIL_SCENE, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); state->setCullMode(gpu::State::CULL_BACK); // state->setCullMode(gpu::State::CULL_FRONT); @@ -255,7 +256,7 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo } else { // Stencil test all the light passes for objects pixels only, not the background - state->setStencilTest(true, 0x00, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + state->setStencilTest(true, 0x00, gpu::State::StencilTest(PrepareStencil::STENCIL_SCENE, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); state->setCullMode(gpu::State::CULL_BACK); // additive blending diff --git a/libraries/render-utils/src/RenderPipelines.cpp b/libraries/render-utils/src/RenderPipelines.cpp index 9ca9187df8..be2bb0efbe 100644 --- a/libraries/render-utils/src/RenderPipelines.cpp +++ b/libraries/render-utils/src/RenderPipelines.cpp @@ -15,6 +15,7 @@ #include #include +#include "StencilMaskPass.h" #include "DeferredLightingEffect.h" #include "TextureCache.h" #include "render/DrawTask.h" @@ -330,7 +331,7 @@ void addPlumberPipeline(ShapePlumber& plumber, bool isWireframed = (i & 4); auto state = std::make_shared(); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(2, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_ZERO)); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_MASK, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_ZERO)); // Depth test depends on transparency state->setDepthTest(true, !key.isTranslucent(), gpu::LESS_EQUAL); diff --git a/libraries/render-utils/src/StencilMaskPass.cpp b/libraries/render-utils/src/StencilMaskPass.cpp index 612324a79b..6cdcfdf8d2 100644 --- a/libraries/render-utils/src/StencilMaskPass.cpp +++ b/libraries/render-utils/src/StencilMaskPass.cpp @@ -23,7 +23,6 @@ using namespace render; gpu::PipelinePointer DrawStencilDeferred::getOpaquePipeline() { if (!_opaquePipeline) { - const gpu::int8 STENCIL_OPAQUE = 0; auto vs = gpu::StandardShaderLib::getDrawUnitQuadTexcoordVS(); auto ps = gpu::StandardShaderLib::getDrawNadaPS(); auto program = gpu::Shader::createProgram(vs, ps); @@ -31,7 +30,7 @@ gpu::PipelinePointer DrawStencilDeferred::getOpaquePipeline() { auto state = std::make_shared(); state->setDepthTest(true, false, gpu::LESS_EQUAL); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(STENCIL_OPAQUE, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_SCENE, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); state->setColorWriteMask(0); _opaquePipeline = gpu::Pipeline::create(program, state); @@ -67,12 +66,12 @@ void DrawStencilDeferred::run(const RenderContextPointer& renderContext, const g gpu::PipelinePointer PrepareStencil::getDrawStencilPipeline() { if (!_drawStencilPipeline) { auto vs = gpu::StandardShaderLib::getDrawVertexPositionVS(); - auto ps = gpu::StandardShaderLib::getDrawWhitePS(); + auto ps = gpu::StandardShaderLib::getDrawNadaPS(); auto program = gpu::Shader::createProgram(vs, ps); gpu::Shader::makeProgram((*program)); auto state = std::make_shared(); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(2, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE)); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_MASK, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE)); // state->setColorWriteMask(0); _drawStencilPipeline = gpu::Pipeline::create(program, state); diff --git a/libraries/render-utils/src/StencilMaskPass.h b/libraries/render-utils/src/StencilMaskPass.h index bf21602462..8c05a46efa 100644 --- a/libraries/render-utils/src/StencilMaskPass.h +++ b/libraries/render-utils/src/StencilMaskPass.h @@ -35,7 +35,9 @@ public: void run(const render::RenderContextPointer& renderContext, const gpu::FramebufferPointer& dstFramebuffer); - static const gpu::int8 STENCIL_MASK = 64; + static const gpu::int8 STENCIL_MASK = 2; + static const gpu::int8 STENCIL_BACKGROUND = 1; + static const gpu::int8 STENCIL_SCENE = 0; private: gpu::PipelinePointer _drawStencilPipeline; diff --git a/libraries/render-utils/src/SurfaceGeometryPass.cpp b/libraries/render-utils/src/SurfaceGeometryPass.cpp index 746c25daa5..a13bc2846e 100644 --- a/libraries/render-utils/src/SurfaceGeometryPass.cpp +++ b/libraries/render-utils/src/SurfaceGeometryPass.cpp @@ -14,7 +14,7 @@ #include #include - +#include "StencilMaskPass.h" const int DepthLinearPass_FrameTransformSlot = 0; const int DepthLinearPass_DepthMapSlot = 0; @@ -224,7 +224,7 @@ const gpu::PipelinePointer& LinearDepthPass::getLinearDepthPipeline() { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); // Stencil test the curvature pass for objects pixels only, not the background - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_SCENE, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); state->setColorWriteMask(true, false, false, false); @@ -554,7 +554,7 @@ const gpu::PipelinePointer& SurfaceGeometryPass::getCurvaturePipeline() { #ifdef USE_STENCIL_TEST // Stencil test the curvature pass for objects pixels only, not the background - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_SCENE, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); #endif // Good to go add the brand new pipeline _curvaturePipeline = gpu::Pipeline::create(program, state); From e02115bcda5b1e921847ad09e3022111ee8e3089 Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Wed, 31 May 2017 23:00:05 -0700 Subject: [PATCH 05/12] clearing up the stencil jobs --- .../render-utils/src/StencilMaskPass.cpp | 66 ++++++++++++------- libraries/render-utils/src/StencilMaskPass.h | 7 +- 2 files changed, 49 insertions(+), 24 deletions(-) diff --git a/libraries/render-utils/src/StencilMaskPass.cpp b/libraries/render-utils/src/StencilMaskPass.cpp index 6cdcfdf8d2..3194dddb49 100644 --- a/libraries/render-utils/src/StencilMaskPass.cpp +++ b/libraries/render-utils/src/StencilMaskPass.cpp @@ -63,21 +63,7 @@ void DrawStencilDeferred::run(const RenderContextPointer& renderContext, const g args->_batch = nullptr; } -gpu::PipelinePointer PrepareStencil::getDrawStencilPipeline() { - if (!_drawStencilPipeline) { - auto vs = gpu::StandardShaderLib::getDrawVertexPositionVS(); - auto ps = gpu::StandardShaderLib::getDrawNadaPS(); - auto program = gpu::Shader::createProgram(vs, ps); - gpu::Shader::makeProgram((*program)); - auto state = std::make_shared(); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_MASK, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE)); - // state->setColorWriteMask(0); - - _drawStencilPipeline = gpu::Pipeline::create(program, state); - } - return _drawStencilPipeline; -} model::MeshPointer PrepareStencil::getMesh() { if (!_mesh) { @@ -94,6 +80,37 @@ model::MeshPointer PrepareStencil::getMesh() { return _mesh; } +gpu::PipelinePointer PrepareStencil::getMeshStencilPipeline() { + if (!_meshStencilPipeline) { + auto vs = gpu::StandardShaderLib::getDrawVertexPositionVS(); + auto ps = gpu::StandardShaderLib::getDrawNadaPS(); + auto program = gpu::Shader::createProgram(vs, ps); + gpu::Shader::makeProgram((*program)); + + auto state = std::make_shared(); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_MASK, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE)); + state->setColorWriteMask(0); + + _meshStencilPipeline = gpu::Pipeline::create(program, state); + } + return _meshStencilPipeline; +} + +gpu::PipelinePointer PrepareStencil::getPaintStencilPipeline() { + if (!_paintStencilPipeline) { + auto vs = gpu::StandardShaderLib::getDrawUnitQuadTexcoordVS(); + auto ps = gpu::StandardShaderLib::getDrawNadaPS(); + auto program = gpu::Shader::createProgram(vs, ps); + gpu::Shader::makeProgram((*program)); + + auto state = std::make_shared(); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_MASK, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE)); + state->setColorWriteMask(0); + + _paintStencilPipeline = gpu::Pipeline::create(program, state); + } + return _paintStencilPipeline; +} void PrepareStencil::run(const RenderContextPointer& renderContext, const gpu::FramebufferPointer& srcFramebuffer) { assert(renderContext->args); @@ -106,16 +123,21 @@ void PrepareStencil::run(const RenderContextPointer& renderContext, const gpu::F batch.setViewportTransform(args->_viewport); - batch.setPipeline(getDrawStencilPipeline()); + if (true) { + batch.setPipeline(getMeshStencilPipeline()); - auto mesh = getMesh(); - batch.setIndexBuffer(mesh->getIndexBuffer()); - batch.setInputFormat((mesh->getVertexFormat())); - batch.setInputStream(0, mesh->getVertexStream()); + auto mesh = getMesh(); + batch.setIndexBuffer(mesh->getIndexBuffer()); + batch.setInputFormat((mesh->getVertexFormat())); + batch.setInputStream(0, mesh->getVertexStream()); - // Draw - auto part = mesh->getPartBuffer().get(0); - batch.drawIndexed(gpu::TRIANGLES, part._numIndices, part._startIndex); + // Draw + auto part = mesh->getPartBuffer().get(0); + batch.drawIndexed(gpu::TRIANGLES, part._numIndices, part._startIndex); + } else { + batch.setPipeline(getPaintStencilPipeline()); + batch.draw(gpu::TRIANGLE_STRIP, 4); + } }); args->_batch = nullptr; } diff --git a/libraries/render-utils/src/StencilMaskPass.h b/libraries/render-utils/src/StencilMaskPass.h index 8c05a46efa..0532e23fac 100644 --- a/libraries/render-utils/src/StencilMaskPass.h +++ b/libraries/render-utils/src/StencilMaskPass.h @@ -40,8 +40,11 @@ public: static const gpu::int8 STENCIL_SCENE = 0; private: - gpu::PipelinePointer _drawStencilPipeline; - gpu::PipelinePointer getDrawStencilPipeline(); + gpu::PipelinePointer _meshStencilPipeline; + gpu::PipelinePointer getMeshStencilPipeline(); + + gpu::PipelinePointer _paintStencilPipeline; + gpu::PipelinePointer getPaintStencilPipeline(); model::MeshPointer _mesh; model::MeshPointer getMesh(); From ea6be93c9c872768cec0c88a029323027a10242c Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Thu, 1 Jun 2017 01:24:57 -0700 Subject: [PATCH 06/12] adding another flavor of the prepare stencil --- .../render-utils/src/StencilMaskPass.cpp | 5 +++-- libraries/render-utils/src/StencilMaskPass.h | 10 +++++++-- .../render-utils/src/stencil_drawMask.slf | 21 +++++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 libraries/render-utils/src/stencil_drawMask.slf diff --git a/libraries/render-utils/src/StencilMaskPass.cpp b/libraries/render-utils/src/StencilMaskPass.cpp index 3194dddb49..358f772354 100644 --- a/libraries/render-utils/src/StencilMaskPass.cpp +++ b/libraries/render-utils/src/StencilMaskPass.cpp @@ -18,6 +18,7 @@ #include +#include "stencil_drawMask_frag.h" using namespace render; @@ -99,7 +100,7 @@ gpu::PipelinePointer PrepareStencil::getMeshStencilPipeline() { gpu::PipelinePointer PrepareStencil::getPaintStencilPipeline() { if (!_paintStencilPipeline) { auto vs = gpu::StandardShaderLib::getDrawUnitQuadTexcoordVS(); - auto ps = gpu::StandardShaderLib::getDrawNadaPS(); + auto ps = gpu::Shader::createPixel(std::string(stencil_drawMask_frag)); auto program = gpu::Shader::createProgram(vs, ps); gpu::Shader::makeProgram((*program)); @@ -123,7 +124,7 @@ void PrepareStencil::run(const RenderContextPointer& renderContext, const gpu::F batch.setViewportTransform(args->_viewport); - if (true) { + if (false) { batch.setPipeline(getMeshStencilPipeline()); auto mesh = getMesh(); diff --git a/libraries/render-utils/src/StencilMaskPass.h b/libraries/render-utils/src/StencilMaskPass.h index 0532e23fac..d1de0cd1f4 100644 --- a/libraries/render-utils/src/StencilMaskPass.h +++ b/libraries/render-utils/src/StencilMaskPass.h @@ -16,7 +16,6 @@ #include #include - class DrawStencilDeferred { public: using JobModel = render::Job::ModelI; @@ -31,7 +30,14 @@ protected: class PrepareStencil { public: - using JobModel = render::Job::ModelI; + class Config : public render::JobConfig { + public: + Config(bool enabled = true) : JobConfig(enabled) {} + }; + + using JobModel = render::Job::ModelI; + + void configure(const Config& config) {} void run(const render::RenderContextPointer& renderContext, const gpu::FramebufferPointer& dstFramebuffer); diff --git a/libraries/render-utils/src/stencil_drawMask.slf b/libraries/render-utils/src/stencil_drawMask.slf new file mode 100644 index 0000000000..cc81fca677 --- /dev/null +++ b/libraries/render-utils/src/stencil_drawMask.slf @@ -0,0 +1,21 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// stencil_drawMask.slf +// fragment shader +// +// Created by Sam Gateau on 5/31/17. +// Copyright 2017 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 +// + +in vec2 varTexCoord0; + +void main(void) { + vec2 pos = varTexCoord0 * 2.0 - vec2(1.0); + pos.x = pos.x * (pos.x > 0.0 ? 2.0 : -2.0) - 1.0; + if (1.0 - dot(pos.xy, pos.xy) > 0.0 ) discard; +} From 9c1e99fe3f9a353b5fbaa15ecaf892c19b0fc969 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 1 Jun 2017 13:06:22 -0700 Subject: [PATCH 07/12] Removing cruft and organizing the stencil config --- .../RenderableParticleEffectEntityItem.cpp | 3 + .../src/RenderablePolyLineEntityItem.cpp | 2 + .../src/RenderablePolyVoxEntityItem.cpp | 5 + .../src/RenderableShapeEntityItem.cpp | 2 + libraries/model/src/model/Skybox.cpp | 2 +- .../src/procedural/ProceduralSkybox.cpp | 2 +- .../render-utils/src/AntialiasingEffect.cpp | 4 + .../src/DeferredLightingEffect.cpp | 4 +- libraries/render-utils/src/GeometryCache.cpp | 20 ++++ libraries/render-utils/src/HitEffect.cpp | 94 ------------------- libraries/render-utils/src/HitEffect.h | 38 -------- libraries/render-utils/src/LightClusters.cpp | 2 + .../render-utils/src/StencilMaskPass.cpp | 63 ++++--------- libraries/render-utils/src/StencilMaskPass.h | 21 ++--- .../render-utils/src/SurfaceGeometryPass.cpp | 1 + .../render-utils/src/ToneMappingEffect.cpp | 3 +- libraries/render-utils/src/ZoneRenderer.cpp | 4 + libraries/render-utils/src/hit_effect.slf | 27 ------ libraries/render-utils/src/hit_effect.slv | 26 ----- 19 files changed, 74 insertions(+), 249 deletions(-) delete mode 100644 libraries/render-utils/src/HitEffect.cpp delete mode 100644 libraries/render-utils/src/HitEffect.h delete mode 100644 libraries/render-utils/src/hit_effect.slf delete mode 100644 libraries/render-utils/src/hit_effect.slv diff --git a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp index 34dc86d92a..d813a73773 100644 --- a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "EntitiesRendererLogging.h" @@ -292,6 +293,7 @@ void RenderableParticleEffectEntityItem::createPipelines() { state->setDepthTest(true, false, gpu::LESS_EQUAL); state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE, gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); + PrepareStencil::testMask(*state); auto vertShader = gpu::Shader::createVertex(std::string(untextured_particle_vert)); auto fragShader = gpu::Shader::createPixel(std::string(untextured_particle_frag)); @@ -305,6 +307,7 @@ void RenderableParticleEffectEntityItem::createPipelines() { state->setDepthTest(true, false, gpu::LESS_EQUAL); state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE, gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); + PrepareStencil::testMask(*state); auto vertShader = gpu::Shader::createVertex(std::string(textured_particle_vert)); auto fragShader = gpu::Shader::createPixel(std::string(textured_particle_frag)); diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index a34a1814b4..1e20956301 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -69,6 +70,7 @@ void RenderablePolyLineEntityItem::createPipeline() { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); state->setDepthTest(true, true, gpu::LESS_EQUAL); + PrepareStencil::testMask(*state); 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); diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index fd5346093b..7567566919 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -46,6 +46,9 @@ #endif #include "model/Geometry.h" + +#include "StencilMaskPass.h" + #include "EntityTreeRenderer.h" #include "polyvox_vert.h" #include "polyvox_frag.h" @@ -743,6 +746,7 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) { auto state = std::make_shared(); state->setCullMode(gpu::State::CULL_BACK); state->setDepthTest(true, true, gpu::LESS_EQUAL); + PrepareStencil::testMaskDrawShape(*state); _pipeline = gpu::Pipeline::create(program, state); @@ -750,6 +754,7 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) { wireframeState->setCullMode(gpu::State::CULL_BACK); wireframeState->setDepthTest(true, true, gpu::LESS_EQUAL); wireframeState->setFillMode(gpu::State::FILL_LINE); + PrepareStencil::testMaskDrawShape(*wireframeState); _wireframePipeline = gpu::Pipeline::create(program, wireframeState); } diff --git a/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp b/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp index 1ad60bf7c6..27dd678d91 100644 --- a/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -93,6 +94,7 @@ void RenderableShapeEntityItem::render(RenderArgs* args) { _procedural->_fragmentSource = simple_frag; _procedural->_opaqueState->setCullMode(gpu::State::CULL_NONE); _procedural->_opaqueState->setDepthTest(true, true, gpu::LESS_EQUAL); + PrepareStencil::testMaskDrawShape(*_procedural->_opaqueState); _procedural->_opaqueState->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); diff --git a/libraries/model/src/model/Skybox.cpp b/libraries/model/src/model/Skybox.cpp index d327593573..c47463666e 100755 --- a/libraries/model/src/model/Skybox.cpp +++ b/libraries/model/src/model/Skybox.cpp @@ -97,7 +97,7 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky } auto skyState = std::make_shared(); - skyState->setStencilTest(true, 0xFF, gpu::State::StencilTest(1, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + skyState->setStencilTest(true, 0x00, gpu::State::StencilTest(1, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); thePipeline = gpu::Pipeline::create(skyShader, skyState); } diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.cpp b/libraries/procedural/src/procedural/ProceduralSkybox.cpp index f5feb434fa..eaacc5d851 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.cpp +++ b/libraries/procedural/src/procedural/ProceduralSkybox.cpp @@ -23,7 +23,7 @@ ProceduralSkybox::ProceduralSkybox() : model::Skybox() { _procedural._fragmentSource = skybox_frag; // Adjust the pipeline state for background using the stencil test _procedural.setDoesFade(false); - _procedural._opaqueState->setStencilTest(true, 0xFF, gpu::State::StencilTest(1, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + _procedural._opaqueState->setStencilTest(true, 0x00, gpu::State::StencilTest(1, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); } bool ProceduralSkybox::empty() { diff --git a/libraries/render-utils/src/AntialiasingEffect.cpp b/libraries/render-utils/src/AntialiasingEffect.cpp index cd378d4e5b..08f69d07d0 100644 --- a/libraries/render-utils/src/AntialiasingEffect.cpp +++ b/libraries/render-utils/src/AntialiasingEffect.cpp @@ -17,6 +17,7 @@ #include #include "AntialiasingEffect.h" +#include "StencilMaskPass.h" #include "TextureCache.h" #include "FramebufferCache.h" #include "DependencyManager.h" @@ -70,6 +71,8 @@ const gpu::PipelinePointer& Antialiasing::getAntialiasingPipeline() { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); + PrepareStencil::testShape(*state); + state->setDepthTest(false, false, gpu::LESS_EQUAL); // Good to go add the brand new pipeline @@ -93,6 +96,7 @@ const gpu::PipelinePointer& Antialiasing::getBlendPipeline() { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); state->setDepthTest(false, false, gpu::LESS_EQUAL); + PrepareStencil::testShape(*state); // Good to go add the brand new pipeline _blendPipeline = gpu::Pipeline::create(program, state); diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 9f28240065..36a9401d00 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -243,7 +243,7 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo state->setColorWriteMask(true, true, true, false); if (lightVolume) { - state->setStencilTest(true, 0x00, gpu::State::StencilTest(PrepareStencil::STENCIL_SCENE, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + PrepareStencil::testShape(*state); state->setCullMode(gpu::State::CULL_BACK); // state->setCullMode(gpu::State::CULL_FRONT); @@ -256,7 +256,7 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo } else { // Stencil test all the light passes for objects pixels only, not the background - state->setStencilTest(true, 0x00, gpu::State::StencilTest(PrepareStencil::STENCIL_SCENE, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + PrepareStencil::testShape(*state); state->setCullMode(gpu::State::CULL_BACK); // additive blending diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index f1c995b943..5755d5a031 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -24,6 +24,7 @@ #include "TextureCache.h" #include "RenderUtilsLogging.h" +#include "StencilMaskPass.h" #include "gpu/StandardShaderLib.h" @@ -1610,6 +1611,9 @@ void GeometryCache::renderGlowLine(gpu::Batch& batch, const glm::vec3& p1, const 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); + + PrepareStencil::testMask(*state); + gpu::Shader::BindingSet slotBindings; slotBindings.insert(gpu::Shader::Binding(std::string("lineData"), LINE_DATA_SLOT)); gpu::Shader::makeProgram(*program, slotBindings); @@ -1663,11 +1667,14 @@ void GeometryCache::useSimpleDrawPipeline(gpu::Batch& batch, bool noBlend) { // enable decal blend state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); + PrepareStencil::testMask(*state); _standardDrawPipeline = gpu::Pipeline::create(program, state); auto stateNoBlend = std::make_shared(); + PrepareStencil::testMaskDrawShape(*state); + auto noBlendPS = gpu::StandardShaderLib::getDrawTextureOpaquePS(); auto programNoBlend = gpu::Shader::createProgram(vs, noBlendPS); gpu::Shader::makeProgram((*programNoBlend)); @@ -1690,12 +1697,14 @@ void GeometryCache::useGridPipeline(gpu::Batch& batch, GridBuffer gridBuffer, bo auto stateLayered = std::make_shared(); stateLayered->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); + PrepareStencil::testMask(*stateLayered); _gridPipelineLayered = gpu::Pipeline::create(program, stateLayered); auto state = std::make_shared(stateLayered->getValues()); const float DEPTH_BIAS = 0.001f; state->setDepthBias(DEPTH_BIAS); state->setDepthTest(true, false, gpu::LESS_EQUAL); + PrepareStencil::testMaskDrawShape(*state); _gridPipeline = gpu::Pipeline::create(program, state); } @@ -1773,6 +1782,11 @@ static void buildWebShader(const std::string& vertShaderText, const std::string& state->setBlendFunction(blendEnable, 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 (blendEnable) { + PrepareStencil::testMaskBlendShape(*state); + } else { + PrepareStencil::testMaskDrawShape(*state); + } pipelinePointerOut = gpu::Pipeline::create(shaderPointerOut, state); } @@ -1858,6 +1872,12 @@ gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transp 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 (config.isTransparent()) { + PrepareStencil::testMask(*state); + } else { + PrepareStencil::testMaskDrawShape(*state); + } + gpu::ShaderPointer program = (config.isUnlit()) ? _unlitShader : _simpleShader; gpu::PipelinePointer pipeline = gpu::Pipeline::create(program, state); _simplePrograms.insert(config, pipeline); diff --git a/libraries/render-utils/src/HitEffect.cpp b/libraries/render-utils/src/HitEffect.cpp deleted file mode 100644 index 319e94384f..0000000000 --- a/libraries/render-utils/src/HitEffect.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// -// HitEffect.cpp -// interface/src/renderer -// -// Created by Andrzej Kapolka on 7/14/13. -// Copyright 2013 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 this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL - - -#include - -#include -#include -#include - -#include "AbstractViewStateInterface.h" -#include "HitEffect.h" - -#include "TextureCache.h" -#include "DependencyManager.h" -#include "ViewFrustum.h" -#include "GeometryCache.h" - -#include - -#include "hit_effect_vert.h" -#include "hit_effect_frag.h" - - -HitEffect::HitEffect() { - _geometryId = DependencyManager::get()->allocateID(); -} - -HitEffect::~HitEffect() { - auto geometryCache = DependencyManager::get(); - if (_geometryId && geometryCache) { - geometryCache->releaseID(_geometryId); - } -} - -const gpu::PipelinePointer& HitEffect::getHitEffectPipeline() { - if (!_hitEffectPipeline) { - auto vs = gpu::Shader::createVertex(std::string(hit_effect_vert)); - auto ps = gpu::Shader::createPixel(std::string(hit_effect_frag)); - gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps); - - - gpu::Shader::BindingSet slotBindings; - gpu::Shader::makeProgram(*program, slotBindings); - - - gpu::StatePointer state = gpu::StatePointer(new gpu::State()); - - state->setDepthTest(false, false, gpu::LESS_EQUAL); - - // Blend on transparent - state->setBlendFunction(true, - gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); - - // Good to go add the brand new pipeline - _hitEffectPipeline = gpu::Pipeline::create(program, state); - } - return _hitEffectPipeline; -} - -void HitEffect::run(const render::RenderContextPointer& renderContext) { - assert(renderContext->args); - assert(renderContext->args->hasViewFrustum()); - RenderArgs* args = renderContext->args; - - gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { - - glm::mat4 projMat; - Transform viewMat; - args->getViewFrustum().evalProjectionMatrix(projMat); - args->getViewFrustum().evalViewTransform(viewMat); - batch.setProjectionTransform(projMat); - batch.setViewTransform(viewMat); - batch.setModelTransform(Transform()); - - batch.setPipeline(getHitEffectPipeline()); - - static const glm::vec4 color(0.0f, 0.0f, 0.0f, 1.0f); - static const glm::vec2 bottomLeft(-1.0f, -1.0f); - static const glm::vec2 topRight(1.0f, 1.0f); - DependencyManager::get()->renderQuad(batch, bottomLeft, topRight, color, _geometryId); - }); -} - diff --git a/libraries/render-utils/src/HitEffect.h b/libraries/render-utils/src/HitEffect.h deleted file mode 100644 index d025d2d980..0000000000 --- a/libraries/render-utils/src/HitEffect.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// hitEffect.h -// hifi -// -// Created by eric levin on 7/17/15. -// -// - -#ifndef hifi_hitEffect_h -#define hifi_hitEffect_h - -#include - -class HitEffectConfig : public render::Job::Config { - Q_OBJECT - Q_PROPERTY(bool enabled MEMBER enabled) -public: - HitEffectConfig() : render::Job::Config(false) {} -}; - -class HitEffect { -public: - using Config = HitEffectConfig; - using JobModel = render::Job::Model; - - HitEffect(); - ~HitEffect(); - void configure(const Config& config) {} - void run(const render::RenderContextPointer& renderContext); - - const gpu::PipelinePointer& getHitEffectPipeline(); - -private: - int _geometryId { 0 }; - gpu::PipelinePointer _hitEffectPipeline; -}; - -#endif diff --git a/libraries/render-utils/src/LightClusters.cpp b/libraries/render-utils/src/LightClusters.cpp index 4145264b2d..7e04b1c2a4 100644 --- a/libraries/render-utils/src/LightClusters.cpp +++ b/libraries/render-utils/src/LightClusters.cpp @@ -16,6 +16,8 @@ #include +#include "StencilMaskPass.h" + #include "lightClusters_drawGrid_vert.h" #include "lightClusters_drawGrid_frag.h" diff --git a/libraries/render-utils/src/StencilMaskPass.cpp b/libraries/render-utils/src/StencilMaskPass.cpp index 358f772354..44e7a571e8 100644 --- a/libraries/render-utils/src/StencilMaskPass.cpp +++ b/libraries/render-utils/src/StencilMaskPass.cpp @@ -22,50 +22,6 @@ using namespace render; -gpu::PipelinePointer DrawStencilDeferred::getOpaquePipeline() { - if (!_opaquePipeline) { - auto vs = gpu::StandardShaderLib::getDrawUnitQuadTexcoordVS(); - auto ps = gpu::StandardShaderLib::getDrawNadaPS(); - auto program = gpu::Shader::createProgram(vs, ps); - gpu::Shader::makeProgram((*program)); - - auto state = std::make_shared(); - state->setDepthTest(true, false, gpu::LESS_EQUAL); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_SCENE, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); - state->setColorWriteMask(0); - - _opaquePipeline = gpu::Pipeline::create(program, state); - } - return _opaquePipeline; -} - -void DrawStencilDeferred::run(const RenderContextPointer& renderContext, const gpu::FramebufferPointer& deferredFramebuffer) { - return; - assert(renderContext->args); - assert(renderContext->args->hasViewFrustum()); - - // from the touched pixel generate the stencil buffer - RenderArgs* args = renderContext->args; - doInBatch(args->_context, [&](gpu::Batch& batch) { - args->_batch = &batch; - - batch.enableStereo(false); - - // batch.setFramebuffer(deferredFramebuffer); - batch.setViewportTransform(args->_viewport); - batch.setStateScissorRect(args->_viewport); - - batch.setPipeline(getOpaquePipeline()); - - batch.draw(gpu::TRIANGLE_STRIP, 4); - batch.setResourceTexture(0, nullptr); - - }); - args->_batch = nullptr; -} - - - model::MeshPointer PrepareStencil::getMesh() { if (!_mesh) { @@ -89,7 +45,7 @@ gpu::PipelinePointer PrepareStencil::getMeshStencilPipeline() { gpu::Shader::makeProgram((*program)); auto state = std::make_shared(); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_MASK, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE)); + drawMask(state); state->setColorWriteMask(0); _meshStencilPipeline = gpu::Pipeline::create(program, state); @@ -105,7 +61,7 @@ gpu::PipelinePointer PrepareStencil::getPaintStencilPipeline() { gpu::Shader::makeProgram((*program)); auto state = std::make_shared(); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_MASK, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE)); + drawMask(state); state->setColorWriteMask(0); _paintStencilPipeline = gpu::Pipeline::create(program, state); @@ -143,3 +99,18 @@ void PrepareStencil::run(const RenderContextPointer& renderContext, const gpu::F args->_batch = nullptr; } +void PrepareStencil::drawMask(gpu::State& state) { + state.setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_MASK, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE)); +} + +void PrepareStencil::testMask(gpu::State& state) { + state.setStencilTest(true, 0x00, gpu::State::StencilTest(PrepareStencil::STENCIL_MASK, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); +} + +void PrepareStencil::testBackground(gpu::State& state) { + state.setStencilTest(true, 0x00, gpu::State::StencilTest(PrepareStencil::STENCIL_BACKGROUND, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); +} + +void PrepareStencil::testMaskDrawShape(gpu::State& state) { + state.setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_MASK, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_ZERO)); +} \ No newline at end of file diff --git a/libraries/render-utils/src/StencilMaskPass.h b/libraries/render-utils/src/StencilMaskPass.h index d1de0cd1f4..c65788ebf8 100644 --- a/libraries/render-utils/src/StencilMaskPass.h +++ b/libraries/render-utils/src/StencilMaskPass.h @@ -16,18 +16,6 @@ #include #include -class DrawStencilDeferred { -public: - using JobModel = render::Job::ModelI; - - void run(const render::RenderContextPointer& renderContext, const gpu::FramebufferPointer& deferredFramebuffer); - -protected: - gpu::PipelinePointer _opaquePipeline; - - gpu::PipelinePointer getOpaquePipeline(); -}; - class PrepareStencil { public: class Config : public render::JobConfig { @@ -43,7 +31,14 @@ public: static const gpu::int8 STENCIL_MASK = 2; static const gpu::int8 STENCIL_BACKGROUND = 1; - static const gpu::int8 STENCIL_SCENE = 0; + static const gpu::int8 STENCIL_SHAPE = 0; + + + static void drawMask(gpu::State& state); + static void testMask(gpu::State& state); + static void testBackground(gpu::State& state); + static void testMaskDrawShape(gpu::State& state); + private: gpu::PipelinePointer _meshStencilPipeline; diff --git a/libraries/render-utils/src/SurfaceGeometryPass.cpp b/libraries/render-utils/src/SurfaceGeometryPass.cpp index a13bc2846e..4b13fa2bf0 100644 --- a/libraries/render-utils/src/SurfaceGeometryPass.cpp +++ b/libraries/render-utils/src/SurfaceGeometryPass.cpp @@ -250,6 +250,7 @@ const gpu::PipelinePointer& LinearDepthPass::getDownsamplePipeline() { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_SCENE, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); state->setColorWriteMask(true, true, true, false); diff --git a/libraries/render-utils/src/ToneMappingEffect.cpp b/libraries/render-utils/src/ToneMappingEffect.cpp index d54481d246..df4e1e0e6a 100644 --- a/libraries/render-utils/src/ToneMappingEffect.cpp +++ b/libraries/render-utils/src/ToneMappingEffect.cpp @@ -15,7 +15,7 @@ #include #include - +#include "StencilMaskPass.h" #include "FramebufferCache.h" #include "toneMapping_frag.h" @@ -39,6 +39,7 @@ void ToneMappingEffect::init() { slotBindings.insert(gpu::Shader::Binding(std::string("colorMap"), ToneMappingEffect_LightingMapSlot)); gpu::Shader::makeProgram(*blitProgram, slotBindings); auto blitState = std::make_shared(); + blitState->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_SCENE, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); blitState->setColorWriteMask(true, true, true, true); _blitLightBuffer = gpu::PipelinePointer(gpu::Pipeline::create(blitProgram, blitState)); } diff --git a/libraries/render-utils/src/ZoneRenderer.cpp b/libraries/render-utils/src/ZoneRenderer.cpp index 3b4870fd3f..2fa6805cde 100644 --- a/libraries/render-utils/src/ZoneRenderer.cpp +++ b/libraries/render-utils/src/ZoneRenderer.cpp @@ -17,6 +17,7 @@ #include #include +#include "StencilMaskPass.h" #include "DeferredLightingEffect.h" #include "zone_drawKeyLight_frag.h" @@ -74,6 +75,7 @@ const gpu::PipelinePointer& DebugZoneLighting::getKeyLightPipeline() { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_SCENE, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); _keyLightPipeline = gpu::Pipeline::create(program, state); } @@ -95,6 +97,7 @@ const gpu::PipelinePointer& DebugZoneLighting::getAmbientPipeline() { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_SCENE, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); _ambientPipeline = gpu::Pipeline::create(program, state); } @@ -115,6 +118,7 @@ const gpu::PipelinePointer& DebugZoneLighting::getBackgroundPipeline() { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_SCENE, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); _backgroundPipeline = gpu::Pipeline::create(program, state); } diff --git a/libraries/render-utils/src/hit_effect.slf b/libraries/render-utils/src/hit_effect.slf deleted file mode 100644 index cc4484442f..0000000000 --- a/libraries/render-utils/src/hit_effect.slf +++ /dev/null @@ -1,27 +0,0 @@ -<@include gpu/Config.slh@> -<$VERSION_HEADER$> -// Generated on <$_SCRIBE_DATE$> -// - -// hit_effect.frag -// fragment shader -// -// Created by Eric Levin on 7/20 -// Copyright 2015 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - - -<@include DeferredBufferWrite.slh@> - -in vec2 varQuadPosition; -out vec4 outFragColor; - -void main(void) { - vec2 center = vec2(0.0, 0.0); - float distFromCenter = distance( vec2(0.0, 0.0), varQuadPosition); - float alpha = mix(0.0, 0.5, pow(distFromCenter,5.)); - outFragColor = vec4(1.0, 0.0, 0.0, alpha); -} \ No newline at end of file diff --git a/libraries/render-utils/src/hit_effect.slv b/libraries/render-utils/src/hit_effect.slv deleted file mode 100644 index b9b0638f9e..0000000000 --- a/libraries/render-utils/src/hit_effect.slv +++ /dev/null @@ -1,26 +0,0 @@ -<@include gpu/Config.slh@> -<$VERSION_HEADER$> -// Generated on <$_SCRIBE_DATE$> -// -// hit_effect.vert -// vertex shader -// -// Created by Eric Levin on 7/20/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 gpu/Inputs.slh@> - -<@include gpu/Transform.slh@> - -<$declareStandardTransform()$> - -out vec2 varQuadPosition; - -void main(void) { - varQuadPosition = inPosition.xy; - gl_Position = inPosition; -} \ No newline at end of file From c5e9551bab387b854ae71915b38e6494cf583754 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 1 Jun 2017 18:05:18 -0700 Subject: [PATCH 08/12] more cleanup --- libraries/render-utils/src/GeometryCache.cpp | 2 +- libraries/render-utils/src/RenderDeferredTask.cpp | 4 ---- libraries/render-utils/src/StencilMaskPass.cpp | 8 ++++++-- libraries/render-utils/src/StencilMaskPass.h | 1 + libraries/render-utils/src/SurfaceGeometryPass.cpp | 4 ++-- libraries/render-utils/src/ToneMappingEffect.cpp | 2 +- libraries/render-utils/src/ZoneRenderer.cpp | 6 +++--- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 5755d5a031..cd87cfdb3d 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1783,7 +1783,7 @@ static void buildWebShader(const std::string& vertShaderText, const std::string& 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 (blendEnable) { - PrepareStencil::testMaskBlendShape(*state); + PrepareStencil::testMask(*state); } else { PrepareStencil::testMaskDrawShape(*state); } diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 89b4b72944..1b99fe92ee 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -33,7 +33,6 @@ #include "DeferredLightingEffect.h" #include "SurfaceGeometryPass.h" #include "FramebufferCache.h" -#include "HitEffect.h" #include "TextureCache.h" #include "ZoneRenderer.h" @@ -91,9 +90,6 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto opaqueInputs = DrawStateSortDeferred::Inputs(opaques, lightingModel).hasVarying(); task.addJob("DrawOpaqueDeferred", opaqueInputs, shapePlumber); - // Once opaque is all rendered create stencil background - task.addJob("DrawOpaqueStencil", primaryFramebuffer); - task.addJob("OpaqueRangeTimer", opaqueRangeTimer); diff --git a/libraries/render-utils/src/StencilMaskPass.cpp b/libraries/render-utils/src/StencilMaskPass.cpp index 44e7a571e8..7a13a2d759 100644 --- a/libraries/render-utils/src/StencilMaskPass.cpp +++ b/libraries/render-utils/src/StencilMaskPass.cpp @@ -45,7 +45,7 @@ gpu::PipelinePointer PrepareStencil::getMeshStencilPipeline() { gpu::Shader::makeProgram((*program)); auto state = std::make_shared(); - drawMask(state); + drawMask(*state); state->setColorWriteMask(0); _meshStencilPipeline = gpu::Pipeline::create(program, state); @@ -61,7 +61,7 @@ gpu::PipelinePointer PrepareStencil::getPaintStencilPipeline() { gpu::Shader::makeProgram((*program)); auto state = std::make_shared(); - drawMask(state); + drawMask(*state); state->setColorWriteMask(0); _paintStencilPipeline = gpu::Pipeline::create(program, state); @@ -113,4 +113,8 @@ void PrepareStencil::testBackground(gpu::State& state) { void PrepareStencil::testMaskDrawShape(gpu::State& state) { state.setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_MASK, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_ZERO)); +} + +void PrepareStencil::testShape(gpu::State& state) { + state.setStencilTest(true, 0x00, gpu::State::StencilTest(PrepareStencil::STENCIL_SHAPE, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); } \ No newline at end of file diff --git a/libraries/render-utils/src/StencilMaskPass.h b/libraries/render-utils/src/StencilMaskPass.h index c65788ebf8..d7d6ee448b 100644 --- a/libraries/render-utils/src/StencilMaskPass.h +++ b/libraries/render-utils/src/StencilMaskPass.h @@ -38,6 +38,7 @@ public: static void testMask(gpu::State& state); static void testBackground(gpu::State& state); static void testMaskDrawShape(gpu::State& state); + static void testShape(gpu::State& state); private: diff --git a/libraries/render-utils/src/SurfaceGeometryPass.cpp b/libraries/render-utils/src/SurfaceGeometryPass.cpp index 4b13fa2bf0..de04c31622 100644 --- a/libraries/render-utils/src/SurfaceGeometryPass.cpp +++ b/libraries/render-utils/src/SurfaceGeometryPass.cpp @@ -224,7 +224,7 @@ const gpu::PipelinePointer& LinearDepthPass::getLinearDepthPipeline() { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); // Stencil test the curvature pass for objects pixels only, not the background - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_SCENE, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + PrepareStencil::testShape(*state); state->setColorWriteMask(true, false, false, false); @@ -250,7 +250,7 @@ const gpu::PipelinePointer& LinearDepthPass::getDownsamplePipeline() { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_SCENE, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + PrepareStencil::testShape(*state); state->setColorWriteMask(true, true, true, false); diff --git a/libraries/render-utils/src/ToneMappingEffect.cpp b/libraries/render-utils/src/ToneMappingEffect.cpp index df4e1e0e6a..62ae9147f3 100644 --- a/libraries/render-utils/src/ToneMappingEffect.cpp +++ b/libraries/render-utils/src/ToneMappingEffect.cpp @@ -39,7 +39,7 @@ void ToneMappingEffect::init() { slotBindings.insert(gpu::Shader::Binding(std::string("colorMap"), ToneMappingEffect_LightingMapSlot)); gpu::Shader::makeProgram(*blitProgram, slotBindings); auto blitState = std::make_shared(); - blitState->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_SCENE, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + PrepareStencil::testShape(*blitState); blitState->setColorWriteMask(true, true, true, true); _blitLightBuffer = gpu::PipelinePointer(gpu::Pipeline::create(blitProgram, blitState)); } diff --git a/libraries/render-utils/src/ZoneRenderer.cpp b/libraries/render-utils/src/ZoneRenderer.cpp index 2fa6805cde..b72e4eac69 100644 --- a/libraries/render-utils/src/ZoneRenderer.cpp +++ b/libraries/render-utils/src/ZoneRenderer.cpp @@ -75,7 +75,7 @@ const gpu::PipelinePointer& DebugZoneLighting::getKeyLightPipeline() { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_SCENE, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + PrepareStencil::testMask(*state); state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); _keyLightPipeline = gpu::Pipeline::create(program, state); } @@ -97,7 +97,7 @@ const gpu::PipelinePointer& DebugZoneLighting::getAmbientPipeline() { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_SCENE, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + PrepareStencil::testMask(*state); state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); _ambientPipeline = gpu::Pipeline::create(program, state); } @@ -118,7 +118,7 @@ const gpu::PipelinePointer& DebugZoneLighting::getBackgroundPipeline() { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_SCENE, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + PrepareStencil::testMask(*state); state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); _backgroundPipeline = gpu::Pipeline::create(program, state); } From 4a419f2d07a4a796834929b85d7aa49dfa24972f Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 1 Jun 2017 18:25:24 -0700 Subject: [PATCH 09/12] Merging with upstream --- libraries/render-utils/src/RenderPipelines.cpp | 2 +- libraries/render-utils/src/StencilMaskPass.cpp | 6 +++--- libraries/render-utils/src/SurfaceGeometryPass.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/render-utils/src/RenderPipelines.cpp b/libraries/render-utils/src/RenderPipelines.cpp index be2bb0efbe..42ed0bdad9 100644 --- a/libraries/render-utils/src/RenderPipelines.cpp +++ b/libraries/render-utils/src/RenderPipelines.cpp @@ -331,7 +331,7 @@ void addPlumberPipeline(ShapePlumber& plumber, bool isWireframed = (i & 4); auto state = std::make_shared(); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_MASK, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_ZERO)); + PrepareStencil::testMaskDrawShape(*state); // Depth test depends on transparency state->setDepthTest(true, !key.isTranslucent(), gpu::LESS_EQUAL); diff --git a/libraries/render-utils/src/StencilMaskPass.cpp b/libraries/render-utils/src/StencilMaskPass.cpp index 7a13a2d759..d8a4afbc43 100644 --- a/libraries/render-utils/src/StencilMaskPass.cpp +++ b/libraries/render-utils/src/StencilMaskPass.cpp @@ -104,11 +104,11 @@ void PrepareStencil::drawMask(gpu::State& state) { } void PrepareStencil::testMask(gpu::State& state) { - state.setStencilTest(true, 0x00, gpu::State::StencilTest(PrepareStencil::STENCIL_MASK, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + state.setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_MASK, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); } void PrepareStencil::testBackground(gpu::State& state) { - state.setStencilTest(true, 0x00, gpu::State::StencilTest(PrepareStencil::STENCIL_BACKGROUND, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + state.setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_BACKGROUND, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); } void PrepareStencil::testMaskDrawShape(gpu::State& state) { @@ -116,5 +116,5 @@ void PrepareStencil::testMaskDrawShape(gpu::State& state) { } void PrepareStencil::testShape(gpu::State& state) { - state.setStencilTest(true, 0x00, gpu::State::StencilTest(PrepareStencil::STENCIL_SHAPE, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + state.setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_SHAPE, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); } \ No newline at end of file diff --git a/libraries/render-utils/src/SurfaceGeometryPass.cpp b/libraries/render-utils/src/SurfaceGeometryPass.cpp index de04c31622..b0c0aa6358 100644 --- a/libraries/render-utils/src/SurfaceGeometryPass.cpp +++ b/libraries/render-utils/src/SurfaceGeometryPass.cpp @@ -555,7 +555,7 @@ const gpu::PipelinePointer& SurfaceGeometryPass::getCurvaturePipeline() { #ifdef USE_STENCIL_TEST // Stencil test the curvature pass for objects pixels only, not the background - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_SCENE, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + PrepareStencil::testMask(*state); #endif // Good to go add the brand new pipeline _curvaturePipeline = gpu::Pipeline::create(program, state); From f9aa400b951e2a9e18c809973fd434780786393b Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Fri, 2 Jun 2017 00:22:38 -0700 Subject: [PATCH 10/12] Refining the stencil configuration and triggering only in hmd mode --- interface/src/Application.cpp | 3 +++ libraries/model/src/model/Skybox.cpp | 2 +- .../src/procedural/ProceduralSkybox.cpp | 2 +- .../render-utils/src/AntialiasingEffect.cpp | 4 ++-- libraries/render-utils/src/StencilMaskPass.cpp | 17 +++++++++-------- .../render-utils/src/SurfaceGeometryPass.cpp | 2 +- .../render-utils/src/ToneMappingEffect.cpp | 2 +- libraries/render-utils/src/stencil_drawMask.slf | 4 +++- libraries/shared/src/RenderArgs.h | 8 ++++---- tests/shaders/src/main.cpp | 11 ----------- 10 files changed, 25 insertions(+), 30 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 8c6bea0905..f232f8c956 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2185,6 +2185,9 @@ void Application::paintGL() { }); renderArgs._context->setStereoProjections(eyeProjections); renderArgs._context->setStereoViews(eyeOffsets); + + // Configure the type of display / stereo + renderArgs._displayMode = (isHMDMode() ? RenderArgs::STEREO_HMD : RenderArgs::STEREO_MONITOR); } renderArgs._blitFramebuffer = finalFramebuffer; displaySide(&renderArgs, _myCamera); diff --git a/libraries/model/src/model/Skybox.cpp b/libraries/model/src/model/Skybox.cpp index c47463666e..d327593573 100755 --- a/libraries/model/src/model/Skybox.cpp +++ b/libraries/model/src/model/Skybox.cpp @@ -97,7 +97,7 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky } auto skyState = std::make_shared(); - skyState->setStencilTest(true, 0x00, gpu::State::StencilTest(1, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + skyState->setStencilTest(true, 0xFF, gpu::State::StencilTest(1, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); thePipeline = gpu::Pipeline::create(skyShader, skyState); } diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.cpp b/libraries/procedural/src/procedural/ProceduralSkybox.cpp index eaacc5d851..f5feb434fa 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.cpp +++ b/libraries/procedural/src/procedural/ProceduralSkybox.cpp @@ -23,7 +23,7 @@ ProceduralSkybox::ProceduralSkybox() : model::Skybox() { _procedural._fragmentSource = skybox_frag; // Adjust the pipeline state for background using the stencil test _procedural.setDoesFade(false); - _procedural._opaqueState->setStencilTest(true, 0x00, gpu::State::StencilTest(1, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + _procedural._opaqueState->setStencilTest(true, 0xFF, gpu::State::StencilTest(1, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); } bool ProceduralSkybox::empty() { diff --git a/libraries/render-utils/src/AntialiasingEffect.cpp b/libraries/render-utils/src/AntialiasingEffect.cpp index 08f69d07d0..139f1ae091 100644 --- a/libraries/render-utils/src/AntialiasingEffect.cpp +++ b/libraries/render-utils/src/AntialiasingEffect.cpp @@ -71,7 +71,7 @@ const gpu::PipelinePointer& Antialiasing::getAntialiasingPipeline() { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); - PrepareStencil::testShape(*state); + PrepareStencil::testMask(*state); state->setDepthTest(false, false, gpu::LESS_EQUAL); @@ -96,7 +96,7 @@ const gpu::PipelinePointer& Antialiasing::getBlendPipeline() { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); state->setDepthTest(false, false, gpu::LESS_EQUAL); - PrepareStencil::testShape(*state); + PrepareStencil::testMask(*state); // Good to go add the brand new pipeline _blendPipeline = gpu::Pipeline::create(program, state); diff --git a/libraries/render-utils/src/StencilMaskPass.cpp b/libraries/render-utils/src/StencilMaskPass.cpp index d8a4afbc43..dcd994763f 100644 --- a/libraries/render-utils/src/StencilMaskPass.cpp +++ b/libraries/render-utils/src/StencilMaskPass.cpp @@ -70,12 +70,14 @@ gpu::PipelinePointer PrepareStencil::getPaintStencilPipeline() { } void PrepareStencil::run(const RenderContextPointer& renderContext, const gpu::FramebufferPointer& srcFramebuffer) { - assert(renderContext->args); - assert(renderContext->args->_context); - RenderArgs* args = renderContext->args; + + // Only draw the stencil mask if in HMD mode. + if (args->_displayMode != RenderArgs::STEREO_HMD) { + return; + } + doInBatch(args->_context, [&](gpu::Batch& batch) { - args->_batch = &batch; batch.enableStereo(false); batch.setViewportTransform(args->_viewport); @@ -96,7 +98,6 @@ void PrepareStencil::run(const RenderContextPointer& renderContext, const gpu::F batch.draw(gpu::TRIANGLE_STRIP, 4); } }); - args->_batch = nullptr; } void PrepareStencil::drawMask(gpu::State& state) { @@ -104,11 +105,11 @@ void PrepareStencil::drawMask(gpu::State& state) { } void PrepareStencil::testMask(gpu::State& state) { - state.setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_MASK, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + state.setStencilTest(true, 0x00, gpu::State::StencilTest(PrepareStencil::STENCIL_MASK, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); } void PrepareStencil::testBackground(gpu::State& state) { - state.setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_BACKGROUND, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + state.setStencilTest(true, 0x00, gpu::State::StencilTest(PrepareStencil::STENCIL_BACKGROUND, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); } void PrepareStencil::testMaskDrawShape(gpu::State& state) { @@ -116,5 +117,5 @@ void PrepareStencil::testMaskDrawShape(gpu::State& state) { } void PrepareStencil::testShape(gpu::State& state) { - state.setStencilTest(true, 0xFF, gpu::State::StencilTest(PrepareStencil::STENCIL_SHAPE, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + state.setStencilTest(true, 0x00, gpu::State::StencilTest(PrepareStencil::STENCIL_SHAPE, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); } \ No newline at end of file diff --git a/libraries/render-utils/src/SurfaceGeometryPass.cpp b/libraries/render-utils/src/SurfaceGeometryPass.cpp index b0c0aa6358..1941766353 100644 --- a/libraries/render-utils/src/SurfaceGeometryPass.cpp +++ b/libraries/render-utils/src/SurfaceGeometryPass.cpp @@ -555,7 +555,7 @@ const gpu::PipelinePointer& SurfaceGeometryPass::getCurvaturePipeline() { #ifdef USE_STENCIL_TEST // Stencil test the curvature pass for objects pixels only, not the background - PrepareStencil::testMask(*state); + PrepareStencil::testShape(*state); #endif // Good to go add the brand new pipeline _curvaturePipeline = gpu::Pipeline::create(program, state); diff --git a/libraries/render-utils/src/ToneMappingEffect.cpp b/libraries/render-utils/src/ToneMappingEffect.cpp index 62ae9147f3..7a3d868236 100644 --- a/libraries/render-utils/src/ToneMappingEffect.cpp +++ b/libraries/render-utils/src/ToneMappingEffect.cpp @@ -39,7 +39,7 @@ void ToneMappingEffect::init() { slotBindings.insert(gpu::Shader::Binding(std::string("colorMap"), ToneMappingEffect_LightingMapSlot)); gpu::Shader::makeProgram(*blitProgram, slotBindings); auto blitState = std::make_shared(); - PrepareStencil::testShape(*blitState); + PrepareStencil::testMask(*blitState); blitState->setColorWriteMask(true, true, true, true); _blitLightBuffer = gpu::PipelinePointer(gpu::Pipeline::create(blitProgram, blitState)); } diff --git a/libraries/render-utils/src/stencil_drawMask.slf b/libraries/render-utils/src/stencil_drawMask.slf index cc81fca677..3eedeecb82 100644 --- a/libraries/render-utils/src/stencil_drawMask.slf +++ b/libraries/render-utils/src/stencil_drawMask.slf @@ -14,8 +14,10 @@ in vec2 varTexCoord0; +float aspectRatio = 0.95; + void main(void) { vec2 pos = varTexCoord0 * 2.0 - vec2(1.0); - pos.x = pos.x * (pos.x > 0.0 ? 2.0 : -2.0) - 1.0; + pos.x = aspectRatio * (pos.x * (pos.x > 0.0 ? 2.0 : -2.0) - 1.0); if (1.0 - dot(pos.xy, pos.xy) > 0.0 ) discard; } diff --git a/libraries/shared/src/RenderArgs.h b/libraries/shared/src/RenderArgs.h index f44d736e1a..d4d88c26a8 100644 --- a/libraries/shared/src/RenderArgs.h +++ b/libraries/shared/src/RenderArgs.h @@ -76,7 +76,7 @@ public: class RenderArgs { public: enum RenderMode { DEFAULT_RENDER_MODE, SHADOW_RENDER_MODE, DIFFUSE_RENDER_MODE, NORMAL_RENDER_MODE, MIRROR_RENDER_MODE }; - enum RenderSide { MONO, STEREO_LEFT, STEREO_RIGHT }; + enum DisplayMode { MONO, STEREO_MONITOR, STEREO_HMD }; enum DebugFlags { RENDER_DEBUG_NONE = 0, RENDER_DEBUG_HULLS = 1 @@ -87,7 +87,7 @@ public: float sizeScale = 1.0f, int boundaryLevelAdjust = 0, RenderMode renderMode = DEFAULT_RENDER_MODE, - RenderSide renderSide = MONO, + DisplayMode displayMode = MONO, DebugFlags debugFlags = RENDER_DEBUG_NONE, gpu::Batch* batch = nullptr) : _context(context), @@ -95,7 +95,7 @@ public: _sizeScale(sizeScale), _boundaryLevelAdjust(boundaryLevelAdjust), _renderMode(renderMode), - _renderSide(renderSide), + _displayMode(displayMode), _debugFlags(debugFlags), _batch(batch) { } @@ -121,7 +121,7 @@ public: float _sizeScale = 1.0f; int _boundaryLevelAdjust = 0; RenderMode _renderMode = DEFAULT_RENDER_MODE; - RenderSide _renderSide = MONO; + DisplayMode _displayMode = MONO; DebugFlags _debugFlags = RENDER_DEBUG_NONE; gpu::Batch* _batch = nullptr; diff --git a/tests/shaders/src/main.cpp b/tests/shaders/src/main.cpp index 8a239f0728..d10ab1ddbe 100644 --- a/tests/shaders/src/main.cpp +++ b/tests/shaders/src/main.cpp @@ -31,13 +31,9 @@ #include #include -#include #include #include -#include -#include - #include #include @@ -66,9 +62,6 @@ #include #include -#include -#include - #include #include @@ -155,11 +148,8 @@ void QTestWindow::draw() { testShaderBuild(simple_vert, simple_frag); testShaderBuild(simple_vert, simple_textured_frag); testShaderBuild(simple_vert, simple_textured_unlit_frag); - testShaderBuild(deferred_light_vert, directional_light_frag); testShaderBuild(deferred_light_vert, directional_ambient_light_frag); testShaderBuild(deferred_light_vert, directional_skybox_light_frag); - testShaderBuild(deferred_light_point_vert, point_light_frag); - testShaderBuild(deferred_light_spot_vert, spot_light_frag); testShaderBuild(standardTransformPNTC_vert, standardDrawTexture_frag); testShaderBuild(standardTransformPNTC_vert, DrawTextureOpaque_frag); @@ -190,7 +180,6 @@ void QTestWindow::draw() { testShaderBuild(ambient_occlusion_vert, ambient_occlusion_frag); testShaderBuild(ambient_occlusion_vert, occlusion_blend_frag); */ - testShaderBuild(hit_effect_vert, hit_effect_frag); testShaderBuild(overlay3D_vert, overlay3D_frag); From f70702beb7a63618a515a33a825db2bcec32f5e0 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 2 Jun 2017 17:54:41 -0700 Subject: [PATCH 11/12] Introducing debug flags --- .../render-utils/src/StencilMaskPass.cpp | 11 ++++++--- libraries/render-utils/src/StencilMaskPass.h | 24 +++++++++++++++---- .../render-utils/src/ToneMappingEffect.cpp | 1 - 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/libraries/render-utils/src/StencilMaskPass.cpp b/libraries/render-utils/src/StencilMaskPass.cpp index dcd994763f..2374f24211 100644 --- a/libraries/render-utils/src/StencilMaskPass.cpp +++ b/libraries/render-utils/src/StencilMaskPass.cpp @@ -22,6 +22,11 @@ using namespace render; +void PrepareStencil::configure(const Config& config) { + _maskMode = config.maskMode; + _forceDraw = config.forceDraw; +} + model::MeshPointer PrepareStencil::getMesh() { if (!_mesh) { @@ -72,8 +77,8 @@ gpu::PipelinePointer PrepareStencil::getPaintStencilPipeline() { void PrepareStencil::run(const RenderContextPointer& renderContext, const gpu::FramebufferPointer& srcFramebuffer) { RenderArgs* args = renderContext->args; - // Only draw the stencil mask if in HMD mode. - if (args->_displayMode != RenderArgs::STEREO_HMD) { + // Only draw the stencil mask if in HMD mode or not forced. + if (!_forceDraw && (args->_displayMode != RenderArgs::STEREO_HMD)) { return; } @@ -82,7 +87,7 @@ void PrepareStencil::run(const RenderContextPointer& renderContext, const gpu::F batch.setViewportTransform(args->_viewport); - if (false) { + if (_maskMode < 0) { batch.setPipeline(getMeshStencilPipeline()); auto mesh = getMesh(); diff --git a/libraries/render-utils/src/StencilMaskPass.h b/libraries/render-utils/src/StencilMaskPass.h index d7d6ee448b..01601d1ae6 100644 --- a/libraries/render-utils/src/StencilMaskPass.h +++ b/libraries/render-utils/src/StencilMaskPass.h @@ -16,16 +16,28 @@ #include #include +class PrepareStencilConfig : public render::Job::Config { + Q_OBJECT + Q_PROPERTY(int maskMode MEMBER maskMode NOTIFY dirty) + Q_PROPERTY(bool forceDraw MEMBER forceDraw NOTIFY dirty) + +public: + PrepareStencilConfig(bool enabled = true) : JobConfig(enabled) {} + + int maskMode { 0 }; + bool forceDraw { false }; + +signals: + void dirty(); +}; + class PrepareStencil { public: - class Config : public render::JobConfig { - public: - Config(bool enabled = true) : JobConfig(enabled) {} - }; + using Config = PrepareStencilConfig; using JobModel = render::Job::ModelI; - void configure(const Config& config) {} + void configure(const Config& config); void run(const render::RenderContextPointer& renderContext, const gpu::FramebufferPointer& dstFramebuffer); @@ -51,6 +63,8 @@ private: model::MeshPointer _mesh; model::MeshPointer getMesh(); + int _maskMode { 0 }; + bool _forceDraw { false }; }; diff --git a/libraries/render-utils/src/ToneMappingEffect.cpp b/libraries/render-utils/src/ToneMappingEffect.cpp index 7a3d868236..ce41cf16fa 100644 --- a/libraries/render-utils/src/ToneMappingEffect.cpp +++ b/libraries/render-utils/src/ToneMappingEffect.cpp @@ -39,7 +39,6 @@ void ToneMappingEffect::init() { slotBindings.insert(gpu::Shader::Binding(std::string("colorMap"), ToneMappingEffect_LightingMapSlot)); gpu::Shader::makeProgram(*blitProgram, slotBindings); auto blitState = std::make_shared(); - PrepareStencil::testMask(*blitState); blitState->setColorWriteMask(true, true, true, true); _blitLightBuffer = gpu::PipelinePointer(gpu::Pipeline::create(blitProgram, blitState)); } From d38a396e9d8b67e976646595e20dd856e4460893 Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Sat, 3 Jun 2017 08:59:47 -0700 Subject: [PATCH 12/12] Fixing warning --- libraries/model/src/model/Geometry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/model/src/model/Geometry.cpp b/libraries/model/src/model/Geometry.cpp index 2525491460..f88c8233ea 100755 --- a/libraries/model/src/model/Geometry.cpp +++ b/libraries/model/src/model/Geometry.cpp @@ -257,7 +257,7 @@ MeshPointer Mesh::createIndexedTriangles_P3F(uint32_t numVertices, uint32_t numI int16_t* shortIndices = nullptr; if (indices) { shortIndicesVector.resize(numIndices); - for (int i = 0; i < numIndices; i++) { + for (uint32_t i = 0; i < numIndices; i++) { shortIndicesVector[i] = indices[i]; } shortIndices = shortIndicesVector.data();