Take back manual depth test for the two pass model rendering

This commit is contained in:
Malin E
2023-02-21 18:08:38 +01:00
parent a877324c95
commit f6eac4f0c7
5 changed files with 111 additions and 7 deletions

View File

@@ -59,7 +59,9 @@ class FramebufferRenderer final : public RaycasterListener, public Deferredcaste
public:
virtual ~FramebufferRenderer() override = default;
// Functions to access and reuse some of the existing textures
//============================//
//===== Reuse textures =====//
//============================//
/**
* Gives access to the currently NOT used pingPongTexture. This texture is available
* for all RenderBins. However, it cannot be used at the same time as the Deferred
@@ -100,6 +102,46 @@ public:
*/
GLuint additionalDepthTexture();
//=============================//
//===== Access G-buffer =====//
//=============================//
// Functions to access the G-buffer textures
/**
* Gives access to the color texture of the G-buffer. NOTE: This texture is used for
* the majority of rendering the scene and might be already in use. Use CAUTION when
* using this function. The size of the texture is the resolution of the viewport.
*
* \return GLuint identifier of the color texture of the G-buffer
*/
GLuint gBufferColorTexture();
/**
* Gives access to the position texture of the G-buffer. NOTE: This texture is used for
* the majority of rendering the scene and might be already in use. Use CAUTION when
* using this function. The size of the texture is the resolution of the viewport.
*
* \return GLuint identifier of the position texture of the G-buffer
*/
GLuint gBufferPositionTexture();
/**
* Gives access to the normal texture of the G-buffer. NOTE: This texture is used for
* the majority of rendering the scene and might be already in use. Use CAUTION when
* using this function. The size of the texture is the resolution of the viewport.
*
* \return GLuint identifier of the normal texture of the G-buffer
*/
GLuint gBufferNormalTexture();
/**
* Gives access to the depth texture of the G-buffer. NOTE: This texture is used for
* the majority of rendering the scene and might be already in use. Use CAUTION when
* using this function. The size of the texture is the resolution of the viewport.
*
* \return GLuint identifier of the depth texture of the G-buffer
*/
GLuint gBufferDepthTexture();
void initialize();
void deinitialize();

View File

@@ -71,11 +71,11 @@ namespace {
GL_COLOR_ATTACHMENT2,
};
constexpr std::array<const char*, 10> UniformNames = {
constexpr std::array<const char*, 12> UniformNames = {
"nLightSources", "lightDirectionsViewSpace", "lightIntensities",
"modelViewTransform", "normalTransform", "projectionTransform",
"performShading", "ambientIntensity", "diffuseIntensity",
"specularIntensity"
"specularIntensity", "performManualDepthTest", "gBufferDepthTexture"
};
constexpr std::array<const char*, 5> UniformOpacityNames = {
@@ -781,6 +781,12 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) {
}
if (!shouldRenderTwise) {
// Reset manual depth test
_program->setUniform(
_uniformCache.performManualDepthTest,
false
);
_geometry->render(*_program);
}
else {
@@ -806,6 +812,26 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) {
glClearBufferfv(GL_COLOR, 1, glm::value_ptr(glm::vec4(0.f, 0.f, 0.f, 0.f)));
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Use a manuel depth test to make the models aware of the rest of the envierment
_program->setUniform(
_uniformCache.performManualDepthTest,
true
);
// Bind the G-buffer depth texture for a manual depth test towards the rest
// of the scene
ghoul::opengl::TextureUnit gBufferDepthTextureUnit;
gBufferDepthTextureUnit.activate();
glBindTexture(
GL_TEXTURE_2D,
global::renderEngine->renderer()->gBufferDepthTexture()
);
_program->setUniform(
_uniformCache.gBufferDepthTexture,
gBufferDepthTextureUnit
);
// Render Pass 1
// Render all parts of the model into the new framebuffer without opacity
_geometry->render(*_program);

View File

@@ -106,7 +106,7 @@ private:
UniformCache(nLightSources, lightDirectionsViewSpace, lightIntensities,
modelViewTransform, normalTransform, projectionTransform,
performShading, ambientIntensity, diffuseIntensity,
specularIntensity) _uniformCache;
specularIntensity, performManualDepthTest, gBufferDepthTexture) _uniformCache;
std::vector<std::unique_ptr<LightSource>> _lightSources;

View File

@@ -48,6 +48,8 @@ uniform vec4 color_specular;
uniform int nLightSources;
uniform vec3 lightDirectionsViewSpace[8];
uniform float lightIntensities[8];
uniform bool performManualDepthTest = false;
uniform sampler2D gBufferDepthTexture;
Fragment getFragment() {
Fragment frag;
@@ -56,6 +58,17 @@ Fragment getFragment() {
frag.gNormal = vec4(vs_normalViewSpace, 0.0);
frag.disableLDR2HDR = true;
if (performManualDepthTest) {
// Manual depth test
float gBufferDepth =
denormalizeFloat(texture(gBufferDepthTexture, viewportPixelCoord).x);
if (vs_screenSpaceDepth > gBufferDepth) {
frag.color = vec4(0.f);
frag.depth = gBufferDepth;
return frag;
}
}
// Render invisible mesh with flashy procedural material
if (use_forced_color) {
vec3 adjustedPos = floor(vs_positionCameraSpace.xyz * 3.0);

View File

@@ -87,9 +87,9 @@ namespace {
namespace openspace {
//=====================================//
//===== Reuse NOT used textures =====//
//=====================================//
//============================//
//===== Reuse textures =====//
//============================//
// Gives access to the currently NOT used pingPongTexture
GLuint FramebufferRenderer::additionalColorTexture1() {
int unusedPingPongIndex = _pingPongIndex == 0 ? 1 : 0;
@@ -111,6 +111,29 @@ GLuint FramebufferRenderer::additionalDepthTexture() {
return _exitDepthTexture;
}
//=============================//
//===== Access G-buffer =====//
//=============================//
// / Gives access to the color texture of the G-buffer
GLuint FramebufferRenderer::gBufferColorTexture() {
return _gBuffers.colorTexture;
}
// Gives access to the position texture of the G-buffer
GLuint FramebufferRenderer::gBufferPositionTexture() {
return _gBuffers.positionTexture;
}
// Gives access to the normal texture of the G-buffer
GLuint FramebufferRenderer::gBufferNormalTexture() {
return _gBuffers.normalTexture;
}
// Gives access to the depth texture of the G-buffer
GLuint FramebufferRenderer::gBufferDepthTexture() {
return _gBuffers.depthTexture;
}
void FramebufferRenderer::initialize() {
ZoneScoped
TracyGpuZone("Rendering initialize");