diff --git a/examples/15-shadowmaps-simple/shadowmaps_simple.cpp b/examples/15-shadowmaps-simple/shadowmaps_simple.cpp index 92437474..500bdfdc 100644 --- a/examples/15-shadowmaps-simple/shadowmaps_simple.cpp +++ b/examples/15-shadowmaps-simple/shadowmaps_simple.cpp @@ -15,8 +15,8 @@ #include "entry/entry.h" #include "fpumath.h" -#define RENDER_PASS_0 0 -#define RENDER_PASS_1 1 +#define RENDER_SHADOW_PASS_ID 0 +#define RENDER_SCENE_PASS_ID 1 uint32_t packUint32(uint8_t _x, uint8_t _y, uint8_t _z, uint8_t _w) { @@ -577,17 +577,13 @@ int _main_(int /*_argc*/, char** /*_argv*/) const float area = 30.0f; mtxOrtho(lightProj, -area, area, -area, area, -100.0f, 100.0f); - /** - * RENDER_PASS_0 - Craft shadow map. - * RENDER_PASS_1 - Draw scene. - */ - bgfx::setViewRect(RENDER_PASS_0, 0, 0, shadowMapSize, shadowMapSize); - bgfx::setViewRect(RENDER_PASS_1, 0, 0, width, height); + bgfx::setViewRect(RENDER_SHADOW_PASS_ID, 0, 0, shadowMapSize, shadowMapSize); + bgfx::setViewRect(RENDER_SCENE_PASS_ID, 0, 0, width, height); - bgfx::setViewTransform(RENDER_PASS_0, lightView, lightProj); - bgfx::setViewTransform(RENDER_PASS_1, view, proj); + bgfx::setViewTransform(RENDER_SHADOW_PASS_ID, lightView, lightProj); + bgfx::setViewTransform(RENDER_SCENE_PASS_ID, view, proj); - bgfx::setViewRenderTarget(RENDER_PASS_0, s_rtShadowMap); + bgfx::setViewRenderTarget(RENDER_SHADOW_PASS_ID, s_rtShadowMap); // Clear backbuffer and shadowmap rendertarget at beginning. bgfx::setViewClearMask(0x3, BGFX_CLEAR_COLOR_BIT | BGFX_CLEAR_DEPTH_BIT, 0x303030ff, 1.0f, 0); @@ -597,10 +593,10 @@ int _main_(int /*_argc*/, char** /*_argv*/) { // Craft shadow map. - hplaneMesh.submit(RENDER_PASS_0, mtxFloor, progPackDepth); - bunnyMesh.submit(RENDER_PASS_0, mtxBunny, progPackDepth); - hollowcubeMesh.submit(RENDER_PASS_0, mtxHollowcube, progPackDepth); - cubeMesh.submit(RENDER_PASS_0, mtxCube, progPackDepth); + hplaneMesh.submit(RENDER_SHADOW_PASS_ID, mtxFloor, progPackDepth); + bunnyMesh.submit(RENDER_SHADOW_PASS_ID, mtxBunny, progPackDepth); + hollowcubeMesh.submit(RENDER_SHADOW_PASS_ID, mtxHollowcube, progPackDepth); + cubeMesh.submit(RENDER_SHADOW_PASS_ID, mtxCube, progPackDepth); } { // Draw Scene. @@ -625,22 +621,22 @@ int _main_(int /*_argc*/, char** /*_argv*/) // Floor. mtxMul(lightMtx, mtxFloor, mtxShadow); bgfx::setUniform(u_lightMtx, lightMtx); - hplaneMesh.submit(RENDER_PASS_1, mtxFloor, progDraw); + hplaneMesh.submit(RENDER_SCENE_PASS_ID, mtxFloor, progDraw); // Bunny. mtxMul(lightMtx, mtxBunny, mtxShadow); bgfx::setUniform(u_lightMtx, lightMtx); - bunnyMesh.submit(RENDER_PASS_1, mtxBunny, progDraw); + bunnyMesh.submit(RENDER_SCENE_PASS_ID, mtxBunny, progDraw); // Hollow cube. mtxMul(lightMtx, mtxHollowcube, mtxShadow); bgfx::setUniform(u_lightMtx, lightMtx); - hollowcubeMesh.submit(RENDER_PASS_1, mtxHollowcube, progDraw); + hollowcubeMesh.submit(RENDER_SCENE_PASS_ID, mtxHollowcube, progDraw); // Cube. mtxMul(lightMtx, mtxCube, mtxShadow); bgfx::setUniform(u_lightMtx, lightMtx); - cubeMesh.submit(RENDER_PASS_1, mtxCube, progDraw); + cubeMesh.submit(RENDER_SCENE_PASS_ID, mtxCube, progDraw); } // Advance to next frame. Rendering thread will be kicked to diff --git a/examples/16-shadowmaps/shadowmaps.cpp b/examples/16-shadowmaps/shadowmaps.cpp index eaf0729e..ca126bae 100644 --- a/examples/16-shadowmaps/shadowmaps.cpp +++ b/examples/16-shadowmaps/shadowmaps.cpp @@ -1552,34 +1552,34 @@ int _main_(int /*_argc*/, char** /*_argv*/) // Materials. Material defaultMaterial = { - {{ 1.0f, 1.0f, 1.0f, 0.0f }} //ambient - ,{{ 1.0f, 1.0f, 1.0f, 0.0f }} //diffuse - ,{{ 1.0f, 1.0f, 1.0f, 0.0f }} //specular, exponent + { { 1.0f, 1.0f, 1.0f, 0.0f } }, //ambient + { { 1.0f, 1.0f, 1.0f, 0.0f } }, //diffuse + { { 1.0f, 1.0f, 1.0f, 0.0f } }, //specular, exponent }; // Lights. Light pointLight = { - {{ 0.0f, 0.0f, 0.0f, 1.0f }}, //position - { 0.0f, 0.0f, 0.0f, 0.0f }, //-ignore - {{ 1.0f, 1.0f, 1.0f, 0.0f }}, //ambient - {{ 1.0f, 1.0f, 1.0f, 850.0f }}, //diffuse - {{ 1.0f, 1.0f, 1.0f, 0.0f }}, //specular - {{ 0.0f,-0.4f,-0.6f, 0.0f }}, //spotdirection, spotexponent - { 0.0f, 0.0f, 0.0f, 0.0f }, //-ignore - {{ 1.0f, 0.0f, 1.0f, 91.0f }}, //attenuation, spotcutoff + { { 0.0f, 0.0f, 0.0f, 1.0f } }, //position + { 0.0f, 0.0f, 0.0f, 0.0f }, //-ignore + { { 1.0f, 1.0f, 1.0f, 0.0f } }, //ambient + { { 1.0f, 1.0f, 1.0f, 850.0f } }, //diffuse + { { 1.0f, 1.0f, 1.0f, 0.0f } }, //specular + { { 0.0f,-0.4f,-0.6f, 0.0f } }, //spotdirection, spotexponent + { 0.0f, 0.0f, 0.0f, 0.0f }, //-ignore + { { 1.0f, 0.0f, 1.0f, 91.0f } }, //attenuation, spotcutoff }; Light directionalLight = { - {{ 0.5f,-1.0f, 0.1f, 0.0f }}, //position - { 0.0f, 0.0f, 0.0f, 0.0f }, //-ignore - {{ 1.0f, 1.0f, 1.0f, 0.02f }}, //ambient - {{ 1.0f, 1.0f, 1.0f, 0.4f }}, //diffuse - {{ 1.0f, 1.0f, 1.0f, 0.0f }}, //specular - {{ 0.0f, 0.0f, 0.0f, 1.0f }}, //spotdirection, spotexponent - { 0.0f, 0.0f, 0.0f, 0.0f }, //-ignore - {{ 0.0f, 0.0f, 0.0f, 1.0f }}, //attenuation, spotcutoff + { { 0.5f,-1.0f, 0.1f, 0.0f } }, //position + { 0.0f, 0.0f, 0.0f, 0.0f }, //-ignore + { { 1.0f, 1.0f, 1.0f, 0.02f } }, //ambient + { { 1.0f, 1.0f, 1.0f, 0.4f } }, //diffuse + { { 1.0f, 1.0f, 1.0f, 0.0f } }, //specular + { { 0.0f, 0.0f, 0.0f, 1.0f } }, //spotdirection, spotexponent + { 0.0f, 0.0f, 0.0f, 0.0f }, //-ignore + { { 0.0f, 0.0f, 0.0f, 1.0f } }, //attenuation, spotcutoff }; // Setup uniforms. @@ -2131,13 +2131,14 @@ int _main_(int /*_argc*/, char** /*_argv*/) static int32_t rightScrollArea = 0; imguiBeginScrollArea("Settings", viewState.m_width - 256 - 10, 10, 256, 660, &rightScrollArea); + #define IMGUI_FLOAT_SLIDER(_name, _val) \ - imguiSlider(_name \ - , &_val \ - , *(((float*)&_val)+1) \ - , *(((float*)&_val)+2) \ - , *(((float*)&_val)+3) \ - ) + imguiSlider(_name \ + , &_val \ + , *(((float*)&_val)+1) \ + , *(((float*)&_val)+2) \ + , *(((float*)&_val)+3) \ + ) imguiBool("Update lights", settings.m_updateLights); imguiBool("Update scene", settings.m_updateScene); @@ -2175,11 +2176,13 @@ int _main_(int /*_argc*/, char** /*_argv*/) case SmImpl::Hard: //imguiLabel("Hard"); break; + case SmImpl::PCF: imguiLabel("PCF"); IMGUI_FLOAT_SLIDER("X Offset:", currentSmSettings->m_xOffset); IMGUI_FLOAT_SLIDER("Y Offset:", currentSmSettings->m_yOffset); break; + case SmImpl::VSM: imguiLabel("VSM"); IMGUI_FLOAT_SLIDER("Min variance", currentSmSettings->m_customParam0); @@ -2191,6 +2194,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) IMGUI_FLOAT_SLIDER("Blur Y Offset:", currentSmSettings->m_yOffset); } break; + case SmImpl::ESM: imguiLabel("ESM"); IMGUI_FLOAT_SLIDER("ESM Hardness", currentSmSettings->m_customParam0); @@ -2203,7 +2207,6 @@ int _main_(int /*_argc*/, char** /*_argv*/) } break; - case SmImpl::Count: default: break; }; @@ -2253,6 +2256,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) } #undef IMGUI_FLOAT_SLIDER + imguiEndScrollArea(); imguiEndFrame(); diff --git a/examples/common/fpumath.h b/examples/common/fpumath.h index 522fd8b7..3c6ffc4c 100644 --- a/examples/common/fpumath.h +++ b/examples/common/fpumath.h @@ -26,12 +26,12 @@ inline float fmaxf(float _a, float _b) inline float toRad(float _deg) { - return _deg * float(M_PI) / 180.0f; + return _deg * float(M_PI / 180.0); } inline float toDeg(float _rad) { - return _rad * 180.0f / float(M_PI); + return _rad * float(180.0 / M_PI); } inline float fclamp(float _a, float _min, float _max)