Cogs.Core
GammaDebugger.cpp
1#include "Inspectors.h"
2
3#include "InspectorGuiHelper.h"
4
5#include "imgui.h"
6
7namespace{
8 float ConvertLinear(float C_srgb)
9 {
10 if(C_srgb <= 0.04045f){
11 return (1.0f/12.92f) * C_srgb;
12 }
13 else{
14 return pow((C_srgb + 0.055f)/1.055f, 2.4f);
15 }
16 }
17 float ConvertSRGB(float C_linear)
18 {
19 if(C_linear < 0.0031308f){
20 return 12.92f * C_linear;
21 }
22 else{
23 return 1.055f * pow(C_linear, (1.0f/2.4f)) - 0.055f;
24 }
25 }
26}
27
28namespace Cogs::Core {
29 void gammaDebugger(class Context* /*context*/, bool* show)
30 {
31 if (*show == false) return;
32 guiBegin("Gamma Debugger", show);
33
34 ImDrawList *draw_list = ImGui::GetWindowDrawList();
35
36 ImGui::Text("Gamma Correct");
37
38 static int test_col = (int)(ConvertSRGB(0.5f)*255);
39
40 {
41 ImVec2 c = ImGui::GetCursorScreenPos();
42 c.x = ceil(c.x);
43 c.y = ceil(c.y);
44 draw_list->AddRectFilled(c, c+ImVec2(200, 200), IM_COL32(0, 0, 0, 255));
45 for(int i=0; i<200; i++){
46 for(int j=0; j<200; j++){
47 if((i&1) != (j&1)) {
48 ImVec2 p = ImVec2((float)i, (float)j);
49 draw_list->AddRectFilled(c+p, c+p+ImVec2(1, 1), IM_COL32(255, 255, 255, 255));
50 }
51 }
52 }
53 }
54 ImGui::Dummy(ImVec2(200, 200));
55
56 ImGui::SameLine(0.0f, 0.0f);
57
58 {
59 ImVec2 c = ImGui::GetCursorScreenPos();
60 draw_list->AddRectFilled(c, c+ImVec2(200, 200), IM_COL32(test_col, test_col, test_col, 255));
61 }
62 ImGui::Dummy(ImVec2(200, 200));
63
64 ImGui::SliderInt("Test Color", &test_col, 0, 255);
65
66 float sRGB = (float)test_col/255.0f;
67 float linear = ConvertLinear(sRGB);
68 ImGui::Text("sRGB: %f Linear: %f", sRGB, linear);
69
70 guiEnd();
71 }
72}
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
@ sRGB
Value is a color and is subject to gamma correction.