From a7dec8fb75fa417400e3594b6e689bc05a6f4f9b Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Mon, 6 Aug 2018 15:49:52 -0700 Subject: [PATCH 1/3] parabola and particle shader fixes --- .../src/textured_particle.slv | 2 +- .../src/procedural/proceduralSkybox.slf | 3 --- libraries/render-utils/src/parabola.slv | 22 +++++++++++-------- .../render/src/render/DrawSceneOctree.cpp | 19 ---------------- libraries/render/src/render/DrawStatus.cpp | 7 ------ 5 files changed, 14 insertions(+), 39 deletions(-) diff --git a/libraries/entities-renderer/src/textured_particle.slv b/libraries/entities-renderer/src/textured_particle.slv index 60bca6e9bd..3eacaec3b5 100644 --- a/libraries/entities-renderer/src/textured_particle.slv +++ b/libraries/entities-renderer/src/textured_particle.slv @@ -149,7 +149,7 @@ void main(void) { vec3 UP = vec3(0, 1, 0); vec3 modelUpWorld; <$transformModelToWorldDir(cam, obj, UP, modelUpWorld)$> - vec3 upWorld = mix(UP, normalize(modelUpWorld), particle.rotateWithEntity); + vec3 upWorld = mix(UP, normalize(modelUpWorld), float(particle.rotateWithEntity)); vec3 upEye = normalize(view3 * upWorld); vec3 FORWARD = vec3(0, 0, -1); vec3 particleRight = normalize(cross(FORWARD, upEye)); diff --git a/libraries/procedural/src/procedural/proceduralSkybox.slf b/libraries/procedural/src/procedural/proceduralSkybox.slf index 9960698ff0..e18b7abef6 100644 --- a/libraries/procedural/src/procedural/proceduralSkybox.slf +++ b/libraries/procedural/src/procedural/proceduralSkybox.slf @@ -39,7 +39,4 @@ 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 color = pow(color, vec3(2.2)); _fragColor = vec4(color, 0.0); - - // FIXME: scribe does not yet scrub out else statements - return; } diff --git a/libraries/render-utils/src/parabola.slv b/libraries/render-utils/src/parabola.slv index 50b5999450..0948b2ab47 100644 --- a/libraries/render-utils/src/parabola.slv +++ b/libraries/render-utils/src/parabola.slv @@ -12,7 +12,7 @@ <@include gpu/Transform.slh@> <$declareStandardTransform()$> -layout(std140, binding=0) uniform parabolaData { +struct ParabolaData { vec3 velocity; float parabolicDistance; vec3 acceleration; @@ -20,34 +20,38 @@ layout(std140, binding=0) uniform parabolaData { vec4 color; int numSections; ivec3 spare; +} + +layout(std140, binding=0) uniform parabolaData { + ParabolaData _parabolaData; }; layout(location=0) out vec4 _color; void main(void) { - _color = color; + _color = _parabolaData.color; - float t = parabolicDistance * (float(gl_VertexID / 2) / float(numSections)); + float t = _parabolaData.parabolicDistance * (float(gl_VertexID / 2) / float(_parabolaData.numSections)); - vec4 pos = vec4(velocity * t + 0.5 * acceleration * t * t, 1); + vec4 pos = vec4(_parabolaData.velocity * t + 0.5 * _parabolaData.acceleration * t * t, 1); const float EPSILON = 0.00001; vec4 normal; TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); - if (dot(acceleration, acceleration) < EPSILON) { + if (dot(_parabolaData.acceleration, _parabolaData.acceleration) < EPSILON) { // Handle case where acceleration == (0, 0, 0) vec3 eyeUp = vec3(0, 1, 0); vec3 worldUp; <$transformEyeToWorldDir(cam, eyeUp, worldUp)$> - normal = vec4(normalize(cross(velocity, worldUp)), 0); + normal = vec4(normalize(cross(_parabolaData.velocity, worldUp)), 0); } else { - normal = vec4(normalize(cross(velocity, acceleration)), 0); + normal = vec4(normalize(cross(_parabolaData.velocity, _parabolaData.acceleration)), 0); } if (gl_VertexID % 2 == 0) { - pos += 0.5 * width * normal; + pos += 0.5 * _parabolaData.width * normal; } else { - pos -= 0.5 * width * normal; + pos -= 0.5 * _parabolaData.width * normal; } <$transformModelToClipPos(cam, obj, pos, gl_Position)$> diff --git a/libraries/render/src/render/DrawSceneOctree.cpp b/libraries/render/src/render/DrawSceneOctree.cpp index b8014b4e4f..f733fa5eb1 100644 --- a/libraries/render/src/render/DrawSceneOctree.cpp +++ b/libraries/render/src/render/DrawSceneOctree.cpp @@ -142,10 +142,6 @@ const gpu::PipelinePointer DrawItemSelection::getDrawItemBoundPipeline() { if (!_drawItemBoundPipeline) { gpu::ShaderPointer program = gpu::Shader::createProgram(shader::render::program::drawItemBounds); - //_drawItemBoundPosLoc = program->getUniforms().findLocation("inBoundPos"); - //_drawItemBoundDimLoc = program->getUniforms().findLocation("inBoundDim"); - //_drawCellLocationLoc = program->getUniforms().findLocation("inCellLocation"); - auto state = std::make_shared(); state->setDepthTest(true, false, gpu::LESS_EQUAL); @@ -194,10 +190,6 @@ void DrawItemSelection::run(const RenderContextPointer& renderContext, const Ite auto itemCell = scene->getSpatialTree().getCellLocation(item.getCell()); glm::ivec4 cellLocation(0, 0, 0, itemCell.depth); - //batch._glUniform4iv(_drawCellLocationLoc, 1, ((const int*)(&cellLocation))); - //batch._glUniform3fv(_drawItemBoundPosLoc, 1, (const float*)(&itemBound.getCorner())); - //batch._glUniform3fv(_drawItemBoundDimLoc, 1, (const float*)(&itemBound.getScale())); - batch.draw(gpu::LINES, 24, 0); } } @@ -209,10 +201,6 @@ void DrawItemSelection::run(const RenderContextPointer& renderContext, const Ite auto itemCell = scene->getSpatialTree().getCellLocation(item.getCell()); glm::ivec4 cellLocation(0, 0, 1, itemCell.depth); - //batch._glUniform4iv(_drawCellLocationLoc, 1, ((const int*)(&cellLocation))); - //batch._glUniform3fv(_drawItemBoundPosLoc, 1, (const float*)(&itemBound.getCorner())); - //batch._glUniform3fv(_drawItemBoundDimLoc, 1, (const float*)(&itemBound.getScale())); - batch.draw(gpu::LINES, 24, 0); } } @@ -224,10 +212,6 @@ void DrawItemSelection::run(const RenderContextPointer& renderContext, const Ite auto itemCell = scene->getSpatialTree().getCellLocation(item.getCell()); glm::ivec4 cellLocation(0, 0, 0, itemCell.depth); - //batch._glUniform4iv(_drawCellLocationLoc, 1, ((const int*)(&cellLocation))); - //batch._glUniform3fv(_drawItemBoundPosLoc, 1, (const float*)(&itemBound.getCorner())); - //batch._glUniform3fv(_drawItemBoundDimLoc, 1, (const float*)(&itemBound.getScale())); - batch.draw(gpu::LINES, 24, 0); } } @@ -238,9 +222,6 @@ void DrawItemSelection::run(const RenderContextPointer& renderContext, const Ite auto itemBound = item.getBound(); auto itemCell = scene->getSpatialTree().getCellLocation(item.getCell()); glm::ivec4 cellLocation(0, 0, 1, itemCell.depth); - //batch._glUniform4iv(_drawCellLocationLoc, 1, ((const int*)(&cellLocation))); - //batch._glUniform3fv(_drawItemBoundPosLoc, 1, (const float*)(&itemBound.getCorner())); - //batch._glUniform3fv(_drawItemBoundDimLoc, 1, (const float*)(&itemBound.getScale())); batch.draw(gpu::LINES, 24, 0); } diff --git a/libraries/render/src/render/DrawStatus.cpp b/libraries/render/src/render/DrawStatus.cpp index 2894a85a30..1c5ab27507 100644 --- a/libraries/render/src/render/DrawStatus.cpp +++ b/libraries/render/src/render/DrawStatus.cpp @@ -33,9 +33,6 @@ void DrawStatusConfig::dirtyHelper() { const gpu::PipelinePointer DrawStatus::getDrawItemBoundsPipeline() { if (!_drawItemBoundsPipeline) { gpu::ShaderPointer program = gpu::Shader::createProgram(shader::render::program::drawItemBounds); - //_drawItemBoundPosLoc = program->getUniforms().findLocation("inBoundPos"); - //_drawItemBoundDimLoc = program->getUniforms().findLocation("inBoundDim"); - //_drawItemCellLocLoc = program->getUniforms().findLocation("inCellLocation"); auto state = std::make_shared(); @@ -55,10 +52,6 @@ const gpu::PipelinePointer DrawStatus::getDrawItemBoundsPipeline() { const gpu::PipelinePointer DrawStatus::getDrawItemStatusPipeline() { if (!_drawItemStatusPipeline) { gpu::ShaderPointer program = gpu::Shader::createProgram(shader::render::program::blurGaussianDepthAwareV); - //_drawItemStatusPosLoc = program->getUniforms().findLocation(""); - //_drawItemStatusDimLoc = program->getUniforms().findLocation(""); - //_drawItemStatusValue0Loc = program->getUniforms().findLocation(""); - //_drawItemStatusValue1Loc = program->getUniforms().findLocation(""); auto state = std::make_shared(); From 82029b4cb011df2cb85a1e1bb3813b267879426e Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Mon, 6 Aug 2018 18:34:57 -0700 Subject: [PATCH 2/3] fix v1 and transparent procedurals --- .../src/RenderableShapeEntityItem.cpp | 4 +- libraries/render-utils/src/forward_simple.slf | 4 +- .../src/forward_simple_transparent.slf | 93 ------------------- libraries/render-utils/src/simple.slf | 4 +- .../render-utils/src/simple_transparent.slf | 32 ++++--- 5 files changed, 25 insertions(+), 112 deletions(-) delete mode 100644 libraries/render-utils/src/forward_simple_transparent.slf diff --git a/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp b/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp index a1b0eaf9e6..02dc6008a3 100644 --- a/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp @@ -35,9 +35,7 @@ ShapeEntityRenderer::ShapeEntityRenderer(const EntityItemPointer& entity) : Pare _procedural._vertexSource = gpu::Shader::getVertexShaderSource(shader::render_utils::vertex::simple); // FIXME: Setup proper uniform slots and use correct pipelines for forward rendering _procedural._opaquefragmentSource = gpu::Shader::getFragmentShaderSource(shader::render_utils::fragment::simple); - // FIXME: Transparent procedural entities only seem to work if they use the opaque pipelines - //_procedural._transparentfragmentSource = simple_transparent_frag::getSource(); - _procedural._transparentfragmentSource = _procedural._opaquefragmentSource; + _procedural._transparentfragmentSource = gpu::Shader::getFragmentShaderSource(shader::render_utils::fragment::simple_transparent); _procedural._opaqueState->setCullMode(gpu::State::CULL_NONE); _procedural._opaqueState->setDepthTest(true, true, gpu::LESS_EQUAL); PrepareStencil::testMaskDrawShape(*_procedural._opaqueState); diff --git a/libraries/render-utils/src/forward_simple.slf b/libraries/render-utils/src/forward_simple.slf index 2c1be14080..ca3a13c024 100644 --- a/libraries/render-utils/src/forward_simple.slf +++ b/libraries/render-utils/src/forward_simple.slf @@ -51,9 +51,9 @@ void main(void) { #ifdef PROCEDURAL #ifdef PROCEDURAL_V1 - specular = getProceduralColor().rgb; + diffuse = getProceduralColor().rgb; // Procedural Shaders are expected to be Gamma corrected so let's bring back the RGB in linear space for the rest of the pipeline - //specular = pow(specular, vec3(2.2)); + //diffuse = pow(diffuse, vec3(2.2)); emissiveAmount = 1.0; #else emissiveAmount = getProceduralColors(diffuse, specular, shininess); diff --git a/libraries/render-utils/src/forward_simple_transparent.slf b/libraries/render-utils/src/forward_simple_transparent.slf deleted file mode 100644 index f8390d6253..0000000000 --- a/libraries/render-utils/src/forward_simple_transparent.slf +++ /dev/null @@ -1,93 +0,0 @@ -<@include gpu/Config.slh@> -<$VERSION_HEADER$> -// Generated on <$_SCRIBE_DATE$> -// -// forward_simple_transparent.frag -// fragment shader -// -// Created by Andrzej Kapolka on 9/15/14. -// Copyright 2014 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 DefaultMaterials.slh@> - -<@include ForwardGlobalLight.slh@> -<$declareEvalGlobalLightingAlphaBlended()$> - -// the interpolated normal -layout(location=RENDER_UTILS_ATTR_NORMAL_WS) in vec3 _normalWS; -layout(location=RENDER_UTILS_ATTR_NORMAL_MS) in vec3 _normalMS; -layout(location=RENDER_UTILS_ATTR_COLOR) in vec4 _color; -layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; -#define _texCoord0 _texCoord01.xy -#define _texCoord1 _texCoord01.zw -layout(location=RENDER_UTILS_ATTR_POSITION_MS) in vec4 _positionMS; -layout(location=RENDER_UTILS_ATTR_POSITION_ES) in vec4 _positionES; - -// For retro-compatibility -#define _normal _normalWS -#define _modelNormal _normalMS -#define _position _positionMS -#define _eyePosition _positionES - -layout(location=0) out vec4 _fragColor0; - -//PROCEDURAL_COMMON_BLOCK - -#line 1001 -//PROCEDURAL_BLOCK - -#line 2030 -void main(void) { - vec3 normal = normalize(_normalWS.xyz); - vec3 diffuse = _color.rgb; - vec3 specular = DEFAULT_SPECULAR; - float shininess = DEFAULT_SHININESS; - float emissiveAmount = 0.0; - -#ifdef PROCEDURAL - -#ifdef PROCEDURAL_V1 - specular = getProceduralColor().rgb; - // Procedural Shaders are expected to be Gamma corrected so let's bring back the RGB in linear space for the rest of the pipeline - //specular = pow(specular, vec3(2.2)); - emissiveAmount = 1.0; -#else - emissiveAmount = getProceduralColors(diffuse, specular, shininess); -#endif - -#endif - - TransformCamera cam = getTransformCamera(); - vec3 fragPosition = _positionES.xyz; - - if (emissiveAmount > 0.0) { - _fragColor0 = vec4(evalGlobalLightingAlphaBlendedWithHaze( - cam._viewInverse, - 1.0, - DEFAULT_OCCLUSION, - fragPosition, - normal, - specular, - DEFAULT_FRESNEL, - DEFAULT_METALLIC, - DEFAULT_EMISSIVE, - DEFAULT_ROUGHNESS, _color.a), - _color.a); - } else { - _fragColor0 = vec4(evalGlobalLightingAlphaBlendedWithHaze( - cam._viewInverse, - 1.0, - DEFAULT_OCCLUSION, - fragPosition, - normal, - diffuse, - DEFAULT_FRESNEL, - DEFAULT_METALLIC, - DEFAULT_EMISSIVE, - DEFAULT_ROUGHNESS, _color.a), - _color.a); - } -} diff --git a/libraries/render-utils/src/simple.slf b/libraries/render-utils/src/simple.slf index 04ffade2fa..a7f5151880 100644 --- a/libraries/render-utils/src/simple.slf +++ b/libraries/render-utils/src/simple.slf @@ -48,9 +48,9 @@ void main(void) { #ifdef PROCEDURAL #ifdef PROCEDURAL_V1 - specular = getProceduralColor().rgb; + diffuse = getProceduralColor().rgb; // Procedural Shaders are expected to be Gamma corrected so let's bring back the RGB in linear space for the rest of the pipeline - //specular = pow(specular, vec3(2.2)); + //diffuse = pow(diffuse, vec3(2.2)); emissiveAmount = 1.0; #else emissiveAmount = getProceduralColors(diffuse, specular, shininess); diff --git a/libraries/render-utils/src/simple_transparent.slf b/libraries/render-utils/src/simple_transparent.slf index f81c06390c..5db54aa770 100644 --- a/libraries/render-utils/src/simple_transparent.slf +++ b/libraries/render-utils/src/simple_transparent.slf @@ -11,8 +11,10 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +<@include DefaultMaterials.slh@> -<@include DeferredBufferWrite.slh@> +<@include DeferredGlobalLight.slh@> +<$declareEvalGlobalLightingAlphaBlendedWithHaze()$> <@include render-utils/ShaderConstants.h@> @@ -26,6 +28,8 @@ layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; layout(location=RENDER_UTILS_ATTR_POSITION_MS) in vec4 _positionMS; layout(location=RENDER_UTILS_ATTR_POSITION_ES) in vec4 _positionES; +layout(location=0) out vec4 _fragColor0; + // For retro-compatibility #define _normal _normalWS #define _modelNormal _normalMS @@ -48,9 +52,9 @@ void main(void) { #ifdef PROCEDURAL #ifdef PROCEDURAL_V1 - specular = getProceduralColor().rgb; + diffuse = getProceduralColor().rgb; // Procedural Shaders are expected to be Gamma corrected so let's bring back the RGB in linear space for the rest of the pipeline - //specular = pow(specular, vec3(2.2)); + //diffuse = pow(diffuse, vec3(2.2)); emissiveAmount = 1.0; #else emissiveAmount = getProceduralColors(diffuse, specular, shininess); @@ -58,19 +62,23 @@ void main(void) { #endif + TransformCamera cam = getTransformCamera(); + vec3 fragPosition = _positionES.xyz; + if (emissiveAmount > 0.0) { - packDeferredFragmentTranslucent( - normal, - _color.a, - specular, - DEFAULT_FRESNEL, - DEFAULT_ROUGHNESS); + _fragColor0 = vec4(diffuse, _color.a); } else { - packDeferredFragmentTranslucent( + _fragColor0 = vec4(evalGlobalLightingAlphaBlendedWithHaze( + cam._viewInverse, + 1.0, + DEFAULT_OCCLUSION, + fragPosition, normal, - _color.a, diffuse, DEFAULT_FRESNEL, - DEFAULT_ROUGHNESS); + length(specular), + DEFAULT_EMISSIVE, + max(0.0, 1.0 - shininess / 128.0), _color.a), + _color.a); } } From 6ff0b9d41777c0d848d9c71f239445e7b209fb0b Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Tue, 7 Aug 2018 15:25:56 -0700 Subject: [PATCH 3/3] fix debug tools --- .../render/src/render/DrawSceneOctree.cpp | 117 ++++++++---------- libraries/render/src/render/DrawSceneOctree.h | 5 +- libraries/render/src/render/DrawStatus.cpp | 57 ++++----- libraries/render/src/render/DrawStatus.h | 7 +- libraries/render/src/render/Item.h | 1 + .../render/src/render/drawCellBounds.slv | 1 - .../render/src/render/drawItemBounds.slv | 4 - .../developer/utilities/render/culling.qml | 16 ++- 8 files changed, 90 insertions(+), 118 deletions(-) diff --git a/libraries/render/src/render/DrawSceneOctree.cpp b/libraries/render/src/render/DrawSceneOctree.cpp index f733fa5eb1..2cb8a5d8ef 100644 --- a/libraries/render/src/render/DrawSceneOctree.cpp +++ b/libraries/render/src/render/DrawSceneOctree.cpp @@ -22,10 +22,8 @@ #include "Args.h" - using namespace render; - const gpu::PipelinePointer DrawSceneOctree::getDrawCellBoundsPipeline() { if (!_drawCellBoundsPipeline) { gpu::ShaderPointer program = gpu::Shader::createProgram(shader::render::program::drawCellBounds); @@ -71,7 +69,6 @@ void DrawSceneOctree::run(const RenderContextPointer& renderContext, const ItemS std::static_pointer_cast(renderContext->jobConfig)->numAllocatedCells = (int)scene->getSpatialTree().getNumAllocatedCells(); std::static_pointer_cast(renderContext->jobConfig)->numFreeCells = (int)scene->getSpatialTree().getNumFreeCells(); - gpu::doInBatch("DrawSceneOctree::run", args->_context, [&](gpu::Batch& batch) { glm::mat4 projMat; Transform viewMat; @@ -86,44 +83,30 @@ void DrawSceneOctree::run(const RenderContextPointer& renderContext, const ItemS // bind the one gpu::Pipeline we need batch.setPipeline(getDrawCellBoundsPipeline()); - if (_showVisibleCells) { - - for (const auto& cellID : inSelection.cellSelection.insideCells) { + auto drawCellBounds = [this, &scene, &batch](const std::vector& cells) { + 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 doDraw = true; - if (cell.isBrickEmpty() || !cell.hasBrick()) { + bool empty = cell.isBrickEmpty() || !cell.hasBrick(); + if (empty) { if (!_showEmptyCells) { - doDraw = false; + continue; } - cellLocation.w *= -1; + cellLocation.w *= -1.0; + } else if (!empty && !_showVisibleCells) { + continue; } - if (doDraw) { - batch._glUniform4iv(gpu::slot::uniform::Extra0, 1, ((const int*)(&cellLocation))); - batch.draw(gpu::LINES, 24, 0); - } - } - for (const auto& cellID : inSelection.cellSelection.partialCells) { - 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 doDraw = true; - if (cell.isBrickEmpty() || !cell.hasBrick()) { - if (!_showEmptyCells) { - doDraw = false; - } - cellLocation.w *= -1; - } - if (doDraw) { - batch._glUniform4iv(gpu::slot::uniform::Extra0, 1, ((const int*)(&cellLocation))); - batch.draw(gpu::LINES, 24, 0); - } + batch._glUniform4iv(gpu::slot::uniform::Extra0, 1, ((const int*)(&cellLocation))); + batch.draw(gpu::LINES, 24, 0); } - } + }; + + drawCellBounds(inSelection.cellSelection.insideCells); + drawCellBounds(inSelection.cellSelection.partialCells); + // Draw the LOD Reticle { float angle = glm::degrees(getPerspectiveAccuracyAngle(args->_sizeScale, args->_boundaryLevelAdjust)); @@ -169,6 +152,19 @@ void DrawItemSelection::run(const RenderContextPointer& renderContext, const Ite RenderArgs* args = renderContext->args; auto& scene = renderContext->_scene; + if (!_boundsBufferInside) { + _boundsBufferInside = std::make_shared(sizeof(render::ItemBound)); + } + if (!_boundsBufferInsideSubcell) { + _boundsBufferInsideSubcell = std::make_shared(sizeof(render::ItemBound)); + } + if (!_boundsBufferPartial) { + _boundsBufferPartial = std::make_shared(sizeof(render::ItemBound)); + } + if (!_boundsBufferPartialSubcell) { + _boundsBufferPartialSubcell = std::make_shared(sizeof(render::ItemBound)); + } + gpu::doInBatch("DrawItemSelection::run", args->_context, [&](gpu::Batch& batch) { glm::mat4 projMat; Transform viewMat; @@ -183,48 +179,35 @@ void DrawItemSelection::run(const RenderContextPointer& renderContext, const Ite // bind the one gpu::Pipeline we need batch.setPipeline(getDrawItemBoundPipeline()); + auto drawItemBounds = [&](const render::ItemIDs itemIDs, const gpu::BufferPointer buffer) { + render::ItemBounds itemBounds; + for (const auto& itemID : itemIDs) { + auto& item = scene->getItem(itemID); + auto itemBound = item.getBound(); + if (!itemBound.isInvalid()) { + itemBounds.emplace_back(itemID, itemBound); + } + } + + if (itemBounds.size() > 0) { + buffer->setData(itemBounds.size() * sizeof(render::ItemBound), (const gpu::Byte*) itemBounds.data()); + batch.setResourceBuffer(0, buffer); + batch.draw(gpu::LINES, (gpu::uint32) itemBounds.size() * 24, 0); + } + }; + if (_showInsideItems) { - for (const auto& itemID : inSelection.insideItems) { - auto& item = scene->getItem(itemID); - auto itemBound = item.getBound(); - auto itemCell = scene->getSpatialTree().getCellLocation(item.getCell()); - glm::ivec4 cellLocation(0, 0, 0, itemCell.depth); - - batch.draw(gpu::LINES, 24, 0); - } + drawItemBounds(inSelection.insideItems, _boundsBufferInside); } - if (_showInsideSubcellItems) { - for (const auto& itemID : inSelection.insideSubcellItems) { - auto& item = scene->getItem(itemID); - auto itemBound = item.getBound(); - auto itemCell = scene->getSpatialTree().getCellLocation(item.getCell()); - glm::ivec4 cellLocation(0, 0, 1, itemCell.depth); - - batch.draw(gpu::LINES, 24, 0); - } + drawItemBounds(inSelection.insideSubcellItems, _boundsBufferInsideSubcell); } - if (_showPartialItems) { - for (const auto& itemID : inSelection.partialItems) { - auto& item = scene->getItem(itemID); - auto itemBound = item.getBound(); - auto itemCell = scene->getSpatialTree().getCellLocation(item.getCell()); - glm::ivec4 cellLocation(0, 0, 0, itemCell.depth); - - batch.draw(gpu::LINES, 24, 0); - } + drawItemBounds(inSelection.partialItems, _boundsBufferPartial); } - if (_showPartialSubcellItems) { - for (const auto& itemID : inSelection.partialSubcellItems) { - auto& item = scene->getItem(itemID); - auto itemBound = item.getBound(); - auto itemCell = scene->getSpatialTree().getCellLocation(item.getCell()); - glm::ivec4 cellLocation(0, 0, 1, itemCell.depth); - - batch.draw(gpu::LINES, 24, 0); - } + drawItemBounds(inSelection.partialSubcellItems, _boundsBufferPartialSubcell); } + batch.setResourceBuffer(0, 0); }); } diff --git a/libraries/render/src/render/DrawSceneOctree.h b/libraries/render/src/render/DrawSceneOctree.h index 54c14e45f2..0b2cd6f685 100644 --- a/libraries/render/src/render/DrawSceneOctree.h +++ b/libraries/render/src/render/DrawSceneOctree.h @@ -52,7 +52,6 @@ namespace render { class DrawSceneOctree { gpu::PipelinePointer _drawCellBoundsPipeline; - gpu::BufferPointer _cells; gpu::PipelinePointer _drawLODReticlePipeline; gpu::PipelinePointer _drawItemBoundPipeline; @@ -107,6 +106,10 @@ namespace render { class DrawItemSelection { gpu::PipelinePointer _drawItemBoundPipeline; + gpu::BufferPointer _boundsBufferInside; + gpu::BufferPointer _boundsBufferInsideSubcell; + gpu::BufferPointer _boundsBufferPartial; + gpu::BufferPointer _boundsBufferPartialSubcell; bool _showInsideItems; // initialized by Config bool _showInsideSubcellItems; // initialized by Config diff --git a/libraries/render/src/render/DrawStatus.cpp b/libraries/render/src/render/DrawStatus.cpp index 1c5ab27507..9b7d4ace2b 100644 --- a/libraries/render/src/render/DrawStatus.cpp +++ b/libraries/render/src/render/DrawStatus.cpp @@ -51,7 +51,7 @@ const gpu::PipelinePointer DrawStatus::getDrawItemBoundsPipeline() { const gpu::PipelinePointer DrawStatus::getDrawItemStatusPipeline() { if (!_drawItemStatusPipeline) { - gpu::ShaderPointer program = gpu::Shader::createProgram(shader::render::program::blurGaussianDepthAwareV); + gpu::ShaderPointer program = gpu::Shader::createProgram(shader::render::program::drawItemStatus); auto state = std::make_shared(); @@ -92,36 +92,30 @@ void DrawStatus::run(const RenderContextPointer& renderContext, const Input& inp const auto& inItems = input.get0(); const auto jitter = input.get1(); - // FIrst thing, we collect the bound and the status for all the items we want to render + // First thing, we collect the bound and the status for all the items we want to render int nbItems = 0; + render::ItemBounds itemBounds; + std::vector> itemStatus; { - _itemBounds.resize(inItems.size()); - _itemStatus.resize(inItems.size()); - _itemCells.resize(inItems.size()); - -// AABox* itemAABox = reinterpret_cast (_itemBounds->editData()); -// glm::ivec4* itemStatus = reinterpret_cast (_itemStatus->editData()); -// Octree::Location* itemCell = reinterpret_cast (_itemCells->editData()); for (size_t i = 0; i < inItems.size(); ++i) { const auto& item = inItems[i]; if (!item.bound.isInvalid()) { if (!item.bound.isNull()) { - _itemBounds[i] = item.bound; + itemBounds.emplace_back(render::ItemBound(item.id, item.bound)); } else { - _itemBounds[i].setBox(item.bound.getCorner(), 0.1f); + itemBounds.emplace_back(item.id, AABox(item.bound.getCorner(), 0.1f)); } - auto& itemScene = scene->getItem(item.id); - _itemCells[i] = scene->getSpatialTree().getCellLocation(itemScene.getCell()); auto itemStatusPointer = itemScene.getStatus(); if (itemStatusPointer) { + itemStatus.push_back(std::pair()); // Query the current status values, this is where the statusGetter lambda get called auto&& currentStatusValues = itemStatusPointer->getCurrentValues(); int valueNum = 0; for (int vec4Num = 0; vec4Num < NUM_STATUS_VEC4_PER_ITEM; vec4Num++) { - auto& value = (vec4Num ? _itemStatus[i].first : _itemStatus[i].second); + auto& value = (vec4Num ? itemStatus[nbItems].first : itemStatus[nbItems].second); value = glm::ivec4(Item::Status::Value::INVALID.getPackedData()); for (int component = 0; component < VEC4_LENGTH; component++) { valueNum = vec4Num * VEC4_LENGTH + component; @@ -131,7 +125,8 @@ void DrawStatus::run(const RenderContextPointer& renderContext, const Input& inp } } } else { - _itemStatus[i].first = _itemStatus[i].second = glm::ivec4(Item::Status::Value::INVALID.getPackedData()); + auto invalid = glm::ivec4(Item::Status::Value::INVALID.getPackedData()); + itemStatus.emplace_back(invalid, invalid); } nbItems++; } @@ -142,7 +137,11 @@ void DrawStatus::run(const RenderContextPointer& renderContext, const Input& inp return; } - // Allright, something to render let's do it + if (!_boundsBuffer) { + _boundsBuffer = std::make_shared(sizeof(render::ItemBound)); + } + + // Alright, something to render let's do it gpu::doInBatch("DrawStatus::run", args->_context, [&](gpu::Batch& batch) { glm::mat4 projMat; Transform viewMat; @@ -158,32 +157,24 @@ void DrawStatus::run(const RenderContextPointer& renderContext, const Input& inp // bind the one gpu::Pipeline we need batch.setPipeline(getDrawItemBoundsPipeline()); - //AABox* itemAABox = reinterpret_cast (_itemBounds->editData()); - //glm::ivec4* itemStatus = reinterpret_cast (_itemStatus->editData()); - //Octree::Location* itemCell = reinterpret_cast (_itemCells->editData()); - - const unsigned int VEC3_ADRESS_OFFSET = 3; + _boundsBuffer->setData(itemBounds.size() * sizeof(render::ItemBound), (const gpu::Byte*) itemBounds.data()); if (_showDisplay) { - for (int i = 0; i < nbItems; i++) { - //batch._glUniform3fv(gpu::slot::uniform::Extra0, 1, (const float*)&(_itemBounds[i])); - //batch._glUniform3fv(gpu::slot::uniform::Extra1, 1, ((const float*)&(_itemBounds[i])) + VEC3_ADRESS_OFFSET); - //glm::ivec4 cellLocation(_itemCells[i].pos, _itemCells[i].depth); - //batch._glUniform4iv(_drawItemCellLocLoc, 1, ((const int*)(&cellLocation))); - batch.draw(gpu::LINES, 24, 0); - } + batch.setResourceBuffer(0, _boundsBuffer); + batch.draw(gpu::LINES, (gpu::uint32) itemBounds.size() * 24, 0); } + batch.setResourceBuffer(0, 0); batch.setResourceTexture(0, gpu::TextureView(getStatusIconMap(), 0)); batch.setPipeline(getDrawItemStatusPipeline()); if (_showNetwork) { - for (int i = 0; i < nbItems; i++) { - batch._glUniform3fv(gpu::slot::uniform::Extra0, 1, (const float*)&(_itemBounds[i])); - batch._glUniform3fv(gpu::slot::uniform::Extra1, 1, ((const float*)&(_itemBounds[i])) + VEC3_ADRESS_OFFSET); - batch._glUniform4iv(gpu::slot::uniform::Extra2, 1, (const int*)&(_itemStatus[i].first)); - batch._glUniform4iv(gpu::slot::uniform::Extra3, 1, (const int*)&(_itemStatus[i].second)); + for (size_t i = 0; i < itemBounds.size(); i++) { + batch._glUniform3fv(gpu::slot::uniform::Extra0, 1, (const float*)&itemBounds[i].bound.getCorner()); + batch._glUniform3fv(gpu::slot::uniform::Extra1, 1, ((const float*)&itemBounds[i].bound.getScale())); + batch._glUniform4iv(gpu::slot::uniform::Extra2, 1, (const int*)&(itemStatus[i].first)); + batch._glUniform4iv(gpu::slot::uniform::Extra3, 1, (const int*)&(itemStatus[i].second)); batch.draw(gpu::TRIANGLES, 24 * NUM_STATUS_VEC4_PER_ITEM, 0); } } diff --git a/libraries/render/src/render/DrawStatus.h b/libraries/render/src/render/DrawStatus.h index 4228d1bd8d..96269fda4d 100644 --- a/libraries/render/src/render/DrawStatus.h +++ b/libraries/render/src/render/DrawStatus.h @@ -62,12 +62,7 @@ namespace render { gpu::PipelinePointer _drawItemBoundsPipeline; gpu::PipelinePointer _drawItemStatusPipeline; - std::vector _itemBounds; - std::vector> _itemStatus; - std::vector _itemCells; - //gpu::BufferPointer _itemBounds; - //gpu::BufferPointer _itemCells; - //gpu::BufferPointer _itemStatus; + gpu::BufferPointer _boundsBuffer; gpu::TexturePointer _statusIconMap; }; } diff --git a/libraries/render/src/render/Item.h b/libraries/render/src/render/Item.h index 28994d82b6..5ecfba2da8 100644 --- a/libraries/render/src/render/Item.h +++ b/libraries/render/src/render/Item.h @@ -321,6 +321,7 @@ inline QDebug operator<<(QDebug debug, const ItemFilter& me) { // Handy type to just pass the ID and the bound of an item class ItemBound { public: + ItemBound() {} ItemBound(ItemID id) : id(id) { } ItemBound(ItemID id, const AABox& bound) : id(id), bound(bound) { } diff --git a/libraries/render/src/render/drawCellBounds.slv b/libraries/render/src/render/drawCellBounds.slv index 8336885365..f3cc4c6411 100644 --- a/libraries/render/src/render/drawCellBounds.slv +++ b/libraries/render/src/render/drawCellBounds.slv @@ -24,7 +24,6 @@ layout(location=GPU_UNIFORM_EXTRA0) uniform ivec4 inCellLocation; layout(location=0) out vec4 varColor; - void main(void) { const vec4 UNIT_BOX[8] = vec4[8]( vec4(0.0, 0.0, 0.0, 1.0), diff --git a/libraries/render/src/render/drawItemBounds.slv b/libraries/render/src/render/drawItemBounds.slv index 059538de47..8925009160 100644 --- a/libraries/render/src/render/drawItemBounds.slv +++ b/libraries/render/src/render/drawItemBounds.slv @@ -20,10 +20,8 @@ <@include gpu/Color.slh@> <$declareColorWheel()$> - layout(location=GPU_UNIFORM_COLOR) uniform vec4 inColor; - struct ItemBound { vec4 id_boundPos; vec4 boundDim_s; @@ -48,8 +46,6 @@ ItemBound getItemBound(int i) { } #endif - - layout(location=0) out vec4 varColor; layout(location=1) out vec2 varTexcoord; diff --git a/scripts/developer/utilities/render/culling.qml b/scripts/developer/utilities/render/culling.qml index 2ce3cc1dea..801cb5b573 100644 --- a/scripts/developer/utilities/render/culling.qml +++ b/scripts/developer/utilities/render/culling.qml @@ -19,7 +19,7 @@ Column { Component.onCompleted: { sceneOctree.enabled = true; - itemSelection.enabled = true; + itemSelection.enabled = true; sceneOctree.showVisibleCells = false; sceneOctree.showEmptyCells = false; itemSelection.showInsideItems = false; @@ -29,9 +29,9 @@ Column { } Component.onDestruction: { sceneOctree.enabled = false; - itemSelection.enabled = false; + itemSelection.enabled = false; Render.getConfig("RenderMainView.FetchSceneSelection").freezeFrustum = false; - Render.getConfig("RenderMainView.CullSceneSelection").freezeFrustum = false; + Render.getConfig("RenderMainView.CullSceneSelection").freezeFrustum = false; } GroupBox { @@ -44,7 +44,7 @@ Column { CheckBox { text: "Freeze Culling Frustum" checked: false - onCheckedChanged: { + onCheckedChanged: { Render.getConfig("RenderMainView.FetchSceneSelection").freezeFrustum = checked; Render.getConfig("RenderMainView.CullSceneSelection").freezeFrustum = checked; } @@ -88,15 +88,19 @@ Column { text: "Partial Sub-cell Items" checked: false onCheckedChanged: { root.itemSelection.showPartialSubcellItems = checked } - } + } } } - } + } GroupBox { title: "Render Items" + anchors.left: parent.left; + anchors.right: parent.right; Column{ + anchors.left: parent.left; + anchors.right: parent.right; Repeater { model: [ "Opaque:RenderMainView.DrawOpaqueDeferred", "Transparent:RenderMainView.DrawTransparentDeferred", "Light:RenderMainView.DrawLight", "Opaque Overlays:RenderMainView.DrawOverlay3DOpaque", "Transparent Overlays:RenderMainView.DrawOverlay3DTransparent" ]