Oolite
Loading...
Searching...
No Matches
OOPlanetTextureGenerator.m
Go to the documentation of this file.
1/*
2 OOPlanetTextureGenerator.m
3
4 Generator for planet diffuse maps.
5
6
7 Oolite
8 Copyright (C) 2004-2013 Giles C Williams and contributors
9
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23 MA 02110-1301, USA.
24*/
25
26#import "OOFoundation.h"
27#import "OOStellarBody.h"
28
29#if NEW_PLANETS
30
31#define DEBUG_DUMP (0 && OOLITE_DEBUG)
32#define DEBUG_DUMP_RAW (1 && DEBUG_DUMP)
33
34#define POLAR_CAPS 1
35#define ALBEDO_FACTOR 0.7f // Overall darkening of everything, allowing better contrast for snow and specular highlights.
36
38#import "OOColor.h"
40
41#ifndef TEXGEN_TEST_RIG
42#import "OOTexture.h"
43#import "Universe.h"
44#endif
45
46#if DEBUG_DUMP
47#import "MyOpenGLView.h"
48#endif
49
50#define FREE(x) \
51 do { \
52 if (0) { \
53 void* x__ = x; \
54 x__ = x__; \
55 } /* Preceeding is for type checking only. */ \
56 void** x_ = (void**)&(x); \
57 free(*x_); \
58 *x_ = NULL; \
59 } while (0)
60
61#define PLANET_TEXTURE_OPTIONS (kOOTextureMinFilterLinear | kOOTextureMagFilterLinear | kOOTextureRepeatS | kOOTextureNoShrink)
62
63enum {
64 kRandomBufferSize = 128
65};
66
67/* The planet generator actually generates two textures when shaders are
68 active, but the texture loader interface assumes we only load/generate
69 one texture per loader. Rather than complicate that, we use a mock
70 generator for the normal/light map.
71*/
72@interface OOPlanetNormalMapGenerator : OOTextureGenerator {
73@private
74 BOOL _enqueued;
75 NSString* _cacheKey;
76 RANROTSeed _seed;
77}
78
79- (id)initWithCacheKey:(NSString*)cacheKey seed:(RANROTSeed)seed;
80
81- (void)completeWithData:(void*)data width:(unsigned)width height:(unsigned)height;
82
83- (BOOL)enqueued;
84
85@end
86
87// Doing the same as above for the atmosphere.
88@interface OOPlanetAtmosphereGenerator : OOTextureGenerator {
89@private
90 BOOL _enqueued;
91 NSString* _cacheKey;
92 RANROTSeed _seed;
93 OOPlanetTextureGenerator* _parent;
94}
95
96- (id)initWithCacheKey:(NSString*)cacheKey seed:(RANROTSeed)seed andParent:(OOPlanetTextureGenerator*)parent;
97
98- (void)completeWithData:(void*)data width:(unsigned)width height:(unsigned)height;
99
100- (BOOL)enqueued;
101
102@end
103
104@interface OOPlanetTextureGenerator (Private)
105
106- (NSString*)cacheKeyForType:(NSString*)type;
107- (OOPlanetNormalMapGenerator*)normalMapGenerator; // Must be called before generator is enqueued for rendering.
108- (OOPlanetAtmosphereGenerator*)atmosphereGenerator; // Must be called before generator is enqueued for rendering.
109
110#if DEBUG_DUMP_RAW
111- (void)dumpNoiseBuffer:(float*)noise;
112#endif
113
114@end
115
116static FloatRGB FloatRGBFromDictColor(NSDictionary* dictionary, NSString* key);
117
118static BOOL FillFBMBuffer(OOPlanetTextureGeneratorInfo* info);
119
120static float QFactor(float* accbuffer, int x, int y, unsigned width, float polar_y_value, float bias, float polar_y);
121static float GetQ(float* qbuffer, int x, int y, unsigned width, unsigned height, unsigned widthMask, unsigned heightMask);
122
123static FloatRGB Blend(float fraction, FloatRGB a, FloatRGB b);
124static float BlendAlpha(float fraction, float a, float b);
125static void SetMixConstants(OOPlanetTextureGeneratorInfo* info, float temperatureFraction);
126static FloatRGBA CloudMix(OOPlanetTextureGeneratorInfo* info, float q, float nearPole);
127static FloatRGBA PlanetMix(OOPlanetTextureGeneratorInfo* info, float q, float nearPole);
128
129enum {
130 kPlanetScale256x256 = 1,
131 kPlanetScale512x512,
132 kPlanetScale1024x1024,
133 kPlanetScale2048x2048,
134 kPlanetScale4096x4096,
135
136 kPlanetScaleReducedDetail = kPlanetScale512x512,
137 kPlanetScaleFullDetail = kPlanetScale1024x1024,
138 kPlanetScaleExtraDetail = kPlanetScale2048x2048
139};
140
141@implementation OOPlanetTextureGenerator
142
143- (id)initWithPlanetInfo:(NSDictionary*)planetInfo
144{
145 OOLog(@"texture.planet.generate", @"%@", @"Initialising planetary generator");
146
147 // AllowCubeMap not used yet but might be in future
148 if ((self = [super initWithPath:[NSString stringWithFormat:@"OOPlanetTexture@%p", self] options:kOOTextureAllowCubeMap])) {
149 OOLog(@"texture.planet.generate", @"Extracting parameters for generator %@", self);
150
151 _info.landFraction = OOClamp_0_1_f([planetInfo oo_floatForKey:@"land_fraction" defaultValue:0.3]);
152 _info.polarFraction = OOClamp_0_1_f([planetInfo oo_floatForKey:@"polar_fraction" defaultValue:0.05]);
153 _info.landColor = FloatRGBFromDictColor(planetInfo, @"land_color");
154 _info.seaColor = FloatRGBFromDictColor(planetInfo, @"sea_color");
155 _info.paleLandColor = FloatRGBFromDictColor(planetInfo, @"polar_land_color");
156 _info.polarSeaColor = FloatRGBFromDictColor(planetInfo, @"polar_sea_color");
157 [[planetInfo objectForKey:@"noise_map_seed"] getValue:&_info.seed];
158 if ([planetInfo objectForKey:@"cloud_alpha"]) {
159 OOLog(@"texture.planet.generate", @"%@", @"Extracting atmosphere parameters");
160 // we have an atmosphere:
161 _info.cloudAlpha = [planetInfo oo_floatForKey:@"cloud_alpha" defaultValue:1.0f];
162 _info.cloudFraction = OOClamp_0_1_f([planetInfo oo_floatForKey:@"cloud_fraction" defaultValue:0.3]);
163 _info.cloudColor = FloatRGBFromDictColor(planetInfo, @"cloud_color");
164 _info.paleCloudColor = FloatRGBFromDictColor(planetInfo, @"polar_cloud_color");
165 }
166
167 OOGraphicsDetail detailLevel = [UNIVERSE detailLevel];
168
169#ifndef TEXGEN_TEST_RIG
170 if (detailLevel < DETAIL_LEVEL_SHADERS || [planetInfo oo_boolForKey:@"isMiniature" defaultValue:NO]) {
171 _planetScale = kPlanetScaleReducedDetail;
172 } else if (detailLevel == DETAIL_LEVEL_SHADERS) {
173 _planetScale = kPlanetScaleFullDetail;
174 } else {
175 _planetScale = kPlanetScaleExtraDetail;
176 }
177#else
178 _planetScale = kPlanetScale4096x4096;
179#endif
180 _info.perlin3d = [planetInfo oo_boolForKey:@"perlin_3d" defaultValue:detailLevel > DETAIL_LEVEL_SHADERS];
181 _info.planetAspectRatio = _info.perlin3d ? 2 : 1;
182 _info.planetScaleOffset = 8 - _info.planetAspectRatio;
183 }
184
185 return self;
186}
187
188+ (OOTexture*)planetTextureWithInfo:(NSDictionary*)planetInfo
189{
190 OOTexture* result = nil;
191 OOPlanetTextureGenerator* generator = [[self alloc] initWithPlanetInfo:planetInfo];
192 if (generator != nil) {
193 result = [OOTexture textureWithGenerator:generator];
194 [generator release];
195 }
196
197 return result;
198}
199
200+ (BOOL)generatePlanetTexture:(OOTexture**)texture andAtmosphere:(OOTexture**)atmosphere withInfo:(NSDictionary*)planetInfo
201{
202 NSParameterAssert(texture != NULL);
203
204 OOPlanetTextureGenerator* diffuseGen = [[[self alloc] initWithPlanetInfo:planetInfo] autorelease];
205 if (diffuseGen == nil)
206 return NO;
207
208 OOPlanetAtmosphereGenerator* atmoGen = [diffuseGen atmosphereGenerator];
209 if (atmoGen == nil)
210 return NO;
211
212 *atmosphere = [OOTexture textureWithGenerator:atmoGen];
213 if (*atmosphere == nil)
214 return NO;
215
216 *texture = [OOTexture textureWithGenerator:diffuseGen enqueue:[atmoGen enqueued]];
217
218 return *texture != nil;
219}
220
221+ (BOOL)generatePlanetTexture:(OOTexture**)texture secondaryTexture:(OOTexture**)secondaryTexture withInfo:(NSDictionary*)planetInfo
222{
223 NSParameterAssert(texture != NULL);
224
225 BOOL enqueue = NO;
226
227 OOPlanetTextureGenerator* diffuseGen = [[[self alloc] initWithPlanetInfo:planetInfo] autorelease];
228 if (diffuseGen == nil)
229 return NO;
230
231 if (secondaryTexture != NULL) {
232 OOPlanetNormalMapGenerator* normalGen = [diffuseGen normalMapGenerator];
233 if (normalGen == nil)
234 return NO;
235
236 *secondaryTexture = [OOTexture textureWithGenerator:normalGen];
237 if (*secondaryTexture == nil)
238 return NO;
239 enqueue = [normalGen enqueued];
240 }
241
242 *texture = [OOTexture textureWithGenerator:diffuseGen enqueue:enqueue];
243
244 return *texture != nil;
245}
246
247+ (BOOL)generatePlanetTexture:(OOTexture**)texture secondaryTexture:(OOTexture**)secondaryTexture andAtmosphere:(OOTexture**)atmosphere withInfo:(NSDictionary*)planetInfo
248{
249 NSParameterAssert(texture != NULL);
250
251 BOOL enqueue = NO;
252
253 OOPlanetTextureGenerator* diffuseGen = [[[self alloc] initWithPlanetInfo:planetInfo] autorelease];
254 if (diffuseGen == nil)
255 return NO;
256
257 if (secondaryTexture != NULL) {
258 OOPlanetNormalMapGenerator* normalGen = [diffuseGen normalMapGenerator];
259 if (normalGen == nil)
260 return NO;
261
262 *secondaryTexture = [OOTexture textureWithGenerator:normalGen];
263 if (*secondaryTexture == nil)
264 return NO;
265 enqueue = [normalGen enqueued];
266 }
267
268 OOPlanetAtmosphereGenerator* atmoGen = [diffuseGen atmosphereGenerator];
269 if (atmoGen == nil)
270 return NO;
271
272 *atmosphere = [OOTexture textureWithGenerator:atmoGen];
273 if (*atmosphere == nil) {
274 if (secondaryTexture != NULL) {
275 *secondaryTexture = nil;
276 }
277 return NO;
278 }
279 enqueue = enqueue || [atmoGen enqueued];
280
281 OOLog(@"texture.planet.generate", @"Generator %@ has atmosphere %@", diffuseGen, *atmosphere);
282
283 *texture = [OOTexture textureWithGenerator:diffuseGen enqueue:enqueue];
284 return *texture != nil;
285}
286
287- (void)dealloc
288{
289 DESTROY(_nMapGenerator);
290 DESTROY(_atmoGenerator);
291
292 [super dealloc];
293}
294
295- (NSString*)descriptionComponents
296{
297 return [NSString stringWithFormat:@"seed: %u,%u land: %g", _info.seed.high, _info.seed.low, _info.landFraction];
298}
299
300- (uint32_t)textureOptions
301{
302 return PLANET_TEXTURE_OPTIONS;
303}
304
305- (NSString*)cacheKey
306{
307 NSString* type = (_nMapGenerator == nil) ? @"diffuse-baked" : @"diffuse-raw";
308 if (_atmoGenerator != nil)
309 type = [NSString stringWithFormat:@"%@-atmo", type];
310 return [self cacheKeyForType:type];
311}
312
313- (NSString*)cacheKeyForType:(NSString*)type
314{
315 return [NSString stringWithFormat:@"OOPlanetTextureGenerator-%@@%u\n%u,%u/%g/%u,%u/%f,%f,%f/%f,%f,%f/%f,%f,%f/%f,%f,%f",
316 type, _planetScale,
317 _info.width, _info.height, _info.landFraction, _info.seed.high, _info.seed.low,
318 _info.landColor.r, _info.landColor.g, _info.landColor.b,
319 _info.seaColor.r, _info.seaColor.g, _info.seaColor.b,
320 _info.paleLandColor.r, _info.paleLandColor.g, _info.paleLandColor.b,
321 _info.polarSeaColor.r, _info.polarSeaColor.g, _info.polarSeaColor.b];
322}
323
324- (OOPlanetNormalMapGenerator*)normalMapGenerator
325{
326 if (_nMapGenerator == nil) {
327 _nMapGenerator = [[OOPlanetNormalMapGenerator alloc] initWithCacheKey:[self cacheKeyForType:@"normal"] seed:_info.seed];
328 }
329 return _nMapGenerator;
330}
331
332- (OOPlanetAtmosphereGenerator*)atmosphereGenerator
333{
334 if (_atmoGenerator == nil) {
335 _atmoGenerator = [[OOPlanetAtmosphereGenerator alloc] initWithCacheKey:[self cacheKeyForType:@"atmo"] seed:_info.seed andParent:self];
336 }
337 return _atmoGenerator;
338}
339
340- (BOOL)getResult:(OOPixMap*)outData
341 format:(OOTextureDataFormat*)outFormat
342 width:(uint32_t*)outWidth
343 height:(uint32_t*)outHeight
344{
345 BOOL waiting = NO;
346 if (![self isReady]) {
347 waiting = true;
348 OOLog(@"texture.planet.generate.wait", @"%s generator %@", "Waiting for", self);
349 }
350
351 BOOL result = [super getResult:outData format:outFormat originalWidth:outWidth originalHeight:outHeight];
352
353 if (waiting) {
354 OOLog(@"texture.planet.generate.dequeue", @"%s generator %@", result ? "Dequeued" : "Failed to dequeue", self);
355 } else {
356 OOLog(@"texture.planet.generate.dequeue", @"%s generator %@ without waiting.", result ? "Dequeued" : "Failed to dequeue", self);
357 }
358
359 return result;
360}
361
362- (void)loadTexture
363{
364 OOLog(@"texture.planet.generate.begin", @"Started generator %@", self);
365
366 BOOL success = NO;
367 BOOL generateNormalMap = (_nMapGenerator != nil);
368 BOOL generateAtmosphere = (_atmoGenerator != nil);
369
370 uint8_t *buffer = NULL, *px = NULL;
371 uint8_t *nBuffer = NULL, *npx = NULL;
372 uint8_t *aBuffer = NULL, *apx = NULL;
373 float* randomBuffer = NULL;
374
375 _height = _info.height = 1 << (_planetScale + _info.planetScaleOffset);
376 _width = _info.width = _height * _info.planetAspectRatio;
377
378#define FAIL_IF(cond) \
379 do { \
380 if (EXPECT_NOT(cond)) \
381 goto END; \
382 } while (0)
383#define FAIL_IF_NULL(x) FAIL_IF((x) == NULL)
384
385 buffer = malloc(4 * _width * _height);
386 FAIL_IF_NULL(buffer);
387 px = buffer;
388
389 if (generateNormalMap) {
390 nBuffer = malloc(4 * _width * _height);
391 FAIL_IF_NULL(nBuffer);
392 npx = nBuffer;
393 }
394
395 if (generateAtmosphere) {
396 aBuffer = malloc(4 * _width * _height);
397 FAIL_IF_NULL(aBuffer);
398 apx = aBuffer;
399 }
400
401 FAIL_IF(!FillFBMBuffer(&_info));
402#if DEBUG_DUMP_RAW
403 [self dumpNoiseBuffer:_info.fbmBuffer];
404#endif
405
406 float paleClouds = (_info.cloudFraction * _info.fbmBuffer[0] < 1.0f - _info.cloudFraction) ? 0.0f : 1.0f;
407 float poleValue = (_info.landFraction > 0.5f) ? 0.5f * _info.landFraction : 0.0f;
408 float seaBias = _info.landFraction - 1.0f;
409
410 _info.paleSeaColor = Blend(0.35f, _info.polarSeaColor, Blend(0.7f, _info.seaColor, _info.landColor));
411 float normalScale = (1 << _planetScale)
412#ifndef NDEBUG
413 // test-release only, make normalScale adjustable from within user defaults
414 * [[NSUserDefaults standardUserDefaults] oo_floatForKey:@"p3dnsf" defaultValue:1.0f]
415#endif
416 ; // float normalScale = ...
417 if (!generateNormalMap)
418 normalScale *= 3.0f;
419
420 // Deep sea colour: sea darker past the continental shelf.
421 _info.deepSeaColor = Blend(0.85f, _info.seaColor, (FloatRGB) { 0, 0, 0 });
422
423 int x, y;
424 FloatRGBA color;
425 Vector norm;
426 float q, yN, yS, yW, yE, nearPole;
427 GLfloat shade;
428 float rHeight = 1.0f / _height;
429 float fy, fHeight = _height;
430 // The second parameter is the temperature fraction. Most favourable: 1.0f, little ice. Most unfavourable: 0.0f, frozen planet. TODO: make it dependent on ranrot / planetinfo key...
431 SetMixConstants(&_info, 1.0f - _info.polarFraction); // no need to recalculate them inside each loop!
432
433 // first pass, calculate q.
434 _info.qBuffer = malloc(_width * _height * sizeof(float));
435 FAIL_IF_NULL(_info.qBuffer);
436
437 for (y = (int)_height - 1, fy = (float)y; y >= 0; y--, fy--) {
438 nearPole = (2.0f * fy - fHeight) * rHeight;
439 nearPole *= nearPole;
440
441 for (x = (int)_width - 1; x >= 0; x--) {
442 _info.qBuffer[y * _width + x] = QFactor(_info.fbmBuffer, x, y, _width, poleValue, seaBias, nearPole);
443 }
444 }
445
446 // second pass, use q.
447 float cloudFraction = _info.cloudFraction;
448 unsigned widthMask = _width - 1;
449 unsigned heightMask = _height - 1;
450
451 for (y = (int)_height - 1, fy = (float)y; y >= 0; y--, fy--) {
452 nearPole = (2.0f * fy - fHeight) * rHeight;
453 nearPole *= nearPole;
454
455 for (x = (int)_width - 1; x >= 0; x--) {
456 q = _info.qBuffer[y * _width + x]; // no need to use GetQ, x and y are always within bounds.
457 yN = GetQ(_info.qBuffer, x, y - 1, _width, _height, widthMask, heightMask); // recalculates x & y if they go out of bounds.
458 yS = GetQ(_info.qBuffer, x, y + 1, _width, _height, widthMask, heightMask);
459 yW = GetQ(_info.qBuffer, x - 1, y, _width, _height, widthMask, heightMask);
460 yE = GetQ(_info.qBuffer, x + 1, y, _width, _height, widthMask, heightMask);
461
462 color = PlanetMix(&_info, q, nearPole);
463
464 norm = vector_normal(make_vector(normalScale * (yE - yW), normalScale * (yN - yS), 1.0f));
465 if (generateNormalMap) {
466 shade = 1.0f;
467
468 // Flatten the sea.
469 norm = OOVectorInterpolate(norm, kBasisZVector, color.a);
470
471 // Put norm in normal map, scaled from [-1..1] to [0..255].
472 *npx++ = 127.5f * (norm.y + 1.0f);
473 *npx++ = 127.5f * (-norm.x + 1.0f);
474 *npx++ = 127.5f * (norm.z + 1.0f);
475
476 *npx++ = 255.0f * color.a; // Specular channel.
477 } else {
478 // Terrain shading - lambertian lighting from straight above.
479 shade = norm.z;
480
481 /* We don't want terrain shading in the sea. The alpha channel
482 of color is a measure of "seaishness" for the specular map,
483 so we can recycle that to avoid branching.
484 -- Ahruman
485 */
486 shade += color.a - color.a * shade; // equivalent to - but slightly faster than - previous implementation.
487 }
488
489 *px++ = 255.0f * color.r * shade;
490 *px++ = 255.0f * color.g * shade;
491 *px++ = 255.0f * color.b * shade;
492
493 *px++ = 0; // FIXME: light map goes here.
494
495 if (generateAtmosphere) {
496 q = QFactor(_info.fbmBuffer, x, y, _width, paleClouds, cloudFraction, nearPole);
497 color = CloudMix(&_info, q, nearPole);
498 *apx++ = 255.0f * color.r;
499 *apx++ = 255.0f * color.g;
500 *apx++ = 255.0f * color.b;
501 *apx++ = 255.0f * color.a * _info.cloudAlpha;
502 }
503 }
504 }
505
506 success = YES;
507 _format = kOOTextureDataRGBA;
508
509END:
510 FREE(_info.fbmBuffer);
511 FREE(_info.qBuffer);
512 FREE(randomBuffer);
513 if (success) {
514 _data = buffer;
515 if (generateNormalMap)
516 [_nMapGenerator completeWithData:nBuffer width:_width height:_height];
517 if (generateAtmosphere)
518 [_atmoGenerator completeWithData:aBuffer width:_width height:_height];
519 } else {
520 FREE(buffer);
521 FREE(nBuffer);
522 FREE(aBuffer);
523 }
524 DESTROY(_nMapGenerator);
525 DESTROY(_atmoGenerator);
526
527 OOLog(@"texture.planet.generate.complete", @"Completed generator %@ %@successfully", self, success ? @"" : @"un");
528
529#if DEBUG_DUMP
530 if (success) {
531 NSString* diffuseName = [NSString stringWithFormat:@"planet-%u-%u-diffuse-new", _info.seed.high, _info.seed.low];
532 NSString* lightsName = [NSString stringWithFormat:@"planet-%u-%u-lights-new", _info.seed.high, _info.seed.low];
533
534 [[UNIVERSE gameView] dumpRGBAToRGBFileNamed:diffuseName
535 andGrayFileNamed:lightsName
536 bytes:buffer
537 width:_width
538 height:_height
539 rowBytes:_width * 4];
540 }
541#endif
542}
543
544#if DEBUG_DUMP_RAW
545
546- (void)dumpNoiseBuffer:(float*)noise
547{
548 NSString* noiseName = [NSString stringWithFormat:@"planet-%u-%u-noise-new", _info.seed.high, _info.seed.low];
549
550 uint8_t* noisePx = malloc(_width * _height);
551 unsigned x, y;
552 for (y = 0; y < _height; y++) {
553 for (x = 0; x < _width; x++) {
554 noisePx[y * _width + x] = 255.0f * noise[y * _width + x];
555 }
556 }
557
558 [[UNIVERSE gameView] dumpGrayToFileNamed:noiseName
559 bytes:noisePx
560 width:_width
561 height:_height
562 rowBytes:_width];
563 FREE(noisePx);
564}
565
566#endif
567
568@end
569
570OOINLINE float Lerp(float v0, float v1, float fraction)
571{
572 // Linear interpolation - equivalent to v0 * (1.0f - fraction) + v1 * fraction.
573 return v0 + fraction * (v1 - v0);
574}
575
576static FloatRGB Blend(float fraction, FloatRGB a, FloatRGB b)
577{
578 return (FloatRGB) {
579 Lerp(b.r, a.r, fraction),
580 Lerp(b.g, a.g, fraction),
581 Lerp(b.b, a.b, fraction)
582 };
583}
584
585static float BlendAlpha(float fraction, float a, float b)
586{
587 return Lerp(b, a, fraction);
588}
589
590static FloatRGBA CloudMix(OOPlanetTextureGeneratorInfo* info, float q, float nearPole)
591{
592// #define AIR_ALPHA (0.15f)
593// #define CLOUD_ALPHA (1.0f)
594// CIM: make distinction between cloud and not-cloud bigger
595#define AIR_ALPHA (0.05f)
596#define CLOUD_ALPHA (2.0f)
597
598#define POLAR_BOUNDARY (0.33f)
599#define CLOUD_BOUNDARY (0.5f)
600#define RECIP_CLOUD_BOUNDARY (1.0f / CLOUD_BOUNDARY)
601
602 FloatRGB cloudColor = info->cloudColor;
603 float alpha = info->cloudAlpha, portion = 0.0f;
604
605 q -= CLOUD_BOUNDARY * 0.5f;
606
607 if (nearPole > POLAR_BOUNDARY) {
608 portion = nearPole > POLAR_BOUNDARY + 0.2f ? 1.0f : (nearPole - POLAR_BOUNDARY) * 5.0f;
609 cloudColor = Blend(portion, info->paleCloudColor, cloudColor);
610
611 portion = nearPole > POLAR_BOUNDARY + 0.625f ? 1.0f : (nearPole - POLAR_BOUNDARY) * 1.6f;
612 }
613
614 if (q <= 0.0f) {
615 if (q >= -CLOUD_BOUNDARY) {
616 alpha *= BlendAlpha(-q * 0.5f * RECIP_CLOUD_BOUNDARY + 0.5f, CLOUD_ALPHA, AIR_ALPHA);
617 } else {
618 alpha *= CLOUD_ALPHA;
619 }
620 } else {
621 if (q < CLOUD_BOUNDARY) {
622 alpha *= BlendAlpha(q * 0.5f * RECIP_CLOUD_BOUNDARY + 0.5f, AIR_ALPHA, CLOUD_ALPHA);
623 } else {
624 alpha *= AIR_ALPHA;
625 }
626 }
627 // magic numbers! at the poles we have fairly thin air.
628 alpha *= BlendAlpha(portion, 0.6f, 1.0f);
629 if (alpha > 1.0) {
630 alpha = 1.0;
631 }
632
633 return (FloatRGBA) { cloudColor.r, cloudColor.g, cloudColor.b, alpha };
634}
635
636static FloatRGBA PlanetMix(OOPlanetTextureGeneratorInfo* info, float q, float nearPole)
637{
638#define RECIP_COASTLINE_PORTION (160.0f)
639#define COASTLINE_PORTION (1.0f / RECIP_COASTLINE_PORTION)
640#define SHALLOWS (2.0f * COASTLINE_PORTION) // increased shallows area.
641#define RECIP_SHALLOWS (1.0f / SHALLOWS)
642// N.B.: DEEPS can't be more than RECIP_COASTLINE_PORTION * COASTLINE_PORTION!
643#define DEEPS (40.0f * COASTLINE_PORTION)
644#define RECIP_DEEPS (1.0f / DEEPS)
645
646 const FloatRGB white = { 1.0f, 1.0f, 1.0f };
647 FloatRGB diffuse;
648 // windows specular 'fix': 0 was showing pitch black continents when on the dark side, 0.01 shows the same shading as on Macs.
649 // TODO: a less hack-like fix.
650 float specular = 0.01f;
651
652 if (q <= 0.0f) {
653 // Below datum - sea.
654 if (q > -SHALLOWS) {
655 // Coastal waters.
656 diffuse = Blend(-q * RECIP_SHALLOWS, info->seaColor, info->paleSeaColor);
657 specular = 1.0f;
658 } else {
659 // Open sea.
660 if (q > -DEEPS)
661 diffuse = Blend(-q * RECIP_DEEPS, info->deepSeaColor, info->seaColor);
662 else
663 diffuse = info->deepSeaColor;
664 specular = Lerp(1.0f, 0.85f, -q);
665 }
666 } else if (q < COASTLINE_PORTION) {
667 // Coastline.
668 specular = q * RECIP_COASTLINE_PORTION;
669 diffuse = Blend(specular, info->landColor, info->paleSeaColor);
670 specular = 1.0f - specular;
671 } else if (q > 1.0f) {
672 // High up - snow-capped peaks. With overrides q can range between -2 to +2.
673 diffuse = white;
674 } else if (q > info->mix_hi) {
675 diffuse = Blend((q - info->mix_hi) * info->mix_ih, white, info->paleLandColor); // Snowline.
676 } else {
677 // Normal land.
678 diffuse = Blend((info->mix_hi - q) * info->mix_oh, info->landColor, info->paleLandColor);
679 }
680
681#if POLAR_CAPS
682 // (q > mix_polarCap + mix_polarCap - nearPole) == ((nearPole + q) / 2 > mix_polarCap)
683 float phi = info->mix_polarCap + info->mix_polarCap - nearPole;
684 if (q > phi) // (nearPole + q) / 2 > pole
685 {
686 // thinner to thicker ice.
687 specular = q > phi + 0.02f ? 1.0f : 0.2f + (q - phi) * 40.0f; // (q - phi) * 40 == ((q-phi) / 0.02) * 0.8
688 // diffuse = info->polarSeaColor;
689 diffuse = Blend(specular, info->polarSeaColor, diffuse);
690 specular = specular * 0.5f; // softer contours under ice, but still contours.
691 }
692#endif
693
694 return (FloatRGBA) { diffuse.r, diffuse.g, diffuse.b, specular };
695}
696
697static FloatRGB FloatRGBFromDictColor(NSDictionary* dictionary, NSString* key)
698{
699 OOColor* color = [dictionary objectForKey:key];
700 NSCAssert1([color isKindOfClass:[OOColor class]], @"Expected OOColor, got %@", [color class]);
701
702 return (FloatRGB) { [color redComponent] * ALBEDO_FACTOR, [color greenComponent] * ALBEDO_FACTOR, [color blueComponent] * ALBEDO_FACTOR };
703}
704
705OOINLINE float Hermite(float q)
706{
707 return 3.0f * q * q - 2.0f * q * q * q;
708}
709
710#if __BIG_ENDIAN__
711#define iman_ 1
712#else
713#define iman_ 0
714#endif
715
716// (same behaviour as, but faster than, FLOAT->INT)
717// Works OK for -32728 to 32727.99999236688
718OOINLINE int32_t fast_floor(double val)
719{
720 val += 68719476736.0 * 1.5;
721 return (((int32_t*)&val)[iman_] >> 16);
722}
723
724static BOOL GenerateFBMNoise(OOPlanetTextureGeneratorInfo* info);
725static BOOL GenerateFBMNoise3D(OOPlanetTextureGeneratorInfo* info);
726
727static BOOL FillFBMBuffer(OOPlanetTextureGeneratorInfo* info)
728{
729 NSCParameterAssert(info != NULL);
730
731 // Allocate result buffer.
732 info->fbmBuffer = calloc(info->width * info->height, sizeof(float));
733 if (info->fbmBuffer != NULL) {
734 if (!info->perlin3d) {
735 GenerateFBMNoise(info);
736 } else {
737 GenerateFBMNoise3D(info);
738 }
739
740 return YES;
741 }
742 return NO;
743}
744
745enum {
746 // Size of permutation buffer used to map integer coordinates to gradients. Must be power of two.
747 kPermutationCount = 1 << 10,
748 kPermutationMask = kPermutationCount - 1,
749
750 // Number of different gradient vectors used. The most important thing is that the gradients are evenly distributed and sum to 0.
751 kGradientCount = 12
752};
753
754#define LUT_DOT 1
755
756#if !LUT_DOT
757static const Vector kGradients[kGradientCount] = {
758 { 1, 1, 0 },
759 { -1, 1, 0 },
760 { 1, -1, 0 },
761 { -1, -1, 0 },
762 { 1, 0, 1 },
763 { -1, 0, 1 },
764 { 1, 0, -1 },
765 { -1, 0, -1 },
766 { 0, 1, 1 },
767 { 0, -1, 1 },
768 { 0, 1, -1 },
769 { 0, -1, -1 }
770};
771#else
772static const uint8_t kGradients[kGradientCount][3] = {
773 { 2, 2, 1 },
774 { 0, 2, 1 },
775 { 2, 0, 1 },
776 { 0, 0, 1 },
777 { 2, 1, 2 },
778 { 0, 1, 2 },
779 { 2, 1, 0 },
780 { 0, 1, 0 },
781 { 1, 2, 2 },
782 { 1, 0, 2 },
783 { 1, 2, 0 },
784 { 1, 0, 0 }
785};
786
787/* Attempted speedup that didn't pan out, but might inspire something better.
788 Since our gradient vectors' components are all -1, 0 or 1, we should be
789 able to calculate the dot product without any multiplication at all, by
790 simply summing the right combination of (x, y, z), (0, 0, 0) and (-x, -y, -z).
791
792 This turns out to be slightly slower than using multiplication, even if
793 the negations are precalculated.
794*/
795OOINLINE float TDot3(const uint8_t grad[3], float x, float y, float z)
796{
797 float xt[3] = { -x, 0.0f, x };
798 float yt[3] = { -y, 0.0f, y };
799 float zt[3] = { -z, 0.0f, z };
800
801 return xt[grad[0]] + yt[grad[1]] + zt[grad[2]];
802}
803#endif
804
805// Sample 3D noise function defined by kGradients and permutation table at point p.
806static float SampleNoise3D(OOPlanetTextureGeneratorInfo* info, Vector p)
807{
808 uint16_t* permutations = info->permutations;
809
810 // Split coordinates into integer and fractional parts.
811 float fx = floor(p.x);
812 float fy = floor(p.y);
813 float fz = floor(p.z);
814 int X = fx;
815 int Y = fy;
816 int Z = fz;
817 float x = p.x - fx;
818 float y = p.y - fy;
819 float z = p.z - fz;
820
821 // Select gradient for each corner.
822#define PERM(v) permutations[(v) & kPermutationMask]
823
824 unsigned PZ0 = PERM(Z);
825 unsigned PZ1 = PERM(Z + 1);
826
827 unsigned PY0Z0 = PERM(Y + PZ0);
828 unsigned PY1Z0 = PERM(Y + 1 + PZ0);
829 unsigned PY0Z1 = PERM(Y + PZ1);
830 unsigned PY1Z1 = PERM(Y + 1 + PZ1);
831
832 unsigned gi000 = PERM(X + PY0Z0);
833 unsigned gi010 = PERM(X + PY1Z0);
834 unsigned gi100 = PERM(X + 1 + PY0Z0);
835 unsigned gi110 = PERM(X + 1 + PY1Z0);
836 unsigned gi001 = PERM(X + PY0Z1);
837 unsigned gi011 = PERM(X + PY1Z1);
838 unsigned gi101 = PERM(X + 1 + PY0Z1);
839 unsigned gi111 = PERM(X + 1 + PY1Z1);
840
841#undef PERM
842
843 // Calculate noise contributions from each of the eight corners.
844#if !LUT_DOT
845#define DOT3(idx, x_, y_, z_) dot_product(kGradients[(idx) % kGradientCount], (Vector) { (x_), (y_), (z_) })
846#else
847#define DOT3(idx, x_, y_, z_) TDot3(kGradients[(idx) % kGradientCount], (x_), (y_), (z_))
848#endif
849
850 float x1 = x - 1.0f;
851 float y1 = y - 1.0f;
852 float z1 = z - 1.0f;
853 float n000 = DOT3(gi000, x, y, z);
854 float n010 = DOT3(gi010, x, y1, z);
855 float n100 = DOT3(gi100, x1, y, z);
856 float n110 = DOT3(gi110, x1, y1, z);
857 float n001 = DOT3(gi001, x, y, z1);
858 float n011 = DOT3(gi011, x, y1, z1);
859 float n101 = DOT3(gi101, x1, y, z1);
860 float n111 = DOT3(gi111, x1, y1, z1);
861
862#undef DOT3
863
864 // Compute the fade curve value for each of x, y, z
865 float u = Hermite(x);
866 float v = Hermite(y);
867 float w = Hermite(z);
868
869 // Interpolate along the contributions from each of the corners.
870 float nx00 = Lerp(n000, n100, u);
871 float nx01 = Lerp(n001, n101, u);
872 float nx10 = Lerp(n010, n110, u);
873 float nx11 = Lerp(n011, n111, u);
874
875 float nxy0 = Lerp(nx00, nx10, v);
876 float nxy1 = Lerp(nx01, nx11, v);
877
878 float nxyz = Lerp(nxy0, nxy1, w);
879
880 return nxyz;
881}
882
883// Noise map generator
884static BOOL MakePermutationTable(OOPlanetTextureGeneratorInfo* info)
885{
886 uint16_t* perms = malloc(sizeof *info->permutations * kPermutationCount);
887 if (EXPECT_NOT(perms == NULL))
888 return NO;
889
890 perms[0] = 0;
891 uint16_t n;
892 for (n = 1; n < kPermutationCount; n++) {
893 perms[n] = RanrotWithSeed(&info->seed) & kPermutationMask;
894 }
895
896 info->permutations = perms;
897 return YES;
898}
899
900static BOOL GenerateFBMNoise3D(OOPlanetTextureGeneratorInfo* info)
901{
902 BOOL OK = NO;
903
904 FAIL_IF(!MakePermutationTable(info));
905
906 unsigned x, y, width = info->width, height = info->height;
907 float lon, lat; // Longitude and latitude in radians.
908 float dlon = 2.0f * M_PI / width;
909 float dlat = M_PI / height;
910 float* px = info->fbmBuffer;
911
912 for (y = 0, lat = -M_PI_2; y < height; y++, lat += dlat) {
913 float las = sin(lat);
914 float lac = cos(lat);
915
916 for (x = 0, lon = -M_PI; x < width; x++, lon += dlon) {
917 // FIXME: in real life, we really don't want sin and cos per pixel.
918 // Convert spherical coordinates to vector.
919 float los = sin(lon);
920 float loc = cos(lon);
921
922 Vector p = {
923 los * lac,
924 las,
925 loc * lac
926 };
927
928#if 1
929 // fBM
930 unsigned octaveMask = 4;
931 float octave = octaveMask;
932 octaveMask -= 1;
933 float scale = 0.4f;
934 float sum = 0;
935
936 while ((octaveMask + 1) < height) {
937 Vector ps = vector_multiply_scalar(p, octave);
938 sum += scale * SampleNoise3D(info, ps);
939
940 octave *= 2.0f;
941 octaveMask = (octaveMask << 1) | 1;
942 scale *= 0.5f;
943 }
944#else
945 // Single octave
946 p = vector_multiply_scalar(p, 4.0f);
947 float sum = 0.5f * SampleNoise3D(info, p);
948#endif
949
950 *px++ = sum + 0.5f;
951 }
952 }
953
954END:
955 FREE(info->permutations);
956 return OK;
957}
958
959// Old 2D value noise.
960
961static void FillRandomBuffer(float* randomBuffer, RANROTSeed seed)
962{
963 unsigned i, len = kRandomBufferSize * kRandomBufferSize;
964 for (i = 0; i < len; i++) {
965 randomBuffer[i] = randfWithSeed(&seed);
966 }
967}
968
969static void AddNoise(OOPlanetTextureGeneratorInfo* info, float* randomBuffer, float octave, unsigned octaveMask, float scale, float* qxBuffer, int* ixBuffer)
970{
971 unsigned x, y;
972 unsigned width = info->width, height = info->height;
973 int ix, jx, iy, jy;
974 float rr = octave / width;
975 float fx, fy, qx, qy, rix, rjx, rfinal;
976 float* dst = info->fbmBuffer;
977
978 for (fy = 0, y = 0; y < height; fy++, y++) {
979 qy = fy * rr;
980 iy = fast_floor(qy);
981 jy = (iy + 1) & octaveMask;
982 qy = Hermite(qy - iy);
983 iy &= (kRandomBufferSize - 1);
984 jy &= (kRandomBufferSize - 1);
985
986 for (fx = 0, x = 0; x < width; fx++, x++) {
987 if (y == 0) {
988 // first pass: initialise buffers.
989 qx = fx * rr;
990 ix = fast_floor(qx);
991 qx -= ix;
992 ix &= (kRandomBufferSize - 1);
993 ixBuffer[x] = ix;
994 qxBuffer[x] = Hermite(qx);
995 } else {
996 // later passes: grab the stored values.
997 ix = ixBuffer[x];
998 qx = qxBuffer[x];
999 }
1000
1001 jx = (ix + 1) & octaveMask;
1002 jx &= (kRandomBufferSize - 1);
1003
1004 rix = Lerp(randomBuffer[iy * kRandomBufferSize + ix], randomBuffer[iy * kRandomBufferSize + jx], qx);
1005 rjx = Lerp(randomBuffer[jy * kRandomBufferSize + ix], randomBuffer[jy * kRandomBufferSize + jx], qx);
1006 rfinal = Lerp(rix, rjx, qy);
1007
1008 *dst++ += scale * rfinal;
1009 }
1010 }
1011}
1012
1013static BOOL GenerateFBMNoise(OOPlanetTextureGeneratorInfo* info)
1014{
1015 // Allocate the temporary buffers we need in one fell swoop, to avoid administrative overhead.
1016 size_t randomBufferSize = kRandomBufferSize * kRandomBufferSize * sizeof(float);
1017 size_t qxBufferSize = info->width * sizeof(float);
1018 size_t ixBufferSize = info->width * sizeof(int);
1019 char* sharedBuffer = malloc(randomBufferSize + qxBufferSize + ixBufferSize);
1020 if (sharedBuffer == NULL)
1021 return NO;
1022
1023 float* randomBuffer = (float*)sharedBuffer;
1024 float* qxBuffer = (float*)(sharedBuffer + randomBufferSize);
1025 int* ixBuffer = (int*)(sharedBuffer + randomBufferSize + qxBufferSize);
1026
1027 // Get us some value noise.
1028 FillRandomBuffer(randomBuffer, info->seed);
1029
1030 // Generate basic fBM noise.
1031 unsigned height = info->height;
1032 unsigned octaveMask = 8 * info->planetAspectRatio;
1033 float octave = octaveMask;
1034 octaveMask -= 1;
1035 float scale = 0.5f;
1036
1037 while ((octaveMask + 1) < height) {
1038 AddNoise(info, randomBuffer, octave, octaveMask, scale, qxBuffer, ixBuffer);
1039 octave *= 2.0f;
1040 octaveMask = (octaveMask << 1) | 1;
1041 scale *= 0.5f;
1042 }
1043
1044 FREE(sharedBuffer);
1045 return YES;
1046}
1047
1048static float QFactor(float* accbuffer, int x, int y, unsigned width, float polar_y_value, float bias, float polar_y)
1049{
1050 float q = accbuffer[y * width + x]; // 0.0 -> 1.0
1051 q += bias;
1052
1053 // Polar Y smooth.
1054 q = q * (1.0f - polar_y) + polar_y * polar_y_value;
1055
1056 return q;
1057}
1058
1059static float GetQ(float* qbuffer, int x, int y, unsigned width, unsigned height, unsigned widthMask, unsigned heightMask)
1060{
1061 // Correct Y wrapping mode, unoptimised.
1062 // if (y < 0) { y = -y - 1; x += width / 2; }
1063 // else if (y >= height) { y = height - (y - height) - 1; x += width / 2; }
1064 // now let's wrap x.
1065 // x = x % width;
1066
1067 // Correct Y wrapping mode, faster method. In the following lines of code, both
1068 // width and height are assumed to be powers of 2: 512, 1024, 2048, etc...
1069 if (y & height) {
1070 y = (y ^ heightMask) & heightMask;
1071 x += width >> 1;
1072 }
1073 // x wrapping.
1074 x &= widthMask;
1075 return qbuffer[y * width + x];
1076}
1077
1078static void SetMixConstants(OOPlanetTextureGeneratorInfo* info, float temperatureFraction)
1079{
1080 info->mix_hi = 0.66667f * info->landFraction;
1081 info->mix_oh = 1.0f / info->mix_hi;
1082 info->mix_ih = 1.0f / (1.0f - info->mix_hi);
1083 info->mix_polarCap = temperatureFraction * (0.28f + 0.24f * info->landFraction); // landmasses make the polar cap proportionally bigger, but not too much bigger.
1084}
1085
1086@implementation OOPlanetNormalMapGenerator
1087
1088- (id)initWithCacheKey:(NSString*)cacheKey seed:(RANROTSeed)seed
1089{
1090 // AllowCubeMap not used yet but might be in future
1091 if ((self = [super initWithPath:[NSString stringWithFormat:@"OOPlanetNormalTexture@%p", self] options:kOOTextureAllowCubeMap])) {
1092 _enqueued = NO;
1093 _cacheKey = [cacheKey copy];
1094 _seed = seed;
1095 }
1096 return self;
1097}
1098
1099- (void)dealloc
1100{
1101 DESTROY(_cacheKey);
1102
1103 [super dealloc];
1104}
1105
1106- (NSString*)cacheKey
1107{
1108 return _cacheKey;
1109}
1110
1111- (uint32_t)textureOptions
1112{
1113 return PLANET_TEXTURE_OPTIONS;
1114}
1115
1116- (BOOL)enqueue
1117{
1118 /* This generator doesn't do any work, so it doesn't need to be queued
1119 at the normal time.
1120 (The alternative would be for it to block a work thread waiting for
1121 the real generator to complete, which seemed silly.)
1122 */
1123 _enqueued = YES;
1124 return YES;
1125}
1126
1127- (BOOL)enqueued
1128{
1129 return _enqueued;
1130}
1131
1132- (void)loadTexture
1133{
1134 // Do nothing.
1135}
1136
1137- (void)completeWithData:(void*)data_ width:(unsigned)width_ height:(unsigned)height_
1138{
1139 _data = data_;
1140 _width = width_;
1141 _height = height_;
1142 _format = kOOTextureDataRGBA;
1143
1144 // Enqueue so superclass can apply texture options and so forth.
1145 [super enqueue];
1146
1147#if DEBUG_DUMP
1148 NSString* normalName = [NSString stringWithFormat:@"planet-%u-%u-normal-new", _seed.high, _seed.low];
1149 NSString* specularName = [NSString stringWithFormat:@"planet-%u-%u-specular-new", _seed.high, _seed.low];
1150
1151 [[UNIVERSE gameView] dumpRGBAToRGBFileNamed:normalName
1152 andGrayFileNamed:specularName
1153 bytes:_data
1154 width:_width
1155 height:_height
1156 rowBytes:_width * 4];
1157#endif
1158}
1159
1160@end
1161
1162@implementation OOPlanetAtmosphereGenerator
1163
1164- (id)initWithCacheKey:(NSString*)cacheKey seed:(RANROTSeed)seed andParent:(OOPlanetTextureGenerator*)parent
1165{
1166 OOLog(@"texture.planet.generate", @"Initialising atmosphere generator %@", cacheKey);
1167 // AllowCubeMap not used yet but might be in future
1168 if ((self = [super initWithPath:[NSString stringWithFormat:@"OOPlanetAtmoTexture@%p", self] options:kOOTextureAllowCubeMap])) {
1169 _cacheKey = [cacheKey copy];
1170 _seed = seed;
1171 _parent = [parent retain];
1172 _enqueued = NO;
1173 }
1174 return self;
1175}
1176
1177- (void)dealloc
1178{
1179 DESTROY(_cacheKey);
1180 DESTROY(_parent);
1181 [super dealloc];
1182}
1183
1184- (NSString*)cacheKey
1185{
1186 return _cacheKey;
1187}
1188
1189- (uint32_t)textureOptions
1190{
1191 return PLANET_TEXTURE_OPTIONS;
1192}
1193
1194- (BOOL)enqueue
1195{
1196 _enqueued = YES;
1197 return YES;
1198}
1199
1200- (BOOL)enqueued
1201{
1202 return _enqueued;
1203}
1204
1205- (void)loadTexture
1206{
1207 // Do nothing.
1208}
1209
1210/* Because of the hack to avoid making texture loaders need to know
1211 * about multiple textures, when we call the atmosphere generator on a
1212 * planet with a from-file texture, things can occasionally go wrong
1213 * because this isn't queued until after it's ready, but might be
1214 * requested from the queue before then. So, when getResult is called,
1215 * it waits for its parent task to complete if it's not itself ready -
1216 * by the time the parent task is complete, this texture loader will
1217 * have been enqueued, and [super getResult] will then work
1218 * properly. - CIM 2014-04-05 */
1219- (BOOL)getResult:(OOPixMap*)result
1220 format:(OOTextureDataFormat*)outFormat
1221 originalWidth:(uint32_t*)outWidth
1222 originalHeight:(uint32_t*)outHeight
1223{
1224 if (!_ready) {
1226 }
1227
1228 return [super getResult:result
1229 format:outFormat
1230 originalWidth:outWidth
1231 originalHeight:outHeight];
1232}
1233
1234- (void)completeWithData:(void*)data_ width:(unsigned)width_ height:(unsigned)height_
1235{
1236 OOLog(@"texture.planet.generate", @"%@", @"Completing atmosphere generator");
1237
1238 _data = data_;
1239 _width = width_;
1240 _height = height_;
1241 _format = kOOTextureDataRGBA;
1242
1243 // Enqueue so superclass can apply texture options and so forth.
1244 [super enqueue];
1245
1246#if DEBUG_DUMP
1247 NSString* rgbName = [NSString stringWithFormat:@"planet-%u-%u-atmosphere-rgb-new", _seed.high, _seed.low];
1248 NSString* alphaName = [NSString stringWithFormat:@"planet-%u-%u-atmosphere-alpha-new", _seed.high, _seed.low];
1249
1250 [[UNIVERSE gameView] dumpRGBAToRGBFileNamed:rgbName
1251 andGrayFileNamed:alphaName
1252 bytes:_data
1253 width:_width
1254 height:_height
1255 rowBytes:_width * 4];
1256#endif
1257}
1258
1259@end
1260
1261#endif // NEW_PLANETS
OOINLINE float OOClamp_0_1_f(float value) INLINE_CONST_FUNC
#define DESTROY(x)
#define EXPECT_NOT(x)
#define OOINLINE
#define OOLog(class, format,...)
Definition OOLogging.h:84
#define M_PI_2
Definition OOMaths.h:57
#define M_PI
Definition OOMaths.h:54
struct OOPixMap OOPixMap
struct OOPlanetTextureGeneratorInfo OOPlanetTextureGeneratorInfo
return nil
float y
float x
@ kOOTextureAllowCubeMap
Definition OOTexture.h:61
@ kOOTextureDataRGBA
Definition OOTexture.h:103
OOPixMapFormat OOTextureDataFormat
Definition OOTexture.h:107
OOGraphicsDetail
Definition OOTypes.h:208
@ DETAIL_LEVEL_SHADERS
Definition OOTypes.h:211
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
Definition OOVector.h:149
struct Vector Vector
OOINLINE Vector OOVectorInterpolate(Vector a, Vector b, OOScalar where) INLINE_CONST_FUNC
Definition OOVector.h:204
const Vector kBasisZVector
Definition OOVector.h:47
OOINLINE Vector vector_multiply_scalar(Vector v, OOScalar s) INLINE_CONST_FUNC
Definition OOVector.h:180
OOINLINE Vector vector_normal(Vector vec) INLINE_CONST_FUNC
Definition OOVector.h:270
#define CLOUD_ALPHA
static FloatRGB FloatRGBFromDictColor(NSDictionary *dictionary, NSString *key)
static FloatRGB Blend(float fraction, FloatRGB a, FloatRGB b)
void waitForTaskToComplete:(id< OOAsyncWorkTask > task)
OOAsyncWorkManager * sharedAsyncWorkManager()
float blueComponent()
Definition OOColor.m:339
float redComponent()
Definition OOColor.m:329
float greenComponent()
Definition OOColor.m:334
id textureWithGenerator:(OOTextureGenerator *generator)
Definition OOTexture.m:209
id textureWithGenerator:enqueue:(OOTextureGenerator *generator,[enqueue] BOOL enqueue)
Definition OOTexture.m:214
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
float randfWithSeed(RANROTSeed *ioSeed)
unsigned RanrotWithSeed(RANROTSeed *ioSeed)
struct RANROTSeed RANROTSeed
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34