37#define DUMP_COMBINER 0
42@interface OOCombinedEmissionMapGenerator (Private)
44- (id)initWithEmissionMapSpec:(NSDictionary*)emissionMapSpec
45 emissionColor:(
OOColor*)emissionColor
47 diffuseColor:(
OOColor*)diffuseColor
48 illuminationMapSpec:(NSDictionary*)illuminationMapSpec
49 illuminationColor:(
OOColor*)illuminationColor
50 isCombinedMap:(BOOL)isCombinedMap
51 optionsSpecifier:(NSDictionary*)spec;
59- (id)initWithEmissionMapSpec:(NSDictionary*)emissionMapSpec
60 emissionColor:(
OOColor*)emissionColor
62 diffuseColor:(
OOColor*)diffuseColor
63 illuminationMapSpec:(NSDictionary*)illuminationMapSpec
64 illuminationColor:(
OOColor*)illuminationColor
65 optionsSpecifier:(NSDictionary*)spec
77- (id)initWithEmissionAndIlluminationMapSpec:(NSDictionary*)emissionAndIlluminationMapSpec
79 diffuseColor:(
OOColor*)diffuseColor
80 emissionColor:(
OOColor*)emissionColor
81 illuminationColor:(
OOColor*)illuminationColor
82 optionsSpecifier:(NSDictionary*)spec
94- (id)initWithEmissionMapSpec:(NSDictionary*)emissionMapSpec
95 emissionColor:(
OOColor*)emissionColor
97 diffuseColor:(
OOColor*)diffuseColor
98 illuminationMapSpec:(NSDictionary*)illuminationMapSpec
99 illuminationColor:(
OOColor*)illuminationColor
100 isCombinedMap:(BOOL)isCombinedMap
101 optionsSpecifier:(NSDictionary*)spec
103 if (emissionMapSpec ==
nil && illuminationMapSpec ==
nil) {
108 NSParameterAssert(illuminationMapSpec ==
nil || !isCombinedMap);
116 if ((
self = [super initWithPath:
@"<generated emission map>" options:options])) {
122 illuminationColor =
ModulateColor(diffuseColor, illuminationColor);
124 if ([emissionColor isWhite])
126 if ([illuminationColor isWhite])
127 illuminationColor =
nil;
128 if (!isCombinedMap && illuminationMapSpec ==
nil)
133 [
emissionSpec oo_setBool:YES forKey:kOOTextureSpecifierExtraShrinkKey];
134 _emissionSpec = emissionSpec;
138 _illuminationSpec = illuminationSpec;
144 _isCombinedMap = isCombinedMap;
146 _textureOptions = options;
147 _anisotropy = anisotropy;
152 if ([
OOTexture existingTextureForKey:_cacheKey] ==
nil) {
157 if (diffuseMap !=
nil) {
160 _diffuseDesc = [[
diffuseMap shortDescription] copy];
169 if (_emissionSpec !=
nil) {
178 if (_illuminationSpec !=
nil) {
198 [
cacheKey appendString:@"combined emission and illumination map;"];
199 else if (_emissionSpec ==
nil)
200 [
cacheKey appendString:@"illumination map;"];
201 else if (_illuminationSpec ==
nil)
202 [
cacheKey appendString:@"emission map;"];
204 [
cacheKey appendString:@"merged emission and illumination map;"];
206 NSString* emissionDesc =
nil;
207 if (_emissionSpec !=
nil) {
209 [
cacheKey appendFormat:@"emission:{%@}", emissionDesc];
210 if (_emissionColor !=
nil)
215 NSString* illuminationDesc =
nil;
216 if (_isCombinedMap) {
217 illuminationDesc = [
NSString stringWithFormat:@"%@:a", emissionDesc];
218 }
else if (_illuminationSpec !=
nil) {
222 if (illuminationDesc !=
nil) {
223 [
cacheKey appendFormat:@"illumination:{%@}*{%@}", illuminationDesc, [
_diffuseMap cacheKey]];
224 if (_illuminationColor !=
nil)
257 BOOL haveIllumination = NO;
260 [
result appendFormat:@"emission map: %@", _emissionDesc];
262 [
result appendString:@".rgb"];
269 [
result appendFormat:@", illumination map: %@.a", _emissionDesc];
270 haveIllumination = YES;
276 [
result appendString:@", "];
277 [
result appendFormat:@"illumination map: %@", _illuminationDesc];
278 haveIllumination = YES;
281 if (haveIllumination) {
283 [
result appendFormat:@" * %@", _diffuseDesc];
317 BOOL haveEmission = NO, haveIllumination = NO, haveDiffuse = NO;
320 static unsigned sTexID = 0;
321 unsigned texID = ++sTexID, dumpCount = 0;
323#define DUMP(pm, label) OODumpPixMap(pm, [NSString stringWithFormat:@"lightmap %u.%u - %@", texID, ++dumpCount, label]);
325#define DUMP(pm, label) \
339 haveIllumination = YES;
340 DUMP(illuminationPx,
@"extracted illumination map");
350 NSAssert(!
_isCombinedMap,
@"OOCombinedEmissionMapGenerator configured with both illumination map and combined emission/illumination map.");
354 haveIllumination = YES;
355 DUMP(illuminationPx,
@"source illumination map");
361 DUMP(illuminationPx,
@"modulated illumination map");
369 if (haveIllumination && haveDiffuse) {
374 DUMP(illuminationPx,
@"combined diffuse and illumination map");
378 if (haveIllumination) {
384 }
else if (haveIllumination) {
388 illuminationPx.
pixels = NULL;
390 haveIllumination = NO;
394 (void)haveIllumination;
408 OOLogERR(
@"texture.combinedEmissionMap.error",
@"Unknown error loading %@",
self);
440 if (pmA->
width != minWidth || pmA->
height != minHeight) {
443 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)
void OOFreePixMap(OOPixMap *ioPixMap)
uint32_t OOPixMapDimension
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()