38#define DUMP_COMBINER 0
45@interface OOCombinedEmissionMapGenerator (Private)
47- (id) initWithEmissionMapSpec:(NSDictionary *)emissionMapSpec
48 emissionColor:(
OOColor *)emissionColor
50 diffuseColor:(
OOColor *)diffuseColor
51 illuminationMapSpec:(NSDictionary *)illuminationMapSpec
52 illuminationColor:(
OOColor *)illuminationColor
53 isCombinedMap:(BOOL)isCombinedMap
54 optionsSpecifier:(NSDictionary *)spec;
63- (id) initWithEmissionMapSpec:(NSDictionary *)emissionMapSpec
64 emissionColor:(
OOColor *)emissionColor
66 diffuseColor:(
OOColor *)diffuseColor
67 illuminationMapSpec:(NSDictionary *)illuminationMapSpec
68 illuminationColor:(
OOColor *)illuminationColor
69 optionsSpecifier:(NSDictionary *)spec
82- (id) initWithEmissionAndIlluminationMapSpec:(NSDictionary *)emissionAndIlluminationMapSpec
84 diffuseColor:(
OOColor *)diffuseColor
85 emissionColor:(
OOColor *)emissionColor
86 illuminationColor:(
OOColor *)illuminationColor
87 optionsSpecifier:(NSDictionary *)spec
100- (id) initWithEmissionMapSpec:(NSDictionary *)emissionMapSpec
101 emissionColor:(
OOColor *)emissionColor
103 diffuseColor:(
OOColor *)diffuseColor
104 illuminationMapSpec:(NSDictionary *)illuminationMapSpec
105 illuminationColor:(
OOColor *)illuminationColor
106 isCombinedMap:(BOOL)isCombinedMap
107 optionsSpecifier:(NSDictionary *)spec
109 if (emissionMapSpec ==
nil && illuminationMapSpec ==
nil)
115 NSParameterAssert(illuminationMapSpec ==
nil || !isCombinedMap);
123 if ((
self = [super initWithPath:
@"<generated emission map>" options:options]))
130 illuminationColor =
ModulateColor(diffuseColor, illuminationColor);
132 if ([emissionColor isWhite]) emissionColor =
nil;
133 if ([illuminationColor isWhite]) illuminationColor =
nil;
134 if (!isCombinedMap && illuminationMapSpec ==
nil) diffuseMap =
nil;
138 [
emissionSpec oo_setBool:YES forKey:kOOTextureSpecifierExtraShrinkKey];
139 _emissionSpec = emissionSpec;
143 _illuminationSpec = illuminationSpec;
149 _isCombinedMap = isCombinedMap;
151 _textureOptions = options;
152 _anisotropy = anisotropy;
163 if (diffuseMap !=
nil)
167 _diffuseDesc = [[
diffuseMap shortDescription] copy];
176 if (_emissionSpec !=
nil)
186 if (_illuminationSpec !=
nil)
207 if (_isCombinedMap) [
cacheKey appendString:@"combined emission and illumination map;"];
208 else if (_emissionSpec ==
nil) [
cacheKey appendString:@"illumination map;"];
209 else if (_illuminationSpec ==
nil) [
cacheKey appendString:@"emission map;"];
210 else [
cacheKey appendString:@"merged emission and illumination map;"];
212 NSString *emissionDesc =
nil;
213 if (_emissionSpec !=
nil)
216 [
cacheKey appendFormat:@"emission:{%@}", emissionDesc];
221 NSString *illuminationDesc =
nil;
224 illuminationDesc = [
NSString stringWithFormat:@"%@:a", emissionDesc];
226 else if (_illuminationSpec !=
nil)
231 if (illuminationDesc !=
nil)
233 [
cacheKey appendFormat:@"illumination:{%@}*{%@}", illuminationDesc, [
_diffuseMap cacheKey]];
268 BOOL haveIllumination = NO;
272 [
result appendFormat:@"emission map: %@", _emissionDesc];
275 [
result appendString:@".rgb"];
284 [
result appendFormat:@", illumination map: %@.a", _emissionDesc];
285 haveIllumination = YES;
292 [
result appendFormat:@"illumination map: %@", _illuminationDesc];
293 haveIllumination = YES;
296 if (haveIllumination)
300 [
result appendFormat:@" * %@", _diffuseDesc];
340 BOOL haveEmission = NO, haveIllumination = NO, haveDiffuse = NO;
343 static unsigned sTexID = 0;
344 unsigned texID = ++sTexID, dumpCount = 0;
346#define DUMP(pm, label) OODumpPixMap(pm, [NSString stringWithFormat:@"lightmap %u.%u - %@", texID, ++dumpCount, label]);
348#define DUMP(pm, label) do {} while (0)
360 haveIllumination = YES;
361 DUMP(illuminationPx,
@"extracted illumination map");
373 NSAssert(!
_isCombinedMap,
@"OOCombinedEmissionMapGenerator configured with both illumination map and combined emission/illumination map.");
377 haveIllumination = YES;
378 DUMP(illuminationPx,
@"source illumination map");
385 DUMP(illuminationPx,
@"modulated illumination map");
392 if (haveIllumination && haveDiffuse)
398 DUMP(illuminationPx,
@"combined diffuse and illumination map");
402 if (haveIllumination)
411 else if (haveIllumination)
416 illuminationPx.
pixels = NULL;
418 haveIllumination = NO;
422 (void)haveIllumination;
438 OOLogERR(
@"texture.combinedEmissionMap.error",
@"Unknown error loading %@",
self);
447 if (a ==
nil)
return b;
448 if (b ==
nil)
return a;
470 if (pmA->
width != minWidth || pmA->
height != minHeight)
474 if (pmB->
width != minWidth || pmB->
height != minHeight)
static OOColor * ModulateColor(OOColor *a, OOColor *b)
static void ScaleToMatch(OOPixMap *pmA, OOPixMap *pmB)
#define OOLogERR(class, format,...)
BOOL OOPixMapModulateUniform(OOPixMap *ioPixMap, float f0, float f1, float f2, float f3)
BOOL OOExtractPixMapChannel(OOPixMap *ioPixMap, uint8_t channelIndex, BOOL compactWhenDone)
BOOL OOPixMapAddPixMap(OOPixMap *ioDstPixMap, OOPixMap otherPixMap)
BOOL OOPixMapModulatePixMap(OOPixMap *ioDstPixMap, OOPixMap otherPixMap)
BOOL OOPixMapToRGBA(OOPixMap *ioPixMap)
uint_fast32_t OOPixMapDimension
void OOFreePixMap(OOPixMap *ioPixMap)
const OOPixMap kOONullPixMap
OOINLINE BOOL OOIsNullPixMap(OOPixMap pixMap)
BOOL OOIsValidPixMap(OOPixMap pixMap)
BOOL OOPixMapFormatHasAlpha(OOPixMapFormat format) PURE_FUNC
OOPixMap OODuplicatePixMap(OOPixMap srcPixMap, size_t desiredSize)
OOINLINE void OOCompactPixMap(OOPixMap *ioPixMap)
OOPixMap OOScalePixMap(OOPixMap srcPixMap, OOPixMapDimension dstWidth, OOPixMapDimension dstHeight, BOOL leaveSpaceForMipMaps)
OOTextureFlags OOApplyTextureOptionDefaults(OOTextureFlags options)
OOPixMapFormat OOTextureDataFormat
BOOL OOInterpretTextureSpecifier(id specifier, NSString **outName, OOTextureFlags *outOptions, float *outAnisotropy, float *outLODBias, BOOL ignoreExtract)
NSString * OOTextureCacheKeyForSpecifier(id specifier)
NSString * constructCacheKey()
NSString * rgbaDescription()
OOColor * colorWithRGBAComponents:(OORGBAComponents components)
OORGBAComponents rgbaComponents()
OOColor * _illuminationColor
NSString * constructCacheKey()
NSString * _illuminationDesc
NSDictionary * _illuminationSpec
NSString * descriptionComponents()
id initWithEmissionMapSpec:emissionColor:diffuseMap:diffuseColor:illuminationMapSpec:illuminationColor:isCombinedMap:optionsSpecifier:(NSDictionary *emissionMapSpec, [emissionColor] OOColor *emissionColor, [diffuseMap] OOTexture *diffuseMap, [diffuseColor] OOColor *diffuseColor, [illuminationMapSpec] NSDictionary *illuminationMapSpec, [illuminationColor] OOColor *illuminationColor, [isCombinedMap] BOOL isCombinedMap, [optionsSpecifier] NSDictionary *spec)
NSDictionary * _emissionSpec
uint32_t textureOptions()
OOTextureDataFormat _format
id loaderWithTextureSpecifier:extraOptions:folder:(id specifier,[extraOptions] uint32_t extraOptions,[folder] NSString *folder)
BOOL getResult:format:originalWidth:originalHeight:(OOPixMap *result,[format] OOTextureDataFormat *outFormat,[originalWidth] uint32_t *outWidth,[originalHeight] uint32_t *outHeight)
OOPixMap copyPixMapRepresentation()