Page 1 of 2

I have a problem with 2D sprite in 3D game

Posted: November 11th, 2019, 3:10 am
by NITROYUASH
Hi PSXDEV. What is the name of this problem? For some reason, a 2D sprites in my game will not drawing correctly when they stand on the floor. Can i fix that using the PS1 function or this is more complicated problem? Can't find a sample by the way because i don't know what kind of problem is it. (Something with Z-sort?)

[BBvideo=560,315]https://youtu.be/LMB4yr6RfUo[/BBvideo]

The simplified sprite source:

Code: Select all

	long	OTz;
	int		i;
	
	obj_ft4 = (POLY_FT4*)gte_myPrimPtr;

	gte_ldv3(&Sprite.co[0], &Sprite.co[1], &Sprite.co[2]);
	gte_rtpt();

	gte_ldv0(&Sprite.co[3]);
	gte_stsxy3(&obj_ft4->x0, &obj_ft4->x1, &obj_ft4->x2);

	gte_rtps();

	gte_avsz4();
	gte_stotz(&OTz);

	if( OTz > 0 ) {
		if (((OTz >> 2) >= GTE_OT_LENGTH)) {
			gte_stsxy(&obj_ft4->x3);
			
			setUVWH(obj_ft4,
				Sprite.settings.u, Sprite.settings.v,
				Sprite.settings.w, Sprite.settings.h);
	
			obj_ft4->tpage = Sprite.texture.tpage;
			obj_ft4->clut  = Sprite.texture.clutid;
			
			setPolyFT4(obj_ft4);
		
			addPrim(OT + (OTz >> 2), obj_ft4);
			gte_myPrimPtr += GTE_POLY_FT4_size;
		}
	}
Thanks for the helping!

Re: I have a problem with 2D sprite in 3D game

Posted: November 11th, 2019, 1:58 pm
by NITROYUASH
Just thought about potential quick-fix.
Maybe i should mark somewhere the floor polygons. Then add the second OT or something like that just for problematic polygons and then draw the sprites always in front of that polygons.

What do you guys think about this?

Re: I have a problem with 2D sprite in 3D game

Posted: November 12th, 2019, 11:58 am
by LameGuy64
If what you're looking for is bill-boarding sprites in a 3D space, there's a billboard example in PSn00bSDK that demonstrates just that.

Re: I have a problem with 2D sprite in 3D game

Posted: November 12th, 2019, 3:01 pm
by NITROYUASH
The problem is not in the billboard.
In fact, the problem applies to all 3D polygons.
As you can see, when the sprite-object (it just POLY_FT4) is not centered on the floor-object (POLY_ANYTHING?), something weird will start happening with the Z-Sort between sprite and the floor.
The larger the polygon of the floor, the higher the risk that it will overlap an object above oneself.

Re: I have a problem with 2D sprite in 3D game

Posted: November 13th, 2019, 1:10 pm
by LameGuy64
That's likely the limits of painter's sort algorithm really as the depth value for Z sorting is computed by averaging the Z coordinates of a polygon, which is typically the center of said polygon.

The best way to work around this is to subdivide polygons with the Z depth computed on each subdivided polygon. The Divide* functions in libgte do not support that, not so sure on libgs as I haven't used that in so long.

Re: I have a problem with 2D sprite in 3D game

Posted: November 13th, 2019, 2:05 pm
by Shadow
Looks like the ordertable is getting overflowed. Have you tried using dual-ordertables? IE: OT1 can be for sprites, but OT2 is then for 3D. Finally, you then sort and draw them. There is a good example by Sony showing how to do this. Basically it gives you a larger ranger of ordertables which helps with that z-sort issue and helps with that annoying flicker :)

Code: Select all

GsSortOt(&WorldOrderingTable2[CurrentBuffer], &WorldOrderingTable1[CurrentBuffer]);
GsDrawOt(&WorldOrderingTable1[CurrentBuffer]);

Re: I have a problem with 2D sprite in 3D game

Posted: November 13th, 2019, 3:05 pm
by NITROYUASH
Tried to use this function, but for some reason, this will reduces the frame rate to 5-10 frames.

Here is a quick-fix for the floor:

Code: Select all

// Floor planes is the... Um... Floor, okay?
// This fix will need to correctly draw the objects like sprite on the floor
// It will shift the OTz a little
// So you'll need to keep the distance between the floor-marked objects and the other planes below!
u_char floor = (Plane.settings.back != 0) ? 12 : 0;

Code: Select all

addPrim(OT + (OTz >> 2) + floor, obj);
PS:
Oh, yes, if you divide the object into many small parts, it will works too, but you still will see the flickering even with the small polygons and it may be a performance killer.

Re: I have a problem with 2D sprite in 3D game

Posted: November 13th, 2019, 11:36 pm
by Shadow
NITROYUASH wrote: November 13th, 2019, 3:05 pmTried to use this function, but for some reason, this will reduces the frame rate to 5-10 frames.
My idea using dual-ordertables reduces the frame rate by 5-10 frames?

Re: I have a problem with 2D sprite in 3D game

Posted: November 14th, 2019, 1:19 am
by NITROYUASH
Yes, i just added it to main loop.

Code: Select all

#define OT_LENGTH	12
#define OT_ENTRIES	(1<<OT_LENGTH)
// Main OT (Main position)
GsOT 		myOT[2];
GsOT_TAG 	myOT_TAG[2][OT_ENTRIES];

// Second OT (Second position)
GsOT		myOT2[2];
GsOT_TAG 	myOT2_TAG[2][OT_ENTRIES];

void PrepDisp() {
//. . . .
	GsClearOt(0, 0,  &myOT[ActiveBuffer]);
	GsClearOt(0, 12, &myOT2[ActiveBuffer]);
//. . . .
}

void Display() {
//. . . .
	//Merge OT's (Here is the problem)
	GsSortOt(&myOT[ActiveBuffer], &myOT2[ActiveBuffer]);

	GsDrawOt(&myOT[ActiveBuffer]);		// Draw GS OT
//. . . .
}

Re: I have a problem with 2D sprite in 3D game

Posted: November 14th, 2019, 2:05 am
by Shadow

Code: Select all

GsSortOt(&myOT[ActiveBuffer], &myOT2[ActiveBuffer]);
This causes the performance drop?

Re: I have a problem with 2D sprite in 3D game

Posted: November 14th, 2019, 2:33 am
by NITROYUASH
Yep, after removing GsSortOt, everything will be fine again.

Re: I have a problem with 2D sprite in 3D game

Posted: November 15th, 2019, 12:12 am
by RetroPsx
Hi

I noticed that this SDK From this site works in 3D

Is there a 3D engine for this SDK?

is there any tutorial on this one?

Re: I have a problem with 2D sprite in 3D game

Posted: November 15th, 2019, 4:59 am
by NITROYUASH
Off Topic
I noticed that this SDK From this site works in 3D
What SDK?

Re: I have a problem with 2D sprite in 3D game

Posted: November 15th, 2019, 12:06 pm
by LameGuy64
If there's an OT overflow going on the program should become unstable as data around the data segment is being corrupted or crash immediately if the overflow went to the other OT, as the latter would likely cause a GPU deadlock in a double OT/primitive buffer setup.

Re: I have a problem with 2D sprite in 3D game

Posted: November 15th, 2019, 10:44 pm
by RetroPsx
Psy-Q SDK and all possible resources in this site

Re: I have a problem with 2D sprite in 3D game

Posted: November 15th, 2019, 11:32 pm
by Dedok179
RetroPsx wrote: November 15th, 2019, 10:44 pm Psy-Q SDK and all possible resources in this site
If you are hoping to come to the ready, then no. It doesn’t work like that.

Re: I have a problem with 2D sprite in 3D game

Posted: November 16th, 2019, 11:46 pm
by RetroPsx
I am looking for information to be ready

So tell me a resume how it works and how to configure its environment of development "psx" in 3D?

Re: I have a problem with 2D sprite in 3D game

Posted: November 17th, 2019, 2:19 pm
by Shadow
NITROYUASH wrote: November 14th, 2019, 2:33 am Yep, after removing GsSortOt, everything will be fine again.
Hmm. That's very interesting. I didn't realise that it caused such a massive performance drop! :?

Off Topic
RetroPsx wrote: November 16th, 2019, 11:46 pm I am looking for information to be ready

So tell me a resume how it works and how to configure its environment of development "psx" in 3D?
Warning issued. Do not hijack and post off topic and silly related questions in poor and broken English.

Re: I have a problem with 2D sprite in 3D game

Posted: November 17th, 2019, 4:50 pm
by NITROYUASH
Shadow wrote: November 17th, 2019, 2:19 pm
NITROYUASH wrote: November 14th, 2019, 2:33 am Yep, after removing GsSortOt, everything will be fine again.
Hmm. That's very interesting. I didn't realise that it caused such a massive performance drop! :?
As said Lameguy, it's maybe a problem with OT overflow (OT_ENTRIES?), not in SortOT. I should test it when i will need that function. Thanks guys for helping by the way c:

Re: I have a problem with 2D sprite in 3D game

Posted: November 17th, 2019, 7:31 pm
by Shadow
If that were the case though, a timeout warning would be issued. Since the library was written by SN Systems we would need to dissemble it to find out exactly what it's doing, but yes the best way would be to simply test it and share the results :)