Skip to content

Commit 2f51b58

Browse files
committed
Scaling issue fix
1 parent eb6e22c commit 2f51b58

6 files changed

Lines changed: 42 additions & 48 deletions

File tree

devlog.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +0,0 @@
1-
The complex function plotter is done!
2-
3-
A little bit of personal lore here: I made another complex function plotter four years ago, when I was still in highschool. It was clunky, but worked fine enough. Still, I felt it missed some things, which led me to work on this project.
4-
Now, I have accomplished all things I have set out to do. Bugfixes aside, I believe I can put this project to rest now.
5-
6-
First, I worked on making the high precision plots reactive. They take a while to render, so having them shut down the main thread while the user waits on a blank screen isn't very fun. Now, each thread updates the canvas for every pixel they render. This allows the user to see the progress being made!
7-
Also, some reconfigurations were needed in the web version, since the browser needs special permissions to run Web Workers (the equivalent to threads for browsers)
8-
9-
Then, some quality of life changes: I added an amortization factor so the graph takes longer to converge to white (and black), and fixed a parsing mistake one of my beta testers caught.
10-
11-
Finally, documentation and benchmarking! I could always tell this tool was _fast_, but never _how fast_. I took upon myself to benchmark my own tool, and some other project's (since they are opensource, I can manually modify the code to do so). The result were great: this project outperforms everything else by a factor of 50.
12-
13-
And that's it for now folks!
14-
15-
Attached, our high precision plotting in real time!
16-
17-
**Commits**
18-
[9dd1515](https://url.jam06452.uk/3yqc6h): Async image generation
19-
[4266aaa](https://url.jam06452.uk/c71kuv): Add threading for web version
20-
[ded05c1](https://url.jam06452.uk/gvwf7p): Update documentation and perform benchmarking
21-
[2e32e99](https://url.jam06452.uk/zgmyyg): Fixed issue where expressions with negations would be evaluated incorrectly
22-
[2e10128](https://url.jam06452.uk/1rzb8g3): Fixed issue where moving the screen would cause the high precision plot to shift as well.

src/graphics/ui.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,11 @@ void render_and_update(FunctionState& state, ViewState& view_state, unsigned int
440440
ImGui::EndPopup();
441441
}
442442
}
443+
ImVec2 main_pos = ImGui::GetWindowPos();
444+
ImVec2 main_size = ImGui::GetWindowSize();
445+
ImVec2 side_spawn_pos = ImVec2(main_pos.x + main_size.x + 15.0f, main_pos.y);
443446
if (view_state.is_high_precision) {
447+
ImGui::SetNextWindowPos(side_spawn_pos, ImGuiCond_Appearing);
444448
ImGui::Begin("High Precision Render", &view_state.is_high_precision, ImGuiWindowFlags_AlwaysAutoResize);
445449
if (view_state.hp_texture != 0) {
446450
ImGui::Text("Resolution: %dx%d", view_state.hp_width, view_state.hp_height);
@@ -468,10 +472,12 @@ void render_and_update(FunctionState& state, ViewState& view_state, unsigned int
468472
else {
469473
ImGui::Text("Initializing...");
470474
}
475+
side_spawn_pos.y += ImGui::GetWindowSize().y + 15.0f;
471476
ImGui::End();
472477
}
473478
if (view_state.is_3d) {
474-
ImGui::Begin("3D Settings");
479+
ImGui::SetNextWindowPos(side_spawn_pos, ImGuiCond_Appearing);
480+
ImGui::Begin("3D Settings",nullptr, ImGuiWindowFlags_AlwaysAutoResize);
475481
ImGui::Text("Height = ");
476482
if (ImGui::IsItemHovered()) ImGui::SetTooltip("Height function. 'z' evaluates on the output of f(z). Defaults to mag(z).");
477483
ImGui::SameLine();
@@ -491,7 +497,7 @@ void render_and_update(FunctionState& state, ViewState& view_state, unsigned int
491497
state.needs_height_reparse = true;
492498
}
493499
ImGui::Spacing();
494-
if (UI::CollapsingHeader("Camera Settings"), nullptr, ImGuiWindowFlags_AlwaysAutoResize) {
500+
if (UI::CollapsingHeader("Camera Settings")) {
495501
ImGui::Text("Camera Mode:");
496502
ImGui::SameLine();
497503

src/graphics/ui_init.cpp

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,35 @@
1111

1212

1313
void init_imgui(GLFWwindow* window) {
14-
IMGUI_CHECKVERSION();
15-
ImGui::CreateContext();
16-
ImGuiIO& io = ImGui::GetIO();
17-
io.FontGlobalScale = 2.0f;
18-
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
19-
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
20-
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
21-
ImGui_ImplGlfw_InitForOpenGL(window, true);
14+
IMGUI_CHECKVERSION();
15+
ImGui::CreateContext();
16+
ImGuiIO& io = ImGui::GetIO();
17+
float xscale = 1.0f;
18+
float yscale = 1.0f;
19+
2220
#ifdef __EMSCRIPTEN__
21+
xscale = emscripten_get_device_pixel_ratio();
22+
#else
23+
glfwGetWindowContentScale(window, &xscale, &yscale);
24+
#endif
25+
io.FontGlobalScale = xscale;
2326

24-
emscripten_browser_clipboard::paste([](std::string&& paste_data, void* callback_data) {
25-
clip_content = std::move(paste_data);
26-
just_pasted = true;
27-
}, nullptr);
28-
29-
ImGui_ImplOpenGL3_Init("#version 300 es");
27+
//ImGui::GetStyle().ScaleAllSizes(xscale);
28+
29+
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
30+
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
31+
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
32+
ImGui_ImplGlfw_InitForOpenGL(window, true);
33+
34+
#ifdef __EMSCRIPTEN__
35+
emscripten_browser_clipboard::paste([](std::string&& paste_data, void* callback_data) {
36+
clip_content = std::move(paste_data);
37+
just_pasted = true;
38+
}, nullptr);
39+
40+
ImGui_ImplOpenGL3_Init("#version 300 es");
3041
#else
31-
ImGui_ImplOpenGL3_Init();
42+
ImGui_ImplOpenGL3_Init();
3243
#endif
3344
}
3445

src/index.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ <h2>Loading...</h2>
7777
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
7878
console.error(text);
7979
},
80-
setCanvasSize: function(width, height, noRepaint) {
81-
const dpr = window.devicePixelRatio || 1;
82-
this.canvas.width = width * dpr;
83-
this.canvas.height = height * dpr;
84-
},
8580
onRuntimeInitialized: function() {
8681
document.getElementById('loading-overlay').style.display = 'none';
8782
canvas.focus();

src/shaders/embedded_shaders.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ uniform float time;
356356
uniform bool show_grid;
357357
uniform bool warp_grid;
358358
359+
const float gamma_correction_constant = 0.65;
360+
359361
#define END_UNIFORM_DECLARATIONS HERE
360362
361363
#define FUNCTION_DEFINITIONS HERE
@@ -681,13 +683,13 @@ void main(){
681683
vec2 z = convert_coordinates(gl_FragCoord.xy,u_resolution,u_range) + shift;
682684
683685
#define INTERPRETER_ASSIGNEMENT HERE
684-
vec2 func_value = run_stack(operator_stack,constant_stack,z);
685-
func_value = clamp(func)shdr" R"shdr(_value, -1e38, 1e38);
686+
vec2 func_value = run_stack(operator_stack)shdr" R"shdr(,constant_stack,z);
687+
func_value = clamp(func_value, -1e38, 1e38);
686688
#define END_INTERPRETER_ASSIGNEMENT HERE
687689
688690
#define INJECTION_POINT HERE
689691
690-
vec3 hsl = domain_color(func_value,0.5);
692+
vec3 hsl = domain_color(func_value,gamma_correction_constant);
691693
692694
if(show_grid){
693695
vec2 target = z;

src/shaders/plotter.frag

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ uniform float time;
4040
uniform bool show_grid;
4141
uniform bool warp_grid;
4242

43+
const float gamma_correction_constant = 0.65;
44+
4345
#define END_UNIFORM_DECLARATIONS HERE
4446

4547
#define FUNCTION_DEFINITIONS HERE
@@ -371,7 +373,7 @@ void main(){
371373

372374
#define INJECTION_POINT HERE
373375

374-
vec3 hsl = domain_color(func_value,0.5);
376+
vec3 hsl = domain_color(func_value,gamma_correction_constant);
375377

376378
if(show_grid){
377379
vec2 target = z;

0 commit comments

Comments
 (0)