forked from rodrigomas/DCTLs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix.dctl
34 lines (27 loc) · 1.05 KB
/
Matrix.dctl
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
// Example to demonstrate the usage of user defined matrix type to transform color
__CONSTANT__ float NORM[] = {1.0f / 3.0f, 1.0f / 3.0f, 1.0f / 3.0f};
typedef struct
{
float c00, c01, c02;
float c10, c11, c12;
} Matrix;
__DEVICE__ float2 applyTransformMatrix(const Matrix p_InMatrix, __CONSTANTREF__ float* p_InConstant)
{
float2 result;
result.x = _saturatef(p_InMatrix.c00 * p_InConstant[0] + p_InMatrix.c01 * p_InConstant[1] + p_InMatrix.c02 * p_InConstant[2]);
result.y = _saturatef(p_InMatrix.c10 * p_InConstant[0] + p_InMatrix.c11 * p_InConstant[1] + p_InMatrix.c12 * p_InConstant[2]);
return result;
}
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p_R, float p_G, float p_B)
{
Matrix mat;
mat.c00 = p_R * 1.2f;
mat.c01 = p_G * 0.5f;
mat.c02 = p_B * 0.8f;
mat.c10 = _logf(p_R);
mat.c11 = trunc(p_G);
mat.c12 = _sqrtf(p_B);
const float2 result = applyTransformMatrix(mat, &NORM[0]);
const float b = _fmaxf(mat.c02, mat.c12);
return make_float3(result.x, result.y, b);
}