pack4x8snorm
Function
Normalized packing maps a bounded floating-point interval onto integer fields.
Related names in other languages
These related operations can differ in arguments, support, and semantics. The foreign names are not accepted TypeShade aliases. Check the target forms and restrictions.
- GLSL:
packSnorm4x8
Compare examples
Compare the components, hexadecimal word, and recovered values. Notice which component occupies the low field.
Example 1pack4x8snorm(vec4(-1, 1, -1, 1))
-11-11 - Result
0x7f817f81
2139193217Example 2pack4x8snorm(vec4(0, 0, 0, 0))
0000 - Result
0x00000000
0Example 3pack4x8snorm(vec4(0.25, 0.25, 0.25, 0.25))
0.250.250.250.25 - Result
0x20202020
538976288The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.
When to use it
Use it to reduce storage or bandwidth when the reduced precision is acceptable.
Inputs and limits
Packing clamps to the normalized interval and quantizes values. Unpacking approximates the original value; the low field belongs to the first component.
For shader input rules and precision, consult WGSL and GLSL ES 3.00.
Related functions
- WGSL
pack4x8snorm(a)- GLSL ES 3.00
(uint(int(floor(0.5 + clamp(a.x, -1.0, 1.0) * 127.0)) & 0xFF) | (uint(int(floor(0.5 + clamp(a.y, -1.0, 1.0) * 127.0)) & 0xFF) << 8) | (uint(int(floor(0.5 + clamp(a.z, -1.0, 1.0) * 127.0)) & 0xFF) << 16) | (uint(int(floor(0.5 + clamp(a.w, -1.0, 1.0) * 127.0)) & 0xFF) << 24))
The signature, the sentence and any message are the compiler's own text at commit af54ddad5.
Packs a vec4 of values in [-1, 1] into the four bytes of a u32 as signed bytes, component 0 in the low byte.
Syntax
declare function pack4x8snorm(a0: vec4): u32declare function pack4x8snorm(e: vec4): u32Parameters
-
evec4
Return value
Description
Hand-inlined on GLSL ES 3.00, which has no packSnorm4x8 (that is ES 3.10).
Targets
- WGSL
-
pack4x8snorm(a) - GLSL ES 3.00
-
(uint(int(floor(0.5 + clamp(a.x, -1.0, 1.0) * 127.0)) & 0xFF) | (uint(int(floor(0.5 + clamp(a.y, -1.0, 1.0) * 127.0)) & 0xFF) << 8) | (uint(int(floor(0.5 + clamp(a.z, -1.0, 1.0) * 127.0)) & 0xFF) << 16) | (uint(int(floor(0.5 + clamp(a.w, -1.0, 1.0) * 127.0)) & 0xFF) << 24))