-
Notifications
You must be signed in to change notification settings - Fork 1
/
gl-sh4-light.S
209 lines (152 loc) · 5.53 KB
/
gl-sh4-light.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/* KallistiGL for KallistiOS ##version##
libgl/gl-sh4-light.S
Copyright (C) 2013-2014 Josh Pearson
Dynamic Vertex Lighting
This Assembly file contains 2 functions:
_glKosSpotLight - This function computes diffuse / spotlight / attenuation
_glKosSpecular - This functions computes the Specular Term
*/
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!float _glKosSpecular( void * vertex6f, void * eyepos, void * Lvectorin );
.globl __glKosSpecular
!r4 = [arg][void*] = vertex
!r5 = [arg][void*] = eyepos
!r6 = [arg][void*] = L vector
!fr0 = return value
!fv0 = vertex position (P)(N)
!fv4 = eye position (E)
!fv8 = L vector (L)
__glKosSpecular:
fmov @r4+, fr0 ! load vertex x to fv0
fmov @r4+, fr1 ! load vertex y to fv0
fmov @r4+, fr2 ! load vertex z to fv0
fmov @r5+, fr4 ! load eye pos x to fv4
fmov @r5+, fr5 ! load eye pos y to fv4
fmov @r5+, fr6 ! load eye pos z to fv4
fmov @r6+, fr8 ! load L vector x to fv8
fmov @r6+, fr9 ! load L vector y to fv8
fmov @r6+, fr10 ! load L vector z to fv8
fsub fr0, fr4 ! fv4 = V = normalize ( E - P )
fsub fr1, fr5
fsub fr2, fr6
fldi0 fr3 ! load 0 for P w
fldi0 fr7 ! load 0 for E w
fipr fv4, fv4 ! Normalize V vector
fsrra fr7
fmul fr7, fr4
fmul fr7, fr5
fmul fr7, fr6
fadd fr4, fr8 ! fv8 = H = normalize( L + V )
fadd fr5, fr9
fadd fr6, fr10
fldi0 fr11 ! load 0 for H w
fipr fv8, fv8 ! Normalize H vector
fsrra fr11
fmul fr11, fr8
fmul fr11, fr9
fmul fr11, fr10
fmov @r4+, fr0 ! load N to fv0
fmov @r4+, fr1
fmov @r4+, fr2
fipr fv0, fv8 ! N dot H for specular term
rts
fmov fr11, fr0 ! move N dot H to fr0 for return
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!int _glKosSpotlight( void * glLight, void * vertex6f, void * Lvectorout );
.globl __glKosSpotlight
!r0 = return value | true or false
!r1 = boolean flag
!r2 = boolean false
!r4 = [arg] = light
!r5 = [arg] = vertex
!r6 = [arg] = output
!fv0 = vertex position
!fv4 = light position | L vector | normalize(light pos - vertex pos) | w = attenuation distance
!fv8 = light direction | N vector = Vertex Normal
!fv12 = Spot vector | normalize(vertex pos - light pos)
__glKosSpotlight:
mov #0, r1 ! load 0 for boolean flag
mov #0, r2 ! load 0 for boolean false
fmov @r4+, fr4 ! load light position x to fv4
fmov @r4+, fr5 ! load light position y to fv4
fmov @r4+, fr6 ! load light position z to fv4
fmov @r4+, fr7 ! load light position w to fv4
fmov @r4+, fr8 ! load light direction x to fv8
fmov @r4+, fr9 ! load light direction y to fv8
fmov @r4+, fr10 ! load light direction z to fv8
fmov @r5+, fr0 ! load vertex position x to fv0
fmov @r5+, fr1 ! load vertex position y to fv0
fmov @r5+, fr2 ! load vertex position z to fv0
fldi0 fr11 ! load 0 for light dir w
fcmp/gt fr11, fr7 ! light pos w component set = spot light
bf .VERTEXLIGHT0 ! light not a spot light - branch to vertex lighting
fschg
fmov dr0, dr12 ! copy vertex x,y to fv12
fschg
fmov fr2, fr14 ! copy vertex z to fv12
fsub fr4, fr12 ! fv12 = ( vertex position - light position)
fsub fr5, fr13
fsub fr6, fr14
fldi0 fr15 ! set fv12 w component to 0
fipr fv12, fv12 ! Normalize vector
fsrra fr15
fmul fr15, fr12
fmul fr15, fr13
fmul fr15, fr14
fldi0 fr15 ! set fv12 w component to 0
fipr fv12, fv8 ! fr11 now holds light cosDir
fmov @r4+, fr15 ! load light cutOff to fr15
mov #1, r1 ! load 1 for boolean flag = indicate light cutOff was read
fcmp/gt fr15, fr11 ! cosDir > cutOff ? 0 : 1
bt .RET0spot ! vertex outside of spotlight = return 0
.VERTEXLIGHT0:
fsub fr0, fr4 ! fv4 = L vector = ( light position - vertex position)
fsub fr1, fr5
fsub fr2, fr6
fldi0 fr7 ! load 0 for L w
fldi0 fr11 ! load 0 for N w
fipr fv4, fv4 ! Normalize L vector
fsrra fr7
fmul fr7, fr4
fmul fr7, fr5
fmul fr7, fr6 ! fv4 = Normalized L Vector
fmov fr7, fr3 ! copy L w to fr3
fldi0 fr7 ! load 0 for L w
fcmp/gt fr7, fr3
bf .RET0spot ! if L w < 0, return 0 now to avoid pointless computations
fmov @r5+, fr8 ! load normal to fv8
fmov @r5+, fr9 ! load normal to fv8
fmov @r5+, fr10 ! load normal to fv8
fipr fv8, fv4 ! N dot L
fcmp/gt fr11, fr7 ! L w < = 0 ? L w = 0
bf .RET0spot: ! if L w < 0, return 0 now to avoid pointless computations
.WRITEDi:
fschg
fmov dr4, @r6 ! write L vector x to output
fschg
add #8, r6
fmov fr6, @r6 ! write L vector z to output
add #4, r6
cmp/gt r2, r1
bt .READattenf
add #4, r4
.READattenf:
fmov @r4+, fr8 ! vertex normal gets overwritten by atten factors
fmov @r4+, fr9
fmov @r4+, fr10
fldi1 fr11
fmul fr3, fr9 ! calculate attenuation
fmul fr3, fr10
fmul fr3, fr10
fadd fr9, fr8
fadd fr10, fr8
fdiv fr8, fr11 ! fr11 = A
fmul fr7, fr11 ! D * A
fmov fr11, @r6 ! write D*A to output
.RET1spot:
rts
mov #1, r0
.RET0spot:
rts
mov #0, r0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!