77 const FloatRGB kWhite = { 1.0, 1.0, 1.0 };
78 float maxq = impress + bias;
80 float hi = 0.66667 * maxq;
82 float ih = 1.0 / (1.0 - hi);
90 return (
FloatRGB){ 1.0f, 1.0f, 1.0f };
94 return Blend(q * 100.0f, paleSeaColor, landColor);
98 return Blend((q - hi) * ih, paleLandColor, kWhite);
101 return Blend((hi - q) * oh, paleLandColor, landColor);
114+ (BOOL) getPlanetTextureNameFor:(NSDictionary *)planetInfo intoData:(
unsigned char **)textureData width:(GLuint *)textureWidth height:(GLuint *)textureHeight
119 int tex_bytes = texture_w * texture_h * 4;
121 NSParameterAssert(textureData != NULL && textureWidth != NULL && textureHeight != NULL);
123 unsigned char *imageBuffer = malloc(tex_bytes);
124 if (imageBuffer == NULL)
return NO;
126 *textureData = imageBuffer;
127 *textureWidth = texture_w;
128 *textureHeight = texture_h;
130 float land_fraction = [[
planetInfo objectForKey:@"land_fraction"] floatValue];
131 float sea_bias = land_fraction - 1.0;
141 FloatRGB pale_sea_color =
Blend(0.45, polar_sea_color,
Blend(0.7, sea_color, land_color));
153+ (BOOL) getCloudTextureNameFor:(
OOColor*)color :(GLfloat)impress :(GLfloat)bias intoData:(
unsigned char **)textureData width:(GLuint *)textureWidth height:(GLuint *)textureHeight
159 tex_bytes = texture_w * texture_h * 4;
161 NSParameterAssert(textureData != NULL && textureWidth != NULL && textureHeight != NULL);
163 unsigned char *imageBuffer = malloc(tex_bytes);
164 if (imageBuffer == NULL)
return NO;
166 *textureData = imageBuffer;
167 *textureWidth = texture_w;
168 *textureHeight = texture_h;
217static 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)
219 while (
x < 0 )
x+= width;
220 while (
y < 0 )
y+= width;
221 while (
x >= width )
x-= width;
222 while (
y >= width )
y-= width;
224 float q = accbuffer[ y * width + x];
229 float polar_y = (2.0f *
y - width) / (
float) width;
230 float polar_x = (2.0f *
x - width) / (
float) width;
236 q = q * (1.0 - polar_x) + polar_x * polar_x_value;
238 q = q * (1.0 - polar_y) + polar_y * polar_y_value;
240 if (q > 1.0) q = 1.0;
241 if (q < 0.0) q = 0.0;
249 NSCParameterAssert(width > 0);
251 float accbuffer[width * width];
252 memset(accbuffer, 0,
sizeof accbuffer);
263 while (octave < width)
265 addNoise(accbuffer, width, octave, scale);
270 float pole_value = (impress * accbuffer[0] - bias < 0.0)? 0.0: 1.0;
272 for (
y = 0;
y < width;
y++)
for (
x = 0;
x < width;
x++)
274 float q =
q_factor(accbuffer,
x,
y, width, YES, pole_value, NO, 0.0, impress, bias);
276 imageBuffer[0 + 4 * (y * width + x) ] = 255 * rgba[0];
277 imageBuffer[1 + 4 * (y * width + x) ] = 255 * rgba[1];
278 imageBuffer[2 + 4 * (y * width + x) ] = 255 * rgba[2];
279 imageBuffer[3 + 4 * (y * width + x) ] = 255 * rgba[3] * q;
282 NSString *name = [NSString stringWithFormat:@"atmosphere-%u-%u-old", sNoiseSeed.high, sNoiseSeed.low];
283 OOLog(
@"planetTex.dump", [NSString stringWithFormat:
@"Saving generated texture to file %@.", name]);
285 [[UNIVERSE gameView] dumpRGBAToFileNamed:name
299 float accbuffer[width * width];
300 memset(accbuffer, 0,
sizeof accbuffer);
304 while (octave < width)
306 addNoise(accbuffer, width, octave, scale);
311 float pole_value = (impress + bias > 0.5)? 0.5 * (impress + bias) : 0.0;
314 for (
y = 0;
y < width;
y++)
for (
x = 0;
x < width;
x++)
316 float q =
q_factor(accbuffer,
x,
y, width, YES, pole_value, NO, 0.0, impress, bias);
318 float yN =
q_factor(accbuffer,
x,
y - 1, width, YES, pole_value, NO, 0.0, impress, bias);
319 float yS =
q_factor(accbuffer,
x,
y + 1, width, YES, pole_value, NO, 0.0, impress, bias);
320 float yW =
q_factor(accbuffer,
x - 1,
y, width, YES, pole_value, NO, 0.0, impress, bias);
321 float yE =
q_factor(accbuffer,
x + 1,
y, width, YES, pole_value, NO, 0.0, impress, bias);
323 Vector norm = make_vector( 24.0 * (yW - yE), 24.0 * (yS - yN), 2.0);
325 norm = vector_normal(norm);
327 GLfloat shade = pow(norm.z, 3.2);
335 imageBuffer[0 + 4 * (y * width + x)] = 255 * color.
r;
336 imageBuffer[1 + 4 * (y * width + x)] = 255 * color.
g;
337 imageBuffer[2 + 4 * (y * width + x)] = 255 * color.
b;
338 imageBuffer[3 + 4 * (y * width + x)] = 255;
341 OOLog(
@"planetTex.dump", [NSString stringWithFormat:
@"Saving generated texture to file planet-%u-%u-old.",
sNoiseSeed.high,
sNoiseSeed.low]);
343 [[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