getValueFromTensorPos.es6 1.0 KB
Newer Older
Y
Yanzhan Yang 已提交
1 2 3 4 5 6 7
/* eslint-disable */
/**
 * @file 公共方法
 * @author yangmingming
 */
export default `
float getValueFromTensorPos_TENSOR_NAME(int r, int g, int b, int a) {
Y
yangmingming 已提交
8 9 10 11 12 13
    vec4 pixels = TEXTURE2D(texture_TENSOR_NAME, 
        vec2(
            (float(a * channel_TENSOR_NAME + g) + 0.5) / float(width_texture_TENSOR_NAME), 
            (float(r * height_shape_TENSOR_NAME + b) + 0.5) / float(height_texture_TENSOR_NAME)
        )
    );
Y
Yanzhan Yang 已提交
14 15 16
    return pixels.r;
}

Y
yangmingming 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29
float getValueFromTensorPosLimit_TENSOR_NAME(int r, int g, int b, int a) {
    float halfW = ceil(float(width_shape_TENSOR_NAME) / 2.0);
    int x = int(mod(float(a), halfW));
    int offsetY = 0;
    if (a > x) {
        offsetY = height_shape_TENSOR_NAME;
    }
    vec4 pixels = TEXTURE2D(texture_TENSOR_NAME, 
        vec2(
            (float(x * channel_TENSOR_NAME + g) + 0.5) / float(width_texture_TENSOR_NAME), 
            (float(r * 2 * height_shape_TENSOR_NAME + b + offsetY) + 0.5) / float(height_texture_TENSOR_NAME)
        )
    );
Y
Yanzhan Yang 已提交
30 31 32
    return pixels.r;
}
`;