Open
Conversation
bjornbytes
commented
Feb 6, 2026
| copyAttribute(vertices, tangents, SN10x3, 1, false, 28, sizeof(ModelVertex), vertexCount, 0); | ||
| copyAttribute(vertices, positions, F32, 3, false, 0, sizeof(ModelVertex), vertexCount, 0, false); | ||
| copyAttribute(vertices, normals, SN10x3, 1, false, 12, sizeof(ModelVertex), vertexCount, 0, false); | ||
| copyAttribute(vertices, uvs, U16, 2, true, 16, sizeof(ModelVertex), vertexCount, 0, true); |
Owner
Author
There was a problem hiding this comment.
Maybe we should only "supernormalize" if the UVs are actually outside of the 0-1 range. It gives worse precision, but means that the UV data can be used as-is in more cases (quad is optional more often)
bjornbytes
commented
Feb 6, 2026
| uint32_t material; | ||
| ModelDrawMode mode; | ||
| float bounds[6]; | ||
| float quad[4]; |
Owner
Author
There was a problem hiding this comment.
Still need to expose this in ModelData
bjornbytes
commented
Feb 6, 2026
| .material = model->materials && part->material != ~0u ? model->materials[part->material] : NULL, | ||
| .transform = transform, // TODO fix skinned mesh transforms? | ||
| .bounds = part->bounds, | ||
| .quad = part->quad, |
Owner
Author
There was a problem hiding this comment.
Worth passing NULL here (and in drawNode) if we know the part doesn't have a quad?
bjornbytes
commented
Feb 6, 2026
| if (accessor->type == F32 && accessor->components == 2) { | ||
| for (uint32_t i = 0; i < accessor->count; i++, data += stride) { | ||
| float* f = (float*) data; | ||
| accessor->min[0] = MIN(accessor->min[0], f[0]); |
Owner
Author
There was a problem hiding this comment.
Should initialize the min/max to FLT_MAX/-FLT_MAX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This tries to solve 2 problems:
Materialobject for each new rectangle, or writing a custom shader.Background
We'd like to switch to 16 bit unsigned normalized UVs to save space and keep model vertices at 32 bytes after we add the second UV set. However, this would mean that we could only support UVs that go from 0-1, which while very common, isn't an acceptable restriction.
To solve this, the model importer normalizes UV data to the 0-1 range and stores the original range of the UVs for each part. That way it's possible to take a compressed 16-bit 0-1 UV and reconstruct the original UV, even for floating point UVs. There is a minor precision loss.
However, we need to send this UV rectangle to shaders somehow. It would be possible to use Material for this, since it already has a UV rectangle, but it would get complicated if 2 meshes shared a material, and we would need to duplicate materials to fix it.
Solution
Another solution is to just add per-draw data for a UV rectangle, which 1) makes it possible for models to scale and bias their compressed UVs, and 2) provides a convenient way of adjusting texture UVs on a per-draw basis. This was added as
Pass:setQuad(x, y, w, h). This is intended to replace Material's uvShift and uvScale properties, eventually.Note that the quad only applies to the first UV set -- the second set of UVs are not transformed. UV2 is intended to be used for lightmapping, and it's rare for lightmap UVs to go outside of 0-1.
Drawbacks
VertexUVdata isn't the true UV anymore (but, like, normals/tangents are compressed too).Other stuff:
:setQuadnaming