harder cases of triangle projection

Started by
10 comments, last by JohnnyCode 9 years, 10 months ago

i was doing software rasterization of a triangle but i didnt do a harder cases of it

what do i mean harder cases -

my 'camera' in the 3d world is like a 'pyramid' you konow what i mean - there is my eye at the 'top" of it and a rectangle of monitor screen on the 'bottom' -

hard case is when traingle crosses the monitor plane or even crosses the eye plane

or both, i do not know what to do in such cases

how do people do that

1) if my triangle crosses the monitor plane should i cut the fragment and it will make some quad instead of triangle then draw it? Or should i magnify the crossed part (some rear part and only cut that when it crosses out the eye-monitor pyramid

is this code for such clipping hard ? im a bit lost in this probably

Advertisement

Clipping against frustum planes is what you want, and the near plane is the most problematic one.

Do a search for triangle clipping against the near plane maybe.

Basically when a triangle intersects the near plane (either one or two of its vertices are behind the near plane) you will need to clip it and create either one or two new triangles to replace the old one.

If two points cross behind the plane will need to calculate two new points that lie on the plane using interpolation and create a new triangle using the vertex in the frustum and your two new verts. If one vertex is behind it, you will again need to make two new vertices on the plane but you will have to create two new triangles to account for the two vertices still left inside the frustum. Hope that made some kind of sense.

Clipping against frustum planes is what you want, and the near plane is the most problematic one.

Do a search for triangle clipping against the near plane maybe.

Basically when a triangle intersects the near plane (either one or two of its vertices are behind the near plane) you will need to clip it and create either one or two new triangles to replace the old one.

If two points cross behind the plane will need to calculate two new points that lie on the plane using interpolation and create a new triangle using the vertex in the frustum and your two new verts. If one vertex is behind it, you will again need to make two new vertices on the plane but you will have to create two new triangles to account for the two vertices still left inside the frustum. Hope that made some kind of sense.

i wonder if in such clipping you need to talk about near plane at all..

wouldnt it be better just not define it and just calculate pure intersection of

pyramid vs triangle?

know what i mean something like

[attachment=22084:clip.JPG]

wouldnt it be better? has some one something to say about this or some code

example or something

A viewing frustum is not normally an exact pyramid but more like this:

https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcT6pqfcLdjjDS8q5E7VT3dU_Vk7GAha_TLAXRCrLr9TRPt3h-OSdQ

Notice how the top of the pyramid is chopped off.

When a point is projected onto screen, any point behind this plane will wrong, it is the nature of projection.

So when I triangle's vertices pass across this line things will start to look wrong, hence the need for clipping. You can clip against the other planes if you want to but it may be unnecessary.

With regards to clipping code there should be a fair bit out there if you look for it.

i.e.:

http://wwwx.cs.unc.edu/~sud/courses/236/a5/softgl_homoclip_smooth.cpp

@up ye i know, i wrote about this cutted pyramid in the first post and about the uncutted in the second - those seem to be two aproaches one can use

it wold be nice if someone would say something more about them both* and some details

*seem that this cutted pyramid is at least more popular though the uncutted maybe may be better, im not sure


it wold be nice if someone would say something more about them both* and some details

*seem that this cutted pyramid is at least more popular though the uncutted maybe may be better, im not sure

It's not a choice, the cut pyramid is correct, and the uncut pyramid is wrong.

You must have a near clipping plane, everything closer then the near clipping plane will misbehave, because math.


it wold be nice if someone would say something more about them both* and some details

*seem that this cutted pyramid is at least more popular though the uncutted maybe may be better, im not sure

It's not a choice, the cut pyramid is correct, and the uncut pyramid is wrong.

You must have a near clipping plane, everything closer then the near clipping plane will misbehave, because math.

dont think so

imagine the pyramid (that is some fragment of 3d space) and imagine the triangle in any position it will be always corect to clip the triangle to the intersection fragment (and then cast it)

It seem to me better than near plane becouse with near plane youre clipping the triangle to some cutted thing (that do not exist in this 3d space) and then you show this cutted partial object (for example you can cut a ball to a half ball with near plane and than show this non existant halfball) - here with full pyrmid you always get correct (at least this seem to be like that for me)

I disagree with Olof Hedman; there is a choice.

fir, you can choose to do it the way you're thinking of doing it, or you can choose to do it the correct way.

Use a "cut pyramid" (a frustum). This requires a near plane, so use a near plane.

I could probably link to some articles explaining why this way is correct, but you've stated your disgust with reading/searching/researching before, so I won't.

The short version is, like Olof Hedman says, math.

Hello to all my stalkers.

I disagree with Olof Hedman; there is a choice.

fir, you can choose to do it the way you're thinking of doing it, or you can choose to do it the correct way.

Use a "cut pyramid" (a frustum). This requires a near plane, so use a near plane.

I could probably link to some articles explaining why this way is correct, but you've stated your disgust with reading/searching/researching before, so I won't.

The short version is, like Olof Hedman says, math.

alright,

but what with this math? - you can just count the intersection and you will get the clipping this is always possible though im not sure how hard or slow this is, maybe near plane is some optymalization shortcut ? *

* When using near plane clipping (which is probably relatively easy though as someone mention can transform a triangle into a quad (which then you probably easily can transform into two new triangles)) you can do such thing as projection then clipping in 2d (so you can omit the more computative 3d pyramid clipping)

The way Im talking is reverse order full 3d clipping then projection - so maybe this way is a harder one but i do not see still the reason why it may be strictly incorrect (as I said it do not makes cuts of the figures in visible space that may occur in the first way (though anyway im not sure if this cutting effect my be masked so player will never see this or this makes visible artifacts though)

The way Im talking is reverse order full 3d clipping then projection - so maybe this way is a harder one but i do not see still the reason why it may be strictly incorrect (as I said it do not makes cuts of the figures in visible space that may occur in the first way (though anyway im not sure if this cutting effect my be masked so player will never see this or this makes visible artifacts though)


It's incorrect because you can end up with a triangle that contains a vertex at the tip of the pyramid, which is a degenerate point. The tip of the pyramid is technically on the projection line of every single point in space. The reason for a near plane is to avoid that problem.

This topic is closed to new replies.

Advertisement