Skip to content

Commit 1cbef4e

Browse files
committed
Fixed RGB19E7 encode in GLSL
1 parent 0dabfde commit 1cbef4e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

include/nbl/builtin/glsl/format/encode.glsl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ uvec2 nbl_glsl_encodeRGB19E7(in vec3 col)
88
const vec3 clamped = clamp(col,vec3(0.0),vec3(nbl_glsl_MAX_RGB19E7));
99
const float maxrgb = max(max(clamped.r,clamped.g),clamped.b);
1010

11-
const int f32_exp = bitfieldExtract(floatBitsToInt(maxrgb),23,8)-127;
12-
const int shared_exp = clamp(f32_exp,-nbl_glsl_RGB19E7_EXP_BIAS,nbl_glsl_MAX_RGB19E7_EXP);
11+
const int f32_exp = ((floatBitsToInt(maxrgb)>>23) & 0xff) - 127;
12+
const int shared_exp = clamp(f32_exp,-nbl_glsl_RGB19E7_EXP_BIAS-1,nbl_glsl_MAX_RGB19E7_EXP) + 1;
1313

14-
const uvec3 mantissas = uvec3(clamped*exp2(nbl_glsl_RGB19E7_MANTISSA_BITS-shared_exp));
14+
const uvec3 mantissas = uvec3(clamped*exp2(nbl_glsl_RGB19E7_MANTISSA_BITS-shared_exp) + 0.5);
1515

1616
uvec2 encoded;
1717
encoded.x = bitfieldInsert(mantissas.x,mantissas.y,nbl_glsl_RGB19E7_COMPONENT_BITOFFSETS[1],nbl_glsl_RGB19E7_G_COMPONENT_SPLIT);
18-
encoded.y = bitfieldInsert(mantissas.y>>nbl_glsl_RGB19E7_G_COMPONENT_SPLIT,mantissas.z,nbl_glsl_RGB19E7_COMPONENT_BITOFFSETS[2],nbl_glsl_RGB19E7_MANTISSA_BITS)|uint((shared_exp+nbl_glsl_RGB19E7_EXP_BIAS)<<nbl_glsl_RGB19E7_COMPONENT_BITOFFSETS[3]);
18+
encoded.y = bitfieldInsert(
19+
mantissas.y>>nbl_glsl_RGB19E7_G_COMPONENT_SPLIT,
20+
mantissas.z,
21+
nbl_glsl_RGB19E7_COMPONENT_BITOFFSETS[2],
22+
nbl_glsl_RGB19E7_MANTISSA_BITS)
23+
| uint((shared_exp+nbl_glsl_RGB19E7_EXP_BIAS)<<nbl_glsl_RGB19E7_COMPONENT_BITOFFSETS[3]);
1924

2025
return encoded;
2126
}

0 commit comments

Comments
 (0)