What's new

Backfacing culling in homogeneous space?

Orkin

d1R3c764 & g1|\|64 m4|<3R
I was wondering if anyone out there that's better at 3D math than I am (which isn't very good) knows if it's possible to do backface culling after the perspective transformation, in homogeneous space (x,y,z,w)?

The reason I ask is because I could get a decent speed boost if I culled away triangles before clipping them, instead of waiting until after clipping and the screen-space transform to do it.

Thanks for any help!
 

Hacktarux

Emulator Developer
Moderator
I don't think it's possible because from what i've seen w can change orientation. Maybe you can quickly divide x and y by w and do the backface culling without clipping. Then if the face isn't culled you can recalculate everything correctly with clipping and all.
 

ector

Emulator Developer
Wouldn't it be better to cull the triangles even before any transformation? I don't really know how N64 graphics work but you could backtransform the camera into each "object" (or collection of triangles with a specific xform matrix) and compute plane equations for the triangles and use those to cull.
 

icepir8

Moderator
Yes, there is a way. I am not sure of how to do it. It involves finding the normal of the triangle's face. If the normal is positive in the z direction it is you do one thing if it is negative then you do the other.

Finding the normal involves doing a cross product of the vectors making up sides 1 and 2 of the triangle.

I hope this helps. :)
 

Hacktarux

Emulator Developer
Moderator
Ice: yea but when i first read his post i thought that's what he already does and he was asking if it's possible to do it in homogeneous coordinates or if he had to divide by w first.

I have tried doing it in homogeneous coordinates in my soft plugin, and it broke everything while if i try to transform coordinates to screen coordinates, it seems to perfectly detect faces orientation. I'm still wondering why, coz i can't see any math reason, but i'm not very good at 3D math, maybe that's why :p

As for Ector's suggestion, maybe it's a good, idea, but i have to read it a few more times to fully understand what's the advantage....
 
OP
Orkin

Orkin

d1R3c764 & g1|\|64 m4|<3R
The reason you can't do it the same way you do in normal 3D space in homogeneous space is because if you ignore the w coordinate, it's as if you were looking at the scene in an orthographic view (no foreshortening), so triangles tipped away from the screen won't always show up. I think there's some way to do it if you include the w coordinate in your calculations, but 4D gives me a headache...

ector: That's not really all that feasible for N64 graphics. Since the N64 can change the transformation matrices between vertices on the same triangle, you won't always know which matrix to reverse-transform the camera position with. An alternate solution would be to split the view and perspective transformations (right now I'm using a combined matrix to do it all at once), and do culling between them, but then you end up doing double the transformations, which becomes slow again. Not to mention that some games (i.e. DKR) don't even have seperate view/perspective matrices.

I think I'll just leave it alone, it appears that it's probably more trouble than it's worth...
 

Gonetz

Plugin Developer (GlideN64)
It is possible to cull triangles before clipping. Dave2001 had implemented this for Glide64, and speed was noticeably increased. You can check cull_tri function in Util.cpp (better for v0.250, it's more simple). This function calculates screen coordinates to check orientation. Vertices have special flag "screen_translated", so screen coordinates are calculated only once per vertex.
 
Last edited:

Top