Jump to content

  • Log In with Google      Sign In   
  • Create Account

harder cases of triangle projection


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 fir   Members   -  Reputation: -456

Like
1Likes
Like

Posted 11 June 2014 - 03:25 AM

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



Sponsor:

#2 bwhiting   Members   -  Reputation: 817

Like
4Likes
Like

Posted 11 June 2014 - 03:35 AM

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.



#3 fir   Members   -  Reputation: -456

Like
0Likes
Like

Posted 11 June 2014 - 05:22 AM

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

 

clip.JPG

 

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

example or something



#4 bwhiting   Members   -  Reputation: 817

Like
3Likes
Like

Posted 11 June 2014 - 05:55 AM

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



#5 fir   Members   -  Reputation: -456

Like
0Likes
Like

Posted 11 June 2014 - 07:19 AM

@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



#6 Olof Hedman   Crossbones+   -  Reputation: 2957

Like
7Likes
Like

Posted 11 June 2014 - 08:12 AM


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.



#7 fir   Members   -  Reputation: -456

Like
0Likes
Like

Posted 11 June 2014 - 10:59 AM

 


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)



#8 Lactose!   GDNet+   -  Reputation: 3837

Like
4Likes
Like

Posted 11 June 2014 - 11:19 AM

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.



#9 fir   Members   -  Reputation: -456

Like
0Likes
Like

Posted 11 June 2014 - 11:29 AM

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)


Edited by fir, 11 June 2014 - 11:52 AM.


#10 Samith   Members   -  Reputation: 2327

Like
3Likes
Like

Posted 11 June 2014 - 12:36 PM

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.

#11 fir   Members   -  Reputation: -456

Like
0Likes
Like

Posted 11 June 2014 - 01:04 PM

 

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 is not any problem though - if so you just can treat that whole screen is in the color of this point of the triangle 



#12 JohnnyCode   Members   -  Reputation: 339

Like
3Likes
Like

Posted 16 June 2014 - 10:06 AM

the near plane clipping is a technical limitation of float range, that can be overcome only by near-far on air tweeks.

 

The rasterized depth tested pixel is (x/w,y/w,z/w.w), where w component is 3rd component of pixel before projection transformation (the view space z).

If w becomes very small, limiting to zero, you end up with too large numbers to sanely represent even in double floating numbers. That is why you clip those pixels before you devide them with their w component and rasterize them. 

 

One other need of near plane and far plane is explaining the distribution of depth buffer as well. If the (far plane)/(near plane) value overcomes the 24 or 32 or 16 bit unsigned integer 0-1 clamp, you have screwed up depth buffer pricision. That is why no one sets near plane to 0.0001 and far plane to 100 000.0.

 

Even if you set the far plane to 0.01f, you will not be able to set near plane to pure exact zero, and you will need near >0 clipping plane  even if you will observe atomic portions of world.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS