move sphere intersection test back to procedure, prepare for multiple material types

This commit is contained in:
Shylie 2023-04-13 20:44:39 -04:00
parent 346719824e
commit 5b8816c2fe
3 changed files with 110 additions and 97 deletions

View File

@ -40,13 +40,15 @@ GRAPHICS := gfx
GFXBUILD := $(BUILD)
#ROMFS := romfs
#GFXBUILD := $(ROMFS)/gfx
APP_TITLE := rt
APP_AUTHOR := Shy
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
CFLAGS := -g -Wall -O2 -mword-relocations \
CFLAGS := -Wall -O3 -mword-relocations \
-ffunction-sections \
$(ARCH)

View File

@ -62,7 +62,7 @@ static s8 sphereColorsUniformLocation;
static s8 sphereLightsUniformLocation;
static s8 randUniformLocation;
static constexpr unsigned int VERTEX_COUNT_W = 210;
static constexpr unsigned int VERTEX_COUNT_W = 150;
static constexpr unsigned int VERTEX_COUNT_H = 10 * VERTEX_COUNT_W / 6;
static constexpr unsigned int VERTEX_COUNT = VERTEX_COUNT_W * VERTEX_COUNT_H;
@ -197,7 +197,7 @@ static void sceneInit()
spheres[0] = FVec4_New(0.0f, -100.5f, -1.0f, 100.0f);
spheres[1] = FVec4_New(0.6f, 0.0f, -1.0f, 0.5f);
spheres[2] = FVec4_New(-0.6f, 0.0f, -1.0f, 0.5f);
spheres[3] = FVec4_New(0.0f, 1.75f, -1.0f, 1.0f);
spheres[3] = FVec4_New(0.0f, 10.0f, -1.0f, 9.0f);
C3D_FVec* sphereColors = C3D_FVUnifWritePtr(GPU_VERTEX_SHADER, sphereColorsUniformLocation, NUM_SPHERES);
sphereColors[0] = FVec3_New(0.9f, 0.3f, 0.3f);

View File

@ -77,7 +77,68 @@
mov r3, spheres[aL]
; do calculation
; call calcSphere
call calcSphere
.end
; check if noHit < albedo
; and exit early if true
; as albedo has not been set
; after the initial set
; which only happens when
; a ray does not hit any spheres
cmp noHit.xyz, lt, lt, r10.xyz
breakc cmp.x
; multiply color by albedo
mul r4.xyz, r4.xyz, r10.xyz
; add emitted light
mad r13.xyz, r4.xyz, r12.xyz, r13.xyz
; set r1 to new ray origin
mov r1.xyz, r5.xyz
; set r2 to new ray direction
call diffuse
.end
; copy final color to output
mov outColor.xyz, r13.xyz
; set alpha to 1
mov outColor.w, ones
end
.end
; Calculate Sphere Intersection
; -----------------------------
;
; Inputs
; ------
; r1.xyz: ray origin
; r2.xyz: ray direction
; r3.xyz: sphere origin
; r3.w: sphere radius
; r4.w: min distance
; r11.xyz: random unit vector
; r11.w: random number
;
; Outputs
; -------
; r4.w: new min distance
; r10.xyz: albedo
; r12.xyz: light emitted
;
; Temporaries
; -----------
; r5.xyz: new origin
; r6.xyz: new direction
; r7.xyz: hit normal
; r8.xyzw: used for calculations
; r9.xyzw: used for calculations
.proc calcSphere
; vec3 oc = origin - center
add r8.xyz, r1.xyz, -r3.xyz
@ -167,58 +228,8 @@
; early exit label
calcSphereExit:
nop
; done with calculation
.end
; check if noHit < albedo
cmp noHit.xyz, lt, lt, r10.xyz
breakc cmp.x
; multiply color by albedo
mul r4.xyz, r4.xyz, r10.xyz
mad r13.xyz, r4.xyz, r12.xyz, r13.xyz
; set r1 to new ray origin
mov r1.xyz, r5.xyz
; set r2 to new ray direction
.proc diffuse
add r2.xyz, r7.xyz, r11.xyz
.end
; copy final color to output
; min r13.xyz, ones, r13.xyz
mov outColor.xyz, r13.xyz
; set alpha to 1
mov outColor.w, ones
end
.end
; Calculate Sphere Intersection
; -----------------------------
;
; Inputs
; ------
; r1.xyz: ray origin
; r2.xyz: ray direction
; r3.xyz: sphere origin
; r3.w: sphere radius
; r4.w: min distance
; r11.xyz: random unit vector
; r11.w: random number
;
; Outputs
; -------
; r4.w: new min distance
; r10.xyz: albedo
; r12.xyz: light emitted
;
; Temporaries
; -----------
; r5.xyz: new origin
; r6.xyz: new direction
; r7.xyz: hit normal
; r8.xyzw: used for calculations
; r9.xyzw: used for calculations