Skip to content

Commit fae6ce0

Browse files
committed
Added grid warping
1 parent 925f383 commit fae6ce0

6 files changed

Lines changed: 25 additions & 6 deletions

File tree

‎src/graphics/ui.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ void render_and_update(FunctionState& state, ViewState& view_state, unsigned int
189189
ImGui::Unindent();
190190
}
191191
ImGui::Checkbox("Show Grid", &view_state.show_grid);
192+
if (view_state.show_grid) {
193+
ImGui::Indent();
194+
ImGui::Checkbox("Warp Grid", &view_state.warp_grid);
195+
if (ImGui::IsItemHovered())
196+
ImGui::SetTooltip("This maps the grid to f(z), which shows how the functions warps space.");
197+
ImGui::Unindent();
198+
}
192199
}
193200

194201
if (ImGui::CollapsingHeader("3D Keybinds")) {

‎src/interactions/interactions.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ typedef struct ViewState {
1414
bool show_inspector = true;
1515
bool inspector_follows_mouse = true;
1616
bool show_grid = true;
17+
bool warp_grid = false;
1718
} ViewState;
1819

1920

‎src/main.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ int main() {
140140
current_shader->setVec2("shift", view_state.shift);
141141
current_shader->setVec2("u_resolution", glm::vec2(view_state.width,view_state.height));
142142
current_shader->setBool("show_grid", view_state.show_grid);
143+
current_shader->setBool("warp_grid", view_state.warp_grid);
143144
if (function_state.is_interpreted) {
144145
glActiveTexture(GL_TEXTURE0);
145146
glBindTexture(GL_TEXTURE_BUFFER, stack_tbo_texture);

‎src/shaders/embedded_shaders.h‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ uniform float u_range;
6060
uniform vec2 shift;
6161
uniform float time;
6262
uniform bool show_grid;
63+
uniform bool warp_grid;
6364
6465
#define END_UNIFORM_DECLARATIONS HERE
6566
@@ -292,16 +293,18 @@ void main(){
292293
vec3 hsl = domain_color(func_value);
293294
294295
if(show_grid){
296+
vec2 target = z;
297+
if(warp_grid) target = func_value;
295298
const float axis_width = 1.5f;
296299
const float grid_width = 1.0f;
297300
298-
vec2 df = fwidth(z);
301+
vec2 df = fwidth(target);
299302
300-
vec2 grid_dist = abs(fract(z+0.5f)-0.5f);
303+
vec2 grid_dist = abs(fract(target+0.5f)-0.5f);
301304
vec2 grid_px = grid_dist/df;
302305
float grid_val = min(grid_px.x,grid_px.y);
303306
304-
vec2 axis_px = abs(z) / df;
307+
vec2 axis_px = abs(target) / df;
305308
float axis_val = min(axis_px.x, axis_px.y);
306309
307310
float grid_alpha = 1.0 - smoothstep(0.0, grid_width, grid_val);
@@ -334,6 +337,8 @@ in vec2 f_z;
334337
out vec4 FragColor;
335338
336339
uniform bool show_grid;
340+
uniform bool warp_grid;
341+
337342
338343
const float PI = 3.14159265359;
339344
const float TWO_OVER_PI = 2.0 / PI;

‎src/shaders/plotter.frag‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ uniform float u_range;
2626
uniform vec2 shift;
2727
uniform float time;
2828
uniform bool show_grid;
29+
uniform bool warp_grid;
2930

3031
#define END_UNIFORM_DECLARATIONS HERE
3132

@@ -258,16 +259,18 @@ void main(){
258259
vec3 hsl = domain_color(func_value);
259260

260261
if(show_grid){
262+
vec2 target = z;
263+
if(warp_grid) target = func_value;
261264
const float axis_width = 1.5f;
262265
const float grid_width = 1.0f;
263266

264-
vec2 df = fwidth(z);
267+
vec2 df = fwidth(target);
265268

266-
vec2 grid_dist = abs(fract(z+0.5f)-0.5f);
269+
vec2 grid_dist = abs(fract(target+0.5f)-0.5f);
267270
vec2 grid_px = grid_dist/df;
268271
float grid_val = min(grid_px.x,grid_px.y);
269272

270-
vec2 axis_px = abs(z) / df;
273+
vec2 axis_px = abs(target) / df;
271274
float axis_val = min(axis_px.x, axis_px.y);
272275

273276
float grid_alpha = 1.0 - smoothstep(0.0, grid_width, grid_val);

‎src/shaders/plotter3d.frag‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ in vec2 f_z;
44
out vec4 FragColor;
55

66
uniform bool show_grid;
7+
uniform bool warp_grid;
8+
79

810
const float PI = 3.14159265359;
911
const float TWO_OVER_PI = 2.0 / PI;

0 commit comments

Comments
 (0)