diff --git a/Components/Hlms/Pbs/include/OgreHlmsJsonPbs.h b/Components/Hlms/Pbs/include/OgreHlmsJsonPbs.h index 02e4b3af309..7537638e881 100644 --- a/Components/Hlms/Pbs/include/OgreHlmsJsonPbs.h +++ b/Components/Hlms/Pbs/include/OgreHlmsJsonPbs.h @@ -60,6 +60,7 @@ namespace Ogre static void parseScale( const rapidjson::Value &jsonArray, Vector4 &offsetScale ); static inline Vector3 parseVector3Array( const rapidjson::Value &jsonArray ); + static inline Vector4 parseVector4Array( const rapidjson::Value &jsonArray ); static inline ColourValue parseColourValueArray( const rapidjson::Value &jsonArray, const ColourValue &defaultValue = ColourValue::White ); diff --git a/Components/Hlms/Pbs/src/OgreHlmsJsonPbs.cpp b/Components/Hlms/Pbs/src/OgreHlmsJsonPbs.cpp index ca5d7038baf..c6bc54a15b2 100644 --- a/Components/Hlms/Pbs/src/OgreHlmsJsonPbs.cpp +++ b/Components/Hlms/Pbs/src/OgreHlmsJsonPbs.cpp @@ -279,6 +279,20 @@ namespace Ogre return retVal; } //----------------------------------------------------------------------------------- + inline Vector4 HlmsJsonPbs::parseVector4Array( const rapidjson::Value &jsonArray ) + { + Vector4 retVal( Vector4::ZERO ); + + const rapidjson::SizeType arraySize = std::min( 4u, jsonArray.Size() ); + for( rapidjson::SizeType i=0; i( jsonArray[i].GetDouble() ); + } + + return retVal; + } + //----------------------------------------------------------------------------------- inline ColourValue HlmsJsonPbs::parseColourValueArray( const rapidjson::Value &jsonArray, const ColourValue &defaultValue ) { @@ -536,6 +550,22 @@ namespace Ogre const rapidjson::Value &subobj = itor->value; loadTexture( subobj, blocks, PBSM_REFLECTION, pbsDatablock, resourceGroup ); } + + itor = json.FindMember( "user_values" ); + if( itor != json.MemberEnd() && itor->value.IsObject() ) + { + const rapidjson::Value &subobj = itor->value; + for( int i = 0; i < 3; ++i ) + { + itor = subobj.FindMember( StringConverter::toString( i ).c_str() ); + + if( itor != subobj.MemberEnd() && itor->value.IsArray() ) + { + pbsDatablock->setUserValue( static_cast( i ), + parseVector4Array( itor->value ) ); + } + } + } } //----------------------------------------------------------------------------------- void HlmsJsonPbs::toQuotedStr( HlmsPbsDatablock::Workflows value, String &outString ) @@ -881,6 +911,40 @@ namespace Ogre if( pbsDatablock->getTexture( PBSM_REFLECTION ) ) saveTexture( "reflection", PBSM_REFLECTION, pbsDatablock, outString ); + + bool bHasUserValues = false; + for( int i = 0; i < 3 && !bHasUserValues; ++i ) + { + const Vector4 userValue = pbsDatablock->getUserValue( static_cast( i ) ); + if( userValue != Vector4::ZERO ) + bHasUserValues = true; + } + + if( bHasUserValues ) + { + outString += ",\n\t\t\t\"user_values\" :\n\t\t\t{"; + + bool bFirstElement = true; + for( int i = 0; i < 3; ++i ) + { + const Vector4 userValue = pbsDatablock->getUserValue( static_cast( i ) ); + + if( userValue != Vector4::ZERO ) + { + char tmpBuffer[64]; + LwString keyName( LwString::FromEmptyPointer( tmpBuffer, sizeof( tmpBuffer ) ) ); + + if( !bFirstElement ) + keyName.a( "," ); + keyName.a( "\n\t\t\t\t\"", i, "\" : " ); + outString += keyName.c_str(); + HlmsJson::toStr( userValue, outString ); + + bFirstElement = false; + } + } + outString += "\n\t\t\t}"; + } } //----------------------------------------------------------------------------------- void HlmsJsonPbs::collectSamplerblocks( const HlmsDatablock *datablock, diff --git a/Docs/2.0/JSON/PbsAllSettings.json b/Docs/2.0/JSON/PbsAllSettings.json index 7d2eeb09632..f7a35ad2528 100644 --- a/Docs/2.0/JSON/PbsAllSettings.json +++ b/Docs/2.0/JSON/PbsAllSettings.json @@ -164,6 +164,13 @@ including invalid combinations (i.e. having a Metallic texture and a Specular te { "texture" : "cubemap.png", "sampler" : "unique_name" + }, + + "user_values" : + { + "0" : [0.0, 0.0, 0.0, 0.0], + "1" : [0.0, 0.0, 0.0, 0.0], + "2" : [0.0, 0.0, 0.0, 0.0] } } }