70 const FloatRGB kWhite = { 1.0, 1.0, 1.0 };
71 float maxq = impress + bias;
73 float hi = 0.66667 * maxq;
75 float ih = 1.0 / (1.0 - hi);
81 return (
FloatRGB) { 1.0f, 1.0f, 1.0f };
84 return Blend(q * 100.0f, paleSeaColor, landColor);
87 return Blend((q - hi) * ih, paleLandColor, kWhite);
90 return Blend((hi - q) * oh, paleLandColor, landColor);
100+ (BOOL)getPlanetTextureNameFor:(NSDictionary*)planetInfo intoData:(
unsigned char**)textureData width:(GLuint*)textureWidth height:(GLuint*)textureHeight
105 int tex_bytes = texture_w * texture_h * 4;
107 NSParameterAssert(textureData != NULL && textureWidth != NULL && textureHeight != NULL);
109 unsigned char* imageBuffer = malloc(tex_bytes);
110 if (imageBuffer == NULL)
113 *textureData = imageBuffer;
114 *textureWidth = texture_w;
115 *textureHeight = texture_h;
117 float land_fraction = [[
planetInfo objectForKey:@"land_fraction"] floatValue];
118 float sea_bias = land_fraction - 1.0;
128 FloatRGB pale_sea_color =
Blend(0.45, polar_sea_color,
Blend(0.7, sea_color, land_color));
139+ (BOOL)getCloudTextureNameFor:(
OOColor*)color impress:(GLfloat)impress bias:(GLfloat)bias intoData:(
unsigned char**)textureData width:(GLuint*)textureWidth height:(GLuint*)textureHeight
145 tex_bytes = texture_w * texture_h * 4;
147 NSParameterAssert(textureData != NULL && textureWidth != NULL && textureHeight != NULL);
149 unsigned char* imageBuffer = malloc(tex_bytes);
150 if (imageBuffer == NULL)
153 *textureData = imageBuffer;
154 *textureWidth = texture_w;
155 *textureHeight = texture_h;
201static float q_factor(
float* accbuffer,
int x,
int y,
int width, BOOL polar_y_smooth,
float polar_y_value, BOOL polar_x_smooth,
float polar_x_value,
float impress,
float bias)
212 float q = accbuffer[y * width + x];
217 float polar_y = (2.0f *
y - width) / (
float)width;
218 float polar_x = (2.0f *
x - width) / (
float)width;
224 q = q * (1.0 - polar_x) + polar_x * polar_x_value;
226 q = q * (1.0 - polar_y) + polar_y * polar_y_value;
238 NSCParameterAssert(width > 0);
240 float accbuffer[width * width];
241 memset(accbuffer, 0,
sizeof accbuffer);
252 while (octave < width) {
253 addNoise(accbuffer, width, octave, scale);
258 float pole_value = (impress * accbuffer[0] - bias < 0.0) ? 0.0 : 1.0;
260 for (
y = 0;
y < width;
y++)
261 for (
x = 0;
x < width;
x++) {
262 float q =
q_factor(accbuffer,
x,
y, width, YES, pole_value, NO, 0.0, impress, bias);
264 imageBuffer[0 + 4 * (y * width + x)] = 255 * rgba[0];
265 imageBuffer[1 + 4 * (y * width + x)] = 255 * rgba[1];
266 imageBuffer[2 + 4 * (y * width + x)] = 255 * rgba[2];
267 imageBuffer[3 + 4 * (y * width + x)] = 255 * rgba[3] * q;
270 NSString* name = [NSString stringWithFormat:@"atmosphere-%u-%u-old", sNoiseSeed.high, sNoiseSeed.low];
271 OOLog(
@"planetTex.dump", [NSString stringWithFormat:
@"Saving generated texture to file %@.", name]);
273 [[UNIVERSE gameView] dumpRGBAToFileNamed:name
287 float accbuffer[width * width];
288 memset(accbuffer, 0,
sizeof accbuffer);
292 while (octave < width) {
293 addNoise(accbuffer, width, octave, scale);
298 float pole_value = (impress + bias > 0.5) ? 0.5 * (impress + bias) : 0.0;
301 for (
y = 0;
y < width;
y++)
302 for (
x = 0;
x < width;
x++) {
303 float q =
q_factor(accbuffer,
x,
y, width, YES, pole_value, NO, 0.0, impress, bias);
305 float yN =
q_factor(accbuffer,
x,
y - 1, width, YES, pole_value, NO, 0.0, impress, bias);
306 float yS =
q_factor(accbuffer,
x,
y + 1, width, YES, pole_value, NO, 0.0, impress, bias);
307 float yW =
q_factor(accbuffer,
x - 1,
y, width, YES, pole_value, NO, 0.0, impress, bias);
308 float yE =
q_factor(accbuffer,
x + 1,
y, width, YES, pole_value, NO, 0.0, impress, bias);
314 GLfloat shade = pow(norm.
z, 3.2);
322 imageBuffer[0 + 4 * (y * width + x)] = 255 * color.
r;
323 imageBuffer[1 + 4 * (y * width + x)] = 255 * color.
g;
324 imageBuffer[2 + 4 * (y * width + x)] = 255 * color.
b;
325 imageBuffer[3 + 4 * (y * width + x)] = 255;
328 OOLog(
@"planetTex.dump", [NSString stringWithFormat:
@"Saving generated texture to file planet-%u-%u-old.",
sNoiseSeed.high,
sNoiseSeed.low]);
330 [[UNIVERSE gameView] dumpRGBAToFileNamed:[NSString stringWithFormat:@"planet-%u-%u-old", sNoiseSeed.high, sNoiseSeed.low]
static RANROTSeed sNoiseSeed
static FloatRGB PlanetTextureColor(float q, float impress, float bias, FloatRGB seaColor, FloatRGB paleSeaColor, FloatRGB landColor, FloatRGB paleLandColor)
static float ranNoiseBuffer[128 *128]
static FloatRGB FloatRGBFromDictColor(NSDictionary *dictionary, NSString *key)
static float q_factor(float *accbuffer, int x, int y, int width, BOOL polar_y_smooth, float polar_y_value, BOOL polar_x_smooth, float polar_x_value, float impress, float bias)
static void fillSquareImageDataWithCloudTexture(unsigned char *imageBuffer, int width, OOColor *cloudcolor, float impress, float bias)
static FloatRGB Blend(float fraction, FloatRGB a, FloatRGB b)
static void fillSquareImageWithPlanetTex(unsigned char *imageBuffer, int width, float impress, float bias, FloatRGB seaColor, FloatRGB paleSeaColor, FloatRGB landColor, FloatRGB paleLandColor)
static void addNoise(float *buffer, int p, int n, float scale)
#define PROC_TEXTURE_SIZE
void fillRanNoiseBuffer()
static NSString *const kOOLogPlanetTextureGen