// This will return the local terrain height at the given local position public float GetSurfaceHeightLocal(Vector3 localPosition) { var uv = SgtHelper.CartesianToPolarUV(localPosition); var color = SampleBilinear(uv); var height01 = default(float); switch (Encoding) { case EncodingType.Alpha: { height01 = color.a; } break; case EncodingType.RedGreen: { height01 = (color.r * 255.0f + color.g) / 256.0f; } break; } if (ZeroCutoff == true) { height01 = Mathf.InverseLerp(HeightmapCutoff, 1.0f, height01); } else { height01 = Mathf.Max(height01, HeightmapCutoff); } return(Mathf.Lerp(InnerRadius, OuterRadius, height01)); }
private void CalculateHeight(SgtVector3D localPosition, ref double height) { if (Heightmap != null) { var uv = SgtHelper.CartesianToPolarUV((Vector3)localPosition); var color = SampleBilinear(uv); var height01 = default(double); switch (Encoding) { case EncodingType.Alpha: { height01 = color.a; } break; case EncodingType.RedGreen: { height01 = (color.r * 255.0 + color.g) / 256.0; } break; } height += DisplacementMin + (DisplacementMax - DisplacementMin) * height01; } }
private float Sample(Vector3 vector) { var final = radius; if (displace == true && lastHeightmap != null) { var uv = SgtHelper.CartesianToPolarUV(vector); var land = lastHeightmap.GetPixelBilinear(uv.x, uv.y).a; if (clampWater == true) { final += displacement * Mathf.InverseLerp(Mathf.Clamp01(waterLevel), 1.0f, land); } else { final += displacement * Mathf.Max(land, waterLevel); } } return(final); }
private int GetCount(double3 point) { var weight = 1.0f; if (splat != null) { var uv = SgtHelper.CartesianToPolarUV((float3)point); var pixel = splat.GetPixelBilinear(uv.x, uv.y); switch (channel) { case ChannelType.Red: weight = pixel.r; break; case ChannelType.Green: weight = pixel.g; break; case ChannelType.Blue: weight = pixel.b; break; case ChannelType.Alpha: weight = pixel.a; break; } } return(Mathf.RoundToInt(count * weight)); }