[Question] Poly-F3/4 lighting ._.''

Graphic based area of development (Graphics Processing Unit), including the Geometry Transform Engine (GTE), TIM, STR (MDEC), etc.
Post Reply
User avatar
NITROYUASH
Serious PSXDEV User
Serious PSXDEV User
Posts: 107
Joined: January 7th, 2018, 12:03 am
PlayStation Model: SCPH-5502
Steam: NITROYUASH
Location: Russian Federation
Contact:

[Question] Poly-F3/4 lighting ._.''

Post by NITROYUASH » March 2nd, 2019, 10:51 am

Hi PSXDEV.
Firstly: You guys are awesome!

Second:
I just don't get understand the lighting system for FT3/FT4 and don't know where to start. So...
If i understand correctly, for lighting we need some things.
1. normals (wut???)
2. some black magic... um, i mean matrix stuff (LMTX, see my code for example, thx LameGuy for the tip)
3. NormalColorCol()
3.5. Not necessary, but useful: SetBackColor()

Well. It's working, but not so good. Firstly, i just don't understand. What is normals? I saw some examples from PSY-Q samples, but never understand how is working...

The second problem: my code for lighting is connected to the object. Probably it's because something is missing here.

Here is the SRC (yay, free working 3D stuff for anyone!):
► Show Spoiler
How it works in the "game":
► Show Spoiler
RIP GsSetFlatLight()

User avatar
LameGuy64
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 368
Joined: April 10th, 2013, 3:47 pm
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Skype: lameguy64
Location: Philippines

Re: [Question] Poly-F3/4 lighting ._.''

Post by LameGuy64 » March 2nd, 2019, 1:47 pm

Normals are basically vectors the plane is facing to whether it be a triangle or a quad. Normals are essential for anything lighting related and should typically be generated by a 3D modelling program though it is possible to compute them manually all in integers on the PS1.

The lighting system of the PS1 is pretty basic. It is comprised of a light matrix which defines three direction vectors for three light sources, a color matrix which defines the color and intensity of the light for the three light sources, a 'back' color set using SetBackColor() which is basically your ambient color, source color (ie. the color of the polygon) and the three vector inputs in the GTE data register are repurposed as normal inputs, you don't have to worry much about the last one unless you're doing light source calculation with the GTE directly.

The value order for the light direction matrix is as follows:

Code: Select all

MATRIX lgt_dirmtx = {
	// X, Y, Z
	4096, 2048, 1024,	// L0
	0, 0, 0,			// L1
	0, 0, 0				// L2
};
The value order for the light color matrix is as follows (ONE or 4096 is basically 1.0):

Code: Select all

MATRIX lgt_colmtx = {
	// L0, L1, L2
	ONE, 0, 0,		// R
	ONE, 0, 0,		// G
	ONE, 0, 0		// B
};
Disabling a light source is just a matter of setting its light direction and color to zero.

The lighting system is only capable of doing directional lighting and not positional or point lighting like in OpenGL so the lighting coordinates are always about direction and never position. If you don't multiply the light matrix with the rotation matrix of the model the light direction will remain fixed.

Point lighting is possible to achieve however but it requires writing a custom model sorting function that performs distance and normal compute between the light source and the polygon being processed and using the distance to determine light intensity for the light color matrix and direction for the light direction matrix.

Image
I'll release code of this after I finish up a small demo featuring this effect. Its pretty advanced GTE stuff though.
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

User avatar
NITROYUASH
Serious PSXDEV User
Serious PSXDEV User
Posts: 107
Joined: January 7th, 2018, 12:03 am
PlayStation Model: SCPH-5502
Steam: NITROYUASH
Location: Russian Federation
Contact:

Re: [Question] Poly-F3/4 lighting ._.''

Post by NITROYUASH » March 2nd, 2019, 5:02 pm

Thanks for the tips, LameGuy.

About the normals: i think .PLY can generate it... Welp, it can. Should work for SVECTOR structure i think.
► Show Spoiler
About the screen from example: It looks fantastic, but source would be nice. I'll wait. :>

PS.
(ONE or 4096 is basically 1.0)
Looks like PS1 easier to work with integers instead float values so they use a huge numbers sometimes.

User avatar
gwald
1997 Yaroze Enthusiast
1997 Yaroze Enthusiast
Posts: 256
Joined: September 18th, 2013, 8:44 am
I am a: programmer/DBA
PlayStation Model: Net Yaroze
Location: Australia
Contact:

Re: [Question] Poly-F3/4 lighting ._.''

Post by gwald » March 3rd, 2019, 10:27 am

NITROYUASH wrote:
March 2nd, 2019, 10:51 am
1. normals (wut???)
Apart from rendering static 3D objects, programming in 3D is going to be pretty hard if you don't understand vectors, normals, product, dot products, trig and matrix functions stuff etc...
You don't have to know how the matrix maths work tho, just know what to put in and expect out of the functions etc..
Understanding the math behind it is worth learning, it's the same math everywhere (GL/DX,ect), just implemented differently.

User avatar
LameGuy64
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 368
Joined: April 10th, 2013, 3:47 pm
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Skype: lameguy64
Location: Philippines

Re: [Question] Poly-F3/4 lighting ._.''

Post by LameGuy64 » March 3rd, 2019, 3:24 pm

Just be sure you multiply the float values of the normals by 4096 when converting them to integers. Using all integer math on the PS1 is recommended because the PS1 has no FPU and the compiler will resort to floating point emulation which is going to be slow.
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest