Merge pull request #104 from dariomanesku/master

Added imguiColorWheel to 18-ibl.
This commit is contained in:
Branimir Karadžić 2014-06-22 23:51:22 -07:00
commit 0ea1d84b21

View file

@ -6,12 +6,17 @@
#include "common.h" #include "common.h"
#include "bgfx_utils.h" #include "bgfx_utils.h"
#include "imgui/imgui.h" #include "imgui/imgui.h"
#include "nanovg/nanovg.h"
#include <bx/readerwriter.h> #include <bx/readerwriter.h>
#include <bx/string.h>
#include <vector> #include <vector>
#include <string> #include <string>
#define IMGUI_VIEWID 30
#define NANOVG_VIEWID 31
static bool s_flipV = false; static bool s_flipV = false;
static float s_texelHalf = 0.0f; static float s_texelHalf = 0.0f;
@ -24,7 +29,7 @@ struct Uniforms
u_time = bgfx::createUniform("u_time", bgfx::UniformType::Uniform1f); u_time = bgfx::createUniform("u_time", bgfx::UniformType::Uniform1f);
u_mtx = bgfx::createUniform("u_mtx", bgfx::UniformType::Uniform4x4fv); u_mtx = bgfx::createUniform("u_mtx", bgfx::UniformType::Uniform4x4fv);
u_params = bgfx::createUniform("u_params", bgfx::UniformType::Uniform4fv); u_params = bgfx::createUniform("u_params", bgfx::UniformType::Uniform4fv);
u_flags = bgfx::createUniform("u_flags", bgfx::UniformType::Uniform4fv); u_flags = bgfx::createUniform("u_flags", bgfx::UniformType::Uniform4fv);
u_camPos = bgfx::createUniform("u_camPos", bgfx::UniformType::Uniform3fv); u_camPos = bgfx::createUniform("u_camPos", bgfx::UniformType::Uniform3fv);
u_rgbDiff = bgfx::createUniform("u_rgbDiff", bgfx::UniformType::Uniform3fv); u_rgbDiff = bgfx::createUniform("u_rgbDiff", bgfx::UniformType::Uniform3fv);
@ -388,6 +393,21 @@ void imguiBool(const char* _str, bool& _flag, bool _enabled = true)
} }
} }
void imguiColorWheel(const char* _str, float _color[3], bool* _activated, bool _enabled = true)
{
char buf[128];
bx::snprintf(buf, 127, "%s [RGB %-2.2f %-2.2f %-2.2f]", _str, _color[0], _color[1], _color[2]);
if (imguiButton(buf, true))
{
*_activated = !*_activated;
}
if (*_activated)
{
imguiColorWheel(_color, false, _enabled);
}
}
int _main_(int /*_argc*/, char** /*_argv*/) int _main_(int /*_argc*/, char** /*_argv*/)
{ {
uint32_t width = 1280; uint32_t width = 1280;
@ -427,6 +447,9 @@ int _main_(int /*_argc*/, char** /*_argv*/)
imguiCreate(data); imguiCreate(data);
free(data); free(data);
NVGcontext* nvg = nvgCreate(512, 512, 1, NANOVG_VIEWID);
bgfx::setViewSeq(NANOVG_VIEWID, true);
// Uniforms. // Uniforms.
s_uniforms.init(); s_uniforms.init();
@ -486,11 +509,6 @@ int _main_(int /*_argc*/, char** /*_argv*/)
bgfx::UniformHandle u_texCube = bgfx::createUniform("u_texCube", bgfx::UniformType::Uniform1i); bgfx::UniformHandle u_texCube = bgfx::createUniform("u_texCube", bgfx::UniformType::Uniform1i);
bgfx::UniformHandle u_texCubeIrr = bgfx::createUniform("u_texCubeIrr", bgfx::UniformType::Uniform1i); bgfx::UniformHandle u_texCubeIrr = bgfx::createUniform("u_texCubeIrr", bgfx::UniformType::Uniform1i);
bgfx::UniformHandle u_texAlbedo = bgfx::createUniform("u_texAlbedo", bgfx::UniformType::Uniform1i);
bgfx::UniformHandle u_texNormal = bgfx::createUniform("u_texNormal", bgfx::UniformType::Uniform1i);
bgfx::UniformHandle u_texSpecular = bgfx::createUniform("u_texSpecular", bgfx::UniformType::Uniform1i);
bgfx::UniformHandle u_texRoughness = bgfx::createUniform("u_texRoughness", bgfx::UniformType::Uniform1i);
bgfx::ProgramHandle programMesh = loadProgram("vs_ibl_mesh", "fs_ibl_mesh"); bgfx::ProgramHandle programMesh = loadProgram("vs_ibl_mesh", "fs_ibl_mesh");
bgfx::ProgramHandle programSky = loadProgram("vs_ibl_skybox", "fs_ibl_skybox"); bgfx::ProgramHandle programSky = loadProgram("vs_ibl_skybox", "fs_ibl_skybox");
@ -509,8 +527,8 @@ int _main_(int /*_argc*/, char** /*_argv*/)
bool m_specular; bool m_specular;
bool m_diffuseIbl; bool m_diffuseIbl;
bool m_specularIbl; bool m_specularIbl;
bool m_singleSliderDiff; bool m_showDiffColorWheel;
bool m_singleSliderSpec; bool m_showSpecColorWheel;
}; };
Settings settings; Settings settings;
@ -528,8 +546,8 @@ int _main_(int /*_argc*/, char** /*_argv*/)
settings.m_specular = true; settings.m_specular = true;
settings.m_diffuseIbl = true; settings.m_diffuseIbl = true;
settings.m_specularIbl = true; settings.m_specularIbl = true;
settings.m_singleSliderDiff = false; settings.m_showDiffColorWheel = false;
settings.m_singleSliderSpec = false; settings.m_showSpecColorWheel = false;
float time = 0.0f; float time = 0.0f;
@ -545,10 +563,13 @@ int _main_(int /*_argc*/, char** /*_argv*/)
, 0 , 0
, width , width
, height , height
, IMGUI_VIEWID
); );
nvgBeginFrame(nvg, int32_t(width), int32_t(height), 1.0f, NVG_STRAIGHT_ALPHA);
static int32_t rightScrollArea = 0; static int32_t rightScrollArea = 0;
imguiBeginScrollArea("Settings", width - 256 - 10, 10, 256, 426, &rightScrollArea); imguiBeginScrollArea("Settings", width - 256 - 10, 10, 256, 426, &rightScrollArea, nvg);
imguiLabel("Shade:"); imguiLabel("Shade:");
imguiSeparator(); imguiSeparator();
@ -575,50 +596,19 @@ int _main_(int /*_argc*/, char** /*_argv*/)
imguiEndScrollArea(); imguiEndScrollArea();
static int32_t leftScrollArea = 0; static int32_t leftScrollArea = 0;
imguiBeginScrollArea("Settings", 10, 70, 256, 576, &leftScrollArea); imguiBeginScrollArea("Settings", 10, 70, 256, 576, &leftScrollArea, nvg);
imguiLabel("Material properties:"); imguiLabel("Material properties:");
imguiSeparator(); imguiSeparator();
imguiSlider("Diffuse - Specular", &settings.m_diffspec, 0.0f, 1.0f, 0.01f); imguiSlider("Diffuse - Specular", &settings.m_diffspec, 0.0f, 1.0f, 0.01f);
imguiSlider("Glossiness" , &settings.m_glossiness, 0.0f, 1.0f, 0.01f); imguiSlider("Glossiness" , &settings.m_glossiness, 0.0f, 1.0f, 0.01f);
imguiSeparatorLine();
imguiLabel("Diffuse color:");
imguiSeparator(); imguiSeparator();
imguiBool("Single slider", settings.m_singleSliderDiff);
if (settings.m_singleSliderDiff)
{
imguiSlider("RGB:", &settings.m_rgbDiff[0], 0.0f, 1.0f, 0.01f);
settings.m_rgbDiff[1] = settings.m_rgbDiff[0];
settings.m_rgbDiff[2] = settings.m_rgbDiff[0];
} imguiColorWheel("Diffuse color:", &settings.m_rgbDiff[0], &settings.m_showDiffColorWheel);
else
{
imguiSlider("R:", &settings.m_rgbDiff[0], 0.0f, 1.0f, 0.01f);
imguiSlider("G:", &settings.m_rgbDiff[1], 0.0f, 1.0f, 0.01f);
imguiSlider("B:", &settings.m_rgbDiff[2], 0.0f, 1.0f, 0.01f);
}
imguiSeparatorLine();
imguiLabel("Specular color:");
imguiSeparator(); imguiSeparator();
imguiBool("Single slider", settings.m_singleSliderSpec); imguiColorWheel("Specular color:", &settings.m_rgbSpec[0], &settings.m_showSpecColorWheel);
if (settings.m_singleSliderSpec)
{
imguiSlider("RGB:", &settings.m_rgbSpec[0], 0.0f, 1.0f, 0.01f);
settings.m_rgbSpec[1] = settings.m_rgbSpec[0];
settings.m_rgbSpec[2] = settings.m_rgbSpec[0];
} imguiSeparator();
else
{
imguiSlider("R:", &settings.m_rgbSpec[0], 0.0f, 1.0f, 0.01f);
imguiSlider("G:", &settings.m_rgbSpec[1], 0.0f, 1.0f, 0.01f);
imguiSlider("B:", &settings.m_rgbSpec[2], 0.0f, 1.0f, 0.01f);
}
imguiSeparatorLine();
imguiLabel("Predefined materials:"); imguiLabel("Predefined materials:");
imguiSeparator(); imguiSeparator();
@ -634,8 +624,6 @@ int _main_(int /*_argc*/, char** /*_argv*/)
settings.m_rgbSpec[0] = 1.0f; settings.m_rgbSpec[0] = 1.0f;
settings.m_rgbSpec[1] = 0.86f; settings.m_rgbSpec[1] = 0.86f;
settings.m_rgbSpec[2] = 0.58f; settings.m_rgbSpec[2] = 0.58f;
settings.m_singleSliderSpec = false;
} }
if (imguiButton("Copper") ) if (imguiButton("Copper") )
@ -650,8 +638,6 @@ int _main_(int /*_argc*/, char** /*_argv*/)
settings.m_rgbSpec[0] = 0.98f; settings.m_rgbSpec[0] = 0.98f;
settings.m_rgbSpec[1] = 0.82f; settings.m_rgbSpec[1] = 0.82f;
settings.m_rgbSpec[2] = 0.76f; settings.m_rgbSpec[2] = 0.76f;
settings.m_singleSliderSpec = false;
} }
if (imguiButton("Titanium") ) if (imguiButton("Titanium") )
@ -666,8 +652,6 @@ int _main_(int /*_argc*/, char** /*_argv*/)
settings.m_rgbSpec[0] = 0.76f; settings.m_rgbSpec[0] = 0.76f;
settings.m_rgbSpec[1] = 0.73f; settings.m_rgbSpec[1] = 0.73f;
settings.m_rgbSpec[2] = 0.71f; settings.m_rgbSpec[2] = 0.71f;
settings.m_singleSliderSpec = false;
} }
if (imguiButton("Steel") ) if (imguiButton("Steel") )
@ -682,11 +666,11 @@ int _main_(int /*_argc*/, char** /*_argv*/)
settings.m_rgbSpec[0] = 0.77f; settings.m_rgbSpec[0] = 0.77f;
settings.m_rgbSpec[1] = 0.78f; settings.m_rgbSpec[1] = 0.78f;
settings.m_rgbSpec[2] = 0.77f; settings.m_rgbSpec[2] = 0.77f;
settings.m_singleSliderSpec = false;
} }
imguiEndScrollArea(); imguiEndScrollArea();
nvgEndFrame(nvg);
imguiEndFrame(); imguiEndFrame();
s_uniforms.m_glossiness = settings.m_glossiness; s_uniforms.m_glossiness = settings.m_glossiness;
@ -739,12 +723,14 @@ int _main_(int /*_argc*/, char** /*_argv*/)
bgfx::setViewRect(0, 0, 0, width, height); bgfx::setViewRect(0, 0, 0, width, height);
bgfx::setViewRect(1, 0, 0, width, height); bgfx::setViewRect(1, 0, 0, width, height);
bgfx::setViewRect(NANOVG_VIEWID, 0, 0, width, height);
// View 0. // View 0.
bgfx::setTexture(4, u_texCube, lightProbes[currentLightProbe].m_tex); bgfx::setTexture(4, u_texCube, lightProbes[currentLightProbe].m_tex);
bgfx::setProgram(programSky); bgfx::setProgram(programSky);
bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE);
screenSpaceQuad( (float)width, (float)height, true); screenSpaceQuad( (float)width, (float)height, true);
s_uniforms.submitPerDrawUniforms();
bgfx::submit(0); bgfx::submit(0);
// View 1. // View 1.
@ -782,11 +768,6 @@ int _main_(int /*_argc*/, char** /*_argv*/)
bgfx::destroyUniform(u_mtx); bgfx::destroyUniform(u_mtx);
bgfx::destroyUniform(u_time); bgfx::destroyUniform(u_time);
bgfx::destroyUniform(u_texRoughness);
bgfx::destroyUniform(u_texSpecular);
bgfx::destroyUniform(u_texNormal);
bgfx::destroyUniform(u_texAlbedo);
bgfx::destroyUniform(u_texCube); bgfx::destroyUniform(u_texCube);
bgfx::destroyUniform(u_texCubeIrr); bgfx::destroyUniform(u_texCubeIrr);
@ -797,6 +778,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
s_uniforms.destroy(); s_uniforms.destroy();
nvgDelete(nvg);
imguiDestroy(); imguiDestroy();
// Shutdown bgfx. // Shutdown bgfx.