From 51594fefa23a764b0adbc7a54abb50d2301cb248 Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 12 Jul 2016 18:21:31 -0700 Subject: [PATCH] more clean up --- .../render-utils/src/DeferredBufferWrite.slh | 12 +++- .../render-utils/src/DeferredGlobalLight.slh | 1 - .../src/DeferredLightingEffect.cpp | 25 ++++---- .../render-utils/src/DeferredLightingEffect.h | 6 +- libraries/render-utils/src/LightPoint.slh | 2 +- libraries/render-utils/src/LightSpot.slh | 2 +- libraries/render-utils/src/LightingModel.cpp | 2 +- libraries/render-utils/src/LightingModel.h | 4 +- libraries/render-utils/src/LightingModel.slh | 7 +-- .../render-utils/src/RenderDeferredTask.cpp | 63 ++++++++++++------- .../render-utils/src/RenderDeferredTask.h | 25 +++++--- .../render-utils/src/ToneMappingEffect.cpp | 5 +- libraries/render-utils/src/overlay3D.slf | 1 - .../src/overlay3D_translucent.slf | 5 +- libraries/render-utils/src/point_light.slf | 1 - libraries/render-utils/src/spot_light.slf | 1 - libraries/render/src/render/ShapePipeline.cpp | 2 + libraries/render/src/render/ShapePipeline.h | 6 +- libraries/render/src/render/Task.h | 9 ++- .../utilities/render/deferredLighting.qml | 14 ++++- 20 files changed, 119 insertions(+), 74 deletions(-) diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index cd62a30611..dece8e9ce3 100755 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -12,6 +12,8 @@ <@def DEFERRED_BUFFER_WRITE_SLH@> <@include DeferredBuffer.slh@> +<@include LightingModel.slh@> + layout(location = 0) out vec4 _fragColor0; layout(location = 1) out vec4 _fragColor1; @@ -38,6 +40,7 @@ void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness if (alpha != 1.0) { discard; } + emissive *= isEmissiveEnabled(); _fragColor0 = vec4(albedo, ((scattering > 0.0) ? packScatteringMetallic(metallic) : packShadedMetallic(metallic))); _fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0)); _fragColor2 = vec4(((scattering > 0.0) ? vec3(scattering) : emissive), occlusion); @@ -50,10 +53,15 @@ void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float r if (alpha != 1.0) { discard; } + _fragColor0 = vec4(albedo, packLightmappedMetallic(metallic)); _fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0)); _fragColor2 = vec4(lightmap, 1.0); - _fragColor3 = vec4(albedo * lightmap, 1.0); + + _fragColor3 = vec4(lightmap * isLightmapEnabled(), 1.0); + if (isAlbedoEnabled() > 0.0) { + _fragColor3.rgb *= albedo; + } } void packDeferredFragmentUnlit(vec3 normal, float alpha, vec3 color) { @@ -63,7 +71,7 @@ void packDeferredFragmentUnlit(vec3 normal, float alpha, vec3 color) { _fragColor0 = vec4(color, packUnlit()); _fragColor1 = vec4(packNormal(normal), 1.0); _fragColor2 = vec4(vec3(0.0), 1.0); - _fragColor3 = vec4(color, 1.0); + _fragColor3 = vec4(color * isUnlitEnabled(), 1.0); } void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 albedo, vec3 fresnel, float roughness) { diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index 95cfc1d151..16cdab535c 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -14,7 +14,6 @@ <@include model/Light.slh@> <@include LightingModel.slh@> -<$declareLightingModel()$> <@include LightAmbient.slh@> <@include LightDirectional.slh@> diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index b15b980e51..57b079dab0 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -66,9 +66,9 @@ enum DeferredShader_MapSlot { }; enum DeferredShader_BufferSlot { DEFERRED_FRAME_TRANSFORM_BUFFER_SLOT = 0, - LIGHTING_MODEL_BUFFER_SLOT, SCATTERING_PARAMETERS_BUFFER_SLOT, - LIGHT_GPU_SLOT, + LIGHTING_MODEL_BUFFER_SLOT = render::ShapePipeline::Slot::LIGHTING_MODEL, + LIGHT_GPU_SLOT = render::ShapePipeline::Slot::LIGHT, }; static void loadLightProgram(const char* vertSource, const char* fragSource, bool lightVolume, gpu::PipelinePointer& program, LightLocationsPtr& locations); @@ -355,16 +355,19 @@ void PreparePrimaryFramebuffer::run(const SceneContextPointer& sceneContext, con primaryFramebuffer = _primaryFramebuffer; } -void PrepareDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const gpu::FramebufferPointer& primaryFramebuffer, Outputs& output) { +void PrepareDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs) { auto args = renderContext->args; + auto primaryFramebuffer = inputs.get0(); + auto lightingModel = inputs.get1(); + if (!_deferredFramebuffer) { _deferredFramebuffer = std::make_shared(); } _deferredFramebuffer->updatePrimaryDepth(primaryFramebuffer->getDepthStencilBuffer()); - output.edit0() = _deferredFramebuffer; - output.edit1() = _deferredFramebuffer->getLightingFramebuffer(); + outputs.edit0() = _deferredFramebuffer; + outputs.edit1() = _deferredFramebuffer->getLightingFramebuffer(); gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { @@ -372,14 +375,7 @@ void PrepareDeferred::run(const SceneContextPointer& sceneContext, const RenderC batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); - // Clear Lighting buffer - /* auto lightingFbo = DependencyManager::get()->getLightingFramebuffer(); - - batch.setFramebuffer(lightingFbo); - batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, vec4(vec3(0), 0), true); -*/ // Clear deferred - // auto deferredFbo = DependencyManager::get()->getDeferredFramebuffer(); auto deferredFbo = _deferredFramebuffer->getDeferredFramebuffer(); batch.setFramebuffer(deferredFbo); @@ -389,6 +385,9 @@ void PrepareDeferred::run(const SceneContextPointer& sceneContext, const RenderC gpu::Framebuffer::BUFFER_DEPTH | gpu::Framebuffer::BUFFER_STENCIL, vec4(vec3(0), 0), 1.0, 0.0, true); + + // For the rest of the rendering, bind the lighting model + batch.setUniformBuffer(LIGHTING_MODEL_BUFFER_SLOT, lightingModel->getParametersBuffer()); }); } @@ -646,7 +645,7 @@ void RenderDeferredCleanup::run(const render::SceneContextPointer& sceneContext, batch.setResourceTexture(SCATTERING_SPECULAR_UNIT, nullptr); batch.setUniformBuffer(SCATTERING_PARAMETERS_BUFFER_SLOT, nullptr); - batch.setUniformBuffer(LIGHTING_MODEL_BUFFER_SLOT, nullptr); + // batch.setUniformBuffer(LIGHTING_MODEL_BUFFER_SLOT, nullptr); batch.setUniformBuffer(DEFERRED_FRAME_TRANSFORM_BUFFER_SLOT, nullptr); }); diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index d520ddc098..af884c0102 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -117,12 +117,14 @@ public: class PrepareDeferred { public: + // Inputs: primaryFramebuffer and lightingModel + using Inputs = render::VaryingSet2 ; // Output: DeferredFramebuffer, LightingFramebuffer using Outputs = render::VaryingSet2; - using JobModel = render::Job::ModelIO; + using JobModel = render::Job::ModelIO; - void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const gpu::FramebufferPointer& primaryFramebuffer, Outputs& output); + void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs); DeferredFramebufferPointer _deferredFramebuffer; }; diff --git a/libraries/render-utils/src/LightPoint.slh b/libraries/render-utils/src/LightPoint.slh index d13d52d360..5c9e66dd24 100644 --- a/libraries/render-utils/src/LightPoint.slh +++ b/libraries/render-utils/src/LightPoint.slh @@ -37,7 +37,7 @@ void evalLightingPoint(out vec3 diffuse, out vec3 specular, Light light, diffuse *= lightEnergy * isDiffuseEnabled() * isPointEnabled(); specular *= lightEnergy * isSpecularEnabled() * isPointEnabled(); - if (getLightShowContour(light) > 0.0) { + if (isShowLightContour() > 0.0) { // Show edge float edge = abs(2.0 * ((getLightRadius(light) - fragLightDistance) / (0.1)) - 1.0); if (edge < 1) { diff --git a/libraries/render-utils/src/LightSpot.slh b/libraries/render-utils/src/LightSpot.slh index 0b66a3e4c1..8a17a5ef4d 100644 --- a/libraries/render-utils/src/LightSpot.slh +++ b/libraries/render-utils/src/LightSpot.slh @@ -38,7 +38,7 @@ void evalLightingSpot(out vec3 diffuse, out vec3 specular, Light light, diffuse *= lightEnergy * isDiffuseEnabled() * isSpotEnabled(); specular *= lightEnergy * isSpecularEnabled() * isSpotEnabled(); - if (getLightShowContour(light) > 0.0) { + if (isShowLightContour() > 0.0) { // Show edges float edgeDistR = (getLightRadius(light) - fragLightDistance); float edgeDistS = dot(fragLightDistance * vec2(cosSpotAngle, sqrt(1.0 - cosSpotAngle * cosSpotAngle)), -getLightSpotOutsideNormal2(light)); diff --git a/libraries/render-utils/src/LightingModel.cpp b/libraries/render-utils/src/LightingModel.cpp index 998659308d..14aea67662 100644 --- a/libraries/render-utils/src/LightingModel.cpp +++ b/libraries/render-utils/src/LightingModel.cpp @@ -122,7 +122,7 @@ void LightingModel::setShowLightContour(bool enable) { } } bool LightingModel::isShowLightContourEnabled() const { - return (bool)_parametersBuffer.get().showLightContour; + return (bool)(_parametersBuffer.get().showLightContour > 0.0); } MakeLightingModel::MakeLightingModel() { diff --git a/libraries/render-utils/src/LightingModel.h b/libraries/render-utils/src/LightingModel.h index 9bd982a080..d895be297c 100644 --- a/libraries/render-utils/src/LightingModel.h +++ b/libraries/render-utils/src/LightingModel.h @@ -81,7 +81,7 @@ protected: float enablePointLight{ 1.0f }; float enableSpotLight{ 1.0f }; - float showLightContour{ 1.0f }; + float showLightContour{ 0.0f }; // false by default glm::vec3 spares{ 0.0f }; Parameters() {} @@ -132,7 +132,7 @@ public: bool enablePointLight{ true }; bool enableSpotLight{ true }; - bool showLightContour{ true }; + bool showLightContour{ false }; // false by default signals: void dirty(); diff --git a/libraries/render-utils/src/LightingModel.slh b/libraries/render-utils/src/LightingModel.slh index b8c73f7dab..f34a770d72 100644 --- a/libraries/render-utils/src/LightingModel.slh +++ b/libraries/render-utils/src/LightingModel.slh @@ -12,9 +12,6 @@ <@def LIGHTING_MODEL_SLH@> <@func declareLightingModel()@> -<@endfunc@> - -<@func declareLightingModelMaster()@> struct LightingModel { vec4 _UnlitShadedEmissiveLightmap; @@ -66,12 +63,12 @@ float isSpotEnabled() { return lightingModel._AmbientDirectionalPointSpot.w; } -float isShowContour() { +float isShowLightContour() { return lightingModel._ShowContour.x; } <@endfunc@> -<$declareLightingModelMaster()$> +<$declareLightingModel()$> <@func declareBeckmannSpecular()@> diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 3fee16f2c3..2a0864c22b 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -97,28 +97,29 @@ RenderDeferredTask::RenderDeferredTask(CullFunctor cullFunctor) { // GPU jobs: Start preparing the primary, deferred and lighting buffer const auto primaryFramebuffer = addJob("PreparePrimaryBuffer"); - const auto deferredAndLightingFramebuffer = addJob("PrepareDeferred", primaryFramebuffer); - const auto deferredFramebuffer = deferredAndLightingFramebuffer.getN(0); - const auto lightingFramebuffer = deferredAndLightingFramebuffer.getN(1); + const auto prepareDeferredInputs = SurfaceGeometryPass::Inputs(primaryFramebuffer, lightingModel).hasVarying(); + const auto prepareDeferredOutputs = addJob("PrepareDeferred", prepareDeferredInputs); + const auto deferredFramebuffer = prepareDeferredOutputs.getN(0); + const auto lightingFramebuffer = prepareDeferredOutputs.getN(1); // Render opaque objects in DeferredBuffer - addJob("DrawOpaqueDeferred", opaques, shapePlumber); + const auto opaqueInputs = DrawStateSortDeferred::Inputs(opaques, lightingModel).hasVarying(); + addJob("DrawOpaqueDeferred", opaqueInputs, shapePlumber); // Once opaque is all rendered create stencil background addJob("DrawOpaqueStencil", deferredFramebuffer); // Opaque all rendered, generate surface geometry buffers - const auto surfaceGeometryPassInputs = render::Varying(SurfaceGeometryPass::Inputs(deferredFrameTransform, deferredFramebuffer)); - const auto geometryFramebufferAndCurvatureFramebufferAndDepth = addJob("SurfaceGeometry", surfaceGeometryPassInputs); - const auto surfaceGeometryFramebuffer = geometryFramebufferAndCurvatureFramebufferAndDepth.getN(0); - const auto curvatureFramebuffer = geometryFramebufferAndCurvatureFramebufferAndDepth.getN(1); - const auto linearDepthTexture = geometryFramebufferAndCurvatureFramebufferAndDepth.getN(2); + const auto surfaceGeometryPassInputs = SurfaceGeometryPass::Inputs(deferredFrameTransform, deferredFramebuffer).hasVarying(); + const auto surfaceGeometryPassOutputs = addJob("SurfaceGeometry", surfaceGeometryPassInputs); + const auto surfaceGeometryFramebuffer = surfaceGeometryPassOutputs.getN(0); + const auto curvatureFramebuffer = surfaceGeometryPassOutputs.getN(1); + const auto linearDepthTexture = surfaceGeometryPassOutputs.getN(2); - const auto curvatureFramebufferAndDepth = render::Varying(BlurGaussianDepthAware::Inputs(curvatureFramebuffer, linearDepthTexture)); - - const auto midCurvatureNormalFramebuffer = addJob("DiffuseCurvatureMid", curvatureFramebufferAndDepth); - const auto lowCurvatureNormalFramebuffer = addJob("DiffuseCurvatureLow", curvatureFramebufferAndDepth, true); + const auto diffuseCurvaturePassInputs = BlurGaussianDepthAware::Inputs(curvatureFramebuffer, linearDepthTexture).hasVarying(); + const auto midCurvatureNormalFramebuffer = addJob("DiffuseCurvatureMid", diffuseCurvaturePassInputs); + const auto lowCurvatureNormalFramebuffer = addJob("DiffuseCurvatureLow", diffuseCurvaturePassInputs, true); // THis blur pass generates it s render resource const auto scatteringResource = addJob("Scattering"); @@ -128,25 +129,29 @@ RenderDeferredTask::RenderDeferredTask(CullFunctor cullFunctor) { // Draw Lights just add the lights to the current list of lights to deal with. NOt really gpu job for now. addJob("DrawLight", lights); - const auto deferredLightingInputs = render::Varying(RenderDeferred::Inputs(deferredFrameTransform, deferredFramebuffer, lightingModel, - surfaceGeometryFramebuffer, lowCurvatureNormalFramebuffer, scatteringResource)); + const auto deferredLightingInputs = RenderDeferred::Inputs(deferredFrameTransform, deferredFramebuffer, lightingModel, + surfaceGeometryFramebuffer, lowCurvatureNormalFramebuffer, scatteringResource).hasVarying(); // DeferredBuffer is complete, now let's shade it into the LightingBuffer addJob("RenderDeferred", deferredLightingInputs); // Use Stencil and draw background in Lighting buffer to complete filling in the opaque - addJob("DrawBackgroundDeferred", background); + const auto backgroundInputs = DrawBackgroundDeferred::Inputs(background, lightingModel).hasVarying(); + addJob("DrawBackgroundDeferred", backgroundInputs); // Render transparent objects forward in LightingBuffer - addJob("DrawTransparentDeferred", transparents, shapePlumber); + const auto transparentsInputs = DrawDeferred::Inputs(transparents, lightingModel).hasVarying(); + addJob("DrawTransparentDeferred", transparentsInputs, shapePlumber); // Lighting Buffer ready for tone mapping const auto toneMappingInputs = render::Varying(ToneMappingDeferred::Inputs(lightingFramebuffer, primaryFramebuffer)); addJob("ToneMapping", toneMappingInputs); // Overlays - addJob("DrawOverlay3DOpaque", overlayOpaques, true); - addJob("DrawOverlay3DTransparent", overlayTransparents, false); + const auto overlayOpaquesInputs = DrawOverlay3D::Inputs(overlayOpaques, lightingModel).hasVarying(); + const auto overlayTransparentsInputs = DrawOverlay3D::Inputs(overlayTransparents, lightingModel).hasVarying(); + addJob("DrawOverlay3DOpaque", overlayOpaquesInputs, true); + addJob("DrawOverlay3DTransparent", overlayTransparentsInputs, false); // Debugging stages @@ -198,12 +203,15 @@ void RenderDeferredTask::run(const SceneContextPointer& sceneContext, const Rend } } -void DrawDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemBounds& inItems) { +void DrawDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Inputs& inputs) { assert(renderContext->args); assert(renderContext->args->hasViewFrustum()); auto config = std::static_pointer_cast(renderContext->jobConfig); + const auto& inItems = inputs.get0(); + const auto& lightingModel = inputs.get1(); + RenderArgs* args = renderContext->args; gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { @@ -226,12 +234,15 @@ void DrawDeferred::run(const SceneContextPointer& sceneContext, const RenderCont config->setNumDrawn((int)inItems.size()); } -void DrawStateSortDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemBounds& inItems) { +void DrawStateSortDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Inputs& inputs) { assert(renderContext->args); assert(renderContext->args->hasViewFrustum()); auto config = std::static_pointer_cast(renderContext->jobConfig); + const auto& inItems = inputs.get0(); + const auto& lightingModel = inputs.get1(); + RenderArgs* args = renderContext->args; gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { @@ -264,12 +275,15 @@ DrawOverlay3D::DrawOverlay3D(bool opaque) : initOverlay3DPipelines(*_shapePlumber); } -void DrawOverlay3D::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const render::ItemBounds& inItems) { +void DrawOverlay3D::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Inputs& inputs) { assert(renderContext->args); assert(renderContext->args->hasViewFrustum()); auto config = std::static_pointer_cast(renderContext->jobConfig); + const auto& inItems = inputs.get0(); + const auto& lightingModel = inputs.get1(); + config->setNumDrawn((int)inItems.size()); emit config->numDrawnChanged(); @@ -341,10 +355,13 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren args->_batch = nullptr; } -void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemBounds& inItems) { +void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Inputs& inputs) { assert(renderContext->args); assert(renderContext->args->hasViewFrustum()); + const auto& inItems = inputs.get0(); + const auto& lightingModel = inputs.get1(); + RenderArgs* args = renderContext->args; doInBatch(args->_context, [&](gpu::Batch& batch) { args->_batch = &batch; diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index 612d1c5ea4..b6ad83985e 100755 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -14,6 +14,8 @@ #include #include +#include "LightingModel.h" + class DrawConfig : public render::Job::Config { Q_OBJECT @@ -37,13 +39,14 @@ protected: class DrawDeferred { public: + using Inputs = render::VaryingSet2 ; using Config = DrawConfig; - using JobModel = render::Job::ModelI; + using JobModel = render::Job::ModelI; DrawDeferred(render::ShapePlumberPointer shapePlumber) : _shapePlumber{ shapePlumber } {} void configure(const Config& config) { _maxDrawn = config.maxDrawn; } - void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const render::ItemBounds& inItems); + void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const Inputs& inputs); protected: render::ShapePlumberPointer _shapePlumber; @@ -73,13 +76,15 @@ protected: class DrawStateSortDeferred { public: + using Inputs = render::VaryingSet2 ; + using Config = DrawStateSortConfig; - using JobModel = render::Job::ModelI; + using JobModel = render::Job::ModelI; DrawStateSortDeferred(render::ShapePlumberPointer shapePlumber) : _shapePlumber{ shapePlumber } {} void configure(const Config& config) { _maxDrawn = config.maxDrawn; _stateSort = config.stateSort; } - void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const render::ItemBounds& inItems); + void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const Inputs& inputs); protected: render::ShapePlumberPointer _shapePlumber; @@ -112,11 +117,13 @@ protected: class DrawBackgroundDeferred { public: + using Inputs = render::VaryingSet2 ; + using Config = DrawBackgroundDeferredConfig; - using JobModel = render::Job::ModelI; + using JobModel = render::Job::ModelI; void configure(const Config& config) {} - void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const render::ItemBounds& inItems); + void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const Inputs& inputs); protected: gpu::RangeTimer _gpuTimer; @@ -142,13 +149,15 @@ protected: class DrawOverlay3D { public: + using Inputs = render::VaryingSet2 ; + using Config = DrawOverlay3DConfig; - using JobModel = render::Job::ModelI; + using JobModel = render::Job::ModelI; DrawOverlay3D(bool opaque); void configure(const Config& config) { _maxDrawn = config.maxDrawn; } - void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const render::ItemBounds& inItems); + void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const Inputs& inputs); protected: render::ShapePlumberPointer _shapePlumber; diff --git a/libraries/render-utils/src/ToneMappingEffect.cpp b/libraries/render-utils/src/ToneMappingEffect.cpp index 1cd0e42ad1..e844ee6eda 100644 --- a/libraries/render-utils/src/ToneMappingEffect.cpp +++ b/libraries/render-utils/src/ToneMappingEffect.cpp @@ -156,10 +156,7 @@ void ToneMappingDeferred::configure(const Config& config) { } void ToneMappingDeferred::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const Inputs& inputs) { - /* auto framebufferCache = DependencyManager::get(); - auto lightingBuffer = framebufferCache->getLightingTexture(); - auto destFbo = framebufferCache->getPrimaryFramebuffer(); - */ + auto lightingBuffer = inputs.get0()->getRenderBuffer(0); auto destFbo = inputs.get1(); _toneMappingEffect.render(renderContext->args, lightingBuffer, destFbo); diff --git a/libraries/render-utils/src/overlay3D.slf b/libraries/render-utils/src/overlay3D.slf index 6ff882188c..b29b9baf64 100644 --- a/libraries/render-utils/src/overlay3D.slf +++ b/libraries/render-utils/src/overlay3D.slf @@ -15,7 +15,6 @@ <@include model/Light.slh@> <@include LightingModel.slh@> -<$declareLightingModel()$> <@include LightDirectional.slh@> <$declareLightingDirectional()$> diff --git a/libraries/render-utils/src/overlay3D_translucent.slf b/libraries/render-utils/src/overlay3D_translucent.slf index d3ddc04543..ce5bbf3589 100644 --- a/libraries/render-utils/src/overlay3D_translucent.slf +++ b/libraries/render-utils/src/overlay3D_translucent.slf @@ -15,7 +15,6 @@ <@include model/Light.slh@> <@include LightingModel.slh@> -<$declareLightingModel()$> <@include LightDirectional.slh@> <$declareLightingDirectional()$> @@ -40,8 +39,8 @@ vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 a vec3 directionalDiffuse; vec3 directionalSpecular; evalLightingDirectional(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation); - color += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled(); - color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled(); + color += directionalDiffuse; + color += directionalSpecular / opacity; return vec4(color, opacity); } diff --git a/libraries/render-utils/src/point_light.slf b/libraries/render-utils/src/point_light.slf index 02a5d0d36c..84475be64e 100644 --- a/libraries/render-utils/src/point_light.slf +++ b/libraries/render-utils/src/point_light.slf @@ -21,7 +21,6 @@ <@include model/Light.slh@> <@include LightingModel.slh@> -<$declareLightingModel()$> <@include LightPoint.slh@> <$declareLightingPoint(supportScattering)$> diff --git a/libraries/render-utils/src/spot_light.slf b/libraries/render-utils/src/spot_light.slf index 3b860e3fb3..cd379af51e 100644 --- a/libraries/render-utils/src/spot_light.slf +++ b/libraries/render-utils/src/spot_light.slf @@ -21,7 +21,6 @@ <@include model/Light.slh@> <@include LightingModel.slh@> -<$declareLightingModel()$> <@include LightSpot.slh@> <$declareLightingSpot(supportScattering)$> diff --git a/libraries/render/src/render/ShapePipeline.cpp b/libraries/render/src/render/ShapePipeline.cpp index 6c5128830e..3b613e0f96 100644 --- a/libraries/render/src/render/ShapePipeline.cpp +++ b/libraries/render/src/render/ShapePipeline.cpp @@ -51,6 +51,7 @@ void ShapePlumber::addPipeline(const Key& key, const gpu::ShaderPointer& program void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& program, const gpu::StatePointer& state, BatchSetter batchSetter) { gpu::Shader::BindingSet slotBindings; + slotBindings.insert(gpu::Shader::Binding(std::string("lightingModelBuffer"), Slot::BUFFER::LIGHTING_MODEL)); slotBindings.insert(gpu::Shader::Binding(std::string("skinClusterBuffer"), Slot::BUFFER::SKINNING)); slotBindings.insert(gpu::Shader::Binding(std::string("materialBuffer"), Slot::BUFFER::MATERIAL)); slotBindings.insert(gpu::Shader::Binding(std::string("texMapArrayBuffer"), Slot::BUFFER::TEXMAPARRAY)); @@ -79,6 +80,7 @@ void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& p locations->metallicTextureUnit = program->getTextures().findLocation("metallicMap"); locations->emissiveTextureUnit = program->getTextures().findLocation("emissiveMap"); locations->occlusionTextureUnit = program->getTextures().findLocation("occlusionMap"); + locations->lightingModelBufferUnit = program->getBuffers().findLocation("lightingModelBuffer"); locations->skinClusterBufferUnit = program->getBuffers().findLocation("skinClusterBuffer"); locations->materialBufferUnit = program->getBuffers().findLocation("materialBuffer"); locations->texMapArrayBufferUnit = program->getBuffers().findLocation("texMapArrayBuffer"); diff --git a/libraries/render/src/render/ShapePipeline.h b/libraries/render/src/render/ShapePipeline.h index e65281fd33..5b60521068 100644 --- a/libraries/render/src/render/ShapePipeline.h +++ b/libraries/render/src/render/ShapePipeline.h @@ -196,10 +196,11 @@ public: class Slot { public: enum BUFFER { - SKINNING = 2, + SKINNING = 0, MATERIAL, TEXMAPARRAY, - LIGHT + LIGHTING_MODEL, + LIGHT, }; enum MAP { @@ -225,6 +226,7 @@ public: int emissiveTextureUnit; int occlusionTextureUnit; int normalFittingMapUnit; + int lightingModelBufferUnit; int skinClusterBufferUnit; int materialBufferUnit; int texMapArrayBufferUnit; diff --git a/libraries/render/src/render/Task.h b/libraries/render/src/render/Task.h index 967c75fc88..a90c7ea40e 100644 --- a/libraries/render/src/render/Task.h +++ b/libraries/render/src/render/Task.h @@ -83,8 +83,6 @@ protected: }; using VaryingPairBase = std::pair; - - template < typename T0, typename T1 > class VaryingSet2 : public VaryingPairBase { public: @@ -110,6 +108,7 @@ public: } virtual uint8_t length() const { return 2; } + Varying hasVarying() const { return Varying((*this)); } }; @@ -142,6 +141,7 @@ public: } virtual uint8_t length() const { return 3; } + Varying hasVarying() const { return Varying((*this)); } }; template @@ -178,6 +178,7 @@ public: } virtual uint8_t length() const { return 4; } + Varying hasVarying() const { return Varying((*this)); } }; @@ -204,6 +205,8 @@ public: const T4& get4() const { return std::get<4>((*this)).template get(); } T4& edit4() { return std::get<4>((*this)).template edit(); } + + Varying hasVarying() const { return Varying((*this)); } }; template @@ -232,6 +235,8 @@ public: const T5& get5() const { return std::get<5>((*this)).template get(); } T5& edit5() { return std::get<5>((*this)).template edit(); } + + Varying hasVarying() const { return Varying((*this)); } }; template < class T, int NUM > diff --git a/scripts/developer/utilities/render/deferredLighting.qml b/scripts/developer/utilities/render/deferredLighting.qml index 372f97bf43..1425013640 100644 --- a/scripts/developer/utilities/render/deferredLighting.qml +++ b/scripts/developer/utilities/render/deferredLighting.qml @@ -22,7 +22,6 @@ Column { Repeater { model: [ "Unlit:LightingModel:enableUnlit", - "Shaded:LightingModel:enableShaded", "Emissive:LightingModel:enableEmissive", "Lightmap:LightingModel:enableLightmap", ] @@ -68,6 +67,19 @@ Column { } } } + Column { + spacing: 10 + Repeater { + model: [ + "Light Contour:LightingModel:showLightContour" + ] + CheckBox { + text: modelData.split(":")[0] + checked: Render.getConfig(modelData.split(":")[1]) + onCheckedChanged: { Render.getConfig(modelData.split(":")[1])[modelData.split(":")[2]] = checked } + } + } + } } Column { spacing: 10