Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Lighting #51

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions citro3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ctru-rs = { git = "https://github.com/rust3ds/ctru-rs.git" }
ctru-sys = { git = "https://github.com/rust3ds/ctru-rs.git" }
document-features = "0.2.7"
libc = "0.2.125"
pin_array = { version = "0.1.1" }

[features]
default = ["glam"]
Expand Down
74 changes: 74 additions & 0 deletions citro3d/examples/assets/frag-shader.pica
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
; modified version of https://github.com/devkitPro/3ds-examples/blob/ea519187782397c279609da80310e0f8c7e80f09/graphics/gpu/fragment_light/source/vshader.v.pica
; Example PICA200 vertex shader

; Uniforms
.fvec projection[4], modelView[4]

; Constants
.constf myconst(0.0, 1.0, -1.0, 0.5)
.alias zeros myconst.xxxx ; Vector full of zeros
.alias ones myconst.yyyy ; Vector full of ones
.alias half myconst.wwww

; Outputs
.out outpos position
.out outtex texcoord0
.out outclr color
.out outview view
.out outnq normalquat

; Inputs (defined as aliases for convenience)
.in inpos
.in innrm
.in intex

.proc main
; Force the w component of inpos to be 1.0
mov r0.xyz, inpos
mov r0.w, ones

; r1 = modelView * inpos
dp4 r1.x, modelView[0], r0
dp4 r1.y, modelView[1], r0
dp4 r1.z, modelView[2], r0
dp4 r1.w, modelView[3], r0

; outview = -r1
mov outview, -r1

; outpos = projection * r1
dp4 outpos.x, projection[0], r1
dp4 outpos.y, projection[1], r1
dp4 outpos.z, projection[2], r1
dp4 outpos.w, projection[3], r1

; outtex = intex
mov outtex, intex

; Transform the normal vector with the modelView matrix
; TODO: use a separate normal matrix that is the transpose of the inverse of modelView
dp3 r14.x, modelView[0], innrm
dp3 r14.y, modelView[1], innrm
dp3 r14.z, modelView[2], innrm
dp3 r6.x, r14, r14
rsq r6.x, r6.x
mul r14.xyz, r14.xyz, r6.x

mov r0, myconst.yxxx
add r4, ones, r14.z
mul r4, half, r4
cmp zeros, ge, ge, r4.x
rsq r4, r4.x
mul r5, half, r14
jmpc cmp.x, degenerate

rcp r0.z, r4.x
mul r0.xy, r5, r4

degenerate:
mov outnq, r0
mov outclr, ones

; We're finished
end
.end
Loading
Loading