Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- kernel RadialVectors : ImageComputationKernel<ePixelWise>
- {
- Image<eRead, eAccessPoint, eEdgeClamped> src; //the input image
- Image<eWrite> dst; //the output image
- param:
- float ratio; //This parameter is made available to the user.
- float2 center;
- float protect;
- float rotate;
- float gamma;
- float multiply;
- float2 size;
- local:
- float _imgDiag; //Image diagonal
- //In define(), parameters can be given labels and default values.
- void define() {
- defineParam(ratio, "Aspect Ratio", 1.0f);
- defineParam(center, "Center", float2(1.0f,1.0f));
- defineParam(protect, "Protect Center", 0.0f);
- defineParam(rotate, "Rotate Vectors", 0.0f);
- defineParam(gamma, "Gamma", 1.0f);
- defineParam(multiply, "Multiply", 1.0f);
- }
- //The init() function is run before any calls to kernel().
- void init() {
- _imgDiag = length(size);
- }
- //The kernel function is run at every pixel to produce the output.
- void process(int2 pos) {
- //float2 posf = float2(pos.x, pos.y);
- float2 posf = float2(src(0)*size.x, src(1)*size.y);
- float2 v = posf-center;
- v = v/(_imgDiag/2.0f);
- // Edit vector magnitude: Blackpoint+clamp for protecting center
- if (protect < (1.0f)){ //If we protect the whole image then we don't need to output any vectors
- // Edit aspect Ratio
- v = float2(v.x, v.y * ratio);
- // Find vector Magnitude so that can be edited
- float magv = length(v);
- magv = max((magv - protect) / (1.0f-protect),0.0f);
- magv = pow(magv, 1.0f/gamma);
- float2 normv;
- if (magv>0.0f){
- normv = normalize(v);
- }
- else {
- normv = float2(1.0f, 0.0f);
- }
- v = normv * magv;
- // Rotate Normals
- if (rotate != 0.0f){
- float r = rotate * 3.141592653589793f / 180.0f;
- v = float2( v.x * cos(r) - v.y * sin(r), v.x * sin(r) + v.y * cos(r));
- }
- // Multiply Output
- //v = v * (_imgDiag/4) * multiply;
- v = v * multiply;
- dst() = float4(v.x, v.y, 0.0f, 0.0f);
- //dst() = float4(magv, magv, magv, 0.0f);
- }
- else{
- dst() = float4(0.0f);
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement