Last active
December 27, 2015 10:39
-
-
Save wilg/7313263 to your computer and use it in GitHub Desktop.
This file contains 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
public Color GetInterpolatedPixel(float x, float y, float z) { | |
x = Mathf.Clamp(x, 0, size - 1); | |
y = Mathf.Clamp(y, 0, size - 1); | |
z = Mathf.Clamp(z, 0, size - 1); | |
int lowerX = Mathf.Clamp(Mathf.FloorToInt(x), 0, size - 1); | |
int upperX = Mathf.Clamp(lowerX + 1, 0, size - 1); | |
int lowerY = Mathf.Clamp(Mathf.FloorToInt(y), 0, size - 1); | |
int upperY = Mathf.Clamp(lowerY + 1, 0, size - 1); | |
int lowerZ = Mathf.Clamp(Mathf.FloorToInt(z), 0, size - 1); | |
int upperZ = Mathf.Clamp(lowerZ + 1, 0, size - 1); | |
Color C000 = GetPixel(lowerX, lowerY, lowerZ); | |
Color C010 = GetPixel(lowerX, lowerY, upperZ); | |
Color C100 = GetPixel(upperX, lowerY, lowerZ); | |
Color C001 = GetPixel(lowerX, upperY, lowerZ); | |
Color C110 = GetPixel(upperX, lowerY, upperZ); | |
Color C111 = GetPixel(upperX, upperY, upperZ); | |
Color C101 = GetPixel(upperX, upperY, lowerZ); | |
Color C011 = GetPixel(lowerX, upperY, upperZ); | |
Color C00 = Color.Lerp(C000, C100, upperX - x); | |
Color C10 = Color.Lerp(C010, C110, upperX - x); | |
Color C01 = Color.Lerp(C001, C101, upperX - x); | |
Color C11 = Color.Lerp(C011, C111, upperX - x); | |
Color C1 = Color.Lerp(C01, C11, upperZ - z); | |
Color C0 = Color.Lerp(C00, C10, upperZ - z); | |
return Color.Lerp(C0, C1, upperY - y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment