srp
software rendering pipeline
Loading...
Searching...
No Matches
Interpolation

Functions related to in-primitive data interpolation. More...

Collaboration diagram for Interpolation:

Files

file  interpolation.c
 
file  interpolation.h
 
void interpolateDepthAndWTriangle (SRPVertexShaderOut *vertices, const float *weights, const float *invW, const SRPShaderProgram *sp, float *depth, float *reciprocalInterpolatedInvW)
 

Detailed Description

Functions related to in-primitive data interpolation.

Function Documentation

◆ interpolateDepthAndWTriangle()

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.

See also
https://www.comp.nus.edu.sg/%7Elowkl/publications/lowk_persp_interp_techrep.pdf
https://www.youtube.com/watch?v=F5X6S35SW2s

Interpolate the depth and inverse W values inside the triangle

Parameters
[in]verticesArray of vertices
[in]weightsArray of barycentric coordinates
[in]invWArray of inverseW values for each corresponding vertex
[in]spThe SRPShaderProgram being used
[out]depthWhere interpolated depth will be stored
[out]reciprocalInterpolatedInvWWhere the reciprocal of interpolated inverse W_clip will be stored