From 938d49eeca2e33edd0531e76ebd0bbdfafc94c20 Mon Sep 17 00:00:00 2001 From: AnotherCommander Date: Fri, 17 Apr 2020 13:44:18 +0200 Subject: [PATCH] Custom planets now support normal maps, with specular on their alpha channel. --- Resources/Config/material-defaults.plist | 30 ++++++++++++++++++++++++ src/Core/Entities/OOPlanetEntity.h | 1 + src/Core/Entities/OOPlanetEntity.m | 28 ++++++++++++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/Resources/Config/material-defaults.plist b/Resources/Config/material-defaults.plist index 5d9334b4..1f5728cb 100644 --- a/Resources/Config/material-defaults.plist +++ b/Resources/Config/material-defaults.plist @@ -64,6 +64,21 @@ OOSTD_CUBE_MAP = 0; OOSTD_HARSH_MISTRESS = 1; }; + "planet-customized-normspec-macros" = + { + IS_OOLITE = 1; + OOSTD_DIFFUSE_MAP = 1; + OOSTD_CUBE_MAP = 0; + OOSTD_NORMAL_AND_SPECULAR_MAP = 1; + }; + "moon-customized-normspec-macros" = + { + IS_OOLITE = 1; + OOSTD_DIFFUSE_MAP = 1; + OOSTD_CUBE_MAP = 0; + OOSTD_HARSH_MISTRESS = 1; + OOSTD_NORMAL_AND_SPECULAR_MAP = 1; + }; "planet-customized-cubemap-macros" = { IS_OOLITE = 1; @@ -77,6 +92,21 @@ OOSTD_CUBE_MAP = 1; OOSTD_HARSH_MISTRESS = 1; }; + "planet-customized-cubemap-normspec-macros" = + { + IS_OOLITE = 1; + OOSTD_DIFFUSE_MAP = 1; + OOSTD_CUBE_MAP = 1; + OOSTD_NORMAL_AND_SPECULAR_MAP = 1; + }; + "moon-customized-cubemap-normspec-macros" = + { + IS_OOLITE = 1; + OOSTD_DIFFUSE_MAP = 1; + OOSTD_CUBE_MAP = 1; + OOSTD_HARSH_MISTRESS = 1; + OOSTD_NORMAL_AND_SPECULAR_MAP = 1; + }; "atmosphere-material" = { vertex_shader = "oolite-default-atmosphere.vertex"; diff --git a/src/Core/Entities/OOPlanetEntity.h b/src/Core/Entities/OOPlanetEntity.h index 4c1160ba..7360ddd0 100644 --- a/src/Core/Entities/OOPlanetEntity.h +++ b/src/Core/Entities/OOPlanetEntity.h @@ -58,6 +58,7 @@ MA 02110-1301, USA. NSDictionary *_materialParameters; NSString *_textureName; + NSString *_normSpecMapName; NSString *_name; } diff --git a/src/Core/Entities/OOPlanetEntity.m b/src/Core/Entities/OOPlanetEntity.m index 9a71bae4..9642ea22 100644 --- a/src/Core/Entities/OOPlanetEntity.m +++ b/src/Core/Entities/OOPlanetEntity.m @@ -181,9 +181,11 @@ static const double kMesosphere = 10.0 * ATMOSPHERE_DEPTH; // atmosphere effect _mesopause2 = (atmosphere) ? (kMesosphere + collision_radius) * (kMesosphere + collision_radius) : 0.0; + _normSpecMapName = [[dict oo_stringForKey:@"texture_normspec"] retain]; // must be set up before _textureName + _textureName = [[dict oo_stringForKey:@"texture"] retain]; [self setUpPlanetFromTexture:_textureName]; - [_planetDrawable setRadius:collision_radius]; + [_planetDrawable setRadius:collision_radius]; // Orientation should be handled by the code that calls this planetEntity. Starting with a default value anyway. orientation = (Quaternion){ M_SQRT1_2, M_SQRT1_2, 0, 0 }; @@ -450,6 +452,7 @@ static OOColor *ColorWithHSBColor(Vector c) //DESTROY(_airColor); // this CTDs on loading savegames.. :( DESTROY(_materialParameters); DESTROY(_textureName); + DESTROY(_normSpecMapName); [[OOGraphicsResetManager sharedManager] unregisterClient:self]; @@ -841,7 +844,28 @@ static OOColor *ColorWithHSBColor(Vector c) } } else textureName = @"dynamic"; - + + // let's try giving some love to normalMap too + if (_normSpecMapName) + { + NSDictionary *nspec = [NSDictionary dictionaryWithObjectsAndKeys:_normSpecMapName, @"name", @"yes", @"repeat_s", @"linear", @"min_filter", @"yes", @"cube_map", nil]; + normalMap = [OOTexture textureWithConfiguration:nspec]; + if (normalMap != nil) // OOTexture will have logged a file-not-found warning. + { + if (shadersOn) + { + [normalMap ensureFinishedLoading]; // only know if it is a cube map if it's loaded + if ([normalMap isCubeMap]) + { + macros = [materialDefaults oo_dictionaryForKey:isMoon ? @"moon-customized-cubemap-normspec-macros" : @"planet-customized-cubemap-normspec-macros"]; + } + else + { + macros = [materialDefaults oo_dictionaryForKey:isMoon ? @"moon-customized-normspec-macros" : @"planet-customized-normspec-macros"]; + } + } + } + } } else {