Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Randomize textures from variants. #5837

Closed
wants to merge 2 commits into from

Conversation

will-ca
Copy link
Collaborator

@will-ca will-ca commented Dec 21, 2021

Pretend the letters are slightly different textures:

image

Adds ImageGetter.getRandomImageVariant(baseFileName: String, seed: Int? = null): String, which randomly chooses an image variant from all available, following the pattern: {"baseName", "baseName-A", "baseName-B", …, "baseName-Z"}.

Short-circuits quickly and should add only minimal overhead if there are no variants available.

Returned result is a new image path String, so it can further be used in other image-getting functions, like getLayeredImageColored. (Note the nation-coloured letters above.) (#3231 is also partly inspiration for this.)

Used in all invocations of .getImage in TileGroup, and only in TileGroup.

Hashcode of tile position Vector2 is used as seed for terrain-y images to make sure the map doesn't change during gameplay.

Added a var randomnessSeed: Int to MapUnit that is set on construction and preserved on .clone() for the same purpose. Currently @Transient, deciding a visual effect isn't worth a save file field. I could see myself getting attached to a special Frigate and getting sad when it's changed on a save reload or something, though.

I actually skimmed through all 118 invocations of .getImage(), and TileGroup was really the only place where it made sense to use random variants. It's just as well to have such a clearly defined scope.

Test files in above screenshot are available as example mod: https://github.com/will-ca/Unciv-Tileset-Variants-Example. If you fork it and tag the fork, I'll delete my repo to keep all the examples consolidated.


Why? Abstract reasons: Perfectly repeating patterns are very unnatural and jarring in textures. Randomly mixing just two or three variants is often enough to break up large-scale patterns a lot. Likewise clones don't exist, so slightly different units are always a really cool touch IMO.

Direct reason/Example: I was experimenting with breaking up coastlines/biomes with fractal and blended boundaries (#5835). Some results looked fairly natural. But repeating textures and patterns are still a big immersion breaker— What are the odds of there being fifty of the exact same, very distinctive mountain?

FantasyHex does a really good job hiding the repetition where possible and working it into the visual style otherwise. That gets harder with more realistic tilesets. I notice a lot more repetition with 5Hex. Contemplated CGI-generating a "photorealistic" tileset— Repetition would be a nightmare unless variants are possible.

@ravignir
Copy link
Contributor

It does not solve the issue for 5Hex without introducing new problems, that is forest/jungle tiles. When these tiles are improved, some trees stay on the same position (for example, compare lumber mill tiles with forest tiles, the trees would be misplaced if the game were to choose completely random texture from the available list).

@will-ca
Copy link
Collaborator Author

will-ca commented Dec 22, 2021

…So, there's an Ancient ruins.png and an Ancient ruins2.png, both of which get used… Which means that somewhere, in some way, some kind of functionality something like this is already in the game…

4fd869d

0c06237

I did search both the code and wiki for keywords… Evidently not thoroughly enough.

Well, compare and contrast, I guess. The code looks basically the same, just moved and used in more places. …IMO Letters would be a clearer convention since unit colours already use numbers, and I guess only one texture would have to be renamed…

@will-ca
Copy link
Collaborator Author

will-ca commented Dec 22, 2021

@ravignir I'm not sure I understand. This PR doesn't change how images are retrieved for improvements, though. It just adds more places where different variants can be provided by the tileset.

@yairm210
Copy link
Owner

We already have this - see TileGroup:254

@yairm210 yairm210 closed this Dec 22, 2021
@will-ca will-ca deleted the image-variants branch January 6, 2022 18:32
@will-ca will-ca restored the image-variants branch January 15, 2022 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants