Commit 83bc86c3 authored by Michele Bosi's avatar Michele Bosi

Depth Peeling auto throttle option (enabled by default)

parent a033273c
......@@ -454,7 +454,7 @@ void VividRenderer::renderFrontToBackPeeling(const RenderQueue* render_queue, Ca
// Fill
mShaderFrontInit->useProgram();
mShaderFrontInit->applyUniformSet();
renderQueue( render_queue, mShaderFrontInit.get(), camera, frame_clock, true, false );
int translucent_count = renderQueue( render_queue, mShaderFrontInit.get(), camera, frame_clock, true, false );
// Outline 3D
mShaderFrontInit_S->useProgram();
......@@ -483,9 +483,10 @@ void VividRenderer::renderFrontToBackPeeling(const RenderQueue* render_queue, Ca
// 2. Depth Peeling + Blending
// ---------------------------------------------------------------------
bool throttle = 0 == translucent_count && mVividRendering->depthPeelingAutoThrottleEnabled();
GLuint samples_passed;
int numLayers = (mNumPasses - 1) * 2;
for (int layer = 1; mUseQueryObject || layer < numLayers; layer++) {
for (int layer = 1; ! throttle && ( mUseQueryObject || layer < numLayers); layer++) {
int currId = layer % 2;
int prevId = 1 - currId;
......@@ -760,9 +761,11 @@ void VividRenderer::render2DOutlines(const RenderQueue* render_queue, Camera* ca
glDisable( GL_POLYGON_OFFSET_FILL );
}
//-------------------------------------------------------------------------------------------------
void VividRenderer::renderQueue(const RenderQueue* render_queue, GLSLProgram* cur_glsl, Camera* camera, real frame_clock, bool depth_peeling_on, bool outline_on ) {
int VividRenderer::renderQueue(const RenderQueue* render_queue, GLSLProgram* cur_glsl, Camera* camera, real frame_clock, bool depth_peeling_on, bool outline_on ) {
mPassCounter++;
int translucent_actor_count = 0;
OpenGLContext* opengl_context = framebuffer()->openglContext();
// Update matrices
......@@ -842,6 +845,28 @@ void VividRenderer::renderQueue(const RenderQueue* render_queue, GLSLProgram* cu
TextureSampler::reset( Vivid::UserTexture, opengl_context );
}
// Simple translucent actor detection
// This works in the simplest but usual cases where:
// - Lighting is on and material diffuse alpha is < 1
// - Outline color alpha is < 1
// - All vertex colors alphas are < 1
// - Texture has transparent texels, ie alpha == 0 (point sprites, alpha masking etc.)
// Does not detect:
// - Some but not all vertex color alphas are < 1
// - Texture has translucent texels, ie 0 < alpha < 1 (as opposed to 0 <= alpha <= 1)
vec4 vc;
Geometry* geom = dynamic_cast<Geometry*>( tok->mRenderable );
if ( geom ) {
ArrayFloat4* ca = geom->colorArray()->as<ArrayFloat4>();
vc = ca && ca->size() ? ca->at(0) : vl::white;
}
if ( shader->getMaterial()->frontDiffuse().a() < 1 ||
shader->getUniform("vl_Vivid.outline.color")->getUniform4F().a() < 1 ||
vc.a() < 1 ) {
++translucent_actor_count;
}
shader->getPointSize()->apply(0, NULL, opengl_context); VL_CHECK_OGL()
shader->getPolygonMode()->apply(0, NULL, opengl_context); VL_CHECK_OGL()
shader->getMaterial()->apply(0, NULL, opengl_context); VL_CHECK_OGL()
......@@ -909,6 +934,8 @@ void VividRenderer::renderQueue(const RenderQueue* render_queue, GLSLProgram* cu
}
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
return translucent_actor_count;
}
//-------------------------------------------------------------------------------------------------
const RenderQueue* VividRenderer::render(const RenderQueue* render_queue, Camera* camera, real frame_clock)
......
......@@ -79,7 +79,7 @@ namespace vl
const Texture* depthFBOTex() const { return mDepthFBOTex.get(); }
protected:
void renderQueue(const RenderQueue* in_render_queue, vl::GLSLProgram* cur_glsl, Camera* camera, real frame_clock, bool depth_peeling_on=true, bool outline_on = false);
int renderQueue(const RenderQueue* in_render_queue, vl::GLSLProgram* cur_glsl, Camera* camera, real frame_clock, bool depth_peeling_on=true, bool outline_on = false);
void renderBackgroundImage( Camera* camera );
void render2DOutlines( const RenderQueue* in_render_queue, Camera* camera, real frame_clock );
// Used to render volumes, text and all Actors that we want to render using the standard VL rendering
......
......@@ -79,6 +79,10 @@ VividRendering::VividRendering() {
mStencilBackground = vl::black;
mStencilEnabled = false;
// Depth Peeling Throttle
m_DepthPeelingAutoThrottleEnabled = true;
// Volume
mVividVolume = new VividVolume( this );
......
......@@ -104,7 +104,6 @@ namespace vl
} ESurfaceMode;
}
//-----------------------------------------------------------------------------
// VividRendering
//-----------------------------------------------------------------------------
......@@ -182,6 +181,19 @@ namespace vl
TextureSampler* backgroundTexSampler() { return mBackgroundTexSampler.get(); }
const TextureSampler* backgroundTexSampler() const { return mBackgroundTexSampler.get(); }
// Allow depth peeling to be disabled for a faster rendering using a simple test.
// This works in the simplest but usual cases where:
// - Lighting is on and material diffuse alpha is < 1
// - Outline color alpha is < 1
// - All vertex colors alphas are < 1
// - Texture has transparent texels, ie alpha == 0 (point sprites, alpha masking etc.)
// - Point sprites may look a bit rough
// Does not detect:
// - Some but not all vertex color alphas are < 1
// - Texture has translucent texels, ie 0 < alpha < 1 (as opposed to 0 <= alpha <= 1)
void setDepthPeelingAutoThrottleEnabled( bool enabled ) { m_DepthPeelingAutoThrottleEnabled = enabled; }
bool depthPeelingAutoThrottleEnabled() const { return m_DepthPeelingAutoThrottleEnabled; }
// Volumes
/** Initializes all the volume data, uniforms and textures using VividVolume::setupVolume() and adds the volume actor to the scene.
......@@ -227,6 +239,8 @@ namespace vl
bool mBackgroundImageEnabled;
ref<TextureSampler> mBackgroundTexSampler;
bool m_DepthPeelingAutoThrottleEnabled;
// Volume
ref<VividVolume> mVividVolume;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment