cleaning up the comments from review and trying something to adress the issue that showed up on i5

This commit is contained in:
samcake 2016-10-07 16:04:19 -07:00
parent 92d71a2e37
commit 8a44140e6b
10 changed files with 69 additions and 102 deletions

View file

@ -89,30 +89,6 @@ void RenderableLightEntityItem::notifyChanged() {
scene->enqueuePendingChanges(pendingChanges);
}
/*
void RenderableLightEntityItem::render(RenderArgs* args) {
PerformanceTimer perfTimer("RenderableLightEntityItem::render");
assert(getType() == EntityTypes::Light);
checkFading();
glm::vec3 position = getPosition();
glm::vec3 dimensions = getDimensions();
glm::quat rotation = getRotation();
float largestDiameter = glm::compMax(dimensions);
// DependencyManager::get<DeferredLightingEffect>()->addLight(_light);
#ifdef WANT_DEBUG
Q_ASSERT(args->_batch);
gpu::Batch& batch = *args->_batch;
batch.setModelTransform(getTransformToCenter());
DependencyManager::get<GeometryCache>()->renderWireSphere(batch, 0.5f, 15, 15, glm::vec4(color, 1.0f));
#endif
};
*/
bool RenderableLightEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
bool& keepSearching, OctreeElementPointer& element, float& distance,
BoxFace& face, glm::vec3& surfaceNormal,

View file

@ -90,7 +90,7 @@ public:
virtual EntityItemProperties getProperties(EntityPropertyFlags desiredProperties = EntityPropertyFlags()) const;
/// returns true if something changed
// THis function calls setSubClass properties and detects if any property changes value.
// This function calls setSubClass properties and detects if any property changes value.
// If something changed then the "somethingChangedNotification" calls happens
virtual bool setProperties(const EntityItemProperties& properties);

View file

@ -109,7 +109,7 @@ protected:
float _cutoff { DEFAULT_CUTOFF };
// Dirty flag turn true when either light properties is changing values.
// THis gets back to false in the somethingChangedNotification() call
// This gets back to false in the somethingChangedNotification() call
// Which is called after a setProperties() or a readEntitySubClassFromBUfferCall on the entity.
bool _lightPropertiesChanged { false };

View file

@ -27,7 +27,6 @@ void GLBackend::do_beginQuery(const Batch& batch, size_t paramOffset) {
if (glquery) {
PROFILE_RANGE_BEGIN(glquery->_profileRangeId, query->getName().c_str(), 0xFFFF7F00);
//glGetInteger64v(GL_TIMESTAMP, (GLint64*)&glquery->_batchElapsedTime);
glquery->_batchElapsedTime = usecTimestampNow() * 1000;
if (timeElapsed) {
glBeginQuery(GL_TIME_ELAPSED, glquery->_endqo);
@ -47,10 +46,8 @@ void GLBackend::do_endQuery(const Batch& batch, size_t paramOffset) {
} else {
glQueryCounter(glquery->_endqo, GL_TIMESTAMP);
}
GLint64 now;
//glGetInteger64v(GL_TIMESTAMP, &now);
now = usecTimestampNow() * 1000;
GLint64 now = usecTimestampNow() * 1000;
glquery->_batchElapsedTime = now - glquery->_batchElapsedTime;
PROFILE_RANGE_END(glquery->_profileRangeId);

View file

@ -44,7 +44,6 @@ void Light::setType(Type type) {
}
updateLightRadius();
}
updateVolumeGeometry();
}
@ -89,7 +88,6 @@ void Light::setMaximumRadius(float radius) {
}
_lightSchemaBuffer.edit().volume.radius = radius;
updateLightRadius();
updateVolumeGeometry();
}
void Light::updateLightRadius() {
@ -125,8 +123,6 @@ void Light::setSpotAngle(float angle) {
if (isSpot()) {
_lightSchemaBuffer.edit().volume.spotCos = _spotCos;
}
updateVolumeGeometry();
}
void Light::setSpotExponent(float exponent) {
@ -162,14 +158,3 @@ void Light::setAmbientMapNumMips(uint16_t numMips) {
_ambientSchemaBuffer.edit().mapNumMips = (float)numMips;
}
void Light::updateVolumeGeometry() {
// enlarge the scales slightly to account for tesselation
/* const float SCALE_EXPANSION = 0.05f;
glm::vec4 volumeGeometry(0.0f, 0.0f, 0.0f, getMaximumRadius() * (1.0f + SCALE_EXPANSION));
if (getType() == SPOT) {
const float TANGENT_LENGTH_SCALE = 0.666f;
volumeGeometry = glm::vec4(getSpotAngleCosSin(), TANGENT_LENGTH_SCALE * tanf(0.5f * getSpotAngle()), volumeGeometry.w);
}
editSchema()._volumeGeometry = volumeGeometry;*/
}

View file

@ -149,7 +149,7 @@ public:
void setAmbientMapNumMips(uint16_t numMips);
uint16_t getAmbientMapNumMips() const { return (uint16_t) _ambientSchemaBuffer->mapNumMips; }
// LIght Schema
// Light Schema
class LightSchema {
public:
LightVolume volume;
@ -158,8 +158,8 @@ public:
class AmbientSchema {
public:
float intensity { 0.f };
float mapNumMips { 0.f };
float intensity { 0.0f };
float mapNumMips { 0.0f };
float spare1;
float spare2;
gpu::SphericalHarmonics ambientSphere;
@ -168,27 +168,6 @@ public:
using LightSchemaBuffer = gpu::StructBuffer<LightSchema>;
using AmbientSchemaBuffer = gpu::StructBuffer<AmbientSchema>;
// Schema to access the attribute values of the light
/* class Schema {
public:
Vec4 _position{0.0f, 0.0f, 0.0f, 1.0f};
Vec3 _direction{0.0f, 0.0f, -1.0f};
float _ambientIntensity{0.0f};
Color _color{1.0f};
float _intensity{1.0f};
Vec4 _attenuation{0.1f, 1.0f, 0.0f, 0.0f};
Vec4 _spot{0.0f, 0.0f, 0.0f, 0.0f};
//Vec4 _shadow{0.0f};
float _ambientMapNumMips{ 0.0f };
Vec3 _control{ 0.0f, 0.0f, 0.0f };
Vec4 _volumeGeometry { 1.f };
gpu::SphericalHarmonics _ambientSphere;
};
*/
const LightSchemaBuffer& getLightSchemaBuffer() const { return _lightSchemaBuffer; }
const AmbientSchemaBuffer& getAmbientSchemaBuffer() const { return _ambientSchemaBuffer; }
@ -207,7 +186,6 @@ protected:
float _spotCos { -1.0f }; // stored here to be able to reset the spot angle when turning the type spot on/off
void updateLightRadius();
void updateVolumeGeometry();
};
typedef std::shared_ptr< Light > LightPointer;

View file

@ -1,5 +1,5 @@
<!
// LightCluserGrid.slh
// LightClusterGrid.slh
//
// Created by Sam Gateau on 9/8/16.
// Copyright 2013 High Fidelity, Inc.

View file

@ -84,44 +84,57 @@ LightClusters::LightClusters() :
_lightIndicesBuffer(std::make_shared<gpu::Buffer>()),
_clusterGridBuffer(/*std::make_shared<gpu::Buffer>(), */gpu::Element::INDEX_INT32),
_clusterContentBuffer(/*std::make_shared<gpu::Buffer>(), */gpu::Element::INDEX_INT32) {
auto dims = _frustumGridBuffer.edit().dims;
_frustumGridBuffer.edit().dims = ivec3(0); // make sure we go through the full reset of the dimensionts ion the setDImensions call
setDimensions(dims, MAX_GRID_DIMENSIONS.w);
}
void LightClusters::setDimensions(glm::uvec3 gridDims, uint32_t listBudget) {
ivec3 configDimensions;
auto gridBudget = MAX_GRID_DIMENSIONS.w;
configDimensions.x = std::min(MAX_GRID_DIMENSIONS.x, gridDims.x);
configDimensions.y = std::min(MAX_GRID_DIMENSIONS.y, gridDims.y);
configDimensions.z = std::min(MAX_GRID_DIMENSIONS.z, gridDims.z);
configDimensions.x = std::max(1, (int) std::min(MAX_GRID_DIMENSIONS.x, gridDims.x));
configDimensions.y = std::max(1, (int) std::min(MAX_GRID_DIMENSIONS.y, gridDims.y));
configDimensions.z = std::max(1, (int) std::min(MAX_GRID_DIMENSIONS.z, gridDims.z));
auto sliceCost = configDimensions.x * configDimensions.y;
auto maxNumSlices = (int)(gridBudget / sliceCost) - 1;
configDimensions.z = std::min(maxNumSlices, configDimensions.z);
static int numFrames = 0;
numFrames++;
auto& dims = _frustumGridBuffer->dims;
if ((numFrames == 10) || (dims.x != configDimensions.x) || (dims.y != configDimensions.y) || (dims.z != configDimensions.z)) {
_frustumGridBuffer.edit().dims = configDimensions;
_frustumGridBuffer.edit().generateGridPlanes(_gridPlanes[0], _gridPlanes[1], _gridPlanes[2]);
}
auto numClusters = _frustumGridBuffer.edit().frustumGrid_numClusters();
if (numClusters != _numClusters) {
_numClusters = numClusters;
_clusterGrid.clear();
_clusterGrid.resize(_numClusters, EMPTY_CLUSTER);
// _clusterGridBuffer._size = _clusterGridBuffer._buffer->resize(_numClusters * sizeof(uint32_t));
_clusterGridBuffer._size = (_numClusters * sizeof(uint32_t));
_clusterGridBuffer._buffer = std::make_shared<gpu::Buffer>(_clusterGridBuffer._size, (gpu::Byte*) _clusterGrid.data(), _clusterGridBuffer._size);
// Grab the frustumGridBuffer and force it updated
const auto& constFrustumGrid = _frustumGridBuffer.get();
const auto& dims = constFrustumGrid.dims;
if ((dims.x != configDimensions.x) || (dims.y != configDimensions.y) || (dims.z != configDimensions.z)) {
auto& theFrustumGrid = _frustumGridBuffer.edit();
theFrustumGrid.dims = configDimensions;
theFrustumGrid.generateGridPlanes(_gridPlanes[0], _gridPlanes[1], _gridPlanes[2]);
_clusterResourcesInvalid = true;
}
auto configListBudget = std::min(MAX_GRID_DIMENSIONS.w, listBudget);
if (_clusterContentBudget != configListBudget) {
_clusterContentBudget = configListBudget;
_clusterResourcesInvalid = true;
}
}
// SInce LightINdex is 2bytes, we can fit 2 in a uint32
uint32_t LightClusters::getNumClusters() const {
auto theFrustumGrid = _frustumGridBuffer.get();
return theFrustumGrid.frustumGrid_numClusters();
}
void LightClusters::updateClusterResource() {
if (!_clusterResourcesInvalid) {
return;
}
_clusterResourcesInvalid = false;
auto numClusters = getNumClusters();
if (numClusters != _clusterGrid.size()) {
_clusterGrid.clear();
_clusterGrid.resize(numClusters, EMPTY_CLUSTER);
_clusterGridBuffer._size = (numClusters * sizeof(uint32_t));
_clusterGridBuffer._buffer = std::make_shared<gpu::Buffer>(_clusterGridBuffer._size, (gpu::Byte*) _clusterGrid.data(), _clusterGridBuffer._size);
}
// Since LightIndex is 2bytes, we can fit 2 in a uint32
auto configListBudget = _clusterContentBudget;
if (sizeof(LightIndex) == 2) {
configListBudget *= 2;
}
@ -129,9 +142,7 @@ void LightClusters::setDimensions(glm::uvec3 gridDims, uint32_t listBudget) {
if (configListBudget != _clusterContent.size()) {
_clusterContent.clear();
_clusterContent.resize(configListBudget, INVALID_LIGHT);
// _clusterContentBuffer._size = _clusterContentBuffer._buffer->resize(configListBudget * sizeof(LightIndex));
_clusterContentBuffer._size = (configListBudget * sizeof(LightIndex));
// _clusterContentBuffer._buffer->setData(_clusterContentBuffer._size, (gpu::Byte*) _clusterContent.data());
_clusterContentBuffer._buffer = std::make_shared<gpu::Buffer>(_clusterContentBuffer._size, (gpu::Byte*) _clusterContent.data(), _clusterContentBuffer._size);
}
}
@ -310,16 +321,23 @@ uint32_t scanLightVolumeSphere(FrustumGrid& grid, const FrustumGrid::Planes plan
}
glm::ivec3 LightClusters::updateClusters() {
// Make sure resource are in good shape
updateClusterResource();
// Clean up last info
std::vector< std::vector< LightIndex > > clusterGridPoint(_numClusters);
std::vector< std::vector< LightIndex > > clusterGridSpot(_numClusters);
uint32_t numClusters = (uint32_t)_clusterGrid.size();
std::vector< std::vector< LightIndex > > clusterGridPoint(numClusters);
std::vector< std::vector< LightIndex > > clusterGridSpot(numClusters);
_clusterGrid.clear();
_clusterGrid.resize(_numClusters, EMPTY_CLUSTER);
_clusterGrid.resize(numClusters, EMPTY_CLUSTER);
uint32_t maxNumIndices = (uint32_t)_clusterContent.size();
_clusterContent.clear();
_clusterContent.resize(maxNumIndices, INVALID_LIGHT);
auto theFrustumGrid(_frustumGridBuffer.get());
glm::ivec3 gridPosToOffset(1, theFrustumGrid.dims.x, theFrustumGrid.dims.x * theFrustumGrid.dims.y);

View file

@ -24,7 +24,7 @@ public:
float rangeFar { 200.0f };
float frustumFar { 10000.0f };
glm::ivec3 dims { 16, 16, 16 };
glm::ivec3 dims { 1, 1, 1 };
float spare;
glm::mat4 eyeToGridProj;
@ -68,6 +68,8 @@ public:
void setDimensions(glm::uvec3 gridDims, uint32_t listBudget = MAX_GRID_DIMENSIONS.w);
void setRangeNearFar(float rangeNear, float rangeFar);
uint32_t getNumClusters() const;
void updateFrustum(const ViewFrustum& frustum);
void updateLightStage(const LightStagePointer& lightStage);
@ -76,8 +78,10 @@ public:
glm::ivec3 updateClusters();
ViewFrustum _frustum;
LightStagePointer _lightStage;
@ -89,8 +93,6 @@ public:
LightStage::LightIndices _visibleLightIndices;
gpu::BufferView _lightIndicesBuffer;
int32_t _numClusters { 0 };
const uint32_t EMPTY_CLUSTER { 0x0000FFFF };
const LightID INVALID_LIGHT { LightStage::INVALID_INDEX };
@ -100,6 +102,10 @@ public:
std::vector<LightIndex> _clusterContent;
gpu::BufferView _clusterGridBuffer;
gpu::BufferView _clusterContentBuffer;
int32_t _clusterContentBudget { 0 };
bool _clusterResourcesInvalid { true };
void updateClusterResource();
};
using LightClustersPointer = std::shared_ptr<LightClusters>;

View file

@ -71,6 +71,13 @@ void LightPayload::render(RenderArgs* args) {
if (isVisible()) {
// FInally, push the light visible in the frame
_stage->_currentFrame.pushLight(_index, _light->getType());
#ifdef WANT_DEBUG
Q_ASSERT(args->_batch);
gpu::Batch& batch = *args->_batch;
batch.setModelTransform(getTransformToCenter());
DependencyManager::get<GeometryCache>()->renderWireSphere(batch, 0.5f, 15, 15, glm::vec4(color, 1.0f));
#endif
}
}