SHARE
TWEET

Untitled

a guest Feb 27th, 2020 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. kernel RadialVectors : ImageComputationKernel<ePixelWise>
  2. {
  3.   Image<eRead, eAccessPoint, eEdgeClamped> src;  //the input image
  4.   Image<eWrite> dst;  //the output image
  5.  
  6.   param:
  7.     float ratio;  //This parameter is made available to the user.
  8.     float2 center;
  9.     float protect;
  10.     float rotate;
  11.     float gamma;
  12.     float multiply;
  13.     float2 size;
  14.  
  15.   local:
  16.  
  17.     float _imgDiag; //Image diagonal
  18.  
  19.   //In define(), parameters can be given labels and default values.
  20.   void define() {
  21.     defineParam(ratio, "Aspect Ratio", 1.0f);
  22.     defineParam(center, "Center", float2(1.0f,1.0f));
  23.     defineParam(protect, "Protect Center", 0.0f);
  24.     defineParam(rotate, "Rotate Vectors", 0.0f);
  25.     defineParam(gamma, "Gamma", 1.0f);
  26.     defineParam(multiply, "Multiply", 1.0f);
  27.   }
  28.  
  29.   //The init() function is run before any calls to kernel().
  30.   void init() {
  31.     _imgDiag = length(size);
  32.   }
  33.  
  34.   //The kernel function is run at every pixel to produce the output.
  35.   void process(int2 pos) {
  36.     //float2 posf = float2(pos.x, pos.y);
  37.     float2 posf = float2(src(0)*size.x, src(1)*size.y);
  38.     float2 v = posf-center;
  39.     v = v/(_imgDiag/2.0f);
  40.    
  41.     // Edit vector magnitude: Blackpoint+clamp for protecting center
  42.     if (protect < (1.0f)){ //If we protect the whole image then we don't need to output any vectors
  43.       // Edit aspect Ratio
  44.       v = float2(v.x, v.y * ratio);
  45.       // Find vector Magnitude so that can be edited
  46.       float magv = length(v);
  47.  
  48.       magv = max((magv - protect) / (1.0f-protect),0.0f);
  49.       magv = pow(magv, 1.0f/gamma);
  50.       float2 normv;
  51.       if (magv>0.0f){
  52.         normv = normalize(v);
  53.       }
  54.       else {
  55.         normv = float2(1.0f, 0.0f);
  56.       }
  57.       v = normv * magv;
  58.       // Rotate Normals
  59.       if (rotate != 0.0f){
  60.         float r = rotate * 3.141592653589793f / 180.0f;
  61.         v = float2( v.x * cos(r) - v.y * sin(r), v.x * sin(r) + v.y * cos(r));
  62.       }
  63.       // Multiply Output
  64.       //v = v * (_imgDiag/4) * multiply;
  65.       v = v * multiply;
  66.       dst() = float4(v.x, v.y, 0.0f, 0.0f);
  67.       //dst() = float4(magv, magv, magv, 0.0f);
  68.     }
  69.     else{
  70.       dst() = float4(0.0f);
  71.     }
  72.  
  73.    }
  74. };
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