|
srp
software rendering pipeline
|
Functions related to in-primitive data interpolation. More...

Files | |
| file | interpolation.c |
| file | interpolation.h |
| void | interpolateDepthAndWTriangle (SRPVertexShaderOut *vertices, const float *weights, const float *invW, const SRPShaderProgram *sp, float *depth, float *reciprocalInterpolatedInvW) |
Functions related to in-primitive data interpolation.
| void interpolateDepthAndWTriangle | ( | SRPVertexShaderOut * | vertices, |
| const float * | weights, | ||
| const float * | invW, | ||
| const SRPShaderProgram * | sp, | ||
| float * | depth, | ||
| float * | reciprocalInterpolatedInvW | ||
| ) |
Let \( v_0, v_1, v_2 \) be points in space that form a triangle and \( a, b, c \) be barycentric coordinates for a point \( P \) according to \( v_0, v_1, v_2 \) respectively. Then, by the property of barycentric coordinates \( P = av_0 + bv_1 + cv_2 \). This can be extrapolated to arbitrary values assigned to vertices, and this is called affine attribute interpolation.
But this method does not take the perspective divide into account, so the texture (for example) will look "wrong".
It can be shown (see the "see also" section) that perspective-correct Z value can be obtained by dividing affinely-interpolated Ai/Wi by affinely-interpolated 1/Wi.
Interpolate the depth and inverse W values inside the triangle
| [in] | vertices | Array of vertices |
| [in] | weights | Array of barycentric coordinates |
| [in] | invW | Array of inverseW values for each corresponding vertex |
| [in] | sp | The SRPShaderProgram being used |
| [out] | depth | Where interpolated depth will be stored |
| [out] | reciprocalInterpolatedInvW | Where the reciprocal of interpolated inverse W_clip will be stored |