1.4.5 • Published 7 months ago

@maptalks/tbn-packer v1.4.5

Weekly downloads
27
License
MIT
Repository
github
Last release
7 months ago

tbn-packer

Circle CI

Pack tangent and normal data into a quaternion, a useful tech published by crytek to compress data push to GPU.

This is ported from C++ implementation of google filament.

Usage

import { packTangentFrame, unpackQuaternion } from "@maptalks/tbn-packer";
const tangent = [1, 0, 0, 1];
const normal = [0, 1, 0];

const q = [];
//pack tangent and normal to a quaternion
packTangentFrame(q, normal, tangent);
const n = [], t = [];
//unpack a given quaternion to a normal and tangent.
unpackQuaternion(q, n, t);

GLSL Code to unpack

From google filament:

/**
 * Extracts the normal vector of the tangent frame encoded in the specified quaternion.
 */
void toTangentFrame(const highp vec4 q, out highp vec3 n) {
    n = vec3( 0.0,  0.0,  1.0) +
        vec3( 2.0, -2.0, -2.0) * q.x * q.zwx +
        vec3( 2.0,  2.0, -2.0) * q.y * q.wzy;
}

/**
 * Extracts the normal and tangent vectors of the tangent frame encoded in the
 * specified quaternion.
 */
void toTangentFrame(const highp vec4 q, out highp vec3 n, out highp vec3 t) {
    toTangentFrame(q, n);
    t = vec3( 1.0,  0.0,  0.0) +
        vec3(-2.0,  2.0, -2.0) * q.y * q.yxw +
        vec3(-2.0,  2.0,  2.0) * q.z * q.zwx;
}

Install

npm i @maptalks/tbn-packer

Test

npm test
1.4.5

7 months ago

1.4.4

7 months ago

1.4.3

7 months ago

1.4.2

7 months ago

1.4.1

7 months ago

1.4.0

9 months ago

1.3.0

9 months ago

1.2.8

2 years ago

1.2.7

3 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago