Paste Code
Paste Blends
Paste Images
/*
Cubic Lens Distortion HLSL Shader

Original Lens Distortion Algorithm from SSontech (Syntheyes)
http://www.ssontech.com/content/lensalg.htm

r2 = image_aspect*image_aspect*u*u + v*v
f = 1 + r2*(k + kcube*sqrt(r2))
u' = f*u
v' = f*v

author : François Tarlier
website : www.francois-tarlier.com/blog/index.php/2009/11/cubic-lens-distortion-shader

*/


sampler s0 : register(s0);

float4 main(float2 tex : TEXCOORD0) : COLOR
{

// lens distortion coefficient (between
float k = -0.15;

// cubic distortion value
float kcube = 0.5;


float r2 = (tex.x-0.5) * (tex.x-0.5) + (tex.y-0.5) * (tex.y-0.5);
float f = 0;


//only compute the cubic distortion if necessary
if( kcube == 0.0){
f = 1 + r2 * k;
}else{
f = 1 + r2 * (k + kcube * sqrt(r2));
};

// get the right pixel for the current position
float x = f*(tex.x-0.5)+0.5;
float y = f*(tex.y-0.5)+0.5;
float3 inputDistord = tex2D(s0,float2(x,y));


return float4(inputDistord.r,inputDistord.g,inputDistord.b,1);
}
  1. /*
  2.         Cubic Lens Distortion HLSL Shader
  3.        
  4.         Original Lens Distortion Algorithm from SSontech (Syntheyes)
  5.         http://www.ssontech.com/content/lensalg.htm
  6.        
  7.         r2 = image_aspect*image_aspect*u*u + v*v
  8.         f = 1 + r2*(k + kcube*sqrt(r2))
  9.         u' = f*u
  10.         v' = f*v
  11.  
  12.         author : François Tarlier
  13.         website : www.francois-tarlier.com/blog/index.php/2009/11/cubic-lens-distortion-shader
  14.  
  15. */
  16.  
  17.  
  18. sampler s0 : register(s0);
  19.  
  20. float4 main(float2 tex : TEXCOORD0) : COLOR
  21. {
  22.        
  23.         // lens distortion coefficient (between
  24.         float k = -0.15;
  25.        
  26.         // cubic distortion value
  27.         float kcube = 0.5;
  28.        
  29.        
  30.         float r2 = (tex.x-0.5) * (tex.x-0.5) + (tex.y-0.5) * (tex.y-0.5);       
  31.         float f = 0;
  32.        
  33.  
  34.         //only compute the cubic distortion if necessary
  35.         if( kcube == 0.0){
  36.                 f = 1 + r2 * k;
  37.         }else{
  38.                 f = 1 + r2 * (k + kcube * sqrt(r2));
  39.         };
  40.        
  41.         // get the right pixel for the current position
  42.         float x = f*(tex.x-0.5)+0.5;
  43.         float y = f*(tex.y-0.5)+0.5;
  44.         float3 inputDistord = tex2D(s0,float2(x,y));
  45.  
  46.  
  47.         return float4(inputDistord.r,inputDistord.g,inputDistord.b,1);
  48. }
go to heaven