Skip to content

Commit

Permalink
Merge pull request zeux#634 from zeux/gltf-vnf
Browse files Browse the repository at this point in the history
gltfpack: Introduce optional floating-point normal quantization
  • Loading branch information
zeux authored Nov 17, 2023
2 parents a5ad826 + e3aab8b commit 8bac922
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions gltf/gltfpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,10 @@ int main(int argc, char** argv)
{
settings.tex_float = true;
}
else if (strcmp(arg, "-vnf") == 0)
{
settings.nrm_float = true;
}
else if (strcmp(arg, "-at") == 0 && i + 1 < argc && isdigit(argv[i + 1][0]))
{
settings.trn_bits = clamp(atoi(argv[++i]), 1, 24);
Expand Down Expand Up @@ -1582,9 +1586,9 @@ int main(int argc, char** argv)
return 1;
}

if (settings.fallback && (settings.pos_float || settings.tex_float))
if (settings.fallback && (settings.pos_float || settings.tex_float || settings.nrm_float))
{
fprintf(stderr, "Option -cf can not be used together with -vpf or -tpf\n");
fprintf(stderr, "Option -cf can not be used together with -vpf, -vtf or -vnf\n");
return 1;
}

Expand Down
1 change: 1 addition & 0 deletions gltf/gltfpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ struct Settings
bool pos_normalized;
bool pos_float;
bool tex_float;
bool nrm_float;

int trn_bits;
int rot_bits;
Expand Down
4 changes: 4 additions & 0 deletions gltf/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,10 @@ StreamFormat writeVertexStream(std::string& bin, const Stream& stream, const Qua
if (!settings.quantize)
return writeVertexStreamRaw(bin, stream, cgltf_type_vec3, 3);

// expand the encoded range to ensure it covers [0..1) interval
if (settings.nrm_float)
return writeVertexStreamFloat(bin, stream, cgltf_type_vec3, 3, settings, settings.nrm_bits, /* min_exp= */ 0);

bool oct = settings.compressmore && stream.target == 0;
int bits = settings.nrm_bits;

Expand Down

0 comments on commit 8bac922

Please sign in to comment.