|
3 | 3 | * @author yueshuangyan |
4 | 4 | */ |
5 | 5 |
|
| 6 | +// 根据tensor坐标获取对应纹理位置的pixel.r,返回值为 R 通道值 |
6 | 7 | export function getValueFromTensorPos( |
7 | 8 | textureName: string, |
8 | 9 | { width_shape, height_shape, channel, width_texture, height_texture } |
9 | 10 | ) { |
10 | 11 | const chw = width_shape * height_shape * channel; |
11 | 12 | const hw = width_shape * height_shape; |
12 | 13 | return ` |
13 | | - // 根据tensor坐标获取这个tensor位置的值 |
14 | 14 | float getValueFromTensorPos_${textureName}(int n, int c, int h, int w) { |
15 | 15 | int index = n * ${chw} + c * ${hw} + h * ${width_shape} + w; |
16 | | - int pos_w = int(mod(float(index), float(${width_texture}))); |
| 16 | + // 0.01 hack: 在 PC/WISE 机器上,出现某个值(比如 index 为 3520) float(index) 和 float(3520) 返回值不同的情况,目前 +0.01 hack |
| 17 | + int pos_w = int(mod(float(index) + 0.01, float(${width_texture}))); |
17 | 18 | int pos_h = index / int(${width_texture}); |
18 | 19 | vec4 pixels = TEXTURE2D(texture_${textureName}, |
19 | 20 | vec2( |
20 | 21 | (float(pos_w) + 0.5) / float(${width_texture}), |
21 | 22 | (float(pos_h) + 0.5) / float(${height_texture}) |
22 | 23 | ) |
23 | 24 | ); |
24 | | - // 只用了r通道 |
25 | 25 | return pixels.r; |
26 | 26 | }`; |
27 | 27 | } |
28 | 28 |
|
| 29 | +// 根据tensor坐标获取对应纹理位置的pixel,返回值为四通道值 RGBA |
29 | 30 | export function getValueFromTensorPosPacking( |
30 | 31 | textureName: string, |
31 | 32 | { channel, height_shape, width_texture, height_texture, width_shape } |
32 | 33 | ) { |
33 | 34 | const chw = width_shape * height_shape * channel; |
34 | 35 | const hw = width_shape * height_shape; |
35 | 36 | return ` |
36 | | - // 根据tensor坐标获取这个tensor位置的值 |
37 | 37 | vec4 getValueFromTensorPosPacking_${textureName}(int n, int c, int h, int w) { |
38 | 38 | int index = n * ${chw} + c * ${hw} + h * ${width_shape} + w; |
39 | | - int pos_w = int(mod(float(index), float(${width_texture}))); |
| 39 | + // 0.01 hack: 在 PC/WISE 设备上,出现某个值(比如 index 为 3520) float(index) 和 float(3520) 返回值不同的情况,目前 +0.01 hack |
| 40 | + int pos_w = int(mod(float(index) + 0.01, float(${width_texture}))); |
40 | 41 | int pos_h = index / int(${width_texture}); |
41 | 42 | vec4 pixels = TEXTURE2D(texture_${textureName}, |
42 | 43 | vec2( |
43 | 44 | (float(pos_w) + 0.5) / float(${width_texture}), |
44 | 45 | (float(pos_h) + 0.5) / float(${height_texture}) |
45 | 46 | ) |
46 | 47 | ); |
47 | | - // 只用了r通道 |
48 | 48 | return pixels; |
49 | 49 | }`; |
50 | 50 | } |
|
0 commit comments