mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 15:43:50 +02:00
Merge pull request #13766 from SamGondelman/shaders
Miscellaneous shader fixes
This commit is contained in:
commit
16b483b338
16 changed files with 129 additions and 269 deletions
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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)$>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Config>(renderContext->jobConfig)->numAllocatedCells = (int)scene->getSpatialTree().getNumAllocatedCells();
|
||||
std::static_pointer_cast<Config>(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<gpu::Stamp>& 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));
|
||||
|
@ -142,10 +125,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<gpu::State>();
|
||||
|
||||
state->setDepthTest(true, false, gpu::LESS_EQUAL);
|
||||
|
@ -173,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<gpu::Buffer>(sizeof(render::ItemBound));
|
||||
}
|
||||
if (!_boundsBufferInsideSubcell) {
|
||||
_boundsBufferInsideSubcell = std::make_shared<gpu::Buffer>(sizeof(render::ItemBound));
|
||||
}
|
||||
if (!_boundsBufferPartial) {
|
||||
_boundsBufferPartial = std::make_shared<gpu::Buffer>(sizeof(render::ItemBound));
|
||||
}
|
||||
if (!_boundsBufferPartialSubcell) {
|
||||
_boundsBufferPartialSubcell = std::make_shared<gpu::Buffer>(sizeof(render::ItemBound));
|
||||
}
|
||||
|
||||
gpu::doInBatch("DrawItemSelection::run", args->_context, [&](gpu::Batch& batch) {
|
||||
glm::mat4 projMat;
|
||||
Transform viewMat;
|
||||
|
@ -187,63 +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._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);
|
||||
}
|
||||
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._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);
|
||||
}
|
||||
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._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);
|
||||
}
|
||||
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._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);
|
||||
}
|
||||
drawItemBounds(inSelection.partialSubcellItems, _boundsBufferPartialSubcell);
|
||||
}
|
||||
batch.setResourceBuffer(0, 0);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<gpu::State>();
|
||||
|
||||
|
@ -54,11 +51,7 @@ 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("");
|
||||
gpu::ShaderPointer program = gpu::Shader::createProgram(shader::render::program::drawItemStatus);
|
||||
|
||||
auto state = std::make_shared<gpu::State>();
|
||||
|
||||
|
@ -99,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<std::pair<glm::ivec4, glm::ivec4>> itemStatus;
|
||||
{
|
||||
_itemBounds.resize(inItems.size());
|
||||
_itemStatus.resize(inItems.size());
|
||||
_itemCells.resize(inItems.size());
|
||||
|
||||
// AABox* itemAABox = reinterpret_cast<AABox*> (_itemBounds->editData());
|
||||
// glm::ivec4* itemStatus = reinterpret_cast<glm::ivec4*> (_itemStatus->editData());
|
||||
// Octree::Location* itemCell = reinterpret_cast<Octree::Location*> (_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<glm::ivec4, glm::ivec4>());
|
||||
// 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;
|
||||
|
@ -138,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++;
|
||||
}
|
||||
|
@ -149,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<gpu::Buffer>(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;
|
||||
|
@ -165,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<AABox*> (_itemBounds->editData());
|
||||
//glm::ivec4* itemStatus = reinterpret_cast<glm::ivec4*> (_itemStatus->editData());
|
||||
//Octree::Location* itemCell = reinterpret_cast<Octree::Location*> (_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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,12 +62,7 @@ namespace render {
|
|||
gpu::PipelinePointer _drawItemBoundsPipeline;
|
||||
gpu::PipelinePointer _drawItemStatusPipeline;
|
||||
|
||||
std::vector<AABox> _itemBounds;
|
||||
std::vector<std::pair<glm::ivec4, glm::ivec4>> _itemStatus;
|
||||
std::vector<Octree::Location> _itemCells;
|
||||
//gpu::BufferPointer _itemBounds;
|
||||
//gpu::BufferPointer _itemCells;
|
||||
//gpu::BufferPointer _itemStatus;
|
||||
gpu::BufferPointer _boundsBuffer;
|
||||
gpu::TexturePointer _statusIconMap;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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) { }
|
||||
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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" ]
|
||||
|
|
Loading…
Reference in a new issue