Add more configs and implement weird power map thing

This commit is contained in:
Camden Dixie O'Brien 2025-01-18 22:24:46 +00:00
parent 9c903179cf
commit 6b593960b4
3 changed files with 56 additions and 26 deletions

View File

@ -44,7 +44,34 @@
//#define POWRATE 0.0001 //#define POWRATE 0.0001
//#define ZOOMRATE 0.0003 //#define ZOOMRATE 0.0003
// Complex power Mandelbrot // Cool tendril stuff (complex power)
//#define SS 4
//#define CPOW_DTHETA 0.000
//#define MAXMAG 100.0
//#define CENTRE_RE -0.84880415
//#define CENTRE_IM 0.03921157
//#define CPOW_START_RE 1.96550429
//#define CPOW_START_IM 0.36985874
//#define ZOOMRATE 0.01
// ??
//#define SS 4
//#define THING
//#define JULIA_C_RE -0.9999999506519784
//#define JULIA_C_IM 3.141592601914583e-4
//#define JULIA_DTHETA 0.00001
//#define MAXMAG 100.0
//#define STARTSCALE 4
//#define ZOOMRATE 0.01
// Funky complex power julia set
#define SS 4 #define SS 4
#define CPOW_DTHETA 0.01 #define JULIA
#define JULIA_C_RE -0.010
#define JULIA_C_IM 0.285
#define JULIA_DTHETA 0.0001
#define CPOW_START_RE 0.0
#define CPOW_START_IM 2.0
#define CPOW_DTHETA 0.0001
#define MAXMAG 100.0 #define MAXMAG 100.0
#define STARTSCALE 1

View File

@ -9,7 +9,7 @@
#define NCOLS 8 #define NCOLS 8
#ifndef CPOW_DTHETA #if !defined(CPOW_DTHETA) && !defined(THING)
#define MAXMAG 2.0 #define MAXMAG 2.0
#endif #endif
@ -17,7 +17,7 @@ layout(location = 0) out vec4 out_colour;
layout(push_constant) uniform Constants { layout(push_constant) uniform Constants {
vec2 img_size; vec2 img_size;
#ifdef JULIA #if defined(JULIA) || defined(THING)
vec2 julia; vec2 julia;
#endif #endif
vec2 centre; vec2 centre;
@ -68,7 +68,6 @@ vec2 maptoz(vec2 xy)
return params.scale * z + params.centre; return params.scale * z + params.centre;
} }
#ifdef CPOW_DTHETA
vec2 cmul(vec2 a, vec2 b) vec2 cmul(vec2 a, vec2 b)
{ {
return vec2(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); return vec2(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
@ -89,16 +88,13 @@ vec2 cpow(vec2 z, vec2 p)
if (z.x == 0.0 && z.y == 0.0) return vec2(0.0, 0.0); if (z.x == 0.0 && z.y == 0.0) return vec2(0.0, 0.0);
return cexp(cmul(p, cln(z))); return cexp(cmul(p, cln(z)));
} }
#else
vec2 zpow(vec2 z, float p) vec2 zpow(vec2 z, float p)
{ {
float r = length(z); float mag = pow(length(z), p);
float theta = atan(z.y, z.x); float arg = p * atan(z.y, z.x);
float mag = pow(r, p); return mag * vec2(cos(arg), sin(arg));
float phi = p * theta;
return mag * vec2(cos(phi), sin(phi));
} }
#endif
int fractal(vec2 c) { int fractal(vec2 c) {
#ifdef JULIA #ifdef JULIA
@ -112,6 +108,8 @@ int fractal(vec2 c) {
z = cpow(z, params.cpow) + c; z = cpow(z, params.cpow) + c;
#elif defined(POWRATE) #elif defined(POWRATE)
z = zpow(z, params.zpow) + c; z = zpow(z, params.zpow) + c;
#elif defined(THING)
z = cpow(z, c) + params.julia;
#else #else
z = vec2(z.x * z.x - z.y * z.y, 2.0 * z.x * z.y) + c; z = vec2(z.x * z.x - z.y * z.y, 2.0 * z.x * z.y) + c;
#endif #endif

13
main.c
View File

@ -31,9 +31,13 @@
#error "Cannot define CPOW_DTHETA and POWRATE simulataneously" #error "Cannot define CPOW_DTHETA and POWRATE simulataneously"
#endif #endif
#ifndef STARTSCALE
#define STARTSCALE 1.0
#endif
typedef struct { typedef struct {
float width, height; float width, height;
#ifdef JULIA #if defined(JULIA) || defined(THING)
struct { struct {
float re, im; float re, im;
} julia; } julia;
@ -61,7 +65,7 @@ static const char *extensions[] = {
// Initial parameters // Initial parameters
static params_t params = { static params_t params = {
#ifdef JULIA #if defined(JULIA) || defined(THING)
.julia = { .julia = {
#ifdef JULIA_C_RE #ifdef JULIA_C_RE
.re = JULIA_C_RE, .re = JULIA_C_RE,
@ -82,12 +86,12 @@ static params_t params = {
}, },
#endif #endif
#ifdef CPOW_DTHETA #ifdef CPOW_DTHETA
.cpow = { .re = 2.0, .im = 0.0 }, .cpow = { .re = CPOW_START_RE, .im = CPOW_START_IM },
#endif #endif
#ifdef POWRATE #ifdef POWRATE
.zpow = 2.0, .zpow = 2.0,
#endif #endif
.scale = 1.0, .scale = STARTSCALE,
}; };
static void static void
@ -599,6 +603,7 @@ int main(void)
vkCmdBeginRenderPass( vkCmdBeginRenderPass(
cmd_buf, &render_pass_begin, VK_SUBPASS_CONTENTS_INLINE); cmd_buf, &render_pass_begin, VK_SUBPASS_CONTENTS_INLINE);
// Send parameters
vkCmdPushConstants( vkCmdPushConstants(
cmd_buf, pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, cmd_buf, pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, 0,
sizeof(params), &params); sizeof(params), &params);