|
@@ -281,6 +281,17 @@ public:
|
|
|
m_debugProgram = loadProgram("vs_deferred_debug", "fs_deferred_debug");
|
|
m_debugProgram = loadProgram("vs_deferred_debug", "fs_deferred_debug");
|
|
|
m_lineProgram = loadProgram("vs_deferred_debug_line", "fs_deferred_debug_line");
|
|
m_lineProgram = loadProgram("vs_deferred_debug_line", "fs_deferred_debug_line");
|
|
|
|
|
|
|
|
|
|
+ m_useTArray = false;
|
|
|
|
|
+
|
|
|
|
|
+ if (0 != (BGFX_CAPS_TEXTURE_2D_ARRAY & bgfx::getCaps()->supported) )
|
|
|
|
|
+ {
|
|
|
|
|
+ m_lightTaProgram = loadProgram("vs_deferred_light", "fs_deferred_light_ta");
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ m_lightTaProgram = BGFX_INVALID_HANDLE;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// Load diffuse texture.
|
|
// Load diffuse texture.
|
|
|
m_textureColor = loadTexture("textures/fieldstone-rgba.dds");
|
|
m_textureColor = loadTexture("textures/fieldstone-rgba.dds");
|
|
|
|
|
|
|
@@ -290,8 +301,8 @@ public:
|
|
|
m_gbufferTex[0].idx = bgfx::kInvalidHandle;
|
|
m_gbufferTex[0].idx = bgfx::kInvalidHandle;
|
|
|
m_gbufferTex[1].idx = bgfx::kInvalidHandle;
|
|
m_gbufferTex[1].idx = bgfx::kInvalidHandle;
|
|
|
m_gbufferTex[2].idx = bgfx::kInvalidHandle;
|
|
m_gbufferTex[2].idx = bgfx::kInvalidHandle;
|
|
|
- m_gbuffer.idx = bgfx::kInvalidHandle;
|
|
|
|
|
- m_lightBuffer.idx = bgfx::kInvalidHandle;
|
|
|
|
|
|
|
+ m_gbuffer.idx = bgfx::kInvalidHandle;
|
|
|
|
|
+ m_lightBuffer.idx = bgfx::kInvalidHandle;
|
|
|
|
|
|
|
|
// Imgui.
|
|
// Imgui.
|
|
|
imguiCreate();
|
|
imguiCreate();
|
|
@@ -337,6 +348,12 @@ public:
|
|
|
|
|
|
|
|
bgfx::destroy(m_geomProgram);
|
|
bgfx::destroy(m_geomProgram);
|
|
|
bgfx::destroy(m_lightProgram);
|
|
bgfx::destroy(m_lightProgram);
|
|
|
|
|
+
|
|
|
|
|
+ if (bgfx::isValid(m_lightTaProgram) )
|
|
|
|
|
+ {
|
|
|
|
|
+ bgfx::destroy(m_lightTaProgram);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
bgfx::destroy(m_combineProgram);
|
|
bgfx::destroy(m_combineProgram);
|
|
|
bgfx::destroy(m_debugProgram);
|
|
bgfx::destroy(m_debugProgram);
|
|
|
bgfx::destroy(m_lineProgram);
|
|
bgfx::destroy(m_lineProgram);
|
|
@@ -402,19 +419,24 @@ public:
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- if (m_oldWidth != m_width
|
|
|
|
|
- || m_oldHeight != m_height
|
|
|
|
|
- || m_oldReset != m_reset
|
|
|
|
|
|
|
+ if (m_oldWidth != m_width
|
|
|
|
|
+ || m_oldHeight != m_height
|
|
|
|
|
+ || m_oldReset != m_reset
|
|
|
|
|
+ || m_oldUseTArray != m_useTArray
|
|
|
|| !bgfx::isValid(m_gbuffer) )
|
|
|| !bgfx::isValid(m_gbuffer) )
|
|
|
{
|
|
{
|
|
|
// Recreate variable size render targets when resolution changes.
|
|
// Recreate variable size render targets when resolution changes.
|
|
|
- m_oldWidth = m_width;
|
|
|
|
|
- m_oldHeight = m_height;
|
|
|
|
|
- m_oldReset = m_reset;
|
|
|
|
|
|
|
+ m_oldWidth = m_width;
|
|
|
|
|
+ m_oldHeight = m_height;
|
|
|
|
|
+ m_oldReset = m_reset;
|
|
|
|
|
+ m_oldUseTArray = m_useTArray;
|
|
|
|
|
|
|
|
if (bgfx::isValid(m_gbuffer) )
|
|
if (bgfx::isValid(m_gbuffer) )
|
|
|
{
|
|
{
|
|
|
bgfx::destroy(m_gbuffer);
|
|
bgfx::destroy(m_gbuffer);
|
|
|
|
|
+ m_gbufferTex[0].idx = bgfx::kInvalidHandle;
|
|
|
|
|
+ m_gbufferTex[1].idx = bgfx::kInvalidHandle;
|
|
|
|
|
+ m_gbufferTex[2].idx = bgfx::kInvalidHandle;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const uint64_t tsFlags = 0
|
|
const uint64_t tsFlags = 0
|
|
@@ -425,10 +447,27 @@ public:
|
|
|
| BGFX_SAMPLER_U_CLAMP
|
|
| BGFX_SAMPLER_U_CLAMP
|
|
|
| BGFX_SAMPLER_V_CLAMP
|
|
| BGFX_SAMPLER_V_CLAMP
|
|
|
;
|
|
;
|
|
|
- m_gbufferTex[0] = bgfx::createTexture2D(uint16_t(m_width), uint16_t(m_height), false, 1, bgfx::TextureFormat::BGRA8, tsFlags);
|
|
|
|
|
- m_gbufferTex[1] = bgfx::createTexture2D(uint16_t(m_width), uint16_t(m_height), false, 1, bgfx::TextureFormat::BGRA8, tsFlags);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ bgfx::Attachment at[3];
|
|
|
|
|
+
|
|
|
|
|
+ if (m_useTArray)
|
|
|
|
|
+ {
|
|
|
|
|
+ m_gbufferTex[0] = bgfx::createTexture2D(uint16_t(m_width), uint16_t(m_height), false, 2, bgfx::TextureFormat::BGRA8, tsFlags);
|
|
|
|
|
+ at[0].init(m_gbufferTex[0], bgfx::Access::Write, 0);
|
|
|
|
|
+ at[1].init(m_gbufferTex[0], bgfx::Access::Write, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ m_gbufferTex[0] = bgfx::createTexture2D(uint16_t(m_width), uint16_t(m_height), false, 1, bgfx::TextureFormat::BGRA8, tsFlags);
|
|
|
|
|
+ m_gbufferTex[1] = bgfx::createTexture2D(uint16_t(m_width), uint16_t(m_height), false, 1, bgfx::TextureFormat::BGRA8, tsFlags);
|
|
|
|
|
+ at[0].init(m_gbufferTex[0]);
|
|
|
|
|
+ at[1].init(m_gbufferTex[1]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
m_gbufferTex[2] = bgfx::createTexture2D(uint16_t(m_width), uint16_t(m_height), false, 1, bgfx::TextureFormat::D24S8, tsFlags);
|
|
m_gbufferTex[2] = bgfx::createTexture2D(uint16_t(m_width), uint16_t(m_height), false, 1, bgfx::TextureFormat::D24S8, tsFlags);
|
|
|
- m_gbuffer = bgfx::createFrameBuffer(BX_COUNTOF(m_gbufferTex), m_gbufferTex, true);
|
|
|
|
|
|
|
+ at[2].init(m_gbufferTex[2]);
|
|
|
|
|
+
|
|
|
|
|
+ m_gbuffer = bgfx::createFrameBuffer(BX_COUNTOF(at), at, true);
|
|
|
|
|
|
|
|
if (bgfx::isValid(m_lightBuffer) )
|
|
if (bgfx::isValid(m_lightBuffer) )
|
|
|
{
|
|
{
|
|
@@ -454,6 +493,16 @@ public:
|
|
|
ImGui::SliderInt("Num lights", &m_numLights, 1, 2048);
|
|
ImGui::SliderInt("Num lights", &m_numLights, 1, 2048);
|
|
|
ImGui::Checkbox("Show G-Buffer.", &m_showGBuffer);
|
|
ImGui::Checkbox("Show G-Buffer.", &m_showGBuffer);
|
|
|
ImGui::Checkbox("Show light scissor.", &m_showScissorRects);
|
|
ImGui::Checkbox("Show light scissor.", &m_showScissorRects);
|
|
|
|
|
+
|
|
|
|
|
+ if (bgfx::isValid(m_lightTaProgram) )
|
|
|
|
|
+ {
|
|
|
|
|
+ ImGui::Checkbox("Use texture array frame buffer.", &m_useTArray);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ ImGui::Text("Texture array frame buffer is not supported.");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
ImGui::Checkbox("Animate mesh.", &m_animateMesh);
|
|
ImGui::Checkbox("Animate mesh.", &m_animateMesh);
|
|
|
ImGui::SliderFloat("Anim.speed", &m_lightAnimationSpeed, 0.0f, 0.4f);
|
|
ImGui::SliderFloat("Anim.speed", &m_lightAnimationSpeed, 0.0f, 0.4f);
|
|
|
|
|
|
|
@@ -668,7 +717,7 @@ public:
|
|
|
| BGFX_STATE_BLEND_ADD
|
|
| BGFX_STATE_BLEND_ADD
|
|
|
);
|
|
);
|
|
|
screenSpaceQuad( (float)m_width, (float)m_height, s_texelHalf, m_caps->originBottomLeft);
|
|
screenSpaceQuad( (float)m_width, (float)m_height, s_texelHalf, m_caps->originBottomLeft);
|
|
|
- bgfx::submit(RENDER_PASS_LIGHT_ID, m_lightProgram);
|
|
|
|
|
|
|
+ bgfx::submit(RENDER_PASS_LIGHT_ID, bgfx::isValid(m_lightTaProgram) && m_useTArray ? m_lightTaProgram : m_lightProgram);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -691,10 +740,10 @@ public:
|
|
|
{
|
|
{
|
|
|
float mtx[16];
|
|
float mtx[16];
|
|
|
bx::mtxSRT(mtx
|
|
bx::mtxSRT(mtx
|
|
|
- , aspectRatio, 1.0f, 1.0f
|
|
|
|
|
- , 0.0f, 0.0f, 0.0f
|
|
|
|
|
- , -7.9f - BX_COUNTOF(m_gbufferTex)*0.1f*0.5f + ii*2.1f*aspectRatio, 4.0f, 0.0f
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ , aspectRatio, 1.0f, 1.0f
|
|
|
|
|
+ , 0.0f, 0.0f, 0.0f
|
|
|
|
|
+ , -7.9f - BX_COUNTOF(m_gbufferTex)*0.1f*0.5f + ii*2.1f*aspectRatio, 4.0f, 0.0f
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
bgfx::setTransform(mtx);
|
|
bgfx::setTransform(mtx);
|
|
|
bgfx::setVertexBuffer(0, m_vbh);
|
|
bgfx::setVertexBuffer(0, m_vbh);
|
|
@@ -734,6 +783,7 @@ public:
|
|
|
|
|
|
|
|
bgfx::ProgramHandle m_geomProgram;
|
|
bgfx::ProgramHandle m_geomProgram;
|
|
|
bgfx::ProgramHandle m_lightProgram;
|
|
bgfx::ProgramHandle m_lightProgram;
|
|
|
|
|
+ bgfx::ProgramHandle m_lightTaProgram;
|
|
|
bgfx::ProgramHandle m_combineProgram;
|
|
bgfx::ProgramHandle m_combineProgram;
|
|
|
bgfx::ProgramHandle m_debugProgram;
|
|
bgfx::ProgramHandle m_debugProgram;
|
|
|
bgfx::ProgramHandle m_lineProgram;
|
|
bgfx::ProgramHandle m_lineProgram;
|
|
@@ -753,6 +803,9 @@ public:
|
|
|
uint32_t m_oldHeight;
|
|
uint32_t m_oldHeight;
|
|
|
uint32_t m_oldReset;
|
|
uint32_t m_oldReset;
|
|
|
|
|
|
|
|
|
|
+ bool m_useTArray;
|
|
|
|
|
+ bool m_oldUseTArray;
|
|
|
|
|
+
|
|
|
int32_t m_scrollArea;
|
|
int32_t m_scrollArea;
|
|
|
int32_t m_numLights;
|
|
int32_t m_numLights;
|
|
|
float m_lightAnimationSpeed;
|
|
float m_lightAnimationSpeed;
|