daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Jul 25th, 2015 114 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. float3 LensDistortionPass(float2 tex){
  2.         // lens distortion coefficient (between
  3.         float k = -0.15;
  4.  
  5.         // cubic distortion value
  6.         float kcube = 0.5;
  7.  
  8.         float r2 = (tex.x-0.5) * (tex.x-0.5) + (tex.y-0.5) * (tex.y-0.5);      
  9.         float f = 0.0;
  10.  
  11.         //only compute the cubic distortion if necessary
  12.         if (kcube == 0.0){
  13.                 f = 1 + r2 * k;
  14.         }
  15.         else {
  16.                 f = 1 + r2 * (k + kcube * sqrt(r2));
  17.         };
  18.  
  19.         // get the right pixel for the current position
  20.         float x = f*(tex.x-0.5)+0.5;
  21.         float y = f*(tex.y-0.5)+0.5;
  22.         float3 inputDistord = tex2D(tDiffuse,float2(x,y)).rgb;
  23.  
  24.         return inputDistord;
  25. }
  26.  
  27. float3 LensDistortionShader(float4 position : SV_Position, float2 texcoord : TEXCOORD0) : SV_Target {
  28.         float3 color = LensDistortionPass(texcoord).rgb;
  29.  
  30.         return color.rgb;
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top