- Planet textures: corrected wrapping method for latitude, minor code cleanup.
git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@2886 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
parent
d417f6390b
commit
4d9f8efb44
@ -80,6 +80,8 @@ enum
|
|||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
static int heightMask, widthMask;
|
||||||
|
|
||||||
static FloatRGB FloatRGBFromDictColor(NSDictionary *dictionary, NSString *key);
|
static FloatRGB FloatRGBFromDictColor(NSDictionary *dictionary, NSString *key);
|
||||||
|
|
||||||
static void FillNoiseBuffer(float *noiseBuffer, RANROTSeed seed);
|
static void FillNoiseBuffer(float *noiseBuffer, RANROTSeed seed);
|
||||||
@ -123,7 +125,7 @@ enum
|
|||||||
_planetScale = 3; // 1024x1024
|
_planetScale = 3; // 1024x1024
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
_planetScale = 5;
|
_planetScale = 5; //4096x4096
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,6 +258,8 @@ enum
|
|||||||
|
|
||||||
height = 1 << (_planetScale + kPlanetScaleOffset);
|
height = 1 << (_planetScale + kPlanetScaleOffset);
|
||||||
width = height * kPlanetAspectRatio;
|
width = height * kPlanetAspectRatio;
|
||||||
|
heightMask = height - 1;
|
||||||
|
widthMask = width - 1;
|
||||||
|
|
||||||
buffer = malloc(4 * width * height);
|
buffer = malloc(4 * width * height);
|
||||||
if (buffer == NULL) goto END;
|
if (buffer == NULL) goto END;
|
||||||
@ -541,14 +545,19 @@ static void AddNoise(float *buffer, unsigned width, unsigned height, float octav
|
|||||||
|
|
||||||
static float QFactor(float *accbuffer, int x, int y, unsigned width, unsigned height, float rHeight, float polar_y_value, float bias)
|
static float QFactor(float *accbuffer, int x, int y, unsigned width, unsigned height, float rHeight, float polar_y_value, float bias)
|
||||||
{
|
{
|
||||||
x = (x + width) & (width - 1);
|
// Correct Y wrapping mode, unoptimised.
|
||||||
// FIXME: wrong wrapping mode for Y, should flip to other hemisphere.
|
//if (y < 0) { y = -y; x += width / 2; }
|
||||||
y = (y + height) & (height - 1);
|
//else if (y >= height) { y -= y + 1 - height; x += width / 2; }
|
||||||
|
|
||||||
|
// Correct Y wrapping mode, faster method. In the following lines of code, both
|
||||||
|
// width and height are assumed to be powers of 2: 512, 1024, 2048, etc...
|
||||||
|
if (y & height) { y = (y ^ heightMask) & heightMask; x += width >> 1; }
|
||||||
|
x &= widthMask;
|
||||||
|
|
||||||
float q = accbuffer[y * width + x]; // 0.0 -> 1.0
|
float q = accbuffer[y * width + x]; // 0.0 -> 1.0
|
||||||
q += bias;
|
q += bias;
|
||||||
|
|
||||||
// Polar Y smooth. FIXME: float/int conversions.
|
// Polar Y smooth.
|
||||||
float polar_y = (2.0f * y - height) * rHeight;
|
float polar_y = (2.0f * y - height) * rHeight;
|
||||||
polar_y *= polar_y;
|
polar_y *= polar_y;
|
||||||
q = q * (1.0f - polar_y) + polar_y * polar_y_value;
|
q = q * (1.0f - polar_y) + polar_y * polar_y_value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user