Skip to content

Commit a0896b6

Browse files
move the decode functions to builtin/glsl/format/decode.glsl
1 parent fe4d1cf commit a0896b6

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

examples_tests/41.VisibilityBuffer/main.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,7 @@ R"(
2525
2626
layout(location = 4) flat out uint drawID; //TODO: override main
2727
28-
vec4 nbl_glsl_decodeRGB10A2_UNORM(in uint x)
29-
{
30-
const uvec4 shifted = uvec4(x,uvec3(x)>>uvec3(10,20,30));
31-
const uvec4 rgbaMask = uvec4(uvec3(0x3ffu),0x3u);
32-
return vec4(shifted&rgbaMask)/vec4(rgbaMask);
33-
}
34-
35-
vec4 nbl_glsl_decodeRGB10A2_SNORM(in uint x)
36-
{
37-
const ivec4 shifted = ivec4(x,uvec3(x)>>uvec3(10u,20u,30u));
38-
const ivec4 rgbaBias = ivec4(ivec3(0x200u),0x2u);
39-
const ivec4 halfMask = rgbaBias-ivec4(1);
40-
const ivec4 signed = (-(shifted&rgbaBias))|(shifted&halfMask);
41-
return max(vec4(signed)/vec4(halfMask),vec4(-1.0));
42-
}
28+
#include "nbl/builtin/glsl/format/decode.glsl"
4329
4430
//pos
4531
layout(set = 0, binding = 0) uniform samplerBuffer MeshPackedDataFloat[2];

include/nbl/builtin/glsl/format/decode.glsl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,20 @@ vec3 nbl_glsl_decodeRGB18E7S3(in uvec2 x)
4444
return v*scale;
4545
}
4646

47-
vec4 nbl_glsl_decodeRGB10A2(in uint x)
47+
vec4 nbl_glsl_decodeRGB10A2_UNORM(in uint x)
4848
{
4949
const uvec3 rgbMask = uvec3(0x3ffu);
5050
const uvec4 shifted = uvec4(x,uvec3(x)>>uvec3(10,20,30));
5151
return vec4(vec3(shifted.rgb&rgbMask),shifted.a)/vec4(vec3(rgbMask),3.0);
5252
}
53+
vec4 nbl_glsl_decodeRGB10A2_SNORM(in uint x)
54+
{
55+
const ivec4 shifted = ivec4(x, uvec3(x) >> uvec3(10u, 20u, 30u));
56+
const ivec4 rgbaBias = ivec4(ivec3(0x200u), 0x2u);
57+
const ivec4 halfMask = rgbaBias - ivec4(1);
58+
const ivec4 signed = (-(shifted & rgbaBias)) | (shifted & halfMask);
59+
return max(vec4(signed) / vec4(halfMask), vec4(-1.0));
60+
}
5361

5462

5563
nbl_glsl_quaternion_t nbl_glsl_decode8888Quaternion(in uint x)

0 commit comments

Comments
 (0)