-
Notifications
You must be signed in to change notification settings - Fork 1
/
Radial2.cpp
42 lines (36 loc) · 2.22 KB
/
Radial2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
kernel Radial_2 : ImageComputationKernel<ePixelWise>
{
Image<eRead,eAccessRandom,eEdgeClamped> src; //input image
Image<eWrite> dst; //output image
param:
float gamma; //gamma param
bool invert; //invert bool
local:
float xt; //width
float yt; //height
float2 position; //UV coordinates
float2 direction; //normalized UVs
float2 center; //center image
float distance; //center distance from bounds
float MaxDist; //vector from center to bounds
float distanceNorm; //normalized distance
float out;
void define(){
defineParam(gamma,"gamma",1.0f); //gamma default
defineParam(invert,"invert", false); //invert default
}
void init(int2 pos){
xt = src.bounds.x2; //bounds X
yt = src.bounds.y2; //bounds Y
center = float2(xt/2 , yt/2); //center image as float2
MaxDist = length(center); //vector from center to bounds
}
void process(int2 pos){
float2 position = float2 (pos.x, pos.y); //pixels positions X and Y
float2 direction = position - center; //offset position / new coordinates
float distance = length(direction); //distance of each pixel to bounds
float distanceNorm = distance / MaxDist; //normalized distance
float out = invert == true ? distanceNorm : 1.0f / distance; //invert conditional
dst() = pow(out,gamma);
}
};