Compare commits
2 Commits
e46df574d4
...
96659f96a6
Author | SHA1 | Date |
---|---|---|
Sylvain PILLOT | 96659f96a6 | |
Sylvain PILLOT | d0100044fa |
|
@ -2,7 +2,7 @@
|
|||
# toolchain file and module path of the fxSDK
|
||||
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
project(Schmup VERSION 1.0 LANGUAGES CXX C ASM)
|
||||
project(MandAzur VERSION 1.0 LANGUAGES CXX C ASM)
|
||||
|
||||
include(GenerateG3A)
|
||||
include(Fxconv)
|
||||
|
@ -15,6 +15,7 @@ set(SOURCES
|
|||
src/main.cpp
|
||||
src/mandelbrot.s
|
||||
src/mandelbrotshader.cpp
|
||||
src/juliashader.cpp
|
||||
src/utilities.cpp
|
||||
# ...
|
||||
)
|
||||
|
@ -25,12 +26,12 @@ set(ASSETS_cg
|
|||
|
||||
fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} WITH_METADATA)
|
||||
|
||||
add_executable(shmup ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}})
|
||||
target_compile_options(shmup PRIVATE -Wall -Wextra -Os -std=c++20)
|
||||
target_link_options(shmup PRIVATE -Wl,-Map=Build_Addin.map -Wl,--print-memory-usage -fpermissive)
|
||||
target_link_libraries(shmup Azur::Azur -lnum LibProf::LibProf Gint::Gint -lstdc++)
|
||||
add_executable(mandazur ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}})
|
||||
target_compile_options(mandazur PRIVATE -Wall -Wextra -Os -std=c++20)
|
||||
target_link_options(mandazur PRIVATE -Wl,-Map=Build_Addin.map -Wl,--print-memory-usage -fpermissive)
|
||||
target_link_libraries(mandazur Azur::Azur -lnum LibProf::LibProf Gint::Gint -lstdc++)
|
||||
|
||||
if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50)
|
||||
generate_g3a(TARGET shmup OUTPUT "MandAzur.g3a"
|
||||
generate_g3a(TARGET mandazur OUTPUT "MandAzur.g3a"
|
||||
NAME " " ICONS assets-cg/icon-uns.png assets-cg/icon-sel.png)
|
||||
endif()
|
||||
|
|
|
@ -6,4 +6,9 @@ void azrp_mandelbrot_init( void );
|
|||
void azrp_mandelbrot_close( void );
|
||||
void azrp_mandelbrot_USBDEBUG( void );
|
||||
|
||||
void azrp_julia( void );
|
||||
void azrp_julia_init( void );
|
||||
void azrp_julia_close( void );
|
||||
void azrp_julia_USBDEBUG( void );
|
||||
|
||||
#endif //MYAZURSHADERS_H
|
|
@ -0,0 +1,174 @@
|
|||
#include <azur/gint/render.h>
|
||||
#include "fractalshaders.h"
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
|
||||
#include <gint/rtc.h>
|
||||
#include <gint/usb.h>
|
||||
#include <gint/usb-ff-bulk.h>
|
||||
|
||||
#include <num/num.h>
|
||||
|
||||
|
||||
|
||||
uint8_t AZRP_SHADER_JULIA = -1;
|
||||
|
||||
|
||||
__attribute__((constructor))
|
||||
static void register_shader(void)
|
||||
{
|
||||
extern azrp_shader_t azrp_shader_julia;
|
||||
AZRP_SHADER_JULIA = azrp_register_shader(azrp_shader_julia);
|
||||
}
|
||||
|
||||
|
||||
void azrp_shader_julia_configure(void)
|
||||
{
|
||||
azrp_set_uniforms(AZRP_SHADER_JULIA, (void *)azrp_width);
|
||||
}
|
||||
|
||||
|
||||
void azrp_julia_USBDEBUG( void )
|
||||
{
|
||||
char texttosend[1024];
|
||||
|
||||
sprintf( texttosend, "data" );
|
||||
usb_fxlink_text(texttosend, 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void azrp_julia_init( )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void azrp_julia_close( void )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
struct command {
|
||||
uint8_t shader_id;
|
||||
uint8_t current_frag;
|
||||
libnum::num xmin;
|
||||
libnum::num xmax;
|
||||
libnum::num ymin;
|
||||
libnum::num ymax;
|
||||
libnum::num xinc;
|
||||
libnum::num yinc;
|
||||
};
|
||||
|
||||
|
||||
void azrp_julia( void )
|
||||
{
|
||||
prof_enter(azrp_perf_cmdgen);
|
||||
|
||||
struct command cmd;
|
||||
|
||||
cmd.shader_id = AZRP_SHADER_JULIA;
|
||||
cmd.current_frag = 0;
|
||||
cmd.xmin = libnum::num(-1.98f);
|
||||
cmd.xmax = libnum::num(1.98f);
|
||||
cmd.ymin = libnum::num(-1.12f);
|
||||
cmd.ymax = libnum::num(1.12f);
|
||||
cmd.xinc = libnum::num((2*1.98f)/azrp_width);
|
||||
cmd.yinc = libnum::num((2*1.12f)/azrp_height);
|
||||
int fragmin = 0;
|
||||
int fragcount = (azrp_height >> 4) + 1;
|
||||
|
||||
azrp_queue_command(&cmd, sizeof cmd, fragmin, fragcount);
|
||||
prof_leave(azrp_perf_cmdgen);
|
||||
}
|
||||
|
||||
|
||||
void azrp_shader_julia( void *uniforms, void *comnd, void *fragment )
|
||||
{
|
||||
struct command *cmd = (struct command *) comnd;
|
||||
uint16_t *frag = (uint16_t *) fragment;
|
||||
|
||||
int maxiter = 256;
|
||||
|
||||
libnum::num zr, zr2;
|
||||
libnum::num zi, zi2;
|
||||
|
||||
libnum::num cr = libnum::num(-0.480f);
|
||||
libnum::num ci = libnum::num(0.600f);
|
||||
|
||||
libnum::num zrsave = cmd->xmin;
|
||||
libnum::num zisave = cmd->ymax - libnum::num(cmd->current_frag*16)*cmd->yinc;
|
||||
|
||||
int offset = 0;
|
||||
|
||||
for( int j=0; j<16; j++)
|
||||
{
|
||||
for( int i=0; i<azrp_width; i++ )
|
||||
{
|
||||
zr = zrsave;
|
||||
zi = zisave;
|
||||
zr2 = zr * zr;
|
||||
zi2 = zi * zi;
|
||||
|
||||
int u=0;
|
||||
|
||||
while((zr2+zi2)<4 && (u<maxiter))
|
||||
{
|
||||
libnum::num temp = zr;
|
||||
zr2 = zr * zr;
|
||||
zi2 = zi * zi;
|
||||
zr = zr2 - zi2 + cr;
|
||||
zi = 2*zi*temp + ci;
|
||||
u++;
|
||||
}
|
||||
|
||||
if(u==maxiter)
|
||||
{
|
||||
frag[offset + i] = 0x0000;
|
||||
}
|
||||
else
|
||||
{
|
||||
int CR, CG, CB;
|
||||
|
||||
if (u<maxiter/4)
|
||||
{
|
||||
CR = 0;
|
||||
CG = u*4;
|
||||
CB = 255;
|
||||
}
|
||||
else if (u<2*maxiter/4)
|
||||
{
|
||||
CR = 0;
|
||||
CG = 255;
|
||||
CB = 255-(u-maxiter)/4;
|
||||
}
|
||||
else if (u<3*maxiter/4)
|
||||
{
|
||||
CR = (u-2*maxiter)/4;
|
||||
CG = 255;
|
||||
CB = 0;
|
||||
}
|
||||
else if (u<4*maxiter/4)
|
||||
{
|
||||
CR = 255;
|
||||
CG = 255-(u-3*maxiter)/4;
|
||||
CB = 0;
|
||||
}
|
||||
|
||||
frag[offset + i] = C_RGB(CR,CG,CB);
|
||||
}
|
||||
|
||||
zrsave += cmd->xinc;
|
||||
|
||||
}
|
||||
|
||||
zrsave = cmd->xmin;
|
||||
zisave -= cmd->yinc;
|
||||
|
||||
offset += azrp_width;
|
||||
|
||||
}
|
||||
|
||||
cmd->current_frag++;
|
||||
}
|
21
src/main.cpp
21
src/main.cpp
|
@ -19,7 +19,7 @@
|
|||
#include <num/num.h>
|
||||
|
||||
#include "utilities.h"
|
||||
#include "mandelbrotshader.h"
|
||||
#include "fractalshaders.h"
|
||||
|
||||
|
||||
bool screenshot = false;
|
||||
|
@ -36,8 +36,13 @@ bool exitToOS = false;
|
|||
|
||||
uint8_t texttodraw=2;
|
||||
|
||||
uint8_t Mandel_Julia_Switch = 1;
|
||||
|
||||
|
||||
void do_nothing( void )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void update( float dt )
|
||||
{
|
||||
|
@ -45,7 +50,6 @@ static void update( float dt )
|
|||
|
||||
}
|
||||
|
||||
|
||||
static void get_inputs( void )
|
||||
{
|
||||
key_event_t ev;
|
||||
|
@ -66,6 +70,8 @@ static void get_inputs( void )
|
|||
if(keydown(KEY_F2)) {texttodraw=1;}
|
||||
if(keydown(KEY_F3)) {texttodraw=2;}
|
||||
if(keydown(KEY_F4)) {texttodraw=3;}
|
||||
if(keydown(KEY_F5)) {Mandel_Julia_Switch=1;} // switch to Julia Set
|
||||
if(keydown(KEY_F6)) {Mandel_Julia_Switch=2;} // switch to Mandelbrot Set
|
||||
}
|
||||
|
||||
|
||||
|
@ -87,6 +93,7 @@ int main(void)
|
|||
azrp_shader_image_p4_configure();
|
||||
|
||||
azrp_mandelbrot_init();
|
||||
azrp_julia_init();
|
||||
|
||||
usb_interface_t const *interfaces[] = { &usb_ff_bulk, NULL };
|
||||
usb_open(interfaces, GINT_CALL_NULL);
|
||||
|
@ -121,7 +128,9 @@ int main(void)
|
|||
// all the stuff to be rendered should be put here
|
||||
azrp_clear( C_BLACK );
|
||||
|
||||
azrp_mandelbrot();
|
||||
if (Mandel_Julia_Switch==1) azrp_mandelbrot();
|
||||
else if(Mandel_Julia_Switch==2) azrp_julia();
|
||||
else do_nothing();
|
||||
|
||||
if (texttodraw>=1) Azur_draw_text(1,01, " FPS = %.0f - Render = %.0f", (float) (1000000.0f / elapsedTime), (float) time_render / 1000.0f );
|
||||
if (texttodraw>=2) Azur_draw_text(1,31, "Update = %.0f mc secs", (float) time_update );
|
||||
|
@ -153,7 +162,10 @@ int main(void)
|
|||
|
||||
if (textoutput && usb_is_open())
|
||||
{
|
||||
azrp_mandelbrot_USBDEBUG( );
|
||||
if (Mandel_Julia_Switch==1) azrp_mandelbrot_USBDEBUG( );
|
||||
else if (Mandel_Julia_Switch==2) azrp_julia_USBDEBUG( );
|
||||
else do_nothing( );
|
||||
|
||||
textoutput = false;
|
||||
}
|
||||
}
|
||||
|
@ -161,6 +173,7 @@ int main(void)
|
|||
|
||||
|
||||
azrp_mandelbrot_close( );
|
||||
azrp_julia_close( );
|
||||
|
||||
prof_quit();
|
||||
usb_close();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include <azur/gint/render.h>
|
||||
#include "mandelbrotshader.h"
|
||||
#include "fractalshaders.h"
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
|
||||
|
@ -53,12 +53,12 @@ void azrp_mandelbrot_close( void )
|
|||
struct command {
|
||||
uint8_t shader_id;
|
||||
uint8_t current_frag;
|
||||
int32_t xmin;
|
||||
int32_t xmax;
|
||||
int32_t ymin;
|
||||
int32_t ymax;
|
||||
int32_t xinc;
|
||||
int32_t yinc;
|
||||
libnum::num xmin;
|
||||
libnum::num xmax;
|
||||
libnum::num ymin;
|
||||
libnum::num ymax;
|
||||
libnum::num xinc;
|
||||
libnum::num yinc;
|
||||
};
|
||||
|
||||
|
||||
|
@ -70,12 +70,12 @@ void azrp_mandelbrot( void )
|
|||
|
||||
cmd.shader_id = AZRP_SHADER_MANDELBROT;
|
||||
cmd.current_frag = 0;
|
||||
cmd.xmin = (int32_t) (65536 * -3.0f);
|
||||
cmd.xmax = (int32_t) (65536 * 2.0f);
|
||||
cmd.ymin = (int32_t) (65536 * -2.0f);
|
||||
cmd.ymax = (int32_t) (65536 * 2.0f);
|
||||
cmd.xinc = (int32_t) (65536 * 5.0f/azrp_width);
|
||||
cmd.yinc = (int32_t) (65536 * 4.0f/azrp_height);
|
||||
cmd.xmin = libnum::num(-2.48f);
|
||||
cmd.xmax = libnum::num(1.48f);
|
||||
cmd.ymin = libnum::num(-1.12f);
|
||||
cmd.ymax = libnum::num(1.12f);
|
||||
cmd.xinc = libnum::num((2*1.98f)/azrp_width);
|
||||
cmd.yinc = libnum::num((2*1.12f)/azrp_height);
|
||||
int fragmin = 0;
|
||||
int fragcount = (azrp_height >> 4) + 1;
|
||||
|
||||
|
@ -94,10 +94,10 @@ void azrp_shader_mandelbrot( void *uniforms, void *comnd, void *fragment )
|
|||
|
||||
int maxiter = 60;
|
||||
|
||||
int32_t zr, zi;
|
||||
libnum::num zr, zi;
|
||||
|
||||
int32_t zrsave = cmd->xmin;
|
||||
int32_t zisave = cmd->ymax - (int32_t) (65536 * (cmd->current_frag*16)*cmd->yinc);
|
||||
libnum::num zrsave = cmd->xmin;
|
||||
libnum::num zisave = cmd->ymax - libnum::num(cmd->current_frag*16)*cmd->yinc;
|
||||
|
||||
int u;
|
||||
|
||||
|
@ -110,7 +110,7 @@ void azrp_shader_mandelbrot( void *uniforms, void *comnd, void *fragment )
|
|||
zr = zrsave;
|
||||
zi = zisave;
|
||||
|
||||
u = mandelbrot( zr, zi, (2*2)<<16, maxiter );
|
||||
u = mandelbrot( zr.v, zi.v, (2*2)<<16, maxiter );
|
||||
|
||||
if (u==0) frag[offset + i] = C_RGB(255,255,255);
|
||||
else frag[offset + i] = C_RGB(u*4,u*4,u*4);
|
||||
|
@ -122,7 +122,6 @@ void azrp_shader_mandelbrot( void *uniforms, void *comnd, void *fragment )
|
|||
zisave -= cmd->yinc;
|
||||
|
||||
offset += azrp_width;
|
||||
|
||||
}
|
||||
|
||||
cmd->current_frag++;
|
||||
|
|
Loading…
Reference in New Issue