aboutsummaryrefslogtreecommitdiff
path: root/contrib/cgltf-tangents/README.md
blob: 2a68b27fedd52b67f9cad17e5ce62569fa3c429c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# cgltf-tangents

A library to compute missing tangent vectors in glTF models using MikkTSpace.

## Example

```
// Load the glTF scene and buffers as usual.
cgltf_result result = cgltf_parse_file(&options, filepath, &data);
cgltf_load_buffers(&options, data, filepath);

// Compute missing tangents.
cgltfTangentBuffer* tangent_buffers = 0;
cgltf_size num_tangent_buffers = 0;
cgltf_compute_tangents(&options, data, &tangent_buffers, &num_tangent_buffers);
```

## About

This is a single-header/source library that combines
[MikkTSpace](https://github.com/mmikk/MikkTSpace) and
[cgltf](https://github.com/jkuhlmann/cgltf) to compute missing tangent vectors
for models.

Mesh primitives in glTF may have a normal map but not necessarily tangent
vectors. An example is the
[DamagedHelmet](https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/DamagedHelmet/glTF)
sample. From the
[spec](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#meshes):

*"When tangents are not specified, client implementations SHOULD calculate
tangents using default MikkTSpace algorithms with the specified vertex
positions, normals, and texture coordinates associated with the normal texture."*

cgltf-tangents takes an input glTF scene and scans it for mesh primitives that
have a normal map but no tangents. cgltf-tangents then invokes MikkTSpace to
compute tangents for those mesh primitives and outputs an array of tangent
buffers. The client can then upload these buffers to GPU memory for rendering.

See `test/` for a complete example.

MikkTSpace is packaged here for convenience. cgltf must be obtained separately.