getValueFromTensorPos.es6 1.4 KB
Newer Older
W
wangqun 已提交
1 2 3 4 5 6 7 8 9
/* eslint-disable */
/**
 * @file 公共方法
 * @author yangmingming
 * desc 根据tensor坐标获取这个tensor位置的值
 */
export default `
// 根据tensor坐标获取这个tensor位置的值
float getValueFromTensorPos_TENSOR_NAME(int r, int g, int b, int a) {
10
    vec4 pixels = TEXTURE2D(texture_TENSOR_NAME,
W
wangqun 已提交
11
        vec2(
12
            (float(a * channel_TENSOR_NAME + g) + 0.5) / float(width_texture_TENSOR_NAME),
W
wangqun 已提交
13 14 15 16 17 18
            (float(r * height_shape_TENSOR_NAME + b) + 0.5) / float(height_texture_TENSOR_NAME)
        )
    );
    // 只用了r通道
    return pixels.r;
}
19 20

// 超限布局根据tensor坐标获取这个tensor位置的值
W
wangqun 已提交
21
float getValueFromTensorPosLimit_TENSOR_NAME(int r, int g, int b, int a) {
22 23
    float pieceW = ceil(float(width_shape_TENSOR_NAME) / 4.0);
    int x = int(mod(float(a), pieceW));
W
wangqun 已提交
24
    int offsetY = 0;
25 26 27 28 29 30 31 32

    if ((float(a) / pieceW) >= 3.0) {
        offsetY = 3 * height_shape_TENSOR_NAME;
    }
    else if (float(a) / pieceW >= 2.0) {
        offsetY = 2 * height_shape_TENSOR_NAME;
    }
    else if (float(a) >= pieceW) {
W
wangqun 已提交
33 34
        offsetY = height_shape_TENSOR_NAME;
    }
35
    vec4 pixels = TEXTURE2D(texture_TENSOR_NAME,
W
wangqun 已提交
36
        vec2(
37 38
            (float(x * channel_TENSOR_NAME + g) + 0.5) / float(width_texture_TENSOR_NAME),
            (float(r * 4 * height_shape_TENSOR_NAME + b + offsetY) + 0.5) / float(height_texture_TENSOR_NAME)
W
wangqun 已提交
39 40 41 42
        )
    );
    return pixels.r;
}
43

W
wangqun 已提交
44
`;