Packing Module
Portable packing helpers for normalized colors, half floats, octahedral normals, RGBE, and RGBM.
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 PlaygroundPortable packing helpers for normalized colors, half floats, octahedral normals, RGBE, and RGBM.
Import
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
pack_rgba8_unorm :: (float4 color) -> uint
unpack_rgba8_unorm
Reference: https://registry.khronos.org/SPIR-V/specs/unified1/GLSL.std.450.html
unpack_rgba8_unorm :: (uint packed) -> float4
pack_rg16_unorm
Packs RG color to 16-bit unsigned normalized channels using the built-in intrinsic.
pack_rg16_unorm :: (float2 value) -> uint
unpack_rg16_unorm
Unpacks RG color from 16-bit unsigned normalized channels using the built-in intrinsic.
unpack_rg16_unorm :: (uint packed) -> float2
pack_rgba8_snorm
Packs RGBA values to 8-bit signed normalized channels using the built-in intrinsic.
pack_rgba8_snorm :: (float4 value) -> uint
unpack_rgba8_snorm
Unpacks RGBA values from 8-bit signed normalized channels using the built-in intrinsic.
unpack_rgba8_snorm :: (uint packed) -> float4
pack_rg16_snorm
Packs RG values to 16-bit signed normalized channels using the built-in intrinsic.
pack_rg16_snorm :: (float2 value) -> uint
unpack_rg16_snorm
Unpacks RG values from 16-bit signed normalized channels using the built-in intrinsic.
unpack_rg16_snorm :: (uint packed) -> float2
pack_half2
Reference: https://en.wikipedia.org/wiki/Half-precision_floating-point_format
pack_half2 :: (float2 value) -> uint
unpack_half2
Reference: https://en.wikipedia.org/wiki/Half-precision_floating-point_format
unpack_half2 :: (uint packed) -> float2
oct_wrap
Reference: https://knarkowicz.wordpress.com/2014/04/16/octahedron-normal-vector-encoding/
oct_wrap :: (float2 v) -> float2
encode_octahedral
Reference: https://jcgt.org/published/0003/02/01/
encode_octahedral :: (float3 n) -> float2
decode_octahedral
Reference: https://jcgt.org/published/0003/02/01/
decode_octahedral :: (float2 e) -> float3
pack_octahedral_16
Uses a uint container for compatibility with byte-packed vertex streams.
pack_octahedral_16 :: (float3 n) -> uint
unpack_octahedral_16
Unpacks a normal from two 8-bit signed normalized octahedral components.
unpack_octahedral_16 :: (uint packed) -> float3
pack_octahedral_32
Packs a normal into two 16-bit signed normalized octahedral components.
pack_octahedral_32 :: (float3 n) -> uint
unpack_octahedral_32
Unpacks a normal from two 16-bit signed normalized octahedral components.
unpack_octahedral_32 :: (uint packed) -> float3
pack_snorm10_10_10
This matches the existing vertex decompression convention in Compression.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].
unpack_snorm10_10_10 :: (uint packed) -> float3
pack_rgbe
Reference: https://en.wikipedia.org/wiki/RGBE_image_format
pack_rgbe :: (float3 color) -> uint
unpack_rgbe
Reference: https://en.wikipedia.org/wiki/RGBE_image_format
unpack_rgbe :: (uint packed) -> float3
encode_rgbm
Reference: https://graphicrants.blogspot.com/2009/04/rgbm-color-encoding.html
encode_rgbm :: (float3 color, float maxRange) -> float4
decode_rgbm
Reference: https://graphicrants.blogspot.com/2009/04/rgbm-color-encoding.html
decode_rgbm :: (float4 rgbm, float maxRange) -> float3
Source
Generated from compiler-reference/modules/Packing.bwsl.