Compiler2 min read

Packing Module

Portable packing helpers for normalized colors, half floats, octahedral normals, RGBE, and RGBM.

Reading Time
2 min
Word Count
289
Sections
6
Try It Live

Turn the guide into code

Take the key idea from this page into the playground and validate it in a real shader instead of leaving it as theory.

Open Playground

Portable packing helpers for normalized colors, half floats, octahedral normals, RGBE, and RGBM.

Import

bwsl
import Packing

This module imports: Math.

Constants

None.

Structs

No structs found.

Enums

No enums found.

Functions

pack_rgba8_unorm

Reference: https://registry.khronos.org/SPIR-V/specs/unified1/GLSL.std.450.html

bwsl
pack_rgba8_unorm :: (float4 color) -> uint

unpack_rgba8_unorm

Reference: https://registry.khronos.org/SPIR-V/specs/unified1/GLSL.std.450.html

bwsl
unpack_rgba8_unorm :: (uint packed) -> float4

pack_rg16_unorm

Packs RG color to 16-bit unsigned normalized channels using the built-in intrinsic.

bwsl
pack_rg16_unorm :: (float2 value) -> uint

unpack_rg16_unorm

Unpacks RG color from 16-bit unsigned normalized channels using the built-in intrinsic.

bwsl
unpack_rg16_unorm :: (uint packed) -> float2

pack_rgba8_snorm

Packs RGBA values to 8-bit signed normalized channels using the built-in intrinsic.

bwsl
pack_rgba8_snorm :: (float4 value) -> uint

unpack_rgba8_snorm

Unpacks RGBA values from 8-bit signed normalized channels using the built-in intrinsic.

bwsl
unpack_rgba8_snorm :: (uint packed) -> float4

pack_rg16_snorm

Packs RG values to 16-bit signed normalized channels using the built-in intrinsic.

bwsl
pack_rg16_snorm :: (float2 value) -> uint

unpack_rg16_snorm

Unpacks RG values from 16-bit signed normalized channels using the built-in intrinsic.

bwsl
unpack_rg16_snorm :: (uint packed) -> float2

pack_half2

Reference: https://en.wikipedia.org/wiki/Half-precision_floating-point_format

bwsl
pack_half2 :: (float2 value) -> uint

unpack_half2

Reference: https://en.wikipedia.org/wiki/Half-precision_floating-point_format

bwsl
unpack_half2 :: (uint packed) -> float2

oct_wrap

Reference: https://knarkowicz.wordpress.com/2014/04/16/octahedron-normal-vector-encoding/

bwsl
oct_wrap :: (float2 v) -> float2

encode_octahedral

Reference: https://jcgt.org/published/0003/02/01/

bwsl
encode_octahedral :: (float3 n) -> float2

decode_octahedral

Reference: https://jcgt.org/published/0003/02/01/

bwsl
decode_octahedral :: (float2 e) -> float3

pack_octahedral_16

Uses a uint container for compatibility with byte-packed vertex streams.

bwsl
pack_octahedral_16 :: (float3 n) -> uint

unpack_octahedral_16

Unpacks a normal from two 8-bit signed normalized octahedral components.

bwsl
unpack_octahedral_16 :: (uint packed) -> float3

pack_octahedral_32

Packs a normal into two 16-bit signed normalized octahedral components.

bwsl
pack_octahedral_32 :: (float3 n) -> uint

unpack_octahedral_32

Unpacks a normal from two 16-bit signed normalized octahedral components.

bwsl
unpack_octahedral_32 :: (uint packed) -> float3

pack_snorm10_10_10

This matches the existing vertex decompression convention in Compression.bwsl.

bwsl
pack_snorm10_10_10 :: (float3 value) -> uint

unpack_snorm10_10_10

Unpacks a signed vector from 10-10-10 unsigned storage into [-1, 1].

bwsl
unpack_snorm10_10_10 :: (uint packed) -> float3

pack_rgbe

Reference: https://en.wikipedia.org/wiki/RGBE_image_format

bwsl
pack_rgbe :: (float3 color) -> uint

unpack_rgbe

Reference: https://en.wikipedia.org/wiki/RGBE_image_format

bwsl
unpack_rgbe :: (uint packed) -> float3

encode_rgbm

Reference: https://graphicrants.blogspot.com/2009/04/rgbm-color-encoding.html

bwsl
encode_rgbm :: (float3 color, float maxRange) -> float4

decode_rgbm

Reference: https://graphicrants.blogspot.com/2009/04/rgbm-color-encoding.html

bwsl
decode_rgbm :: (float4 rgbm, float maxRange) -> float3

Source

Generated from compiler-reference/modules/Packing.bwsl.