math & physics
memnarch at December 2nd, 2011 19:40 — #1
Currently rewriting my old Rasterizer based on Nicolas Capens Half-Space Rasterizer.
In one of his comment(which is not accessible atm) he showed and example on how to interpolate any given value on the 3D Triangle face using normalvector. Because i lost some of my source, this part is gone, too.
Googled the whole day, but it seemed i missed it. Maybe someone here knows/rememberes how it worked? Its been a long time...since i have worked on my rasterizer.
Link to Cached Post of Nicolas:
reedbeta at December 2nd, 2011 20:35 — #2
Are you sure it was using the normals? That doesn't make much sense to me. Interpolation of values on triangles is usually done with barycentric coordinates. The depth, normals, UVs, and any other attribute can be interpolated this way. Maybe you're misremembering?
memnarch at December 3rd, 2011 10:03 — #3
If i remember correctly, he used the normals to calculate a step value. By adding this step after each cycle, you got the Barycentric coordinate.
Sofar, if iam misremembering, any tip on how to interpolate the Barycentric coordinates without calculating the 3 subtriangles everytime?(avoiding to much calculation per pixel)
memnarch at December 3rd, 2011 14:19 — #4
Nobody an Idea?
reedbeta at December 3rd, 2011 15:03 — #5
OK, with a little googling I was able to track down all the pages of that thread in the google cache.
Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8
This might be the post you're referring to (on page 3):
The easiest and most robust way is to use the plane equation.
Let's say we want to interpolate some component z linearly across the polygon (note that z stands for any interpolant). We can visualize this as a plane going through the x, y and z positions of the triangle, in 3D space. Now, the equation of a 3D plane is generally:
A * x + B * y + C * z + D = 0
From this we can derive that:
z = -A / C * x - B / C * y - D
Note that for every step in the x-direction, z increments by -A / C, and likewise it increments by -B / C for every step in the y-direction. So these are the gradients we're looking for to perform linear interpolation. In the plane equation (A, B, C) is the normal vector of the plane. It can easily be computed with a cross product.
Now that we have the gradients, let's call them dz/dx (which is -A /
C) and dz/dy (which is -B / C), we can easily compute z everywhere on the triangle. We know the z value in all three vertex positions. Let's call the one of the first vertex z0, and it's position coordinates (x0, y0). Then a generic z value of a point (x, y) can be computed as:
z = z0 + dz/dx * (x - x0) + dz/dy * (y - y0)
Once you've computed the z value for the center of the starting pixel this way, you can easily add dz/dx to get the z value for the next pixel, or dz/dy for the pixel below (with the y-axis going down).
I hope this helps! Don't hesitate to ask for further clarification.
memnarch at December 3rd, 2011 16:22 — #6
Wow, thanks .
Yes thats the post, and as you noted before: normals are wrong .
Meanwhile i found this(Which focuses on the same):
Thanks for your effort.
Still running slow, but i'll optimize later\\^\\^
andyharglesis at January 3rd, 2012 03:17 — #7
Now, the equation of a 3D plane is generally: A * x + B * y + C * z + D = 0
Care to explain how or why?
reedbeta at January 3rd, 2012 15:37 — #8
Enthusiastic, just google "plane equation" and you'll find plenty of articles about that.
andyharglesis at January 4th, 2012 02:35 — #9
Okay, I did.
And under what law should I care to follow the mathematical operations given to provide an "ideal" measurement of something in a space from an already generated "perspective" of how it works?
I can tell you that a Nivotyev Lokiq is 3 * 44 \\^ *33 + X.
What is X? Nobody knows but me because I made it up to represent something in MY head.
How do you understand it? By listening to what I tell you.
Nivotyev Lokigs are something I made up as well and you MUST understand that 3 * 44 \\^ *33 + X = a polygonal, six-faced 3-point lighted scale of a Nivotyev Lokig.
Accept or you'll never learn.
Also, it is stored in Pomerazquep memory. Memory in circles. Don't ask, just accept it.
Not accepting? Never will learn what I tell you then and you'll never work for me or succeed in Nivotyev programming logic.
geon at January 4th, 2012 08:19 — #10
Enthusiastic, what's your point? If you find some article, that's incomprehensible, just search until you find one that you can understand. There is plenty of great material on the interwebz.
If you still can't understand, you might need to brush up on the mathematics behind it.