diff --git a/engine/includes/components/pointlight.h b/engine/includes/components/pointlight.h index 89fc4794b..7eb4103a1 100644 --- a/engine/includes/components/pointlight.h +++ b/engine/includes/components/pointlight.h @@ -8,8 +8,8 @@ class ENGINE_EXPORT PointLight : public BaseLight { A_PROPERTIES( A_PROPERTY(float, attenuationRadius, PointLight::attenuationRadius, PointLight::setAttenuationRadius), - A_PROPERTY(float, sourceRadius, PointLight::sourceRadius, PointLight::setSourceRadius), - A_PROPERTY(float, sourceLength, PointLight::sourceLength, PointLight::setSourceLength) + A_PROPERTY(float, sourceRadius, PointLight::sourceRadius, PointLight::setSourceRadius), + A_PROPERTY(float, sourceLength, PointLight::sourceLength, PointLight::setSourceLength) ) A_NOMETHODS() @@ -33,7 +33,6 @@ class ENGINE_EXPORT PointLight : public BaseLight { void drawGizmos() override; void drawGizmosSelected() override; - private: AABBox m_box; diff --git a/engine/includes/components/postprocessvolume.h b/engine/includes/components/postprocessvolume.h index 7671e37c8..0ec9258ba 100644 --- a/engine/includes/components/postprocessvolume.h +++ b/engine/includes/components/postprocessvolume.h @@ -6,7 +6,7 @@ class PostProcessSettings; class ENGINE_EXPORT PostProcessVolume : public Component { - A_REGISTER(PostProcessVolume, Component, General) + A_REGISTER(PostProcessVolume, Component, Components/Volumes) A_PROPERTIES( A_PROPERTY(int, priority, PostProcessVolume::priority, PostProcessVolume::setPriority), @@ -16,6 +16,7 @@ class ENGINE_EXPORT PostProcessVolume : public Component { public: PostProcessVolume(); + ~PostProcessVolume(); int priority() const; void setPriority(int priority); @@ -28,11 +29,13 @@ class ENGINE_EXPORT PostProcessVolume : public Component { AABBox bound() const; - const PostProcessSettings &settings() const; + const PostProcessSettings *settings() const; private: void setProperty(const char *name, const Variant &value) override; + void setSystem(ObjectSystem *system) override; + void drawGizmos() override; private: diff --git a/engine/includes/components/private/postprocessorsettings.h b/engine/includes/components/private/postprocessorsettings.h index 75b575579..378bca4c8 100644 --- a/engine/includes/components/private/postprocessorsettings.h +++ b/engine/includes/components/private/postprocessorsettings.h @@ -1,34 +1,27 @@ #ifndef POSTPROCESSORSETTINGS_H #define POSTPROCESSORSETTINGS_H -#include - #include -using namespace std; - -namespace { - static map s_settingsMap; -}; - class PostProcessSettings { public: PostProcessSettings(); - static map &settings(); + static std::map &settings(); - static void registerSetting(const string &name, const Variant &value); + static void registerSetting(const std::string &name, const Variant &value); - Variant readValue(const string &name) const; - void writeValue(const string &name, const Variant &value); + static Variant defaultValue(const std::string &name); - void lerp(const PostProcessSettings &settings, float t); + Variant readValue(const std::string &name) const; + void writeValue(const std::string &name, const Variant &value); void resetDefault(); private: - unordered_map m_currentValues; + std::unordered_map m_currentValues; + static std::map s_settingsMap; }; #endif // POSTPROCESSORSETTINGS_H diff --git a/engine/includes/pipelinecontext.h b/engine/includes/pipelinecontext.h index 3a2e2af7a..936d93e09 100644 --- a/engine/includes/pipelinecontext.h +++ b/engine/includes/pipelinecontext.h @@ -59,6 +59,8 @@ class ENGINE_EXPORT PipelineContext : public Object { std::list &culledComponents(); std::list &sceneLights(); + std::list > &culledPostEffectSettings(); + std::list frustumCulling(const std::array &frustum, std::list &list, AABBox &box); void setPipeline(Pipeline *pipeline); @@ -97,8 +99,11 @@ class ENGINE_EXPORT PipelineContext : public Object { std::list m_sceneComponents; std::list m_culledComponents; + std::list m_sceneLights; + std::list> m_culledPostProcessSettings; + BuffersMap m_textureBuffers; std::list m_renderTasks; @@ -109,14 +114,10 @@ class ENGINE_EXPORT PipelineContext : public Object { CommandBuffer *m_buffer; - PostProcessSettings *m_postProcessSettings; - MaterialInstance *m_finalMaterial; RenderTarget *m_defaultTarget; - Texture *m_radianceMap; - Camera *m_camera; int32_t m_width; diff --git a/engine/includes/pipelinetask.h b/engine/includes/pipelinetask.h index b2666074a..d3dae0aa3 100644 --- a/engine/includes/pipelinetask.h +++ b/engine/includes/pipelinetask.h @@ -29,10 +29,6 @@ class ENGINE_EXPORT PipelineTask : public Object { std::string outputName(int index) const; virtual Texture *output(int index); - virtual void setProperty(const std::string &name, const Variant &value); - - virtual void setSettings(const PostProcessSettings &settings); - void setEnabled(bool enable); bool isEnabled() const; diff --git a/engine/includes/pipelinetasks/ambientocclusion.h b/engine/includes/pipelinetasks/ambientocclusion.h index 08781a8eb..a1da381b3 100644 --- a/engine/includes/pipelinetasks/ambientocclusion.h +++ b/engine/includes/pipelinetasks/ambientocclusion.h @@ -18,7 +18,7 @@ class AmbientOcclusion : public PipelineTask { private: void exec(PipelineContext &context) override; - void setSettings(const PostProcessSettings &settings) override; + void resize(int32_t width, int32_t height) override; void setInput(int index, Texture *texture) override; @@ -28,14 +28,14 @@ class AmbientOcclusion : public PipelineTask { float m_power; Texture *m_noiseTexture; + Texture *m_aoTexture; + Texture *m_blurTexture; - RenderTarget *m_ssaoTarget; + RenderTarget *m_aoTarget; RenderTarget *m_blurTarget; - RenderTarget *m_combineTarget; MaterialInstance *m_occlusion; MaterialInstance *m_blur; - MaterialInstance *m_combine; }; diff --git a/engine/includes/pipelinetasks/antialiasing.h b/engine/includes/pipelinetasks/antialiasing.h index 795544ae8..771613012 100644 --- a/engine/includes/pipelinetasks/antialiasing.h +++ b/engine/includes/pipelinetasks/antialiasing.h @@ -11,6 +11,7 @@ class AntiAliasing : public PipelineTask { public: AntiAliasing(); + ~AntiAliasing(); private: void exec(PipelineContext &context) override; @@ -18,9 +19,11 @@ class AntiAliasing : public PipelineTask { void setInput(int index, Texture *texture) override; private: + Texture *m_resultTexture; + RenderTarget *m_resultTarget; - MaterialInstance *m_material; + MaterialInstance *m_resultMaterial; }; diff --git a/engine/includes/pipelinetasks/bloom.h b/engine/includes/pipelinetasks/bloom.h index 51c08da6c..ab007e37c 100644 --- a/engine/includes/pipelinetasks/bloom.h +++ b/engine/includes/pipelinetasks/bloom.h @@ -30,14 +30,13 @@ class Bloom : public PipelineTask { public: Bloom(); + ~Bloom(); private: void exec(PipelineContext &context) override; void resize(int32_t width, int32_t height) override; - void setSettings(const PostProcessSettings &settings) override; - void setInput(int index, Texture *source) override; void generateKernel(float radius, int32_t steps, float *points); diff --git a/engine/includes/pipelinetasks/deferredlighting.h b/engine/includes/pipelinetasks/deferredlighting.h index fa6b128a8..543767287 100644 --- a/engine/includes/pipelinetasks/deferredlighting.h +++ b/engine/includes/pipelinetasks/deferredlighting.h @@ -4,12 +4,14 @@ #include "pipelinetask.h" class RenderTarget; +class MaterialInstance; class DeferredLighting : public PipelineTask { A_REGISTER(DeferredLighting, PipelineTask, Pipeline) public: DeferredLighting(); + ~DeferredLighting(); private: void exec(PipelineContext &context) override; @@ -17,6 +19,8 @@ class DeferredLighting : public PipelineTask { void setInput(int index, Texture *texture) override; private: + Vector3 m_sunDirection; + RenderTarget *m_lightPass; }; diff --git a/engine/includes/pipelinetasks/indirect.h b/engine/includes/pipelinetasks/indirect.h new file mode 100644 index 000000000..a34117679 --- /dev/null +++ b/engine/includes/pipelinetasks/indirect.h @@ -0,0 +1,33 @@ +#ifndef DEFERREDINDIRECT_H +#define DEFERREDINDIRECT_H + +#include "pipelinetask.h" + +class RenderTarget; +class MaterialInstance; + +class DeferredIndirect : public PipelineTask { + A_REGISTER(DeferredIndirect, PipelineTask, Pipeline) + +public: + DeferredIndirect(); + +private: + void analyze(World *world) override; + void exec(PipelineContext &context) override; + + void setInput(int index, Texture *texture) override; + +private: + Vector4 m_cameraColor; + + MaterialInstance *m_iblMaterial; + + Texture *m_cameraTexture; + Texture *m_iblTexture; + + RenderTarget *m_iblTarget; + +}; + +#endif // DEFERREDINDIRECT_H diff --git a/engine/includes/pipelinetasks/reflections.h b/engine/includes/pipelinetasks/reflections.h index 07b7f84fa..d4fd60933 100644 --- a/engine/includes/pipelinetasks/reflections.h +++ b/engine/includes/pipelinetasks/reflections.h @@ -3,9 +3,8 @@ #include "pipelinetask.h" -class Texture; -class MaterialInstance; class RenderTarget; +class MaterialInstance; class Reflections : public PipelineTask { A_REGISTER(Reflections, PipelineTask, Pipeline) @@ -19,13 +18,11 @@ class Reflections : public PipelineTask { void setInput(int index, Texture *texture) override; private: - MaterialInstance *m_slrMaterial; - MaterialInstance *m_combineMaterial; + MaterialInstance *m_sslrMaterial; - Texture *m_environmentTexture; + Texture *m_sslrTexture; - RenderTarget *m_slrTarget; - RenderTarget *m_combineTarget; + RenderTarget *m_sslrTarget; }; diff --git a/engine/src/components/component.cpp b/engine/src/components/component.cpp index 3c19bd5f7..4d3e6e96d 100644 --- a/engine/src/components/component.cpp +++ b/engine/src/components/component.cpp @@ -186,13 +186,26 @@ Object *loadObjectHelper(const Variant &value, const MetaObject *meta, Object *r void Component::loadUserData(const VariantMap &data) { PROFILE_FUNCTION(); + std::list> properties; const MetaObject *meta = metaObject(); for(int index = 0; index < meta->propertyCount(); index++) { MetaProperty property = meta->property(index); - auto field = data.find(property.name()); + properties.push_back(std::make_pair(property.name(), property.type().name())); + } + for(auto it : dynamicPropertyNames()) { + properties.push_back(std::make_pair(it, "")); + } + + for(auto it : properties) { + auto field = data.find(it.first); if(field != data.end()) { bool isArray = false; - std::string typeName = property.type().name(); + std::string typeName = it.second; + if(typeName.empty()) { + Variant value = property(it.first.c_str()); + typeName = MetaType::name(value.userType()); + } + trimmType(typeName, isArray); auto factory = System::metaFactory(typeName); if(factory) { @@ -204,11 +217,11 @@ void Component::loadUserData(const VariantMap &data) { Object *object = loadObjectHelper(it, factory->first, root); list.push_back(Variant(type, &object)); } - property.write(this, list); + setProperty(it.first.c_str(), list); } else { Object *object = loadObjectHelper(field->second, factory->first, root); if(object) { - property.write(this, Variant(type, &object)); + setProperty(it.first.c_str(), Variant(type, &object)); } } } @@ -233,25 +246,38 @@ VariantMap Component::saveUserData() const { PROFILE_FUNCTION(); VariantMap result; + std::list> properties; + const MetaObject *meta = metaObject(); for(int index = 0; index < meta->propertyCount(); index++) { MetaProperty property = meta->property(index); + properties.push_back(std::make_pair(property.name(), property.type().name())); + } + for(auto it : dynamicPropertyNames()) { + properties.push_back(std::make_pair(it, "")); + } + + for(auto it : properties) { + Variant value = property(it.first.c_str()); + bool isArray = false; - std::string typeName = property.type().name(); + std::string typeName = it.second; + if(typeName.empty()) { + typeName = MetaType::name(value.userType()); + } trimmType(typeName, isArray); auto factory = System::metaFactory(typeName); if(factory) { - Variant value = property.read(this); if(isArray) { VariantList list; for(auto it : value.toList()) { Object *object = (value.data() == nullptr) ? nullptr : *(reinterpret_cast(it.data())); list.push_back(saveObjectHelper(object, factory->first)); } - result[property.name()] = list; + result[it.first] = list; } else { Object *object = (value.data() == nullptr) ? nullptr : *(reinterpret_cast(value.data())); - result[property.name()] = saveObjectHelper(object, factory->first); + result[it.first] = saveObjectHelper(object, factory->first); } } } diff --git a/engine/src/components/postprocessvolume.cpp b/engine/src/components/postprocessvolume.cpp index 65e1eef49..cfd31e16e 100644 --- a/engine/src/components/postprocessvolume.cpp +++ b/engine/src/components/postprocessvolume.cpp @@ -1,19 +1,17 @@ #include "components/postprocessvolume.h" +#include "components/private/postprocessorsettings.h" + #include "components/world.h" #include "components/actor.h" #include "components/transform.h" -#include "components/private/postprocessorsettings.h" #include "resources/texture.h" -#include "gizmos.h" +#include "systems/rendersystem.h" -namespace { - const char *gComponents = "Components"; - const char *gVolume = "PostProcessVolume"; -} +#include "gizmos.h" /*! \class PostProcessVolume @@ -33,6 +31,10 @@ PostProcessVolume::PostProcessVolume() : Object::setProperty(it.first.c_str(), it.second); } } + +PostProcessVolume::~PostProcessVolume() { + static_cast(system())->removePostProcessVolume(this); +} /*! Returns the priority of volume in the list. */ @@ -82,8 +84,8 @@ AABBox PostProcessVolume::bound() const { /*! \internal */ -const PostProcessSettings &PostProcessVolume::settings() const { - return *m_settings; +const PostProcessSettings *PostProcessVolume::settings() const { + return m_settings; } /*! \internal @@ -96,6 +98,15 @@ void PostProcessVolume::setProperty(const char *name, const Variant &value) { /*! \internal */ +void PostProcessVolume::setSystem(ObjectSystem *system) { + Component::setSystem(system); + + RenderSystem *render = static_cast(system); + render->addPostProcessVolume(this); +} +/*! + \internal +*/ void PostProcessVolume::drawGizmos() { Transform *t = transform(); diff --git a/engine/src/components/private/postprocessorsettings.cpp b/engine/src/components/private/postprocessorsettings.cpp index 9ef36507a..bfeec31a3 100644 --- a/engine/src/components/private/postprocessorsettings.cpp +++ b/engine/src/components/private/postprocessorsettings.cpp @@ -1,54 +1,41 @@ #include "components/private/postprocessorsettings.h" +std::map PostProcessSettings::s_settingsMap; + PostProcessSettings::PostProcessSettings() { } -map &PostProcessSettings::settings() { +std::map &PostProcessSettings::settings() { return s_settingsMap; } -void PostProcessSettings::registerSetting(const string &name, const Variant &value) { - s_settingsMap[name + "_override"] = false; +void PostProcessSettings::registerSetting(const std::string &name, const Variant &value) { s_settingsMap[name] = value; } -Variant PostProcessSettings::readValue(const string &name) const { +Variant PostProcessSettings::defaultValue(const std::string &name) { + auto it = s_settingsMap.find(name); + if(it != s_settingsMap.end()) { + return it->second; + } + + return Variant(); +} + +Variant PostProcessSettings::readValue(const std::string &name) const { auto it = m_currentValues.find(name); if(it != m_currentValues.end()) { return it->second; } + return Variant(); } -void PostProcessSettings::writeValue(const string &name, const Variant &value) { +void PostProcessSettings::writeValue(const std::string &name, const Variant &value) { m_currentValues[name] = value; } -void PostProcessSettings::lerp(const PostProcessSettings &settings, float t) { - for(auto &it : settings.m_currentValues) { - size_t pos = it.first.find("_override"); - if(pos != std::string::npos) { - if(it.second.toBool()) { - const string key(it.first.substr(0, pos)); - const Variant value1 = m_currentValues[key]; - auto v = settings.m_currentValues.find(key); - if(v != settings.m_currentValues.end()) { - Variant value2 = v->second; - switch(value1.type()) { - case MetaType::INTEGER: m_currentValues[key] = MIX(value1.toInt(), value2.toInt(), t); break; - case MetaType::FLOAT: m_currentValues[key] = MIX(value1.toFloat(), value2.toFloat(), t); break; - case MetaType::VECTOR2: m_currentValues[key] = MIX(value1.toVector2(), value2.toVector2(), t); break; - case MetaType::VECTOR3: m_currentValues[key] = MIX(value1.toVector3(), value2.toVector3(), t); break; - case MetaType::VECTOR4: m_currentValues[key] = MIX(value1.toVector4(), value2.toVector4(), t); break; - default: break; - } - } - } - } - } -} - void PostProcessSettings::resetDefault() { - m_currentValues.insert(s_settingsMap.begin(), s_settingsMap.end()); + m_currentValues.clear(); } diff --git a/engine/src/components/world.cpp b/engine/src/components/world.cpp index 2cefed218..28f92f731 100644 --- a/engine/src/components/world.cpp +++ b/engine/src/components/world.cpp @@ -51,14 +51,14 @@ void World::makeDirty() { /*! Create an empty new Scene at runtime with the given \a name. */ -Scene *World::createScene(const string &name) { +Scene *World::createScene(const std::string &name) { return Engine::objectCreate(name, this); } /*! Loads the scene stored in the .map files by the it's \a path. \note The previous scenes will be not unloaded in the case of an \a additive flag is true. */ -Scene *World::loadScene(const string &path, bool additive) { +Scene *World::loadScene(const std::string &path, bool additive) { Map *map = Engine::loadResource(path); if(map) { Scene *scene = map->scene(); diff --git a/engine/src/pipelinecontext.cpp b/engine/src/pipelinecontext.cpp index 9b5f3a5c5..2afd82db8 100644 --- a/engine/src/pipelinecontext.cpp +++ b/engine/src/pipelinecontext.cpp @@ -43,10 +43,8 @@ PipelineContext::PipelineContext() : m_world(nullptr), m_pipeline(nullptr), m_buffer(Engine::objectCreate()), - m_postProcessSettings(new PostProcessSettings), m_finalMaterial(nullptr), m_defaultTarget(Engine::objectCreate()), - m_radianceMap(Engine::objectCreate(gRadianceMap)), m_camera(nullptr), m_width(64), m_height(64), @@ -59,19 +57,6 @@ PipelineContext::PipelineContext() : setPipeline(Engine::loadResource(Engine::value(".pipeline", ".embedded/Deferred.pipeline").toString())); - m_radianceMap->setFormat(Texture::RGBA8); - m_radianceMap->resize(2, 2); - auto &surface = m_radianceMap->surface(0); - - uint32_t v = 0x00000000;//0x00352400; - uint32_t *dst = reinterpret_cast(surface[0].data()); - for(uint8_t i = 0; i < 4; i++) { - *dst = v; - dst++; - } - - m_buffer->setGlobalTexture(m_radianceMap->name().c_str(), m_radianceMap); - uint32_t size = Texture::maxTextureSize(); m_buffer->setGlobalValue("shadow.pageSize", Vector4(1.0f / size, 1.0f / size, size, size)); } @@ -189,13 +174,11 @@ void PipelineContext::analizeGraph() { for(auto it : RenderSystem::renderables()) { if(it->isEnabled()) { Actor *actor = it->actor(); - if(actor && actor->isEnabledInHierarchy()) { - if((actor->world() == m_world)) { - if(update) { - it->update(); - } - m_sceneComponents.push_back(it); + if(actor && (actor->world() == m_world) && actor->isEnabledInHierarchy()) { + if(update) { + it->update(); } + m_sceneComponents.push_back(it); } } } @@ -231,26 +214,21 @@ void PipelineContext::analizeGraph() { } // Add Post process volumes - m_postProcessSettings->resetDefault(); - + m_culledPostProcessSettings.clear(); for(auto it : RenderSystem::postProcessVolumes()) { if(it->isEnabled()) { Actor *actor = it->actor(); - if(actor && actor->isEnabledInHierarchy()) { - Scene *scene = actor->scene(); - if(scene && scene->parent() == m_world) { - if(!it->unbound() && !it->bound().intersect(cameraTransform->worldPosition(), camera->nearPlane())) { - continue; - } - m_postProcessSettings->lerp(it->settings(), it->blendWeight()); + if(actor && (actor->world() == m_world) && actor->isEnabledInHierarchy()) { + if(!it->unbound() && !it->bound().intersect(cameraTransform->worldPosition(), camera->nearPlane())) { + continue; } + m_culledPostProcessSettings.push_back(std::make_pair(it->settings(), it->blendWeight())); } } } for(auto &it : m_renderTasks) { it->analyze(m_world); - it->setSettings(*m_postProcessSettings); } } /*! @@ -293,7 +271,7 @@ void PipelineContext::addTextureBuffer(Texture *texture) { /*! Returns a texture buffer based on its \a name. */ -Texture *PipelineContext::textureBuffer(const string &name) { +Texture *PipelineContext::textureBuffer(const std::string &name) { auto it = m_textureBuffers.find(name); if(it != m_textureBuffers.end()) { return it->second; @@ -332,7 +310,7 @@ void PipelineContext::setPipeline(Pipeline *pipeline) { if(m_pipeline) { for(int i = 0; i < m_pipeline->renderTasksCount(); i++) { - string taskName = m_pipeline->renderTaskName(i); + std::string taskName = m_pipeline->renderTaskName(i); PipelineTask *task = dynamic_cast(Engine::objectCreate(taskName, taskName, this)); if(task) { insertRenderTask(task); @@ -386,14 +364,14 @@ void PipelineContext::insertRenderTask(PipelineTask *task, PipelineTask *before) /*! Returns the list of rendering tasks associated with the pipeline context. */ -const list &PipelineContext::renderTasks() const { +const std::list &PipelineContext::renderTasks() const { return m_renderTasks; } /*! Returns a list of names of the global textures. */ -list PipelineContext::renderTextures() const { - list result; +std::list PipelineContext::renderTextures() const { + std::list result; for(auto &it : m_textureBuffers) { result.push_back(it.first); } @@ -403,7 +381,7 @@ list PipelineContext::renderTextures() const { /*! Draws the specified \a list of Renderable compoenents on the given \a layer and \a flags. */ -void PipelineContext::drawRenderers(const list &list, uint32_t layer, uint32_t flags) { +void PipelineContext::drawRenderers(const std::list &list, uint32_t layer, uint32_t flags) { uint32_t lastHash = 0; uint32_t lastSub = 0; Mesh *lastMesh = nullptr; @@ -448,21 +426,27 @@ void PipelineContext::drawRenderers(const list &list, uint32_t lay /*! Returns the list of scene components relevant for rendering. */ -list &PipelineContext::sceneComponents() { +std::list &PipelineContext::sceneComponents() { return m_sceneComponents; } /*! Returns the list of culled scene components based on frustum culling. */ -list &PipelineContext::culledComponents() { +std::list &PipelineContext::culledComponents() { return m_frustumCulling ? m_culledComponents : m_sceneComponents; } /*! Returns the list of scene lights relevant for rendering. */ -list &PipelineContext::sceneLights() { +std::list &PipelineContext::sceneLights() { return m_sceneLights; } +/*! + Returns the list of filtered scene post effect settings relevant for rendering. +*/ +std::list> &PipelineContext::culledPostEffectSettings() { + return m_culledPostProcessSettings; +} /*! Returns the currently set camera for rendering. */ @@ -473,7 +457,7 @@ Camera *PipelineContext::currentCamera() const { Filters out an incoming \a list which are not in the \a frustum. Returns filtered list. The output parameter returns a bounding \a box for filtered objects. */ -list PipelineContext::frustumCulling(const array &frustum, list &list, AABBox &box) { +std::list PipelineContext::frustumCulling(const std::array &frustum, std::list &list, AABBox &box) { box.extent = Vector3(-1.0f); Plane pl[6]; diff --git a/engine/src/pipelinetask.cpp b/engine/src/pipelinetask.cpp index 72ba5905b..704344eb2 100644 --- a/engine/src/pipelinetask.cpp +++ b/engine/src/pipelinetask.cpp @@ -93,19 +93,6 @@ Texture *PipelineTask::output(int index) { } return nullptr; } -/*! - Changes a property \a value with given \a name. -*/ -void PipelineTask::setProperty(const std::string &name, const Variant &value) { - A_UNUSED(name); - A_UNUSED(value); -} -/*! - A callback to react on chage of \a settings. -*/ -void PipelineTask::setSettings(const PostProcessSettings &settings) { - A_UNUSED(settings); -} /*! Sets task to \a enable or disable. The disabled effect will not be executed. diff --git a/engine/src/pipelinetasks/ambientocclusion.cpp b/engine/src/pipelinetasks/ambientocclusion.cpp index 6e06eca34..78a67d01b 100644 --- a/engine/src/pipelinetasks/ambientocclusion.cpp +++ b/engine/src/pipelinetasks/ambientocclusion.cpp @@ -1,7 +1,5 @@ #include "pipelinetasks/ambientocclusion.h" -#include "engine.h" - #include "components/private/postprocessorsettings.h" #include "resources/material.h" @@ -10,8 +8,6 @@ #include "pipelinecontext.h" #include "commandbuffer.h" -#include "amath.h" - #include #define KERNEL_SIZE 16 @@ -19,27 +15,27 @@ namespace { const char *ambientOcclusion("graphics.ambientocclusion"); - const char *ambientRadius("ambientOcclusion/Radius"); - const char *ambientBias("ambientOcclusion/Bias"); - const char *ambientPower("ambientOcclusion/Power"); + const char *ambientRadius("ambientOcclusion/radius"); + const char *ambientBias("ambientOcclusion/bias"); + const char *ambientPower("ambientOcclusion/power"); }; AmbientOcclusion::AmbientOcclusion() : m_radius(0.2f), m_bias(0.025f), m_power(2.0f), - m_noiseTexture(Engine::objectCreate("noiseTexture")), - m_ssaoTarget(Engine::objectCreate("ssaoTarget")), - m_blurTarget(Engine::objectCreate("ssaoBlurTarget")), - m_combineTarget(Engine::objectCreate("ssaoCombineTarget")), + m_noiseTexture(Engine::objectCreate("aoNoiseTexture")), + m_aoTexture(Engine::objectCreate("aoOcclusion")), + m_blurTexture(Engine::objectCreate("aoBlur")), + m_aoTarget(Engine::objectCreate("aoTarget")), + m_blurTarget(Engine::objectCreate("aoBlurTarget")), m_occlusion(nullptr), - m_blur(nullptr), - m_combine(nullptr) { + m_blur(nullptr) { setName("AmbientOcclusion"); m_inputs.push_back("In"); - m_outputs.push_back(make_pair("Result", nullptr)); + m_outputs.push_back(std::make_pair("Result", nullptr)); Engine::setValue(ambientOcclusion, true); @@ -64,25 +60,20 @@ AmbientOcclusion::AmbientOcclusion() : ptr[i].normalize(); } - Texture *ssaoTexture = Engine::objectCreate("SSAO"); - ssaoTexture->setFormat(Texture::R8); - ssaoTexture->setFlags(Texture::Render); - // Temporary - m_outputs.push_back(make_pair(ssaoTexture->name(), ssaoTexture)); + m_aoTexture->setFormat(Texture::R8); + m_aoTexture->setFlags(Texture::Render); - Texture *blurTexture = Engine::objectCreate("SSAOBlur"); - blurTexture->setFormat(Texture::R8); - blurTexture->setFlags(Texture::Render); - // Temporary - m_outputs.push_back(make_pair(blurTexture->name(), blurTexture)); + m_aoTarget->setColorAttachment(0, m_aoTexture); - m_ssaoTarget->setColorAttachment(0, ssaoTexture); - m_blurTarget->setColorAttachment(0, blurTexture); + m_blurTexture->setFormat(Texture::R8); + m_blurTexture->setFlags(Texture::Render); + + m_blurTarget->setColorAttachment(0, m_blurTexture); { - Material *mtl = Engine::loadResource(".embedded/AmbientOcclusion.shader"); - if(mtl) { - m_occlusion = mtl->createInstance(); + Material *material = Engine::loadResource(".embedded/SSAO.shader"); + if(material) { + m_occlusion = material->createInstance(); Vector3 samplesKernel[KERNEL_SIZE]; for(int32_t i = 0; i < KERNEL_SIZE; i++) { @@ -99,73 +90,103 @@ AmbientOcclusion::AmbientOcclusion() : } m_occlusion->setVector3("samplesKernel", samplesKernel, KERNEL_SIZE); m_occlusion->setTexture("noiseMap", m_noiseTexture); + + m_occlusion->setFloat("radius", &m_radius); + m_occlusion->setFloat("bias", &m_bias); + m_occlusion->setFloat("power", &m_power); } } { - Material *mtl = Engine::loadResource(".embedded/BlurOcclusion.shader"); - if(mtl) { - m_blur = mtl->createInstance(); - m_blur->setTexture("ssaoSample", ssaoTexture); - } - } - { - Material *mtl = Engine::loadResource(".embedded/CombineOcclusion.shader"); - if(mtl) { - m_combine = mtl->createInstance(); - m_combine->setTexture("ssaoMap", blurTexture); + Material *material = Engine::loadResource(".embedded/BlurOcclusion.shader"); + if(material) { + m_blur = material->createInstance(); + m_blur->setTexture("aoMap", m_aoTexture); } } + + m_outputs.push_back(make_pair(m_blurTexture->name(), m_blurTexture)); } AmbientOcclusion::~AmbientOcclusion() { m_noiseTexture->deleteLater(); + m_aoTexture->deleteLater(); + m_blurTexture->deleteLater(); + + m_aoTarget->deleteLater(); + m_blurTarget->deleteLater(); } void AmbientOcclusion::exec(PipelineContext &context) { CommandBuffer *buffer = context.buffer(); + + float radius = PostProcessSettings::defaultValue(ambientRadius).toFloat(); + for(auto pool : context.culledPostEffectSettings()) { + const PostProcessSettings *settings = pool.first; + Variant value = settings->readValue(ambientRadius); + if(value.isValid()) { + radius = MIX(m_radius, value.toFloat(), pool.second); + } + } + if(radius != m_radius) { + m_radius = radius; + if(m_occlusion) { + m_occlusion->setFloat("radius", &m_radius); + } + } + + float bias = PostProcessSettings::defaultValue(ambientBias).toFloat(); + for(auto pool : context.culledPostEffectSettings()) { + Variant value = pool.first->readValue(ambientBias); + if(value.isValid()) { + bias = MIX(bias, value.toFloat(), pool.second); + } + } + if(bias != m_radius) { + m_bias = bias; + if(m_occlusion) { + m_occlusion->setFloat("bias", &m_bias); + } + } + + float power = PostProcessSettings::defaultValue(ambientPower).toFloat(); + for(auto pool : context.culledPostEffectSettings()) { + Variant value = pool.first->readValue(ambientPower); + if(value.isValid()) { + power = MIX(power, value.toFloat(), pool.second); + } + } + if(power != m_power) { + m_power = power; + if(m_occlusion) { + m_occlusion->setFloat("power", &m_power); + } + } + buffer->beginDebugMarker("AmbientOcclusion"); if(m_occlusion) { - buffer->setViewport(0, 0, m_outputs.front().second->width(), m_outputs.front().second->height()); + buffer->setViewport(0, 0, m_aoTexture->width(), m_aoTexture->height()); - buffer->setRenderTarget(m_ssaoTarget); + buffer->setRenderTarget(m_aoTarget); buffer->drawMesh(PipelineContext::defaultPlane(), 0, CommandBuffer::UI, *m_occlusion); } if(m_blur) { - buffer->setViewport(0, 0, m_outputs.back().second->width(), m_outputs.back().second->height()); + buffer->setViewport(0, 0, m_blurTexture->width(), m_blurTexture->height()); buffer->setRenderTarget(m_blurTarget); buffer->drawMesh(PipelineContext::defaultPlane(), 0, CommandBuffer::UI, *m_blur); } - if(m_combine) { - Texture *texture = m_combineTarget->colorAttachment(0); - if(texture) { - buffer->setViewport(0, 0, texture->width(), texture->height()); - } - - buffer->setRenderTarget(m_combineTarget); - buffer->drawMesh(PipelineContext::defaultPlane(), 0, CommandBuffer::UI, *m_combine); - } - buffer->endDebugMarker(); } -void AmbientOcclusion::setSettings(const PostProcessSettings &settings) { - m_radius = settings.readValue(ambientRadius).toFloat(); - m_bias = settings.readValue(ambientBias).toFloat(); - m_power = settings.readValue(ambientPower).toFloat(); +void AmbientOcclusion::resize(int32_t width, int32_t height) { + PipelineTask::resize(width, height); - if(m_occlusion) { - m_occlusion->setFloat("radius", &m_radius); - m_occlusion->setFloat("bias", &m_bias); - m_occlusion->setFloat("power", &m_power); - } + m_aoTexture->resize(width, height); } void AmbientOcclusion::setInput(int index, Texture *texture) { - m_combineTarget->setColorAttachment(0, texture); - m_outputs.front().second = texture; } diff --git a/engine/src/pipelinetasks/antialiasing.cpp b/engine/src/pipelinetasks/antialiasing.cpp index a4a0442bf..605138e8c 100644 --- a/engine/src/pipelinetasks/antialiasing.cpp +++ b/engine/src/pipelinetasks/antialiasing.cpp @@ -13,8 +13,9 @@ namespace { }; AntiAliasing::AntiAliasing() : + m_resultTexture(Engine::objectCreate("antiAliasing")), m_resultTarget(Engine::objectCreate()), - m_material(nullptr) { + m_resultMaterial(nullptr) { setName("AntiAliasing"); @@ -24,32 +25,35 @@ AntiAliasing::AntiAliasing() : Material *material = Engine::loadResource(".embedded/FXAA.shader"); if(material) { - m_material = material->createInstance(); + m_resultMaterial = material->createInstance(); } - Texture *resultTexture = Engine::objectCreate("AntiAliasing"); - resultTexture->setFormat(Texture::RGB10A2); - resultTexture->setFlags(Texture::Render); - m_outputs.push_back(std::make_pair("Result", resultTexture)); + m_resultTexture->setFormat(Texture::RGB10A2); + m_resultTexture->setFlags(Texture::Render); - m_resultTarget->setColorAttachment(0, resultTexture); + m_resultTarget->setColorAttachment(0, m_resultTexture); + m_outputs.push_back(std::make_pair(m_resultTexture->name(), m_resultTexture)); +} + +AntiAliasing::~AntiAliasing() { + m_resultTarget->deleteLater(); } void AntiAliasing::exec(PipelineContext &context) { - if(m_material) { + if(m_resultMaterial) { CommandBuffer *buffer = context.buffer(); buffer->beginDebugMarker("AntiAliasing"); buffer->setRenderTarget(m_resultTarget); - buffer->drawMesh(PipelineContext::defaultPlane(), 0, CommandBuffer::UI, *m_material); + buffer->drawMesh(PipelineContext::defaultPlane(), 0, CommandBuffer::UI, *m_resultMaterial); buffer->endDebugMarker(); } } void AntiAliasing::setInput(int index, Texture *texture) { - if(m_material) { - m_material->setTexture("rgbMap", texture); + if(m_resultMaterial) { + m_resultMaterial->setTexture("rgbMap", texture); } } diff --git a/engine/src/pipelinetasks/bloom.cpp b/engine/src/pipelinetasks/bloom.cpp index 5f5fc889a..7358ff9d9 100644 --- a/engine/src/pipelinetasks/bloom.cpp +++ b/engine/src/pipelinetasks/bloom.cpp @@ -87,15 +87,41 @@ Bloom::Bloom() : m_bloomPasses[4].blurSize = 64.0f; m_inputs.push_back("In"); - m_outputs.push_back(make_pair("Result", nullptr)); + m_outputs.push_back(std::make_pair("Result", nullptr)); +} + +Bloom::~Bloom() { + for(int i = 0; i < BLOOM_PASSES; i++) { + m_bloomPasses[i].downTexture->deleteLater(); + m_bloomPasses[i].downTarget->deleteLater(); + + delete m_bloomPasses[i].downMaterial; + delete m_bloomPasses[i].blurMaterialH; + delete m_bloomPasses[i].blurMaterialV; + } + + m_resultTarget->deleteLater(); + m_blurTempTarget->deleteLater(); + + m_blurTempTexture->deleteLater(); } void Bloom::exec(PipelineContext &context) { CommandBuffer *buffer = context.buffer(); - Texture *texture(m_outputs.front().second); - m_bloomPasses[0].downMaterial->setTexture(rgbMap, texture); - m_resultTarget->setColorAttachment(0, texture); + float threshold = PostProcessSettings::defaultValue(bloomThreshold).toFloat(); + for(auto pool : context.culledPostEffectSettings()) { + Variant value = pool.first->readValue(bloomThreshold); + if(value.isValid()) { + threshold = MIX(threshold, value.toFloat(), pool.second); + } + } + if(threshold != m_threshold) { + m_threshold = threshold; + for(uint8_t i = 0; i < BLOOM_PASSES; i++) { + m_bloomPasses[i].downMaterial->setFloat("threshold", &m_threshold); + } + } buffer->beginDebugMarker("Bloom"); @@ -109,7 +135,7 @@ void Bloom::exec(PipelineContext &context) { buffer->drawMesh(PipelineContext::defaultPlane(), 0, CommandBuffer::UI, *m_bloomPasses[i].downMaterial); } - buffer->setViewport(0, 0, texture->width(), texture->height()); + buffer->setViewport(0, 0, m_width, m_height); buffer->endDebugMarker(); @@ -160,16 +186,11 @@ void Bloom::resize(int32_t width, int32_t height) { PipelineTask::resize(width, height); } -void Bloom::setSettings(const PostProcessSettings &settings) { - m_threshold = settings.readValue(bloomThreshold).toFloat(); - - for(uint8_t i = 0; i < BLOOM_PASSES; i++) { - m_bloomPasses[i].downMaterial->setFloat("threshold", &m_threshold); - } -} - void Bloom::setInput(int index, Texture *source) { m_outputs.front().second = source; + + m_bloomPasses[0].downMaterial->setTexture(rgbMap, source); + m_resultTarget->setColorAttachment(0, source); } void Bloom::generateKernel(float radius, int32_t steps, float *points) { diff --git a/engine/src/pipelinetasks/deferredlighting.cpp b/engine/src/pipelinetasks/deferredlighting.cpp index e39db1a91..1b5b4bc0a 100644 --- a/engine/src/pipelinetasks/deferredlighting.cpp +++ b/engine/src/pipelinetasks/deferredlighting.cpp @@ -14,14 +14,14 @@ #include "commandbuffer.h" namespace { - const char *uniPosition = "position"; - const char *uniDirection = "direction"; - const char *uniRight = "right"; - const char *uniUp = "up"; + const char *gUniPosition("position"); + const char *gUniDirection("direction"); + const char *gUniRight("right"); + const char *gUniUp("up"); } DeferredLighting::DeferredLighting() : - m_lightPass(Engine::objectCreate("lightPass")) { + m_lightPass(Engine::objectCreate("lightPass")) { setName("DeferredLighting"); @@ -29,12 +29,17 @@ DeferredLighting::DeferredLighting() : m_outputs.push_back(std::make_pair("Result", nullptr)); } +DeferredLighting::~DeferredLighting() { + m_lightPass->deleteLater(); +} + void DeferredLighting::exec(PipelineContext &context) { CommandBuffer *buffer = context.buffer(); + buffer->beginDebugMarker("DeferredLighting"); buffer->setRenderTarget(m_lightPass); - // Light pass + for(auto it : context.sceneLights()) { BaseLight *light = static_cast(it); @@ -55,10 +60,10 @@ void DeferredLighting::exec(PipelineContext &context) { Vector3 up(m.rotation() * Vector3(0.0f, 1.0f, 0.0f)); instance->setTransform(Matrix4(position, Quaternion(), Vector3(d))); - instance->setVector3(uniPosition, &position); - instance->setVector3(uniDirection, &direction); - instance->setVector3(uniRight, &right); - instance->setVector3(uniUp, &up); + instance->setVector3(gUniPosition, &position); + instance->setVector3(gUniDirection, &direction); + instance->setVector3(gUniRight, &right); + instance->setVector3(gUniUp, &up); } } break; case BaseLight::PointLight: { @@ -72,8 +77,8 @@ void DeferredLighting::exec(PipelineContext &context) { Vector3 direction(m.rotation() * Vector3(0.0f, 1.0f, 0.0f)); instance->setTransform(Matrix4(position, Quaternion(), Vector3(d))); - instance->setVector3(uniPosition, &position); - instance->setVector3(uniDirection, &direction); + instance->setVector3(gUniPosition, &position); + instance->setVector3(gUniDirection, &direction); } } break; case BaseLight::SpotLight: { @@ -95,8 +100,8 @@ void DeferredLighting::exec(PipelineContext &context) { Vector3(radius * 2.0f, radius * 2.0f, distance)); instance->setTransform(mat); - instance->setVector3(uniPosition, &position); - instance->setVector3(uniDirection, &direction); + instance->setVector3(gUniPosition, &position); + instance->setVector3(gUniDirection, &direction); } } break; case BaseLight::DirectLight: { @@ -105,9 +110,9 @@ void DeferredLighting::exec(PipelineContext &context) { auto instance = light->material(); if(instance) { Transform *t = light->transform(); - Vector3 direction(t->worldQuaternion() * Vector3(0.0f, 0.0f, 1.0f)); + m_sunDirection = Vector3(t->worldQuaternion() * Vector3(0.0f, 0.0f, 1.0f)); - instance->setVector3(uniDirection, &direction); + instance->setVector3(gUniDirection, &m_sunDirection); } } break; default: break; @@ -121,5 +126,5 @@ void DeferredLighting::exec(PipelineContext &context) { void DeferredLighting::setInput(int index, Texture *texture) { m_lightPass->setColorAttachment(0, texture); - m_outputs.back().second = texture; + m_outputs.front().second = texture; } diff --git a/engine/src/pipelinetasks/gbuffer.cpp b/engine/src/pipelinetasks/gbuffer.cpp index b40ab427f..36662c0de 100644 --- a/engine/src/pipelinetasks/gbuffer.cpp +++ b/engine/src/pipelinetasks/gbuffer.cpp @@ -7,8 +7,6 @@ #include "pipelinecontext.h" #include "commandbuffer.h" -#define GBUFFER "gBuffer" - #define DEPTH_MAP "depthMap" #define G_EMISSIVE "emissiveMap" #define G_NORMALS "normalsMap" @@ -16,7 +14,7 @@ #define G_PARAMS "paramsMap" GBuffer::GBuffer() : - m_gbuffer(Engine::objectCreate(GBUFFER)) { + m_gbuffer(Engine::objectCreate("gBuffer")) { setName("GBuffer"); @@ -64,7 +62,7 @@ void GBuffer::exec(PipelineContext &context) { context.cameraReset(); buffer->setRenderTarget(m_gbuffer); - buffer->clearRenderTarget(true, context.currentCamera()->color()); + buffer->clearRenderTarget(); context.drawRenderers(context.culledComponents(), CommandBuffer::DEFAULT); diff --git a/engine/src/pipelinetasks/indirect.cpp b/engine/src/pipelinetasks/indirect.cpp new file mode 100644 index 000000000..2be061c70 --- /dev/null +++ b/engine/src/pipelinetasks/indirect.cpp @@ -0,0 +1,127 @@ +#include "pipelinetasks/indirect.h" + +#include "components/private/postprocessorsettings.h" + +#include "components/world.h" +#include "components/camera.h" + +#include "resources/material.h" +#include "resources/rendertarget.h" + +#include "pipelinecontext.h" +#include "commandbuffer.h" + +namespace { + const char *environmentMap("deferredIndirect/environmentMap"); + const char *iblMap("iblMap"); +}; + +DeferredIndirect::DeferredIndirect() : + m_iblMaterial(nullptr), + m_cameraTexture(Engine::objectCreate("cameraTexture")), + m_iblTexture(nullptr), + m_iblTarget(Engine::objectCreate()) { + + setName("Indirect"); + + m_inputs.push_back("In"); + m_inputs.push_back("Normals"); + m_inputs.push_back("Params"); + m_inputs.push_back("Depth"); + m_inputs.push_back("SSAO"); + m_inputs.push_back("SSLR"); + + m_outputs.push_back(std::make_pair("Result", nullptr)); + + PostProcessSettings::registerSetting(environmentMap, Variant::fromValue(m_iblTexture)); + + // Building camera background color texture cubemap + m_cameraTexture->setFormat(Texture::RGBA8); + m_cameraTexture->setFiltering(Texture::Bilinear); + m_cameraTexture->resize(1, 1); + m_cameraTexture->clear(); + + Texture::Surface surface; + surface.push_back({0, 0, 0, 255}); + + for(int i = 0; i < 6; i++) { + m_cameraTexture->addSurface(surface); + } + + // Building material instance + Material *mtl = Engine::loadResource(".embedded/IblReflections.shader"); + if(mtl) { + m_iblMaterial = mtl->createInstance(); + m_iblMaterial->setTexture(iblMap, m_cameraTexture); + } + +} + +void DeferredIndirect::analyze(World *world) { + Camera *camera = Camera::current(); + if(camera) { + Vector4 color(camera->color()); + if(color != m_cameraColor) { + m_cameraColor = color; + + for(int i = 0; i < 6; i++) { + Texture::Surface &surface = m_cameraTexture->surface(i); + surface[0][0] = uint8_t(m_cameraColor.x * 255); + surface[0][1] = uint8_t(m_cameraColor.y * 255); + surface[0][2] = uint8_t(m_cameraColor.z * 255); + surface[0][3] = uint8_t(m_cameraColor.w * 255); + } + m_cameraTexture->setDirty(); + } + } + + +} + +void DeferredIndirect::exec(PipelineContext &context) { + CommandBuffer *buffer = context.buffer(); + + for(auto it : context.culledPostEffectSettings()) { + Texture *texture = it.first->readValue(environmentMap).value(); + if(texture != m_iblTexture) { + m_iblTexture = texture; + if(m_iblMaterial) { + m_iblMaterial->setTexture(iblMap, m_iblTexture ? m_iblTexture : m_cameraTexture); + } + } + } + + buffer->beginDebugMarker("ReflectionIndirect"); + if(m_iblMaterial) { + buffer->setRenderTarget(m_iblTarget); + buffer->drawMesh(PipelineContext::defaultPlane(), 0, CommandBuffer::UI, *m_iblMaterial); + } + buffer->endDebugMarker(); +} + +void DeferredIndirect::setInput(int index, Texture *texture) { + if(m_iblMaterial) { + switch(index) { + case 0: { // In + m_iblTarget->setColorAttachment(0, texture); + m_outputs.front().second = texture; + } break; + case 1: { // normalsMap + m_iblMaterial->setTexture("normalsMap", texture); + } break; + case 2: { // paramsMap + m_iblMaterial->setTexture("paramsMap", texture); + } break; + case 3: { // depthMap + m_iblMaterial->setTexture("depthMap", texture); + } break; + case 4: { // aoMap + m_iblMaterial->setTexture("aoMap", texture); + } break; + case 5: { // sslrMap + m_iblMaterial->setTexture("sslrMap", texture); + } break; + default: break; + } + } +} diff --git a/engine/src/pipelinetasks/reflections.cpp b/engine/src/pipelinetasks/reflections.cpp index 74fd687f0..3d114a33b 100644 --- a/engine/src/pipelinetasks/reflections.cpp +++ b/engine/src/pipelinetasks/reflections.cpp @@ -1,9 +1,5 @@ #include "pipelinetasks/reflections.h" -#include "engine.h" - -#include "components/world.h" - #include "resources/material.h" #include "resources/rendertarget.h" @@ -13,99 +9,68 @@ #include "amath.h" namespace { - const char *reflections("graphics.reflections"); + const char *gReflections("graphics.reflections"); }; Reflections::Reflections() : - m_slrMaterial(nullptr), - m_combineMaterial(nullptr), - m_environmentTexture(nullptr), - m_slrTarget(Engine::objectCreate()), - m_combineTarget(Engine::objectCreate()) { + m_sslrMaterial(nullptr), + m_sslrTexture(Engine::objectCreate("localReflections")), + m_sslrTarget(Engine::objectCreate()) { setName("Reflections"); - m_inputs.push_back("normalsMap"); - m_inputs.push_back("paramsMap"); - m_inputs.push_back("emissiveMap"); - m_inputs.push_back("depthMap"); + Engine::setValue(gReflections, true); - Engine::setValue(reflections, true); + m_inputs.push_back("In"); + m_inputs.push_back("LastFrame"); + m_inputs.push_back("Normals"); + m_inputs.push_back("Params"); + m_inputs.push_back("Depth"); m_outputs.push_back(std::make_pair("Result", nullptr)); + m_outputs.push_back(std::make_pair(m_sslrTexture->name(), m_sslrTexture)); - Texture *slrTexture(Engine::objectCreate("localReflections")); - slrTexture->setFormat(Texture::RGB10A2); - slrTexture->setFlags(Texture::Render); - m_outputs.push_back(std::make_pair(slrTexture->name(), slrTexture)); - - m_slrTarget->setColorAttachment(0, slrTexture); + m_sslrTexture->setFormat(Texture::RGB10A2); + m_sslrTexture->setFlags(Texture::Render); - Material *material = Engine::loadResource(".embedded/IblReflections.shader"); - if(material) { - m_combineMaterial = material->createInstance(); - m_combineMaterial->setTexture("slrMap", slrTexture); - m_combineMaterial->setTexture("environmentMap", m_environmentTexture); - } + m_sslrTarget->setColorAttachment(0, m_sslrTexture); - material = Engine::loadResource(".embedded/SSLR.shader"); + Material *material = Engine::loadResource(".embedded/SSLR.shader"); if(material) { - m_slrMaterial = material->createInstance(); + m_sslrMaterial = material->createInstance(); } } void Reflections::exec(PipelineContext &context) { CommandBuffer *buffer = context.buffer(); - buffer->beginDebugMarker("Reflections"); - if(m_slrMaterial) { // sslr step - buffer->setRenderTarget(m_slrTarget); - - buffer->drawMesh(PipelineContext::defaultPlane(), 0, CommandBuffer::UI, *m_slrMaterial); + buffer->beginDebugMarker("ScreenReflections"); + if(m_sslrMaterial) { + buffer->setRenderTarget(m_sslrTarget); + buffer->drawMesh(PipelineContext::defaultPlane(), 0, CommandBuffer::UI, *m_sslrMaterial); } - - if(m_combineMaterial) { // combine step - buffer->setRenderTarget(m_combineTarget); - - buffer->drawMesh(PipelineContext::defaultPlane(), 0, CommandBuffer::UI, *m_combineMaterial); - } - buffer->endDebugMarker(); } void Reflections::setInput(int index, Texture *texture) { - switch(index) { - case 0: { // normalsMap - if(m_slrMaterial) { - m_slrMaterial->setTexture("normalsMap", texture); - } - if(m_combineMaterial) { - m_combineMaterial->setTexture("normalsMap", texture); - } - } break; - case 1: { // paramsMap - if(m_slrMaterial) { - m_slrMaterial->setTexture("paramsMap", texture); - } - if(m_combineMaterial) { - m_combineMaterial->setTexture("paramsMap", texture); - } - } break; - case 2: { // emissiveMap - if(m_slrMaterial) { - m_slrMaterial->setTexture("emissiveMap", texture); - } - m_combineTarget->setColorAttachment(0, texture); - m_outputs.front().second = texture; - } break; - case 3: { // depthMap - if(m_slrMaterial) { - m_slrMaterial->setTexture("depthMap", texture); - } - if(m_combineMaterial) { - m_combineMaterial->setTexture("depthMap", texture); - } - } break; - default: break; + if(m_sslrMaterial) { + switch(index) { + case 0: { + m_outputs.front().second = texture; + } break; + case 1: { // lastFrame + m_sslrMaterial->setTexture("emissiveMap", texture); + } break; + case 2: { // normalsMap + m_sslrMaterial->setTexture("normalsMap", texture); + } break; + case 3: { // paramsMap + m_sslrMaterial->setTexture("paramsMap", texture); + } break; + case 4: { // depthMap + m_sslrMaterial->setTexture("depthMap", texture); + } break; + default: break; + } } } diff --git a/engine/src/pipelinetasks/shadowmap.cpp b/engine/src/pipelinetasks/shadowmap.cpp index ffcae27a5..46041dea7 100644 --- a/engine/src/pipelinetasks/shadowmap.cpp +++ b/engine/src/pipelinetasks/shadowmap.cpp @@ -25,17 +25,17 @@ #define SPLIT_WEIGHT 0.95f // 0.75f -#define SHADOW_MAP "shadowMap" - namespace { const char *shadowmap("graphics.shadowmap"); - const char *uniLod = "lod"; - const char *uniMatrix = "matrix"; - const char *uniTiles = "tiles"; - const char *uniBias = "bias"; - const char *uniPlaneDistance = "planeDistance"; - const char *uniShadows = "shadows"; + const char *shadowMap("shadowMap"); + + const char *uniLod("lod"); + const char *uniMatrix("matrix"); + const char *uniTiles("tiles"); + const char *uniBias("bias"); + const char *uniPlaneDistance("planeDistance"); + const char *uniShadows("shadows"); }; ShadowMap::ShadowMap() : @@ -64,6 +64,7 @@ ShadowMap::ShadowMap() : void ShadowMap::exec(PipelineContext &context) { CommandBuffer *buffer = context.buffer(); + buffer->beginDebugMarker("ShadowMap"); cleanShadowCache(); @@ -144,7 +145,7 @@ void ShadowMap::areaLightUpdate(PipelineContext &context, AreaLight *light, std: instance->setMatrix4(uniMatrix, matrix, SIDES); instance->setVector4(uniTiles, tiles, SIDES); instance->setVector4(uniBias, &bias); - instance->setTexture(SHADOW_MAP, shadowTarget->depthAttachment()); + instance->setTexture(shadowMap, shadowTarget->depthAttachment()); } } @@ -190,6 +191,9 @@ void ShadowMap::directLightUpdate(PipelineContext &context, DirectLight *light, Matrix4 matrix[MAX_LODS]; buffer->setRenderTarget(shadowTarget); + buffer->enableScissor(x[0], y[0], x[MAX_LODS-1] + w[MAX_LODS-1], y[MAX_LODS-1] + h[MAX_LODS-1]); + buffer->clearRenderTarget(); + for(int32_t lod = 0; lod < MAX_LODS; lod++) { float dist = distance[lod]; auto points = Camera::frustumCorners(orthographic, sigma, ratio, cameraPos, cameraRot, nearPlane, dist); @@ -198,7 +202,7 @@ void ShadowMap::directLightUpdate(PipelineContext &context, DirectLight *light, AABBox box; box.setBox(points.data(), 8); - box *= rot.rotation(); + box *= lightRot; AABBox bb; auto corners = Camera::frustumCorners(true, box.extent.y * 2.0f, 1.0f, box.center, lightRot, -FLT_MAX, FLT_MAX); @@ -221,9 +225,6 @@ void ShadowMap::directLightUpdate(PipelineContext &context, DirectLight *light, static_cast(w[lod]) / pageSize, static_cast(h[lod]) / pageSize); - buffer->enableScissor(x[lod], y[lod], w[lod], h[lod]); - buffer->clearRenderTarget(); - buffer->setViewProjection(view, crop); buffer->setViewport(x[lod], y[lod], w[lod], h[lod]); @@ -246,7 +247,7 @@ void ShadowMap::directLightUpdate(PipelineContext &context, DirectLight *light, instance->setVector4(uniTiles, tiles, MAX_LODS); instance->setVector4(uniBias, &bias); instance->setVector4(uniPlaneDistance, &planeDistance); - instance->setTexture(SHADOW_MAP, shadowTarget->depthAttachment()); + instance->setTexture(shadowMap, shadowTarget->depthAttachment()); } } @@ -303,7 +304,7 @@ void ShadowMap::pointLightUpdate(PipelineContext &context, PointLight *light, st instance->setMatrix4(uniMatrix, matrix, SIDES); instance->setVector4(uniTiles, tiles, SIDES); instance->setVector4(uniBias, &bias); - instance->setTexture(SHADOW_MAP, shadowTarget->depthAttachment()); + instance->setTexture(shadowMap, shadowTarget->depthAttachment()); } } @@ -355,7 +356,7 @@ void ShadowMap::spotLightUpdate(PipelineContext &context, SpotLight *light, std: instance->setMatrix4(uniMatrix, &matrix); instance->setVector4(uniTiles, &tiles); instance->setVector4(uniBias, &bias); - instance->setTexture(SHADOW_MAP, shadowTarget->depthAttachment()); + instance->setTexture(shadowMap, shadowTarget->depthAttachment()); } } diff --git a/engine/src/pipelinetasks/translucent.cpp b/engine/src/pipelinetasks/translucent.cpp index ed2aca845..867eeb295 100644 --- a/engine/src/pipelinetasks/translucent.cpp +++ b/engine/src/pipelinetasks/translucent.cpp @@ -1,10 +1,6 @@ #include "pipelinetasks/translucent.h" -#include "components/actor.h" -#include "components/transform.h" - #include "resources/rendertarget.h" -#include "resources/mesh.h" #include "pipelinecontext.h" #include "commandbuffer.h" @@ -18,27 +14,29 @@ Translucent::Translucent() : m_inputs.push_back("Depth"); m_outputs.push_back(std::make_pair("Result", nullptr)); - } void Translucent::exec(PipelineContext &context) { CommandBuffer *buffer = context.buffer(); - buffer->beginDebugMarker("Translucent Pass"); + + buffer->beginDebugMarker("TranslucentPass"); buffer->setRenderTarget(m_translucentPass); - // Transparent pass context.drawRenderers(context.culledComponents(), CommandBuffer::TRANSLUCENT); buffer->endDebugMarker(); } void Translucent::setInput(int index, Texture *texture) { - if(texture->depthBits() > 0) { - m_translucentPass->setDepthAttachment(texture); - } else { - m_translucentPass->setColorAttachment(0, texture); - - m_outputs.front().second = texture; + switch(index) { + case 0: { + m_translucentPass->setColorAttachment(0, texture); + m_outputs.front().second = texture; + } break; + case 1: { + m_translucentPass->setDepthAttachment(texture); + } break; + default: break; } } diff --git a/engine/src/systems/rendersystem.cpp b/engine/src/systems/rendersystem.cpp index fb7217a20..1fa4c62ec 100644 --- a/engine/src/systems/rendersystem.cpp +++ b/engine/src/systems/rendersystem.cpp @@ -26,6 +26,7 @@ #include "pipelinetasks/deferredlighting.h" #include "pipelinetasks/gbuffer.h" #include "pipelinetasks/reflections.h" +#include "pipelinetasks/indirect.h" #include "pipelinetasks/shadowmap.h" #include "pipelinetasks/translucent.h" @@ -75,6 +76,7 @@ RenderSystem::RenderSystem() : DeferredLighting::registerClassFactory(this); GBuffer::registerClassFactory(this); Reflections::registerClassFactory(this); + DeferredIndirect::registerClassFactory(this); ShadowMap::registerClassFactory(this); Translucent::registerClassFactory(this); } @@ -87,6 +89,7 @@ RenderSystem::~RenderSystem() { --m_registered; if(m_registered) { + // Core Renderable::unregisterClassFactory(this); MeshRender::unregisterClassFactory(this); TextRender::unregisterClassFactory(this); @@ -103,9 +106,24 @@ RenderSystem::~RenderSystem() { TileMapRender::unregisterClassFactory(this); + PostProcessVolume::unregisterClassFactory(this); + + // System CommandBuffer::unregisterClassFactory(this); - PostProcessVolume::unregisterClassFactory(this); + PipelineContext::unregisterClassFactory(this); + + // Pipline tasks + PipelineTask::unregisterClassFactory(this); + AmbientOcclusion::unregisterClassFactory(this); + AntiAliasing::unregisterClassFactory(this); + Bloom::unregisterClassFactory(this); + DeferredLighting::unregisterClassFactory(this); + GBuffer::unregisterClassFactory(this); + Reflections::unregisterClassFactory(this); + DeferredIndirect::unregisterClassFactory(this); + ShadowMap::unregisterClassFactory(this); + Translucent::unregisterClassFactory(this); } } diff --git a/modules/editor/shadertools/shaders/Shader.frag b/modules/editor/shadertools/shaders/Shader.frag index 1d39d0c38..16f9e81ee 100644 --- a/modules/editor/shadertools/shaders/Shader.frag +++ b/modules/editor/shadertools/shaders/Shader.frag @@ -21,9 +21,11 @@ layout(location = 9) in mat4 _modelView; layout(location = 0) out vec4 gbuffer0; #ifdef USE_GBUFFER - layout(location = 1) out vec4 gbuffer1; - layout(location = 2) out vec4 gbuffer2; - layout(location = 3) out vec4 gbuffer3; + #ifndef VISIBILITY_BUFFER + layout(location = 1) out vec4 gbuffer1; + layout(location = 2) out vec4 gbuffer2; + layout(location = 3) out vec4 gbuffer3; + #endif #endif #pragma uniforms @@ -53,11 +55,10 @@ void main(void) { #ifdef VISIBILITY_BUFFER gbuffer0 = _objectId; return; -#endif - +#else vec3 emit = Emissive * _color.xyz; -#ifdef USE_GBUFFER + #ifdef USE_GBUFFER float model = 0.0f; vec3 normal = vec3(0.5f, 0.5f, 1.0f); vec3 albedo = Diffuse * _color.xyz; @@ -66,7 +67,6 @@ void main(void) { normal = Normal * 2.0f - 1.0f; normal = normalize(normal.x * _t + normal.y * _b + normal.z * _n); - emit += mix(albedo, vec3(0.0f), Metallic); model = 0.333f; normal = normal * 0.5f + 0.5f; Roughness = max(0.01f, Roughness); @@ -77,9 +77,11 @@ void main(void) { gbuffer2 = vec4(albedo, model); gbuffer3 = vec4(Roughness, 0.0f, Metallic, 1.0f); // Variables -#else + #else gbuffer0 = vec4(emit, alpha); + #endif + #endif } diff --git a/modules/renders/rendergl/src/renderglsystem.cpp b/modules/renders/rendergl/src/renderglsystem.cpp index 2411d7882..a0f6cfa67 100644 --- a/modules/renders/rendergl/src/renderglsystem.cpp +++ b/modules/renders/rendergl/src/renderglsystem.cpp @@ -96,7 +96,6 @@ bool RenderGLSystem::init() { aWarning() << "[ RenderGL ] Failed to initialize OpenGL context."; return false; } - glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); CheckGLError(); #endif int32_t texture; diff --git a/modules/renders/rendergl/src/resources/texturegl.cpp b/modules/renders/rendergl/src/resources/texturegl.cpp index e678bf8b7..49364bde1 100644 --- a/modules/renders/rendergl/src/resources/texturegl.cpp +++ b/modules/renders/rendergl/src/resources/texturegl.cpp @@ -63,11 +63,16 @@ void TextureGL::updateTexture() { int32_t glwrap = GL_CLAMP_TO_EDGE; - switch(wrap()) { - case Repeat: glwrap = GL_REPEAT; break; - case Mirrored: glwrap = GL_MIRRORED_REPEAT; break; - default: break; + if(isCubemap()) { + glwrap = GL_MIRRORED_REPEAT; + } else { + switch(wrap()) { + case Repeat: glwrap = GL_REPEAT; break; + case Mirrored: glwrap = GL_MIRRORED_REPEAT; break; + default: break; + } } + glTexParameteri(target, GL_TEXTURE_WRAP_S, glwrap); glTexParameteri(target, GL_TEXTURE_WRAP_T, glwrap); glTexParameteri(target, GL_TEXTURE_WRAP_R, glwrap); diff --git a/thirdparty/next/inc/core/object.h b/thirdparty/next/inc/core/object.h index aab815435..948635222 100644 --- a/thirdparty/next/inc/core/object.h +++ b/thirdparty/next/inc/core/object.h @@ -174,7 +174,7 @@ class NEXT_LIBRARY_EXPORT Object { virtual Variant property(const char *name) const; virtual void setProperty(const char *name, const Variant &value); - const std::list dynamicPropertyNames() const; + const std::list &dynamicPropertyNames() const; virtual bool event(Event *event); diff --git a/thirdparty/next/inc/math/aabb.h b/thirdparty/next/inc/math/aabb.h index 783d8cd4f..f7323dce2 100644 --- a/thirdparty/next/inc/math/aabb.h +++ b/thirdparty/next/inc/math/aabb.h @@ -26,6 +26,7 @@ class Matrix3; class Matrix4; +class Quaternion; class NEXT_LIBRARY_EXPORT AABBox { public: @@ -43,9 +44,11 @@ class NEXT_LIBRARY_EXPORT AABBox { const AABBox operator*(const Vector3 &vector) const; const AABBox operator*(const Matrix3 &matrix) const; const AABBox operator*(const Matrix4 &matrix) const; + const AABBox operator*(const Quaternion &quaternion) const; AABBox &operator*=(const Matrix3 &matrix); AABBox &operator*=(const Matrix4 &matrix); + AABBox &operator*=(const Quaternion &quaternion); void encapsulate(const Vector3 &position, areal radius = 0.0f); void encapsulate(const AABBox &box); diff --git a/thirdparty/next/src/core/object.cpp b/thirdparty/next/src/core/object.cpp index fe3c8f73b..98c443771 100644 --- a/thirdparty/next/src/core/object.cpp +++ b/thirdparty/next/src/core/object.cpp @@ -979,7 +979,7 @@ void Object::setProperty(const char *name, const Variant &value) { /*! Returns the names of all properties that were dynamically added to the object using setProperty() */ -const std::list Object::dynamicPropertyNames() const { +const std::list &Object::dynamicPropertyNames() const { return m_dynamicPropertyNames; } /*! @@ -1039,31 +1039,23 @@ VariantList Object::serializeData(const MetaObject *meta) const { result.push_back(name()); // Save base properties - VariantMap properties; + std::list propertyNames; for(int i = 0; i < meta->propertyCount(); i++) { MetaProperty property = meta->property(i); if(property.isValid()) { - Variant v = property.read(this); - uint32_t type = v.userType(); - if(type < MetaType::USERTYPE && type != MetaType::VARIANTLIST && type != MetaType::VARIANTMAP) { - properties[property.name()] = v; - } + propertyNames.push_back(property.name()); } } - // Save dynamic properties - VariantList dynamic; - auto dynamicNames = m_dynamicPropertyNames.begin(); - auto dynamicValues = m_dynamicPropertyValues.begin(); - for(int i = 0; i < m_dynamicPropertyNames.size(); i++) { - VariantList pair; - pair.push_back(*dynamicNames); - pair.push_back(*dynamicValues); - - dynamic.push_back(pair); - - ++dynamicNames; - ++dynamicValues; + propertyNames.insert(propertyNames.end(), m_dynamicPropertyNames.begin(), m_dynamicPropertyNames.end()); + + VariantMap properties; + for(auto it : propertyNames) { + Variant v = property(it.c_str()); + uint32_t type = v.userType(); + if(type < MetaType::USERTYPE && type != MetaType::VARIANTLIST && type != MetaType::VARIANTMAP) { + properties[it] = v; + } } // Save links @@ -1086,9 +1078,6 @@ VariantList Object::serializeData(const MetaObject *meta) const { result.push_back(properties); result.push_back(links); result.push_back(saveUserData()); - if(!dynamic.empty()) { - result.push_back(dynamic); - } return result; } diff --git a/thirdparty/next/src/math/aabb.cpp b/thirdparty/next/src/math/aabb.cpp index b8ce2377d..2456d638a 100644 --- a/thirdparty/next/src/math/aabb.cpp +++ b/thirdparty/next/src/math/aabb.cpp @@ -226,17 +226,45 @@ const AABBox AABBox::operator*(const Matrix4 &matrix) const { return result; } /*! - Multiplies this box by the given rotation \a matrix, and returns a reference to this vector. + Returns a copy of this box, multiplied by the given \a quaternion. +*/ +const AABBox AABBox::operator*(const Quaternion &quaternion) const { + AABBox result; + + Vector3 rotPoints[4] = { + (quaternion * Vector3(-extent.x, extent.y, -extent.z)).abs(), + (quaternion * Vector3(-extent.x, extent.y, extent.z)).abs(), + (quaternion * Vector3( extent.x, extent.y, extent.z)).abs(), + (quaternion * Vector3( extent.x, extent.y, -extent.z)).abs() + }; + + result.center = center; + result.extent = Vector3(MAX(rotPoints[0].x, MAX(rotPoints[1].x, MAX(rotPoints[2].x, rotPoints[3].x))), + MAX(rotPoints[0].y, MAX(rotPoints[1].y, MAX(rotPoints[2].y, rotPoints[3].y))), + MAX(rotPoints[0].z, MAX(rotPoints[1].z, MAX(rotPoints[2].z, rotPoints[3].z)))); + + result.radius = result.extent.length(); + + return result; +} +/*! + Multiplies this box by the given rotation \a matrix, and returns a reference to this AABB. */ AABBox &AABBox::operator*=(const Matrix3 &matrix) { return *this = *this * matrix; } /*! - Multiplies this box by the given transform \a matrix, and returns a reference to this vector. + Multiplies this box by the given transform \a matrix, and returns a reference to this AABB. */ AABBox &AABBox::operator*=(const Matrix4 &matrix) { return *this = *this * matrix; } +/*! + Multiplies this box by the given \a quaternion, and returns a reference to this AABB. +*/ +AABBox &AABBox::operator*=(const Quaternion &quaternion) { + return *this = *this * quaternion; +} /*! Returns \a min and \a max points of bounding box as output arguments. */ diff --git a/worldeditor/bin/engine/materials/BlurOcclusion.shader b/worldeditor/bin/engine/materials/BlurOcclusion.shader index 62e6d5b6c..4eb8686ae 100644 --- a/worldeditor/bin/engine/materials/BlurOcclusion.shader +++ b/worldeditor/bin/engine/materials/BlurOcclusion.shader @@ -1,6 +1,6 @@ - + - + 0.0) { - color = vec4(0, 0, 0, 1.0 - texture(ssaoMap, _uv0).x); + color = vec4(0, 0, 0, 1.0 - texture(aoMap, _uv0).x); } else { color = vec4(0, 0, 0, 0); } diff --git a/worldeditor/bin/engine/materials/DefaultMesh.shader b/worldeditor/bin/engine/materials/DefaultMesh.shader index f0d059924..b54830fe4 100644 --- a/worldeditor/bin/engine/materials/DefaultMesh.shader +++ b/worldeditor/bin/engine/materials/DefaultMesh.shader @@ -18,27 +18,27 @@ layout(location = 7) flat in vec4 _objectId; layout(location = 8) flat in int _instanceOffset; layout(location = 0) out vec4 gbuffer0; -layout(location = 1) out vec4 gbuffer1; -layout(location = 2) out vec4 gbuffer2; -layout(location = 3) out vec4 gbuffer3; +#ifndef VISIBILITY_BUFFER + layout(location = 1) out vec4 gbuffer1; + layout(location = 2) out vec4 gbuffer2; + layout(location = 3) out vec4 gbuffer3; +#endif void main() { - vec3 emissive = vec3(0.1f) * _color.xyz; +#ifdef VISIBILITY_BUFFER + gbuffer0 = _objectId; +#else + vec3 emissive = vec3(0.0f); vec3 albedo = vec3(1.0f) * _color.xyz; float roughness = 0.9f; float metallic = 0.0f; - float model = 0.333f; -#ifdef VISIBILITY_BUFFER - gbuffer0 = _objectId; - return; -#endif - gbuffer0 = vec4(emissive, 0.0f); gbuffer1 = vec4(_n * 0.5f + 0.5f, model); gbuffer2 = vec4(albedo, model); gbuffer3 = vec4(roughness, 0.0f, metallic, 1.0f); +#endif } ]]> diff --git a/worldeditor/bin/engine/materials/IblReflections.shader b/worldeditor/bin/engine/materials/IblReflections.shader index 99d8862b8..e34dfc6ab 100644 --- a/worldeditor/bin/engine/materials/IblReflections.shader +++ b/worldeditor/bin/engine/materials/IblReflections.shader @@ -1,10 +1,35 @@ - - - + + + + + + + 0.0f) { + vec3 n = normSamp.xyz * 2.0f - 1.0f; + + vec3 world = getWorld(g.cameraScreenToWorld, proj, depth); + vec3 v = normalize(world - g.cameraPosition.xyz); + vec3 refl = reflect(v, n); + + float rough = texture(paramsMap, proj).x; + + vec4 sslr = texture(sslrMap, proj); + vec3 ibl = texture(iblMap, mix(refl, n, rough)).xyz; + float occlusion = texture(aoMap, proj).x; + color = mix(ibl, sslr.xyz, sslr.w) * texture(diffuseMap, proj).xyz * occlusion; + } else { // material is emissive no indirect + color = vec3(0.0f); + } return; } - color = vec3(0.0); + color = texture(iblMap, normalize(getWorld(g.cameraScreenToWorld, proj, 1.0f))).xyz; } ]]> diff --git a/worldeditor/bin/engine/materials/AmbientOcclusion.shader b/worldeditor/bin/engine/materials/SSAO.shader similarity index 75% rename from worldeditor/bin/engine/materials/AmbientOcclusion.shader rename to worldeditor/bin/engine/materials/SSAO.shader index c8a468454..33c37db1e 100644 --- a/worldeditor/bin/engine/materials/AmbientOcclusion.shader +++ b/worldeditor/bin/engine/materials/SSAO.shader @@ -39,40 +39,40 @@ layout(location = 2) in vec4 _color; layout(location = 0) out float color; void main(void) { - vec2 scale = vec2(g.cameraScreen.x / 4.0, g.cameraScreen.y / 4.0); + vec2 scale = vec2(g.cameraScreen.x / 4.0f, g.cameraScreen.y / 4.0f); float depth = texture(depthMap, _uv0).x; - if(depth < 1.0) { + if(depth < 1.0f) { vec3 world = getWorld(g.cameraProjectionInv, _uv0, depth); - vec3 view = mat3(g.cameraView) * (texture(normalsMap, _uv0).xyz * 2.0 - 1.0); + vec3 view = mat3(g.cameraView) * (texture(normalsMap, _uv0).xyz * 2.0f - 1.0f); vec3 normal = normalize(view); vec3 random = texture(noiseMap, _uv0 * scale).xyz; vec3 tangent = normalize(random - normal * dot(random, normal)); - vec3 binormal = cross(normal, tangent); - mat3 tbn = mat3(tangent, binormal, normal); + vec3 bitangent = normalize(cross(normal, tangent)); + mat3 tbn = mat3(tangent, bitangent, normal); float ssao = 0; for(int i = 0; i < MAX_SAMPLE_COUNT; i++) { vec3 samp = tbn * uni.samplesKernel[i]; samp = world + samp * uni.radius; - vec4 offset = vec4(samp, 1.0); + vec4 offset = vec4(samp, 1.0f); offset = g.cameraProjection * offset; offset.xyz /= offset.w; - offset.xyz = offset.xyz * 0.5 + 0.5; + offset.xyz = offset.xyz * 0.5f + 0.5f; float sampleDepth = texture(depthMap, offset.xy).x; - vec3 sampWorld = getWorld(g.cameraProjectionInv, offset.xy, sampleDepth); + sampleDepth = getWorld(g.cameraProjectionInv, offset.xy, sampleDepth).z; - float rangeCheck = smoothstep(0.0, 1.0, uni.radius / abs(world.z - sampWorld.z)); - ssao += step(samp.z + uni.bias, sampWorld.z) * rangeCheck; + float rangeCheck = smoothstep(0.0f, 1.0f, uni.radius / abs(world.z - sampleDepth)); + ssao += step(samp.z + uni.bias, sampleDepth) * rangeCheck; } - color = pow(1.0 - ssao / MAX_SAMPLE_COUNT, uni.power); + color = pow(1.0f - ssao / MAX_SAMPLE_COUNT, uni.power); } else { - color = 1.0; + color = 1.0f; } } ]]> diff --git a/worldeditor/bin/engine/materials/AmbientOcclusion.shader.set b/worldeditor/bin/engine/materials/SSAO.shader.set similarity index 100% rename from worldeditor/bin/engine/materials/AmbientOcclusion.shader.set rename to worldeditor/bin/engine/materials/SSAO.shader.set diff --git a/worldeditor/bin/engine/materials/SSLR.shader b/worldeditor/bin/engine/materials/SSLR.shader index 4514a9c01..1162af897 100644 --- a/worldeditor/bin/engine/materials/SSLR.shader +++ b/worldeditor/bin/engine/materials/SSLR.shader @@ -5,6 +5,28 @@ + 0.8) { return; } - vec3 origin = vec3(_uv0, depth); + vec3 origin = vec3(proj, depth); vec3 world = getWorld(g.cameraScreenToWorld, origin.xy, origin.z); vec3 v = normalize(world - g.cameraPosition.xyz); @@ -102,7 +125,8 @@ void main(void) { vec3 dir = normalize(ray.xyz - origin); vec3 coord = rayMarch(origin, dir, 1.0 / marchSteps); - color = vec4(texture(emissiveMap, coord.xy).xyz, coord.z); + float mask = 1.0f - step(coord.z, 0.0f); + color = vec4(texture(emissiveMap, coord.xy).xyz * mask, mask); } } ]]> diff --git a/worldeditor/bin/engine/pipelines/Deferred.pipeline b/worldeditor/bin/engine/pipelines/Deferred.pipeline index cc0fc0ac0..5c161eb46 100644 --- a/worldeditor/bin/engine/pipelines/Deferred.pipeline +++ b/worldeditor/bin/engine/pipelines/Deferred.pipeline @@ -1,321 +1,48 @@ - - - - 1 - 2 - 0 - 8 - - - 0 - 1 - 0 - 8 - - - 0 - 1 - 2 - 1 - - - 4 - 3 - 5 - 1 - - - 0 - 1 - 1 - 9 - - - 5 - 2 - 2 - 1 - - - 4 - 6 - 4 - 1 - - - 5 - 5 - 5 - 1 - - - 7 - 6 - 5 - 1 - - - 0 - 1 - 2 - 1 - - - 5 - 2 - 2 - 1 - - - 0 - 1 - 3 - 2 - - - 3 - 2 - 3 - 2 - - - 0 - 1 - 3 - 2 - - - 3 - 2 - 3 - 2 - - - 0 - 1 - 4 - 3 - - - 3 - 2 - 4 - 3 - - - 4 - 6 - 4 - 1 - - - 0 - 1 - 4 - 3 - - - 3 - 2 - 4 - 3 - - - 0 - 1 - 5 - 4 - - - 6 - 2 - 5 - 4 - - - 4 - 3 - 5 - 1 - - - 5 - 5 - 5 - 1 - - - 7 - 6 - 5 - 1 - - - 0 - 1 - 5 - 4 - - - 6 - 2 - 5 - 4 - - - 0 - 1 - 6 - 5 - - - 3 - 2 - 6 - 5 - - - 0 - 1 - 7 - 6 - - - 3 - 2 - 7 - 6 - - - 0 - 1 - 6 - 5 - - - 3 - 2 - 6 - 5 - - - 0 - 1 - 7 - 6 - - - 3 - 2 - 7 - 6 - - - 0 - 1 - 8 - 7 - - - 3 - 2 - 8 - 7 - - - 1 - 2 - 0 - 8 - - - 0 - 1 - 0 - 8 - - - 0 - 1 - 8 - 7 - - - 3 - 2 - 8 - 7 - - - 0 - 1 - 1 - 9 - - - - - 1 - - - -1659 - 180 - - - 2 - - - -1419 - 0 - - - 3 - - - -1219 - 0 - - - 4 - - - -1019 - 0 - - - 5 - - - -819 - 0 - - - 6 - - - -609 - 0 - - - 7 - - - -408 - 0 - - - 8 - - - -208 - 0 - - - 9 - - - -1909 - 100 - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/worldeditor/bin/engine/pipelines/Deferred.pipeline.set b/worldeditor/bin/engine/pipelines/Deferred.pipeline.set index 7b0c82726..fda3834a7 100644 --- a/worldeditor/bin/engine/pipelines/Deferred.pipeline.set +++ b/worldeditor/bin/engine/pipelines/Deferred.pipeline.set @@ -1,10 +1,10 @@ { "guid": "{9e7e2e22-61f6-432d-93d3-a92037783a00}", - "md5": "{40ebab14-e417-adb6-a6a9-031a5179bdf1}", + "md5": "{c2c0d363-a5c6-09fd-b54c-dcd1da2a6f51}", "settings": { }, "subitems": { }, - "type": 86, - "version": 1 + "type": 84, + "version": 11 } diff --git a/worldeditor/src/screens/propertyedit/custom/array/arrayelement.cpp b/worldeditor/src/screens/propertyedit/custom/array/arrayelement.cpp index 8b54f41bc..e2ee37ed7 100644 --- a/worldeditor/src/screens/propertyedit/custom/array/arrayelement.cpp +++ b/worldeditor/src/screens/propertyedit/custom/array/arrayelement.cpp @@ -27,7 +27,7 @@ QVariant ArrayElement::data() const { void ArrayElement::setData(int index, const QVariant &data, const QString &name, QObject *object) { m_index = index; - ui->label->setText(QString("Element %1").arg(m_index)); + ui->label->setText(QString("#%1").arg(m_index)); if(m_editor && m_editor->data().typeName() == data.typeName()) { m_editor->setData(data); diff --git a/worldeditor/src/screens/propertyedit/property.cpp b/worldeditor/src/screens/propertyedit/property.cpp index b08ea086f..ca009f120 100644 --- a/worldeditor/src/screens/propertyedit/property.cpp +++ b/worldeditor/src/screens/propertyedit/property.cpp @@ -361,7 +361,10 @@ QVariant Property::qVariant(const Variant &value, const MetaProperty &property, } bool isArray = false; - std::string typeName = property.type().name(); + std::string typeName = MetaType::name(value.userType()); + if(property.isValid()) { + typeName = property.type().name(); + } trimmType(typeName, isArray); if(isArray) { @@ -466,7 +469,10 @@ Variant Property::aVariant(const QVariant &value, const Variant ¤t, const } bool isArray = false; - std::string typeName = property.type().name(); + std::string typeName = MetaType::name(current.userType()); + if(property.isValid()) { + typeName = property.type().name(); + } trimmType(typeName, isArray); if(isArray) {