Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions engine/includes/components/component.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class ENGINE_EXPORT Component : public Object {
bool isEnabled() const;
virtual void setEnabled(bool enable);

bool isEnabledInHierarchy() const;

bool isStarted() const;
void setStarted(bool started);

Expand Down
1 change: 0 additions & 1 deletion engine/includes/editor/viewport/tasks/gizmorender.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ class GizmoRender : public PipelineTask {
t->setQuaternion(q);
t->setPosition(q * Vector3(0.0f, 0.0f, gNaviCubeDist));

buffer->clearRenderTarget(false);
buffer->setViewport(m_width-gNaviCubeSize, m_height-gNaviCubeSize, gNaviCubeSize, gNaviCubeSize);
buffer->setViewProjection(m_camera->viewMatrix(), m_camera->projectionMatrix());
buffer->drawMesh(PipelineContext::defaultCube(), 0, CommandBuffer::UI, *m_cubeMaterial);
Expand Down
2 changes: 1 addition & 1 deletion engine/includes/editor/viewport/tasks/outlinerender.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Outline : public PipelineTask {

m_outlineTarget->setColorAttachment(0, m_outlineMap);
m_outlineTarget->setDepthAttachment(m_outlineDepth);
m_outlineTarget->setClearFlags(RenderTarget::ClearColor | RenderTarget::ClearDepth);

Material *material = Engine::loadResource<Material>(".embedded/outline.shader");
if(material) {
Expand Down Expand Up @@ -83,7 +84,6 @@ class Outline : public PipelineTask {
buffer->beginDebugMarker("Outline");

buffer->setRenderTarget(m_outlineTarget);
buffer->clearRenderTarget();
RenderList filter;
for(auto actor : m_controller->selected()) {
for(auto it : m_context->culledComponents()) {
Expand Down
4 changes: 3 additions & 1 deletion engine/includes/pipelinecontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class ENGINE_EXPORT PipelineContext : public Object {

std::list<std::pair<const PostProcessSettings *, float> > &culledPostEffectSettings();

void frustumCulling(const Frustum &frustum, const RenderList &in, RenderList &out, AABBox &box);
void frustumCulling(const Frustum &frustum, const RenderList &in, RenderList &out, AABBox *box = nullptr);

void setPipeline(Pipeline *pipeline);
void insertRenderTask(PipelineTask *task, PipelineTask *before = nullptr);
Expand Down Expand Up @@ -131,6 +131,8 @@ class ENGINE_EXPORT PipelineContext : public Object {

bool m_frustumCulling;

bool m_renderablesSorting;

};

#endif // PIPELINECONTEXT
25 changes: 24 additions & 1 deletion engine/includes/resources/rendertarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ class ENGINE_EXPORT RenderTarget : public Resource {

A_NOPROPERTIES()
A_NOMETHODS()

enum ClearFlags {
DoNothing = 0,
ClearColor,
ClearDepth
};

A_NOENUMS()

public:
Expand All @@ -24,6 +31,12 @@ class ENGINE_EXPORT RenderTarget : public Resource {
Texture *depthAttachment() const;
virtual void setDepthAttachment(Texture *texture);

int clearFlags() const;
void setClearFlags(int flags);

void clearRegion(int32_t &x, int32_t &y, int32_t &width, int32_t &height) const;
void setClearRegion(int32_t x, int32_t y, int32_t width, int32_t height);

protected:
void makeNative();
bool isNative() const;
Expand All @@ -36,7 +49,17 @@ class ENGINE_EXPORT RenderTarget : public Resource {

Texture *m_depth;

bool m_native = false;
int m_clearFlags;

int m_clearX;

int m_clearY;

int m_clearWidth;

int m_clearHeigh;

bool m_native;

};

Expand Down
10 changes: 10 additions & 0 deletions engine/src/components/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ bool Component::isEnabled() const {
void Component::setEnabled(bool enabled) {
m_enable = enabled;
}
/*!
Returns false in case of one of Actors in top hierarchy or this component was disabled; otherwise returns true.
*/
bool Component::isEnabledInHierarchy() const {
Actor *actor = Component::actor();
if(actor) {
return actor->isEnabledInHierarchy() && m_enable;
}
return m_enable;
}
/*!
Returns true if the component is flagged as started; otherwise returns false.
\note This method is used for internal purposes and shouldn't be called manually.
Expand Down
87 changes: 43 additions & 44 deletions engine/src/pipelinecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ PipelineContext::PipelineContext() :
m_camera(nullptr),
m_width(64),
m_height(64),
m_frustumCulling(true) {
m_frustumCulling(true),
m_renderablesSorting(true) {

Material *mtl = Engine::loadResource<Material>(".embedded/DefaultPostEffect.shader");
if(mtl) {
Expand All @@ -65,6 +66,11 @@ PipelineContext::PipelineContext() :

PipelineContext::~PipelineContext() {
m_textureBuffers.clear();

m_defaultTarget->deleteLater();
m_buffer->deleteLater();

delete m_finalMaterial;
}
/*!
Retrieves the command buffer associated with the pipeline context.
Expand All @@ -83,18 +89,15 @@ void PipelineContext::draw(Camera *camera) {
setCurrentCamera(camera);

for(auto it : m_renderTasks) {
if(it) {
if(it->isEnabled()) {
it->exec();
}
if(it && it->isEnabled()) {
it->exec();
}
}

m_finalMaterial->setTexture(gTexture, resultTexture());

// Finish
m_buffer->setRenderTarget(m_defaultTarget);
m_buffer->clearRenderTarget();
m_buffer->drawMesh(defaultPlane(), 0, CommandBuffer::UI, *m_finalMaterial);

for(auto it : m_postObservers) {
Expand Down Expand Up @@ -201,58 +204,50 @@ void PipelineContext::analizeGraph() {
// Add renderables
m_sceneComponents.clear();
for(auto it : RenderSystem::renderables()) {
if(it->isEnabled()) {
Actor *actor = it->actor();
if(actor && (actor->world() == m_world) && actor->isEnabledInHierarchy()) {
if(update) {
it->update();
}
m_sceneComponents.push_back(it);
if(it->world() == m_world && it->isEnabledInHierarchy()) {
if(update) {
it->update();
}
m_sceneComponents.push_back(it);
}
}
// Renderables cull and sort
// Renderables frustum culling
if(m_frustumCulling) {
frustumCulling(camera->frustum(), m_sceneComponents, m_culledComponents, m_worldBound);
frustumCulling(camera->frustum(), m_sceneComponents, m_culledComponents, &m_worldBound);
}

Vector3 origin = cameraTransform->position();
culledComponents().sort([origin](const Renderable *left, const Renderable *right) {
int p1 = left->priority();
int p2 = right->priority();
if(p1 == p2) {
const Matrix4 &m1 = left->transform()->worldTransform();
const Matrix4 &m2 = right->transform()->worldTransform();

return origin.dot(Vector3(m1[12], m1[13], m1[14])) < origin.dot(Vector3(m2[12], m2[13], m2[14]));
}
return p1 < p2;
});
// Renderables sort
if(m_renderablesSorting) {
Vector3 origin(cameraTransform->worldPosition());
culledComponents().sort([origin](const Renderable *left, const Renderable *right) {
int p1 = left->priority();
int p2 = right->priority();
if(p1 == p2) {
const Matrix4 &m1 = left->transform()->worldTransform();
const Matrix4 &m2 = right->transform()->worldTransform();

return origin.dot(Vector3(m1[12], m1[13], m1[14])) < origin.dot(Vector3(m2[12], m2[13], m2[14]));
}
return p1 < p2;
});
}

// Add lights
m_sceneLights.clear();
for(auto it : RenderSystem::lights()) {
if(it->isEnabled()) {
Actor *actor = it->actor();
if(actor && actor->isEnabledInHierarchy()) {
if((actor->world() == m_world)) {
m_sceneLights.push_back(it);
}
}
if(it->world() == m_world && it->isEnabledInHierarchy()) {
m_sceneLights.push_back(it);
}
}

// Add Post process volumes
m_culledPostProcessSettings.clear();
for(auto it : RenderSystem::postProcessVolumes()) {
if(it->isEnabled()) {
Actor *actor = it->actor();
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()));
if(it->world() == m_world && it->isEnabledInHierarchy()) {
if(!it->unbound() && !it->bound().intersect(cameraTransform->worldPosition(), camera->nearPlane())) {
continue;
}
m_culledPostProcessSettings.push_back(std::make_pair(it->settings(), it->blendWeight()));
}
}

Expand Down Expand Up @@ -469,15 +464,19 @@ 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.
*/
void PipelineContext::frustumCulling(const Frustum &frustum, const RenderList &in, RenderList &out, AABBox &box) {
box.extent = Vector3(-1.0f);
void PipelineContext::frustumCulling(const Frustum &frustum, const RenderList &in, RenderList &out, AABBox *box) {
if(box) {
box->extent = Vector3(-1.0f);
}

out.clear();
for(auto it : in) {
AABBox bb = it->bound();
if(bb.extent.x < 0.0f || frustum.contains(bb)) {
out.push_back(it);
box.encapsulate(bb);
if(box) {
box->encapsulate(bb);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion engine/src/pipelinetasks/bloom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Bloom::Bloom() :
m_blurTempTexture->setFlags(Texture::Render);

m_blurTempTarget->setColorAttachment(0, m_blurTempTexture);
m_blurTempTarget->setClearFlags(RenderTarget::ClearColor);

if(blur) {
for(uint8_t i = 0; i < BLOOM_PASSES; i++) {
Expand Down Expand Up @@ -117,7 +118,6 @@ void Bloom::exec() {

for(uint8_t i = 0; i < BLOOM_PASSES; i++) {
buffer->setRenderTarget(m_blurTempTarget);
buffer->clearRenderTarget(true, Vector4(0.0f), false, 1.0f);
buffer->drawMesh(PipelineContext::defaultPlane(), 0, CommandBuffer::UI, *m_bloomPasses[i].blurMaterialH);

buffer->setRenderTarget(m_resultTarget);
Expand Down
3 changes: 2 additions & 1 deletion engine/src/pipelinetasks/gbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ GBuffer::GBuffer() :
m_gbuffer->setColorAttachment(i, m_outputs[i].second);
}
}

m_gbuffer->setClearFlags(RenderTarget::ClearColor | RenderTarget::ClearDepth);
}

void GBuffer::exec() {
Expand All @@ -62,7 +64,6 @@ void GBuffer::exec() {
m_context->cameraReset();

buffer->setRenderTarget(m_gbuffer);
buffer->clearRenderTarget();

m_context->drawRenderers(m_context->culledComponents(), CommandBuffer::DEFAULT);

Expand Down
Loading