mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:44:01 +02:00
CLeaning up the code for the RenderableLightEntityItem
This commit is contained in:
parent
92a9037b07
commit
0c45627d94
7 changed files with 198 additions and 183 deletions
|
@ -11,9 +11,7 @@
|
|||
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
#include <gpu/Batch.h>
|
||||
|
||||
#include <DeferredLightingEffect.h>
|
||||
#include <GLMHelpers.h>
|
||||
#include <PerfStat.h>
|
||||
|
||||
|
@ -29,16 +27,68 @@ RenderableLightEntityItem::RenderableLightEntityItem(const EntityItemID& entityI
|
|||
{
|
||||
}
|
||||
|
||||
void RenderableLightEntityItem::updateLightFromEntity(render::PendingChanges& pendingChanges) {
|
||||
bool RenderableLightEntityItem::addToScene(EntityItemPointer self, std::shared_ptr<render::Scene> scene, render::PendingChanges& pendingChanges) {
|
||||
_myItem = scene->allocateID();
|
||||
|
||||
auto renderItem = std::make_shared<LightPayload>();
|
||||
updateRenderItemFromEntity(renderItem.get());
|
||||
|
||||
auto renderPayload = std::make_shared<LightPayload::Payload>(renderItem);
|
||||
|
||||
render::Item::Status::Getters statusGetters;
|
||||
makeEntityItemStatusGetters(self, statusGetters);
|
||||
renderPayload->addStatusGetters(statusGetters);
|
||||
|
||||
pendingChanges.resetItem(_myItem, renderPayload);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderableLightEntityItem::somethingChangedNotification() {
|
||||
if (_lightPropertiesChanged) {
|
||||
notifyChanged();
|
||||
}
|
||||
LightEntityItem::somethingChangedNotification();
|
||||
}
|
||||
|
||||
void RenderableLightEntityItem::removeFromScene(EntityItemPointer self, std::shared_ptr<render::Scene> scene, render::PendingChanges& pendingChanges) {
|
||||
pendingChanges.removeItem(_myItem);
|
||||
render::Item::clearID(_myItem);
|
||||
}
|
||||
|
||||
void RenderableLightEntityItem::locationChanged(bool tellPhysics) {
|
||||
EntityItem::locationChanged(tellPhysics);
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
void RenderableLightEntityItem::dimensionsChanged() {
|
||||
EntityItem::dimensionsChanged();
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
void RenderableLightEntityItem::checkFading() {
|
||||
bool transparent = isTransparent();
|
||||
if (transparent != _prevIsTransparent) {
|
||||
notifyChanged();
|
||||
_isFading = false;
|
||||
_prevIsTransparent = transparent;
|
||||
}
|
||||
}
|
||||
|
||||
void RenderableLightEntityItem::notifyChanged() {
|
||||
|
||||
if (!render::Item::isValidID(_myItem)) {
|
||||
return;
|
||||
}
|
||||
|
||||
render::PendingChanges pendingChanges;
|
||||
render::ScenePointer scene = AbstractViewStateInterface::instance()->getMain3DScene();
|
||||
|
||||
pendingChanges.updateItem<LightRenderItem>(_myItem, [this](LightRenderItem& data) {
|
||||
data.updateLightFromEntity(this);
|
||||
});
|
||||
updateLightFromEntity(pendingChanges);
|
||||
|
||||
scene->enqueuePendingChanges(pendingChanges);
|
||||
}
|
||||
|
||||
/*
|
||||
void RenderableLightEntityItem::render(RenderArgs* args) {
|
||||
PerformanceTimer perfTimer("RenderableLightEntityItem::render");
|
||||
|
@ -72,75 +122,54 @@ bool RenderableLightEntityItem::findDetailedRayIntersection(const glm::vec3& ori
|
|||
}
|
||||
|
||||
|
||||
|
||||
namespace render {
|
||||
template <> const ItemKey payloadGetKey(const LightRenderItem::Pointer& payload) {
|
||||
return ItemKey::Builder::light();
|
||||
void RenderableLightEntityItem::updateLightFromEntity(render::PendingChanges& pendingChanges) {
|
||||
if (!render::Item::isValidID(_myItem)) {
|
||||
return;
|
||||
}
|
||||
|
||||
template <> const Item::Bound payloadGetBound(const LightRenderItem::Pointer& payload) {
|
||||
if (payload) {
|
||||
return payload->_bound;
|
||||
}
|
||||
return render::Item::Bound();
|
||||
}
|
||||
template <> void payloadRender(const LightRenderItem::Pointer& payload, RenderArgs* args) {
|
||||
if (args) {
|
||||
if (payload) {
|
||||
payload->render(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pendingChanges.updateItem<LightPayload>(_myItem, [this](LightPayload& data) {
|
||||
this->updateRenderItemFromEntity(&data);
|
||||
});
|
||||
}
|
||||
|
||||
LightRenderItem::LightRenderItem() :
|
||||
_light(std::make_shared<model::Light>())
|
||||
{
|
||||
}
|
||||
|
||||
void LightRenderItem::updateLightFromEntity(RenderableLightEntityItem* entity) {
|
||||
_light->setPosition(entity->getPosition());
|
||||
_light->setOrientation(entity->getRotation());
|
||||
void RenderableLightEntityItem::updateRenderItemFromEntity(LightPayload* lightPayload) {
|
||||
auto entity = this;
|
||||
auto light = lightPayload->editLight();
|
||||
light->setPosition(entity->getPosition());
|
||||
light->setOrientation(entity->getRotation());
|
||||
|
||||
bool success;
|
||||
_bound = entity->getAABox(success);
|
||||
lightPayload->editBound() = entity->getAABox(success);
|
||||
if (!success) {
|
||||
_bound = render::Item::Bound();
|
||||
lightPayload->editBound() = render::Item::Bound();
|
||||
}
|
||||
|
||||
glm::vec3 dimensions = entity->getDimensions();
|
||||
float largestDiameter = glm::max(dimensions.x, dimensions.y, dimensions.z);
|
||||
_light->setMaximumRadius(largestDiameter / 2.0f);
|
||||
light->setMaximumRadius(largestDiameter / 2.0f);
|
||||
|
||||
_light->setColor(toGlm(entity->getXColor()));
|
||||
light->setColor(toGlm(entity->getXColor()));
|
||||
|
||||
float intensity = entity->getIntensity();//* entity->getFadingRatio();
|
||||
_light->setIntensity(intensity);
|
||||
light->setIntensity(intensity);
|
||||
|
||||
_light->setFalloffRadius(entity->getFalloffRadius());
|
||||
light->setFalloffRadius(entity->getFalloffRadius());
|
||||
|
||||
|
||||
float exponent = entity->getExponent();
|
||||
float cutoff = glm::radians(entity->getCutoff());
|
||||
if (!entity->getIsSpotlight()) {
|
||||
_light->setType(model::Light::POINT);
|
||||
light->setType(model::Light::POINT);
|
||||
} else {
|
||||
_light->setType(model::Light::SPOT);
|
||||
light->setType(model::Light::SPOT);
|
||||
|
||||
_light->setSpotAngle(cutoff);
|
||||
_light->setSpotExponent(exponent);
|
||||
light->setSpotAngle(cutoff);
|
||||
light->setSpotExponent(exponent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void LightRenderItem::render(RenderArgs* args) {
|
||||
|
||||
//updateLightFromEntity();
|
||||
|
||||
DependencyManager::get<DeferredLightingEffect>()->addLight(_light);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -13,32 +13,9 @@
|
|||
#define hifi_RenderableLightEntityItem_h
|
||||
|
||||
#include <LightEntityItem.h>
|
||||
#include <model/Light.h>
|
||||
#include <LightPayload.h>
|
||||
#include "RenderableEntityItem.h"
|
||||
|
||||
class RenderableLightEntityItem;
|
||||
|
||||
class LightRenderItem {
|
||||
public:
|
||||
using Payload = render::Payload<LightRenderItem>;
|
||||
using Pointer = Payload::DataPointer;
|
||||
|
||||
model::LightPointer _light;
|
||||
|
||||
render::Item::Bound _bound;
|
||||
|
||||
LightRenderItem();
|
||||
void render(RenderArgs* args);
|
||||
|
||||
void updateLightFromEntity(RenderableLightEntityItem* entity);
|
||||
|
||||
};
|
||||
|
||||
namespace render {
|
||||
template <> const ItemKey payloadGetKey(const LightRenderItem::Pointer& payload);
|
||||
template <> const Item::Bound payloadGetBound(const LightRenderItem::Pointer& payload);
|
||||
template <> void payloadRender(const LightRenderItem::Pointer& payload, RenderArgs* args);
|
||||
}
|
||||
|
||||
class RenderableLightEntityItem : public LightEntityItem {
|
||||
public:
|
||||
|
@ -53,67 +30,18 @@ public:
|
|||
|
||||
void updateLightFromEntity(render::PendingChanges& pendingChanges);
|
||||
|
||||
virtual bool addToScene(EntityItemPointer self, std::shared_ptr<render::Scene> scene, render::PendingChanges& pendingChanges) override {
|
||||
_myItem = scene->allocateID();
|
||||
virtual bool addToScene(EntityItemPointer self, std::shared_ptr<render::Scene> scene, render::PendingChanges& pendingChanges) override;
|
||||
|
||||
auto renderItem = std::make_shared<LightRenderItem>();
|
||||
renderItem->updateLightFromEntity(this);
|
||||
virtual void somethingChangedNotification() override;
|
||||
virtual void removeFromScene(EntityItemPointer self, std::shared_ptr<render::Scene> scene, render::PendingChanges& pendingChanges) override;
|
||||
|
||||
auto renderPayload = std::make_shared<LightRenderItem::Payload>(renderItem);
|
||||
virtual void locationChanged(bool tellPhysics = true) override;
|
||||
|
||||
render::Item::Status::Getters statusGetters;
|
||||
makeEntityItemStatusGetters(self, statusGetters);
|
||||
renderPayload->addStatusGetters(statusGetters);
|
||||
virtual void dimensionsChanged() override;
|
||||
|
||||
pendingChanges.resetItem(_myItem, renderPayload);
|
||||
void checkFading();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void somethingChangedNotification() override {
|
||||
if (_lightPropertiesChanged) {
|
||||
notifyChanged();
|
||||
}
|
||||
LightEntityItem::somethingChangedNotification();
|
||||
}
|
||||
|
||||
virtual void removeFromScene(EntityItemPointer self, std::shared_ptr<render::Scene> scene, render::PendingChanges& pendingChanges) override {
|
||||
pendingChanges.removeItem(_myItem);
|
||||
render::Item::clearID(_myItem);
|
||||
}
|
||||
|
||||
virtual void locationChanged(bool tellPhysics = true) override {
|
||||
EntityItem::locationChanged(tellPhysics);
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
virtual void dimensionsChanged() override {
|
||||
EntityItem::dimensionsChanged();
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
void checkFading() {
|
||||
bool transparent = isTransparent();
|
||||
if (transparent != _prevIsTransparent) {
|
||||
notifyChanged();
|
||||
_isFading = false;
|
||||
_prevIsTransparent = transparent;
|
||||
}
|
||||
}
|
||||
|
||||
void notifyChanged() {
|
||||
|
||||
if (!render::Item::isValidID(_myItem)) {
|
||||
return;
|
||||
}
|
||||
|
||||
render::PendingChanges pendingChanges;
|
||||
render::ScenePointer scene = AbstractViewStateInterface::instance()->getMain3DScene();
|
||||
|
||||
updateLightFromEntity(pendingChanges);
|
||||
|
||||
scene->enqueuePendingChanges(pendingChanges);
|
||||
}
|
||||
void notifyChanged();
|
||||
|
||||
private:
|
||||
bool _prevIsTransparent { isTransparent() };
|
||||
|
@ -121,6 +49,8 @@ private:
|
|||
|
||||
// Dirty flag turn true when either setSubClassProperties or readEntitySubclassDataFromBuffer is changing a value
|
||||
|
||||
void updateRenderItemFromEntity(LightPayload* lightPayload);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -425,7 +425,6 @@ void PrepareDeferred::run(const SceneContextPointer& sceneContext, const RenderC
|
|||
outputs.edit0() = _deferredFramebuffer;
|
||||
outputs.edit1() = _deferredFramebuffer->getLightingFramebuffer();
|
||||
|
||||
|
||||
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||
batch.enableStereo(false);
|
||||
batch.setViewportTransform(args->_viewport);
|
||||
|
@ -457,7 +456,8 @@ void RenderDeferredSetup::run(const render::SceneContextPointer& sceneContext, c
|
|||
const SubsurfaceScatteringResourcePointer& subsurfaceScatteringResource) {
|
||||
|
||||
auto args = renderContext->args;
|
||||
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||
auto& batch = (*args->_batch);
|
||||
// gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||
|
||||
// Framebuffer copy operations cannot function as multipass stereo operations.
|
||||
batch.enableStereo(false);
|
||||
|
@ -567,7 +567,7 @@ void RenderDeferredSetup::run(const render::SceneContextPointer& sceneContext, c
|
|||
batch.setResourceTexture(SKYBOX_MAP_UNIT, nullptr);
|
||||
}
|
||||
batch.setResourceTexture(SHADOW_MAP_UNIT, nullptr);
|
||||
});
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
|
@ -589,9 +589,10 @@ void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext,
|
|||
return;
|
||||
}
|
||||
auto args = renderContext->args;
|
||||
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||
auto& batch = (*args->_batch);
|
||||
// gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||
// Framebuffer copy operations cannot function as multipass stereo operations.
|
||||
batch.enableStereo(false);
|
||||
/// batch.enableStereo(false);
|
||||
|
||||
// THe main viewport is assumed to be the mono viewport (or the 2 stereo faces side by side within that viewport)
|
||||
auto viewport = args->_viewport;
|
||||
|
@ -730,12 +731,13 @@ void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext,
|
|||
}
|
||||
}*/
|
||||
}
|
||||
});
|
||||
// });
|
||||
}
|
||||
|
||||
void RenderDeferredCleanup::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext) {
|
||||
auto args = renderContext->args;
|
||||
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||
auto& batch = (*args->_batch);
|
||||
// gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||
// Probably not necessary in the long run because the gpu layer would unbound this texture if used as render target
|
||||
batch.setResourceTexture(DEFERRED_BUFFER_COLOR_UNIT, nullptr);
|
||||
batch.setResourceTexture(DEFERRED_BUFFER_NORMAL_UNIT, nullptr);
|
||||
|
@ -752,7 +754,7 @@ void RenderDeferredCleanup::run(const render::SceneContextPointer& sceneContext,
|
|||
batch.setUniformBuffer(SCATTERING_PARAMETERS_BUFFER_SLOT, nullptr);
|
||||
// batch.setUniformBuffer(LIGHTING_MODEL_BUFFER_SLOT, nullptr);
|
||||
batch.setUniformBuffer(DEFERRED_FRAME_TRANSFORM_BUFFER_SLOT, nullptr);
|
||||
});
|
||||
// });
|
||||
|
||||
auto deferredLightingEffect = DependencyManager::get<DeferredLightingEffect>();
|
||||
|
||||
|
@ -788,9 +790,14 @@ void RenderDeferred::run(const SceneContextPointer& sceneContext, const RenderCo
|
|||
_gpuTimer = std::make_shared < gpu::RangeTimer>(__FUNCTION__);
|
||||
}
|
||||
|
||||
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||
auto previousBatch = args->_batch;
|
||||
gpu::Batch batch;
|
||||
// f(batch);
|
||||
args->_batch = &batch;
|
||||
|
||||
// gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||
_gpuTimer->begin(batch);
|
||||
});
|
||||
// });
|
||||
|
||||
setupJob.run(sceneContext, renderContext, deferredTransform, deferredFramebuffer, lightingModel, surfaceGeometryFramebuffer, ssaoFramebuffer, subsurfaceScatteringResource);
|
||||
|
||||
|
@ -798,10 +805,14 @@ void RenderDeferred::run(const SceneContextPointer& sceneContext, const RenderCo
|
|||
|
||||
cleanupJob.run(sceneContext, renderContext);
|
||||
|
||||
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||
// gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||
_gpuTimer->end(batch);
|
||||
});
|
||||
// });
|
||||
|
||||
args->_context->appendFrameBatch(batch);
|
||||
args->_batch = previousBatch;
|
||||
|
||||
|
||||
auto config = std::static_pointer_cast<Config>(renderContext->jobConfig);
|
||||
config->setGPUBatchRunTime(_gpuTimer->getGPUAverage(), _gpuTimer->getBatchAverage());
|
||||
}
|
||||
|
|
45
libraries/render-utils/src/LightPayload.cpp
Normal file
45
libraries/render-utils/src/LightPayload.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
//
|
||||
// LightPayload.cpp
|
||||
//
|
||||
// Created by Sam Gateau on 9/6/16.
|
||||
// Copyright 2016 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
#include "LightPayload.h"
|
||||
|
||||
|
||||
#include <gpu/Batch.h>
|
||||
#include "DeferredLightingEffect.h"
|
||||
|
||||
|
||||
namespace render {
|
||||
template <> const ItemKey payloadGetKey(const LightPayload::Pointer& payload) {
|
||||
return ItemKey::Builder::light();
|
||||
}
|
||||
|
||||
template <> const Item::Bound payloadGetBound(const LightPayload::Pointer& payload) {
|
||||
if (payload) {
|
||||
return payload->editBound();
|
||||
}
|
||||
return render::Item::Bound();
|
||||
}
|
||||
template <> void payloadRender(const LightPayload::Pointer& payload, RenderArgs* args) {
|
||||
if (args) {
|
||||
if (payload) {
|
||||
payload->render(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LightPayload::LightPayload() :
|
||||
_light(std::make_shared<model::Light>())
|
||||
{
|
||||
}
|
||||
|
||||
void LightPayload::render(RenderArgs* args) {
|
||||
|
||||
DependencyManager::get<DeferredLightingEffect>()->addLight(_light);
|
||||
}
|
41
libraries/render-utils/src/LightPayload.h
Normal file
41
libraries/render-utils/src/LightPayload.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
//
|
||||
// LightPayload.h
|
||||
//
|
||||
// Created by Sam Gateau on 9/6/16.
|
||||
// Copyright 2016 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_LightPayload_h
|
||||
#define hifi_LightPayload_h
|
||||
|
||||
|
||||
#include <model/Light.h>
|
||||
#include <render/Item.h>
|
||||
|
||||
|
||||
class LightPayload {
|
||||
public:
|
||||
using Payload = render::Payload<LightPayload>;
|
||||
using Pointer = Payload::DataPointer;
|
||||
|
||||
LightPayload();
|
||||
void render(RenderArgs* args);
|
||||
|
||||
model::LightPointer editLight() { return _light; }
|
||||
render::Item::Bound& editBound() { return _bound; }
|
||||
|
||||
protected:
|
||||
model::LightPointer _light;
|
||||
render::Item::Bound _bound;
|
||||
};
|
||||
|
||||
namespace render {
|
||||
template <> const ItemKey payloadGetKey(const LightPayload::Pointer& payload);
|
||||
template <> const Item::Bound payloadGetBound(const LightPayload::Pointer& payload);
|
||||
template <> void payloadRender(const LightPayload::Pointer& payload, RenderArgs* args);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -47,7 +47,7 @@ void main(void) {
|
|||
texCoord += texcoordFrameTransform.xy;*/
|
||||
|
||||
vec4 fragPosition = unpackDeferredPositionFromZeye(texCoord);
|
||||
DeferredFragment frag = unpackDeferredFragmentNoPositionNoAmbient(texCoord);
|
||||
DeferredFragment frag = unpackDeferredFragmentNoPosition(texCoord);
|
||||
|
||||
if (frag.mode == FRAG_MODE_UNLIT) {
|
||||
discard;
|
||||
|
|
|
@ -109,47 +109,6 @@ Item {
|
|||
}
|
||||
]
|
||||
}
|
||||
|
||||
PlotPerf {
|
||||
title: "Batch Timing"
|
||||
height: parent.evalEvenHeight()
|
||||
object: parent.drawOpaqueConfig
|
||||
valueUnit: "ms"
|
||||
valueScale: 1
|
||||
valueNumDigits: "4"
|
||||
plots: [
|
||||
{
|
||||
object: Render.getConfig("OpaqueRangeTimer"),
|
||||
prop: "gpuBatchTime",
|
||||
label: "Opaque",
|
||||
color: "#FFFFFF"
|
||||
},
|
||||
{
|
||||
object: Render.getConfig("LinearDepth"),
|
||||
prop: "gpuBatchTime",
|
||||
label: "LinearDepth",
|
||||
color: "#00FF00"
|
||||
},{
|
||||
object: Render.getConfig("SurfaceGeometry"),
|
||||
prop: "gpuBatchTime",
|
||||
label: "SurfaceGeometry",
|
||||
color: "#00FFFF"
|
||||
},
|
||||
{
|
||||
object: Render.getConfig("RenderDeferred"),
|
||||
prop: "gpuBatchTime",
|
||||
label: "DeferredLighting",
|
||||
color: "#FF00FF"
|
||||
}
|
||||
,
|
||||
{
|
||||
object: Render.getConfig("ToneAndPostRangeTimer"),
|
||||
prop: "gpuBatchTime",
|
||||
label: "tone and post",
|
||||
color: "#FF0000"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue