diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 690a833c3b..27361d0bd0 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -5110,7 +5110,7 @@ namespace render { auto& batch = *args->_batch; DependencyManager::get()->bindSimpleProgram(batch); - renderWorldBox(batch); + renderWorldBox(args, batch); } } } diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 78a503bc71..7822b78244 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -34,7 +34,7 @@ using namespace std; -void renderWorldBox(gpu::Batch& batch) { +void renderWorldBox(RenderArgs* args, gpu::Batch& batch) { auto geometryCache = DependencyManager::get(); // Show center of world @@ -115,7 +115,7 @@ void renderWorldBox(gpu::Batch& batch) { geometryIds[17]); - geometryCache->renderWireCubeInstance(batch, GREY4); + geometryCache->renderWireCubeInstance(args, batch, GREY4); // Draw meter markers along the 3 axis to help with measuring things const float MARKER_DISTANCE = 1.0f; @@ -123,23 +123,23 @@ void renderWorldBox(gpu::Batch& batch) { transform = Transform().setScale(MARKER_RADIUS); batch.setModelTransform(transform); - geometryCache->renderSolidSphereInstance(batch, RED); + geometryCache->renderSolidSphereInstance(args, batch, RED); transform = Transform().setTranslation(glm::vec3(MARKER_DISTANCE, 0.0f, 0.0f)).setScale(MARKER_RADIUS); batch.setModelTransform(transform); - geometryCache->renderSolidSphereInstance(batch, RED); + geometryCache->renderSolidSphereInstance(args, batch, RED); transform = Transform().setTranslation(glm::vec3(0.0f, MARKER_DISTANCE, 0.0f)).setScale(MARKER_RADIUS); batch.setModelTransform(transform); - geometryCache->renderSolidSphereInstance(batch, GREEN); + geometryCache->renderSolidSphereInstance(args, batch, GREEN); transform = Transform().setTranslation(glm::vec3(0.0f, 0.0f, MARKER_DISTANCE)).setScale(MARKER_RADIUS); batch.setModelTransform(transform); - geometryCache->renderSolidSphereInstance(batch, BLUE); + geometryCache->renderSolidSphereInstance(args, batch, BLUE); transform = Transform().setTranslation(glm::vec3(MARKER_DISTANCE, 0.0f, MARKER_DISTANCE)).setScale(MARKER_RADIUS); batch.setModelTransform(transform); - geometryCache->renderSolidSphereInstance(batch, GREY); + geometryCache->renderSolidSphereInstance(args, batch, GREY); } // Do some basic timing tests and report the results diff --git a/interface/src/Util.h b/interface/src/Util.h index b1b4c78bcb..48acb53936 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -16,8 +16,9 @@ #include #include +#include -void renderWorldBox(gpu::Batch& batch); +void renderWorldBox(RenderArgs* args, gpu::Batch& batch); void runTimingTests(); void runUnitTests(); diff --git a/interface/src/ui/overlays/Cube3DOverlay.cpp b/interface/src/ui/overlays/Cube3DOverlay.cpp index 8af4c1d908..707aabc241 100644 --- a/interface/src/ui/overlays/Cube3DOverlay.cpp +++ b/interface/src/ui/overlays/Cube3DOverlay.cpp @@ -73,7 +73,7 @@ void Cube3DOverlay::render(RenderArgs* args) { if (_isSolid) { transform.setScale(dimensions); batch->setModelTransform(transform); - geometryCache->renderSolidCubeInstance(*batch, cubeColor, pipeline); + geometryCache->renderSolidCubeInstance(args, *batch, cubeColor, pipeline); } else { geometryCache->bindSimpleProgram(*batch, false, false, false, true, true); if (getIsDashedLine()) { @@ -109,7 +109,7 @@ void Cube3DOverlay::render(RenderArgs* args) { } else { transform.setScale(dimensions); batch->setModelTransform(transform); - geometryCache->renderWireCubeInstance(*batch, cubeColor, pipeline); + geometryCache->renderWireCubeInstance(args, *batch, cubeColor, pipeline); } } } diff --git a/interface/src/ui/overlays/Shape3DOverlay.cpp b/interface/src/ui/overlays/Shape3DOverlay.cpp index 2556bc84aa..72c57565d4 100644 --- a/interface/src/ui/overlays/Shape3DOverlay.cpp +++ b/interface/src/ui/overlays/Shape3DOverlay.cpp @@ -53,9 +53,9 @@ void Shape3DOverlay::render(RenderArgs* args) { transform.setScale(dimensions); batch->setModelTransform(transform); if (_isSolid) { - geometryCache->renderSolidShapeInstance(*batch, _shape, cubeColor, pipeline); + geometryCache->renderSolidShapeInstance(args, *batch, _shape, cubeColor, pipeline); } else { - geometryCache->renderWireShapeInstance(*batch, _shape, cubeColor, pipeline); + geometryCache->renderWireShapeInstance(args, *batch, _shape, cubeColor, pipeline); } } } diff --git a/interface/src/ui/overlays/Sphere3DOverlay.cpp b/interface/src/ui/overlays/Sphere3DOverlay.cpp index 07c2861f16..67e11cf1d8 100644 --- a/interface/src/ui/overlays/Sphere3DOverlay.cpp +++ b/interface/src/ui/overlays/Sphere3DOverlay.cpp @@ -50,9 +50,9 @@ void Sphere3DOverlay::render(RenderArgs* args) { } if (_isSolid) { - geometryCache->renderSolidSphereInstance(*batch, sphereColor, pipeline); + geometryCache->renderSolidSphereInstance(args, *batch, sphereColor, pipeline); } else { - geometryCache->renderWireSphereInstance(*batch, sphereColor, pipeline); + geometryCache->renderWireSphereInstance(args, *batch, sphereColor, pipeline); } } } diff --git a/interface/src/ui/overlays/Text3DOverlay.cpp b/interface/src/ui/overlays/Text3DOverlay.cpp index ebc28ca86a..ed29bc4e1b 100644 --- a/interface/src/ui/overlays/Text3DOverlay.cpp +++ b/interface/src/ui/overlays/Text3DOverlay.cpp @@ -138,7 +138,7 @@ void Text3DOverlay::render(RenderArgs* args) { _textRenderer->draw(batch, 0, 0, getText(), textColor, glm::vec2(-1.0f), getDrawInFront()); // so before we continue, we must reset the pipeline batch.setPipeline(args->_pipeline->pipeline); - args->_pipeline->prepare(batch); + args->_pipeline->prepare(batch, args); } const render::ShapeKey Text3DOverlay::getShapeKey() { diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index a0a348388e..6cdffff844 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -609,7 +609,7 @@ void Avatar::render(RenderArgs* renderArgs) { if (showCollisionShapes && shouldRenderHead(renderArgs) && _skeletonModel->isRenderable()) { PROFILE_RANGE_BATCH(batch, __FUNCTION__":skeletonBoundingCollisionShapes"); const float BOUNDING_SHAPE_ALPHA = 0.7f; - _skeletonModel->renderBoundingCollisionShapes(*renderArgs->_batch, getUniformScale(), BOUNDING_SHAPE_ALPHA); + _skeletonModel->renderBoundingCollisionShapes(renderArgs, *renderArgs->_batch, getUniformScale(), BOUNDING_SHAPE_ALPHA); } if (showReceiveStats || showNamesAboveHeads) { diff --git a/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.cpp b/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.cpp index 2a2817e68b..9651951b46 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.cpp @@ -322,20 +322,20 @@ void SkeletonModel::computeBoundingShape() { _boundingCapsuleLocalOffset = invScale * offset; } -void SkeletonModel::renderBoundingCollisionShapes(gpu::Batch& batch, float scale, float alpha) { +void SkeletonModel::renderBoundingCollisionShapes(RenderArgs* args, gpu::Batch& batch, float scale, float alpha) { auto geometryCache = DependencyManager::get(); // draw a blue sphere at the capsule top point glm::vec3 topPoint = _translation + getRotation() * (scale * (_boundingCapsuleLocalOffset + (0.5f * _boundingCapsuleHeight) * Vectors::UNIT_Y)); batch.setModelTransform(Transform().setTranslation(topPoint).postScale(scale * _boundingCapsuleRadius)); - geometryCache->renderSolidSphereInstance(batch, glm::vec4(0.6f, 0.6f, 0.8f, alpha)); + geometryCache->renderSolidSphereInstance(args, batch, glm::vec4(0.6f, 0.6f, 0.8f, alpha)); // draw a yellow sphere at the capsule bottom point glm::vec3 bottomPoint = topPoint - glm::vec3(0.0f, scale * _boundingCapsuleHeight, 0.0f); glm::vec3 axis = topPoint - bottomPoint; batch.setModelTransform(Transform().setTranslation(bottomPoint).postScale(scale * _boundingCapsuleRadius)); - geometryCache->renderSolidSphereInstance(batch, glm::vec4(0.8f, 0.8f, 0.6f, alpha)); + geometryCache->renderSolidSphereInstance(args, batch, glm::vec4(0.8f, 0.8f, 0.6f, alpha)); // draw a green cylinder between the two points glm::vec3 origin(0.0f); diff --git a/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.h b/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.h index db87a37477..e48884c581 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.h +++ b/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.h @@ -96,7 +96,7 @@ public: /// \return whether or not the head was found. glm::vec3 getDefaultEyeModelPosition() const; - void renderBoundingCollisionShapes(gpu::Batch& batch, float scale, float alpha); + void renderBoundingCollisionShapes(RenderArgs* args, gpu::Batch& batch, float scale, float alpha); float getBoundingCapsuleRadius() const { return _boundingCapsuleRadius; } float getBoundingCapsuleHeight() const { return _boundingCapsuleHeight; } const glm::vec3 getBoundingCapsuleOffset() const { return _boundingCapsuleLocalOffset; } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index f343fdb155..e94a965156 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -380,7 +380,7 @@ void RenderableModelEntityItem::render(RenderArgs* args) { auto shapeTransform = getTransformToCenter(success); if (success) { batch.setModelTransform(shapeTransform); // we want to include the scale as well - DependencyManager::get()->renderWireCubeInstance(batch, greenColor); + DependencyManager::get()->renderWireCubeInstance(args, batch, greenColor); } return; } diff --git a/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp b/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp index 27dd678d91..62ab3377a8 100644 --- a/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp @@ -128,9 +128,9 @@ void RenderableShapeEntityItem::render(RenderArgs* args) { auto pipeline = color.a < 1.0f ? geometryCache->getTransparentShapePipeline() : geometryCache->getOpaqueShapePipeline(); if (render::ShapeKey(args->_globalShapeKey).isWireframe()) { - geometryCache->renderWireShapeInstance(batch, MAPPING[_shape], color, pipeline); + geometryCache->renderWireShapeInstance(args, batch, MAPPING[_shape], color, pipeline); } else { - geometryCache->renderSolidShapeInstance(batch, MAPPING[_shape], color, pipeline); + geometryCache->renderSolidShapeInstance(args, batch, MAPPING[_shape], color, pipeline); } } diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index da0aef75aa..bb07454992 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -221,10 +221,10 @@ void RenderableZoneEntityItem::render(RenderArgs* args) { if (getShapeType() == SHAPE_TYPE_SPHERE) { shapeTransform.postScale(SPHERE_ENTITY_SCALE); batch.setModelTransform(shapeTransform); - geometryCache->renderWireSphereInstance(batch, DEFAULT_COLOR); + geometryCache->renderWireSphereInstance(args, batch, DEFAULT_COLOR); } else { batch.setModelTransform(shapeTransform); - geometryCache->renderWireCubeInstance(batch, DEFAULT_COLOR); + geometryCache->renderWireCubeInstance(args, batch, DEFAULT_COLOR); } break; } diff --git a/libraries/render-utils/src/BackgroundStage.cpp b/libraries/render-utils/src/BackgroundStage.cpp index b980887471..c164b584a9 100644 --- a/libraries/render-utils/src/BackgroundStage.cpp +++ b/libraries/render-utils/src/BackgroundStage.cpp @@ -60,7 +60,6 @@ void DrawBackgroundStage::run(const render::RenderContextPointer& renderContext, // Background rendering decision - // auto backgroundStage = DependencyManager::get()->getBackgroundStage(); auto backgroundStage = renderContext->_scene->getStage("BACKGROUND_STAGE"); model::SunSkyStagePointer background; model::SkyboxPointer skybox; @@ -69,9 +68,9 @@ void DrawBackgroundStage::run(const render::RenderContextPointer& renderContext, auto background = backgroundStage->getBackground(backgroundId); if (background) { skybox = background->getSkybox(); - } + } } else { - // skybox = DependencyManager::get()->getDefaultSkybox(); + skybox = backgroundStage->getBackground(0)->getSkybox(); } /* auto backgroundMode = skyStage->getBackgroundMode(); diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 374487a79d..84c972bab3 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -99,64 +99,23 @@ void DeferredLightingEffect::init() { loadLightProgram(deferred_light_vert, local_lights_shading_frag, true, _localLight, _localLightLocations); loadLightProgram(deferred_light_vert, local_lights_drawOutline_frag, true, _localLightOutline, _localLightOutlineLocations); - - // Light Stage and clusters - /* _lightStage = std::make_shared(); - - // Allocate a global light representing the Global Directional light casting shadow (the sun) and the ambient light - _allocatedLights.push_back(std::make_shared()); - model::LightPointer lp = _allocatedLights[0]; - lp->setType(model::Light::SUN); - lp->setDirection(glm::vec3(-1.0f)); - lp->setColor(glm::vec3(1.0f)); - lp->setIntensity(1.0f); - lp->setType(model::Light::SUN); - lp->setAmbientSpherePreset(gpu::SphericalHarmonics::Preset::OLD_TOWN_SQUARE); - - // Add the global light to the light stage (for later shadow rendering) - _globalLights.push_back(_lightStage->addLight(lp)); - _lightStage->addShadow(_globalLights[0]); - - - _backgroundStage = std::make_shared(); - - auto textureCache = DependencyManager::get(); - - { - PROFILE_RANGE(render, "Process Default Skybox"); - auto textureCache = DependencyManager::get(); - - auto skyboxUrl = PathUtils::resourcesPath().toStdString() + "images/Default-Sky-9-cubemap.ktx"; - - _defaultSkyboxTexture = gpu::Texture::unserialize(skyboxUrl); - _defaultSkyboxAmbientTexture = _defaultSkyboxTexture; - - _defaultSkybox->setCubemap(_defaultSkyboxTexture); - } - - - lp->setAmbientIntensity(0.5f); - lp->setAmbientMap(_defaultSkyboxAmbientTexture); - auto irradianceSH = _defaultSkyboxAmbientTexture->getIrradiance(); - if (irradianceSH) { - lp->setAmbientSphere((*irradianceSH)); - }*/ } -void DeferredLightingEffect::setupKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit) { +void DeferredLightingEffect::setupKeyLightBatch(const RenderArgs* args, gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit) { PerformanceTimer perfTimer("DLE->setupBatch()"); model::LightPointer keySunLight; - if (_lightStage && _lightStage->_currentFrame._sunLights.size()) { - keySunLight = _lightStage->getLight(_lightStage->_currentFrame._sunLights.front()); + auto lightStage = args->_scene->getStage("LIGHT_STAGE"); + if (lightStage && lightStage->_currentFrame._sunLights.size()) { + keySunLight = lightStage->getLight(lightStage->_currentFrame._sunLights.front()); } else { - keySunLight = _allocatedLights[_globalLights.front()]; + keySunLight = lightStage->getLight(0); } model::LightPointer keyAmbiLight; - if (_lightStage && _lightStage->_currentFrame._ambientLights.size()) { - keyAmbiLight = _lightStage->getLight(_lightStage->_currentFrame._ambientLights.front()); + if (lightStage && lightStage->_currentFrame._ambientLights.size()) { + keyAmbiLight = lightStage->getLight(lightStage->_currentFrame._ambientLights.front()); } else { - keyAmbiLight = _allocatedLights[_globalLights.front()]; + keyAmbiLight = lightStage->getLight(0); } if (lightBufferUnit >= 0) { @@ -266,21 +225,6 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo } -void DeferredLightingEffect::setGlobalLight(const model::LightPointer& light) { - /* auto globalLight = _allocatedLights.front(); - globalLight->setDirection(light->getDirection()); - globalLight->setColor(light->getColor()); - globalLight->setIntensity(light->getIntensity()); - globalLight->setAmbientIntensity(light->getAmbientIntensity()); - globalLight->setAmbientSphere(light->getAmbientSphere()); - globalLight->setAmbientMap(light->getAmbientMap());*/ -} -/* -const model::LightPointer& DeferredLightingEffect::getGlobalLight() const { - return _allocatedLights.front(); -} -*/ - #include model::MeshPointer DeferredLightingEffect::getPointLightMesh() { @@ -483,8 +427,6 @@ void PrepareDeferred::run(const RenderContextPointer& renderContext, const Input // Prepare a fresh Light Frame - //auto deferredLightingEffect = DependencyManager::get(); - //deferredLightingEffect->getLightStage()->_currentFrame.clear(); auto lightStage = renderContext->_scene->getStage("LIGHT_STAGE"); lightStage->_currentFrame.clear(); } @@ -550,9 +492,7 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, // Global directional light and ambient pass auto lightStage = renderContext->_scene->getStage("LIGHT_STAGE"); - // assert(deferredLightingEffect->getLightStage()->getNumLights() > 0); assert(lightStage->getNumLights() > 0); - // auto lightAndShadow = deferredLightingEffect->getLightStage()->getLightAndShadow(0); auto lightAndShadow = lightStage->getLightAndShadow(0); const auto& globalShadow = lightAndShadow.second; @@ -563,7 +503,8 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, auto& program = deferredLightingEffect->_directionalSkyboxLight; LightLocationsPtr locations = deferredLightingEffect->_directionalSkyboxLightLocations; - const auto& keyLight = deferredLightingEffect->_allocatedLights[deferredLightingEffect->_globalLights.front()]; + + auto keyLight = lightStage->getLight(0); // Setup the global directional pass pipeline { @@ -602,7 +543,7 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, batch._glUniform4fv(locations->texcoordFrameTransform, 1, reinterpret_cast< const float* >(&textureFrameTransform)); // Setup the global lighting - deferredLightingEffect->setupKeyLightBatch(batch, locations->lightBufferUnit, locations->ambientBufferUnit, SKYBOX_MAP_UNIT); + deferredLightingEffect->setupKeyLightBatch(args, batch, locations->lightBufferUnit, locations->ambientBufferUnit, SKYBOX_MAP_UNIT); batch.draw(gpu::TRIANGLE_STRIP, 4); @@ -759,7 +700,7 @@ void RenderDeferred::run(const RenderContextPointer& renderContext, const Inputs void DefaultLightingSetup::run(const RenderContextPointer& renderContext) { - if (!_defaultLight) { + if (!_defaultLight || !_defaultBackground) { if (!_defaultSkyboxTexture) { auto textureCache = DependencyManager::get(); { @@ -779,7 +720,7 @@ void DefaultLightingSetup::run(const RenderContextPointer& renderContext) { if (lightStage) { // Allocate a default global light directional and ambient - model::LightPointer lp = std::make_shared(); + auto lp = std::make_shared(); lp->setType(model::Light::SUN); lp->setDirection(glm::vec3(-1.0f)); lp->setColor(glm::vec3(1.0f)); @@ -801,6 +742,19 @@ void DefaultLightingSetup::run(const RenderContextPointer& renderContext) { auto defaultLightID = lightStage->addLight(lp); lightStage->addShadow(defaultLightID); } + + auto backgroundStage = renderContext->_scene->getStage("BACKGROUND_STAGE"); + if (backgroundStage) { + + auto background = std::make_shared(); + background->setSkybox(_defaultSkybox); + + // capture deault background + _defaultBackground = background; + + // Add the global light to the light stage (for later shadow rendering) + auto defaultBackgroundID = backgroundStage->addBackground(_defaultBackground); + } } } diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 0e1b365149..fcbb8acf25 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -47,7 +47,7 @@ class DeferredLightingEffect : public Dependency { public: void init(); - void setupKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit); + void setupKeyLightBatch(const RenderArgs* args, gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit); void unsetKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit); // update global lighting @@ -203,6 +203,7 @@ public: protected: model::LightPointer _defaultLight; + model::SunSkyStagePointer _defaultBackground; model::SkyboxPointer _defaultSkybox { new ProceduralSkybox() }; gpu::TexturePointer _defaultSkyboxTexture; gpu::TexturePointer _defaultSkyboxAmbientTexture; diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index dcf90012c1..49b844efb0 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -455,7 +455,7 @@ _nextID(0) { buildShapes(); GeometryCache::_simpleOpaquePipeline = std::make_shared(getSimplePipeline(false, false, true, false), nullptr, - [](const render::ShapePipeline&, gpu::Batch& batch) { + [](const render::ShapePipeline&, gpu::Batch& batch, RenderArgs* args) { // Set the defaults needed for a simple program batch.setResourceTexture(render::ShapePipeline::Slot::MAP::ALBEDO, DependencyManager::get()->getWhiteTexture()); @@ -463,7 +463,7 @@ _nextID(0) { ); GeometryCache::_simpleTransparentPipeline = std::make_shared(getSimplePipeline(false, true, true, false), nullptr, - [](const render::ShapePipeline&, gpu::Batch& batch) { + [](const render::ShapePipeline&, gpu::Batch& batch, RenderArgs* args) { // Set the defaults needed for a simple program batch.setResourceTexture(render::ShapePipeline::Slot::MAP::ALBEDO, DependencyManager::get()->getWhiteTexture()); @@ -471,7 +471,7 @@ _nextID(0) { ); GeometryCache::_simpleWirePipeline = std::make_shared(getSimplePipeline(false, false, true, true), nullptr, - [](const render::ShapePipeline&, gpu::Batch& batch) {}); + [](const render::ShapePipeline&, gpu::Batch& batch, RenderArgs* args) {}); } GeometryCache::~GeometryCache() { @@ -1938,7 +1938,7 @@ uint32_t toCompactColor(const glm::vec4& color) { static const size_t INSTANCE_COLOR_BUFFER = 0; -void renderInstances(gpu::Batch& batch, const glm::vec4& color, bool isWire, +void renderInstances(RenderArgs* args, gpu::Batch& batch, const glm::vec4& color, bool isWire, const render::ShapePipelinePointer& pipeline, GeometryCache::Shape shape) { // Add pipeline to name std::string instanceName = (isWire ? "wire_shapes_" : "solid_shapes_") + std::to_string(shape) + "_" + std::to_string(std::hash()(pipeline)); @@ -1951,9 +1951,9 @@ void renderInstances(gpu::Batch& batch, const glm::vec4& color, bool isWire, } // Add call to named buffer - batch.setupNamedCalls(instanceName, [isWire, pipeline, shape](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { + batch.setupNamedCalls(instanceName, [args, isWire, pipeline, shape](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { batch.setPipeline(pipeline->pipeline); - pipeline->prepare(batch); + pipeline->prepare(batch, args); if (isWire) { DependencyManager::get()->renderWireShapeInstances(batch, shape, data.count(), data.buffers[INSTANCE_COLOR_BUFFER]); @@ -1963,28 +1963,28 @@ void renderInstances(gpu::Batch& batch, const glm::vec4& color, bool isWire, }); } -void GeometryCache::renderSolidShapeInstance(gpu::Batch& batch, GeometryCache::Shape shape, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { - renderInstances(batch, color, false, pipeline, shape); +void GeometryCache::renderSolidShapeInstance(RenderArgs* args, gpu::Batch& batch, GeometryCache::Shape shape, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { + renderInstances(args, batch, color, false, pipeline, shape); } -void GeometryCache::renderWireShapeInstance(gpu::Batch& batch, GeometryCache::Shape shape, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { - renderInstances(batch, color, true, pipeline, shape); +void GeometryCache::renderWireShapeInstance(RenderArgs* args, gpu::Batch& batch, GeometryCache::Shape shape, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { + renderInstances(args, batch, color, true, pipeline, shape); } -void GeometryCache::renderSolidSphereInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { - renderInstances(batch, color, false, pipeline, GeometryCache::Sphere); +void GeometryCache::renderSolidSphereInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { + renderInstances(args, batch, color, false, pipeline, GeometryCache::Sphere); } -void GeometryCache::renderWireSphereInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { - renderInstances(batch, color, true, pipeline, GeometryCache::Sphere); +void GeometryCache::renderWireSphereInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { + renderInstances(args, batch, color, true, pipeline, GeometryCache::Sphere); } // Enable this in a debug build to cause 'box' entities to iterate through all the // available shape types, both solid and wireframes //#define DEBUG_SHAPES -void GeometryCache::renderSolidCubeInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { +void GeometryCache::renderSolidCubeInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { #ifdef DEBUG_SHAPES static auto startTime = usecTimestampNow(); renderInstances(INSTANCE_NAME, batch, color, pipeline, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { @@ -2018,11 +2018,11 @@ void GeometryCache::renderSolidCubeInstance(gpu::Batch& batch, const glm::vec4& } }); #else - renderInstances(batch, color, false, pipeline, GeometryCache::Cube); + renderInstances(args, batch, color, false, pipeline, GeometryCache::Cube); #endif } -void GeometryCache::renderWireCubeInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { +void GeometryCache::renderWireCubeInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { static const std::string INSTANCE_NAME = __FUNCTION__; - renderInstances(batch, color, true, pipeline, GeometryCache::Cube); + renderInstances(args, batch, color, true, pipeline, GeometryCache::Cube); } diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 9853269280..fa558a1151 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -172,46 +172,46 @@ public: void renderShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& colorBuffer); void renderWireShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& colorBuffer); - void renderSolidShapeInstance(gpu::Batch& batch, Shape shape, const glm::vec4& color = glm::vec4(1), + void renderSolidShapeInstance(RenderArgs* args, gpu::Batch& batch, Shape shape, const glm::vec4& color = glm::vec4(1), const render::ShapePipelinePointer& pipeline = _simpleOpaquePipeline); - void renderSolidShapeInstance(gpu::Batch& batch, Shape shape, const glm::vec3& color, + void renderSolidShapeInstance(RenderArgs* args, gpu::Batch& batch, Shape shape, const glm::vec3& color, const render::ShapePipelinePointer& pipeline = _simpleOpaquePipeline) { - renderSolidShapeInstance(batch, shape, glm::vec4(color, 1.0f), pipeline); + renderSolidShapeInstance(args, batch, shape, glm::vec4(color, 1.0f), pipeline); } - void renderWireShapeInstance(gpu::Batch& batch, Shape shape, const glm::vec4& color = glm::vec4(1), + void renderWireShapeInstance(RenderArgs* args, gpu::Batch& batch, Shape shape, const glm::vec4& color = glm::vec4(1), const render::ShapePipelinePointer& pipeline = _simpleOpaquePipeline); - void renderWireShapeInstance(gpu::Batch& batch, Shape shape, const glm::vec3& color, + void renderWireShapeInstance(RenderArgs* args, gpu::Batch& batch, Shape shape, const glm::vec3& color, const render::ShapePipelinePointer& pipeline = _simpleOpaquePipeline) { - renderWireShapeInstance(batch, shape, glm::vec4(color, 1.0f), pipeline); + renderWireShapeInstance(args, batch, shape, glm::vec4(color, 1.0f), pipeline); } - void renderSolidSphereInstance(gpu::Batch& batch, const glm::vec4& color, + void renderSolidSphereInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline = _simpleOpaquePipeline); - void renderSolidSphereInstance(gpu::Batch& batch, const glm::vec3& color, + void renderSolidSphereInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec3& color, const render::ShapePipelinePointer& pipeline = _simpleOpaquePipeline) { - renderSolidSphereInstance(batch, glm::vec4(color, 1.0f), pipeline); + renderSolidSphereInstance(args, batch, glm::vec4(color, 1.0f), pipeline); } - void renderWireSphereInstance(gpu::Batch& batch, const glm::vec4& color, + void renderWireSphereInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline = _simpleWirePipeline); - void renderWireSphereInstance(gpu::Batch& batch, const glm::vec3& color, + void renderWireSphereInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec3& color, const render::ShapePipelinePointer& pipeline = _simpleWirePipeline) { - renderWireSphereInstance(batch, glm::vec4(color, 1.0f), pipeline); + renderWireSphereInstance(args, batch, glm::vec4(color, 1.0f), pipeline); } - void renderSolidCubeInstance(gpu::Batch& batch, const glm::vec4& color, + void renderSolidCubeInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline = _simpleOpaquePipeline); - void renderSolidCubeInstance(gpu::Batch& batch, const glm::vec3& color, + void renderSolidCubeInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec3& color, const render::ShapePipelinePointer& pipeline = _simpleOpaquePipeline) { - renderSolidCubeInstance(batch, glm::vec4(color, 1.0f), pipeline); + renderSolidCubeInstance(args, batch, glm::vec4(color, 1.0f), pipeline); } - void renderWireCubeInstance(gpu::Batch& batch, const glm::vec4& color, + void renderWireCubeInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline = _simpleWirePipeline); - void renderWireCubeInstance(gpu::Batch& batch, const glm::vec3& color, + void renderWireCubeInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec3& color, const render::ShapePipelinePointer& pipeline = _simpleWirePipeline) { - renderWireCubeInstance(batch, glm::vec4(color, 1.0f), pipeline); + renderWireCubeInstance(args, batch, glm::vec4(color, 1.0f), pipeline); } // Dynamic geometry diff --git a/libraries/render-utils/src/RenderPipelines.cpp b/libraries/render-utils/src/RenderPipelines.cpp index 42ed0bdad9..6c3a58b7e5 100644 --- a/libraries/render-utils/src/RenderPipelines.cpp +++ b/libraries/render-utils/src/RenderPipelines.cpp @@ -76,8 +76,8 @@ void initForwardPipelines(ShapePlumber& plumber); void addPlumberPipeline(ShapePlumber& plumber, const ShapeKey& key, const gpu::ShaderPointer& vertex, const gpu::ShaderPointer& pixel); -void batchSetter(const ShapePipeline& pipeline, gpu::Batch& batch); -void lightBatchSetter(const ShapePipeline& pipeline, gpu::Batch& batch); +void batchSetter(const ShapePipeline& pipeline, gpu::Batch& batch, RenderArgs* args); +void lightBatchSetter(const ShapePipeline& pipeline, gpu::Batch& batch, RenderArgs* args); void initOverlay3DPipelines(ShapePlumber& plumber) { auto vertex = gpu::Shader::createVertex(std::string(overlay3D_vert)); @@ -359,7 +359,7 @@ void addPlumberPipeline(ShapePlumber& plumber, } } -void batchSetter(const ShapePipeline& pipeline, gpu::Batch& batch) { +void batchSetter(const ShapePipeline& pipeline, gpu::Batch& batch, RenderArgs* args) { // Set a default albedo map batch.setResourceTexture(render::ShapePipeline::Slot::MAP::ALBEDO, DependencyManager::get()->getWhiteTexture()); @@ -382,13 +382,13 @@ void batchSetter(const ShapePipeline& pipeline, gpu::Batch& batch) { } } -void lightBatchSetter(const ShapePipeline& pipeline, gpu::Batch& batch) { +void lightBatchSetter(const ShapePipeline& pipeline, gpu::Batch& batch, RenderArgs* args) { // Set the batch - batchSetter(pipeline, batch); + batchSetter(pipeline, batch, args); // Set the light if (pipeline.locations->lightBufferUnit >= 0) { - DependencyManager::get()->setupKeyLightBatch(batch, + DependencyManager::get()->setupKeyLightBatch(args, batch, pipeline.locations->lightBufferUnit, pipeline.locations->lightAmbientBufferUnit, pipeline.locations->lightAmbientMapUnit); diff --git a/libraries/render-utils/src/UpdateSceneTask.cpp b/libraries/render-utils/src/UpdateSceneTask.cpp index 1a9beb4bed..2daee5fb5a 100644 --- a/libraries/render-utils/src/UpdateSceneTask.cpp +++ b/libraries/render-utils/src/UpdateSceneTask.cpp @@ -16,11 +16,11 @@ #include "DeferredLightingEffect.h" void UpdateSceneTask::build(JobModel& task, const render::Varying& input, render::Varying& output) { - - task.addJob("PerformSceneTransaction"); - task.addJob("LightStageSetup"); + task.addJob("BackgroundStageSetup"); task.addJob("DefaultLightingSetup"); + + task.addJob("PerformSceneTransaction"); } diff --git a/libraries/render-utils/src/ZoneRenderer.cpp b/libraries/render-utils/src/ZoneRenderer.cpp index e20e7d9ed8..80be123f0f 100644 --- a/libraries/render-utils/src/ZoneRenderer.cpp +++ b/libraries/render-utils/src/ZoneRenderer.cpp @@ -52,14 +52,19 @@ void ZoneRendererTask::build(JobModel& task, const Varying& input, Varying& oupu } void SetupZones::run(const RenderContextPointer& context, const Inputs& inputs) { - - // auto backgroundStage = DependencyManager::get()->getBackgroundStage(); auto backgroundStage = context->_scene->getStage("BACKGROUND_STAGE"); backgroundStage->_currentFrame.clear(); // call render in the correct order first... render::renderItems(context, inputs); + // Finally add the default lights and background: + auto lightStage = context->_scene->getStage("LIGHT_STAGE"); + lightStage->_currentFrame.pushSunLight(0); + lightStage->_currentFrame.pushAmbientLight(0); + + backgroundStage->_currentFrame.pushBackground(0); + } const gpu::PipelinePointer& DebugZoneLighting::getKeyLightPipeline() { @@ -131,7 +136,6 @@ void DebugZoneLighting::run(const render::RenderContextPointer& context, const I auto deferredTransform = inputs; - // auto lightStage = DependencyManager::get()->getLightStage(); auto lightStage = context->_scene->getStage("LIGHT_STAGE"); std::vector keyLightStack; if (lightStage && lightStage->_currentFrame._sunLights.size()) { @@ -139,8 +143,7 @@ void DebugZoneLighting::run(const render::RenderContextPointer& context, const I keyLightStack.push_back(lightStage->getLight(index)); } } - // keyLightStack.push_back(DependencyManager::get()->getGlobalLight()); - keyLightStack.push_back(lightStage->getLight(0)); + // keyLightStack.push_back(lightStage->getLight(0)); std::vector ambientLightStack; if (lightStage && lightStage->_currentFrame._ambientLights.size()) { @@ -148,11 +151,8 @@ void DebugZoneLighting::run(const render::RenderContextPointer& context, const I ambientLightStack.push_back(lightStage->getLight(index)); } } - // ambientLightStack.push_back(DependencyManager::get()->getGlobalLight()); - ambientLightStack.push_back(lightStage->getLight(0)); + // ambientLightStack.push_back(lightStage->getLight(0)); - - // auto backgroundStage = DependencyManager::get()->getBackgroundStage(); auto backgroundStage = context->_scene->getStage("BACKGROUND_STAGE"); std::vector skyboxStack; if (backgroundStage && backgroundStage->_currentFrame._backgrounds.size()) { @@ -163,7 +163,7 @@ void DebugZoneLighting::run(const render::RenderContextPointer& context, const I } } } - // skyboxStack.push_back(DependencyManager::get()->getDefaultSkybox()); + // skyboxStack.push_back(backgroundStage->getBackground(0)->getSkybox()); gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { diff --git a/libraries/render/src/render/ShapePipeline.cpp b/libraries/render/src/render/ShapePipeline.cpp index d51d7f8cb6..79ac5c0990 100644 --- a/libraries/render/src/render/ShapePipeline.cpp +++ b/libraries/render/src/render/ShapePipeline.cpp @@ -17,9 +17,9 @@ using namespace render; -void ShapePipeline::prepare(gpu::Batch& batch) { +void ShapePipeline::prepare(gpu::Batch& batch, RenderArgs* args) { if (batchSetter) { - batchSetter(*this, batch); + batchSetter(*this, batch, args); } } @@ -119,7 +119,7 @@ const ShapePipelinePointer ShapePlumber::pickPipeline(RenderArgs* args, const Ke // Run the pipeline's BatchSetter on the passed in batch if (shapePipeline->batchSetter) { - shapePipeline->batchSetter(*shapePipeline, *batch); + shapePipeline->batchSetter(*shapePipeline, *batch, args); } return shapePipeline; diff --git a/libraries/render/src/render/ShapePipeline.h b/libraries/render/src/render/ShapePipeline.h index 434c909198..1b97baae7c 100644 --- a/libraries/render/src/render/ShapePipeline.h +++ b/libraries/render/src/render/ShapePipeline.h @@ -240,14 +240,14 @@ public: }; using LocationsPointer = std::shared_ptr; - using BatchSetter = std::function; + using BatchSetter = std::function; ShapePipeline(gpu::PipelinePointer pipeline, LocationsPointer locations, BatchSetter batchSetter) : pipeline(pipeline), locations(locations), batchSetter(batchSetter) {} // Normally, a pipeline is accessed thorugh pickPipeline. If it needs to be set manually, // after calling setPipeline this method should be called to prepare the pipeline with default buffers. - void prepare(gpu::Batch& batch); + void prepare(gpu::Batch& batch, RenderArgs* args); gpu::PipelinePointer pipeline; std::shared_ptr locations; diff --git a/tests/gpu-test/src/TestWindow.cpp b/tests/gpu-test/src/TestWindow.cpp index 6436ff1ef4..5b5102701a 100644 --- a/tests/gpu-test/src/TestWindow.cpp +++ b/tests/gpu-test/src/TestWindow.cpp @@ -77,7 +77,7 @@ void TestWindow::initGl() { #ifdef DEFERRED_LIGHTING auto deferredLightingEffect = DependencyManager::get(); deferredLightingEffect->init(); - deferredLightingEffect->setGlobalLight(_light); + // deferredLightingEffect->setGlobalLight(_light); initDeferredPipelines(*_shapePlumber); #endif } diff --git a/tests/render-perf/src/main.cpp b/tests/render-perf/src/main.cpp index 52592cd202..f725e1f09d 100644 --- a/tests/render-perf/src/main.cpp +++ b/tests/render-perf/src/main.cpp @@ -891,7 +891,7 @@ private: // Setup the current Zone Entity lighting { auto stage = DependencyManager::get()->getSkyStage(); - DependencyManager::get()->setGlobalLight(stage->getSunLight()); + // DependencyManager::get()->setGlobalLight(stage->getSunLight()); } { @@ -914,7 +914,7 @@ private: // The pending changes collecting the changes here render::Transaction transaction; // Setup the current Zone Entity lighting - DependencyManager::get()->setGlobalLight(_sunSkyStage.getSunLight()); + // DependencyManager::get()->setGlobalLight(_sunSkyStage.getSunLight()); { PerformanceTimer perfTimer("SceneProcessTransaction"); _main3DScene->enqueueTransaction(transaction);