From d25990487ea74868aae88d6dd7c840e6908d85f8 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 6 Oct 2014 06:29:03 +0200 Subject: [PATCH 1/3] Added return value for imguiCube(). --- examples/common/imgui/imgui.cpp | 20 +++++++++++++++----- examples/common/imgui/imgui.h | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index c0b2ca038..df39f137a 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -1619,10 +1619,10 @@ struct Imgui imageChannel(_image, _channel, _lod, int32_t(width), int32_t(height), _align); } - void cubeMap(bgfx::TextureHandle _cubemap, float _lod, bool _cross, ImguiAlign::Enum _align) + bool cubeMap(bgfx::TextureHandle _cubemap, float _lod, bool _cross, ImguiAlign::Enum _align) { - uint32_t numVertices = 14; - uint32_t numIndices = 36; + const uint32_t numVertices = 14; + const uint32_t numIndices = 36; if (bgfx::checkAvailTransientBuffers(numVertices, PosNormalVertex::ms_decl, numIndices) ) { bgfx::TransientVertexBuffer tvb; @@ -1692,6 +1692,8 @@ struct Imgui indices += quad(indices, 10, 12, 13, 11); } + const uint32_t id = getId(); + Area& area = getCurrentArea(); int32_t xx; int32_t width; @@ -1717,6 +1719,10 @@ struct Imgui const int32_t yy = area.m_widgetY; area.m_widgetY += height + DEFAULT_SPACING; + const bool enabled = isEnabled(m_areaId); + const bool over = enabled && inRect(xx, yy, width, height); + const bool res = buttonLogic(id, over); + const float scale = float(width/2); float mtx[16]; @@ -1734,7 +1740,11 @@ struct Imgui ); setCurrentScissor(); bgfx::submit(m_view); + + return res; } + + return false; } bool collapse(const char* _text, const char* _subtext, bool _checked, bool _enabled) @@ -3271,9 +3281,9 @@ void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, s_imgui.imageChannel(_image, _channel, _lod, _width, _aspect, _align); } -void imguiCube(bgfx::TextureHandle _cubemap, float _lod, bool _cross, ImguiAlign::Enum _align) +bool imguiCube(bgfx::TextureHandle _cubemap, float _lod, bool _cross, ImguiAlign::Enum _align) { - s_imgui.cubeMap(_cubemap, _lod, _cross, _align); + return s_imgui.cubeMap(_cubemap, _lod, _cross, _align); } float imguiGetTextLength(const char* _text, ImguiFontHandle _handle) diff --git a/examples/common/imgui/imgui.h b/examples/common/imgui/imgui.h index f33c0599f..e7761aa4e 100644 --- a/examples/common/imgui/imgui.h +++ b/examples/common/imgui/imgui.h @@ -178,7 +178,7 @@ void imguiImage(bgfx::TextureHandle _image, float _lod, int32_t _width, int32_t void imguiImage(bgfx::TextureHandle _image, float _lod, float _scale, float _aspect, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, bool _originBottomLeft = false); void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align = ImguiAlign::LeftIndented); void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, float _scale, float _aspect, ImguiAlign::Enum _align = ImguiAlign::LeftIndented); -void imguiCube(bgfx::TextureHandle _cubemap, float _lod = 0.0f, bool _cross = true, ImguiAlign::Enum _align = ImguiAlign::LeftIndented); +bool imguiCube(bgfx::TextureHandle _cubemap, float _lod = 0.0f, bool _cross = true, ImguiAlign::Enum _align = ImguiAlign::LeftIndented); float imguiGetTextLength(const char* _text, ImguiFontHandle _handle); bool imguiMouseOverArea(); From ba9651cb57dace2b070d9d1157f53525160828be Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 6 Oct 2014 06:30:11 +0200 Subject: [PATCH 2/3] 18-ibl now makes use of clickable imguiCube(). --- examples/18-ibl/ibl.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/examples/18-ibl/ibl.cpp b/examples/18-ibl/ibl.cpp index 6e6cdeb56..72ca5df71 100644 --- a/examples/18-ibl/ibl.cpp +++ b/examples/18-ibl/ibl.cpp @@ -486,6 +486,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) bool m_specularIbl; bool m_showDiffColorWheel; bool m_showSpecColorWheel; + bool m_crossCubemapPreview; }; Settings settings; @@ -505,6 +506,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) settings.m_specularIbl = true; settings.m_showDiffColorWheel = false; settings.m_showSpecColorWheel = false; + settings.m_crossCubemapPreview = false; float time = 0.0f; @@ -523,7 +525,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) ); static int32_t rightScrollArea = 0; - imguiBeginScrollArea("Settings", width - 256 - 10, 10, 256, 520, &rightScrollArea); + imguiBeginScrollArea("Settings", width - 256 - 10, 10, 256, 590, &rightScrollArea); imguiLabel("Shade:"); imguiSeparator(); @@ -534,8 +536,12 @@ int _main_(int /*_argc*/, char** /*_argv*/) imguiSeparatorLine(); imguiSlider("Speed", settings.m_speed, 0.0f, 1.0f, 0.01f); - imguiSeparatorLine(); + + imguiSeparator(); + imguiSlider("Exposure", settings.m_exposure, -8.0f, 8.0f, 0.01f); + imguiSeparator(); + imguiLabel("Environment:"); currentLightProbe = LightProbe::Enum(imguiChoose(currentLightProbe , "Wells" @@ -545,11 +551,12 @@ int _main_(int /*_argc*/, char** /*_argv*/) , "Grace" ) ); static float lod = 0.0f; - imguiCube(lightProbes[currentLightProbe].m_tex, lod, false); + if (imguiCube(lightProbes[currentLightProbe].m_tex, lod, settings.m_crossCubemapPreview)) + { + settings.m_crossCubemapPreview = !settings.m_crossCubemapPreview; + } imguiSlider("Texture LOD", lod, float(0.0f), 10.1f, 0.1f); - imguiSeparator(); - imguiSlider("Exposure", settings.m_exposure, -8.0f, 8.0f, 0.01f); imguiEndScrollArea(); imguiBeginScrollArea("Settings", 10, 70, 256, 576, &leftScrollArea); From 48ce6bb5ff290c96a6372c7cebb54c3b2314125d Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 6 Oct 2014 07:03:41 +0200 Subject: [PATCH 3/3] Added custom mtxProj() call to properly handle OGL NDC. --- examples/03-raymarch/raymarch.cpp | 11 ++++++--- examples/09-hdr/hdr.cpp | 24 ++++++++++++------- examples/13-stencil/stencil.cpp | 7 +++++- examples/14-shadowvolumes/shadowvolumes.cpp | 10 +++++++- .../shadowmaps_simple.cpp | 7 +++++- examples/19-oit/oit.cpp | 7 +++++- examples/21-deferred/deferred.cpp | 15 ++++++++---- 7 files changed, 61 insertions(+), 20 deletions(-) diff --git a/examples/03-raymarch/raymarch.cpp b/examples/03-raymarch/raymarch.cpp index a60ffb415..7d20edd9f 100644 --- a/examples/03-raymarch/raymarch.cpp +++ b/examples/03-raymarch/raymarch.cpp @@ -30,7 +30,12 @@ struct PosColorTexCoord0Vertex bgfx::VertexDecl PosColorTexCoord0Vertex::ms_decl; -static bool s_flipV = false; +static bool s_oglNdc = false; + +inline void mtxProj(float* _result, float _fovy, float _aspect, float _near, float _far) +{ + bx::mtxProj(_result, _fovy, _aspect, _near, _far, s_oglNdc); +} void renderScreenSpaceQuad(uint32_t _view, bgfx::ProgramHandle _program, float _x, float _y, float _width, float _height) { @@ -128,7 +133,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) case bgfx::RendererType::OpenGL: case bgfx::RendererType::OpenGLES: - s_flipV = true; + s_oglNdc = true; break; } @@ -175,7 +180,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) float view[16]; float proj[16]; bx::mtxLookAt(view, eye, at); - bx::mtxProj(proj, 60.0f, float(width)/float(height), 0.1f, 100.0f); + mtxProj(proj, 60.0f, float(width)/float(height), 0.1f, 100.0f); // Set view and projection matrix for view 1. bgfx::setViewTransform(0, view, proj); diff --git a/examples/09-hdr/hdr.cpp b/examples/09-hdr/hdr.cpp index e6a00245b..df13e9855 100644 --- a/examples/09-hdr/hdr.cpp +++ b/examples/09-hdr/hdr.cpp @@ -8,6 +8,12 @@ #include "imgui/imgui.h" static float s_texelHalf = 0.0f; +static bool s_originBottomLeft = false; + +inline void mtxProj(float* _result, float _fovy, float _aspect, float _near, float _far) +{ + bx::mtxProj(_result, _fovy, _aspect, _near, _far, s_originBottomLeft); +} struct PosColorTexCoord0Vertex { @@ -209,7 +215,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) const bgfx::RendererType::Enum renderer = bgfx::getRendererType(); s_texelHalf = bgfx::RendererType::Direct3D9 == renderer ? 0.5f : 0.0f; - const bool originBottomLeft = bgfx::RendererType::OpenGL == renderer || bgfx::RendererType::OpenGLES == renderer; + s_originBottomLeft = bgfx::RendererType::OpenGL == renderer || bgfx::RendererType::OpenGLES == renderer; uint32_t oldWidth = 0; uint32_t oldHeight = 0; @@ -372,7 +378,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::setTexture(0, u_texColor, fbtextures[0]); bgfx::setProgram(lumProgram); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); - screenSpaceQuad(128.0f, 128.0f, originBottomLeft); + screenSpaceQuad(128.0f, 128.0f, s_originBottomLeft); bgfx::submit(2); // Downscale luminance 0. @@ -380,7 +386,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::setTexture(0, u_texColor, lum[0]); bgfx::setProgram(lumAvgProgram); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); - screenSpaceQuad(64.0f, 64.0f, originBottomLeft); + screenSpaceQuad(64.0f, 64.0f, s_originBottomLeft); bgfx::submit(3); // Downscale luminance 1. @@ -388,7 +394,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::setTexture(0, u_texColor, lum[1]); bgfx::setProgram(lumAvgProgram); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); - screenSpaceQuad(16.0f, 16.0f, originBottomLeft); + screenSpaceQuad(16.0f, 16.0f, s_originBottomLeft); bgfx::submit(4); // Downscale luminance 2. @@ -396,7 +402,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::setTexture(0, u_texColor, lum[2]); bgfx::setProgram(lumAvgProgram); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); - screenSpaceQuad(4.0f, 4.0f, originBottomLeft); + screenSpaceQuad(4.0f, 4.0f, s_originBottomLeft); bgfx::submit(5); // Downscale luminance 3. @@ -404,7 +410,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::setTexture(0, u_texColor, lum[3]); bgfx::setProgram(lumAvgProgram); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); - screenSpaceQuad(1.0f, 1.0f, originBottomLeft); + screenSpaceQuad(1.0f, 1.0f, s_originBottomLeft); bgfx::submit(6); float tonemap[4] = { middleGray, square(white), treshold, 0.0f }; @@ -416,14 +422,14 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::setTexture(1, u_texLum, lum[4]); bgfx::setProgram(brightProgram); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); - screenSpaceQuad( (float)width/2.0f, (float)height/2.0f, originBottomLeft); + screenSpaceQuad( (float)width/2.0f, (float)height/2.0f, s_originBottomLeft); bgfx::submit(7); // Blur bright pass vertically. bgfx::setTexture(0, u_texColor, bright); bgfx::setProgram(blurProgram); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); - screenSpaceQuad( (float)width/8.0f, (float)height/8.0f, originBottomLeft); + screenSpaceQuad( (float)width/8.0f, (float)height/8.0f, s_originBottomLeft); bgfx::submit(8); // Blur bright pass horizontally, do tonemaping and combine. @@ -432,7 +438,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::setTexture(2, u_texBlur, blur); bgfx::setProgram(tonemapProgram); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); - screenSpaceQuad( (float)width, (float)height, originBottomLeft); + screenSpaceQuad( (float)width, (float)height, s_originBottomLeft); bgfx::submit(9); // Advance to next frame. Rendering thread will be kicked to diff --git a/examples/13-stencil/stencil.cpp b/examples/13-stencil/stencil.cpp index cdaaa31f5..d9755d0dd 100644 --- a/examples/13-stencil/stencil.cpp +++ b/examples/13-stencil/stencil.cpp @@ -151,6 +151,11 @@ static uint32_t s_viewMask = 0; static uint32_t s_clearMask = 0; static bgfx::UniformHandle u_texColor; +inline void mtxProj(float* _result, float _fovy, float _aspect, float _near, float _far) +{ + bx::mtxProj(_result, _fovy, _aspect, _near, _far, s_flipV); +} + static void shaderFilePath(char* _out, const char* _name) { strcpy(_out, s_shaderPath); @@ -1004,7 +1009,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) // Set view and projection matrices. const float aspect = float(viewState.m_width)/float(viewState.m_height); - bx::mtxProj(viewState.m_proj, 60.0f, aspect, 0.1f, 100.0f); + mtxProj(viewState.m_proj, 60.0f, aspect, 0.1f, 100.0f); float initialPos[3] = { 0.0f, 18.0f, -40.0f }; cameraCreate(); diff --git a/examples/14-shadowvolumes/shadowvolumes.cpp b/examples/14-shadowvolumes/shadowvolumes.cpp index f703d0573..ab11e0013 100644 --- a/examples/14-shadowvolumes/shadowvolumes.cpp +++ b/examples/14-shadowvolumes/shadowvolumes.cpp @@ -111,6 +111,7 @@ static const uint16_t s_planeIndices[] = }; static const char* s_shaderPath = NULL; +static bool s_oglNdc = false; static float s_texelHalf = 0.0f; static uint32_t s_viewMask = 0; @@ -221,6 +222,11 @@ void setViewRectMask(uint32_t _viewMask, uint16_t _x, uint16_t _y, uint16_t _wid } } +inline void mtxProj(float* _result, float _fovy, float _aspect, float _near, float _far) +{ + bx::mtxProj(_result, _fovy, _aspect, _near, _far, s_oglNdc); +} + void mtxBillboard(float* __restrict _result , const float* __restrict _view , const float* __restrict _pos @@ -1951,10 +1957,12 @@ int _main_(int /*_argc*/, char** /*_argv*/) case bgfx::RendererType::OpenGL: s_shaderPath = "shaders/glsl/"; + s_oglNdc = true; break; case bgfx::RendererType::OpenGLES: s_shaderPath = "shaders/gles/"; + s_oglNdc = true; break; } @@ -2163,7 +2171,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) const float aspect = float(viewState.m_width)/float(viewState.m_height); const float nearPlane = 1.0f; const float farPlane = 1000.0f; - bx::mtxProj(viewState.m_proj, fov, aspect, nearPlane, farPlane); + mtxProj(viewState.m_proj, fov, aspect, nearPlane, farPlane); float initialPos[3] = { 3.0f, 20.0f, -58.0f }; cameraCreate(); diff --git a/examples/15-shadowmaps-simple/shadowmaps_simple.cpp b/examples/15-shadowmaps-simple/shadowmaps_simple.cpp index 2c73df610..f95a527d9 100644 --- a/examples/15-shadowmaps-simple/shadowmaps_simple.cpp +++ b/examples/15-shadowmaps-simple/shadowmaps_simple.cpp @@ -71,6 +71,11 @@ static float s_texelHalf = 0.0f; bgfx::FrameBufferHandle s_shadowMapFB; static bgfx::UniformHandle u_shadowMap; +inline void mtxProj(float* _result, float _fovy, float _aspect, float _near, float _far) +{ + bx::mtxProj(_result, _fovy, _aspect, _near, _far, s_flipV); +} + static void shaderFilePath(char* _out, const char* _name) { strcpy(_out, s_shaderPath); @@ -486,7 +491,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) bx::mtxLookAt(view, eye, at); const float aspect = float(int32_t(width) ) / float(int32_t(height) ); - bx::mtxProj(proj, 60.0f, aspect, 0.1f, 1000.0f); + mtxProj(proj, 60.0f, aspect, 0.1f, 1000.0f); // Time acumulators. float timeAccumulatorLight = 0.0f; diff --git a/examples/19-oit/oit.cpp b/examples/19-oit/oit.cpp index 801763664..08e9d77d9 100644 --- a/examples/19-oit/oit.cpp +++ b/examples/19-oit/oit.cpp @@ -83,6 +83,11 @@ static const uint16_t s_cubeIndices[36] = static float s_texelHalf = 0.0f; static bool s_flipV = false; +inline void mtxProj(float* _result, float _fovy, float _aspect, float _near, float _far) +{ + bx::mtxProj(_result, _fovy, _aspect, _near, _far, s_flipV); +} + void screenSpaceQuad(float _textureWidth, float _textureHeight, bool _originBottomLeft = false, float _width = 1.0f, float _height = 1.0f) { if (bgfx::checkAvailTransientVertexBuffer(3, PosColorTexCoord0Vertex::ms_decl) ) @@ -303,7 +308,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) // Set view and projection matrix for view 0. bx::mtxLookAt(view, eye, at); - bx::mtxProj(proj, 60.0f, float(width)/float(height), 0.1f, 100.0f); + mtxProj(proj, 60.0f, float(width)/float(height), 0.1f, 100.0f); bgfx::setViewTransform(0, view, proj); diff --git a/examples/21-deferred/deferred.cpp b/examples/21-deferred/deferred.cpp index 00a06ff24..7612002ff 100644 --- a/examples/21-deferred/deferred.cpp +++ b/examples/21-deferred/deferred.cpp @@ -15,6 +15,13 @@ #define RENDER_PASS_DEBUG_LIGHTS_ID 3 #define RENDER_PASS_DEBUG_GBUFFER_ID 4 +static bool s_originBottomLeft = false; + +inline void mtxProj(float* _result, float _fovy, float _aspect, float _near, float _far) +{ + bx::mtxProj(_result, _fovy, _aspect, _near, _far, s_originBottomLeft); +} + struct PosNormalTangentTexcoordVertex { float m_x; @@ -303,7 +310,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) const int64_t timeOffset = bx::getHPCounter(); const bgfx::RendererType::Enum renderer = bgfx::getRendererType(); const float texelHalf = bgfx::RendererType::Direct3D9 == renderer ? 0.5f : 0.0f; - const bool originBottomLeft = bgfx::RendererType::OpenGL == renderer || bgfx::RendererType::OpenGLES == renderer; + s_originBottomLeft = bgfx::RendererType::OpenGL == renderer || bgfx::RendererType::OpenGLES == renderer; // Get renderer capabilities info. const bgfx::Caps* caps = bgfx::getCaps(); @@ -448,7 +455,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::setViewFrameBuffer(RENDER_PASS_LIGHT_ID, lightBuffer); float proj[16]; - bx::mtxProj(proj, 60.0f, float(width)/float(height), 0.1f, 100.0f); + mtxProj(proj, 60.0f, float(width)/float(height), 0.1f, 100.0f); bgfx::setViewFrameBuffer(RENDER_PASS_GEOMETRY_ID, gbuffer); bgfx::setViewTransform(RENDER_PASS_GEOMETRY_ID, view, proj); @@ -647,7 +654,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) | BGFX_STATE_ALPHA_WRITE | BGFX_STATE_BLEND_ADD ); - screenSpaceQuad( (float)width, (float)height, texelHalf, originBottomLeft); + screenSpaceQuad( (float)width, (float)height, texelHalf, s_originBottomLeft); bgfx::submit(RENDER_PASS_LIGHT_ID); } } @@ -660,7 +667,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) | BGFX_STATE_RGB_WRITE | BGFX_STATE_ALPHA_WRITE ); - screenSpaceQuad( (float)width, (float)height, texelHalf, originBottomLeft); + screenSpaceQuad( (float)width, (float)height, texelHalf, s_originBottomLeft); bgfx::submit(RENDER_PASS_COMBINE_ID); if (showGBuffer)