Skip to content

Commit 19cf482

Browse files
authored
Merge pull request #75 from rust3ds/feat/lighting
[Feature] Lighting implementation
2 parents e336164 + 11b67ba commit 19cf482

File tree

7 files changed

+1299
-0
lines changed

7 files changed

+1299
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# IDE files
2+
.zed
3+
14
# Generated by Cargo
25
# will have compiled files and executables
36
debug/

citro3d/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ ctru-rs = { git = "https://github.com/rust3ds/ctru-rs.git" }
1616
ctru-sys = { git = "https://github.com/rust3ds/ctru-rs.git" }
1717
document-features = "0.2.11"
1818
libc = "0.2.175"
19+
pin_array = "0.1.2"
1920

2021
[features]
2122
default = ["glam"]
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
; modified version of https://github.com/devkitPro/3ds-examples/blob/ea519187782397c279609da80310e0f8c7e80f09/graphics/gpu/fragment_light/source/vshader.v.pica
2+
; Example PICA200 vertex shader
3+
4+
; Uniforms
5+
.fvec projection[4], modelView[4]
6+
7+
; Constants
8+
.constf myconst(0.0, 1.0, -1.0, 0.5)
9+
.alias zeros myconst.xxxx ; Vector full of zeros
10+
.alias ones myconst.yyyy ; Vector full of ones
11+
.alias half myconst.wwww
12+
13+
; Outputs
14+
.out outpos position
15+
.out outtex texcoord0
16+
.out outclr color
17+
.out outview view
18+
.out outnq normalquat
19+
20+
; Inputs (defined as aliases for convenience)
21+
.in inpos
22+
.in innrm
23+
.in intex
24+
25+
.proc main
26+
; Force the w component of inpos to be 1.0
27+
mov r0.xyz, inpos
28+
mov r0.w, ones
29+
30+
; r1 = modelView * inpos
31+
dp4 r1.x, modelView[0], r0
32+
dp4 r1.y, modelView[1], r0
33+
dp4 r1.z, modelView[2], r0
34+
dp4 r1.w, modelView[3], r0
35+
36+
; outview = -r1
37+
mov outview, -r1
38+
39+
; outpos = projection * r1
40+
dp4 outpos.x, projection[0], r1
41+
dp4 outpos.y, projection[1], r1
42+
dp4 outpos.z, projection[2], r1
43+
dp4 outpos.w, projection[3], r1
44+
45+
; outtex = intex
46+
mov outtex, intex
47+
48+
; Transform the normal vector with the modelView matrix
49+
; TODO: use a separate normal matrix that is the transpose of the inverse of modelView
50+
dp3 r14.x, modelView[0], innrm
51+
dp3 r14.y, modelView[1], innrm
52+
dp3 r14.z, modelView[2], innrm
53+
dp3 r6.x, r14, r14
54+
rsq r6.x, r6.x
55+
mul r14.xyz, r14.xyz, r6.x
56+
57+
mov r0, myconst.yxxx
58+
add r4, ones, r14.z
59+
mul r4, half, r4
60+
cmp zeros, ge, ge, r4.x
61+
rsq r4, r4.x
62+
mul r5, half, r14
63+
jmpc cmp.x, degenerate
64+
65+
rcp r0.z, r4.x
66+
mul r0.xy, r5, r4
67+
68+
degenerate:
69+
mov outnq, r0
70+
mov outclr, ones
71+
72+
; We're finished
73+
end
74+
.end

0 commit comments

Comments
 (0)