diff options
Diffstat (limited to '3rdparty/bgfx/examples/15-shadowmaps-simple/shadowmaps_simple.cpp')
-rw-r--r-- | 3rdparty/bgfx/examples/15-shadowmaps-simple/shadowmaps_simple.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/3rdparty/bgfx/examples/15-shadowmaps-simple/shadowmaps_simple.cpp b/3rdparty/bgfx/examples/15-shadowmaps-simple/shadowmaps_simple.cpp index 07f692cff47..3ef2e057d0e 100644 --- a/3rdparty/bgfx/examples/15-shadowmaps-simple/shadowmaps_simple.cpp +++ b/3rdparty/bgfx/examples/15-shadowmaps-simple/shadowmaps_simple.cpp @@ -91,6 +91,13 @@ int _main_(int _argc, char** _argv) bgfx::UniformHandle u_shadowMap = bgfx::createUniform("u_shadowMap", bgfx::UniformType::Int1); bgfx::UniformHandle u_lightPos = bgfx::createUniform("u_lightPos", bgfx::UniformType::Vec4); bgfx::UniformHandle u_lightMtx = bgfx::createUniform("u_lightMtx", bgfx::UniformType::Mat4); + // When using GL clip space depth range [-1, 1] and packing depth into color buffer, we need to + // adjust the depth range to be [0, 1] for writing to the color buffer + bgfx::UniformHandle u_depthScaleOffset = bgfx::createUniform("u_depthScaleOffset", bgfx::UniformType::Vec4); + const float depthScale = flipV ? 0.5f : 1.0f; + const float depthOffset = flipV ? 0.5f : 0.0f; + float depthScaleOffset[4] = {depthScale, depthOffset, 0.0f, 0.0f}; + bgfx::setUniform(u_depthScaleOffset, depthScaleOffset); // Vertex declarations. bgfx::VertexDecl PosNormalDecl; @@ -148,7 +155,7 @@ int _main_(int _argc, char** _argv) bgfx::TextureHandle fbtextures[] = { shadowMapTexture, - bgfx::createTexture2D(shadowMapSize, shadowMapSize, 1, bgfx::TextureFormat::D16, BGFX_TEXTURE_RT_BUFFER_ONLY), + bgfx::createTexture2D(shadowMapSize, shadowMapSize, 1, bgfx::TextureFormat::D16, BGFX_TEXTURE_RT_WRITE_ONLY), }; shadowMapFB = bgfx::createFrameBuffer(BX_COUNTOF(fbtextures), fbtextures, true); } @@ -274,7 +281,7 @@ int _main_(int _argc, char** _argv) bx::mtxLookAt(lightView, eye, at); const float area = 30.0f; - bx::mtxOrtho(lightProj, -area, area, -area, area, -100.0f, 100.0f); + bx::mtxOrtho(lightProj, -area, area, -area, area, -100.0f, 100.0f, 0.0f, flipV); bgfx::setViewRect(RENDER_SHADOW_PASS_ID, 0, 0, shadowMapSize, shadowMapSize); bgfx::setViewFrameBuffer(RENDER_SHADOW_PASS_ID, shadowMapFB); @@ -303,8 +310,8 @@ int _main_(int _argc, char** _argv) { 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, sy, 0.0f, 0.0f, - 0.0f, 0.0f, 0.5f, 0.0f, - 0.5f, 0.5f, 0.5f, 1.0f, + 0.0f, 0.0f, depthScale, 0.0f, + 0.5f, 0.5f, depthOffset, 1.0f, }; float mtxTmp[16]; |