10-23-2001, 09:56 AM

I am trying to implement Phong Shading algorithm. My question is how to find the exact number of pixels between two vertices since I need to find the normal for each pixel by interperlating.

Thanks a lot.

ce

Thanks a lot.

ce

View Full Version : finding number of pixels

10-23-2001, 09:56 AM

I am trying to implement Phong Shading algorithm. My question is how to find the exact number of pixels between two vertices since I need to find the normal for each pixel by interperlating.

Thanks a lot.

ce

Thanks a lot.

ce

Screaming Lunatic

10-23-2001, 10:03 AM

Talk to your good friend Pythagourous (sp?) or even DeCartes (sp?), they'll tell you that:

# pixels = sqrt( (x2 - x1)^2 + (y2 - y1)^2 )

Also known as the Cartesian distance or if you're talking about triangles the Pythagorean thereom.

But that's assuming you've already transformed your vertices from world space to screen space.

SL

[This message has been edited by Screaming Lunatic (edited 10-23-2001).]

# pixels = sqrt( (x2 - x1)^2 + (y2 - y1)^2 )

Also known as the Cartesian distance or if you're talking about triangles the Pythagorean thereom.

But that's assuming you've already transformed your vertices from world space to screen space.

SL

[This message has been edited by Screaming Lunatic (edited 10-23-2001).]

10-23-2001, 10:22 AM

Thank you very much.

My vertices have the form (x, y, z) so I guess that they are in world coordination system. How do I transform them to screen system?

ce

My vertices have the form (x, y, z) so I guess that they are in world coordination system. How do I transform them to screen system?

ce

Screaming Lunatic

10-23-2001, 08:53 PM

Oh boy, meet Foley, VanDam, Feiner, and Hughes handy? You'll find that they can your good friends too.

Well you want to multiply your vertex on the left by the matrix below to go from world-space to view-space:

[1 0 0 0]

[0 1 0 0]

[0 0 1 0]

[0 0 1/d 0]

Where d is the distance from the origin to the front clipping plane. I'm assuming you want a perspective projection rather than an orthogonal projection. But for an orthogonal you just drop the z coordinate.

Now, to go from view space to screen space the matrix is a little more complicated.

Let me know if you really need the matrix for that. You should be able to do a search at google for it. But I really recommend that you get Foley, VanDam, Feiner, and Hughes.

SL

Well you want to multiply your vertex on the left by the matrix below to go from world-space to view-space:

[1 0 0 0]

[0 1 0 0]

[0 0 1 0]

[0 0 1/d 0]

Where d is the distance from the origin to the front clipping plane. I'm assuming you want a perspective projection rather than an orthogonal projection. But for an orthogonal you just drop the z coordinate.

Now, to go from view space to screen space the matrix is a little more complicated.

Let me know if you really need the matrix for that. You should be able to do a search at google for it. But I really recommend that you get Foley, VanDam, Feiner, and Hughes.

SL

Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.