pack4xU8Clamp
On this page

pack4xU8Clamp

Function

Integer byte packing combines components into one word.

Compare examples

Compare the components, hexadecimal word, and recovered values. Notice which component occupies the low field.

Example 1pack4xU8Clamp(vec4u(1, 2, 3, 4))
1234
Components in this example
Result
0x04030201
Word in binary: 67305985
Example 2pack4xU8Clamp(vec4u(255, 255, 255, 255))
255255255255
Components in this example
Result
0xffffffff
Word in binary: 4294967295
Example 3pack4xU8Clamp(vec4u(300, 300, 300, 300))
300300300300
Components in this example
Result
0xffffffff
Word in binary: 4294967295

The 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

This variant clamps each component before storing it. These integer byte operations are WebGPU-only in this compiler.

For shader input rules and precision, consult WGSL and GLSL ES 3.00.

The signature, the sentence and any message are the compiler's own text at commit af54ddad5.

Packs a vec4u into a u32 as four bytes, clamping each component into [0, 255] first.

Syntax

declare function pack4xU8Clamp(a0: vec4u): u32
declare function pack4xU8Clamp(e: vec4u): u32

Parameters

Return value

u32

Description

Not supported yet on the WebGL2 tier.

Targets

WGSL
pack4xU8Clamp(a)
GLSL ES 3.00
pack4xU8Clamp is not supported yet on the WebGL2 tier

Examples

See also

Edit this page Report a problem