Cleanup.
This commit is contained in:
parent
a7d937f990
commit
3fcaac24fb
@ -47,29 +47,29 @@ class ExampleShadowmapsSimple : public entry::AppI
|
|||||||
{
|
{
|
||||||
|
|
||||||
Args args(_argc, _argv);
|
Args args(_argc, _argv);
|
||||||
|
|
||||||
m_width = 1280;
|
m_width = 1280;
|
||||||
m_height = 720;
|
m_height = 720;
|
||||||
m_debug = BGFX_DEBUG_TEXT;
|
m_debug = BGFX_DEBUG_TEXT;
|
||||||
m_reset = BGFX_RESET_VSYNC;
|
m_reset = BGFX_RESET_VSYNC;
|
||||||
|
|
||||||
bgfx::init(args.m_type, args.m_pciId);
|
bgfx::init(args.m_type, args.m_pciId);
|
||||||
bgfx::reset(m_width, m_height, m_reset);
|
bgfx::reset(m_width, m_height, m_reset);
|
||||||
|
|
||||||
bgfx::RendererType::Enum renderer = bgfx::getRendererType();
|
bgfx::RendererType::Enum renderer = bgfx::getRendererType();
|
||||||
m_flipV = false
|
m_flipV = false
|
||||||
|| renderer == bgfx::RendererType::OpenGL
|
|| renderer == bgfx::RendererType::OpenGL
|
||||||
|| renderer == bgfx::RendererType::OpenGLES
|
|| renderer == bgfx::RendererType::OpenGLES
|
||||||
;
|
;
|
||||||
|
|
||||||
// Enable debug text.
|
// Enable debug text.
|
||||||
bgfx::setDebug(m_debug);
|
bgfx::setDebug(m_debug);
|
||||||
|
|
||||||
// Uniforms.
|
// Uniforms.
|
||||||
u_shadowMap = bgfx::createUniform("u_shadowMap", bgfx::UniformType::Int1);
|
u_shadowMap = bgfx::createUniform("u_shadowMap", bgfx::UniformType::Int1);
|
||||||
u_lightPos = bgfx::createUniform("u_lightPos", bgfx::UniformType::Vec4);
|
u_lightPos = bgfx::createUniform("u_lightPos", bgfx::UniformType::Vec4);
|
||||||
u_lightMtx = bgfx::createUniform("u_lightMtx", bgfx::UniformType::Mat4);
|
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
|
// 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
|
// adjust the depth range to be [0, 1] for writing to the color buffer
|
||||||
u_depthScaleOffset = bgfx::createUniform("u_depthScaleOffset", bgfx::UniformType::Vec4);
|
u_depthScaleOffset = bgfx::createUniform("u_depthScaleOffset", bgfx::UniformType::Vec4);
|
||||||
@ -77,45 +77,45 @@ class ExampleShadowmapsSimple : public entry::AppI
|
|||||||
m_depthOffset = m_flipV ? 0.5f : 0.0f;
|
m_depthOffset = m_flipV ? 0.5f : 0.0f;
|
||||||
float depthScaleOffset[4] = {m_depthScale, m_depthOffset, 0.0f, 0.0f};
|
float depthScaleOffset[4] = {m_depthScale, m_depthOffset, 0.0f, 0.0f};
|
||||||
bgfx::setUniform(u_depthScaleOffset, depthScaleOffset);
|
bgfx::setUniform(u_depthScaleOffset, depthScaleOffset);
|
||||||
|
|
||||||
// Vertex declarations.
|
// Vertex declarations.
|
||||||
bgfx::VertexDecl PosNormalDecl;
|
bgfx::VertexDecl PosNormalDecl;
|
||||||
PosNormalDecl.begin()
|
PosNormalDecl.begin()
|
||||||
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
|
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
|
||||||
.add(bgfx::Attrib::Normal, 4, bgfx::AttribType::Uint8, true, true)
|
.add(bgfx::Attrib::Normal, 4, bgfx::AttribType::Uint8, true, true)
|
||||||
.end();
|
.end();
|
||||||
|
|
||||||
// Meshes.
|
// Meshes.
|
||||||
m_bunny = meshLoad("meshes/bunny.bin");
|
m_bunny = meshLoad("meshes/bunny.bin");
|
||||||
m_cube = meshLoad("meshes/cube.bin");
|
m_cube = meshLoad("meshes/cube.bin");
|
||||||
m_hollowcube = meshLoad("meshes/hollowcube.bin");
|
m_hollowcube = meshLoad("meshes/hollowcube.bin");
|
||||||
|
|
||||||
m_vbh = bgfx::createVertexBuffer(
|
m_vbh = bgfx::createVertexBuffer(
|
||||||
bgfx::makeRef(s_hplaneVertices, sizeof(s_hplaneVertices) )
|
bgfx::makeRef(s_hplaneVertices, sizeof(s_hplaneVertices) )
|
||||||
, PosNormalDecl
|
, PosNormalDecl
|
||||||
);
|
);
|
||||||
|
|
||||||
m_ibh = bgfx::createIndexBuffer(
|
m_ibh = bgfx::createIndexBuffer(
|
||||||
bgfx::makeRef(s_planeIndices, sizeof(s_planeIndices) )
|
bgfx::makeRef(s_planeIndices, sizeof(s_planeIndices) )
|
||||||
);
|
);
|
||||||
|
|
||||||
// Render targets.
|
// Render targets.
|
||||||
m_shadowMapSize = 512;
|
m_shadowMapSize = 512;
|
||||||
|
|
||||||
// Get renderer capabilities info.
|
// Get renderer capabilities info.
|
||||||
const bgfx::Caps* caps = bgfx::getCaps();
|
const bgfx::Caps* caps = bgfx::getCaps();
|
||||||
// Shadow samplers are supported at least partially supported if texture
|
// Shadow samplers are supported at least partially supported if texture
|
||||||
// compare less equal feature is supported.
|
// compare less equal feature is supported.
|
||||||
m_shadowSamplerSupported = 0 != (caps->supported & BGFX_CAPS_TEXTURE_COMPARE_LEQUAL);
|
m_shadowSamplerSupported = 0 != (caps->supported & BGFX_CAPS_TEXTURE_COMPARE_LEQUAL);
|
||||||
|
|
||||||
bgfx::TextureHandle shadowMapTexture;
|
bgfx::TextureHandle shadowMapTexture;
|
||||||
|
|
||||||
if (m_shadowSamplerSupported)
|
if (m_shadowSamplerSupported)
|
||||||
{
|
{
|
||||||
// Depth textures and shadow samplers are supported.
|
// Depth textures and shadow samplers are supported.
|
||||||
m_progShadow = loadProgram("vs_sms_shadow", "fs_sms_shadow");
|
m_progShadow = loadProgram("vs_sms_shadow", "fs_sms_shadow");
|
||||||
m_progMesh = loadProgram("vs_sms_mesh", "fs_sms_mesh");
|
m_progMesh = loadProgram("vs_sms_mesh", "fs_sms_mesh");
|
||||||
|
|
||||||
shadowMapTexture = bgfx::createTexture2D(m_shadowMapSize, m_shadowMapSize, false, 1, bgfx::TextureFormat::D16, BGFX_TEXTURE_RT | BGFX_TEXTURE_COMPARE_LEQUAL);
|
shadowMapTexture = bgfx::createTexture2D(m_shadowMapSize, m_shadowMapSize, false, 1, bgfx::TextureFormat::D16, BGFX_TEXTURE_RT | BGFX_TEXTURE_COMPARE_LEQUAL);
|
||||||
bgfx::TextureHandle fbtextures[] = { shadowMapTexture };
|
bgfx::TextureHandle fbtextures[] = { shadowMapTexture };
|
||||||
m_shadowMapFB = bgfx::createFrameBuffer(BX_COUNTOF(fbtextures), fbtextures, true);
|
m_shadowMapFB = bgfx::createFrameBuffer(BX_COUNTOF(fbtextures), fbtextures, true);
|
||||||
@ -126,7 +126,7 @@ class ExampleShadowmapsSimple : public entry::AppI
|
|||||||
// depth packing into color buffer instead.
|
// depth packing into color buffer instead.
|
||||||
m_progShadow = loadProgram("vs_sms_shadow_pd", "fs_sms_shadow_pd");
|
m_progShadow = loadProgram("vs_sms_shadow_pd", "fs_sms_shadow_pd");
|
||||||
m_progMesh = loadProgram("vs_sms_mesh", "fs_sms_mesh_pd");
|
m_progMesh = loadProgram("vs_sms_mesh", "fs_sms_mesh_pd");
|
||||||
|
|
||||||
shadowMapTexture = bgfx::createTexture2D(m_shadowMapSize, m_shadowMapSize, false, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_RT);
|
shadowMapTexture = bgfx::createTexture2D(m_shadowMapSize, m_shadowMapSize, false, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_RT);
|
||||||
bgfx::TextureHandle fbtextures[] =
|
bgfx::TextureHandle fbtextures[] =
|
||||||
{
|
{
|
||||||
@ -135,7 +135,7 @@ class ExampleShadowmapsSimple : public entry::AppI
|
|||||||
};
|
};
|
||||||
m_shadowMapFB = bgfx::createFrameBuffer(BX_COUNTOF(fbtextures), fbtextures, true);
|
m_shadowMapFB = bgfx::createFrameBuffer(BX_COUNTOF(fbtextures), fbtextures, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_state[0] = meshStateCreate();
|
m_state[0] = meshStateCreate();
|
||||||
m_state[0]->m_state = 0
|
m_state[0]->m_state = 0
|
||||||
| BGFX_STATE_RGB_WRITE
|
| BGFX_STATE_RGB_WRITE
|
||||||
@ -148,7 +148,7 @@ class ExampleShadowmapsSimple : public entry::AppI
|
|||||||
m_state[0]->m_program = m_progShadow;
|
m_state[0]->m_program = m_progShadow;
|
||||||
m_state[0]->m_viewId = RENDER_SHADOW_PASS_ID;
|
m_state[0]->m_viewId = RENDER_SHADOW_PASS_ID;
|
||||||
m_state[0]->m_numTextures = 0;
|
m_state[0]->m_numTextures = 0;
|
||||||
|
|
||||||
m_state[1] = meshStateCreate();
|
m_state[1] = meshStateCreate();
|
||||||
m_state[1]->m_state = 0
|
m_state[1]->m_state = 0
|
||||||
| BGFX_STATE_RGB_WRITE
|
| BGFX_STATE_RGB_WRITE
|
||||||
@ -165,46 +165,46 @@ class ExampleShadowmapsSimple : public entry::AppI
|
|||||||
m_state[1]->m_textures[0].m_stage = 0;
|
m_state[1]->m_textures[0].m_stage = 0;
|
||||||
m_state[1]->m_textures[0].m_sampler = u_shadowMap;
|
m_state[1]->m_textures[0].m_sampler = u_shadowMap;
|
||||||
m_state[1]->m_textures[0].m_texture = shadowMapTexture;
|
m_state[1]->m_textures[0].m_texture = shadowMapTexture;
|
||||||
|
|
||||||
// Set view and projection matrices.
|
// Set view and projection matrices.
|
||||||
|
|
||||||
float eye[3] = { 0.0f, 30.0f, -60.0f };
|
float eye[3] = { 0.0f, 30.0f, -60.0f };
|
||||||
float at[3] = { 0.0f, 5.0f, 0.0f };
|
float at[3] = { 0.0f, 5.0f, 0.0f };
|
||||||
bx::mtxLookAt(m_view, eye, at);
|
bx::mtxLookAt(m_view, eye, at);
|
||||||
|
|
||||||
const float aspect = float(int32_t(m_width) ) / float(int32_t(m_height) );
|
const float aspect = float(int32_t(m_width) ) / float(int32_t(m_height) );
|
||||||
bx::mtxProj(m_proj, 60.0f, aspect, 0.1f, 1000.0f, bgfx::getCaps()->homogeneousDepth);
|
bx::mtxProj(m_proj, 60.0f, aspect, 0.1f, 1000.0f, bgfx::getCaps()->homogeneousDepth);
|
||||||
|
|
||||||
// Time acumulators.
|
// Time acumulators.
|
||||||
m_timeAccumulatorLight = 0.0f;
|
m_timeAccumulatorLight = 0.0f;
|
||||||
m_timeAccumulatorScene = 0.0f;
|
m_timeAccumulatorScene = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int shutdown() BX_OVERRIDE
|
virtual int shutdown() BX_OVERRIDE
|
||||||
{
|
{
|
||||||
meshUnload(m_bunny);
|
meshUnload(m_bunny);
|
||||||
meshUnload(m_cube);
|
meshUnload(m_cube);
|
||||||
meshUnload(m_hollowcube);
|
meshUnload(m_hollowcube);
|
||||||
|
|
||||||
meshStateDestroy(m_state[0]);
|
meshStateDestroy(m_state[0]);
|
||||||
meshStateDestroy(m_state[1]);
|
meshStateDestroy(m_state[1]);
|
||||||
|
|
||||||
bgfx::destroyVertexBuffer(m_vbh);
|
bgfx::destroyVertexBuffer(m_vbh);
|
||||||
bgfx::destroyIndexBuffer(m_ibh);
|
bgfx::destroyIndexBuffer(m_ibh);
|
||||||
|
|
||||||
bgfx::destroyProgram(m_progShadow);
|
bgfx::destroyProgram(m_progShadow);
|
||||||
bgfx::destroyProgram(m_progMesh);
|
bgfx::destroyProgram(m_progMesh);
|
||||||
|
|
||||||
bgfx::destroyFrameBuffer(m_shadowMapFB);
|
bgfx::destroyFrameBuffer(m_shadowMapFB);
|
||||||
|
|
||||||
bgfx::destroyUniform(u_shadowMap);
|
bgfx::destroyUniform(u_shadowMap);
|
||||||
bgfx::destroyUniform(u_lightPos);
|
bgfx::destroyUniform(u_lightPos);
|
||||||
bgfx::destroyUniform(u_lightMtx);
|
bgfx::destroyUniform(u_lightMtx);
|
||||||
bgfx::destroyUniform(u_depthScaleOffset);
|
bgfx::destroyUniform(u_depthScaleOffset);
|
||||||
|
|
||||||
// Shutdown bgfx.
|
// Shutdown bgfx.
|
||||||
bgfx::shutdown();
|
bgfx::shutdown();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,26 +220,26 @@ class ExampleShadowmapsSimple : public entry::AppI
|
|||||||
const double freq = double(bx::getHPFrequency() );
|
const double freq = double(bx::getHPFrequency() );
|
||||||
const double toMs = 1000.0/freq;
|
const double toMs = 1000.0/freq;
|
||||||
const float deltaTime = float(frameTime/freq);
|
const float deltaTime = float(frameTime/freq);
|
||||||
|
|
||||||
// Update time accumulators.
|
// Update time accumulators.
|
||||||
m_timeAccumulatorLight += deltaTime;
|
m_timeAccumulatorLight += deltaTime;
|
||||||
m_timeAccumulatorScene += deltaTime;
|
m_timeAccumulatorScene += deltaTime;
|
||||||
|
|
||||||
// Use debug font to print information about this example.
|
// Use debug font to print information about this example.
|
||||||
bgfx::dbgTextClear();
|
bgfx::dbgTextClear();
|
||||||
bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/15-shadowmaps-simple");
|
bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/15-shadowmaps-simple");
|
||||||
bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Shadow maps example (technique: %s).", m_shadowSamplerSupported ? "depth texture and shadow samplers" : "shadow depth packed into color texture");
|
bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Shadow maps example (technique: %s).", m_shadowSamplerSupported ? "depth texture and shadow samplers" : "shadow depth packed into color texture");
|
||||||
bgfx::dbgTextPrintf(0, 3, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs);
|
bgfx::dbgTextPrintf(0, 3, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs);
|
||||||
|
|
||||||
// Setup lights.
|
// Setup lights.
|
||||||
float lightPos[4];
|
float lightPos[4];
|
||||||
lightPos[0] = -bx::fcos(m_timeAccumulatorLight);
|
lightPos[0] = -bx::fcos(m_timeAccumulatorLight);
|
||||||
lightPos[1] = -1.0f;
|
lightPos[1] = -1.0f;
|
||||||
lightPos[2] = -bx::fsin(m_timeAccumulatorLight);
|
lightPos[2] = -bx::fsin(m_timeAccumulatorLight);
|
||||||
lightPos[3] = 0.0f;
|
lightPos[3] = 0.0f;
|
||||||
|
|
||||||
bgfx::setUniform(u_lightPos, lightPos);
|
bgfx::setUniform(u_lightPos, lightPos);
|
||||||
|
|
||||||
// Setup instance matrices.
|
// Setup instance matrices.
|
||||||
float mtxFloor[16];
|
float mtxFloor[16];
|
||||||
bx::mtxSRT(mtxFloor
|
bx::mtxSRT(mtxFloor
|
||||||
@ -247,62 +247,62 @@ class ExampleShadowmapsSimple : public entry::AppI
|
|||||||
, 0.0f, 0.0f, 0.0f
|
, 0.0f, 0.0f, 0.0f
|
||||||
, 0.0f, 0.0f, 0.0f
|
, 0.0f, 0.0f, 0.0f
|
||||||
);
|
);
|
||||||
|
|
||||||
float mtxBunny[16];
|
float mtxBunny[16];
|
||||||
bx::mtxSRT(mtxBunny
|
bx::mtxSRT(mtxBunny
|
||||||
, 5.0f, 5.0f, 5.0f
|
, 5.0f, 5.0f, 5.0f
|
||||||
, 0.0f, bx::kPi - m_timeAccumulatorScene, 0.0f
|
, 0.0f, bx::kPi - m_timeAccumulatorScene, 0.0f
|
||||||
, 15.0f, 5.0f, 0.0f
|
, 15.0f, 5.0f, 0.0f
|
||||||
);
|
);
|
||||||
|
|
||||||
float mtxHollowcube[16];
|
float mtxHollowcube[16];
|
||||||
bx::mtxSRT(mtxHollowcube
|
bx::mtxSRT(mtxHollowcube
|
||||||
, 2.5f, 2.5f, 2.5f
|
, 2.5f, 2.5f, 2.5f
|
||||||
, 0.0f, 1.56f - m_timeAccumulatorScene, 0.0f
|
, 0.0f, 1.56f - m_timeAccumulatorScene, 0.0f
|
||||||
, 0.0f, 10.0f, 0.0f
|
, 0.0f, 10.0f, 0.0f
|
||||||
);
|
);
|
||||||
|
|
||||||
float mtxCube[16];
|
float mtxCube[16];
|
||||||
bx::mtxSRT(mtxCube
|
bx::mtxSRT(mtxCube
|
||||||
, 2.5f, 2.5f, 2.5f
|
, 2.5f, 2.5f, 2.5f
|
||||||
, 0.0f, 1.56f - m_timeAccumulatorScene, 0.0f
|
, 0.0f, 1.56f - m_timeAccumulatorScene, 0.0f
|
||||||
, -15.0f, 5.0f, 0.0f
|
, -15.0f, 5.0f, 0.0f
|
||||||
);
|
);
|
||||||
|
|
||||||
// Define matrices.
|
// Define matrices.
|
||||||
float lightView[16];
|
float lightView[16];
|
||||||
float lightProj[16];
|
float lightProj[16];
|
||||||
|
|
||||||
float eye[3] = { -lightPos[0], -lightPos[1], -lightPos[2] };
|
float eye[3] = { -lightPos[0], -lightPos[1], -lightPos[2] };
|
||||||
float at[3] = { 0.0f, 0.0f, 0.0f };
|
float at[3] = { 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
bx::mtxLookAt(lightView, eye, at);
|
bx::mtxLookAt(lightView, eye, at);
|
||||||
|
|
||||||
const float area = 30.0f;
|
const float area = 30.0f;
|
||||||
bx::mtxOrtho(lightProj, -area, area, -area, area, -100.0f, 100.0f, 0.0f, m_flipV);
|
bx::mtxOrtho(lightProj, -area, area, -area, area, -100.0f, 100.0f, 0.0f, m_flipV);
|
||||||
|
|
||||||
bgfx::setViewRect(RENDER_SHADOW_PASS_ID, 0, 0, m_shadowMapSize, m_shadowMapSize);
|
bgfx::setViewRect(RENDER_SHADOW_PASS_ID, 0, 0, m_shadowMapSize, m_shadowMapSize);
|
||||||
bgfx::setViewFrameBuffer(RENDER_SHADOW_PASS_ID, m_shadowMapFB);
|
bgfx::setViewFrameBuffer(RENDER_SHADOW_PASS_ID, m_shadowMapFB);
|
||||||
bgfx::setViewTransform(RENDER_SHADOW_PASS_ID, lightView, lightProj);
|
bgfx::setViewTransform(RENDER_SHADOW_PASS_ID, lightView, lightProj);
|
||||||
|
|
||||||
bgfx::setViewRect(RENDER_SCENE_PASS_ID, 0, 0, uint16_t(m_width), uint16_t(m_height) );
|
bgfx::setViewRect(RENDER_SCENE_PASS_ID, 0, 0, uint16_t(m_width), uint16_t(m_height) );
|
||||||
bgfx::setViewTransform(RENDER_SCENE_PASS_ID, m_view, m_proj);
|
bgfx::setViewTransform(RENDER_SCENE_PASS_ID, m_view, m_proj);
|
||||||
|
|
||||||
// Clear backbuffer and shadowmap framebuffer at beginning.
|
// Clear backbuffer and shadowmap framebuffer at beginning.
|
||||||
bgfx::setViewClear(RENDER_SHADOW_PASS_ID
|
bgfx::setViewClear(RENDER_SHADOW_PASS_ID
|
||||||
, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH
|
, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH
|
||||||
, 0x303030ff, 1.0f, 0
|
, 0x303030ff, 1.0f, 0
|
||||||
);
|
);
|
||||||
|
|
||||||
bgfx::setViewClear(RENDER_SCENE_PASS_ID
|
bgfx::setViewClear(RENDER_SCENE_PASS_ID
|
||||||
, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH
|
, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH
|
||||||
, 0x303030ff, 1.0f, 0
|
, 0x303030ff, 1.0f, 0
|
||||||
);
|
);
|
||||||
|
|
||||||
// Render.
|
// Render.
|
||||||
float mtxShadow[16];
|
float mtxShadow[16];
|
||||||
float lightMtx[16];
|
float lightMtx[16];
|
||||||
|
|
||||||
const float sy = m_flipV ? 0.5f : -0.5f;
|
const float sy = m_flipV ? 0.5f : -0.5f;
|
||||||
const float mtxCrop[16] =
|
const float mtxCrop[16] =
|
||||||
{
|
{
|
||||||
@ -311,11 +311,11 @@ class ExampleShadowmapsSimple : public entry::AppI
|
|||||||
0.0f, 0.0f, m_depthScale, 0.0f,
|
0.0f, 0.0f, m_depthScale, 0.0f,
|
||||||
0.5f, 0.5f, m_depthOffset, 1.0f,
|
0.5f, 0.5f, m_depthOffset, 1.0f,
|
||||||
};
|
};
|
||||||
|
|
||||||
float mtxTmp[16];
|
float mtxTmp[16];
|
||||||
bx::mtxMul(mtxTmp, lightProj, mtxCrop);
|
bx::mtxMul(mtxTmp, lightProj, mtxCrop);
|
||||||
bx::mtxMul(mtxShadow, lightView, mtxTmp);
|
bx::mtxMul(mtxShadow, lightView, mtxTmp);
|
||||||
|
|
||||||
// Floor.
|
// Floor.
|
||||||
bx::mtxMul(lightMtx, mtxFloor, mtxShadow);
|
bx::mtxMul(lightMtx, mtxFloor, mtxShadow);
|
||||||
uint32_t cached = bgfx::setTransform(mtxFloor);
|
uint32_t cached = bgfx::setTransform(mtxFloor);
|
||||||
@ -338,74 +338,74 @@ class ExampleShadowmapsSimple : public entry::AppI
|
|||||||
bgfx::setState(st.m_state);
|
bgfx::setState(st.m_state);
|
||||||
bgfx::submit(st.m_viewId, st.m_program);
|
bgfx::submit(st.m_viewId, st.m_program);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bunny.
|
// Bunny.
|
||||||
bx::mtxMul(lightMtx, mtxBunny, mtxShadow);
|
bx::mtxMul(lightMtx, mtxBunny, mtxShadow);
|
||||||
bgfx::setUniform(u_lightMtx, lightMtx);
|
bgfx::setUniform(u_lightMtx, lightMtx);
|
||||||
meshSubmit(m_bunny, &m_state[0], 1, mtxBunny);
|
meshSubmit(m_bunny, &m_state[0], 1, mtxBunny);
|
||||||
bgfx::setUniform(u_lightMtx, lightMtx);
|
bgfx::setUniform(u_lightMtx, lightMtx);
|
||||||
meshSubmit(m_bunny, &m_state[1], 1, mtxBunny);
|
meshSubmit(m_bunny, &m_state[1], 1, mtxBunny);
|
||||||
|
|
||||||
// Hollow cube.
|
// Hollow cube.
|
||||||
bx::mtxMul(lightMtx, mtxHollowcube, mtxShadow);
|
bx::mtxMul(lightMtx, mtxHollowcube, mtxShadow);
|
||||||
bgfx::setUniform(u_lightMtx, lightMtx);
|
bgfx::setUniform(u_lightMtx, lightMtx);
|
||||||
meshSubmit(m_hollowcube, &m_state[0], 1, mtxHollowcube);
|
meshSubmit(m_hollowcube, &m_state[0], 1, mtxHollowcube);
|
||||||
bgfx::setUniform(u_lightMtx, lightMtx);
|
bgfx::setUniform(u_lightMtx, lightMtx);
|
||||||
meshSubmit(m_hollowcube, &m_state[1], 1, mtxHollowcube);
|
meshSubmit(m_hollowcube, &m_state[1], 1, mtxHollowcube);
|
||||||
|
|
||||||
// Cube.
|
// Cube.
|
||||||
bx::mtxMul(lightMtx, mtxCube, mtxShadow);
|
bx::mtxMul(lightMtx, mtxCube, mtxShadow);
|
||||||
bgfx::setUniform(u_lightMtx, lightMtx);
|
bgfx::setUniform(u_lightMtx, lightMtx);
|
||||||
meshSubmit(m_cube, &m_state[0], 1, mtxCube);
|
meshSubmit(m_cube, &m_state[0], 1, mtxCube);
|
||||||
bgfx::setUniform(u_lightMtx, lightMtx);
|
bgfx::setUniform(u_lightMtx, lightMtx);
|
||||||
meshSubmit(m_cube, &m_state[1], 1, mtxCube);
|
meshSubmit(m_cube, &m_state[1], 1, mtxCube);
|
||||||
|
|
||||||
// Advance to next frame. Rendering thread will be kicked to
|
// Advance to next frame. Rendering thread will be kicked to
|
||||||
// process submitted rendering primitives.
|
// process submitted rendering primitives.
|
||||||
bgfx::frame();
|
bgfx::frame();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry::MouseState m_mouseState;
|
entry::MouseState m_mouseState;
|
||||||
uint32_t m_width;
|
uint32_t m_width;
|
||||||
uint32_t m_height;
|
uint32_t m_height;
|
||||||
uint32_t m_debug;
|
uint32_t m_debug;
|
||||||
uint32_t m_reset;
|
uint32_t m_reset;
|
||||||
|
|
||||||
bool m_flipV;
|
bool m_flipV;
|
||||||
|
|
||||||
bgfx::UniformHandle u_shadowMap;
|
bgfx::UniformHandle u_shadowMap;
|
||||||
bgfx::UniformHandle u_lightPos;
|
bgfx::UniformHandle u_lightPos;
|
||||||
bgfx::UniformHandle u_lightMtx;
|
bgfx::UniformHandle u_lightMtx;
|
||||||
|
|
||||||
bgfx::UniformHandle u_depthScaleOffset;
|
bgfx::UniformHandle u_depthScaleOffset;
|
||||||
float m_depthScale;
|
float m_depthScale;
|
||||||
float m_depthOffset;
|
float m_depthOffset;
|
||||||
|
|
||||||
Mesh* m_bunny;
|
Mesh* m_bunny;
|
||||||
Mesh* m_cube;
|
Mesh* m_cube;
|
||||||
Mesh* m_hollowcube;
|
Mesh* m_hollowcube;
|
||||||
|
|
||||||
bgfx::VertexBufferHandle m_vbh;
|
bgfx::VertexBufferHandle m_vbh;
|
||||||
bgfx::IndexBufferHandle m_ibh;
|
bgfx::IndexBufferHandle m_ibh;
|
||||||
|
|
||||||
uint16_t m_shadowMapSize;
|
uint16_t m_shadowMapSize;
|
||||||
|
|
||||||
bgfx::ProgramHandle m_progShadow;
|
bgfx::ProgramHandle m_progShadow;
|
||||||
bgfx::ProgramHandle m_progMesh;
|
bgfx::ProgramHandle m_progMesh;
|
||||||
bgfx::FrameBufferHandle m_shadowMapFB;
|
bgfx::FrameBufferHandle m_shadowMapFB;
|
||||||
|
|
||||||
bool m_shadowSamplerSupported;
|
bool m_shadowSamplerSupported;
|
||||||
|
|
||||||
MeshState* m_state[2];
|
MeshState* m_state[2];
|
||||||
|
|
||||||
float m_timeAccumulatorLight;
|
float m_timeAccumulatorLight;
|
||||||
float m_timeAccumulatorScene;
|
float m_timeAccumulatorScene;
|
||||||
|
|
||||||
float m_view[16];
|
float m_view[16];
|
||||||
float m_proj[16];
|
float m_proj[16];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user