Sign in to follow this  
Phong

Interpolation on GPU

Recommended Posts

This question has no practical reason, but I am very curious about it. How modern GPU interpolates values across polygon, using baricentric coordinates or just scanline bilinear interpolation. And how it performs perspective-correction.

Share this post


Link to post
Share on other sites
In general, modern GPUs have fixed function hardware to provide interpolated values at points on the polygon. There are a fixed number of these 'interpolators' in a GPU. This number determines the maximum number of interpolated attributes you can use before becoming 'interpolator limited'. It's normally hard to reach this limit before hitting a bottleneck somewhere else, though.
Different GPUs will implement these units in different ways, barycentric coordinates is one way to implement them.
No modern GPUs use scanline based interpolation. Everything is done with small blocks of pixels in parallel (say 2x2 - a quad). Linear interpolation would not produce perspective correct interpolants anyway.
To get perspective correct interpolation, you need to perform 'perspective division' at each point. To make a linear interpolator produce perspective correct values, interpolate the coordinate divided by W (say, U/W), and the reciprocal of the W component (1/W) of your homogeneous coordinate across the polygon. Then at each point, divide all your coordinates through by this reciprocal (W/U / 1/W = U). This is normally accomplished by reciprocating 1/W and multiplying by that because multiplication is cheaper than division. Read up on 'rational linear interpolation' or 'hyperbolic interpolation' for more information.

Share this post


Link to post
Share on other sites
Thanks a lot for this valuable piece of information. Also wanted to ask, what if perspective is not along z axis? I mean 4x4 projection matrix allows to do perspective along y or x axis or a combination.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this