Initial Commit

This commit is contained in:
2025-11-19 22:20:27 +01:00
parent 8dfe2dce9e
commit 2ad6d49511
29 changed files with 8930 additions and 3 deletions

42
example/CMakeLists.txt Executable file
View File

@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.22)
find_program(PICASSO NAMES picasso REQUIRED)
# Function origanally Created in Re-Craft-3DS
function(__amy_make_shader arg1 arg2)
# These only exist cause i was stupid
set(__FILE ${arg1})
set(__NAME ${arg2})
# Need to build shaders during config stage :(
execute_process(
COMMAND ${PICASSO} -o "${CMAKE_CURRENT_SOURCE_DIR}/romfs/shaders/${__NAME}.shbin" "${__FILE}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endfunction()
project(amethyst-example)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED true)
__amy_make_shader(${CMAKE_CURRENT_SOURCE_DIR}/shaders/shader2d.v.pica shader2d)
__amy_make_shader(${CMAKE_CURRENT_SOURCE_DIR}/shaders/lithium.v.pica lithium)
add_executable(${PROJECT_NAME} source/main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE amethyst)
target_compile_options(${PROJECT_NAME} PRIVATE -O2)
ctr_generate_smdh(
${CMAKE_BINARY_DIR}/${PROJECT_NAME}.smdh
NAME "Amethyst Example"
DESCRIPTION "Example of Amethyst lib"
AUTHOR "tobid7"
ICON "${CMAKE_CURRENT_SOURCE_DIR}/romfs/icon.png"
)
ctr_create_3dsx(
${PROJECT_NAME}
OUTPUT "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.3dsx"
SMDH "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.smdh"
ROMFS "${CMAKE_CURRENT_SOURCE_DIR}/romfs"
)

BIN
example/romfs/icon.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 844 B

0
example/romfs/shaders/.gitkeep Executable file
View File

34
example/shaders/lithium.v.pica Executable file
View File

@@ -0,0 +1,34 @@
; LI7 Shader
; Constants
.constf myconst(0.0, 1.0, 0.00392156862745, 0.0)
.alias ones myconst.yyyy ; Vector full of ones
; Uniforms
.fvec projection[4]
; Outputs
.out out_position position
.out out_color color
.out out_uv texcoord0
; Inputs
.alias in_xy v0
.alias in_uvc v1
.alias in_col v2
.entry vmain
.proc vmain
mov r0.xy, in_xy.xy
mov r0.w, ones
dp4 out_position.x, projection[0], r0
dp4 out_position.y, projection[1], r0
dp4 out_position.z, projection[2], r0
dp4 out_position.w, projection[3], r0
mov out_uv, in_uvc.xy
mul r1, myconst.zzzz, in_col
mov out_color, r1
end
.end

38
example/shaders/shader2d.v.pica Executable file
View File

@@ -0,0 +1,38 @@
; Example PICA200 vertex shader
; Uniforms
.fvec projection[4]
; Constants
.constf myconst(0.0, 1.0, -1.0, 0.1)
.constf myconst2(0.3, 0.0, 0.0, 0.0)
.alias zeros myconst.xxxx ; Vector full of zeros
.alias ones myconst.yyyy ; Vector full of ones
; Outputs
.out outpos position
.out outclr color
; Inputs (defined as aliases for convenience)
.alias inpos v0
.alias inclr v1
.bool test
.proc main
; Force the w component of inpos to be 1.0
mov r0.xyz, inpos
mov r0.w, ones
; outpos = projectionMatrix * inpos
dp4 outpos.x, projection[0], r0
dp4 outpos.y, projection[1], r0
dp4 outpos.z, projection[2], r0
dp4 outpos.w, projection[3], r0
; outclr = inclr
mov outclr, inclr
; We're finished
end
.end

36
example/source/main.cpp Executable file
View File

@@ -0,0 +1,36 @@
#include <amethyst.hpp>
static C3D_Mtx projection;
int main() {
amy::registerCxxExceptionHandler();
amy::ctru::init();
amy::c3d::init();
auto top = amy::c3d::createScreen(GFX_TOP, GFX_LEFT);
auto shader = new amy::c3d::shader("romfs:/shaders/shader2d.shbin");
shader->input(GPU_FLOAT, 3);
shader->input(GPU_FLOAT, 3);
amy::c3d::frag::edit();
amy::c3d::frag::src(C3D_Both);
amy::c3d::frag::func(C3D_Both, GPU_REPLACE);
Mtx_Identity(&projection);
Mtx_OrthoTilt(&projection, 0.0, 400.0, 0.0, 240.0, 0.0, 1.0, true);
while (aptMainLoop()) {
amy::c3d::startFrame();
top->startDraw();
top->clear();
shader->use();
shader->setMat4(0, &projection);
C3D_ImmDrawBegin(GPU_TRIANGLES);
C3D_ImmSendAttrib(200, 200, 0.5, 0);
C3D_ImmSendAttrib(1, 0, 0, 1);
C3D_ImmSendAttrib(100, 40, 0.5, 0);
C3D_ImmSendAttrib(0, 1, 0, 1);
C3D_ImmSendAttrib(300, 40, 0.5, 0);
C3D_ImmSendAttrib(0, 0, 1, 1);
C3D_ImmDrawEnd();
amy::c3d::endFrame();
}
amy::c3d::deleteScreen(top);
return 0;
}