more fixes

This commit is contained in:
HifiExperiments 2024-02-29 17:39:15 -08:00
parent d5e251d8da
commit f2ebca9935
11 changed files with 62 additions and 65 deletions

View file

@ -120,8 +120,6 @@ const Backend::TransformCamera& Backend::TransformCamera::recomputeDerived(const
viewUntranslated[3] = Vec4(0.0f, 0.0f, 0.0f, 1.0f); viewUntranslated[3] = Vec4(0.0f, 0.0f, 0.0f, 1.0f);
_previousProjectionViewUntranslated = previousProjection * viewUntranslated; _previousProjectionViewUntranslated = previousProjection * viewUntranslated;
//_previousProjectionViewUntranslated = _projection * viewUntranslated;
_stereoInfo = Vec4(0.0f); _stereoInfo = Vec4(0.0f);
return *this; return *this;

View file

@ -10,8 +10,6 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
<@include graphics/ShaderConstants.h@>
<@include skybox.slh@> <@include skybox.slh@>
<@if HIFI_USE_FORWARD@> <@if HIFI_USE_FORWARD@>
@ -63,7 +61,7 @@ void main(void) {
_fragColor.rgb = mix(_fragColor.rgb, hazeColor.rgb, hazeColor.a); _fragColor.rgb = mix(_fragColor.rgb, hazeColor.rgb, hazeColor.a);
} }
<@else@> <@else@>
packDeferredFragmentSky(_prevPositionCS, color, normal); packDeferredFragmentSky(_prevPositionCS, color);
<@endif@> <@endif@>
} }

View file

@ -11,6 +11,8 @@
<@if not SKYBOX_SLH@> <@if not SKYBOX_SLH@>
<@def SKYBOX_SLH@> <@def SKYBOX_SLH@>
<@include graphics/ShaderConstants.h@>
<@include gpu/Transform.slh@> <@include gpu/Transform.slh@>
<$declareStandardCameraTransform()$> <$declareStandardCameraTransform()$>
@ -45,19 +47,12 @@ vec2 packVelocity(vec4 prevPositionCS) {
return deltaUV; return deltaUV;
} }
// Must match layout in DeferredBufferWrite.slh, but only velocity and lighting are used layout(location = 0) out vec4 _lighting; // calculated lighting
layout(location = 0) out vec4 _albedoMetallic; // albedo / metallic layout(location = 1) out vec4 _velocity; // velocity
layout(location = 1) out vec4 _normalRoughness; // normal / roughness
layout(location = 2) out vec4 _scatteringEmissiveOcclusion; // scattering / emissive / occlusion
layout(location = 3) out vec4 _velocity; // velocity
layout(location = 4) out vec4 _lighting; // emissive
void packDeferredFragmentSky(vec4 prevPositionCS, vec3 color, vec3 normal) { void packDeferredFragmentSky(vec4 prevPositionCS, vec3 color) {
_albedoMetallic = vec4(color, 0.6f);
_normalRoughness = vec4(packNormal(normal), 1.0f);
_scatteringEmissiveOcclusion = vec4(0.0f);
_velocity = vec4(packVelocity(prevPositionCS), 0.0f, 0.0f);
_lighting = vec4(color, 1.0f); _lighting = vec4(color, 1.0f);
_velocity = vec4(packVelocity(prevPositionCS), 0.0f, 0.0f);
} }
<@endfunc@> <@endfunc@>

View file

@ -11,8 +11,6 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
<@include graphics/ShaderConstants.h@>
<@include graphics/skybox.slh@> <@include graphics/skybox.slh@>
<$declarePackDeferredFragmentSky()$> <$declarePackDeferredFragmentSky()$>
@ -37,5 +35,5 @@ void main(void) {
// Procedural Shaders are expected to be Gamma corrected so let's bring back the RGB in linear space for the rest of the pipeline // Procedural Shaders are expected to be Gamma corrected so let's bring back the RGB in linear space for the rest of the pipeline
color = pow(color, vec3(2.2)); color = pow(color, vec3(2.2));
packDeferredFragmentSky(_prevPositionCS, color, _normal); packDeferredFragmentSky(_prevPositionCS, color);
} }

View file

@ -15,7 +15,6 @@
<@include DeferredBuffer.slh@> <@include DeferredBuffer.slh@>
<@include DeferredBufferWrite_shared.slh@> <@include DeferredBufferWrite_shared.slh@>
// Must match layout in skybox.slh
layout(location = DEFERRED_COLOR_SLOT) out vec4 _albedoMetallic; // albedo / metallic layout(location = DEFERRED_COLOR_SLOT) out vec4 _albedoMetallic; // albedo / metallic
layout(location = DEFERRED_NORMAL_SLOT) out vec4 _normalRoughness; // normal / roughness layout(location = DEFERRED_NORMAL_SLOT) out vec4 _normalRoughness; // normal / roughness
layout(location = DEFERRED_SPECULAR_SLOT) out vec4 _scatteringEmissiveOcclusion; // scattering / emissive / occlusion layout(location = DEFERRED_SPECULAR_SLOT) out vec4 _scatteringEmissiveOcclusion; // scattering / emissive / occlusion

View file

@ -287,7 +287,6 @@ void PrepareDeferred::run(const RenderContextPointer& renderContext, const Input
outputs.edit0() = _deferredFramebuffer; outputs.edit0() = _deferredFramebuffer;
outputs.edit1() = _deferredFramebuffer->getLightingFramebuffer(); outputs.edit1() = _deferredFramebuffer->getLightingFramebuffer();
outputs.edit2() = _deferredFramebuffer->getLightingWithVelocityFramebuffer();
gpu::doInBatch("PrepareDeferred::run", args->_context, [&](gpu::Batch& batch) { gpu::doInBatch("PrepareDeferred::run", args->_context, [&](gpu::Batch& batch) {
batch.enableStereo(false); batch.enableStereo(false);
@ -507,7 +506,7 @@ void RenderDeferredLocals::run(const render::RenderContextPointer& renderContext
} }
} }
void RenderDeferredCleanup::run(const render::RenderContextPointer& renderContext) { void RenderDeferredCleanup::run(const render::RenderContextPointer& renderContext, const DeferredFramebufferPointer& deferredFramebuffer) {
auto args = renderContext->args; auto args = renderContext->args;
auto& batch = (*args->_batch); auto& batch = (*args->_batch);
{ {
@ -532,6 +531,8 @@ void RenderDeferredCleanup::run(const render::RenderContextPointer& renderContex
batch.setUniformBuffer(ru::Buffer::LightClusterGrid, nullptr); batch.setUniformBuffer(ru::Buffer::LightClusterGrid, nullptr);
batch.setUniformBuffer(ru::Buffer::LightClusterContent, nullptr); batch.setUniformBuffer(ru::Buffer::LightClusterContent, nullptr);
// Restore the lighting with velocity framebuffer so that following stages, like drawing the background, can get motion vectors.
batch.setFramebuffer(deferredFramebuffer->getLightingWithVelocityFramebuffer());
} }
} }
@ -572,7 +573,7 @@ void RenderDeferred::run(const RenderContextPointer& renderContext, const Inputs
lightsJob.run(renderContext, deferredTransform, deferredFramebuffer, lightingModel, surfaceGeometryFramebuffer, lightClusters); lightsJob.run(renderContext, deferredTransform, deferredFramebuffer, lightingModel, surfaceGeometryFramebuffer, lightClusters);
cleanupJob.run(renderContext); cleanupJob.run(renderContext, deferredFramebuffer);
_gpuTimer->end(batch); _gpuTimer->end(batch);
}); });

View file

@ -78,7 +78,7 @@ class PrepareDeferred {
public: public:
// Inputs: primaryFramebuffer and lightingModel // Inputs: primaryFramebuffer and lightingModel
using Inputs = render::VaryingSet2 <gpu::FramebufferPointer, LightingModelPointer>; using Inputs = render::VaryingSet2 <gpu::FramebufferPointer, LightingModelPointer>;
using Outputs = render::VaryingSet3<DeferredFramebufferPointer, gpu::FramebufferPointer, gpu::FramebufferPointer>; using Outputs = render::VaryingSet2<DeferredFramebufferPointer, gpu::FramebufferPointer>;
using JobModel = render::Job::ModelIO<PrepareDeferred, Inputs, Outputs>; using JobModel = render::Job::ModelIO<PrepareDeferred, Inputs, Outputs>;
@ -122,8 +122,8 @@ public:
class RenderDeferredCleanup { class RenderDeferredCleanup {
public: public:
using JobModel = render::Job::Model<RenderDeferredCleanup>; using JobModel = render::Job::Model<RenderDeferredCleanup>;
void run(const render::RenderContextPointer& renderContext); void run(const render::RenderContextPointer& renderContext, const DeferredFramebufferPointer& deferredFramebuffer);
}; };
using RenderDeferredConfig = render::GPUJobConfig; using RenderDeferredConfig = render::GPUJobConfig;

View file

@ -153,7 +153,6 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
const auto prepareDeferredOutputs = task.addJob<PrepareDeferred>("PrepareDeferred", prepareDeferredInputs); const auto prepareDeferredOutputs = task.addJob<PrepareDeferred>("PrepareDeferred", prepareDeferredInputs);
const auto deferredFramebuffer = prepareDeferredOutputs.getN<PrepareDeferred::Outputs>(0); const auto deferredFramebuffer = prepareDeferredOutputs.getN<PrepareDeferred::Outputs>(0);
const auto lightingFramebuffer = prepareDeferredOutputs.getN<PrepareDeferred::Outputs>(1); const auto lightingFramebuffer = prepareDeferredOutputs.getN<PrepareDeferred::Outputs>(1);
const auto lightingWithVelocityFramebuffer = prepareDeferredOutputs.getN<PrepareDeferred::Outputs>(2);
// draw a stencil mask in hidden regions of the framebuffer. // draw a stencil mask in hidden regions of the framebuffer.
task.addJob<PrepareStencil>("PrepareStencil", scaledPrimaryFramebuffer); task.addJob<PrepareStencil>("PrepareStencil", scaledPrimaryFramebuffer);

View file

@ -61,6 +61,7 @@ const gpu::PipelinePointer DrawSceneOctree::getDrawLODReticlePipeline() {
void DrawSceneOctree::configure(const Config& config) { void DrawSceneOctree::configure(const Config& config) {
_showVisibleCells = config.showVisibleCells; _showVisibleCells = config.showVisibleCells;
_showEmptyCells = config.showEmptyCells; _showEmptyCells = config.showEmptyCells;
_showLODReticle = config.showLODReticle;
} }
@ -76,45 +77,48 @@ void DrawSceneOctree::run(const RenderContextPointer& renderContext, const ItemS
gpu::doInBatch("DrawSceneOctree::run", args->_context, [&](gpu::Batch& batch) { gpu::doInBatch("DrawSceneOctree::run", args->_context, [&](gpu::Batch& batch) {
batch.setViewportTransform(args->_viewport); batch.setViewportTransform(args->_viewport);
batch.setSavedViewProjectionTransform(_transformSlot); batch.setSavedViewProjectionTransform(_transformSlot);
batch.setModelTransform(Transform());
// bind the one gpu::Pipeline we need if (_showEmptyCells || _showVisibleCells) {
batch.setPipeline(getDrawCellBoundsPipeline()); batch.setModelTransform(Transform());
batch.setInputFormat(_cellBoundsFormat);
std::vector<ivec4> cellBounds; // bind the one gpu::Pipeline we need
auto drawCellBounds = [this, &cellBounds, &scene](const std::vector<gpu::Stamp>& cells) { batch.setPipeline(getDrawCellBoundsPipeline());
cellBounds.reserve(cellBounds.size() + cells.size()); batch.setInputFormat(_cellBoundsFormat);
for (const auto& cellID : cells) {
auto cell = scene->getSpatialTree().getConcreteCell(cellID);
auto cellLoc = cell.getlocation();
glm::ivec4 cellLocation(cellLoc.pos.x, cellLoc.pos.y, cellLoc.pos.z, cellLoc.depth);
bool empty = cell.isBrickEmpty() || !cell.hasBrick(); std::vector<ivec4> cellBounds;
if (empty) { auto drawCellBounds = [this, &cellBounds, &scene](const std::vector<gpu::Stamp>& cells) {
if (!_showEmptyCells) { cellBounds.reserve(cellBounds.size() + cells.size());
for (const auto& cellID : cells) {
auto cell = scene->getSpatialTree().getConcreteCell(cellID);
auto cellLoc = cell.getlocation();
glm::ivec4 cellLocation(cellLoc.pos.x, cellLoc.pos.y, cellLoc.pos.z, cellLoc.depth);
bool empty = cell.isBrickEmpty() || !cell.hasBrick();
if (empty) {
if (!_showEmptyCells) {
continue;
}
cellLocation.w *= -1.0;
} else if (!_showVisibleCells) {
continue; continue;
} }
cellLocation.w *= -1.0; cellBounds.push_back(cellLocation);
} else if (!empty && !_showVisibleCells) {
continue;
} }
cellBounds.push_back(cellLocation); };
}
};
drawCellBounds(inSelection.cellSelection.insideCells); drawCellBounds(inSelection.cellSelection.insideCells);
drawCellBounds(inSelection.cellSelection.partialCells); drawCellBounds(inSelection.cellSelection.partialCells);
auto size = cellBounds.size() * sizeof(ivec4); auto size = cellBounds.size() * sizeof(ivec4);
if (size > _cellBoundsBuffer->getSize()) { if (size > _cellBoundsBuffer->getSize()) {
_cellBoundsBuffer->resize(size); _cellBoundsBuffer->resize(size);
}
_cellBoundsBuffer->setSubData(0, cellBounds);
batch.setInputBuffer(0, _cellBoundsBuffer, 0, sizeof(ivec4));
batch.drawInstanced((uint32_t)cellBounds.size(), gpu::LINES, 24);
} }
_cellBoundsBuffer->setSubData(0, cellBounds);
batch.setInputBuffer(0, _cellBoundsBuffer, 0, sizeof(ivec4));
batch.drawInstanced((uint32_t)cellBounds.size(), gpu::LINES, 24);
// Draw the LOD Reticle // Draw the LOD Reticle
{ if (_showLODReticle) {
float angle = glm::degrees(getPerspectiveAccuracyHalfAngle(args->_sizeScale, args->_boundaryLevelAdjust)); float angle = glm::degrees(getPerspectiveAccuracyHalfAngle(args->_sizeScale, args->_boundaryLevelAdjust));
Transform crosshairModel; Transform crosshairModel;
crosshairModel.setTranslation(glm::vec3(0.0, 0.0, -1000.0)); crosshairModel.setTranslation(glm::vec3(0.0, 0.0, -1000.0));

View file

@ -23,6 +23,7 @@ namespace render {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool showVisibleCells READ getShowVisibleCells WRITE setShowVisibleCells NOTIFY dirty()) Q_PROPERTY(bool showVisibleCells READ getShowVisibleCells WRITE setShowVisibleCells NOTIFY dirty())
Q_PROPERTY(bool showEmptyCells READ getShowEmptyCells WRITE setShowEmptyCells NOTIFY dirty()) Q_PROPERTY(bool showEmptyCells READ getShowEmptyCells WRITE setShowEmptyCells NOTIFY dirty())
Q_PROPERTY(bool showLODReticle READ getShowLODReticle WRITE setShowLODReticle NOTIFY dirty())
Q_PROPERTY(int numAllocatedCells READ getNumAllocatedCells) Q_PROPERTY(int numAllocatedCells READ getNumAllocatedCells)
Q_PROPERTY(int numFreeCells READ getNumFreeCells) Q_PROPERTY(int numFreeCells READ getNumFreeCells)
@ -36,15 +37,18 @@ namespace render {
int getNumAllocatedCells() const { return numAllocatedCells; } int getNumAllocatedCells() const { return numAllocatedCells; }
int getNumFreeCells() const { return numFreeCells; } int getNumFreeCells() const { return numFreeCells; }
bool showVisibleCells{ true }; bool showVisibleCells { false };
bool showEmptyCells{ false }; bool showEmptyCells { false };
bool showLODReticle { false };
bool getShowVisibleCells() { return showVisibleCells; } bool getShowVisibleCells() { return showVisibleCells; }
bool getShowEmptyCells() { return showEmptyCells; } bool getShowEmptyCells() { return showEmptyCells; }
bool getShowLODReticle() { return showLODReticle; }
public slots: public slots:
void setShowVisibleCells(bool show) { showVisibleCells = show; emit dirty(); } void setShowVisibleCells(bool show) { showVisibleCells = show; emit dirty(); }
void setShowEmptyCells(bool show) { showEmptyCells = show; emit dirty(); } void setShowEmptyCells(bool show) { showEmptyCells = show; emit dirty(); }
void setShowLODReticle(bool show) { showLODReticle = show; emit dirty(); }
signals: signals:
void dirty(); void dirty();
@ -57,8 +61,10 @@ namespace render {
gpu::BufferPointer _cellBoundsBuffer; gpu::BufferPointer _cellBoundsBuffer;
gpu::Stream::FormatPointer _cellBoundsFormat; gpu::Stream::FormatPointer _cellBoundsFormat;
bool _showVisibleCells; // initialized by Config // initialized by Config
bool _showEmptyCells; // initialized by Config bool _showVisibleCells;
bool _showEmptyCells;
bool _showLODReticle;
public: public:
using Config = DrawSceneOctreeConfig; using Config = DrawSceneOctreeConfig;

View file

@ -22,8 +22,7 @@ Item {
anchors.fill:parent anchors.fill:parent
Component.onCompleted: { Component.onCompleted: {
Render.getConfig("RenderMainView.DrawSceneOctree").showVisibleCells = false Render.getConfig("RenderMainView.DrawSceneOctree").enabled = true
Render.getConfig("RenderMainView.DrawSceneOctree").showEmptyCells = false
} }
Component.onDestruction: { Component.onDestruction: {
@ -38,9 +37,9 @@ Item {
HifiControls.CheckBox { HifiControls.CheckBox {
boxSize: 20 boxSize: 20
text: "Show LOD Reticule" text: "Show LOD Reticle"
checked: Render.getConfig("RenderMainView.DrawSceneOctree").enabled checked: Render.getConfig("RenderMainView.DrawSceneOctree").showLODReticle
onCheckedChanged: { Render.getConfig("RenderMainView.DrawSceneOctree").enabled = checked } onCheckedChanged: { Render.getConfig("RenderMainView.DrawSceneOctree").showLODReticle = checked }
} }
RichSlider { RichSlider {