// GetPixelHeightAlpha - Float public override HeightAlpha GetPixelHeightAlpha(float x, float y) { if (!IsLoaded) { if (OnDemandStorage.onDemandLogOnMissing) { Debug.Log("[OD] ERROR: getting pixelHeightAlphaF with unloaded map " + name + " of path " + Path + ", autoload = " + AutoLoad); } if (AutoLoad) { Load(); } else { return(new HeightAlpha(0f, 0f)); } } BilinearCoords coords = ConstructBilinearCoords(x, y); return(HeightAlpha.Lerp( HeightAlpha.Lerp( GetPixelHeightAlpha(coords.xFloor, coords.yFloor), GetPixelHeightAlpha(coords.xCeiling, coords.yFloor), coords.u), HeightAlpha.Lerp( GetPixelHeightAlpha(coords.xFloor, coords.yCeiling), GetPixelHeightAlpha(coords.xFloor, coords.yCeiling), coords.u), coords.v)); }
// ConstructBilinearCoords from double protected new BilinearCoords ConstructBilinearCoords(double x, double y) { // Create the struct BilinearCoords coords = new BilinearCoords(); // Floor x = Math.Abs(x - Math.Floor(x)); y = Math.Abs(y - Math.Floor(y)); // X to U coords.x = x * _width; coords.xFloor = (int)Math.Floor(coords.x); coords.xCeiling = (int)Math.Ceiling(coords.x); coords.u = (float)(coords.x - coords.xFloor); if (coords.xCeiling == _width) { coords.xCeiling = 0; } // Y to V coords.y = y * _height; coords.yFloor = (int)Math.Floor(coords.y); coords.yCeiling = (int)Math.Ceiling(coords.y); coords.v = (float)(coords.y - coords.yFloor); if (coords.yCeiling == this._height) { coords.yCeiling = 0; } // We're done return(coords); }
// GetPixelColor32 - Float - Honestly Squad, why are they named GetPixelColor32, but return normal Colors instead of Color32? public override Color GetPixelColor32(float x, float y) { if (!IsLoaded) { if (OnDemandStorage.onDemandLogOnMissing) { Debug.Log("[OD] ERROR: getting pixelCol32F with unloaded map " + name + " of path " + Path + ", autoload = " + AutoLoad); } if (AutoLoad) { Load(); } else { return(Color.black); } } BilinearCoords coords = ConstructBilinearCoords(x, y); return(Color32.Lerp( Color32.Lerp( this.GetPixelColor32(coords.xFloor, coords.yFloor), this.GetPixelColor32(coords.xCeiling, coords.yFloor), coords.u), Color32.Lerp( this.GetPixelColor32(coords.xFloor, coords.yCeiling), this.GetPixelColor32(coords.xCeiling, coords.yCeiling), coords.u), coords.v)); }
// GetPixelFloat - Double public override float GetPixelFloat(double x, double y) { if (!IsLoaded) { if (OnDemandStorage.onDemandLogOnMissing) { Debug.Log("[OD] ERROR: getting pixelFloatD with unloaded map " + name + " of path " + Path + ", autoload = " + AutoLoad); } if (AutoLoad) { Load(); } else { return(0f); } } BilinearCoords coords = ConstructBilinearCoords(x, y); return(Mathf.Lerp( Mathf.Lerp( GetPixelFloat(coords.xFloor, coords.yFloor), GetPixelFloat(coords.xCeiling, coords.yFloor), coords.u), Mathf.Lerp( GetPixelFloat(coords.xFloor, coords.yCeiling), GetPixelFloat(coords.xCeiling, coords.yCeiling), coords.u), coords.v)); }
/// GetPixelHeightAlpha - Float public HeightAlpha GetPixelHeightAlpha(Single x, Single y) { BilinearCoords coords = ConstructBilinearCoords(x, y); return(HeightAlpha.Lerp( HeightAlpha.Lerp( GetPixelHeightAlpha(coords.xFloor, coords.yFloor), GetPixelHeightAlpha(coords.xCeiling, coords.yFloor), coords.u), HeightAlpha.Lerp( GetPixelHeightAlpha(coords.xFloor, coords.yCeiling), GetPixelHeightAlpha(coords.xFloor, coords.yCeiling), coords.u), coords.v)); }
/// GetPixelFloat - Float public Single GetPixelFloat(Single x, Single y) { BilinearCoords coords = ConstructBilinearCoords(x, y); return(Mathf.Lerp( Mathf.Lerp( GetPixelFloat(coords.xFloor, coords.yFloor), GetPixelFloat(coords.xCeiling, coords.yFloor), coords.u), Mathf.Lerp( GetPixelFloat(coords.xFloor, coords.yCeiling), GetPixelFloat(coords.xCeiling, coords.yCeiling), coords.u), coords.v)); }
/// GetPixelColor32 - Float - Honestly Squad, why are they named GetPixelColor32, but return normal Colors instead of Color32? public Color GetPixelColor32(Single x, Single y) { BilinearCoords coords = ConstructBilinearCoords(x, y); return(Color32.Lerp( Color32.Lerp( this.GetPixelColor32(coords.xFloor, coords.yFloor), this.GetPixelColor32(coords.xCeiling, coords.yFloor), coords.u), Color32.Lerp( this.GetPixelColor32(coords.xFloor, coords.yCeiling), this.GetPixelColor32(coords.xCeiling, coords.yCeiling), coords.u), coords.v)); }
// Function taken from https://github.com/Kopernicus/pqsmods-standalone/blob/master/KSP/MapSO.cs L340 public static BilinearCoords ConstructBilinearCoords(Double x, Double y, MapSO heightMap) { // Create the struct BilinearCoords coords = new BilinearCoords(); // Floor x = x - Math.Truncate(x); y = y - Math.Truncate(y); if (x < 0) { x = 1.0 + x; } if (y < 0) { y = -y; } // X to U coords.x = x * heightMap.Width; if (coords.x >= heightMap.Width) { coords.x -= heightMap.Width; } coords.xFloor = (Int32)Math.Floor(coords.x); coords.xCeiling = (Int32)Math.Ceiling(coords.x); coords.u = (Single)(coords.x - Math.Truncate(coords.x)); if (coords.xCeiling >= heightMap.Width) { coords.xCeiling -= heightMap.Width; } // Y to V coords.y = y * heightMap.Height; if (coords.y >= heightMap.Height) { coords.y = heightMap.Height - 1 - (coords.y - heightMap.Height); } coords.yFloor = (Int32)Math.Floor(coords.y); coords.yCeiling = (Int32)Math.Ceiling(coords.y); coords.v = (Single)(coords.y - Math.Truncate(coords.y)); if (coords.yCeiling >= heightMap.Height) { coords.yCeiling = heightMap.Height - 1 - (coords.yCeiling - heightMap.Height); } // We're done return(coords); }
public static float SampleHeightmap16(Double u, Double v, MapSO heightMap, bool bits24) { if (heightMap == null || !heightMap.IsCompiled) { return(0); } BilinearCoords coords = VertexHeightMap16.ConstructBilinearCoords(u, v, heightMap); return(Mathf.Lerp( Mathf.Lerp( SingleSample(coords.xFloor, coords.yFloor, heightMap, bits24), SingleSample(coords.xCeiling, coords.yFloor, heightMap, bits24), coords.u), Mathf.Lerp( SingleSample(coords.xFloor, coords.yCeiling, heightMap, bits24), SingleSample(coords.xCeiling, coords.yCeiling, heightMap, bits24), coords.u), coords.v)); }
// ConstructBilinearCoords from double protected new BilinearCoords ConstructBilinearCoords(double x, double y) { // Create the struct BilinearCoords coords = new BilinearCoords(); // Floor x = Math.Abs(x - Math.Floor(x)); y = Math.Abs(y - Math.Floor(y)); // X to U coords.x = x * _width; coords.xFloor = (int)Math.Floor(coords.x); coords.xCeiling = (int)Math.Ceiling(coords.x); coords.u = (float)(coords.x - coords.xFloor); if (coords.xCeiling == _width) coords.xCeiling = 0; // Y to V coords.y = y * _height; coords.yFloor = (int)Math.Floor(coords.y); coords.yCeiling = (int)Math.Ceiling(coords.y); coords.v = (float)(coords.y - coords.yFloor); if (coords.yCeiling == this._height) coords.yCeiling = 0; // We're done return coords; }