Probabilistic duplicated texture detection#8
Open
rainbow-eagle wants to merge 2 commits into
Open
Conversation
…ough. - The command line argument "-m" can be used to set a tolerance threshold above which 2 textures are considered identical (threshold between 0.0 and 100.0). NOTE: The full length argument "--texture-merge-threshold" does not work for now. Probably because of an issue in the argument parsin system. - Textures reuse also works for triangle polygons (without breaking the vertex2 = vertex3 rule). - Whether texture are identical is detected even if they are mirrored vertically, horizontally, or both (also works for triangle polygons). - Texture comparison is based on the shapes traced by the UVs (and no longer on the UV coordinates themselves) and texture content within the shape. Texture content is compared with a custom algorithm. - Some old commented code contains 2 other texture content comparison methods that were rejected.
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.
Added an option allowing the user to define a similarity threshold beyond which 2 textures will be considered identical. That way, more textures are reused, less textures are generated and space is saved in VRAM.
Texture duplication is expanded to triangular polygons.
If the new option is not used, the behavior defaults to pixel perfect match like before (except that pixel perfect triangle polygon textures duplication is still handled, contrary to before).
Note on testing and performance
Tested on specifically made test cases + random models extracted from actual games.
On the random models, the VRAM usage diminution is on average
~4.3% of the initial VRAM usage if pixel perfect match (thanks to reuse of texture for triangular polygons)
~15,5% of the initial VRAM usage if the threshold is set to 70.0 (without visibly altering the resulting models). The rate lies between 6 and 31%. The large standard deviation is explained by the variety of models: a more symmetrical model will contain more opportunities to reuse textures.
Special Use Case
This option allows to solve a potential issue when converting a model designed to be used with traditional (i.e. non-Saturn) texturing approach. In the illustrated example, a same region of the texture image is reused by many different UVs that are vaguely located on top of one another (on the left of the first illustration below). On the PS1, for which the model was designed, this is a smart way to texture a model without any extra cost in memory. But on the Sega Saturn, the converter would create a different image for each polygon, which explodes in memory and goes way beyond the 100% VRAM usage for this model alone.
Using the new option with a large tolerance threshold, the exporter can decide to reuse the same texture for all these different shapes. The second illustration compares the result of exporting the model without using the option (left) and using the option with the threshold 50 (right). Without option we see that textures are missing from many polygons because the VRAM is full. On the right, very decent texturing is obtained and memory usage falls down to 29% of VRAM.
Issue with argument handling
The short option "-m " works fine, but the longer version "texture-merge-threshold " seems to be ignored.