BugFix WhiteBalance Display View and Rendering window

Use of Settings whitebalance parameters for rendering both window and display preview window. Not most optimal maybe, but efficient and clear.
This commit is contained in:
Bruno Herbelin
2023-03-02 23:30:17 +01:00
parent 6e3497e4c4
commit 0defff8f7c
5 changed files with 31 additions and 56 deletions

View File

@@ -44,6 +44,8 @@
#define WINDOW_TITLEBAR_HEIGHT 0.03f #define WINDOW_TITLEBAR_HEIGHT 0.03f
FilteringProgram _whitebalance("Whitebalance", "shaders/filters/whitebalance.glsl", "", { { "Red", 1.0}, { "Green", 1.0}, { "Blue", 1.0}, { "Temperature", 0.5} });
DisplaysView::DisplaysView() : View(DISPLAYS) DisplaysView::DisplaysView() : View(DISPLAYS)
{ {
@@ -68,7 +70,9 @@ DisplaysView::DisplaysView() : View(DISPLAYS)
// surface background and texture // surface background and texture
w->surface_ = new Surface; w->surface_ = new Surface;
w->root_->attach(w->surface_); w->root_->attach(w->surface_);
w->render_ = new Surface; w->shader_ = new ImageFilteringShader;
w->shader_->setCode( _whitebalance.code().first );
w->render_ = new Surface(w->shader_);
w->root_->attach(w->render_); w->root_->attach(w->render_);
// icon if disabled // icon if disabled
w->icon_ = new Handles(Handles::EYESLASHED); w->icon_ = new Handles(Handles::EYESLASHED);
@@ -233,7 +237,7 @@ void DisplaysView::draw()
if (windows_[i].render_->visible_) { if (windows_[i].render_->visible_) {
// rendering of framebuffer in window // rendering of framebuffer in window
if (Settings::application.windows[1].scaled) { if (Settings::application.windows[i+1].scaled) {
windows_[i].render_->scale_ = glm::vec3(1.f, 1.f, 1.f); windows_[i].render_->scale_ = glm::vec3(1.f, 1.f, 1.f);
} }
else { else {
@@ -243,6 +247,12 @@ void DisplaysView::draw()
else else
windows_[i].render_->scale_ = glm::vec3(1.f, out_ar / output_ar, 1.f); windows_[i].render_->scale_ = glm::vec3(1.f, out_ar / output_ar, 1.f);
} }
if (windows_[i].shader_) {
windows_[i].shader_->uniforms_["Red"] = Settings::application.windows[i+1].whitebalance.x;
windows_[i].shader_->uniforms_["Green"] = Settings::application.windows[i+1].whitebalance.y;
windows_[i].shader_->uniforms_["Blue"] = Settings::application.windows[i+1].whitebalance.z;
windows_[i].shader_->uniforms_["Temperature"] = Settings::application.windows[i+1].whitebalance.w;
}
} }
// update overlay // update overlay
@@ -379,7 +389,6 @@ void DisplaysView::draw()
if (ImGuiToolkit::IconButton(18, 4, "More windows")) { if (ImGuiToolkit::IconButton(18, 4, "More windows")) {
++Settings::application.num_output_windows; ++Settings::application.num_output_windows;
current_window_ = Settings::application.num_output_windows-1; current_window_ = Settings::application.num_output_windows-1;
Settings::application.windows[1+current_window_].whitebalance = Rendering::manager().outputWindow(current_window_).whiteBalance();
} }
} }
else else
@@ -437,9 +446,6 @@ void DisplaysView::draw()
Settings::application.windows[1+current_window_].whitebalance.x = std::get<0>(c); Settings::application.windows[1+current_window_].whitebalance.x = std::get<0>(c);
Settings::application.windows[1+current_window_].whitebalance.y = std::get<1>(c); Settings::application.windows[1+current_window_].whitebalance.y = std::get<1>(c);
Settings::application.windows[1+current_window_].whitebalance.z = std::get<2>(c); Settings::application.windows[1+current_window_].whitebalance.z = std::get<2>(c);
// set White Balance Color matrix to shader
Rendering::manager().outputWindow(current_window_).setWhiteBalance( Settings::application.windows[1+current_window_].whitebalance );
} }
// White ballance temperature // White ballance temperature
@@ -451,10 +457,7 @@ void DisplaysView::draw()
{ {
ImGuiToolkit::PushFont(ImGuiToolkit::FONT_DEFAULT); ImGuiToolkit::PushFont(ImGuiToolkit::FONT_DEFAULT);
ImGuiToolkit::Indication("9000 K", " " ICON_FA_THERMOMETER_FULL); ImGuiToolkit::Indication("9000 K", " " ICON_FA_THERMOMETER_FULL);
if ( ImGui::VSliderFloat("##Temperature", ImVec2(30,260), &Settings::application.windows[1+current_window_].whitebalance.w, 0.0, 1.0, "") ){ ImGui::VSliderFloat("##Temperature", ImVec2(30,260), &Settings::application.windows[1+current_window_].whitebalance.w, 0.0, 1.0, "");
Rendering::manager().outputWindow(current_window_).setWhiteBalance( Settings::application.windows[1+current_window_].whitebalance );
}
if (ImGui::IsItemHovered() || ImGui::IsItemActive() ) { if (ImGui::IsItemHovered() || ImGui::IsItemActive() ) {
ImGui::BeginTooltip(); ImGui::BeginTooltip();
ImGui::Text("%d K", 4000 + (int) ceil(Settings::application.windows[1+current_window_].whitebalance.w * 5000.f)); ImGui::Text("%d K", 4000 + (int) ceil(Settings::application.windows[1+current_window_].whitebalance.w * 5000.f));
@@ -552,7 +555,9 @@ void DisplaysView::draw()
rect.p = Mixer::manager().session()->frame()->width(); rect.p = Mixer::manager().session()->frame()->width();
rect.q = Mixer::manager().session()->frame()->height(); rect.q = Mixer::manager().session()->frame()->height();
Rendering::manager().outputWindow(current_window_).setDecoration(true); Rendering::manager().outputWindow(current_window_).setDecoration(true);
Rendering::manager().outputWindow(current_window_).setWhiteBalance( glm::vec4(1.f, 1.f, 1.f, 0.5f) ); Settings::application.windows[1+current_window_].show_pattern = false;
Settings::application.windows[1+current_window_].scaled = false;
Settings::application.windows[1+current_window_].whitebalance = glm::vec4(1.f, 1.f, 1.f, 0.5f);
if (Settings::application.windows[current_window_+1].fullscreen) if (Settings::application.windows[current_window_+1].fullscreen)
Rendering::manager().outputWindow(current_window_).exitFullscreen(); Rendering::manager().outputWindow(current_window_).exitFullscreen();
else else

View File

@@ -9,6 +9,7 @@ struct WindowPreview
Group *status_; Group *status_;
Surface *surface_; Surface *surface_;
Surface *render_; Surface *render_;
ImageFilteringShader *shader_;
Switch *overlays_; Switch *overlays_;
Switch *mode_; Switch *mode_;
Handles *handles_; Handles *handles_;

View File

@@ -1092,32 +1092,6 @@ void RenderingWindow::swap()
FilteringProgram whitebalance("Whitebalance", "shaders/filters/whitebalance.glsl", "", { { "Red", 1.0}, { "Green", 1.0}, { "Blue", 1.0}, { "Temperature", 0.5} }); FilteringProgram whitebalance("Whitebalance", "shaders/filters/whitebalance.glsl", "", { { "Red", 1.0}, { "Green", 1.0}, { "Blue", 1.0}, { "Temperature", 0.5} });
void RenderingWindow::setWhiteBalance(glm::vec4 colorcorrection)
{
if (shader_)
shader_->uniforms_ = std::map< std::string, float >{
{ "Red", colorcorrection.x},
{ "Green", colorcorrection.y},
{ "Blue", colorcorrection.z},
{ "Temperature", colorcorrection.w}
};
}
glm::vec4 RenderingWindow::whiteBalance() const
{
glm::vec4 ret(1.f, 1.f, 1.f, 0.5f);
if (shader_) {
ret.x = shader_->uniforms_["Red"];
ret.y = shader_->uniforms_["Green"];
ret.z = shader_->uniforms_["Blue"];
ret.w = shader_->uniforms_["Temperature"];
}
return ret;
}
bool RenderingWindow::draw(FrameBuffer *fb) bool RenderingWindow::draw(FrameBuffer *fb)
{ {
// cannot draw if there is no window or invalid framebuffer // cannot draw if there is no window or invalid framebuffer
@@ -1150,14 +1124,19 @@ bool RenderingWindow::draw(FrameBuffer *fb)
// VAO is not shared between multiple contexts of different windows // VAO is not shared between multiple contexts of different windows
// so we have to create a new VAO for rendering the surface in this window // so we have to create a new VAO for rendering the surface in this window
if (surface_ == nullptr) { if (surface_ == nullptr) {
// create shader that performs white balance correction
const std::pair<std::string, std::string> codes = whitebalance.code();
shader_ = new ImageFilteringShader; shader_ = new ImageFilteringShader;
shader_->setCode( codes.first ); shader_->setCode( whitebalance.code().first );
shader_->uniforms_ = whitebalance.parameters(); // create surface using the shader
surface_ = new WindowSurface(shader_); surface_ = new WindowSurface(shader_);
} }
// update values of the shader
if (shader_) {
shader_->uniforms_["Red"] = Settings::application.windows[index_].whitebalance.x;
shader_->uniforms_["Green"] = Settings::application.windows[index_].whitebalance.y;
shader_->uniforms_["Blue"] = Settings::application.windows[index_].whitebalance.z;
shader_->uniforms_["Temperature"] = Settings::application.windows[index_].whitebalance.w;
}
// calculate scaling factor of frame buffer inside window // calculate scaling factor of frame buffer inside window
const float windowAspectRatio = aspectRatio(); const float windowAspectRatio = aspectRatio();

View File

@@ -79,13 +79,9 @@ public:
// get monitor in which the window is // get monitor in which the window is
GLFWmonitor *monitor(); GLFWmonitor *monitor();
// set geometry and decoration // set geometry, color correction and decoration
void setCoordinates(glm::ivec4 rect); void setCoordinates (glm::ivec4 rect);
void setDecoration (bool on); void setDecoration (bool on);
// set color correction
void setWhiteBalance(glm::vec4 colorcorrection);
glm::vec4 whiteBalance() const;
// get width of rendering area // get width of rendering area
int width(); int width();

View File

@@ -330,7 +330,7 @@ struct Application
show_tooptips = true; show_tooptips = true;
accept_connections = false; accept_connections = false;
stream_protocol = 0; stream_protocol = 0;
broadcast_port = 0; broadcast_port = 7070;
recentSRT.protocol = "srt://"; recentSRT.protocol = "srt://";
recentSRT.default_host = { "127.0.0.1", "7070"}; recentSRT.default_host = { "127.0.0.1", "7070"};
loopback_camera = 0; loopback_camera = 0;
@@ -343,12 +343,6 @@ struct Application
windows = std::vector<WindowConfig>(1+MAX_OUTPUT_WINDOW); windows = std::vector<WindowConfig>(1+MAX_OUTPUT_WINDOW);
windows[0].w = 1600; windows[0].w = 1600;
windows[0].h = 900; windows[0].h = 900;
windows[1].w = 1270;
windows[1].h = 720;
windows[2].w = 1270;
windows[2].h = 720;
windows[3].w = 1270;
windows[3].h = 720;
} }
}; };