|
|
@@ -275,6 +275,7 @@ public:
|
|
|
u_mtx = bgfx::createUniform("u_mtx", bgfx::UniformType::Mat4);
|
|
|
u_lightPosRadius = bgfx::createUniform("u_lightPosRadius", bgfx::UniformType::Vec4);
|
|
|
u_lightRgbInnerR = bgfx::createUniform("u_lightRgbInnerR", bgfx::UniformType::Vec4);
|
|
|
+ u_layer = bgfx::createUniform("u_layer", bgfx::UniformType::Vec4);
|
|
|
|
|
|
// Create program from shaders.
|
|
|
m_geomProgram = loadProgram("vs_deferred_geom", "fs_deferred_geom");
|
|
|
@@ -288,11 +289,15 @@ public:
|
|
|
|
|
|
if (0 != (BGFX_CAPS_TEXTURE_2D_ARRAY & bgfx::getCaps()->supported) )
|
|
|
{
|
|
|
- m_lightTaProgram = loadProgram("vs_deferred_light", "fs_deferred_light_ta");
|
|
|
+ m_lightTaProgram = loadProgram("vs_deferred_light", "fs_deferred_light_ta");
|
|
|
+ m_combineTaProgram = loadProgram("vs_deferred_combine", "fs_deferred_combine_ta");
|
|
|
+ m_debugTaProgram = loadProgram("vs_deferred_debug", "fs_deferred_debug_ta");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- m_lightTaProgram = BGFX_INVALID_HANDLE;
|
|
|
+ m_lightTaProgram = BGFX_INVALID_HANDLE;
|
|
|
+ m_combineTaProgram = BGFX_INVALID_HANDLE;
|
|
|
+ m_debugTaProgram = BGFX_INVALID_HANDLE;
|
|
|
}
|
|
|
|
|
|
if (0 != (BGFX_CAPS_IMAGE_RW & bgfx::getCaps()->supported)
|
|
|
@@ -388,7 +393,19 @@ public:
|
|
|
}
|
|
|
|
|
|
bgfx::destroy(m_combineProgram);
|
|
|
+
|
|
|
+ if (bgfx::isValid(m_combineTaProgram) )
|
|
|
+ {
|
|
|
+ bgfx::destroy(m_combineTaProgram);
|
|
|
+ }
|
|
|
+
|
|
|
bgfx::destroy(m_debugProgram);
|
|
|
+
|
|
|
+ if (bgfx::isValid(m_debugTaProgram) )
|
|
|
+ {
|
|
|
+ bgfx::destroy(m_debugTaProgram);
|
|
|
+ }
|
|
|
+
|
|
|
bgfx::destroy(m_lineProgram);
|
|
|
|
|
|
bgfx::destroy(m_textureColor);
|
|
|
@@ -819,21 +836,30 @@ public:
|
|
|
}
|
|
|
|
|
|
// Combine color and light buffers.
|
|
|
- bgfx::setTexture(0, s_albedo, m_gbufferTex[0]);
|
|
|
+ bgfx::setTexture(0, s_albedo, bgfx::getTexture(m_gbuffer, 0) );
|
|
|
bgfx::setTexture(1, s_light, m_lightBufferTex);
|
|
|
bgfx::setState(0
|
|
|
| BGFX_STATE_WRITE_RGB
|
|
|
| BGFX_STATE_WRITE_A
|
|
|
);
|
|
|
screenSpaceQuad( (float)m_width, (float)m_height, s_texelHalf, m_caps->originBottomLeft);
|
|
|
- bgfx::submit(kRenderPassCombine, m_combineProgram);
|
|
|
+
|
|
|
+ if (bgfx::isValid(m_lightTaProgram)
|
|
|
+ && m_useTArray)
|
|
|
+ {
|
|
|
+ bgfx::submit(kRenderPassCombine, m_combineTaProgram);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bgfx::submit(kRenderPassCombine, m_combineProgram);
|
|
|
+ }
|
|
|
|
|
|
if (m_showGBuffer)
|
|
|
{
|
|
|
const float aspectRatio = float(m_width)/float(m_height);
|
|
|
|
|
|
// Draw m_debug m_gbuffer.
|
|
|
- for (uint32_t ii = 0; ii < BX_COUNTOF(m_gbufferTex); ++ii)
|
|
|
+ for (uint8_t ii = 0; ii < BX_COUNTOF(m_gbufferTex); ++ii)
|
|
|
{
|
|
|
float mtx[16];
|
|
|
bx::mtxSRT(mtx
|
|
|
@@ -845,9 +871,21 @@ public:
|
|
|
bgfx::setTransform(mtx);
|
|
|
bgfx::setVertexBuffer(0, m_vbh);
|
|
|
bgfx::setIndexBuffer(m_ibh, 0, 6);
|
|
|
- bgfx::setTexture(0, s_texColor, m_gbufferTex[ii]);
|
|
|
+ bgfx::setTexture(0, s_texColor, bgfx::getTexture(m_gbuffer, ii) );
|
|
|
bgfx::setState(BGFX_STATE_WRITE_RGB);
|
|
|
- bgfx::submit(kRenderPassDebugGBuffer, m_debugProgram);
|
|
|
+
|
|
|
+ if (ii != BX_COUNTOF(m_gbufferTex) - 1
|
|
|
+ && bgfx::isValid(m_lightTaProgram)
|
|
|
+ && m_useTArray)
|
|
|
+ {
|
|
|
+ const float layer[4] = { float(ii) };
|
|
|
+ bgfx::setUniform(u_layer, layer);
|
|
|
+ bgfx::submit(kRenderPassDebugGBuffer, m_debugTaProgram);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bgfx::submit(kRenderPassDebugGBuffer, m_debugProgram);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -877,6 +915,7 @@ public:
|
|
|
bgfx::UniformHandle u_mtx;
|
|
|
bgfx::UniformHandle u_lightPosRadius;
|
|
|
bgfx::UniformHandle u_lightRgbInnerR;
|
|
|
+ bgfx::UniformHandle u_layer;
|
|
|
|
|
|
bgfx::ProgramHandle m_geomProgram;
|
|
|
bgfx::ProgramHandle m_lightProgram;
|
|
|
@@ -884,7 +923,9 @@ public:
|
|
|
bgfx::ProgramHandle m_lightUavProgram;
|
|
|
bgfx::ProgramHandle m_clearUavProgram;
|
|
|
bgfx::ProgramHandle m_combineProgram;
|
|
|
+ bgfx::ProgramHandle m_combineTaProgram;
|
|
|
bgfx::ProgramHandle m_debugProgram;
|
|
|
+ bgfx::ProgramHandle m_debugTaProgram;
|
|
|
bgfx::ProgramHandle m_lineProgram;
|
|
|
bgfx::TextureHandle m_textureColor;
|
|
|
bgfx::TextureHandle m_textureNormal;
|