Move SSAO code into renderLight in order to use a lighter rtt (8 bits instead of 32)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14755 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
vincentlj 2013-12-23 17:00:27 +00:00
parent 45db87de8a
commit 5db6705889
6 changed files with 56 additions and 110 deletions

View File

@ -1,4 +1,5 @@
uniform sampler2D tex; uniform sampler2D diffuse_and_spec;
uniform sampler2D ambient_occlusion;
uniform vec3 ambient; uniform vec3 ambient;
//uniform sampler2D spectex; //uniform sampler2D spectex;
@ -6,10 +7,10 @@ void main()
{ {
vec2 texc = gl_TexCoord[0].xy; vec2 texc = gl_TexCoord[0].xy;
vec4 col = texture2D(tex, texc); vec4 col = texture2D(diffuse_and_spec, texc);
//vec4 specular = texture2D(spectex, texc); float ao = texture2D(ambient_occlusion, texc).x;
col.xyz += ambient; col.xyz += ao * ambient;
float spec = col.a - 0.05; float spec = col.a - 0.05;
//spec *= specular.a; //spec *= specular.a;
col.xyz += spec * col.xyz; col.xyz += spec * col.xyz;

View File

@ -332,8 +332,10 @@ void LightBlendProvider::OnSetConstants(IMaterialRendererServices *srv, int)
float ambient[3] = { s.r, s.g, s.b }; float ambient[3] = { s.r, s.g, s.b };
srv->setVertexShaderConstant("ambient", ambient, 3); srv->setVertexShaderConstant("ambient", ambient, 3);
//int spectex = 1; int tex = 0;
//srv->setVertexShaderConstant("spectex", &spectex, 1); srv->setVertexShaderConstant("diffuse_and_spec", &tex, 1);
tex = 1;
srv->setVertexShaderConstant("ambient_occlusion", &tex, 1);
} }
//------------------------------------- //-------------------------------------

View File

@ -203,102 +203,7 @@ void PostProcessing::renderSolid(const u32 cam)
{ {
if (!irr_driver->isGLSL()) return; if (!irr_driver->isGLSL()) return;
// Early out: do nothing if at all possible
if (UserConfigParams::m_ssao < 1 && !World::getWorld()->getTrack()->isFogEnabled())
return;
static u8 tick = 0;
IVideoDriver * const drv = irr_driver->getVideoDriver(); IVideoDriver * const drv = irr_driver->getVideoDriver();
drv->setTransform(ETS_WORLD, core::IdentityMatrix);
drv->setTransform(ETS_VIEW, core::IdentityMatrix);
drv->setTransform(ETS_PROJECTION, core::IdentityMatrix);
GaussianBlurProvider * const gacb = (GaussianBlurProvider *) irr_driver->
getCallback(ES_GAUSSIAN3H);
if (UserConfigParams::m_ssao == 1) // SSAO low
{
m_material.MaterialType = irr_driver->getShader(ES_SSAO);
m_material.setTexture(0, irr_driver->getRTT(RTT_NORMAL_AND_DEPTH));
drv->setRenderTarget(irr_driver->getRTT(RTT_SSAO), true, false,
SColor(255, 255, 255, 255));
drawQuad(cam, m_material);
// Blur it to reduce noise.
{
gacb->setResolution(UserConfigParams::m_width / 4,
UserConfigParams::m_height / 4);
m_material.MaterialType = irr_driver->getShader(ES_GAUSSIAN3V);
m_material.setTexture(0, irr_driver->getRTT(RTT_SSAO));
drv->setRenderTarget(irr_driver->getRTT(RTT_QUARTER2), true, false);
drawQuad(cam, m_material);
m_material.MaterialType = irr_driver->getShader(ES_GAUSSIAN3H);
m_material.setTexture(0, irr_driver->getRTT(RTT_QUARTER2));
drv->setRenderTarget(irr_driver->getRTT(RTT_SSAO), false, false);
drawQuad(cam, m_material);
}
// Overlay
m_material.MaterialType = EMT_ONETEXTURE_BLEND;
m_material.setTexture(0, irr_driver->getRTT(RTT_SSAO));
m_material.setTexture(1, 0);
m_material.BlendOperation = EBO_ADD;
m_material.MaterialTypeParam = pack_textureBlendFunc(EBF_DST_COLOR, EBF_ZERO);
drv->setRenderTarget(irr_driver->getRTT(RTT_COLOR), false, false);
drawQuad(cam, m_material);
m_material.BlendOperation = EBO_NONE;
m_material.MaterialTypeParam = 0;
} else if (UserConfigParams::m_ssao == 2) // SSAO high
{
m_material.MaterialType = irr_driver->getShader(ES_SSAO);
m_material.setTexture(0, irr_driver->getRTT(RTT_NORMAL_AND_DEPTH));
drv->setRenderTarget(irr_driver->getRTT(RTT_SSAO), true, false,
SColor(255, 255, 255, 255));
drawQuad(cam, m_material);
// Blur it to reduce noise.
{
gacb->setResolution(UserConfigParams::m_width,
UserConfigParams::m_height);
m_material.MaterialType = irr_driver->getShader(ES_GAUSSIAN6V);
m_material.setTexture(0, irr_driver->getRTT(RTT_SSAO));
drv->setRenderTarget(irr_driver->getRTT(RTT_TMP3), true, false);
drawQuad(cam, m_material);
m_material.MaterialType = irr_driver->getShader(ES_GAUSSIAN6H);
m_material.setTexture(0, irr_driver->getRTT(RTT_TMP3));
drv->setRenderTarget(irr_driver->getRTT(RTT_SSAO), false, false);
drawQuad(cam, m_material);
}
// Overlay
m_material.MaterialType = EMT_ONETEXTURE_BLEND;
m_material.setTexture(0, irr_driver->getRTT(RTT_SSAO));
m_material.setTexture(1, 0);
m_material.BlendOperation = EBO_ADD;
m_material.MaterialTypeParam = pack_textureBlendFunc(EBF_DST_COLOR, EBF_ZERO);
drv->setRenderTarget(irr_driver->getRTT(RTT_COLOR), false, false);
drawQuad(cam, m_material);
m_material.BlendOperation = EBO_NONE;
m_material.MaterialTypeParam = 0;
}
if (World::getWorld()->getTrack()->isFogEnabled()) if (World::getWorld()->getTrack()->isFogEnabled())
{ {
m_material.MaterialType = irr_driver->getShader(ES_FOG); m_material.MaterialType = irr_driver->getShader(ES_FOG);
@ -314,11 +219,6 @@ void PostProcessing::renderSolid(const u32 cam)
m_material.BlendOperation = EBO_NONE; m_material.BlendOperation = EBO_NONE;
m_material.MaterialTypeParam = 0; m_material.MaterialTypeParam = 0;
} }
tick++;
tick %= 2;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -765,6 +765,47 @@ void IrrDriver::renderLights(const core::aabbox3df& cambox,
} // for i in lights } // for i in lights
// Handle SSAO
SMaterial m_material;
GaussianBlurProvider * const gacb = (GaussianBlurProvider *) irr_driver->
getCallback(ES_GAUSSIAN3H);
m_material.ZWriteEnable = false;
m_material.MaterialType = irr_driver->getShader(ES_SSAO);
m_material.setTexture(0, irr_driver->getRTT(RTT_NORMAL_AND_DEPTH));
m_video_driver->setRenderTarget(irr_driver->getRTT(RTT_SSAO), true, false,
SColor(255, 255, 255, 255));
m_post_processing->drawQuad(cam, m_material);
// Blur it to reduce noise.
if(UserConfigParams::m_ssao == 1) {
gacb->setResolution(UserConfigParams::m_width / 4,
UserConfigParams::m_height / 4);
m_material.MaterialType = irr_driver->getShader(ES_GAUSSIAN3V);
m_material.setTexture(0, irr_driver->getRTT(RTT_SSAO));
m_video_driver->setRenderTarget(irr_driver->getRTT(RTT_QUARTER4), true, false);
m_post_processing->drawQuad(cam, m_material);
m_material.MaterialType = irr_driver->getShader(ES_GAUSSIAN3H);
m_material.setTexture(0, irr_driver->getRTT(RTT_QUARTER4));
m_video_driver->setRenderTarget(irr_driver->getRTT(RTT_SSAO), false, false);
m_post_processing->drawQuad(cam, m_material);
} else if (UserConfigParams::m_ssao == 2) {
gacb->setResolution(UserConfigParams::m_width,
UserConfigParams::m_height);
m_material.MaterialType = irr_driver->getShader(ES_GAUSSIAN6V);
m_material.setTexture(0, irr_driver->getRTT(RTT_SSAO));
m_video_driver->setRenderTarget(irr_driver->getRTT(RTT_TMP4), true, false);
m_post_processing->drawQuad(cam, m_material);
m_material.MaterialType = irr_driver->getShader(ES_GAUSSIAN6H);
m_material.setTexture(0, irr_driver->getRTT(RTT_TMP4));
m_video_driver->setRenderTarget(irr_driver->getRTT(RTT_SSAO), false, false);
m_post_processing->drawQuad(cam, m_material);
}
// Blend lights to the image // Blend lights to the image
video::SMaterial lightmat; video::SMaterial lightmat;
lightmat.Lighting = false; lightmat.Lighting = false;
@ -773,8 +814,8 @@ void IrrDriver::renderLights(const core::aabbox3df& cambox,
lightmat.setFlag(video::EMF_BILINEAR_FILTER, false); lightmat.setFlag(video::EMF_BILINEAR_FILTER, false);
lightmat.setTexture(0, m_rtts->getRTT(RTT_TMP1)); lightmat.setTexture(0, m_rtts->getRTT(RTT_TMP1));
// Specular mapping // Apply ambient occlusion
//lightmat.setTexture(1, m_rtts->getRTT(RTT_COLOR)); lightmat.setTexture(1, m_rtts->getRTT(RTT_SSAO));
lightmat.MaterialType = m_shaders->getShader(ES_LIGHTBLEND); lightmat.MaterialType = m_shaders->getShader(ES_LIGHTBLEND);
lightmat.MaterialTypeParam = video::pack_textureBlendFunc(video::EBF_DST_COLOR, video::EBF_ZERO); lightmat.MaterialTypeParam = video::pack_textureBlendFunc(video::EBF_DST_COLOR, video::EBF_ZERO);

View File

@ -65,7 +65,7 @@ RTT::RTT()
} }
rtts[RTT_TMP2] = drv->addRenderTargetTexture(res, "rtt.tmp2", ECF_A8R8G8B8, stencil); rtts[RTT_TMP2] = drv->addRenderTargetTexture(res, "rtt.tmp2", ECF_A8R8G8B8, stencil);
rtts[RTT_TMP3] = drv->addRenderTargetTexture(res, "rtt.tmp3", ECF_A8R8G8B8, stencil); rtts[RTT_TMP3] = drv->addRenderTargetTexture(res, "rtt.tmp3", ECF_A8R8G8B8, stencil);
rtts[RTT_TMP4] = drv->addRenderTargetTexture(res, "rtt.tmp4", ECF_A8R8G8B8, stencil); rtts[RTT_TMP4] = drv->addRenderTargetTexture(res, "rtt.tmp4", ECF_R8, stencil);
rtts[RTT_NORMAL_AND_DEPTH] = drv->addRenderTargetTexture(res, "rtt.normal_and_depth", ECF_A32B32G32R32F, stencil); rtts[RTT_NORMAL_AND_DEPTH] = drv->addRenderTargetTexture(res, "rtt.normal_and_depth", ECF_A32B32G32R32F, stencil);
rtts[RTT_COLOR] = drv->addRenderTargetTexture(res, "rtt.color", ECF_A8R8G8B8, stencil); rtts[RTT_COLOR] = drv->addRenderTargetTexture(res, "rtt.color", ECF_A8R8G8B8, stencil);
@ -75,6 +75,7 @@ RTT::RTT()
rtts[RTT_QUARTER1] = drv->addRenderTargetTexture(quarter, "rtt.q1", ECF_A8R8G8B8, stencil); rtts[RTT_QUARTER1] = drv->addRenderTargetTexture(quarter, "rtt.q1", ECF_A8R8G8B8, stencil);
rtts[RTT_QUARTER2] = drv->addRenderTargetTexture(quarter, "rtt.q2", ECF_A8R8G8B8, stencil); rtts[RTT_QUARTER2] = drv->addRenderTargetTexture(quarter, "rtt.q2", ECF_A8R8G8B8, stencil);
rtts[RTT_QUARTER3] = drv->addRenderTargetTexture(quarter, "rtt.q3", ECF_A8R8G8B8, stencil); rtts[RTT_QUARTER3] = drv->addRenderTargetTexture(quarter, "rtt.q3", ECF_A8R8G8B8, stencil);
rtts[RTT_QUARTER4] = drv->addRenderTargetTexture(quarter, "rtt.q4", ECF_R8, stencil);
rtts[RTT_EIGHTH1] = drv->addRenderTargetTexture(eighth, "rtt.e1", ECF_A8R8G8B8, stencil); rtts[RTT_EIGHTH1] = drv->addRenderTargetTexture(eighth, "rtt.e1", ECF_A8R8G8B8, stencil);
rtts[RTT_EIGHTH2] = drv->addRenderTargetTexture(eighth, "rtt.e2", ECF_A8R8G8B8, stencil); rtts[RTT_EIGHTH2] = drv->addRenderTargetTexture(eighth, "rtt.e2", ECF_A8R8G8B8, stencil);
@ -82,7 +83,7 @@ RTT::RTT()
rtts[RTT_SIXTEENTH1] = drv->addRenderTargetTexture(sixteenth, "rtt.s1", ECF_A8R8G8B8, stencil); rtts[RTT_SIXTEENTH1] = drv->addRenderTargetTexture(sixteenth, "rtt.s1", ECF_A8R8G8B8, stencil);
rtts[RTT_SIXTEENTH2] = drv->addRenderTargetTexture(sixteenth, "rtt.s2", ECF_A8R8G8B8, stencil); rtts[RTT_SIXTEENTH2] = drv->addRenderTargetTexture(sixteenth, "rtt.s2", ECF_A8R8G8B8, stencil);
rtts[RTT_SSAO] = drv->addRenderTargetTexture(ssaosize, "rtt.ssao", ECF_A8R8G8B8, stencil); rtts[RTT_SSAO] = drv->addRenderTargetTexture(ssaosize, "rtt.ssao", ECF_R8, stencil);
rtts[RTT_SHADOW] = drv->addRenderTargetTexture(shadowsize, "rtt.shadow", ECF_A8R8G8B8, stencil); rtts[RTT_SHADOW] = drv->addRenderTargetTexture(shadowsize, "rtt.shadow", ECF_A8R8G8B8, stencil);
rtts[RTT_WARPV] = drv->addRenderTargetTexture(warpvsize, "rtt.warpv", ECF_A8R8G8B8, stencil); rtts[RTT_WARPV] = drv->addRenderTargetTexture(warpvsize, "rtt.warpv", ECF_A8R8G8B8, stencil);

View File

@ -40,6 +40,7 @@ enum TypeRTT
RTT_QUARTER1, RTT_QUARTER1,
RTT_QUARTER2, RTT_QUARTER2,
RTT_QUARTER3, RTT_QUARTER3,
RTT_QUARTER4,
RTT_EIGHTH1, RTT_EIGHTH1,
RTT_EIGHTH2, RTT_EIGHTH2,