69 f32 shadowDirX, shadowDirY, shadowDirZ;
73 f32 shadowColorR, shadowColorG, shadowColorB;
74 f32 commonColorR, commonColorG, commonColorB;
75 f32 backColorR, backColorG, backColorB;
76 f32 frontColorR, frontColorG, frontColorB;
123 if ((-Mxz * Pxz + Mzz * Pzz) < 0.0f) {
132 dx = posX - lightSource->
pos.
x;
133 dy = posY - lightSource->
pos.
y;
134 dz = posZ - lightSource->
pos.
z;
136 distSq =
SQ(dx) +
SQ(dy) +
SQ(dz);
138 if (distSq != 0.0f) {
139 dist =
sqrtf(distSq);
140 invDist = 1.0f / dist;
154 if ((dist == 0.0f) && (lightSource->
falloff == 0.0f)) {
155 intensityScale = 1.0f;
157 intensityScale = 1.0f / (dist * lightSource->
falloff);
158 dx *= intensityScale;
159 dy *= intensityScale;
160 dz *= intensityScale;
163 if ((distSq == 0.0f) && (lightSource->
falloff == 0.0f)) {
164 intensityScale = 1.0f;
166 intensityScale = 1.0f / (distSq * lightSource->
falloff);
167 dx *= intensityScale;
168 dy *= intensityScale;
169 dz *= intensityScale;
172 intensityScale = 1.0f;
175 if (intensityScale > 1.0f) {
176 intensityScale = 1.0f;
183 if (facingDir < 0.0f) {
192 temp_f10 = ex * dx + ey * dy + ez * dz;
194 if (facingDir < 0.0f) {
203 temp_f16 = wx * dx + wy * dy + wz * dz;
205 shadowIntensity = intensityScale *
fabsf(temp_f10);
206 lightIntensity = intensityScale *
fabsf(temp_f16);
207 if (temp_f10 > 0.0f) {
208 commonColorR += lightSource->
rgb.
r * shadowIntensity;
209 commonColorG += lightSource->
rgb.
g * shadowIntensity;
210 commonColorB += lightSource->
rgb.
b * shadowIntensity;
211 if (temp_f16 > 0.0f) {
212 backColorR += lightSource->
rgb.
r * lightIntensity;
213 backColorG += lightSource->
rgb.
g * lightIntensity;
214 backColorB += lightSource->
rgb.
b * lightIntensity;
216 frontColorR += lightSource->
rgb.
r * lightIntensity;
217 frontColorG += lightSource->
rgb.
g * lightIntensity;
218 frontColorB += lightSource->
rgb.
b * lightIntensity;
221 shadowColorR += lightSource->
rgb.
r * shadowIntensity;
222 shadowColorG += lightSource->
rgb.
g * shadowIntensity;
223 shadowColorB += lightSource->
rgb.
b * shadowIntensity;
224 if (temp_f16 > 0.0f) {
225 backColorR += lightSource->
rgb.
r * lightIntensity;
226 backColorG += lightSource->
rgb.
g * lightIntensity;
227 backColorB += lightSource->
rgb.
b * lightIntensity;
229 frontColorR += lightSource->
rgb.
r * lightIntensity;
230 frontColorG += lightSource->
rgb.
g * lightIntensity;
231 frontColorB += lightSource->
rgb.
b * lightIntensity;
237 if (facingDir < 0.0f) {
247 if (qx * shadowDirX + qy * shadowDirY + qz * shadowDirZ > 0.0f) {
252 shadowDirX, shadowDirY, shadowDirZ,
253 shadowColorR, shadowColorG, shadowColorB,
265 shadowDirX, shadowDirY, shadowDirZ,
266 shadowColorR, shadowColorG, shadowColorB,
278 s32 uls, s32 ult, s32 lrs, s32 lrt,
280 f32 shadowX, f32 shadowY, f32 shadowZ,
281 s32 shadowR, s32 shadowG, s32 shadowB,
282 s32 highlightR, s32 highlightG, s32 highlightB,
283 s32 ambientPower, s32 renderMode)
296 f32 pm02, pm12, pm22;
298 shadowMag =
SQ(shadowX) +
SQ(shadowY) +
SQ(shadowZ);
300 if (shadowMag < 1.0) {
301 ambientPower *= shadowMag;
303 if (shadowMag != 0.0f) {
304 shadowMag = 1.0f /
sqrtf(shadowMag);
306 shadowX *= shadowMag;
307 shadowY *= shadowMag;
308 shadowZ *= shadowMag;
316 if (facingDir < 0.0f) {
330 offsetX = ambientPower * ((shadowX * -pm22) + (shadowZ * pm02));
332 shadowXZ =
SQ(shadowX) +
SQ(shadowZ);
333 if (shadowXZ != 0.0f) {
334 shadowXZ =
sqrtf(shadowXZ);
339 var_f12_2 =
SQ(mtx01) +
SQ(mtx21);
340 if (var_f12_2 != 0.0f) {
341 var_f12_2 =
sqrtf(var_f12_2);
343 offsetY = -((shadowXZ * var_f12_2) + (shadowY * mtx11)) * ambientPower;
354 if (highlightR > 255) {
357 if (highlightG > 255) {
360 if (highlightB > 255) {
364 gDPSetPrimColor(
gMainGfxPos++, 0, 0, shadowR, shadowG, shadowB, alpha);
367 gDPSetScissor(
gMainGfxPos++, G_SC_NON_INTERLACE, 0, 0, 16, 1);
369 gSPSetOtherMode(
gMainGfxPos++, G_SETOTHERMODE_H, 4, 18,
370 G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_POINT | G_TT_NONE | G_TL_TILE |
371 G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE);
373 gDPSetRenderMode(
gMainGfxPos++, G_RM_OPA_SURF, G_RM_OPA_SURF2);
375 gDPSetPrimColor(
gMainGfxPos++, 0, 0, shadowR, shadowG, shadowB, alpha);
376 gDPSetEnvColor(
gMainGfxPos++, highlightR, highlightG, highlightB, 0);
378 gSPTextureRectangle(
gMainGfxPos++, 0, 0, 16 << 2, 1 << 2, 2, 0, 0, 4 << 10, 1 << 10);
392 gSPSetOtherMode(
gMainGfxPos++, G_SETOTHERMODE_H, 4, 18,
393 G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_RGBA16 | G_TL_TILE |
394 G_TD_CLAMP | G_TP_PERSP | G_CYC_2CYCLE | G_PM_NPRIMITIVE);
396 gDPSetRenderMode(
gMainGfxPos++, G_RM_PASS, renderMode);
408 ((uls + 0x100) << 2) + (s32)(offsetX * facingDir),
409 ((ult + 0x100) << 2) + (s32)offsetY,
410 ((lrs + 0x100 - 1) << 2) + (s32)(offsetX * facingDir),
411 ((lrt + 0x100 - 1) << 2) + (s32)offsetY
void appendGfx_shading_palette(Matrix4f mtx, s32 uls, s32 ult, s32 lrs, s32 lrt, s32 alpha, f32 shadowX, f32 shadowY, f32 shadowZ, s32 shadowR, s32 shadowG, s32 shadowB, s32 highlightR, s32 highlightG, s32 highlightB, s32 ambientPower, s32 otherModeLBits)