mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:14:59 +02:00
experimenting with drawHUDLayer depth testing
This commit is contained in:
parent
0117950546
commit
658acd91f2
6 changed files with 33 additions and 14 deletions
|
@ -24,4 +24,7 @@ out vec4 FragColor;
|
|||
void main() {
|
||||
FragColor = texture(sampler, vTexCoord);
|
||||
FragColor.a *= overlay.alpha;
|
||||
if (FragColor.a <= 0.0) {
|
||||
discard;
|
||||
}
|
||||
}
|
|
@ -41,7 +41,7 @@
|
|||
|
||||
Q_LOGGING_CATEGORY(trace_render_overlays, "trace.render.overlays")
|
||||
|
||||
extern void initOverlay3DPipelines(render::ShapePlumber& plumber);
|
||||
extern void initOverlay3DPipelines(render::ShapePlumber& plumber, bool depthTest = false);
|
||||
|
||||
void Overlays::cleanupAllOverlays() {
|
||||
QMap<OverlayID, Overlay::Pointer> overlaysHUD;
|
||||
|
@ -74,7 +74,7 @@ void Overlays::init() {
|
|||
_scriptEngine = new QScriptEngine();
|
||||
#endif
|
||||
_shapePlumber = std::make_shared<render::ShapePlumber>();
|
||||
initOverlay3DPipelines(*_shapePlumber);
|
||||
initOverlay3DPipelines(*_shapePlumber, true);
|
||||
}
|
||||
|
||||
void Overlays::update(float deltatime) {
|
||||
|
|
|
@ -626,6 +626,11 @@ void OpenGLDisplayPlugin::compositeLayers() {
|
|||
compositeScene();
|
||||
}
|
||||
|
||||
// Clear the depth framebuffer after drawing the scene so that the HUD elements can depth test against each other
|
||||
render([&](gpu::Batch& batch) {
|
||||
batch.setFramebuffer(_compositeFramebuffer);
|
||||
batch.clearDepthFramebuffer(UINT32_MAX);
|
||||
});
|
||||
|
||||
#ifdef HIFI_ENABLE_NSIGHT_DEBUG
|
||||
if (false) // do not compositeoverlay if running nsight debug
|
||||
|
@ -635,12 +640,6 @@ void OpenGLDisplayPlugin::compositeLayers() {
|
|||
compositeOverlay();
|
||||
}
|
||||
|
||||
auto compositorHelper = DependencyManager::get<CompositorHelper>();
|
||||
if (compositorHelper->getReticleVisible()) {
|
||||
PROFILE_RANGE_EX(render_detail, "compositePointer", 0xff0077ff, (uint64_t)presentCount())
|
||||
compositePointer();
|
||||
}
|
||||
|
||||
// Only render HUD layer 3D overlays in HMD mode
|
||||
if (isHmd()) {
|
||||
PROFILE_RANGE_EX(render_detail, "compositeHUDOverlays", 0xff0077ff, (uint64_t)presentCount())
|
||||
|
@ -655,6 +654,18 @@ void OpenGLDisplayPlugin::compositeLayers() {
|
|||
PROFILE_RANGE_EX(render_detail, "compositeExtra", 0xff0077ff, (uint64_t)presentCount())
|
||||
compositeExtra();
|
||||
}
|
||||
|
||||
// Clear the depth buffer again and draw the pointer last so it's on top of everything
|
||||
render([&](gpu::Batch& batch) {
|
||||
batch.setFramebuffer(_compositeFramebuffer);
|
||||
batch.clearDepthFramebuffer(UINT32_MAX);
|
||||
});
|
||||
|
||||
auto compositorHelper = DependencyManager::get<CompositorHelper>();
|
||||
if (compositorHelper->getReticleVisible()) {
|
||||
PROFILE_RANGE_EX(render_detail, "compositePointer", 0xff0077ff, (uint64_t)presentCount())
|
||||
compositePointer();
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLDisplayPlugin::internalPresent() {
|
||||
|
@ -861,7 +872,8 @@ OpenGLDisplayPlugin::~OpenGLDisplayPlugin() {
|
|||
void OpenGLDisplayPlugin::updateCompositeFramebuffer() {
|
||||
auto renderSize = getRecommendedRenderSize();
|
||||
if (!_compositeFramebuffer || _compositeFramebuffer->getSize() != renderSize) {
|
||||
_compositeFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("OpenGLDisplayPlugin::composite", gpu::Element::COLOR_RGBA_32, renderSize.x, renderSize.y));
|
||||
auto depthFormat = gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::DEPTH_STENCIL);
|
||||
_compositeFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("OpenGLDisplayPlugin::composite", gpu::Element::COLOR_RGBA_32, depthFormat, renderSize.x, renderSize.y));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -443,7 +443,7 @@ void HmdDisplayPlugin::OverlayRenderer::updatePipeline() {
|
|||
this->uniformsLocation = program->getUniformBuffers().findLocation("overlayBuffer");
|
||||
|
||||
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
|
||||
state->setDepthTest(gpu::State::DepthTest(true));
|
||||
state->setDepthTest(gpu::State::DepthTest(true, true, gpu::LESS_EQUAL));
|
||||
state->setBlendFunction(true,
|
||||
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
|
||||
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
|
||||
|
||||
using namespace render;
|
||||
extern void initOverlay3DPipelines(render::ShapePlumber& plumber);
|
||||
extern void initOverlay3DPipelines(render::ShapePlumber& plumber, bool depthTest = false);
|
||||
extern void initDeferredPipelines(render::ShapePlumber& plumber);
|
||||
|
||||
void RenderDeferredTask::build(JobModel& task, const render::Varying& input, render::Varying& output) {
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
using namespace render;
|
||||
using namespace std::placeholders;
|
||||
|
||||
void initOverlay3DPipelines(ShapePlumber& plumber);
|
||||
void initOverlay3DPipelines(ShapePlumber& plumber, bool depthTest = false);
|
||||
void initDeferredPipelines(ShapePlumber& plumber);
|
||||
void initForwardPipelines(ShapePlumber& plumber);
|
||||
|
||||
|
@ -79,7 +79,7 @@ void addPlumberPipeline(ShapePlumber& plumber,
|
|||
void batchSetter(const ShapePipeline& pipeline, gpu::Batch& batch, RenderArgs* args);
|
||||
void lightBatchSetter(const ShapePipeline& pipeline, gpu::Batch& batch, RenderArgs* args);
|
||||
|
||||
void initOverlay3DPipelines(ShapePlumber& plumber) {
|
||||
void initOverlay3DPipelines(ShapePlumber& plumber, bool depthTest) {
|
||||
auto vertex = gpu::Shader::createVertex(std::string(overlay3D_vert));
|
||||
auto vertexModel = gpu::Shader::createVertex(std::string(model_vert));
|
||||
auto pixel = gpu::Shader::createPixel(std::string(overlay3D_frag));
|
||||
|
@ -106,7 +106,11 @@ void initOverlay3DPipelines(ShapePlumber& plumber) {
|
|||
bool isOpaque = (i & 4);
|
||||
|
||||
auto state = std::make_shared<gpu::State>();
|
||||
state->setDepthTest(false);
|
||||
if (depthTest) {
|
||||
state->setDepthTest(true, true, gpu::LESS_EQUAL);
|
||||
} else {
|
||||
state->setDepthTest(false);
|
||||
}
|
||||
state->setCullMode(isCulled ? gpu::State::CULL_BACK : gpu::State::CULL_NONE);
|
||||
if (isBiased) {
|
||||
state->setDepthBias(1.0f);
|
||||
|
|
Loading…
Reference in a new issue