Adding debuggy visualizer, hoping to fix visual artefacts in the shader.
This commit is contained in:
@@ -122,6 +122,23 @@ public:
|
||||
/// Passes the current window size to subordinate objects, such as the JUI scene.
|
||||
void PropagateWindowSize();
|
||||
|
||||
Vector2 FractalSpaceToScreenSpace(const Vector2& pos) {
|
||||
Vector2 R(GetWidth(), GetHeight());
|
||||
Vector2 translation(u_translation.x, -u_translation.y);
|
||||
|
||||
return ((pos + u_translation) * R.y + R + Vector2(1.f, 1.f)) / u_scale;
|
||||
}
|
||||
|
||||
Vector2 ScreenSpaceToFractalSpace(const Vector2& pos) {
|
||||
Vector2 tpos = -pos;
|
||||
Vector2 R(GetWidth(), GetHeight());
|
||||
Vector2 scaled = pos * u_scale;
|
||||
Vector2 translation(u_translation.x, -u_translation.y);
|
||||
|
||||
Vector2 uv = ((scaled - R - Vector2(1.f, 1.f)) / R.y) - u_translation;
|
||||
return uv;
|
||||
}
|
||||
|
||||
void ZoomIn(float rate);
|
||||
|
||||
void ZoomInTowards(const Vector2 &dir, float rate);
|
||||
|
@@ -24,7 +24,7 @@ uniform vec3 u_rgb_3;
|
||||
uniform vec3 u_rgb_4;
|
||||
|
||||
#define N 256. // Number of iterations?
|
||||
#define B 4. // What does B mean?
|
||||
#define B 8. // What does B mean?
|
||||
|
||||
// The mandelbrot set is a set of complex numbers c for which the function:
|
||||
// f(z) = z*z + c
|
||||
@@ -38,8 +38,8 @@ float iterate_mandelbrot(vec2 p) {
|
||||
for (i=0.; i < N; i++ ) {
|
||||
// This line performs the core Mandelbrot iteration: z = z^2 + c.
|
||||
// It is done using a matrix multiplication to perform the complex number squaring.
|
||||
// If z = x + iy, then z&2 = (i+iy)(x+iy) = x^2 - y ^ 2 + 2ixy.
|
||||
// The matrix [x, -y; y, x] multiplied by [x, y] gives [x*x - y&y, y*x + x*y] = [Re(z^2) Im(z^2)].
|
||||
// If z = x + iy, then z&2 = (x+iy)(x+iy) = x^2 - y ^ 2 + 2ixy.
|
||||
// The matrix [x, -y; y, x] multiplied by [x, y] gives [x*x - y*y, y*x + x*y] = [Re(z^2) Im(z^2)].
|
||||
// Then we add the constant complex number c (represented by the input vec2).
|
||||
z = mat2(z, -z.y, z.x) * z + c;
|
||||
|
||||
|
@@ -256,8 +256,8 @@ void FractalInspectorApp::CreateMenu() {
|
||||
// TODO: Utilize for things later.
|
||||
colorpicker_window = new JUI::Window(scene);
|
||||
colorpicker_window->SetTitle("Color-Pickers");
|
||||
colorpicker_window->MinSize({600, 150});
|
||||
colorpicker_window->Size({600_px, 150_px});
|
||||
colorpicker_window->MinSize({300, 150});
|
||||
colorpicker_window->Size({400_px, 150_px});
|
||||
colorpicker_window->Position({50_px, 50_px});
|
||||
|
||||
auto* col_layout = new JUI::HorizontalListLayout(colorpicker_window->Content());
|
||||
@@ -541,6 +541,9 @@ void FractalInspectorApp::Update(float elapsed) {
|
||||
Math::Round(u_translation.x, 4), Math::Round(u_translation.y, 4), readable_scale, fps);
|
||||
|
||||
fps_label->SetContent(fps_text);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
float FractalInspectorApp::ReadableScale() {
|
||||
@@ -574,6 +577,16 @@ void FractalInspectorApp::UpdateShaderUniforms(float elapsed) {
|
||||
shader.SetVector2("u_translation", u_translation);
|
||||
}
|
||||
|
||||
Vector2 solve(Vector2 a, Vector2 b) {
|
||||
float real = (a.x*a.x) + (-1 * a.y*a.y);
|
||||
float imag = (a.x*a.y)*2;
|
||||
|
||||
real += b.x;
|
||||
imag += b.y;
|
||||
|
||||
return {real, imag};
|
||||
}
|
||||
|
||||
void FractalInspectorApp::Draw() {
|
||||
|
||||
Shader::UseDefault();
|
||||
@@ -588,6 +601,46 @@ void FractalInspectorApp::Draw() {
|
||||
J2D::DrawRenderTarget(canvas, {0, 0});
|
||||
J2D::End();
|
||||
|
||||
J2D::Begin();
|
||||
|
||||
const float N = 512.f;
|
||||
const float B = 2.f;
|
||||
|
||||
auto mpos_ipair = GetMouseCoordinates();
|
||||
Vector2 mpos (mpos_ipair.x, mpos_ipair.y);
|
||||
Vector2 R(GetWidth(), GetHeight());
|
||||
|
||||
|
||||
|
||||
Vector2 trans = Vector2(0, R.y) - u_translation;
|
||||
|
||||
Vector2 z = Vector2(0, 0);
|
||||
|
||||
Vector2 c = ScreenSpaceToFractalSpace(mpos);
|
||||
Vector2 last_z = c;
|
||||
|
||||
J2D::FillCircle(Colors::Red, FractalSpaceToScreenSpace(ScreenSpaceToFractalSpace(mpos)), 6);
|
||||
|
||||
|
||||
for (float i = 0.f; i < N; i++) {
|
||||
float x = z.x;
|
||||
float y = z.y;
|
||||
Vector2 z_nplus1 = Vector2(x*x - y*y, y*x + x*y) + c;
|
||||
|
||||
|
||||
J2D::DrawLine(Colors::White, FractalSpaceToScreenSpace(z), FractalSpaceToScreenSpace(last_z), 0.25);
|
||||
|
||||
last_z = z;
|
||||
z = z_nplus1;
|
||||
|
||||
|
||||
|
||||
|
||||
if (Vector2::Dot(z, z) > B*B) break;
|
||||
}
|
||||
//
|
||||
J2D::End();
|
||||
|
||||
scene->Draw();
|
||||
|
||||
JGL::J2D::Begin(canvas, true);
|
||||
|
Reference in New Issue
Block a user