Clean up advanced pipeline off code

Don't use RTT at all in game when it's off
This commit is contained in:
Benau 2018-01-25 15:36:34 +08:00
parent 5b4be274fb
commit ff38cb6423
7 changed files with 224 additions and 229 deletions

View File

@ -10,12 +10,16 @@ out vec4 FragColor;
void main(void) void main(void)
{ {
float billboard_alpha = mix(1.0, texture(tex, tc).a, billboard_mix);
#if defined(Advanced_Lighting_Enabled)
vec2 xy = gl_FragCoord.xy / u_screen; vec2 xy = gl_FragCoord.xy / u_screen;
float FragZ = gl_FragCoord.z; float FragZ = gl_FragCoord.z;
vec4 FragmentPos = getPosFromUVDepth(vec3(xy, FragZ), u_inverse_projection_matrix); vec4 FragmentPos = getPosFromUVDepth(vec3(xy, FragZ), u_inverse_projection_matrix);
float EnvZ = texture(dtex, xy).x; float EnvZ = texture(dtex, xy).x;
vec4 EnvPos = getPosFromUVDepth(vec3(xy, EnvZ), u_inverse_projection_matrix); vec4 EnvPos = getPosFromUVDepth(vec3(xy, EnvZ), u_inverse_projection_matrix);
float alpha = clamp((EnvPos.z - FragmentPos.z) * 0.3, 0., 1.); float alpha = clamp((EnvPos.z - FragmentPos.z) * 0.3, 0., 1.);
float billboard_alpha = mix(1.0, texture(tex, tc).a, billboard_mix); #else
float alpha = 1.0;
#endif
FragColor = texture(tex, tc) * billboard_alpha * pc * alpha; FragColor = texture(tex, tc) * billboard_alpha * pc * alpha;
} }

View File

@ -297,7 +297,8 @@ void CPUParticleManager::drawAll()
{ {
ParticleRenderer::getInstance()->setTextureUnits ParticleRenderer::getInstance()->setTextureUnits
(cur_mat->getTexture()->getOpenGLTextureName(), (cur_mat->getTexture()->getOpenGLTextureName(),
irr_driver->getDepthStencilTexture()); CVS->isDefferedEnabled() ?
irr_driver->getDepthStencilTexture() : 0);
ParticleRenderer::getInstance()->setUniforms(flips, billboard); ParticleRenderer::getInstance()->setUniforms(flips, billboard);
} }
else else

View File

@ -53,11 +53,12 @@ static GLuint generateRTT(const core::dimension2du &res, GLint internalFormat, G
return result; return result;
} }
RTT::RTT(unsigned int width, unsigned int height, float rtt_scale) RTT::RTT(unsigned int width, unsigned int height, float rtt_scale,
bool use_default_fbo_only)
{ {
m_width = (unsigned int)(width * rtt_scale); m_width = (unsigned int)(width * rtt_scale);
m_height = (unsigned int)(height * rtt_scale); m_height = (unsigned int)(height * rtt_scale);
m_shadow_FBO = NULL; m_shadow_fbo = NULL;
using namespace video; using namespace video;
using namespace core; using namespace core;
@ -75,7 +76,10 @@ RTT::RTT(unsigned int width, unsigned int height, float rtt_scale)
unsigned linear_depth_mip_levels = int(ceilf(log2f( float(max_(res.Width, res.Height)) ))); unsigned linear_depth_mip_levels = int(ceilf(log2f( float(max_(res.Width, res.Height)) )));
DepthStencilTexture = generateRTT(res, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8); if (!use_default_fbo_only)
{
m_depth_stencil_tex = generateRTT(res, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
}
// All RTTs are currently RGBA16F mostly with stencil. The four tmp RTTs are the same size // All RTTs are currently RGBA16F mostly with stencil. The four tmp RTTs are the same size
// as the screen, for use in post-processing. // as the screen, for use in post-processing.
@ -103,190 +107,193 @@ RTT::RTT(unsigned int width, unsigned int height, float rtt_scale)
type = GL_UNSIGNED_BYTE; type = GL_UNSIGNED_BYTE;
} }
#endif #endif
if (!CVS->isDefferedEnabled())
{
// RTT is used in only deferred shading which need hdr framebuffer
rgba_internal_format = GL_RGBA8;
type = GL_UNSIGNED_BYTE;
}
RenderTargetTextures[RTT_TMP1] = generateRTT(res, rgba_internal_format, rgba_format, type); if (!use_default_fbo_only)
RenderTargetTextures[RTT_TMP2] = generateRTT(res, rgba_internal_format, rgba_format, type); {
RenderTargetTextures[RTT_TMP3] = generateRTT(res, rgba_internal_format, rgba_format, type); m_render_target_textures[RTT_COLOR] = generateRTT(res, rgba_internal_format, rgba_format, type);
RenderTargetTextures[RTT_TMP4] = generateRTT(res, red_internal_format, red_format, type); }
RenderTargetTextures[RTT_LINEAR_DEPTH] = generateRTT(res, red32_internal_format, red_format, type, linear_depth_mip_levels); if (CVS->isDefferedEnabled())
RenderTargetTextures[RTT_NORMAL_AND_DEPTH] = generateRTT(res, GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV); {
RenderTargetTextures[RTT_COLOR] = generateRTT(res, rgba_internal_format, rgba_format, type); m_render_target_textures[RTT_NORMAL_AND_DEPTH] = generateRTT(res, GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV);
RenderTargetTextures[RTT_MLAA_COLORS] = generateRTT(res, rgb_internal_format, rgb_format, GL_UNSIGNED_BYTE); m_render_target_textures[RTT_TMP1] = generateRTT(res, rgba_internal_format, rgba_format, type);
RenderTargetTextures[RTT_MLAA_TMP] = generateRTT(res, rgb_internal_format, rgb_format, GL_UNSIGNED_BYTE); m_render_target_textures[RTT_TMP2] = generateRTT(res, rgba_internal_format, rgba_format, type);
RenderTargetTextures[RTT_MLAA_BLEND] = generateRTT(res, rgb_internal_format, rgb_format, GL_UNSIGNED_BYTE); m_render_target_textures[RTT_TMP3] = generateRTT(res, rgba_internal_format, rgba_format, type);
RenderTargetTextures[RTT_SSAO] = generateRTT(res, red_internal_format, red_format, type); m_render_target_textures[RTT_TMP4] = generateRTT(res, red_internal_format, red_format, type);
RenderTargetTextures[RTT_DISPLACE] = generateRTT(res, rgba_internal_format, rgba_format, type); m_render_target_textures[RTT_LINEAR_DEPTH] = generateRTT(res, red32_internal_format, red_format, type, linear_depth_mip_levels);
RenderTargetTextures[RTT_DIFFUSE] = generateRTT(res, diffuse_specular_internal_format, rgb_format, type); m_render_target_textures[RTT_MLAA_COLORS] = generateRTT(res, rgb_internal_format, rgb_format, GL_UNSIGNED_BYTE);
RenderTargetTextures[RTT_SPECULAR] = generateRTT(res, diffuse_specular_internal_format, rgb_format, type); m_render_target_textures[RTT_MLAA_TMP] = generateRTT(res, rgb_internal_format, rgb_format, GL_UNSIGNED_BYTE);
m_render_target_textures[RTT_MLAA_BLEND] = generateRTT(res, rgb_internal_format, rgb_format, GL_UNSIGNED_BYTE);
m_render_target_textures[RTT_SSAO] = generateRTT(res, red_internal_format, red_format, type);
m_render_target_textures[RTT_DISPLACE] = generateRTT(res, rgba_internal_format, rgba_format, type);
m_render_target_textures[RTT_DIFFUSE] = generateRTT(res, diffuse_specular_internal_format, rgb_format, type);
m_render_target_textures[RTT_SPECULAR] = generateRTT(res, diffuse_specular_internal_format, rgb_format, type);
RenderTargetTextures[RTT_HALF1] = generateRTT(half, rgba_internal_format, rgba_format, type); m_render_target_textures[RTT_HALF1] = generateRTT(half, rgba_internal_format, rgba_format, type);
RenderTargetTextures[RTT_QUARTER1] = generateRTT(quarter, rgba_internal_format, rgba_format, type); m_render_target_textures[RTT_QUARTER1] = generateRTT(quarter, rgba_internal_format, rgba_format, type);
RenderTargetTextures[RTT_EIGHTH1] = generateRTT(eighth, rgba_internal_format, rgba_format, type); m_render_target_textures[RTT_EIGHTH1] = generateRTT(eighth, rgba_internal_format, rgba_format, type);
RenderTargetTextures[RTT_HALF1_R] = generateRTT(half, red_internal_format, red_format, type); m_render_target_textures[RTT_HALF1_R] = generateRTT(half, red_internal_format, red_format, type);
RenderTargetTextures[RTT_HALF2] = generateRTT(half, rgba_internal_format, rgba_format, type); m_render_target_textures[RTT_HALF2] = generateRTT(half, rgba_internal_format, rgba_format, type);
RenderTargetTextures[RTT_QUARTER2] = generateRTT(quarter, rgba_internal_format, rgba_format, type); m_render_target_textures[RTT_QUARTER2] = generateRTT(quarter, rgba_internal_format, rgba_format, type);
RenderTargetTextures[RTT_EIGHTH2] = generateRTT(eighth, rgba_internal_format, rgba_format, type); m_render_target_textures[RTT_EIGHTH2] = generateRTT(eighth, rgba_internal_format, rgba_format, type);
RenderTargetTextures[RTT_HALF2_R] = generateRTT(half, red_internal_format, red_format, type); m_render_target_textures[RTT_HALF2_R] = generateRTT(half, red_internal_format, red_format, type);
RenderTargetTextures[RTT_BLOOM_1024] = generateRTT(shadowsize0, rgba_internal_format, rgb_format, type); m_render_target_textures[RTT_BLOOM_1024] = generateRTT(shadowsize0, rgba_internal_format, rgb_format, type);
RenderTargetTextures[RTT_BLOOM_512] = generateRTT(shadowsize1, rgba_internal_format, rgb_format, type); m_render_target_textures[RTT_BLOOM_512] = generateRTT(shadowsize1, rgba_internal_format, rgb_format, type);
RenderTargetTextures[RTT_TMP_512] = generateRTT(shadowsize1, rgba_internal_format, rgb_format, type); m_render_target_textures[RTT_TMP_512] = generateRTT(shadowsize1, rgba_internal_format, rgb_format, type);
RenderTargetTextures[RTT_LENS_512] = generateRTT(shadowsize1, rgba_internal_format, rgb_format, type); m_render_target_textures[RTT_LENS_512] = generateRTT(shadowsize1, rgba_internal_format, rgb_format, type);
RenderTargetTextures[RTT_BLOOM_256] = generateRTT(shadowsize2, rgba_internal_format, rgb_format, type); m_render_target_textures[RTT_BLOOM_256] = generateRTT(shadowsize2, rgba_internal_format, rgb_format, type);
RenderTargetTextures[RTT_TMP_256] = generateRTT(shadowsize2, rgba_internal_format, rgb_format, type); m_render_target_textures[RTT_TMP_256] = generateRTT(shadowsize2, rgba_internal_format, rgb_format, type);
RenderTargetTextures[RTT_LENS_256] = generateRTT(shadowsize2, rgba_internal_format, rgb_format, type); m_render_target_textures[RTT_LENS_256] = generateRTT(shadowsize2, rgba_internal_format, rgb_format, type);
RenderTargetTextures[RTT_BLOOM_128] = generateRTT(shadowsize3, rgba_internal_format, rgb_format, type); m_render_target_textures[RTT_BLOOM_128] = generateRTT(shadowsize3, rgba_internal_format, rgb_format, type);
RenderTargetTextures[RTT_TMP_128] = generateRTT(shadowsize3, rgba_internal_format, rgb_format, type); m_render_target_textures[RTT_TMP_128] = generateRTT(shadowsize3, rgba_internal_format, rgb_format, type);
RenderTargetTextures[RTT_LENS_128] = generateRTT(shadowsize3, rgba_internal_format, rgb_format, type); m_render_target_textures[RTT_LENS_128] = generateRTT(shadowsize3, rgba_internal_format, rgb_format, type);
RenderTargetTextures[RTT_SP_GLOSS] = generateRTT(res, GL_RG8, GL_RG, GL_UNSIGNED_BYTE); m_render_target_textures[RTT_SP_GLOSS] = generateRTT(res, GL_RG8, GL_RG, GL_UNSIGNED_BYTE);
RenderTargetTextures[RTT_SP_DIFF_COLOR] = generateRTT(res, GL_RGBA8, rgb_format, GL_UNSIGNED_BYTE); m_render_target_textures[RTT_SP_DIFF_COLOR] = generateRTT(res, GL_RGBA8, rgb_format, GL_UNSIGNED_BYTE);
}
std::vector<GLuint> somevector; std::vector<GLuint> somevector;
somevector.push_back(RenderTargetTextures[RTT_SSAO]); if (!use_default_fbo_only)
FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); {
somevector.push_back(m_render_target_textures[RTT_COLOR]);
m_frame_buffers.push_back(new FrameBuffer(somevector, m_depth_stencil_tex, res.Width, res.Height));
}
if (CVS->isDefferedEnabled())
{
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_NORMAL_AND_DEPTH]); somevector.push_back(m_render_target_textures[RTT_NORMAL_AND_DEPTH]);
FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, m_depth_stencil_tex, res.Width, res.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_DIFFUSE]); somevector.push_back(m_render_target_textures[RTT_SSAO]);
somevector.push_back(RenderTargetTextures[RTT_SPECULAR]); m_frame_buffers.push_back(new FrameBuffer(somevector, res.Width, res.Height));
FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_COLOR]); somevector.push_back(m_render_target_textures[RTT_DIFFUSE]);
FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height)); somevector.push_back(m_render_target_textures[RTT_SPECULAR]);
m_frame_buffers.push_back(new FrameBuffer(somevector, m_depth_stencil_tex, res.Width, res.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_DIFFUSE]); somevector.push_back(m_render_target_textures[RTT_MLAA_COLORS]);
FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, res.Width, res.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_SPECULAR]); somevector.push_back(m_render_target_textures[RTT_MLAA_BLEND]);
FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, res.Width, res.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_MLAA_COLORS]); somevector.push_back(m_render_target_textures[RTT_MLAA_TMP]);
FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, res.Width, res.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_MLAA_BLEND]); somevector.push_back(m_render_target_textures[RTT_TMP1]);
FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, m_depth_stencil_tex, res.Width, res.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_MLAA_TMP]); somevector.push_back(m_render_target_textures[RTT_TMP2]);
FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, m_depth_stencil_tex, res.Width, res.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_TMP1]); somevector.push_back(m_render_target_textures[RTT_TMP4]);
FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, res.Width, res.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_TMP2]); somevector.push_back(m_render_target_textures[RTT_LINEAR_DEPTH]);
FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, res.Width, res.Height));
somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_TMP4]);
FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height));
somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_LINEAR_DEPTH]);
FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_HALF1]); somevector.push_back(m_render_target_textures[RTT_HALF1]);
FrameBuffers.push_back(new FrameBuffer(somevector, half.Width, half.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, half.Width, half.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_HALF1_R]); somevector.push_back(m_render_target_textures[RTT_HALF1_R]);
FrameBuffers.push_back(new FrameBuffer(somevector, half.Width, half.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, half.Width, half.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_HALF2]); somevector.push_back(m_render_target_textures[RTT_HALF2]);
FrameBuffers.push_back(new FrameBuffer(somevector, half.Width, half.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, half.Width, half.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_HALF2_R]); somevector.push_back(m_render_target_textures[RTT_HALF2_R]);
FrameBuffers.push_back(new FrameBuffer(somevector, half.Width, half.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, half.Width, half.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_QUARTER1]); somevector.push_back(m_render_target_textures[RTT_QUARTER1]);
FrameBuffers.push_back(new FrameBuffer(somevector, quarter.Width, quarter.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, quarter.Width, quarter.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_QUARTER2]); somevector.push_back(m_render_target_textures[RTT_QUARTER2]);
FrameBuffers.push_back(new FrameBuffer(somevector, quarter.Width, quarter.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, quarter.Width, quarter.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_EIGHTH1]); somevector.push_back(m_render_target_textures[RTT_EIGHTH1]);
FrameBuffers.push_back(new FrameBuffer(somevector, eighth.Width, eighth.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, eighth.Width, eighth.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_EIGHTH2]); somevector.push_back(m_render_target_textures[RTT_EIGHTH2]);
FrameBuffers.push_back(new FrameBuffer(somevector, eighth.Width, eighth.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, eighth.Width, eighth.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_DISPLACE]); somevector.push_back(m_render_target_textures[RTT_DISPLACE]);
FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, m_depth_stencil_tex, res.Width, res.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_BLOOM_1024]); somevector.push_back(m_render_target_textures[RTT_BLOOM_1024]);
FrameBuffers.push_back(new FrameBuffer(somevector, shadowsize0.Width, shadowsize0.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, shadowsize0.Width, shadowsize0.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_BLOOM_512]); somevector.push_back(m_render_target_textures[RTT_BLOOM_512]);
FrameBuffers.push_back(new FrameBuffer(somevector, shadowsize1.Width, shadowsize1.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, shadowsize1.Width, shadowsize1.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_TMP_512]); somevector.push_back(m_render_target_textures[RTT_TMP_512]);
FrameBuffers.push_back(new FrameBuffer(somevector, shadowsize1.Width, shadowsize1.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, shadowsize1.Width, shadowsize1.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_LENS_512]); somevector.push_back(m_render_target_textures[RTT_LENS_512]);
FrameBuffers.push_back(new FrameBuffer(somevector, shadowsize1.Width, shadowsize1.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, shadowsize1.Width, shadowsize1.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_BLOOM_256]); somevector.push_back(m_render_target_textures[RTT_BLOOM_256]);
FrameBuffers.push_back(new FrameBuffer(somevector, shadowsize2.Width, shadowsize2.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, shadowsize2.Width, shadowsize2.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_TMP_256]); somevector.push_back(m_render_target_textures[RTT_TMP_256]);
FrameBuffers.push_back(new FrameBuffer(somevector, shadowsize2.Width, shadowsize2.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, shadowsize2.Width, shadowsize2.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_LENS_256]); somevector.push_back(m_render_target_textures[RTT_LENS_256]);
FrameBuffers.push_back(new FrameBuffer(somevector, shadowsize2.Width, shadowsize2.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, shadowsize2.Width, shadowsize2.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_BLOOM_128]); somevector.push_back(m_render_target_textures[RTT_BLOOM_128]);
FrameBuffers.push_back(new FrameBuffer(somevector, shadowsize3.Width, shadowsize3.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, shadowsize3.Width, shadowsize3.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_TMP_128]); somevector.push_back(m_render_target_textures[RTT_TMP_128]);
FrameBuffers.push_back(new FrameBuffer(somevector, shadowsize3.Width, shadowsize3.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, shadowsize3.Width, shadowsize3.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_LENS_128]); somevector.push_back(m_render_target_textures[RTT_LENS_128]);
FrameBuffers.push_back(new FrameBuffer(somevector, shadowsize3.Width, shadowsize3.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, shadowsize3.Width, shadowsize3.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_SP_DIFF_COLOR]); somevector.push_back(m_render_target_textures[RTT_SP_DIFF_COLOR]);
somevector.push_back(RenderTargetTextures[RTT_NORMAL_AND_DEPTH]); somevector.push_back(m_render_target_textures[RTT_NORMAL_AND_DEPTH]);
somevector.push_back(RenderTargetTextures[RTT_SP_GLOSS]); somevector.push_back(m_render_target_textures[RTT_SP_GLOSS]);
FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height)); m_frame_buffers.push_back(new FrameBuffer(somevector, m_depth_stencil_tex, res.Width, res.Height));
if (CVS->isShadowEnabled()) if (CVS->isShadowEnabled())
{ {
shadowDepthTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, UserConfigParams::m_shadows_resolution, UserConfigParams::m_shadows_resolution, 4, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 1); m_shadow_depth_tex = generateRTT3D(GL_TEXTURE_2D_ARRAY, UserConfigParams::m_shadows_resolution, UserConfigParams::m_shadows_resolution, 4, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 1);
somevector.clear(); somevector.clear();
m_shadow_FBO = new FrameBufferLayer(somevector, shadowDepthTex, UserConfigParams::m_shadows_resolution, UserConfigParams::m_shadows_resolution, 4); m_shadow_fbo = new FrameBufferLayer(somevector, m_shadow_depth_tex, UserConfigParams::m_shadows_resolution, UserConfigParams::m_shadows_resolution, 4);
} }
// Clear this FBO to 1s so that if no SSAO is computed we can still use it. // Clear this FBO to 1s so that if no SSAO is computed we can still use it.
getFBO(FBO_HALF1_R).bind(); getFBO(FBO_HALF1_R).bind();
glClearColor(1., 1., 1., 1.); glClearColor(1., 1., 1., 1.);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
}
getFBO(FBO_COMBINED_DIFFUSE_SPECULAR).bind();
float color = 0.5;
#if defined(USE_GLES2)
if (!CVS->isDefferedEnabled())
color = pow(color, 1. / 2.2);
#endif
glClearColor(color, color, color, color);
glClear(GL_COLOR_BUFFER_BIT);
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
} }
RTT::~RTT() RTT::~RTT()
{ {
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDeleteTextures(RTT_COUNT, RenderTargetTextures); glDeleteTextures(RTT_COUNT, m_render_target_textures);
glDeleteTextures(1, &DepthStencilTexture); glDeleteTextures(1, &m_depth_stencil_tex);
if (CVS->isShadowEnabled()) if (CVS->isShadowEnabled())
{ {
delete m_shadow_FBO; delete m_shadow_fbo;
glDeleteTextures(1, &shadowDepthTex); glDeleteTextures(1, &m_shadow_depth_tex);
} }
} }

View File

@ -39,12 +39,10 @@ using irr::video::ITexture;
enum TypeFBO enum TypeFBO
{ {
FBO_SSAO,
FBO_NORMAL_AND_DEPTHS,
FBO_COMBINED_DIFFUSE_SPECULAR,
FBO_COLORS, FBO_COLORS,
FBO_DIFFUSE, FBO_NORMAL_AND_DEPTHS,
FBO_SPECULAR, FBO_SSAO,
FBO_COMBINED_DIFFUSE_SPECULAR,
FBO_MLAA_COLORS, FBO_MLAA_COLORS,
FBO_MLAA_BLEND, FBO_MLAA_BLEND,
FBO_MLAA_TMP, FBO_MLAA_TMP,
@ -79,13 +77,13 @@ enum TypeFBO
enum TypeRTT : unsigned int enum TypeRTT : unsigned int
{ {
RTT_TMP1 = 0, RTT_COLOR = 0,
RTT_NORMAL_AND_DEPTH,
RTT_TMP1,
RTT_TMP2, RTT_TMP2,
RTT_TMP3, RTT_TMP3,
RTT_TMP4, RTT_TMP4,
RTT_LINEAR_DEPTH, RTT_LINEAR_DEPTH,
RTT_NORMAL_AND_DEPTH,
RTT_COLOR,
RTT_DIFFUSE, RTT_DIFFUSE,
RTT_SPECULAR, RTT_SPECULAR,
@ -143,27 +141,36 @@ enum TypeRTT : unsigned int
class RTT class RTT
{ {
public: public:
RTT(unsigned int width, unsigned int height, float rtt_scale = 1.0f); RTT(unsigned int width, unsigned int height, float rtt_scale = 1.0f,
bool use_default_fbo_only = false);
~RTT(); ~RTT();
unsigned int getWidth () const { return m_width ; } unsigned int getWidth () const { return m_width ; }
unsigned int getHeight() const { return m_height; } unsigned int getHeight() const { return m_height; }
FrameBufferLayer* getShadowFrameBuffer() { return m_shadow_FBO; } FrameBufferLayer* getShadowFrameBuffer() { return m_shadow_fbo; }
unsigned getDepthStencilTexture() const { return DepthStencilTexture; } unsigned getDepthStencilTexture() const
unsigned getRenderTarget(enum TypeRTT target) const { return RenderTargetTextures[target]; } {
FrameBuffer& getFBO(enum TypeFBO fbo) { return FrameBuffers[fbo]; } assert(m_depth_stencil_tex != 0);
return m_depth_stencil_tex;
}
unsigned getRenderTarget(enum TypeRTT target) const
{
assert(m_render_target_textures[target] != 0);
return m_render_target_textures[target];
}
FrameBuffer& getFBO(enum TypeFBO fbo) { return m_frame_buffers[fbo]; }
private: private:
unsigned RenderTargetTextures[RTT_COUNT]; unsigned m_render_target_textures[RTT_COUNT] = {};
PtrVector<FrameBuffer> FrameBuffers; PtrVector<FrameBuffer> m_frame_buffers;
unsigned DepthStencilTexture; unsigned m_depth_stencil_tex = 0;
unsigned int m_width; unsigned int m_width;
unsigned int m_height; unsigned int m_height;
unsigned shadowDepthTex; unsigned m_shadow_depth_tex = 0;
FrameBufferLayer* m_shadow_FBO; FrameBufferLayer* m_shadow_fbo;
LEAK_CHECK(); LEAK_CHECK();
}; };

View File

@ -50,9 +50,6 @@
#include <algorithm> #include <algorithm>
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void ShaderBasedRenderer::setRTT(RTT* rtts) void ShaderBasedRenderer::setRTT(RTT* rtts)
{ {
m_rtts = rtts; m_rtts = rtts;
@ -111,8 +108,7 @@ void ShaderBasedRenderer::computeMatrixesAndCameras(scene::ICameraSceneNode *con
unsigned int width, unsigned int height) unsigned int width, unsigned int height)
{ {
m_current_screen_size = core::vector2df((float)width, (float)height); m_current_screen_size = core::vector2df((float)width, (float)height);
m_shadow_matrices.computeMatrixesAndCameras(camnode, width, height, m_shadow_matrices.computeMatrixesAndCameras(camnode, width, height);
m_rtts->getDepthStencilTexture());
} // computeMatrixesAndCameras } // computeMatrixesAndCameras
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -440,27 +436,6 @@ void ShaderBasedRenderer::renderScene(scene::ICameraSceneNode * const camnode,
glDisable(GL_BLEND); glDisable(GL_BLEND);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
if (!forceRTT)
{
// We need a cleared depth buffer for some effect (eg particles depth blending)
m_rtts->getFBO(FBO_NORMAL_AND_DEPTHS).bind();
// Bind() modifies the viewport. In order not to affect anything else,
// the viewport is just reset here and not removed in Bind().
const core::recti &vp = Camera::getActiveCamera()->getViewport();
glViewport(vp.UpperLeftCorner.X,
irr_driver->getActualScreenSize().Height - vp.LowerRightCorner.Y,
vp.LowerRightCorner.X - vp.UpperLeftCorner.X,
vp.LowerRightCorner.Y - vp.UpperLeftCorner.Y);
glClear(GL_DEPTH_BUFFER_BIT);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
else
{
m_rtts->getFBO(FBO_NORMAL_AND_DEPTHS).bind();
glClearColor(0., 0., 0., 0.);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
}
if (forceRTT) if (forceRTT)
{ {
m_rtts->getFBO(FBO_COLORS).bind(); m_rtts->getFBO(FBO_COLORS).bind();
@ -471,6 +446,8 @@ void ShaderBasedRenderer::renderScene(scene::ICameraSceneNode * const camnode,
glClearColor(clearColor.getRed() / 255.f, clearColor.getGreen() / 255.f, glClearColor(clearColor.getRed() / 255.f, clearColor.getGreen() / 255.f,
clearColor.getBlue() / 255.f, clearColor.getAlpha() / 255.f); clearColor.getBlue() / 255.f, clearColor.getAlpha() / 255.f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
} }
{ {
@ -651,7 +628,8 @@ void ShaderBasedRenderer::onLoadWorld()
unsigned int width = viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X; unsigned int width = viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X;
unsigned int height = viewport.LowerRightCorner.Y - viewport.UpperLeftCorner.Y; unsigned int height = viewport.LowerRightCorner.Y - viewport.UpperLeftCorner.Y;
RTT* rtts = new RTT(width, height, CVS->isDefferedEnabled() ? RTT* rtts = new RTT(width, height, CVS->isDefferedEnabled() ?
UserConfigParams::m_scale_rtts_factor : 1.0f); UserConfigParams::m_scale_rtts_factor : 1.0f,
!CVS->isDefferedEnabled());
setRTT(rtts); setRTT(rtts);
} }

View File

@ -193,8 +193,7 @@ core::matrix4 ShadowMatrices::getTighestFitOrthoProj(const core::matrix4 &transf
* \param height of the rendering viewport * \param height of the rendering viewport
*/ */
void ShadowMatrices::computeMatrixesAndCameras(scene::ICameraSceneNode *const camnode, void ShadowMatrices::computeMatrixesAndCameras(scene::ICameraSceneNode *const camnode,
unsigned int width, unsigned int height, unsigned int width, unsigned int height)
GLuint depth_stencil_texture)
{ {
camnode->render(); camnode->render();
irr_driver->setProjMatrix(irr_driver->getVideoDriver() irr_driver->setProjMatrix(irr_driver->getVideoDriver()

View File

@ -62,8 +62,7 @@ public:
~ShadowMatrices(); ~ShadowMatrices();
void computeMatrixesAndCameras(scene::ICameraSceneNode *const camnode, void computeMatrixesAndCameras(scene::ICameraSceneNode *const camnode,
unsigned int width, unsigned int height, unsigned int width, unsigned int height);
GLuint depth_stencil_texture);
void addLight(const core::vector3df &pos); void addLight(const core::vector3df &pos);
void updateSunOrthoMatrices(); void updateSunOrthoMatrices();
void renderShadowsDebug(const FrameBuffer* shadow_framebuffer, void renderShadowsDebug(const FrameBuffer* shadow_framebuffer,