Render depth buffer to quad

Useful for graphics debugging
This commit is contained in:
Niraj Venkat 2015-07-16 09:46:28 -07:00
parent 0ee916fb6f
commit 022529f03f
4 changed files with 32 additions and 12 deletions

View file

@ -27,6 +27,7 @@
#include "TextureCache.h"
#include "DependencyManager.h"
#include "ViewFrustum.h"
#include "GeometryCache.h"
#include "ambient_occlusion_vert.h"
#include "ambient_occlusion_frag.h"
@ -190,10 +191,10 @@ const gpu::PipelinePointer& AmbientOcclusion::getAOPipeline() {
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
state->setDepthTest(true, false, gpu::LESS_EQUAL);
state->setDepthTest(false, false, gpu::LESS_EQUAL);
// Blend on transparent
state->setBlendFunction(true,
state->setBlendFunction(false,
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
gpu::State::DEST_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ZERO);
@ -225,11 +226,17 @@ void AmbientOcclusion::run(const render::SceneContextPointer& sceneContext, cons
batch.setProjectionTransform(projMat);
batch.setViewTransform(viewMat);
batch.setModelTransform(Transform());
batch.setResourceTexture(0, DependencyManager::get<TextureCache>()->getPrimaryDepthTexture());
// bind the one gpu::Pipeline we need
batch.setPipeline(getAOPipeline());
//renderFullscreenQuad();
glm::vec4 color(0.0f, 0.0f, 0.0f, 1.0f);
glm::vec2 bottomLeft(0.5f, -1.0f);
glm::vec2 topRight(1.0f, -0.5f);
glm::vec2 texCoordTopLeft(0.0f, 0.0f);
glm::vec2 texCoordBottomRight(1.0f, 1.0f);
DependencyManager::get<GeometryCache>()->renderQuad(batch, bottomLeft, topRight, texCoordTopLeft, texCoordBottomRight, color);
args->_context->syncCache();
renderContext->args->_context->syncCache();

View file

@ -59,6 +59,7 @@ RenderDeferredTask::RenderDeferredTask() : Task() {
_jobs.push_back(Job(new ResetGLState::JobModel()));
_jobs.push_back(Job(new RenderDeferred::JobModel("RenderDeferred")));
_jobs.push_back(Job(new ResolveDeferred::JobModel("ResolveDeferred")));
_jobs.push_back(Job(new AmbientOcclusion::JobModel("AmbientOcclusion")));
_jobs.push_back(Job(new FetchItems::JobModel("FetchTransparent",
FetchItems(
ItemFilter::Builder::transparentShape().withoutLayered(),
@ -77,8 +78,9 @@ RenderDeferredTask::RenderDeferredTask() : Task() {
_jobs.back().setEnabled(false);
_drawStatusJobIndex = _jobs.size() - 1;
//_jobs.push_back(Job(new AmbientOcclusion::JobModel("AmbientOcclusion")));
_jobs.push_back(Job(new DrawOverlay3D::JobModel("DrawOverlay3D")));
_jobs.push_back(Job(new AmbientOcclusion::JobModel("AmbientOcclusion")));
_jobs.push_back(Job(new ResetGLState::JobModel()));
// Give ourselves 3 frmaes of timer queries

View file

@ -2,11 +2,11 @@
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// simple.frag
// ambient_occlusion.frag
// fragment shader
//
// Created by Andrzej Kapolka on 9/15/14.
// Copyright 2014 High Fidelity, Inc.
// Created by Niraj Venkat on 7/15/15.
// Copyright 2015 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
@ -17,6 +17,16 @@
// the interpolated normal
//varying vec4 interpolatedNormal;
varying vec2 varTexcoord;
uniform sampler2D depthTexture;
void main(void) {
gl_FragColor = vec4(0.0, 1.0, 1.0, 1.0);
vec4 depthColor = texture2D(depthTexture, varTexcoord.xy);
float z = depthColor.r; // fetch the z-value from our depth texture
float n = 1.0; // the near plane
float f = 30.0; // the far plane
float c = (2.0 * n) / (f + n - z * (f - n)); // convert to linear values
gl_FragColor = vec4(c, c, c, 1.0);
}

View file

@ -2,11 +2,11 @@
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// simple.vert
// ambient_occlusion.vert
// vertex shader
//
// Created by Andrzej Kapolka on 9/15/14.
// Copyright 2014 High Fidelity, Inc.
// Created by Niraj Venkat on 7/15/15.
// Copyright 2015 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
@ -18,8 +18,9 @@
// the interpolated normal
//varying vec4 interpolatedNormal;
varying vec2 varTexcoord;
void main(void) {
//gl_TexCoord[0] = gl_MultiTexCoord0;
varTexcoord = gl_MultiTexCoord0.xy;
gl_Position = gl_Vertex;
}