Skip to content

Instantly share code, notes, and snippets.

@elliotwoods
Created April 23, 2012 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elliotwoods/2469513 to your computer and use it in GitHub Desktop.
Save elliotwoods/2469513 to your computer and use it in GitHub Desktop.
Padé replacement function
// - - - - pade BEGIN - - - -
float coefficient(int iDimension, int iCoefficient)
{
int iRow, iColumn;
iRow = iDimension*2 + (iCoefficient/4);
iColumn = iCoefficient % 4;
return tV[iRow][iColumn];
}
float4 PadePosP(float4 PosW)
{
//KCNote: This bit's changed
//so that it reads back
//perspective shift as distance
//from camera.
//perform Pade
float4 PosVP = float4(0,0,0,1);
float Pos2D[2];
float w[2];
for (int i=0; i<2; i++)
{
w[i] = (PosW.x*coefficient(i,4) +
PosW.y*coefficient(i,5) +
PosW.z*coefficient(i,6) +
coefficient(i,7));
Pos2D[i] = (PosW.x*coefficient(i,0) +
PosW.y*coefficient(i,1) +
PosW.z*coefficient(i,2) +
coefficient(i,3))
/ w[i];
}
return float4(Pos2D[0],Pos2D[1],(1-1/(w[0]+w[1]))/1000.0,1);
}
// - - - - pade END - - - -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment