-
Notifications
You must be signed in to change notification settings - Fork 20
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
FastBiomeQuery #151
base: dev
Are you sure you want to change the base?
FastBiomeQuery #151
Conversation
…, need to condition BiomeMapOptimizer from a KSPCF patch - MapSOCorrectWrapping : fixed some issues and improved performance a bit
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
On a side note, I did a bit of perf profiling between the Kopernicus "biome cache" used by Parallax and the FastBiomeQuery I think I will look into pushing the FastBiomeQuery implementation as a Koperncius PR as well as a KSPCF patch. The existing Kop biome sampler can be rewired to use it, and I can disable the KSPCF patch when Koperncius is present. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
For reference, the Kopernicus implementation of this patch has been released. |
The stock biome maps (
CBAttributeMapSO
class) store a texture as RGB color data in a byte array where every pixel takes 3 bytes. Each biome definition (CBAttributeMapSO.MapAttribute
) is given a specific color, and is stored in an array.Querying a biome at a position (
CBAttributeMapSO.GetAtt()
) is a complex method that perform bilinear interpolation on that color array, attempts to find the closest color in the biome definition array, and does a bunch of heuristics in case the texture colors don't exactly match the ones defined in the biome definitions.Some issues with this :
This is a replacement for the stock class, implemented as a
KSPCFFastBiomeMap
class deriving fromCBAttributeMapSO
:CBAttributeMapSO
or from aTexture2D
), following the same heuristics as the stockGetAtt()
method, allowing upfront validation of biome map, and preventing having to do it on every query.CBAttributeMapSO.GetAtt()
method doing a direct lookup for the biome index instead of parsing colors, performing a correct bilinear interpolation.The benefits are :
GetAtt()
), unaffected by biome count. On average 15-20x faster than the stock implementation, up to 30x on bodies with a large amount of biomes.Drawbacks :
CBAttributeMapSO
instances into aKSPCFFastBiomeMap
. This is performed afterPSystemSetup
to catch Kopernicus changes, and before the main menu is loaded. The conversion is multithreaded, but it will introduce a perceptible delay on lower end machines. For reference, on a 5800X3D :While I think this is acceptable, it should be noted that doing this in the context of biome maps loaded by Kopernicus is utterly inefficient, as the complete chain of events is something like :
byte[]
from diskColor32[]
, then copy it as aTexture2D
, in other cases it relies on Unity to perform the conversion from thebyte[]
to aTexture2D
.CBAttributeMapSO
parser, which :Color32[]
Color32[]
to a 3Bpp RGB databyte[]
byte[]
to produce a biome indices 1Bppbyte[]
, with aColor32[]
conversion in between.It would be vastly more efficient for Kopernicus to directly feed the KSPCF implementation the
Texture2D
orColor32[]
without the useless conversion to aCBAttributeMapSO
in between. This is difficult to implement from the KSPCF side (at least efficiently). Aside, Kopernicus would benefit from an overhaul of its biome querying stuff, so it seems more sensible to actually have a side by side implementation of the KSPCF fast biome in Kopernicus.From a practial PoV, I will be AWOL from the KSP modding scene for some time, effective right now. Consequently, I will delay pushing this patch to KSPCF in case there are issues popping up that require some fixing. Plus I would like to contribute that work to Kopernicus, ideally synchronizing that feature release both in KSPCF and Kopernicus.
In the meantime, here is a build with the changes, for those willing to test it :
KSPCommunityFixes_1.29.0_FastBiomeQueryPR.zip
For reference, this illustrate the bug with biome transitions in the stock bilinear sampler :