Search across packages, versions, files, declarations, and comments. Use multiple terms to narrow results (AND), and add @vertex, @fragment, or @compute to filter by shader stage.
2fn decompress_vertex_position(compressed_position: vec4<f32>, aabb_center: vec3<f32>, aabb_half_extents: vec3<f32>) -> vec3<f32> {
3 return aabb_center + aabb_half_extents * compressed_position.xyz;
4}
6fn decompress_vertex_normal(compressed_normal: vec2<f32>) -> vec3<f32> {
7 return octahedral_decode_signed(compressed_normal);
8}
10fn decompress_vertex_tangent(compressed_tangent: vec2<f32>) -> vec4<f32> {
11 return octahedral_decode_tangent(compressed_tangent);
14fn decompress_vertex_uv(compressed_uv: vec2<f32>, uv_min_and_extents: vec4<f32>) -> vec2<f32> {
15 return uv_min_and_extents.xy + uv_min_and_extents.zw * compressed_uv;
18/// For decoding normals or unit direction vectors from octahedral coordinates. Input is [-1, 1].
19fn octahedral_decode_signed(v: vec2<f32>) -> vec3<f32> {
20 var n = vec3(v.xy, 1.0 - abs(v.x) - abs(v.y));
21 let t = saturate(-n.z);
22 let w = select(vec2(t), vec2(-t), n.xy >= vec2(0.0));
23 n = vec3(n.xy + w, n.z);
24 return normalize(n);
27/// Decode tangent vectors from octahedral coordinates and return the sign. Input is [-1, 1]. The y component should have been mapped to always be positive and then encoded the sign.
28fn octahedral_decode_tangent(v: vec2<f32>) -> vec4<f32> {
29 let sign = sign(v.y);
30 var f = v;
31 f.y = abs(f.y);
32 f.y = f.y * 2.0 - 1.0;
33 return vec4<f32>(octahedral_decode_signed(f), sign);
36/// https://jcgt.org/published/0003/02/01/paper.pdf
37/// For encoding normals or unit direction vectors as octahedral coordinates.
38fn octahedral_encode(v: vec3<f32>) -> vec2<f32> {
39 var n = v / (abs(v.x) + abs(v.y) + abs(v.z));
40 let octahedral_wrap = (1.0 - abs(n.yx)) * select(vec2(-1.0), vec2(1.0), n.xy >= vec2f(0.0));
41 let n_xy = select(octahedral_wrap, n.xy, n.z >= 0.0);
42 return n_xy * 0.5 + 0.5;
45/// For decoding normals or unit direction vectors from octahedral coordinates.
46fn octahedral_decode(v: vec2<f32>) -> vec3<f32> {
47 let f = v * 2.0 - 1.0;
48 return octahedral_decode_signed(f);
Contents