nx_normal_decode_candidate_t279.nx source
↩ module page · 19 lines · 892 B
1import "nx_nxa_texbake_lib.nx"
2// Explicit normal-map transfer contracts; IDs are wire semantics, not inferred from pixels.
3// Numerators retain exact RGB8 quantization. Normalize the decoded vector after XY scale
4// and tangent-frame transformation; this decoder does not claim unit length or provenance.
5const NTB_NORMAL_ENCODING_NATIVE_MID_SCALE: i64 = 1
6const NTB_NORMAL_ENCODING_GLTF_UNORM: i64 = 2
7func ntb_normal_decode_rgb8(encoding:i64,r:i64,g:i64,b:i64,out3:*i64)->i64 {
8 if (out3 as i64)==0{return 0-1}
9 if r<0||r>NTB_GREY_MAX||g<0||g>NTB_GREY_MAX||b<0||b>NTB_GREY_MAX{return 0-2}
10 if encoding==NTB_NORMAL_ENCODING_NATIVE_MID_SCALE{
11 out3[0]=r-NTB_N_MID;out3[1]=g-NTB_N_MID;out3[2]=b-NTB_N_MID
12 return NTB_N_SCALE
13 }
14 if encoding==NTB_NORMAL_ENCODING_GLTF_UNORM{
15 out3[0]=2*r-NTB_GREY_MAX;out3[1]=2*g-NTB_GREY_MAX;out3[2]=2*b-NTB_GREY_MAX
16 return NTB_GREY_MAX
17 }
18 return 0-3
19}