__________________________________________
(C) by Wolf of eTc / Scene
Phong Shading (fake phong - all just
and beautiful).
Truth - is misleading,
lasting for a century, the same error -
it is the truth, which lasted a minute.
(C) Golovachev
As told to me by a friend to Fido:
"True phong - tupizna, it certainly imho.
Fong - is the same Guro, only
interpolated intensity value is not
color, and the values of the outward normal,
which is then used to calculate
color. "
I would like to add that the interpolation of the vector
outward normal is in the range of
-1 To 1 (If the normal is normalized, ie
reduced to unit length).
1. First of all, a little linear
algebra.
Vector normal to the plane - it is such
vector that is perpendicular to the plane
about the origin.
Normalization of the normal - this cast
normals to unit length, it can be
to do so:
Len = sqrt (x * x + y * y + z * z)
x = x / len
y = y / len
z = z / len
x, y, z - coordinates of the normal.
But I do not, it is best
ration is not between -1 and 1, and in some
other convenient limits, for example, from -64
to 64, then everything will look like this
as follows:
Len = sqrt (x * x + y * y + z * z)
x = x * 64/len
y = y * 64/len
z = z * 64/len
Finally, it is the vector product.
The formula is certainly not without multiplication, but that
done:
V3.x = V1.y * V2.z-V1.z * V2.y
V3.y = V1.z * V2.x-V1.x * V2.z
V3.z = V1.x * V2.y-V1.y * V2.x
V3 - is the vector product
vectors V1 and V2.
2. Precalculations for Phong Shading
Based on the fact that any
three-dimensional object, the normal changes in
each face, we need to calculate
normal to each vertex of the object.
Normal at the vertex is considered as the average
arithmetic mean of all normal to those
faces that belong to this
top.
A normal to the face is this:
Suppose we have three vertices
triangle defined in a clockwise direction:
V1 (x, y, z)
V2 (x, y, z)
V3 (x, y, z),
then
V1 '= V3-V1
V2 '= V2-V1
But she is already considered as normal
vector product of two vectors V1 'and
V2 ':
normal = vector_mul (V1 ', V2') (the multiplication
described above:)
Here is the procedure for the calculation of normals
each face in C, because on this Basic'e
will look extrim:
/ / Part of 3D-engine (c) by Wolf of eTc
group / Scene
/ / Calculating the normals to the faces of
for (i = 0; i
(Texture obtyanet "object, such as
stone) can be observed when the rotation
3D-object, we will rotate and the normal.
Only the best of these normal
standardize the calculation of the coordinates in the
texture.
Alexander Kulik (Wolf) 2:4635 / 8.18
__________________________________________