Page 1 of 1

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

Posted: March 2nd, 2019, 10:51 am
by NITROYUASH
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!):
ABBC3_SPOILER_SHOW
How it works in the "game":
ABBC3_SPOILER_SHOW
RIP GsSetFlatLight()

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

Posted: March 2nd, 2019, 1:47 pm
by LameGuy64
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.

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

Posted: March 2nd, 2019, 5:02 pm
by NITROYUASH
Thanks for the tips, LameGuy.

About the normals: i think .PLY can generate it... Welp, it can. Should work for SVECTOR structure i think.
ABBC3_SPOILER_SHOW
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.

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

Posted: March 3rd, 2019, 10:27 am
by gwald
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.

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

Posted: March 3rd, 2019, 3:24 pm
by LameGuy64
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.