Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOMaterialConvenienceCreators.m File Reference
+ Include dependency graph for OOMaterialConvenienceCreators.m:

Go to the source code of this file.

Classes

struct  OOMaterialSynthContext
 

Macros

#define USE_NEW_SHADER_SYNTHESIZER   0
 

Functions

static void SetUniform (NSMutableDictionary *uniforms, NSString *key, NSString *type, id value)
 
static void SetUniformFloat (OOMaterialSynthContext *context, NSString *key, float value)
 
static void AddTexture (OOMaterialSynthContext *context, NSString *uniformName, NSString *nonShaderKey, NSString *macroName, NSDictionary *specifier)
 
static void AddColorIfAppropriate (OOMaterialSynthContext *context, SEL selector, NSString *key, NSString *macroName)
 
static void AddMacroColorIfAppropriate (OOMaterialSynthContext *context, SEL selector, NSString *macroName)
 
static void SynthDiffuse (OOMaterialSynthContext *context, NSString *name)
 
static void SynthEmissionAndIllumination (OOMaterialSynthContext *context)
 
static void SynthNormalMap (OOMaterialSynthContext *context)
 
static void SynthSpecular (OOMaterialSynthContext *context)
 

Macro Definition Documentation

◆ USE_NEW_SHADER_SYNTHESIZER

#define USE_NEW_SHADER_SYNTHESIZER   0

Definition at line 29 of file OOMaterialConvenienceCreators.m.

Function Documentation

◆ AddColorIfAppropriate()

static void AddColorIfAppropriate ( OOMaterialSynthContext * context,
SEL selector,
NSString * key,
NSString * macroName )
static

Definition at line 420 of file OOMaterialConvenienceCreators.m.

421{
422 OOColor *color = [context->inConfig performSelector:selector];
423
424 if (color != nil)
425 {
426 [context->outConfig setObject:[color normalizedArray] forKey:key];
427 if (macroName != nil) [context->macros setObject:@"1" forKey:macroName];
428 }
429}
return nil
NSArray * normalizedArray()
Definition OOColor.m:511

References nil, and OOColor::normalizedArray.

Referenced by SynthDiffuse(), and SynthEmissionAndIllumination().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddMacroColorIfAppropriate()

static void AddMacroColorIfAppropriate ( OOMaterialSynthContext * context,
SEL selector,
NSString * macroName )
static

Definition at line 432 of file OOMaterialConvenienceCreators.m.

433{
434 OOColor *color = [context->inConfig performSelector:selector];
435
436 if (color != nil)
437 {
438 NSString *macroText = [NSString stringWithFormat:@"vec4(%g, %g, %g, %g)",
439 [color redComponent],
440 [color greenComponent],
441 [color blueComponent],
442 [color alphaComponent]];
443 [context->macros setObject:macroText forKey:macroName];
444 }
445}
float alphaComponent()
Definition OOColor.m:486
float blueComponent()
Definition OOColor.m:362
float redComponent()
Definition OOColor.m:350
float greenComponent()
Definition OOColor.m:356

References OOColor::alphaComponent, OOColor::blueComponent, OOColor::greenComponent, nil, and OOColor::redComponent.

Referenced by SynthEmissionAndIllumination().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddTexture()

static void AddTexture ( OOMaterialSynthContext * context,
NSString * uniformName,
NSString * nonShaderKey,
NSString * macroName,
NSDictionary * specifier )
static

Definition at line 402 of file OOMaterialConvenienceCreators.m.

403{
404 NSCParameterAssert(context->texturesUsed < context->maxTextures);
405
406 context->texturesUsed++;
407 SetUniform(context->uniforms, uniformName, @"texture", [NSNumber numberWithUnsignedInteger:[context->textures count]]);
408 [context->textures addObject:specifier];
409 if (nonShaderKey != nil)
410 {
411 [context->outConfig setObject:specifier forKey:kOOMaterialDiffuseMapName];
412 }
413 if (macroName != nil)
414 {
415 [context->macros setObject:@"1" forKey:macroName];
416 }
417}
static void SetUniform(NSMutableDictionary *uniforms, NSString *key, NSString *type, id value)
unsigned count

References count, OOMaterialSynthContext::maxTextures, nil, SetUniform(), OOMaterialSynthContext::textures, OOMaterialSynthContext::texturesUsed, and OOMaterialSynthContext::uniforms.

Referenced by SynthDiffuse(), SynthEmissionAndIllumination(), SynthNormalMap(), and SynthSpecular().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetUniform()

static void SetUniform ( NSMutableDictionary * uniforms,
NSString * key,
NSString * type,
id value )
static

Definition at line 390 of file OOMaterialConvenienceCreators.m.

391{
392 [uniforms setObject:[NSDictionary dictionaryWithObjectsAndKeys:type, @"type", value, @"value", nil] forKey:key];
393}

Referenced by AddTexture(), and SetUniformFloat().

+ Here is the caller graph for this function:

◆ SetUniformFloat()

static void SetUniformFloat ( OOMaterialSynthContext * context,
NSString * key,
float value )
static

Definition at line 396 of file OOMaterialConvenienceCreators.m.

397{
398 SetUniform(context->uniforms, key, @"float", [NSNumber numberWithFloat:value]);
399}

References SetUniform(), and OOMaterialSynthContext::uniforms.

Referenced by SynthNormalMap(), and SynthSpecular().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SynthDiffuse()

static void SynthDiffuse ( OOMaterialSynthContext * context,
NSString * name )
static

Definition at line 448 of file OOMaterialConvenienceCreators.m.

449{
450 // Set up diffuse map if appropriate.
451 NSDictionary *diffuseMapSpec = [context->inConfig oo_diffuseMapSpecifierWithDefaultName:name];
452 if (diffuseMapSpec != nil && context->texturesUsed < context->maxTextures)
453 {
454 AddTexture(context, @"uDiffuseMap", kOOMaterialDiffuseMapName, @"OOSTD_DIFFUSE_MAP", diffuseMapSpec);
455
456 if ([diffuseMapSpec oo_boolForKey:@"cube_map"])
457 {
458 [context->macros setObject:@"1" forKey:@"OOSTD_DIFFUSE_MAP_IS_CUBE_MAP"];
459 }
460 }
461 else
462 {
463 // No diffuse map must be specified explicitly.
464 [context->outConfig setObject:@"" forKey:kOOMaterialDiffuseMapName];
465 }
466
467 // Set up diffuse colour if any.
468 AddColorIfAppropriate(context, @selector(oo_diffuseColor), kOOMaterialDiffuseColorName, nil);
469}
static void AddColorIfAppropriate(OOMaterialSynthContext *context, SEL selector, NSString *key, NSString *macroName)
static void AddTexture(OOMaterialSynthContext *context, NSString *uniformName, NSString *nonShaderKey, NSString *macroName, NSDictionary *specifier)
NSString *const kOOMaterialDiffuseColorName
NSString *const kOOMaterialDiffuseMapName

References AddColorIfAppropriate(), AddTexture(), kOOMaterialDiffuseColorName, kOOMaterialDiffuseMapName, OOMaterialSynthContext::maxTextures, nil, and OOMaterialSynthContext::texturesUsed.

+ Here is the call graph for this function:

◆ SynthEmissionAndIllumination()

static void SynthEmissionAndIllumination ( OOMaterialSynthContext * context)
static

Definition at line 472 of file OOMaterialConvenienceCreators.m.

473{
474 // Read the various emission and illumination textures, and decide what to do with them.
475 NSDictionary *emissionMapSpec = [context->inConfig oo_emissionMapSpecifier];
476 NSDictionary *illuminationMapSpec = [context->inConfig oo_illuminationMapSpecifier];
477 NSDictionary *emissionAndIlluminationSpec = [context->inConfig oo_emissionAndIlluminationMapSpecifier];
478 BOOL isCombinedSpec = NO;
479 BOOL haveIlluminationMap = NO;
480
481 if (emissionMapSpec == nil && emissionAndIlluminationSpec != nil)
482 {
483 emissionMapSpec = emissionAndIlluminationSpec;
484 if (illuminationMapSpec == nil) isCombinedSpec = YES; // Else use only emission part of emission_and_illumination_map, combined with full illumination_map.
485 }
486
487 if (emissionMapSpec != nil && context->texturesUsed < context->maxTextures)
488 {
489 /* FIXME: at this point, if there is an illumination map, we should
490 consider merging it into the emission map using
491 OOCombinedEmissionMapGenerator if the total number of texture
492 specifiers is greater than context->maxTextures. This will
493 require adding a new type of texture specifier - not a big deal.
494 -- Ahruman 2010-05-21
495 */
496 AddTexture(context, @"uEmissionMap", nil, isCombinedSpec ? @"OOSTD_EMISSION_AND_ILLUMINATION_MAP" : @"OOSTD_EMISSION_MAP", emissionMapSpec);
497 /* Note that this sets emission_color, not emission_modulate_color.
498 This is because the emission colour value is sent through the
499 standard OpenGL emission colour attribute by OOBasicMaterial.
500 */
501 AddColorIfAppropriate(context, @selector(oo_emissionModulateColor), kOOMaterialEmissionColorName, @"OOSTD_EMISSION");
502
503 haveIlluminationMap = isCombinedSpec;
504 }
505 else
506 {
507 // No emission map, use overall emission colour if specified.
508 AddColorIfAppropriate(context, @selector(oo_emissionColor), kOOMaterialEmissionColorName, @"OOSTD_EMISSION");
509 }
510
511 if (illuminationMapSpec != nil && context->texturesUsed < context->maxTextures)
512 {
513 AddTexture(context, @"uIlluminationMap", nil, @"OOSTD_ILLUMINATION_MAP", illuminationMapSpec);
514 haveIlluminationMap = YES;
515 }
516
517 if (haveIlluminationMap)
518 {
519 AddMacroColorIfAppropriate(context, @selector(oo_illuminationModulateColor), @"OOSTD_ILLUMINATION_COLOR");
520 }
521}
static void AddMacroColorIfAppropriate(OOMaterialSynthContext *context, SEL selector, NSString *macroName)
NSString *const kOOMaterialEmissionColorName

References AddColorIfAppropriate(), AddMacroColorIfAppropriate(), AddTexture(), kOOMaterialEmissionColorName, OOMaterialSynthContext::maxTextures, nil, and OOMaterialSynthContext::texturesUsed.

+ Here is the call graph for this function:

◆ SynthNormalMap()

static void SynthNormalMap ( OOMaterialSynthContext * context)
static

Definition at line 524 of file OOMaterialConvenienceCreators.m.

525{
526 if (context->texturesUsed < context->maxTextures)
527 {
528 BOOL hasParallax = YES;
529 NSDictionary *normalMapSpec = [context->inConfig oo_normalAndParallaxMapSpecifier];
530 if (normalMapSpec == nil)
531 {
532 hasParallax = NO;
533 normalMapSpec = [context->inConfig oo_normalMapSpecifier];
534 }
535
536 if (normalMapSpec != nil)
537 {
538 AddTexture(context, @"uNormalMap", nil, @"OOSTD_NORMAL_MAP", normalMapSpec);
539
540 if (hasParallax)
541 {
542 [context->macros setObject:@"1" forKey:@"OOSTD_NORMAL_AND_PARALLAX_MAP"];
543 SetUniformFloat(context, @"uParallaxScale", [context->inConfig oo_parallaxScale]);
544 SetUniformFloat(context, @"uParallaxBias", [context->inConfig oo_parallaxBias]);
545 }
546 }
547 }
548}
static void SetUniformFloat(OOMaterialSynthContext *context, NSString *key, float value)

References AddTexture(), OOMaterialSynthContext::inConfig, OOMaterialSynthContext::maxTextures, nil, SetUniformFloat(), and OOMaterialSynthContext::texturesUsed.

+ Here is the call graph for this function:

◆ SynthSpecular()

static void SynthSpecular ( OOMaterialSynthContext * context)
static

Definition at line 551 of file OOMaterialConvenienceCreators.m.

552{
553 GLint shininess = [context->inConfig oo_specularExponent];
554 if (shininess <= 0) return;
555
556 GLfloat gloss = [context->inConfig oo_gloss];
557 if (gloss < 0.0f || gloss > 1.0f) return;
558
559 BOOL gammaCorrect = [context->inConfig oo_gammaCorrect];
560
561 NSDictionary *specularMapSpec = nil;
562 OOColor *specularColor = nil;
563
564 if (context->texturesUsed < context->maxTextures)
565 {
566 specularMapSpec = [context->inConfig oo_combinedSpecularMapSpecifier];
567 }
568
569 if (specularMapSpec != nil) specularColor = [context->inConfig oo_specularModulateColor];
570 else specularColor = [context->inConfig oo_specularColor];
571 if ([specularColor isBlack]) return;
572
573 SetUniformFloat(context, @"uGloss", gloss);
574
575 [context->outConfig setObject:[NSNumber numberWithUnsignedInt:shininess] forKey:kOOMaterialSpecularExponentLegacyName];
576
577 if (specularMapSpec != nil)
578 {
579 AddTexture(context, @"uSpecularMap", kOOMaterialDiffuseMapName, @"OOSTD_SPECULAR_MAP", specularMapSpec);
580 }
581
582 if (specularColor != nil)
583 {
584 /* As with emission colour, specular_modulate_color is transformed to
585 specular_color here because the shader reads it from the standard
586 material specular colour property set by OOBasicMaterial.
587 */
588 [context->outConfig setObject:[specularColor normalizedArray] forKey:kOOMaterialSpecularColorName];
589 }
590 [context->macros setObject:@"1" forKey:@"OOSTD_SPECULAR"];
591
592 // setting a bool as a float uniform, to be used in the shader as a bool again
593 // this is how hackish I can get... maybe a better way exists, but this is quick
594 // and can be used also for the shader materials in a not too different way
595 // - Nikos 20181001
596 SetUniformFloat(context, @"uGammaCorrect", (float)gammaCorrect);
597}

References AddTexture(), kOOMaterialDiffuseMapName, OOMaterialSynthContext::maxTextures, nil, OOColor::normalizedArray, SetUniformFloat(), and OOMaterialSynthContext::texturesUsed.

+ Here is the call graph for this function: