diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index dece8e9ce3..9adb7948df 100755 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -70,8 +70,8 @@ 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 * isUnlitEnabled(), 1.0); + // _fragColor2 = vec4(vec3(0.0), 1.0); + _fragColor3 = vec4(color, 1.0); } void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 albedo, vec3 fresnel, float roughness) { diff --git a/libraries/render-utils/src/RenderShadowTask.cpp b/libraries/render-utils/src/RenderShadowTask.cpp index 5680660122..2e3901a769 100644 --- a/libraries/render-utils/src/RenderShadowTask.cpp +++ b/libraries/render-utils/src/RenderShadowTask.cpp @@ -85,8 +85,7 @@ void RenderShadowMap::run(const render::SceneContextPointer& sceneContext, const }); } -// The shadow task *must* use this base ctor to initialize with its own Config, see Task.h -RenderShadowTask::RenderShadowTask(CullFunctor cullFunctor) : Task(std::make_shared()) { +RenderShadowTask::RenderShadowTask(CullFunctor cullFunctor) { cullFunctor = cullFunctor ? cullFunctor : [](const RenderArgs*, const AABox&){ return true; }; // Prepare the ShapePipeline diff --git a/libraries/render-utils/src/model_unlit.slf b/libraries/render-utils/src/model_unlit.slf index 3c2e4ae2e0..c64f9a07d7 100644 --- a/libraries/render-utils/src/model_unlit.slf +++ b/libraries/render-utils/src/model_unlit.slf @@ -40,5 +40,5 @@ void main(void) { packDeferredFragmentUnlit( normalize(_normal), opacity, - albedo); + albedo * isUnlitEnabled()); } diff --git a/libraries/render/src/render/Task.h b/libraries/render/src/render/Task.h index a42fb4f0ac..cc38830498 100644 --- a/libraries/render/src/render/Task.h +++ b/libraries/render/src/render/Task.h @@ -368,8 +368,6 @@ public: TaskConfig() = default ; TaskConfig(bool enabled) : JobConfig(enabled) {} - void init(Task* task) { _task = task; } - // getter for qml integration, prefer the templated getter Q_INVOKABLE QObject* getConfig(const QString& name) { return QObject::findChild(name); } // getter for cpp (strictly typed), prefer this getter @@ -382,6 +380,7 @@ public slots: void refresh(); private: + friend class Task; Task* _task; }; @@ -498,8 +497,6 @@ public: // A task is a specialized job to run a collection of other jobs // It is defined with JobModel = Task::Model -// -// A task with a custom config *must* use the templated constructor class Task { public: using Config = TaskConfig; @@ -521,9 +518,10 @@ public: template Model(const Varying& input, A&&... args) : - Concept(std::make_shared()), _data(Data(std::forward(args)...)), _input(input), _output(Output()) { - _config = _data._config; - std::static_pointer_cast(_config)->init(&_data); + Concept(nullptr), _data(Data(std::forward(args)...)), _input(input), _output(Output()) { + // Recreate the Config to use the templated type + _data.createConfiguration(); + _config = _data.getConfiguration(); applyConfiguration(); } @@ -545,23 +543,19 @@ public: using Jobs = std::vector; - // A task must use its Config for construction - Task() : _config{ std::make_shared() } {} - template Task(std::shared_ptr config) : _config{ config } {} - // Create a new job in the container's queue; returns the job's output template const Varying addJob(std::string name, const Varying& input, A&&... args) { _jobs.emplace_back(name, std::make_shared(input, std::forward(args)...)); QConfigPointer config = _jobs.back().getConfiguration(); - config->setParent(_config.get()); + config->setParent(getConfiguration().get()); config->setObjectName(name.c_str()); // Connect loaded->refresh - QObject::connect(config.get(), SIGNAL(loaded()), _config.get(), SLOT(refresh())); + QObject::connect(config.get(), SIGNAL(loaded()), getConfiguration().get(), SLOT(refresh())); static const char* DIRTY_SIGNAL = "dirty()"; if (config->metaObject()->indexOfSignal(DIRTY_SIGNAL) != -1) { // Connect dirty->refresh if defined - QObject::connect(config.get(), SIGNAL(dirty()), _config.get(), SLOT(refresh())); + QObject::connect(config.get(), SIGNAL(dirty()), getConfiguration().get(), SLOT(refresh())); } return _jobs.back().getOutput(); @@ -571,16 +565,36 @@ public: return addJob(name, input, std::forward(args)...); } + template void createConfiguration() { + auto config = std::make_shared(); + if (_config) { + // Transfer children to the new configuration + auto children = _config->children(); + for (auto& child : children) { + child->setParent(config.get()); + QObject::connect(child, SIGNAL(loaded()), config.get(), SLOT(refresh())); + static const char* DIRTY_SIGNAL = "dirty()"; + if (child->metaObject()->indexOfSignal(DIRTY_SIGNAL) != -1) { + // Connect dirty->refresh if defined + QObject::connect(child, SIGNAL(dirty()), config.get(), SLOT(refresh())); + } + } + } + _config = config; + std::static_pointer_cast(_config)->_task = this; + } + std::shared_ptr getConfiguration() { - auto config = std::static_pointer_cast(_config); - // If we are here, we were not made by a Model, so we must initialize our own config - config->init(this); - return config; + if (!_config) { + createConfiguration(); + } + return std::static_pointer_cast(_config); } void configure(const QObject& configuration) { for (auto& job : _jobs) { job.applyConfiguration(); + } }