Skip to content

Instantly share code, notes, and snippets.

@lf94
Created August 4, 2023 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lf94/75cf37a3e0227c688a48dcdd13e3daa2 to your computer and use it in GitHub Desktop.
Save lf94/75cf37a3e0227c688a48dcdd13e3daa2 to your computer and use it in GitHub Desktop.
PS2 OSDSYS opening sequence lights circles
static void
DrawLights(void)
{
int l, i, j, k;
vif1SetZWrite(0);
vif1SetZTest(0);
vif1SetTexture(&textures[TEXID_CRBL]);
for(l = 0; l < 4; l++) {
float c = cosf((frameCount + lightsSeed + l*17)*0.01f*(l+10)*0.1f);
float s = sinf((frameCount + lightsSeed + l*15)*0.005f*(l+10)*0.1f);
// other formula from init
//c = cosf(frameCount*0.005f*(l+1));
//s = sinf(frameCount*0.003f*(l+1));
for(i = 0; i < 4; i++) {
if(i == 3) {
lightPositions[l][0] = (10.0f-l)*c;
lightPositions[l][1] = (3.0f+l)*s;
lightPositions[l][2] = c*12.0f + 88.0f;
lightPositions[l][3] = 0.0f;
sceVu0TransMatrix(sprMatrices->worldMatrix, sprMatrices->unit, lightPositions[l]);
sceVu0MulMatrix(sprMatrices->worldScreenMatrix, sprMatrices->cameraScreenMatrix, sprMatrices->worldMatrix);
sceVu0CopyMatrix(lightMatrixHistory[l][3], sprMatrices->worldScreenMatrix);
} else {
sceVu0CopyMatrix(lightMatrixHistory[l][i], lightMatrixHistory[l][i+1]);
sceVu0CopyMatrix(sprMatrices->worldScreenMatrix, lightMatrixHistory[l][i]);
}
sprTransformVertex(lightTrailVerts[l][lightTrailEnd], origin, sprMatrices->worldScreenMatrix);
vif1Begin();
for(j = 0; j < 2; j++) {
pktSetAlphaBlend(1, 5, 128);
pktSetAD(SCE_GS_PRIM, SCE_GS_SET_PRIM(SCE_GS_PRIM_TRISTRIP, 1, 1, 0, 1, 0, 0, 0, 0));
if(sceVu0ClipAll(clipMin, clipMax, sprMatrices->worldScreenMatrix, &lightVertices[j*4], 4))
continue;
for(k = 0; k < 4; k++) {
float q = sprTransformVertex(sprVertices->verts2[0], lightVertices[j*4+k], sprMatrices->worldScreenMatrix);
float s = lightTexCoords[k][0]*q;
float t = lightTexCoords[k][1]*q;
rand(); // eh?
int r, g, b, a;
if(j == 0) {
r = lightColors[l%4][0]*0.5f;
g = lightColors[l%4][1]*0.5f;
b = lightColors[l%4][2]*0.5f;
a = lightAlphas[j]*(i+1)/5;
} else {
r = g = b = 128;
a = lightAlphas[j]*(i+1)/5;
}
pktSetAD(SCE_GS_RGBAQ, SCE_GS_SET_RGBAQ(r, g, b, a, *(u32*)&q));
pktSetAD(SCE_GS_ST, SCE_GS_SET_ST(*(u32*)&s, *(u32*)&t));
u32 *v = sprVertices->verts2[0];
pktSetAD(SCE_GS_XYZF2, SCE_GS_SET_XYZF(v[0], v[1], v[2], 0));
}
}
vif1End();
}
}
lightTrailEnd = (lightTrailEnd+1) % 128;
if(lightTrailEnd == lightTrailStart)
lightTrailStart = (lightTrailStart+1) % 128;
// trails
vif1Begin();
pktSetAlphaBlend(1, 5, 128);
vif1End();
for(l = 0; l < 4; l++) {
vif1Begin();
float x0 = 0.0f;
float y0 = 0.0f;
// weird setting...
pktSetAD(SCE_GS_PRIM, SCE_GS_SET_PRIM(SCE_GS_PRIM_LINESTRIP, 1, 0, 0, 0, 1, 1, 0, 0));
i = (lightTrailStart+1) % 128;
k = (lightTrailEnd+128-1) % 128;
int intensity = (lightTrailEnd+128-1 - i) % 128;
for(j = 0; k != i; k = (k+128-1) % 128, j++) {
if((j & 7) != 0)
continue;
int r, g, b, a;
a = (intensity - j)*64/intensity;
r = lightColors[l][0]*a/128.0f;
g = lightColors[l][1]*a/128.0f;
b = lightColors[l][2]*a/128.0f;
pktSetAD(SCE_GS_RGBAQ, SCE_GS_SET_RGBAQ(r, g, b, a*2, 0));
u32 *v = lightTrailVerts[l][k];
float x1 = x0; // BUG: this isn't updated in original
float y1 = y0;
x0 = (v[0]>>4)-2048+320;
y0 = (v[1]>>4)-2048+112;
if(v[2]>>4 < 5 ||
x0 < 0 || x0 > 640 ||
y0 < 0 || y0 > 224 ||
x1 < 0 || x1 > 640 ||
y1 < 0 || y1 > 224)
pktSetAD(SCE_GS_XYZF3, SCE_GS_SET_XYZF(v[0], v[1], v[2], 0));
else
pktSetAD(SCE_GS_XYZF2, SCE_GS_SET_XYZF(v[0], v[1], v[2], 0));
}
vif1End();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment