diff --git a/engine/includes/pipelinetask.h b/engine/includes/pipelinetask.h index e2f297281..789ae074d 100644 --- a/engine/includes/pipelinetask.h +++ b/engine/includes/pipelinetask.h @@ -16,7 +16,7 @@ class ENGINE_EXPORT PipelineTask : public Object { PipelineTask(); ~PipelineTask(); - virtual void exec(PipelineContext *context); + virtual void exec(PipelineContext &context); virtual void resize(int width, int height); diff --git a/engine/includes/pipelinetasks/ambientocclusion.h b/engine/includes/pipelinetasks/ambientocclusion.h index ad99ff3da..08781a8eb 100644 --- a/engine/includes/pipelinetasks/ambientocclusion.h +++ b/engine/includes/pipelinetasks/ambientocclusion.h @@ -16,7 +16,7 @@ class AmbientOcclusion : public PipelineTask { ~AmbientOcclusion(); private: - void exec(PipelineContext *context) override; + void exec(PipelineContext &context) override; void setSettings(const PostProcessSettings &settings) override; diff --git a/engine/includes/pipelinetasks/antialiasing.h b/engine/includes/pipelinetasks/antialiasing.h index d56395a63..795544ae8 100644 --- a/engine/includes/pipelinetasks/antialiasing.h +++ b/engine/includes/pipelinetasks/antialiasing.h @@ -13,7 +13,7 @@ class AntiAliasing : public PipelineTask { AntiAliasing(); private: - void exec(PipelineContext *context) override; + void exec(PipelineContext &context) override; void setInput(int index, Texture *texture) override; diff --git a/engine/includes/pipelinetasks/bloom.h b/engine/includes/pipelinetasks/bloom.h index 83274b3d6..56e917beb 100644 --- a/engine/includes/pipelinetasks/bloom.h +++ b/engine/includes/pipelinetasks/bloom.h @@ -28,7 +28,7 @@ class Bloom : public PipelineTask { Bloom(); private: - void exec(PipelineContext *context) override; + void exec(PipelineContext &context) override; void resize(int32_t width, int32_t height) override; diff --git a/engine/includes/pipelinetasks/deferredlighting.h b/engine/includes/pipelinetasks/deferredlighting.h index e85b0b8f1..fa6b128a8 100644 --- a/engine/includes/pipelinetasks/deferredlighting.h +++ b/engine/includes/pipelinetasks/deferredlighting.h @@ -12,7 +12,7 @@ class DeferredLighting : public PipelineTask { DeferredLighting(); private: - void exec(PipelineContext *context) override; + void exec(PipelineContext &context) override; void setInput(int index, Texture *texture) override; diff --git a/engine/includes/pipelinetasks/gbuffer.h b/engine/includes/pipelinetasks/gbuffer.h index b516bac57..15c9796d9 100644 --- a/engine/includes/pipelinetasks/gbuffer.h +++ b/engine/includes/pipelinetasks/gbuffer.h @@ -12,7 +12,7 @@ class GBuffer : public PipelineTask { GBuffer(); private: - void exec(PipelineContext *context) override; + void exec(PipelineContext &context) override; private: RenderTarget *m_gbuffer; diff --git a/engine/includes/pipelinetasks/guilayer.h b/engine/includes/pipelinetasks/guilayer.h index 36dffad4d..9b2f60c6f 100644 --- a/engine/includes/pipelinetasks/guilayer.h +++ b/engine/includes/pipelinetasks/guilayer.h @@ -14,7 +14,7 @@ class GuiLayer : public PipelineTask { void showUiAsSceneView(bool flag); private: - void exec(PipelineContext *context) override; + void exec(PipelineContext &context) override; void setInput(int index, Texture *source) override; diff --git a/engine/includes/pipelinetasks/reflections.h b/engine/includes/pipelinetasks/reflections.h index c33e9b715..07b7f84fa 100644 --- a/engine/includes/pipelinetasks/reflections.h +++ b/engine/includes/pipelinetasks/reflections.h @@ -14,7 +14,7 @@ class Reflections : public PipelineTask { Reflections(); private: - void exec(PipelineContext *context) override; + void exec(PipelineContext &context) override; void setInput(int index, Texture *texture) override; diff --git a/engine/includes/pipelinetasks/shadowmap.h b/engine/includes/pipelinetasks/shadowmap.h index 91007fd9f..e423804da 100644 --- a/engine/includes/pipelinetasks/shadowmap.h +++ b/engine/includes/pipelinetasks/shadowmap.h @@ -23,16 +23,16 @@ class ShadowMap : public PipelineTask { ShadowMap(); private: - void exec(PipelineContext *context) override; + void exec(PipelineContext &context) override; - void areaLightUpdate(PipelineContext *context, AreaLight *light, list &components); - void directLightUpdate(PipelineContext *context, DirectLight *light, list &components, const Camera &camera); - void pointLightUpdate(PipelineContext *context, PointLight *light, list &components); - void spotLightUpdate(PipelineContext *context, SpotLight *light, list &components); + void areaLightUpdate(PipelineContext &context, AreaLight *light, list &components); + void directLightUpdate(PipelineContext &context, DirectLight *light, list &components, const Camera &camera); + void pointLightUpdate(PipelineContext &context, PointLight *light, list &components); + void spotLightUpdate(PipelineContext &context, SpotLight *light, list &components); void cleanShadowCache(); - RenderTarget *requestShadowTiles(uint32_t id, uint32_t lod, int32_t *x, int32_t *y, int32_t *w, int32_t *h, uint32_t count); + RenderTarget *requestShadowTiles(PipelineContext &context, uint32_t id, uint32_t lod, int32_t *x, int32_t *y, int32_t *w, int32_t *h, uint32_t count); private: unordered_map>> m_tiles; @@ -44,6 +44,8 @@ class ShadowMap : public PipelineTask { float m_bias; + uint32_t m_shadowResolution; + }; #endif // SHADOWMAP_H diff --git a/engine/includes/pipelinetasks/translucent.h b/engine/includes/pipelinetasks/translucent.h index ad874d0f6..4f33f1648 100644 --- a/engine/includes/pipelinetasks/translucent.h +++ b/engine/includes/pipelinetasks/translucent.h @@ -12,7 +12,7 @@ class Translucent : public PipelineTask { Translucent(); private: - void exec(PipelineContext *context) override; + void exec(PipelineContext &context) override; void setInput(int index, Texture *texture) override; diff --git a/engine/src/components/spotlight.cpp b/engine/src/components/spotlight.cpp index bef8a1103..4b3a577f2 100644 --- a/engine/src/components/spotlight.cpp +++ b/engine/src/components/spotlight.cpp @@ -94,12 +94,12 @@ void SpotLight::drawGizmosSelected() { float radius = tan(DEG2RAD * m_angle * 0.5f) * distance; Matrix4 m(t->worldPosition(), t->worldQuaternion() * Quaternion(Vector3(1, 0, 0), 90), Vector3(1.0f)); - Gizmos::drawCircle(t->worldQuaternion() * Vector3(0.0f, 0.0f, distance), radius, gizmoColor(), m); + Gizmos::drawCircle(t->worldQuaternion() * Vector3(0.0f, 0.0f, -distance), radius, gizmoColor(), m); Gizmos::drawLines({Vector3(), - Vector3( 0.0f, radius, distance), - Vector3( 0.0f,-radius, distance), - Vector3( radius, 0.0f, distance), - Vector3(-radius, 0.0f, distance)}, + Vector3( 0.0f, radius, -distance), + Vector3( 0.0f,-radius, -distance), + Vector3( radius, 0.0f, -distance), + Vector3(-radius, 0.0f, -distance)}, {0, 1, 0, 2, 0, 3, 0, 4}, gizmoColor(), t->worldTransform()); } diff --git a/engine/src/editor/viewport/viewport.cpp b/engine/src/editor/viewport/viewport.cpp index fcfa20646..9c16de7a6 100644 --- a/engine/src/editor/viewport/viewport.cpp +++ b/engine/src/editor/viewport/viewport.cpp @@ -96,23 +96,23 @@ class Outline : public PipelineTask { } private: - void exec(PipelineContext *context) override { + void exec(PipelineContext &context) override { if(m_combineMaterial && m_controller) { - CommandBuffer *buffer = context->buffer(); + CommandBuffer *buffer = context.buffer(); buffer->beginDebugMarker("Outline"); buffer->setRenderTarget(m_outlineTarget); buffer->clearRenderTarget(); RenderList filter; for(auto actor : m_controller->selected()) { - for(auto it : context->culledComponents()) { + for(auto it : context.culledComponents()) { Renderable *component = dynamic_cast(it); if(component && component->actor()->isInHierarchy(static_cast(actor))) { filter.push_back(component); } } } - context->drawRenderers(CommandBuffer::RAYCAST, filter); + context.drawRenderers(CommandBuffer::RAYCAST, filter); buffer->setRenderTarget(m_resultTarget); buffer->drawMesh(Matrix4(), PipelineContext::defaultPlane(), 0, CommandBuffer::UI, m_combineMaterial); @@ -196,7 +196,7 @@ class GridRender : public PipelineTask { } private: - void exec(PipelineContext *context) override { + void exec(PipelineContext &context) override { Camera *camera = Camera::current(); Transform *t = camera->transform(); @@ -275,7 +275,7 @@ class GridRender : public PipelineTask { m_grid->setFloat("scale", &m_scale); m_grid->setFloat("width", &width); - CommandBuffer *buffer = context->buffer(); + CommandBuffer *buffer = context.buffer(); buffer->beginDebugMarker("GridRender"); @@ -335,8 +335,8 @@ class GizmoRender : public PipelineTask { } private: - void exec(PipelineContext *context) override { - CommandBuffer *buffer = context->buffer(); + void exec(PipelineContext &context) override { + CommandBuffer *buffer = context.buffer(); buffer->beginDebugMarker("GizmoRender"); Gizmos::clear(); @@ -400,15 +400,15 @@ class DebugRender : public PipelineTask { } private: - void exec(PipelineContext *context) override { + void exec(PipelineContext &context) override { if(!m_buffers.empty()) { - CommandBuffer *buffer = context->buffer(); + CommandBuffer *buffer = context.buffer(); buffer->beginDebugMarker("DebugRender"); buffer->setScreenProjection(0, 0, m_width, m_height); int i = 0; for(auto &it : m_buffers) { - it.second->setTexture("texture0", context->textureBuffer(it.first)); + it.second->setTexture("texture0", context.textureBuffer(it.first)); float width = m_width * 0.25f; float height = m_height * 0.25f; diff --git a/engine/src/pipelinecontext.cpp b/engine/src/pipelinecontext.cpp index 748f9e82e..81215728b 100644 --- a/engine/src/pipelinecontext.cpp +++ b/engine/src/pipelinecontext.cpp @@ -85,7 +85,7 @@ void PipelineContext::draw(Camera *camera) { for(auto it : m_renderTasks) { if(it->isEnabled()) { - it->exec(this); + it->exec(*this); } } diff --git a/engine/src/pipelinetask.cpp b/engine/src/pipelinetask.cpp index d21662716..bdff4038c 100644 --- a/engine/src/pipelinetask.cpp +++ b/engine/src/pipelinetask.cpp @@ -24,7 +24,7 @@ PipelineTask::~PipelineTask() { /*! The task will be executed for the provided \a context. */ -void PipelineTask::exec(PipelineContext *context) { +void PipelineTask::exec(PipelineContext &context) { A_UNUSED(context); } /*! diff --git a/engine/src/pipelinetasks/ambientocclusion.cpp b/engine/src/pipelinetasks/ambientocclusion.cpp index 582c60ae6..d0271cad9 100644 --- a/engine/src/pipelinetasks/ambientocclusion.cpp +++ b/engine/src/pipelinetasks/ambientocclusion.cpp @@ -121,8 +121,8 @@ AmbientOcclusion::~AmbientOcclusion() { m_noiseTexture->deleteLater(); } -void AmbientOcclusion::exec(PipelineContext *context) { - CommandBuffer *buffer = context->buffer(); +void AmbientOcclusion::exec(PipelineContext &context) { + CommandBuffer *buffer = context.buffer(); buffer->beginDebugMarker("AmbientOcclusion"); if(m_occlusion) { diff --git a/engine/src/pipelinetasks/antialiasing.cpp b/engine/src/pipelinetasks/antialiasing.cpp index c304267af..6bf12c2a6 100644 --- a/engine/src/pipelinetasks/antialiasing.cpp +++ b/engine/src/pipelinetasks/antialiasing.cpp @@ -37,9 +37,9 @@ AntiAliasing::AntiAliasing() : } -void AntiAliasing::exec(PipelineContext *context) { +void AntiAliasing::exec(PipelineContext &context) { if(m_material) { - CommandBuffer *buffer = context->buffer(); + CommandBuffer *buffer = context.buffer(); buffer->beginDebugMarker("AntiAliasing"); buffer->setRenderTarget(m_resultTarget); diff --git a/engine/src/pipelinetasks/bloom.cpp b/engine/src/pipelinetasks/bloom.cpp index baf1d096b..68980dc15 100644 --- a/engine/src/pipelinetasks/bloom.cpp +++ b/engine/src/pipelinetasks/bloom.cpp @@ -53,9 +53,9 @@ Bloom::Bloom() : m_outputs.push_back(make_pair("Result", nullptr)); } -void Bloom::exec(PipelineContext *context) { +void Bloom::exec(PipelineContext &context) { if(m_material) { - CommandBuffer *buffer = context->buffer(); + CommandBuffer *buffer = context.buffer(); buffer->beginDebugMarker("Bloom"); Texture *texture(m_outputs.front().second); diff --git a/engine/src/pipelinetasks/deferredlighting.cpp b/engine/src/pipelinetasks/deferredlighting.cpp index c1a999278..8a06d6a12 100644 --- a/engine/src/pipelinetasks/deferredlighting.cpp +++ b/engine/src/pipelinetasks/deferredlighting.cpp @@ -27,13 +27,13 @@ DeferredLighting::DeferredLighting() : m_outputs.push_back(make_pair("Result", nullptr)); } -void DeferredLighting::exec(PipelineContext *context) { - CommandBuffer *buffer = context->buffer(); +void DeferredLighting::exec(PipelineContext &context) { + CommandBuffer *buffer = context.buffer(); buffer->beginDebugMarker("DeferredLighting"); buffer->setRenderTarget(m_lightPass); // Light pass - for(auto it : context->sceneLights()) { + for(auto it : context.sceneLights()) { BaseLight *light = static_cast(it); Mesh *mesh = PipelineContext::defaultCube(); @@ -82,7 +82,7 @@ void DeferredLighting::exec(PipelineContext *context) { Quaternion q(t->worldQuaternion()); Vector3 position(m[12], m[13], m[14]); - Vector3 direction(q * Vector3(0.0f, 0.0f,-1.0f)); + Vector3 direction(q * Vector3(0.0f, 0.0f, 1.0f)); float distance = static_cast(light)->attenuationDistance(); float angle = static_cast(light)->outerAngle(); diff --git a/engine/src/pipelinetasks/gbuffer.cpp b/engine/src/pipelinetasks/gbuffer.cpp index 3309ca9cd..dde19883d 100644 --- a/engine/src/pipelinetasks/gbuffer.cpp +++ b/engine/src/pipelinetasks/gbuffer.cpp @@ -50,17 +50,17 @@ GBuffer::GBuffer() : } } -void GBuffer::exec(PipelineContext *context) { - CommandBuffer *buffer = context->buffer(); +void GBuffer::exec(PipelineContext &context) { + CommandBuffer *buffer = context.buffer(); buffer->beginDebugMarker("GBuffer Pass"); buffer->setViewport(0, 0, m_width, m_height); - context->cameraReset(); + context.cameraReset(); buffer->setRenderTarget(m_gbuffer); - buffer->clearRenderTarget(true, context->currentCamera()->color()); + buffer->clearRenderTarget(true, context.currentCamera()->color()); - context->drawRenderers(CommandBuffer::DEFAULT, context->culledComponents()); + context.drawRenderers(CommandBuffer::DEFAULT, context.culledComponents()); buffer->endDebugMarker(); } diff --git a/engine/src/pipelinetasks/guilayer.cpp b/engine/src/pipelinetasks/guilayer.cpp index b034049d1..cb84f8024 100644 --- a/engine/src/pipelinetasks/guilayer.cpp +++ b/engine/src/pipelinetasks/guilayer.cpp @@ -17,18 +17,18 @@ GuiLayer::GuiLayer() : m_outputs.push_back(make_pair("Result", nullptr)); } -void GuiLayer::exec(PipelineContext *context) { - CommandBuffer *buffer = context->buffer(); +void GuiLayer::exec(PipelineContext &context) { + CommandBuffer *buffer = context.buffer(); buffer->beginDebugMarker("GuiLayer"); if(!m_uiAsSceneView) { buffer->setScreenProjection(0, 0, m_width, m_height); } else { - context->cameraReset(); + context.cameraReset(); } - for(auto it : context->uiComponents()) { + for(auto it : context.uiComponents()) { it->draw(*buffer, CommandBuffer::UI); } diff --git a/engine/src/pipelinetasks/reflections.cpp b/engine/src/pipelinetasks/reflections.cpp index 16e5d5e9a..526e91661 100644 --- a/engine/src/pipelinetasks/reflections.cpp +++ b/engine/src/pipelinetasks/reflections.cpp @@ -55,8 +55,8 @@ Reflections::Reflections() : } } -void Reflections::exec(PipelineContext *context) { - CommandBuffer *buffer = context->buffer(); +void Reflections::exec(PipelineContext &context) { + CommandBuffer *buffer = context.buffer(); buffer->beginDebugMarker("Reflections"); if(m_slrMaterial) { // sslr step diff --git a/engine/src/pipelinetasks/shadowmap.cpp b/engine/src/pipelinetasks/shadowmap.cpp index 570f8483a..a307797d1 100644 --- a/engine/src/pipelinetasks/shadowmap.cpp +++ b/engine/src/pipelinetasks/shadowmap.cpp @@ -25,8 +25,6 @@ #define SPLIT_WEIGHT 0.95f // 0.75f -#define SM_RESOLUTION_DEFAULT 4096 - #define SHADOW_MAP "shadowMap" namespace { @@ -41,7 +39,8 @@ namespace { }; ShadowMap::ShadowMap() : - m_bias(0.0f) { + m_bias(0.0f), + m_shadowResolution(4096) { Engine::setValue(shadowmap, true); m_scale[0] = 0.5f; @@ -60,13 +59,13 @@ ShadowMap::ShadowMap() : Quaternion()}; } -void ShadowMap::exec(PipelineContext *context) { - CommandBuffer *buffer = context->buffer(); +void ShadowMap::exec(PipelineContext &context) { + CommandBuffer *buffer = context.buffer(); buffer->beginDebugMarker("ShadowMap"); cleanShadowCache(); - list &components = context->sceneComponents(); - for(auto &it : context->sceneLights()) { + list &components = context.sceneComponents(); + for(auto &it : context.sceneLights()) { BaseLight *base = static_cast(it); auto instance = base->material(); @@ -77,7 +76,7 @@ void ShadowMap::exec(PipelineContext *context) { if(base->castShadows()) { switch(base->lightType()) { - case BaseLight::DirectLight: directLightUpdate(context, static_cast(base), components, *context->currentCamera()); break; + case BaseLight::DirectLight: directLightUpdate(context, static_cast(base), components, *context.currentCamera()); break; case BaseLight::AreaLight: areaLightUpdate(context, static_cast(base), components); break; case BaseLight::PointLight: pointLightUpdate(context, static_cast(base), components); break; case BaseLight::SpotLight: spotLightUpdate(context, static_cast(base), components); break; @@ -90,12 +89,12 @@ void ShadowMap::exec(PipelineContext *context) { buffer->endDebugMarker(); } -void ShadowMap::areaLightUpdate(PipelineContext *context, AreaLight *light, list &components) { - CommandBuffer *buffer = context->buffer(); +void ShadowMap::areaLightUpdate(PipelineContext &context, AreaLight *light, list &components) { + CommandBuffer *buffer = context.buffer(); Transform *t = light->transform(); int32_t x[SIDES], y[SIDES], w[SIDES], h[SIDES]; - RenderTarget *shadowTarget = requestShadowTiles(light->uuid(), 1, x, y, w, h, SIDES); + RenderTarget *shadowTarget = requestShadowTiles(context, light->uuid(), 1, x, y, w, h, SIDES); float zNear = 0.1f; float zFar = light->radius(); @@ -131,7 +130,7 @@ void ShadowMap::areaLightUpdate(PipelineContext *context, AreaLight *light, list AABBox bb; auto corners = Camera::frustumCorners(false, 90.0f, 1.0f, position, m_directions[i], zNear, zFar); - RenderList filter = context->frustumCulling(corners, components, bb); + RenderList filter = context.frustumCulling(corners, components, bb); // Draw in the depth buffer from position of the light source for(auto it : filter) { static_cast(it)->draw(*buffer, CommandBuffer::SHADOWCAST); @@ -150,8 +149,8 @@ void ShadowMap::areaLightUpdate(PipelineContext *context, AreaLight *light, list } } -void ShadowMap::directLightUpdate(PipelineContext *context, DirectLight *light, list &components, const Camera &camera) { - CommandBuffer *buffer = context->buffer(); +void ShadowMap::directLightUpdate(PipelineContext &context, DirectLight *light, list &components, const Camera &camera) { + CommandBuffer *buffer = context.buffer(); float nearPlane = camera.nearPlane(); @@ -186,13 +185,11 @@ void ShadowMap::directLightUpdate(PipelineContext *context, DirectLight *light, ratio = camera.ratio(); int32_t x[MAX_LODS], y[MAX_LODS], w[MAX_LODS], h[MAX_LODS]; - RenderTarget *shadowTarget = requestShadowTiles(light->uuid(), 0, x, y, w, h, MAX_LODS); + RenderTarget *shadowTarget = requestShadowTiles(context, light->uuid(), 0, x, y, w, h, MAX_LODS); Vector4 tiles[MAX_LODS]; Matrix4 matrix[MAX_LODS]; - context->addTextureBuffer(shadowTarget->depthAttachment()); - buffer->setRenderTarget(shadowTarget); for(int32_t lod = 0; lod < MAX_LODS; lod++) { float dist = distance[lod]; @@ -206,7 +203,7 @@ void ShadowMap::directLightUpdate(PipelineContext *context, DirectLight *light, AABBox bb; auto corners = Camera::frustumCorners(true, box.extent.y * 2.0f, 1.0f, box.center, lightRot, -FLT_MAX, FLT_MAX); - RenderList filter(context->frustumCulling(corners, components, bb)); + RenderList filter(context.frustumCulling(corners, components, bb)); float radius = MAX(box.radius, bb.radius); @@ -241,7 +238,6 @@ void ShadowMap::directLightUpdate(PipelineContext *context, DirectLight *light, auto instance = light->material(); if(instance) { - Vector3 direction(lightRot * Vector3(0.0f, 0.0f, 1.0f)); Vector4 bias(m_bias); const float biasModifier = 0.5f; @@ -257,12 +253,12 @@ void ShadowMap::directLightUpdate(PipelineContext *context, DirectLight *light, } } -void ShadowMap::pointLightUpdate(PipelineContext *context, PointLight *light, list &components) { - CommandBuffer *buffer = context->buffer(); +void ShadowMap::pointLightUpdate(PipelineContext &context, PointLight *light, list &components) { + CommandBuffer *buffer = context.buffer(); Transform *t = light->transform(); int32_t x[SIDES], y[SIDES], w[SIDES], h[SIDES]; - RenderTarget *shadowTarget = requestShadowTiles(light->uuid(), 1, x, y, w, h, SIDES); + RenderTarget *shadowTarget = requestShadowTiles(context, light->uuid(), 1, x, y, w, h, SIDES); float zNear = 0.1f; float zFar = light->attenuationRadius(); @@ -298,7 +294,7 @@ void ShadowMap::pointLightUpdate(PipelineContext *context, PointLight *light, li AABBox bb; auto corners = Camera::frustumCorners(false, 90.0f, 1.0f, position, m_directions[i], zNear, zFar); - RenderList filter = context->frustumCulling(corners, components, bb); + RenderList filter = context.frustumCulling(corners, components, bb); // Draw in the depth buffer from position of the light source for(auto it : filter) { @@ -309,7 +305,6 @@ void ShadowMap::pointLightUpdate(PipelineContext *context, PointLight *light, li auto instance = light->material(); if(instance) { - Vector3 direction(wt.rotation() * Vector3(0.0f, 1.0f, 0.0f)); Vector4 bias(m_bias); instance->setMatrix4(uniMatrix, matrix, SIDES); @@ -319,8 +314,8 @@ void ShadowMap::pointLightUpdate(PipelineContext *context, PointLight *light, li } } -void ShadowMap::spotLightUpdate(PipelineContext *context, SpotLight *light, list &components) { - CommandBuffer *buffer = context->buffer(); +void ShadowMap::spotLightUpdate(PipelineContext &context, SpotLight *light, list &components) { + CommandBuffer *buffer = context.buffer(); Transform *t = light->transform(); Quaternion q(t->worldQuaternion()); @@ -331,20 +326,13 @@ void ShadowMap::spotLightUpdate(PipelineContext *context, SpotLight *light, list float zNear = 0.1f; float zFar = light->attenuationDistance(); - Matrix4 crop(Matrix4::perspective(light->outerAngle() * 2.0f, 1.0f, zNear, zFar)); + Matrix4 crop(Matrix4::perspective(light->outerAngle(), 1.0f, zNear, zFar)); int32_t x = 0; int32_t y = 0; int32_t w = 0; int32_t h = 0; - RenderTarget *shadowTarget = requestShadowTiles(light->uuid(), 1, &x, &y, &w, &h, 1); - - uint32_t pageSize = Texture::maxTextureSize(); - Matrix4 matrix(m_scale * crop * rot); - Vector4 tiles(static_cast(x) / pageSize, - static_cast(y) / pageSize, - static_cast(w) / pageSize, - static_cast(h) / pageSize); + RenderTarget *shadowTarget = requestShadowTiles(context, light->uuid(), 0, &x, &y, &w, &h, 1); buffer->setRenderTarget(shadowTarget); buffer->enableScissor(x, y, w, h); @@ -356,7 +344,7 @@ void ShadowMap::spotLightUpdate(PipelineContext *context, SpotLight *light, list AABBox bb; auto corners = Camera::frustumCorners(false, light->outerAngle() * 2.0f, 1.0f, position, q, zNear, zFar); - RenderList filter = context->frustumCulling(corners, components, bb); + RenderList filter = context.frustumCulling(corners, components, bb); // Draw in the depth buffer from position of the light source for(auto it : filter) { @@ -366,9 +354,15 @@ void ShadowMap::spotLightUpdate(PipelineContext *context, SpotLight *light, list auto instance = light->material(); if(instance) { - Vector3 direction(q * Vector3(0.0f, 0.0f, 1.0f)); Vector4 bias(m_bias); + uint32_t pageSize = Texture::maxTextureSize(); + Matrix4 matrix(m_scale * crop * rot); + Vector4 tiles(static_cast(x) / pageSize, + static_cast(y) / pageSize, + static_cast(w) / pageSize, + static_cast(h) / pageSize); + instance->setMatrix4(uniMatrix, &matrix); instance->setVector4(uniTiles, &tiles); instance->setVector4(uniBias, &bias); @@ -406,7 +400,7 @@ void ShadowMap::cleanShadowCache() { } } -RenderTarget *ShadowMap::requestShadowTiles(uint32_t id, uint32_t lod, int32_t *x, int32_t *y, int32_t *w, int32_t *h, uint32_t count) { +RenderTarget *ShadowMap::requestShadowTiles(PipelineContext &context, uint32_t id, uint32_t lod, int32_t *x, int32_t *y, int32_t *w, int32_t *h, uint32_t count) { auto tile = m_tiles.find(id); if(tile != m_tiles.end()) { for(uint32_t i = 0; i < count; i++) { @@ -420,8 +414,8 @@ RenderTarget *ShadowMap::requestShadowTiles(uint32_t id, uint32_t lod, int32_t * return tile->second.first; } - int32_t width = (SM_RESOLUTION_DEFAULT >> lod); - int32_t height = (SM_RESOLUTION_DEFAULT >> lod); + int32_t width = (m_shadowResolution >> lod); + int32_t height = (m_shadowResolution >> lod); uint32_t columns = MAX(count / 2, 1); uint32_t rows = count / columns; @@ -441,12 +435,14 @@ RenderTarget *ShadowMap::requestShadowTiles(uint32_t id, uint32_t lod, int32_t * if(sub == nullptr) { uint32_t pageSize = Texture::maxTextureSize(); - Texture *map = Engine::objectCreate("shadowAtlas"); + Texture *map = Engine::objectCreate(string("shadowAtlas ") + to_string(m_shadowPages.size())); map->setFormat(Texture::Depth); map->setWidth(pageSize); map->setHeight(pageSize); map->setDepthBits(24); + context.addTextureBuffer(map); + target = Engine::objectCreate(); target->setDepthAttachment(map); diff --git a/engine/src/pipelinetasks/translucent.cpp b/engine/src/pipelinetasks/translucent.cpp index 935e32693..67a20aa8c 100644 --- a/engine/src/pipelinetasks/translucent.cpp +++ b/engine/src/pipelinetasks/translucent.cpp @@ -19,14 +19,14 @@ Translucent::Translucent() : } -void Translucent::exec(PipelineContext *context) { - CommandBuffer *buffer = context->buffer(); +void Translucent::exec(PipelineContext &context) { + CommandBuffer *buffer = context.buffer(); buffer->beginDebugMarker("Translucent Pass"); buffer->setRenderTarget(m_translucentPass); // Transparent pass - context->drawRenderers(CommandBuffer::TRANSLUCENT, context->culledComponents()); + context.drawRenderers(CommandBuffer::TRANSLUCENT, context.culledComponents()); buffer->endDebugMarker(); } diff --git a/modules/editor/shadertools/editor/materialedit.cpp b/modules/editor/shadertools/editor/materialedit.cpp index 5242180d2..06df07e70 100644 --- a/modules/editor/shadertools/editor/materialedit.cpp +++ b/modules/editor/shadertools/editor/materialedit.cpp @@ -39,8 +39,8 @@ class PreviewRender : public PipelineTask { } private: - void exec(PipelineContext *context) override { - CommandBuffer *buffer = context->buffer(); + void exec(PipelineContext &context) override { + CommandBuffer *buffer = context.buffer(); if(m_graph) { buffer->setViewport(0, 0, 128, 128); m_graph->updatePreviews(*buffer); diff --git a/worldeditor/bin/engine/materials/SpotLight.shader b/worldeditor/bin/engine/materials/SpotLight.shader index a72a351a5..6a5f74e75 100644 --- a/worldeditor/bin/engine/materials/SpotLight.shader +++ b/worldeditor/bin/engine/materials/SpotLight.shader @@ -87,7 +87,7 @@ void main (void) { float cosTheta = clamp(dot(l, n), 0.0, 1.0); float shadow = 1.0; - if(uni.shadows > 1.0) { + if(uni.shadows > 0.0) { vec4 offset = uni.tiles; vec4 proj = uni.matrix * vec4(world, 1.0); vec3 coord = (proj.xyz / proj.w); diff --git a/worldeditor/src/screens/scenecomposer/objectcontroller.cpp b/worldeditor/src/screens/scenecomposer/objectcontroller.cpp index fa9953e6c..9ff165d8f 100644 --- a/worldeditor/src/screens/scenecomposer/objectcontroller.cpp +++ b/worldeditor/src/screens/scenecomposer/objectcontroller.cpp @@ -81,20 +81,20 @@ class ViewportRaycast : public PipelineTask { m_resultTarget->setDepthAttachment(m_depth); } - void exec(PipelineContext *context) override { - CommandBuffer *buffer = context->buffer(); + void exec(PipelineContext &context) override { + CommandBuffer *buffer = context.buffer(); buffer->beginDebugMarker("ViewportRaycast"); buffer->setRenderTarget(m_resultTarget); buffer->clearRenderTarget(); - for(auto it : context->culledComponents()) { + for(auto it : context.culledComponents()) { if(it->actor()->hideFlags() & Actor::SELECTABLE) { it->draw(*buffer, CommandBuffer::RAYCAST); } } - for(auto it : context->uiComponents()) { + for(auto it : context.uiComponents()) { if(it->actor()->hideFlags() & Actor::SELECTABLE) { it->draw(*buffer, CommandBuffer::RAYCAST); } @@ -121,7 +121,7 @@ class ViewportRaycast : public PipelineTask { for(auto it : m_dragList) { it->update(); - context->culledComponents().push_back(it); + context.culledComponents().push_back(it); } buffer->endDebugMarker();