Migrate ColorGrading to SimpleViewer.
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
#include <vector>
|
||||
|
||||
using namespace filagui;
|
||||
using namespace filament::math;
|
||||
|
||||
namespace filament {
|
||||
namespace viewer {
|
||||
@@ -54,6 +55,250 @@ filament::math::mat4f fitIntoUnitCube(const filament::Aabb& bounds) {
|
||||
return mat4f::scaling(float3(scaleFactor)) * mat4f::translation(-center);
|
||||
}
|
||||
|
||||
static void computeRangePlot(Settings& settings, float* rangePlot) {
|
||||
float4& ranges = settings.view.colorGrading.ranges;
|
||||
ranges.y = clamp(ranges.y, ranges.x + 1e-5f, ranges.w - 1e-5f); // darks
|
||||
ranges.z = clamp(ranges.z, ranges.x + 1e-5f, ranges.w - 1e-5f); // lights
|
||||
|
||||
for (size_t i = 0; i < 1024; i++) {
|
||||
float x = i / 1024.0f;
|
||||
float s = 1.0f - smoothstep(ranges.x, ranges.y, x);
|
||||
float h = smoothstep(ranges.z, ranges.w, x);
|
||||
rangePlot[i] = s;
|
||||
rangePlot[1024 + i] = 1.0f - s - h;
|
||||
rangePlot[2048 + i] = h;
|
||||
}
|
||||
}
|
||||
|
||||
static void rangePlotSeriesStart(int series) {
|
||||
switch (series) {
|
||||
case 0:
|
||||
ImGui::PushStyleColor(ImGuiCol_PlotLines, (ImVec4) ImColor::HSV(0.4f, 0.25f, 1.0f));
|
||||
break;
|
||||
case 1:
|
||||
ImGui::PushStyleColor(ImGuiCol_PlotLines, (ImVec4) ImColor::HSV(0.8f, 0.25f, 1.0f));
|
||||
break;
|
||||
case 2:
|
||||
ImGui::PushStyleColor(ImGuiCol_PlotLines, (ImVec4) ImColor::HSV(0.17f, 0.21f, 1.0f));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void rangePlotSeriesEnd(int series) {
|
||||
if (series < 3) {
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
}
|
||||
|
||||
static float getRangePlotValue(int series, void* data, int index) {
|
||||
return ((float*) data)[series * 1024 + index];
|
||||
}
|
||||
|
||||
inline float3 curves(float3 v, float3 shadowGamma, float3 midPoint, float3 highlightScale) {
|
||||
float3 d = 1.0f / (pow(midPoint, shadowGamma - 1.0f));
|
||||
float3 dark = pow(v, shadowGamma) * d;
|
||||
float3 light = highlightScale * (v - midPoint) + midPoint;
|
||||
return float3{
|
||||
v.r <= midPoint.r ? dark.r : light.r,
|
||||
v.g <= midPoint.g ? dark.g : light.g,
|
||||
v.b <= midPoint.b ? dark.b : light.b,
|
||||
};
|
||||
}
|
||||
|
||||
static void computeCurvePlot(Settings& settings, float* curvePlot) {
|
||||
const auto& colorGradingOptions = settings.view.colorGrading;
|
||||
for (size_t i = 0; i < 1024; i++) {
|
||||
float3 x{i / 1024.0f * 2.0f};
|
||||
float3 y = curves(x,
|
||||
colorGradingOptions.gamma,
|
||||
colorGradingOptions.midPoint,
|
||||
colorGradingOptions.scale);
|
||||
curvePlot[i] = y.r;
|
||||
curvePlot[1024 + i] = y.g;
|
||||
curvePlot[2048 + i] = y.b;
|
||||
}
|
||||
}
|
||||
|
||||
static void tooltipFloat(float value) {
|
||||
if (ImGui::IsItemActive() || ImGui::IsItemHovered()) {
|
||||
ImGui::SetTooltip("%.2f", value);
|
||||
}
|
||||
}
|
||||
|
||||
static void pushSliderColors(float hue) {
|
||||
ImGui::PushStyleColor(ImGuiCol_FrameBg, (ImVec4) ImColor::HSV(hue, 0.5f, 0.5f));
|
||||
ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, (ImVec4) ImColor::HSV(hue, 0.6f, 0.5f));
|
||||
ImGui::PushStyleColor(ImGuiCol_FrameBgActive, (ImVec4) ImColor::HSV(hue, 0.7f, 0.5f));
|
||||
ImGui::PushStyleColor(ImGuiCol_SliderGrab, (ImVec4) ImColor::HSV(hue, 0.9f, 0.9f));
|
||||
}
|
||||
|
||||
static void popSliderColors() { ImGui::PopStyleColor(4); }
|
||||
|
||||
static void colorGradingUI(Settings& settings, float* rangePlot, float* curvePlot) {
|
||||
const static ImVec2 verticalSliderSize(18.0f, 160.0f);
|
||||
const static ImVec2 plotLinesSize(260.0f, 160.0f);
|
||||
const static ImVec2 plotLinesWideSize(350.0f, 120.0f);
|
||||
|
||||
if (ImGui::CollapsingHeader("Color grading")) {
|
||||
ColorGradingSettings& colorGrading = settings.view.colorGrading;
|
||||
|
||||
ImGui::Indent();
|
||||
ImGui::Checkbox("Enabled##colorGrading", &colorGrading.enabled);
|
||||
|
||||
int quality = (int) colorGrading.quality;
|
||||
ImGui::Combo("Quality##colorGradingQuality", &quality, "Low\0Medium\0High\0Ultra\0\0");
|
||||
colorGrading.quality = (decltype(colorGrading.quality)) quality;
|
||||
|
||||
int toneMapping = (int) colorGrading.toneMapping;
|
||||
ImGui::Combo("Tone-mapping", &toneMapping,
|
||||
"Linear\0ACES (legacy)\0ACES\0Filmic\0Uchimura\0Reinhard\0Display Range\0\0");
|
||||
colorGrading.toneMapping = (decltype(colorGrading.toneMapping)) toneMapping;
|
||||
|
||||
if (ImGui::CollapsingHeader("White balance")) {
|
||||
int temperature = colorGrading.temperature * 100.0f;
|
||||
int tint = colorGrading.tint * 100.0f;
|
||||
ImGui::SliderInt("Temperature", &temperature, -100, 100);
|
||||
ImGui::SliderInt("Tint", &tint, -100, 100);
|
||||
colorGrading.temperature = temperature / 100.0f;
|
||||
colorGrading.tint = tint / 100.0f;
|
||||
}
|
||||
|
||||
if (ImGui::CollapsingHeader("Channel mixer")) {
|
||||
pushSliderColors(0.0f / 7.0f);
|
||||
ImGui::VSliderFloat("##outRed.r", verticalSliderSize, &colorGrading.outRed.r, -2.0f, 2.0f, "");
|
||||
tooltipFloat(colorGrading.outRed.r);
|
||||
ImGui::SameLine();
|
||||
ImGui::VSliderFloat("##outRed.g", verticalSliderSize, &colorGrading.outRed.g, -2.0f, 2.0f, "");
|
||||
tooltipFloat(colorGrading.outRed.g);
|
||||
ImGui::SameLine();
|
||||
ImGui::VSliderFloat("##outRed.b", verticalSliderSize, &colorGrading.outRed.b, -2.0f, 2.0f, "");
|
||||
tooltipFloat(colorGrading.outRed.b);
|
||||
ImGui::SameLine(0.0f, 18.0f);
|
||||
popSliderColors();
|
||||
|
||||
pushSliderColors(2.0f / 7.0f);
|
||||
ImGui::VSliderFloat("##outGreen.r", verticalSliderSize, &colorGrading.outGreen.r, -2.0f, 2.0f, "");
|
||||
tooltipFloat(colorGrading.outGreen.r);
|
||||
ImGui::SameLine();
|
||||
ImGui::VSliderFloat("##outGreen.g", verticalSliderSize, &colorGrading.outGreen.g, -2.0f, 2.0f, "");
|
||||
tooltipFloat(colorGrading.outGreen.g);
|
||||
ImGui::SameLine();
|
||||
ImGui::VSliderFloat("##outGreen.b", verticalSliderSize, &colorGrading.outGreen.b, -2.0f, 2.0f, "");
|
||||
tooltipFloat(colorGrading.outGreen.b);
|
||||
ImGui::SameLine(0.0f, 18.0f);
|
||||
popSliderColors();
|
||||
|
||||
pushSliderColors(4.0f / 7.0f);
|
||||
ImGui::VSliderFloat("##outBlue.r", verticalSliderSize, &colorGrading.outBlue.r, -2.0f, 2.0f, "");
|
||||
tooltipFloat(colorGrading.outBlue.r);
|
||||
ImGui::SameLine();
|
||||
ImGui::VSliderFloat("##outBlue.g", verticalSliderSize, &colorGrading.outBlue.g, -2.0f, 2.0f, "");
|
||||
tooltipFloat(colorGrading.outBlue.g);
|
||||
ImGui::SameLine();
|
||||
ImGui::VSliderFloat("##outBlue.b", verticalSliderSize, &colorGrading.outBlue.b, -2.0f, 2.0f, "");
|
||||
tooltipFloat(colorGrading.outBlue.b);
|
||||
popSliderColors();
|
||||
}
|
||||
if (ImGui::CollapsingHeader("Tonal ranges")) {
|
||||
ImGui::ColorEdit3("Shadows", &colorGrading.shadows.x);
|
||||
ImGui::SliderFloat("Weight##shadowsWeight", &colorGrading.shadows.w, -2.0f, 2.0f);
|
||||
ImGui::ColorEdit3("Mid-tones", &colorGrading.midtones.x);
|
||||
ImGui::SliderFloat("Weight##midTonesWeight", &colorGrading.midtones.w, -2.0f, 2.0f);
|
||||
ImGui::ColorEdit3("Highlights", &colorGrading.highlights.x);
|
||||
ImGui::SliderFloat("Weight##highlightsWeight", &colorGrading.highlights.w, -2.0f, 2.0f);
|
||||
ImGui::SliderFloat4("Ranges", &colorGrading.ranges.x, 0.0f, 1.0f);
|
||||
computeRangePlot(settings, rangePlot);
|
||||
ImGuiExt::PlotLinesSeries("", 3,
|
||||
rangePlotSeriesStart, getRangePlotValue, rangePlotSeriesEnd,
|
||||
rangePlot, 1024, 0, "", 0.0f, 1.0f, plotLinesWideSize);
|
||||
}
|
||||
if (ImGui::CollapsingHeader("Color decision list")) {
|
||||
ImGui::SliderFloat3("Slope", &colorGrading.slope.x, 0.0f, 2.0f);
|
||||
ImGui::SliderFloat3("Offset", &colorGrading.offset.x, -0.5f, 0.5f);
|
||||
ImGui::SliderFloat3("Power", &colorGrading.power.x, 0.0f, 2.0f);
|
||||
}
|
||||
if (ImGui::CollapsingHeader("Adjustments")) {
|
||||
ImGui::SliderFloat("Contrast", &colorGrading.contrast, 0.0f, 2.0f);
|
||||
ImGui::SliderFloat("Vibrance", &colorGrading.vibrance, 0.0f, 2.0f);
|
||||
ImGui::SliderFloat("Saturation", &colorGrading.saturation, 0.0f, 2.0f);
|
||||
}
|
||||
if (ImGui::CollapsingHeader("Curves")) {
|
||||
ImGui::Checkbox("Linked curves", &colorGrading.linkedCurves);
|
||||
|
||||
computeCurvePlot(settings, curvePlot);
|
||||
|
||||
if (!colorGrading.linkedCurves) {
|
||||
pushSliderColors(0.0f / 7.0f);
|
||||
ImGui::VSliderFloat("##curveGamma.r", verticalSliderSize, &colorGrading.gamma.r, 0.0f, 4.0f, "");
|
||||
tooltipFloat(colorGrading.gamma.r);
|
||||
ImGui::SameLine();
|
||||
ImGui::VSliderFloat("##curveMid.r", verticalSliderSize, &colorGrading.midPoint.r, 0.0f, 2.0f, "");
|
||||
tooltipFloat(colorGrading.midPoint.r);
|
||||
ImGui::SameLine();
|
||||
ImGui::VSliderFloat("##curveScale.r", verticalSliderSize, &colorGrading.scale.r, 0.0f, 4.0f, "");
|
||||
tooltipFloat(colorGrading.scale.r);
|
||||
ImGui::SameLine(0.0f, 18.0f);
|
||||
popSliderColors();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_PlotLines, (ImVec4) ImColor::HSV(0.0f, 0.7f, 0.8f));
|
||||
ImGui::PlotLines("", curvePlot, 1024, 0, "Red", 0.0f, 2.0f, plotLinesSize);
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
pushSliderColors(2.0f / 7.0f);
|
||||
ImGui::VSliderFloat("##curveGamma.g", verticalSliderSize, &colorGrading.gamma.g, 0.0f, 4.0f, "");
|
||||
tooltipFloat(colorGrading.gamma.g);
|
||||
ImGui::SameLine();
|
||||
ImGui::VSliderFloat("##curveMid.g", verticalSliderSize, &colorGrading.midPoint.g, 0.0f, 2.0f, "");
|
||||
tooltipFloat(colorGrading.midPoint.g);
|
||||
ImGui::SameLine();
|
||||
ImGui::VSliderFloat("##curveScale.g", verticalSliderSize, &colorGrading.scale.g, 0.0f, 4.0f, "");
|
||||
tooltipFloat(colorGrading.scale.g);
|
||||
ImGui::SameLine(0.0f, 18.0f);
|
||||
popSliderColors();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_PlotLines, (ImVec4) ImColor::HSV(0.3f, 0.7f, 0.8f));
|
||||
ImGui::PlotLines("", curvePlot + 1024, 1024, 0, "Green", 0.0f, 2.0f, plotLinesSize);
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
pushSliderColors(4.0f / 7.0f);
|
||||
ImGui::VSliderFloat("##curveGamma.b", verticalSliderSize, &colorGrading.gamma.b, 0.0f, 4.0f, "");
|
||||
tooltipFloat(colorGrading.gamma.b);
|
||||
ImGui::SameLine();
|
||||
ImGui::VSliderFloat("##curveMid.b", verticalSliderSize, &colorGrading.midPoint.b, 0.0f, 2.0f, "");
|
||||
tooltipFloat(colorGrading.midPoint.b);
|
||||
ImGui::SameLine();
|
||||
ImGui::VSliderFloat("##curveScale.b", verticalSliderSize, &colorGrading.scale.b, 0.0f, 4.0f, "");
|
||||
tooltipFloat(colorGrading.scale.b);
|
||||
ImGui::SameLine(0.0f, 18.0f);
|
||||
popSliderColors();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_PlotLines, (ImVec4) ImColor::HSV(0.6f, 0.7f, 0.8f));
|
||||
ImGui::PlotLines("", curvePlot + 2048, 1024, 0, "Blue", 0.0f, 2.0f, plotLinesSize);
|
||||
ImGui::PopStyleColor();
|
||||
} else {
|
||||
ImGui::VSliderFloat("##curveGamma", verticalSliderSize, &colorGrading.gamma.r, 0.0f, 4.0f, "");
|
||||
tooltipFloat(colorGrading.gamma.r);
|
||||
ImGui::SameLine();
|
||||
ImGui::VSliderFloat("##curveMid", verticalSliderSize, &colorGrading.midPoint.r, 0.0f, 2.0f, "");
|
||||
tooltipFloat(colorGrading.midPoint.r);
|
||||
ImGui::SameLine();
|
||||
ImGui::VSliderFloat("##curveScale", verticalSliderSize, &colorGrading.scale.r, 0.0f, 4.0f, "");
|
||||
tooltipFloat(colorGrading.scale.r);
|
||||
ImGui::SameLine(0.0f, 18.0f);
|
||||
|
||||
colorGrading.gamma = float3{colorGrading.gamma.r};
|
||||
colorGrading.midPoint = float3{colorGrading.midPoint.r};
|
||||
colorGrading.scale = float3{colorGrading.scale.r};
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_PlotLines, (ImVec4) ImColor::HSV(0.17f, 0.21f, 0.9f));
|
||||
ImGui::PlotLines("", curvePlot, 1024, 0, "RGB", 0.0f, 2.0f, plotLinesSize);
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
}
|
||||
ImGui::Unindent();
|
||||
}
|
||||
}
|
||||
|
||||
SimpleViewer::SimpleViewer(filament::Engine* engine, filament::Scene* scene, filament::View* view,
|
||||
int sidebarWidth) :
|
||||
mEngine(engine), mScene(scene), mView(view),
|
||||
@@ -413,6 +658,8 @@ void SimpleViewer::updateUserInterface() {
|
||||
ImGui::Unindent();
|
||||
}
|
||||
|
||||
colorGradingUI(mSettings, mRangePlot, mCurvePlot);
|
||||
|
||||
// At this point, all View settings have been modified,
|
||||
// so we can now push them into the Filament View.
|
||||
applySettings(mSettings.view, mView);
|
||||
|
||||
Reference in New Issue
Block a user