diff --git a/Engine/source/T3D/assets/ImageAsset.cpp b/Engine/source/T3D/assets/ImageAsset.cpp index 1af4a60ab..a65667958 100644 --- a/Engine/source/T3D/assets/ImageAsset.cpp +++ b/Engine/source/T3D/assets/ImageAsset.cpp @@ -315,7 +315,7 @@ const char* ImageAsset::getImageTypeNameFromType(ImageAsset::ImageTypes type) static const char* _names[] = { "Albedo", "Normal", - "PBRConfig", + "ORMConfig", "GUI", "Roughness", "AO", diff --git a/Engine/source/T3D/assets/ImageAsset.h b/Engine/source/T3D/assets/ImageAsset.h index 5287c0c00..1b4925aef 100644 --- a/Engine/source/T3D/assets/ImageAsset.h +++ b/Engine/source/T3D/assets/ImageAsset.h @@ -56,7 +56,7 @@ public: { Albedo = 0, Normal = 1, - PBRConfig = 2, + ORMConfig = 2, GUI = 3, Roughness = 4, AO = 5, diff --git a/Engine/source/T3D/assets/assetImporter.cpp b/Engine/source/T3D/assets/assetImporter.cpp index bc55d6a53..1414fc831 100644 --- a/Engine/source/T3D/assets/assetImporter.cpp +++ b/Engine/source/T3D/assets/assetImporter.cpp @@ -61,7 +61,7 @@ AssetImportConfig::AssetImportConfig() : reverseWindingOrder(false), invertNormals(false), ImportMaterials(true), - CreatePBRConfig(true), + CreateORMConfig(true), UseDiffuseSuffixOnOriginImage(false), UseExistingMaterials(false), IgnoreMaterials(""), @@ -160,11 +160,11 @@ void AssetImportConfig::initPersistFields() addGroup("Materials"); addField("ImportMaterials", TypeBool, Offset(ImportMaterials, AssetImportConfig), "Does this config allow for importing of materials"); - addField("CreatePBRConfig", TypeBool, Offset(PreventImportWithErrors, AssetImportConfig), "When importing a material, should it automatically attempt to merge Roughness, AO and Metalness maps into a single, composited PBR Configuration map"); + addField("CreateORMConfig", TypeBool, Offset(PreventImportWithErrors, AssetImportConfig), "When importing a material, should it automatically attempt to merge Roughness, AO and Metalness maps into a single, composited PBR Configuration map"); addField("UseDiffuseSuffixOnOriginImage", TypeBool, Offset(UseDiffuseSuffixOnOriginImage, AssetImportConfig), "When generating a material off of an importing image, should the importer force appending a diffusemap suffix onto the end to avoid potential naming confusion.\n e.g. MyCoolStuff.png is imported, generating MyCoolStuff material asset and MyCoolStuff_Diffuse image asset"); addField("UseExistingMaterials", TypeBool, Offset(UseExistingMaterials, AssetImportConfig), "Should the importer try and use existing material assets in the game directory if at all possible. (Not currently utilized)"); addField("IgnoreMaterials", TypeRealString, Offset(IgnoreMaterials, AssetImportConfig), "A list of material names that should not be imported. Separated by either , or ;"); - addField("PopulateMaterialMaps", TypeBool, Offset(PopulateMaterialMaps, AssetImportConfig), "When processing a material asset, should the importer attempt to populate the various material maps on it by looking up common naming conventions for potentially relevent image files.\n e.g. If MyCoolStuff_Diffuse.png is imported, generating MyCoolStuff material, it would also find MyCoolStuff_Normal and MyCoolStuff_PBR images and map them to the normal and PBRConfig maps respectively automatically"); + addField("PopulateMaterialMaps", TypeBool, Offset(PopulateMaterialMaps, AssetImportConfig), "When processing a material asset, should the importer attempt to populate the various material maps on it by looking up common naming conventions for potentially relevent image files.\n e.g. If MyCoolStuff_Diffuse.png is imported, generating MyCoolStuff material, it would also find MyCoolStuff_Normal and MyCoolStuff_PBR images and map them to the normal and ORMConfig maps respectively automatically"); endGroup("Materials"); addGroup("Meshes"); @@ -186,14 +186,14 @@ void AssetImportConfig::initPersistFields() addGroup("Images"); addField("importImages", TypeBool, Offset(importImages, AssetImportConfig), "Does this configuration support importing images."); - addField("ImageType", TypeRealString, Offset(ImageType, AssetImportConfig), "What is the default ImageType images are imported as. Options are: N/A, Diffuse, Normal, Metalness, Roughness, AO, PBRConfig, GUI, Cubemap"); + addField("ImageType", TypeRealString, Offset(ImageType, AssetImportConfig), "What is the default ImageType images are imported as. Options are: N/A, Diffuse, Normal, Metalness, Roughness, AO, ORMConfig, GUI, Cubemap"); addField("DiffuseTypeSuffixes", TypeRealString, Offset(DiffuseTypeSuffixes, AssetImportConfig), "What type of suffixes are scanned to detect if an importing image is a diffuse map. \n e.g. _Albedo or _Color"); addField("NormalTypeSuffixes", TypeRealString, Offset(NormalTypeSuffixes, AssetImportConfig), "What type of suffixes are scanned to detect if an importing image is a normal map. \n e.g. _Normal or _Norm"); addField("MetalnessTypeSuffixes", TypeRealString, Offset(MetalnessTypeSuffixes, AssetImportConfig), "What type of suffixes are scanned to detect if an importing image is a metalness map. \n e.g. _Metalness or _Metal"); addField("RoughnessTypeSuffixes", TypeRealString, Offset(RoughnessTypeSuffixes, AssetImportConfig), "What type of suffixes are scanned to detect if an importing image is a roughness map.\n e.g. _roughness or _rough"); addField("SmoothnessTypeSuffixes", TypeRealString, Offset(SmoothnessTypeSuffixes, AssetImportConfig), "What type of suffixes are scanned to detect if an importing image is a smoothness map. \n e.g. _smoothness or _smooth"); addField("AOTypeSuffixes", TypeRealString, Offset(AOTypeSuffixes, AssetImportConfig), "What type of suffixes are scanned to detect if an importing image is a ambient occlusion map. \n e.g. _ambient or _ao"); - addField("PBRTypeSuffixes", TypeRealString, Offset(PBRTypeSuffixes, AssetImportConfig), "What type of suffixes are scanned to detect if an importing image is a PBRConfig map.\n e.g. _Composite or _PBR"); + addField("PBRTypeSuffixes", TypeRealString, Offset(PBRTypeSuffixes, AssetImportConfig), "What type of suffixes are scanned to detect if an importing image is a ORMConfig map.\n e.g. _Composite or _PBR"); addField("TextureFilteringMode", TypeRealString, Offset(TextureFilteringMode, AssetImportConfig), "Indicates what filter mode images imported with this configuration utilizes. Options are Linear, Bilinear, Trilinear"); addField("UseMips", TypeBool, Offset(UseMips, AssetImportConfig), "Indicates if images imported with this configuration utilize mipmaps"); @@ -251,7 +251,7 @@ void AssetImportConfig::loadImportConfig(Settings* configSettings, String config //Materials ImportMaterials = dAtob(configSettings->value(String(configName + "/Materials/ImportMaterials").c_str())); - CreatePBRConfig = dAtob(configSettings->value(String(configName + "/Materials/CreatePBRConfig").c_str())); + CreateORMConfig = dAtob(configSettings->value(String(configName + "/Materials/CreateORMConfig").c_str())); UseDiffuseSuffixOnOriginImage = dAtob(configSettings->value(String(configName + "/Materials/UseDiffuseSuffixOnOriginImage").c_str())); UseExistingMaterials = dAtob(configSettings->value(String(configName + "/Materials/UseExistingMaterials").c_str())); IgnoreMaterials = configSettings->value(String(configName + "/Materials/IgnoreMaterials").c_str()); @@ -334,7 +334,7 @@ void AssetImportConfig::CopyTo(AssetImportConfig* target) const //Materials target->ImportMaterials = ImportMaterials; - target->CreatePBRConfig = CreatePBRConfig; + target->CreateORMConfig = CreateORMConfig; target->UseDiffuseSuffixOnOriginImage = UseDiffuseSuffixOnOriginImage; target->UseExistingMaterials = UseExistingMaterials; target->IgnoreMaterials = IgnoreMaterials; @@ -439,7 +439,7 @@ void AssetImportObject::initPersistFields() addField("tamlFilePath", TypeRealString, Offset(tamlFilePath, AssetImportObject), "What is the ultimate asset taml file path for this import item"); - addField("imageType", TypeRealString, Offset(imageSuffixType, AssetImportObject), "Specific to ImageAsset type. What is the image asset's suffix type. Options are: Albedo, Normal, Roughness, AO, Metalness, PBRConfig"); + addField("imageType", TypeRealString, Offset(imageSuffixType, AssetImportObject), "Specific to ImageAsset type. What is the image asset's suffix type. Options are: Albedo, Normal, Roughness, AO, Metalness, ORMConfig"); addField("shapeInfo", TYPEID< GuiTreeViewCtrl >(), Offset(shapeInfo, AssetImportObject), "Specific to ShapeAsset type. Processed information about the shape file. Contains numbers and lists of meshes, materials and animations"); } @@ -714,7 +714,7 @@ String AssetImporter::parseImageSuffixes(String assetName, String* suffixType) break; case 5: suffixList = activeImportConfig->PBRTypeSuffixes; - suffixType->insert(0, "PBRConfig", 10); + suffixType->insert(0, "ORMConfig", 10); break; default: suffixList = ""; @@ -1635,7 +1635,7 @@ void AssetImporter::processMaterialAsset(AssetImportObject* assetItem) case ImageAsset::Normal: suffixList = activeImportConfig->NormalTypeSuffixes; break; - case ImageAsset::PBRConfig: + case ImageAsset::ORMConfig: suffixList = activeImportConfig->PBRTypeSuffixes; break; case ImageAsset::Metalness: @@ -2644,10 +2644,10 @@ Torque::Path AssetImporter::importMaterialAsset(AssetImportObject* assetItem) return ""; } - //build the PBRConfig file if we're flagged to and have valid image maps - if (activeImportConfig->CreatePBRConfig) + //build the ORMConfig file if we're flagged to and have valid image maps + if (activeImportConfig->CreateORMConfig) { - AssetImportObject* pbrConfigMap = nullptr; + AssetImportObject* ormMap = nullptr; AssetImportObject* roughnessMap = nullptr; AssetImportObject* metalnessMap = nullptr; AssetImportObject* aoMap = nullptr; @@ -2660,8 +2660,8 @@ Torque::Path AssetImporter::importMaterialAsset(AssetImportObject* assetItem) if (childItem->skip || childItem->assetType.compare("ImageAsset") != 0) continue; - if (childItem->imageSuffixType.compare("PBRConfig") == 0) - pbrConfigMap = childItem; + if (childItem->imageSuffixType.compare("ORMConfig") == 0) + ormMap = childItem; else if(childItem->imageSuffixType.compare("Roughness") == 0) roughnessMap = childItem; else if (childItem->imageSuffixType.compare("Metalness") == 0) @@ -2670,14 +2670,14 @@ Torque::Path AssetImporter::importMaterialAsset(AssetImportObject* assetItem) aoMap = childItem; } - if (pbrConfigMap != nullptr && pbrConfigMap->generatedAsset) + if (ormMap != nullptr && ormMap->generatedAsset) { if (roughnessMap != nullptr || metalnessMap != nullptr || aoMap != nullptr) { U32 channelKey[4] = { 0,1,2,3 }; GFX->getTextureManager()->saveCompositeTexture(aoMap->filePath.getFullPath(), roughnessMap->filePath.getFullPath(), metalnessMap->filePath.getFullPath(), "", - channelKey, pbrConfigMap->filePath.getFullPath(), &GFXTexturePersistentProfile); + channelKey, ormMap->filePath.getFullPath(), &GFXTexturePersistentProfile); } } } @@ -2722,9 +2722,9 @@ Torque::Path AssetImporter::importMaterialAsset(AssetImportObject* assetItem) { mapFieldName = "NormalMap"; } - else if (imageType == ImageAsset::ImageTypes::PBRConfig) + else if (imageType == ImageAsset::ImageTypes::ORMConfig) { - mapFieldName = "PBRConfig"; + mapFieldName = "ORMConfig"; } else if (imageType == ImageAsset::ImageTypes::Metalness) { @@ -2784,9 +2784,9 @@ Torque::Path AssetImporter::importMaterialAsset(AssetImportObject* assetItem) { mapFieldName = "NormalMap"; } - else if (imageType == ImageAsset::ImageTypes::PBRConfig) + else if (imageType == ImageAsset::ImageTypes::ORMConfig) { - mapFieldName = "PBRConfigMap"; + mapFieldName = "ORMConfigMap"; } else if (imageType == ImageAsset::ImageTypes::Metalness) { diff --git a/Engine/source/T3D/assets/assetImporter.h b/Engine/source/T3D/assets/assetImporter.h index 3920ceb4f..d923e7aad 100644 --- a/Engine/source/T3D/assets/assetImporter.h +++ b/Engine/source/T3D/assets/assetImporter.h @@ -185,7 +185,7 @@ public: /// /// When importing a material, should it automatically attempt to merge Roughness, AO and Metalness maps into a single, composited PBR Configuration map /// - bool CreatePBRConfig; + bool CreateORMConfig; /// /// When generating a material off of an importing image, should the importer force appending a diffusemap suffix onto the end to avoid potential naming confusion. @@ -205,7 +205,7 @@ public: /// /// When processing a material asset, should the importer attempt to populate the various material maps on it by looking up common naming conventions for potentially relevent image files - /// e.g. If MyCoolStuff_Diffuse.png is imported, generating MyCoolStuff material, it would also find MyCoolStuff_Normal and MyCoolStuff_PBR images and map them to the normal and PBRConfig maps respectively automatically + /// e.g. If MyCoolStuff_Diffuse.png is imported, generating MyCoolStuff material, it would also find MyCoolStuff_Normal and MyCoolStuff_PBR images and map them to the normal and ORMConfig maps respectively automatically /// bool PopulateMaterialMaps; @@ -276,7 +276,7 @@ public: bool importImages; /// - /// What is the default ImageType images are imported as. Options are: N/A, Diffuse, Normal, Metalness, Roughness, AO, PBRConfig, GUI, Cubemap + /// What is the default ImageType images are imported as. Options are: N/A, Diffuse, Normal, Metalness, Roughness, AO, ORMConfig, GUI, Cubemap /// String ImageType; @@ -317,7 +317,7 @@ public: String AOTypeSuffixes; /// - /// What type of suffixes are scanned to detect if an importing image is a PBRConfig map. + /// What type of suffixes are scanned to detect if an importing image is a ORMConfig map. /// e.g. _Composite or _PBR /// String PBRTypeSuffixes; @@ -490,7 +490,7 @@ public: // /// /// Specific to ImageAsset type - /// What is the image asset's suffix type. Options are: Albedo, Normal, Roughness, AO, Metalness, PBRConfig + /// What is the image asset's suffix type. Options are: Albedo, Normal, Roughness, AO, Metalness, ORMConfig /// String imageSuffixType; diff --git a/Engine/source/T3D/lighting/reflectionProbe.cpp b/Engine/source/T3D/lighting/reflectionProbe.cpp index 4a5a3b2f8..7230ab759 100644 --- a/Engine/source/T3D/lighting/reflectionProbe.cpp +++ b/Engine/source/T3D/lighting/reflectionProbe.cpp @@ -132,7 +132,7 @@ ReflectionProbe::ReflectionProbe() : mProbeInfo = nullptr; mPrefilterSize = 64; - mPrefilterMipLevels = mLog2(F32(mPrefilterSize)); + mPrefilterMipLevels = mLog2(F32(mPrefilterSize))+1; mPrefilterMap = nullptr; mIrridianceMap = nullptr; @@ -645,7 +645,7 @@ void ReflectionProbe::processDynamicCubemap() if (mCubeReflector.getCubemap()) { U32 resolution = Con::getIntVariable("$pref::ReflectionProbes::BakeResolution", 64); - U32 prefilterMipLevels = mLog2(F32(resolution)); + U32 prefilterMipLevels = mLog2(F32(resolution))+1; //Prep it with whatever resolution we've dictated for our bake mIrridianceMap->mCubemap->initDynamic(resolution, PROBEMGR->PROBE_FORMAT); @@ -700,7 +700,7 @@ void ReflectionProbe::processBakedCubemap() mIrridianceMap->updateFaces(); } - if (mIrridianceMap == nullptr || mIrridianceMap->mCubemap.isNull()) + if (mIrridianceMap == nullptr || !mIrridianceMap->mCubemap->isInitialized()) { Con::errorf("ReflectionProbe::processDynamicCubemap() - Unable to load baked irradiance map at %s", getIrradianceMapPath().c_str()); return; @@ -713,7 +713,7 @@ void ReflectionProbe::processBakedCubemap() mPrefilterMap->updateFaces(); } - if (mPrefilterMap == nullptr || mPrefilterMap->mCubemap.isNull()) + if (mPrefilterMap == nullptr || !mPrefilterMap->mCubemap->isInitialized()) { Con::errorf("ReflectionProbe::processDynamicCubemap() - Unable to load baked prefilter map at %s", getPrefilterMapPath().c_str()); return; diff --git a/Engine/source/gfx/gfxTextureManager.cpp b/Engine/source/gfx/gfxTextureManager.cpp index 357a3bebb..c4eff42dd 100644 --- a/Engine/source/gfx/gfxTextureManager.cpp +++ b/Engine/source/gfx/gfxTextureManager.cpp @@ -1028,26 +1028,45 @@ GFXTextureObject *GFXTextureManager::createCompositeTexture(const Torque::Path & GFXTextureObject *cacheHit = _lookupTexture(resourceTag, profile); if (cacheHit != NULL) return cacheHit; + Torque::Path lastValidPath = ""; GBitmap*bitmap[4]; - bitmap[0] = loadUncompressedTexture(pathR, profile); + + if (!pathR.isEmpty()) + { + bitmap[0] = loadUncompressedTexture(pathR, profile); + lastValidPath = pathR; + } + else + bitmap[0] = NULL; + if (!pathG.isEmpty()) + { bitmap[1] = loadUncompressedTexture(pathG, profile); + lastValidPath = pathG; + } else bitmap[1] = NULL; if (!pathB.isEmpty()) + { bitmap[2] = loadUncompressedTexture(pathB, profile); + lastValidPath = pathB; + } else bitmap[2] = NULL; + if (!pathA.isEmpty()) + { bitmap[3] = loadUncompressedTexture(pathA, profile); + lastValidPath = pathA; + } else bitmap[3] = NULL; Path realPath; GFXTextureObject *retTexObj = NULL; - realPath = validatePath(pathR); //associate path with r channel texture in. + realPath = validatePath(lastValidPath); //associate path with last valid channel texture in. retTexObj = createCompositeTexture(bitmap, inputKey, resourceTag, profile, false); @@ -1087,26 +1106,45 @@ void GFXTextureManager::saveCompositeTexture(const Torque::Path &pathR, const To cacheHit->dumpToDisk("png", saveAs.getFullPath()); return; } - GBitmap*bitmap[4]; - bitmap[0] = loadUncompressedTexture(pathR, profile); + + Torque::Path lastValidPath = ""; + GBitmap* bitmap[4]; + + if (!pathR.isEmpty()) + { + bitmap[0] = loadUncompressedTexture(pathR, profile); + lastValidPath = pathR; + } + else + bitmap[0] = NULL; + if (!pathG.isEmpty()) + { bitmap[1] = loadUncompressedTexture(pathG, profile); + lastValidPath = pathG; + } else bitmap[1] = NULL; if (!pathB.isEmpty()) + { bitmap[2] = loadUncompressedTexture(pathB, profile); + lastValidPath = pathB; + } else bitmap[2] = NULL; + if (!pathA.isEmpty()) + { bitmap[3] = loadUncompressedTexture(pathA, profile); + lastValidPath = pathA; + } else bitmap[3] = NULL; - Path realPath; GFXTextureObject *retTexObj = NULL; - realPath = validatePath(pathR); //associate path with r channel texture in. + realPath = validatePath(lastValidPath); //associate path with last valid channel texture in. retTexObj = createCompositeTexture(bitmap, inputKey, resourceTag, profile, false); if (retTexObj != NULL) @@ -1130,9 +1168,16 @@ DefineEngineFunction(saveCompositeTexture, void, (const char* pathR, const char* GFXTextureObject *GFXTextureManager::createCompositeTexture(GBitmap*bmp[4], U32 inputKey[4], const String &resourceName, GFXTextureProfile *profile, bool deleteBmp) { - if (!bmp[0]) + S32 lastValidTex = -1; + for (U32 i = 0; i < 4; i++) { - Con::errorf(ConsoleLogEntry::General, "GFXTextureManager::createCompositeTexture() - Got NULL bitmap(R)!"); + if (bmp[i]) + lastValidTex = i; + } + + if (lastValidTex == -1) + { + Con::errorf(ConsoleLogEntry::General, "GFXTextureManager::createCompositeTexture() - Got all NULL bitmaps!"); return NULL; } @@ -1145,11 +1190,11 @@ GFXTextureObject *GFXTextureManager::createCompositeTexture(GBitmap*bmp[4], U32 U8 rChan, gChan, bChan, aChan; GBitmap *outBitmap = new GBitmap(); - outBitmap->allocateBitmap(bmp[0]->getWidth(), bmp[0]->getHeight(),false, GFXFormatR8G8B8A8); + outBitmap->allocateBitmap(bmp[lastValidTex]->getWidth(), bmp[lastValidTex]->getHeight(),false, GFXFormatR8G8B8A8); //pack additional bitmaps into the origional - for (U32 x = 0; x < bmp[0]->getWidth(); x++) + for (U32 x = 0; x < bmp[lastValidTex]->getWidth(); x++) { - for (U32 y = 0; y < bmp[0]->getHeight(); y++) + for (U32 y = 0; y < bmp[lastValidTex]->getHeight(); y++) { rChan = bmp[0]->getChanelValueAt(x, y, inputKey[0]); diff --git a/Engine/source/lighting/advanced/glsl/advancedLightingFeaturesGLSL.cpp b/Engine/source/lighting/advanced/glsl/advancedLightingFeaturesGLSL.cpp index 74074a42f..ff8fc81f8 100644 --- a/Engine/source/lighting/advanced/glsl/advancedLightingFeaturesGLSL.cpp +++ b/Engine/source/lighting/advanced/glsl/advancedLightingFeaturesGLSL.cpp @@ -364,7 +364,7 @@ void DeferredBumpFeatGLSL::processPix( Vector &componentList, Parent::processPix( componentList, fd ); return; } - else if (!fd.features[MFT_PBRConfigMap] ) + else if (!fd.features[MFT_OrmMap] ) { Var *bumpSample = (Var *)LangElement::find( "bumpSample" ); if( bumpSample == NULL ) @@ -395,7 +395,7 @@ ShaderFeature::Resources DeferredBumpFeatGLSL::getResources( const MaterialFeatu return Parent::getResources( fd ); Resources res; - if(!fd.features[MFT_PBRConfigMap]) + if(!fd.features[MFT_OrmMap]) { res.numTex = 1; res.numTexReg = 1; @@ -438,7 +438,7 @@ void DeferredBumpFeatGLSL::setTexData( Material::StageData &stageDat, passData.mTexSlot[texIndex++].texObject = stageDat.getTex(MFT_DetailNormalMap); } } - else if (!fd.features[MFT_Parallax] && !fd.features[MFT_PBRConfigMap] && + else if (!fd.features[MFT_Parallax] && !fd.features[MFT_OrmMap] && ( fd.features[MFT_DeferredConditioner]) ) { passData.mTexType[ texIndex ] = Material::Bump; diff --git a/Engine/source/lighting/advanced/glsl/deferredShadingFeaturesGLSL.cpp b/Engine/source/lighting/advanced/glsl/deferredShadingFeaturesGLSL.cpp index c3e94c79f..3d881b398 100644 --- a/Engine/source/lighting/advanced/glsl/deferredShadingFeaturesGLSL.cpp +++ b/Engine/source/lighting/advanced/glsl/deferredShadingFeaturesGLSL.cpp @@ -35,72 +35,72 @@ //**************************************************************************** // Deferred Shading Features //**************************************************************************** -U32 PBRConfigMapGLSL::getOutputTargets(const MaterialFeatureData& fd) const +U32 DeferredOrmMapGLSL::getOutputTargets(const MaterialFeatureData& fd) const { return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::DefaultTarget; } -void PBRConfigMapGLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) +void DeferredOrmMapGLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { // Get the texture coord. Var *texCoord = getInTexCoord( "texCoord", "vec2", componentList ); MultiLine* meta = new MultiLine; - Var* pbrConfig; + Var* ormConfig; if (fd.features[MFT_isDeferred]) { - pbrConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2)); - if (!pbrConfig) + ormConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2)); + if (!ormConfig) { // create material var - pbrConfig = new Var; - pbrConfig->setType("vec4"); - pbrConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2)); - pbrConfig->setStructName("OUT"); + ormConfig = new Var; + ormConfig->setType("vec4"); + ormConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2)); + ormConfig->setStructName("OUT"); } } else { - pbrConfig = (Var*)LangElement::find("PBRConfig"); - if (!pbrConfig) + ormConfig = (Var*)LangElement::find("ORMConfig"); + if (!ormConfig) { - pbrConfig = new Var("PBRConfig", "vec4"); - meta->addStatement(new GenOp(" @;\r\n", new DecOp(pbrConfig))); + ormConfig = new Var("ORMConfig", "vec4"); + meta->addStatement(new GenOp(" @;\r\n", new DecOp(ormConfig))); } } // create texture var - Var *pbrConfigMap = new Var; - pbrConfigMap->setType( "sampler2D" ); - pbrConfigMap->setName( "pbrConfigMap" ); - pbrConfigMap->uniform = true; - pbrConfigMap->sampler = true; - pbrConfigMap->constNum = Var::getTexUnitNum(); - LangElement *texOp = new GenOp( "tex2D(@, @)", pbrConfigMap, texCoord ); + Var *ormMap = new Var; + ormMap->setType( "sampler2D" ); + ormMap->setName( "ormMap" ); + ormMap->uniform = true; + ormMap->sampler = true; + ormMap->constNum = Var::getTexUnitNum(); + LangElement *texOp = new GenOp( "tex2D(@, @)", ormMap, texCoord ); Var *metalness = (Var*)LangElement::find("metalness"); if (!metalness) metalness = new Var("metalness", "float"); - Var *smoothness = (Var*)LangElement::find("smoothness"); - if (!smoothness) smoothness = new Var("smoothness", "float"); + Var *roughness = (Var*)LangElement::find("roughness"); + if (!roughness) roughness = new Var("roughness", "float"); Var* ao = (Var*)LangElement::find("ao"); if (!ao) ao = new Var("ao", "float"); - meta->addStatement(new GenOp(" @.bga = @.rgb;\r\n", pbrConfig, texOp)); + meta->addStatement(new GenOp(" @.gba = @.rgb;\r\n", ormConfig, texOp)); - meta->addStatement(new GenOp(" @ = @.b;\r\n", new DecOp(smoothness), pbrConfig)); - if (fd.features[MFT_InvertSmoothness]) + meta->addStatement(new GenOp(" @ = @.g;\r\n", new DecOp(ao), ormConfig)); + meta->addStatement(new GenOp(" @ = @.b;\r\n", new DecOp(roughness), ormConfig)); + if (fd.features[MFT_InvertRoughness]) { - meta->addStatement(new GenOp(" @.b = 1.0-@.b;\r\n", pbrConfig, pbrConfig)); - meta->addStatement(new GenOp(" @ = 1.0-@;\r\n", smoothness, smoothness)); + meta->addStatement(new GenOp(" @.b = 1.0-@.b;\r\n", ormConfig, ormConfig)); + meta->addStatement(new GenOp(" @ = 1.0-@;\r\n", roughness, roughness)); } - meta->addStatement(new GenOp(" @ = @.g;\r\n", new DecOp(ao), pbrConfig)); - meta->addStatement(new GenOp(" @ = @.a;\r\n", new DecOp(metalness), pbrConfig)); + meta->addStatement(new GenOp(" @ = @.a;\r\n", new DecOp(metalness), ormConfig)); output = meta; } -ShaderFeature::Resources PBRConfigMapGLSL::getResources( const MaterialFeatureData &fd ) +ShaderFeature::Resources DeferredOrmMapGLSL::getResources( const MaterialFeatureData &fd ) { Resources res; res.numTex = 1; @@ -109,21 +109,21 @@ ShaderFeature::Resources PBRConfigMapGLSL::getResources( const MaterialFeatureDa return res; } -void PBRConfigMapGLSL::setTexData( Material::StageData &stageDat, +void DeferredOrmMapGLSL::setTexData( Material::StageData &stageDat, const MaterialFeatureData &fd, RenderPassData &passData, U32 &texIndex ) { - GFXTextureObject *tex = stageDat.getTex(MFT_PBRConfigMap); + GFXTextureObject *tex = stageDat.getTex(MFT_OrmMap); if ( tex ) { passData.mTexType[ texIndex ] = Material::Standard; - passData.mSamplerNames[ texIndex ] = "pbrConfigMap"; + passData.mSamplerNames[ texIndex ] = "ormMap"; passData.mTexSlot[ texIndex++ ].texObject = tex; } } -void PBRConfigMapGLSL::processVert( Vector &componentList, +void DeferredOrmMapGLSL::processVert( Vector &componentList, const MaterialFeatureData &fd ) { MultiLine *meta = new MultiLine; @@ -145,26 +145,26 @@ void MatInfoFlagsGLSL::processPix( Vector &componentList, cons { MultiLine *meta = new MultiLine; - Var* pbrConfig; + Var* ormConfig; if (fd.features[MFT_isDeferred]) { - pbrConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2)); - if (!pbrConfig) + ormConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2)); + if (!ormConfig) { // create material var - pbrConfig = new Var; - pbrConfig->setType("vec4"); - pbrConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2)); - pbrConfig->setStructName("OUT"); + ormConfig = new Var; + ormConfig->setType("vec4"); + ormConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2)); + ormConfig->setStructName("OUT"); } } else { - pbrConfig = (Var*)LangElement::find("PBRConfig"); - if (!pbrConfig) + ormConfig = (Var*)LangElement::find("ORMConfig"); + if (!ormConfig) { - pbrConfig = new Var("PBRConfig", "vec4"); - meta->addStatement(new GenOp(" @;\r\n", new DecOp(pbrConfig))); + ormConfig = new Var("ORMConfig", "vec4"); + meta->addStatement(new GenOp(" @;\r\n", new DecOp(ormConfig))); } } @@ -174,57 +174,57 @@ void MatInfoFlagsGLSL::processPix( Vector &componentList, cons matInfoFlags->uniform = true; matInfoFlags->constSortPos = cspPotentialPrimitive; - meta->addStatement(output = new GenOp(" @.r = @;\r\n", pbrConfig, matInfoFlags)); + meta->addStatement(output = new GenOp(" @.r = @;\r\n", ormConfig, matInfoFlags)); output = meta; } -U32 PBRConfigVarsGLSL::getOutputTargets(const MaterialFeatureData& fd) const +U32 ORMConfigVarsGLSL::getOutputTargets(const MaterialFeatureData& fd) const { return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::DefaultTarget; } // Spec Strength -> Blue Channel of Material Info Buffer. // Spec Power -> Alpha Channel ( of Material Info Buffer. -void PBRConfigVarsGLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) +void ORMConfigVarsGLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { MultiLine* meta = new MultiLine; - Var* pbrConfig; + Var* ormConfig; if (fd.features[MFT_isDeferred]) { - pbrConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2)); - if (!pbrConfig) + ormConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2)); + if (!ormConfig) { // create material var - pbrConfig = new Var; - pbrConfig->setType("vec4"); - pbrConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2)); - pbrConfig->setStructName("OUT"); + ormConfig = new Var; + ormConfig->setType("vec4"); + ormConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2)); + ormConfig->setStructName("OUT"); } } else { - pbrConfig = (Var*)LangElement::find("PBRConfig"); - if (!pbrConfig) + ormConfig = (Var*)LangElement::find("ORMConfig"); + if (!ormConfig) { - pbrConfig = new Var("PBRConfig", "vec4"); - meta->addStatement(new GenOp(" @;\r\n", new DecOp(pbrConfig))); + ormConfig = new Var("ORMConfig", "vec4"); + meta->addStatement(new GenOp(" @;\r\n", new DecOp(ormConfig))); } } Var* metalness = new Var("metalness", "float"); metalness->uniform = true; metalness->constSortPos = cspPotentialPrimitive; - Var* smoothness = new Var("smoothness", "float"); - smoothness->uniform = true; - smoothness->constSortPos = cspPotentialPrimitive; + Var* roughness = new Var("roughness", "float"); + roughness->uniform = true; + roughness->constSortPos = cspPotentialPrimitive; //matinfo.g slot reserved for AO later - meta->addStatement(new GenOp(" @.g = 1.0;\r\n", pbrConfig)); - meta->addStatement(new GenOp(" @.b = @;\r\n", pbrConfig, smoothness)); - if (fd.features[MFT_InvertSmoothness]) - meta->addStatement(new GenOp(" @ = 1.0-@;\r\n", smoothness, smoothness)); - meta->addStatement(new GenOp(" @.a = @;\r\n", pbrConfig, metalness)); + meta->addStatement(new GenOp(" @.g = 1.0;\r\n", ormConfig)); + meta->addStatement(new GenOp(" @.b = @;\r\n", ormConfig, roughness)); + if (fd.features[MFT_InvertRoughness]) + meta->addStatement(new GenOp(" @ = 1.0-@;\r\n", roughness, roughness)); + meta->addStatement(new GenOp(" @.a = @;\r\n", ormConfig, metalness)); output = meta; } diff --git a/Engine/source/lighting/advanced/glsl/deferredShadingFeaturesGLSL.h b/Engine/source/lighting/advanced/glsl/deferredShadingFeaturesGLSL.h index 27fce45db..3d8c46be6 100644 --- a/Engine/source/lighting/advanced/glsl/deferredShadingFeaturesGLSL.h +++ b/Engine/source/lighting/advanced/glsl/deferredShadingFeaturesGLSL.h @@ -27,7 +27,7 @@ #include "shaderGen/GLSL/bumpGLSL.h" // Specular Outputs -class PBRConfigMapGLSL : public ShaderFeatureGLSL +class DeferredOrmMapGLSL : public ShaderFeatureGLSL { public: virtual String getName() { return "Deferred Shading: PBR Config Map"; } @@ -60,7 +60,7 @@ public: virtual U32 getOutputTargets(const MaterialFeatureData& fd) const; }; -class PBRConfigVarsGLSL : public ShaderFeatureGLSL +class ORMConfigVarsGLSL : public ShaderFeatureGLSL { public: virtual String getName() { return "Deferred Shading: PBR Config Explicit Numbers"; } diff --git a/Engine/source/lighting/advanced/hlsl/advancedLightingFeaturesHLSL.cpp b/Engine/source/lighting/advanced/hlsl/advancedLightingFeaturesHLSL.cpp index ab6b9450b..77f2251d2 100644 --- a/Engine/source/lighting/advanced/hlsl/advancedLightingFeaturesHLSL.cpp +++ b/Engine/source/lighting/advanced/hlsl/advancedLightingFeaturesHLSL.cpp @@ -395,7 +395,7 @@ void DeferredBumpFeatHLSL::processPix( Vector &componentList, Parent::processPix( componentList, fd ); return; } - else if (!fd.features[MFT_PBRConfigMap] ) + else if (!fd.features[MFT_OrmMap] ) { Var *bumpSample = (Var *)LangElement::find( "bumpSample" ); if( bumpSample == NULL ) @@ -428,7 +428,7 @@ ShaderFeature::Resources DeferredBumpFeatHLSL::getResources( const MaterialFeatu return Parent::getResources( fd ); Resources res; - if(!fd.features[MFT_PBRConfigMap]) + if(!fd.features[MFT_OrmMap]) { res.numTex = 1; res.numTexReg = 1; @@ -471,7 +471,7 @@ void DeferredBumpFeatHLSL::setTexData( Material::StageData &stageDat, passData.mTexSlot[ texIndex++ ].texObject = stageDat.getTex( MFT_DetailNormalMap ); } } - else if ( !fd.features[MFT_Parallax] && !fd.features[MFT_PBRConfigMap] && + else if ( !fd.features[MFT_Parallax] && !fd.features[MFT_OrmMap] && ( fd.features[MFT_DeferredConditioner]) ) { passData.mTexType[ texIndex ] = Material::Bump; diff --git a/Engine/source/lighting/advanced/hlsl/deferredShadingFeaturesHLSL.cpp b/Engine/source/lighting/advanced/hlsl/deferredShadingFeaturesHLSL.cpp index 0fad444a4..42518830a 100644 --- a/Engine/source/lighting/advanced/hlsl/deferredShadingFeaturesHLSL.cpp +++ b/Engine/source/lighting/advanced/hlsl/deferredShadingFeaturesHLSL.cpp @@ -35,79 +35,79 @@ //**************************************************************************** // Deferred Shading Features //**************************************************************************** -U32 PBRConfigMapHLSL::getOutputTargets(const MaterialFeatureData& fd) const +U32 DeferredOrmMapHLSL::getOutputTargets(const MaterialFeatureData& fd) const { return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::DefaultTarget; } -void PBRConfigMapHLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) +void DeferredOrmMapHLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { // Get the texture coord. Var *texCoord = getInTexCoord( "texCoord", "float2", componentList ); MultiLine* meta = new MultiLine; - Var* pbrConfig; + Var* ormConfig; if (fd.features[MFT_isDeferred]) { - pbrConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2)); - if (!pbrConfig) + ormConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2)); + if (!ormConfig) { // create material var - pbrConfig = new Var; - pbrConfig->setType("fragout"); - pbrConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2)); - pbrConfig->setStructName("OUT"); + ormConfig = new Var; + ormConfig->setType("fragout"); + ormConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2)); + ormConfig->setStructName("OUT"); } } else { - pbrConfig = (Var*)LangElement::find("PBRConfig"); - if (!pbrConfig) + ormConfig = (Var*)LangElement::find("ORMConfig"); + if (!ormConfig) { - pbrConfig = new Var("PBRConfig", "float4"); - meta->addStatement(new GenOp(" @;\r\n", new DecOp(pbrConfig))); + ormConfig = new Var("ORMConfig", "float4"); + meta->addStatement(new GenOp(" @;\r\n", new DecOp(ormConfig))); } } // create texture var - Var * pbrConfigMap = new Var; - pbrConfigMap->setType( "SamplerState" ); - pbrConfigMap->setName( "PBRConfigMap" ); - pbrConfigMap->uniform = true; - pbrConfigMap->sampler = true; - pbrConfigMap->constNum = Var::getTexUnitNum(); + Var * ormMap = new Var; + ormMap->setType( "SamplerState" ); + ormMap->setName( "ORMConfigMap" ); + ormMap->uniform = true; + ormMap->sampler = true; + ormMap->constNum = Var::getTexUnitNum(); - Var* pbrConfigMapTex = new Var; - pbrConfigMapTex->setName("PBRConfigMapTex"); - pbrConfigMapTex->setType("Texture2D"); - pbrConfigMapTex->uniform = true; - pbrConfigMapTex->texture = true; - pbrConfigMapTex->constNum = pbrConfigMap->constNum; - LangElement *texOp = new GenOp("@.Sample(@, @)", pbrConfigMapTex, pbrConfigMap, texCoord); + Var* ormMapTex = new Var; + ormMapTex->setName("ORMConfigMapTex"); + ormMapTex->setType("Texture2D"); + ormMapTex->uniform = true; + ormMapTex->texture = true; + ormMapTex->constNum = ormMap->constNum; + LangElement *texOp = new GenOp("@.Sample(@, @)", ormMapTex, ormMap, texCoord); Var *metalness = (Var*)LangElement::find("metalness"); if (!metalness) metalness = new Var("metalness", "float"); - Var *smoothness = (Var*)LangElement::find("smoothness"); - if (!smoothness) smoothness = new Var("smoothness", "float"); + Var *roughness = (Var*)LangElement::find("roughness"); + if (!roughness) roughness = new Var("roughness", "float"); Var* ao = (Var*)LangElement::find("ao"); if (!ao) ao = new Var("ao", "float"); - meta->addStatement(new GenOp(" @.bga = @.rgb;\r\n", pbrConfig, texOp)); + meta->addStatement(new GenOp(" @.gba = @.rgb;\r\n", ormConfig, texOp)); - meta->addStatement(new GenOp(" @ = @.b;\r\n", new DecOp(smoothness), pbrConfig)); - if (fd.features[MFT_InvertSmoothness]) + meta->addStatement(new GenOp(" @ = @.g;\r\n", new DecOp(ao), ormConfig)); + meta->addStatement(new GenOp(" @ = @.b;\r\n", new DecOp(roughness), ormConfig)); + if (fd.features[MFT_InvertRoughness]) { - meta->addStatement(new GenOp(" @.b = 1.0-@.b;\r\n", pbrConfig, pbrConfig)); - meta->addStatement(new GenOp(" @ = 1.0-@;\r\n", smoothness, smoothness)); + meta->addStatement(new GenOp(" @.b = 1.0-@.b;\r\n", ormConfig, ormConfig)); + meta->addStatement(new GenOp(" @ = 1.0-@;\r\n", roughness, roughness)); } - meta->addStatement(new GenOp(" @ = @.g;\r\n", new DecOp(ao), pbrConfig)); - meta->addStatement(new GenOp(" @ = @.a;\r\n", new DecOp(metalness), pbrConfig)); + meta->addStatement(new GenOp(" @ = @.a;\r\n", new DecOp(metalness), ormConfig)); output = meta; } -ShaderFeature::Resources PBRConfigMapHLSL::getResources( const MaterialFeatureData &fd ) +ShaderFeature::Resources DeferredOrmMapHLSL::getResources( const MaterialFeatureData &fd ) { Resources res; res.numTex = 1; @@ -116,21 +116,21 @@ ShaderFeature::Resources PBRConfigMapHLSL::getResources( const MaterialFeatureDa return res; } -void PBRConfigMapHLSL::setTexData( Material::StageData &stageDat, +void DeferredOrmMapHLSL::setTexData( Material::StageData &stageDat, const MaterialFeatureData &fd, RenderPassData &passData, U32 &texIndex ) { - GFXTextureObject *tex = stageDat.getTex(MFT_PBRConfigMap); + GFXTextureObject *tex = stageDat.getTex(MFT_OrmMap); if ( tex ) { passData.mTexType[ texIndex ] = Material::Standard; - passData.mSamplerNames[ texIndex ] = "PBRConfigMap"; + passData.mSamplerNames[ texIndex ] = "ORMConfigMap"; passData.mTexSlot[ texIndex++ ].texObject = tex; } } -void PBRConfigMapHLSL::processVert( Vector &componentList, +void DeferredOrmMapHLSL::processVert( Vector &componentList, const MaterialFeatureData &fd ) { MultiLine *meta = new MultiLine; @@ -151,23 +151,23 @@ U32 MatInfoFlagsHLSL::getOutputTargets(const MaterialFeatureData& fd) const void MatInfoFlagsHLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { // search for material var - Var* pbrConfig; + Var* ormConfig; if (fd.features[MFT_isDeferred]) { - pbrConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2)); - if (!pbrConfig) + ormConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2)); + if (!ormConfig) { // create material var - pbrConfig = new Var; - pbrConfig->setType("fragout"); - pbrConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2)); - pbrConfig->setStructName("OUT"); + ormConfig = new Var; + ormConfig->setType("fragout"); + ormConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2)); + ormConfig->setStructName("OUT"); } } else { - pbrConfig = (Var*)LangElement::find("PBRConfig"); - if (!pbrConfig) pbrConfig = new Var("PBRConfig", "float4"); + ormConfig = (Var*)LangElement::find("ORMConfig"); + if (!ormConfig) ormConfig = new Var("ORMConfig", "float4"); } Var *matInfoFlags = new Var; @@ -176,50 +176,50 @@ void MatInfoFlagsHLSL::processPix( Vector &componentList, cons matInfoFlags->uniform = true; matInfoFlags->constSortPos = cspPotentialPrimitive; - output = new GenOp( " @.r = @;\r\n", pbrConfig, matInfoFlags ); + output = new GenOp( " @.r = @;\r\n", ormConfig, matInfoFlags ); } -U32 PBRConfigVarsHLSL::getOutputTargets(const MaterialFeatureData& fd) const +U32 ORMConfigVarsHLSL::getOutputTargets(const MaterialFeatureData& fd) const { return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::DefaultTarget; } -void PBRConfigVarsHLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) +void ORMConfigVarsHLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { MultiLine* meta = new MultiLine; - Var* pbrConfig; + Var* ormConfig; if (fd.features[MFT_isDeferred]) { - pbrConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2)); - if (!pbrConfig) + ormConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2)); + if (!ormConfig) { // create material var - pbrConfig = new Var; - pbrConfig->setType("fragout"); - pbrConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2)); - pbrConfig->setStructName("OUT"); + ormConfig = new Var; + ormConfig->setType("fragout"); + ormConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2)); + ormConfig->setStructName("OUT"); } } else { - pbrConfig = (Var*)LangElement::find("PBRConfig"); - if (!pbrConfig) pbrConfig = new Var("PBRConfig", "float4"); - meta->addStatement(new GenOp(" @;\r\n", new DecOp(pbrConfig))); + ormConfig = (Var*)LangElement::find("ORMConfig"); + if (!ormConfig) ormConfig = new Var("ORMConfig", "float4"); + meta->addStatement(new GenOp(" @;\r\n", new DecOp(ormConfig))); } Var *metalness = new Var("metalness", "float"); metalness->uniform = true; metalness->constSortPos = cspPotentialPrimitive; - Var *smoothness = new Var("smoothness", "float"); - smoothness->uniform = true; - smoothness->constSortPos = cspPotentialPrimitive; + Var *roughness = new Var("roughness", "float"); + roughness->uniform = true; + roughness->constSortPos = cspPotentialPrimitive; //matinfo.g slot reserved for AO later - meta->addStatement(new GenOp(" @.g = 1.0;\r\n", pbrConfig)); - meta->addStatement(new GenOp(" @.b = @;\r\n", pbrConfig, smoothness)); - if (fd.features[MFT_InvertSmoothness]) - meta->addStatement(new GenOp(" @ = 1.0-@;\r\n", smoothness, smoothness)); - meta->addStatement(new GenOp(" @.a = @;\r\n", pbrConfig, metalness)); + meta->addStatement(new GenOp(" @.g = 1.0;\r\n", ormConfig)); + meta->addStatement(new GenOp(" @.b = @;\r\n", ormConfig, roughness)); + if (fd.features[MFT_InvertRoughness]) + meta->addStatement(new GenOp(" @ = 1.0-@;\r\n", roughness, roughness)); + meta->addStatement(new GenOp(" @.a = @;\r\n", ormConfig, metalness)); output = meta; } diff --git a/Engine/source/lighting/advanced/hlsl/deferredShadingFeaturesHLSL.h b/Engine/source/lighting/advanced/hlsl/deferredShadingFeaturesHLSL.h index b2934ad92..5657c4d03 100644 --- a/Engine/source/lighting/advanced/hlsl/deferredShadingFeaturesHLSL.h +++ b/Engine/source/lighting/advanced/hlsl/deferredShadingFeaturesHLSL.h @@ -26,7 +26,7 @@ #include "shaderGen/HLSL/shaderFeatureHLSL.h" #include "shaderGen/HLSL/bumpHLSL.h" -class PBRConfigMapHLSL : public ShaderFeatureHLSL +class DeferredOrmMapHLSL : public ShaderFeatureHLSL { public: virtual String getName() { return "Deferred Shading: PBR Config Map"; } @@ -59,7 +59,7 @@ public: virtual U32 getOutputTargets(const MaterialFeatureData& fd) const; }; -class PBRConfigVarsHLSL : public ShaderFeatureHLSL +class ORMConfigVarsHLSL : public ShaderFeatureHLSL { public: virtual String getName() { return "Deferred Shading: PBR Config Explicit Numbers"; } diff --git a/Engine/source/materials/materialDefinition.cpp b/Engine/source/materials/materialDefinition.cpp index 66239cd83..c5c0c8c75 100644 --- a/Engine/source/materials/materialDefinition.cpp +++ b/Engine/source/materials/materialDefinition.cpp @@ -118,13 +118,13 @@ Material::Material() mDiffuse[i].set( 1.0f, 1.0f, 1.0f, 1.0f ); mDiffuseMapSRGB[i] = true; - mSmoothness[i] = 0.0f; + mRoughness[i] = 1.0f; mMetalness[i] = 0.0f; mIsSRGb[i] = true; - mInvertSmoothness[i] = false; + mInvertRoughness[i] = false; - mSmoothnessChan[i] = 0; + mRoughnessChan[i] = 0; mAOChan[i] = 1; mMetalChan[i] = 2; @@ -265,11 +265,11 @@ void Material::initPersistFields() addField( "detailNormalMapStrength", TypeF32, Offset(mDetailNormalMapStrength, Material), MAX_STAGES, "Used to scale the strength of the detail normal map when blended with the base normal map." ); - addField("smoothness", TypeF32, Offset(mSmoothness, Material), MAX_STAGES, - "The degree of smoothness when not using a PBRConfigMap." ); + addField("roughness", TypeF32, Offset(mRoughness, Material), MAX_STAGES, + "The degree of roughness when not using a ORMConfigMap." ); addField("metalness", TypeF32, Offset(mMetalness, Material), MAX_STAGES, - "The degree of Metalness when not using a PBRConfigMap." ); + "The degree of Metalness when not using a ORMConfigMap." ); addField("glowMul", TypeF32, Offset(mGlowMul, Material), MAX_STAGES, "glow mask multiplier"); @@ -295,11 +295,11 @@ void Material::initPersistFields() addField("isSRGb", TypeBool, Offset(mIsSRGb, Material), MAX_STAGES, "Substance Designer Workaround."); - addField("invertSmoothness", TypeBool, Offset(mInvertSmoothness, Material), MAX_STAGES, - "Treat Smoothness as Roughness"); + addField("invertRoughness", TypeBool, Offset(mInvertRoughness, Material), MAX_STAGES, + "Treat Roughness as Roughness"); - addField("smoothnessChan", TypeF32, Offset(mSmoothnessChan, Material), MAX_STAGES, - "The input channel smoothness maps use."); + addField("roughnessChan", TypeF32, Offset(mRoughnessChan, Material), MAX_STAGES, + "The input channel roughness maps use."); addField("AOChan", TypeF32, Offset(mAOChan, Material), MAX_STAGES, "The input channel AO maps use."); diff --git a/Engine/source/materials/materialDefinition.h b/Engine/source/materials/materialDefinition.h index 32b79b92d..e5e058c61 100644 --- a/Engine/source/materials/materialDefinition.h +++ b/Engine/source/materials/materialDefinition.h @@ -211,11 +211,11 @@ public: DECLARE_TEXTUREARRAY(ToneMap, MAX_STAGES); DECLARE_TEXTUREARRAY(DetailMap, MAX_STAGES);; DECLARE_TEXTUREARRAY(NormalMap, MAX_STAGES); - DECLARE_TEXTUREARRAY(PBRConfigMap, MAX_STAGES); + DECLARE_TEXTUREARRAY(ORMConfigMap, MAX_STAGES); bool mIsSRGb[MAX_STAGES]; DECLARE_TEXTUREARRAY(RoughMap, MAX_STAGES); - bool mInvertSmoothness[MAX_STAGES]; - F32 mSmoothnessChan[MAX_STAGES]; + bool mInvertRoughness[MAX_STAGES]; + F32 mRoughnessChan[MAX_STAGES]; DECLARE_TEXTUREARRAY(AOMap, MAX_STAGES); F32 mAOChan[MAX_STAGES]; DECLARE_TEXTUREARRAY(MetalMap, MAX_STAGES); @@ -240,7 +240,7 @@ public: /// the diffuse texture color. LinearColorF mDiffuse[MAX_STAGES]; - F32 mSmoothness[MAX_STAGES]; + F32 mRoughness[MAX_STAGES]; F32 mMetalness[MAX_STAGES]; bool mVertLit[MAX_STAGES]; diff --git a/Engine/source/materials/materialFeatureTypes.cpp b/Engine/source/materials/materialFeatureTypes.cpp index 9abee92b5..408f5111c 100644 --- a/Engine/source/materials/materialFeatureTypes.cpp +++ b/Engine/source/materials/materialFeatureTypes.cpp @@ -43,9 +43,9 @@ ImplementFeatureType( MFT_DetailMap, MFG_Texture, 4.0f, true ); ImplementFeatureType( MFT_DiffuseColor, MFG_Texture, 5.0f, true ); ImplementFeatureType( MFT_DiffuseVertColor, MFG_Texture, 6.0f, true ); ImplementFeatureType( MFT_AlphaTest, MFG_Texture, 7.0f, true ); -ImplementFeatureType( MFT_InvertSmoothness, U32(-1), -1, true); -ImplementFeatureType( MFT_PBRConfigMap, MFG_Texture, 8.0f, true); -ImplementFeatureType( MFT_PBRConfigVars, MFG_Texture, 8.0f, true); +ImplementFeatureType( MFT_InvertRoughness, U32(-1), -1, true); +ImplementFeatureType( MFT_OrmMap, MFG_Texture, 8.0f, true); +ImplementFeatureType( MFT_ORMConfigVars, MFG_Texture, 8.0f, true); ImplementFeatureType( MFT_MatInfoFlags, MFG_Texture, 9.0f, true); ImplementFeatureType( MFT_NormalMap, MFG_Texture, 11.0f, true ); ImplementFeatureType( MFT_DetailNormalMap, MFG_Texture, 12.0f, true ); diff --git a/Engine/source/materials/materialFeatureTypes.h b/Engine/source/materials/materialFeatureTypes.h index 6ab6ba418..7a2eff089 100644 --- a/Engine/source/materials/materialFeatureTypes.h +++ b/Engine/source/materials/materialFeatureTypes.h @@ -124,9 +124,9 @@ DeclareFeatureType( MFT_VertLitTone ); DeclareFeatureType( MFT_StaticCubemap ); DeclareFeatureType( MFT_CubeMap ); -DeclareFeatureType( MFT_InvertSmoothness ); -DeclareFeatureType( MFT_PBRConfigMap ); -DeclareFeatureType( MFT_PBRConfigVars ); +DeclareFeatureType( MFT_InvertRoughness ); +DeclareFeatureType( MFT_OrmMap ); +DeclareFeatureType( MFT_ORMConfigVars ); DeclareFeatureType( MFT_GlowMap ); diff --git a/Engine/source/materials/processedMaterial.cpp b/Engine/source/materials/processedMaterial.cpp index caa86dbba..05d3aac16 100644 --- a/Engine/source/materials/processedMaterial.cpp +++ b/Engine/source/materials/processedMaterial.cpp @@ -485,27 +485,27 @@ void ProcessedMaterial::_setStageData() if (mMaterial->mIsSRGb[i]) profile = &GFXStaticTextureSRGBProfile; - // PBRConfig - if (mMaterial->mPBRConfigMapFilename[i].isNotEmpty()) + // ORMConfig + if (mMaterial->mORMConfigMapFilename[i].isNotEmpty()) { - mStages[i].setTex(MFT_PBRConfigMap, _createTexture(mMaterial->mPBRConfigMapFilename[i], profile)); - if (!mStages[i].getTex(MFT_PBRConfigMap)) - mMaterial->logError("Failed to load PBR Config map %s for stage %i", _getTexturePath(mMaterial->mPBRConfigMapFilename[i]).c_str(), i); + mStages[i].setTex(MFT_OrmMap, _createTexture(mMaterial->mORMConfigMapFilename[i], profile)); + if (!mStages[i].getTex(MFT_OrmMap)) + mMaterial->logError("Failed to load PBR Config map %s for stage %i", _getTexturePath(mMaterial->mORMConfigMapFilename[i]).c_str(), i); } else { if (mMaterial->mRoughMapFilename[i].isNotEmpty() && mMaterial->mMetalMapFilename[i].isNotEmpty()) { U32 inputKey[4]; - inputKey[0] = mMaterial->mSmoothnessChan[i]; - inputKey[1] = mMaterial->mAOChan[i]; + inputKey[0] = mMaterial->mAOChan[i]; + inputKey[1] = mMaterial->mRoughnessChan[i]; inputKey[2] = mMaterial->mMetalChan[i]; inputKey[3] = 0; - mStages[i].setTex(MFT_PBRConfigMap, _createCompositeTexture(mMaterial->mRoughMapFilename[i], mMaterial->mAOMapFilename[i], + mStages[i].setTex(MFT_OrmMap, _createCompositeTexture( mMaterial->mAOMapFilename[i], mMaterial->mRoughMapFilename[i], mMaterial->mMetalMapFilename[i], "", inputKey, profile)); - if (!mStages[i].getTex(MFT_PBRConfigMap)) - mMaterial->logError("Failed to load PBR Config map %s for stage %i", _getTexturePath(mMaterial->mPBRConfigMapFilename[i]).c_str(), i); + if (!mStages[i].getTex(MFT_OrmMap)) + mMaterial->logError("Failed to load PBR Config map %s for stage %i", _getTexturePath(mMaterial->mORMConfigMapFilename[i]).c_str(), i); } } if (mMaterial->mGlowMapFilename[i].isNotEmpty()) diff --git a/Engine/source/materials/processedShaderMaterial.cpp b/Engine/source/materials/processedShaderMaterial.cpp index fcd2a0c6a..a5ae8c95a 100644 --- a/Engine/source/materials/processedShaderMaterial.cpp +++ b/Engine/source/materials/processedShaderMaterial.cpp @@ -59,8 +59,8 @@ void ShaderConstHandles::init( GFXShader *shader, CustomMaterial* mat /*=NULL*/) mDiffuseColorSC = shader->getShaderConstHandle("$diffuseMaterialColor"); mTexMatSC = shader->getShaderConstHandle(ShaderGenVars::texMat); mToneMapTexSC = shader->getShaderConstHandle(ShaderGenVars::toneMap); - mPBRConfigSC = shader->getShaderConstHandle(ShaderGenVars::pbrConfig); - mSmoothnessSC = shader->getShaderConstHandle(ShaderGenVars::smoothness); + mORMConfigSC = shader->getShaderConstHandle(ShaderGenVars::ormConfig); + mRoughnessSC = shader->getShaderConstHandle(ShaderGenVars::roughness); mMetalnessSC = shader->getShaderConstHandle(ShaderGenVars::metalness); mGlowMulSC = shader->getShaderConstHandle(ShaderGenVars::glowMul); mAccuScaleSC = shader->getShaderConstHandle("$accuScale"); @@ -304,8 +304,8 @@ void ProcessedShaderMaterial::_determineFeatures( U32 stageNum, // First we add all the features which the // material has defined. - if (mMaterial->mInvertSmoothness[stageNum]) - fd.features.addFeature(MFT_InvertSmoothness); + if (mMaterial->mInvertRoughness[stageNum]) + fd.features.addFeature(MFT_InvertRoughness); if ( mMaterial->isTranslucent() ) { @@ -429,12 +429,12 @@ void ProcessedShaderMaterial::_determineFeatures( U32 stageNum, } // Deferred Shading : PBR Config - if (mStages[stageNum].getTex(MFT_PBRConfigMap)) + if (mStages[stageNum].getTex(MFT_OrmMap)) { - fd.features.addFeature(MFT_PBRConfigMap); + fd.features.addFeature(MFT_OrmMap); } else - fd.features.addFeature(MFT_PBRConfigVars); + fd.features.addFeature(MFT_ORMConfigVars); // Deferred Shading : Material Info Flags fd.features.addFeature(MFT_MatInfoFlags); @@ -450,7 +450,7 @@ void ProcessedShaderMaterial::_determineFeatures( U32 stageNum, fd.features.addFeature(MFT_SkyBox); fd.features.removeFeature(MFT_ReflectionProbes); - fd.features.removeFeature(MFT_PBRConfigVars); + fd.features.removeFeature(MFT_ORMConfigVars); fd.features.removeFeature(MFT_MatInfoFlags); } @@ -1109,7 +1109,7 @@ void ProcessedShaderMaterial::_setShaderConstants(SceneRenderState * state, cons if ( !shaderConsts->wasLost() ) return; - shaderConsts->setSafe(handles->mSmoothnessSC, mMaterial->mSmoothness[stageNum]); + shaderConsts->setSafe(handles->mRoughnessSC, mMaterial->mRoughness[stageNum]); shaderConsts->setSafe(handles->mMetalnessSC, mMaterial->mMetalness[stageNum]); shaderConsts->setSafe(handles->mGlowMulSC, mMaterial->mGlowMul[stageNum]); diff --git a/Engine/source/materials/processedShaderMaterial.h b/Engine/source/materials/processedShaderMaterial.h index c0bc14cf7..dc63f4f25 100644 --- a/Engine/source/materials/processedShaderMaterial.h +++ b/Engine/source/materials/processedShaderMaterial.h @@ -46,8 +46,8 @@ public: GFXShaderConstHandle* mDiffuseColorSC; GFXShaderConstHandle* mToneMapTexSC; GFXShaderConstHandle* mTexMatSC; - GFXShaderConstHandle* mPBRConfigSC; - GFXShaderConstHandle* mSmoothnessSC; + GFXShaderConstHandle* mORMConfigSC; + GFXShaderConstHandle* mRoughnessSC; GFXShaderConstHandle* mMetalnessSC; GFXShaderConstHandle* mGlowMulSC; GFXShaderConstHandle* mParallaxInfoSC; diff --git a/Engine/source/renderInstance/renderDeferredMgr.cpp b/Engine/source/renderInstance/renderDeferredMgr.cpp index e59de5d9a..5adda3c3f 100644 --- a/Engine/source/renderInstance/renderDeferredMgr.cpp +++ b/Engine/source/renderInstance/renderDeferredMgr.cpp @@ -633,16 +633,16 @@ void ProcessedDeferredMaterial::_determineFeatures( U32 stageNum, } newFeatures.addFeature( MFT_DiffuseColor ); - if (mMaterial->mInvertSmoothness[stageNum]) - newFeatures.addFeature(MFT_InvertSmoothness); + if (mMaterial->mInvertRoughness[stageNum]) + newFeatures.addFeature(MFT_InvertRoughness); // Deferred Shading : PBR Config - if( mStages[stageNum].getTex( MFT_PBRConfigMap ) ) + if( mStages[stageNum].getTex( MFT_OrmMap ) ) { - newFeatures.addFeature( MFT_PBRConfigMap ); + newFeatures.addFeature( MFT_OrmMap ); } else - newFeatures.addFeature( MFT_PBRConfigVars ); + newFeatures.addFeature( MFT_ORMConfigVars ); if (mStages[stageNum].getTex(MFT_GlowMap)) { diff --git a/Engine/source/renderInstance/renderProbeMgr.cpp b/Engine/source/renderInstance/renderProbeMgr.cpp index 89c42fe08..b114da55a 100644 --- a/Engine/source/renderInstance/renderProbeMgr.cpp +++ b/Engine/source/renderInstance/renderProbeMgr.cpp @@ -204,7 +204,8 @@ RenderProbeMgr::RenderProbeMgr() mHasSkylight(false), mSkylightCubemapIdx(-1), mCubeMapCount(0), - mDefaultSkyLight(nullptr) + mDefaultSkyLight(nullptr), + mBakeRenderTarget(nullptr) { mEffectiveProbeCount = 0; mMipCount = 0; @@ -462,7 +463,7 @@ void RenderProbeMgr::_setupStaticParameters() continue; U32 mips = mRegisteredProbes[i].mPrefilterCubemap.getPointer()->getMipMapLevels(); - mMipCount = mips != 0 && mips >= mMipCount ? mips : 0; + mMipCount = (mips != 0 && mips >= mMipCount) ? mips : 0; if (curEntry.mIsSkylight) { @@ -853,7 +854,7 @@ void RenderProbeMgr::render( SceneRenderState *state ) //PROFILE_END(); } -void RenderProbeMgr::bakeProbe(ReflectionProbe *probe, bool writeFiles) +void RenderProbeMgr::bakeProbe(ReflectionProbe* probe, bool writeFiles) { GFXDEBUGEVENT_SCOPE(RenderProbeMgr_Bake, ColorI::WHITE); @@ -862,7 +863,7 @@ void RenderProbeMgr::bakeProbe(ReflectionProbe *probe, bool writeFiles) String path = Con::getVariable("$pref::ReflectionProbes::CurrentLevelPath", "levels/"); U32 resolution = Con::getIntVariable("$pref::ReflectionProbes::BakeResolution", 64); - U32 prefilterMipLevels = mLog2(F32(resolution)); + U32 prefilterMipLevels = mLog2(F32(resolution))+1; bool renderWithProbes = Con::getIntVariable("$pref::ReflectionProbes::RenderWithProbes", false); ReflectionProbe* clientProbe = nullptr; @@ -957,12 +958,13 @@ void RenderProbeMgr::bakeProbe(ReflectionProbe *probe, bool writeFiles) clientProbe->mIrridianceMap->mCubemap->initDynamic(resolution, reflectFormat); clientProbe->mPrefilterMap->mCubemap->initDynamic(resolution, reflectFormat); - GFXTextureTargetRef renderTarget = GFX->allocRenderToTextureTarget(false); + if (mBakeRenderTarget == nullptr) + mBakeRenderTarget = GFX->allocRenderToTextureTarget(false); + else + mBakeRenderTarget->resurrect(); - IBLUtilities::GenerateIrradianceMap(renderTarget, cubeRefl.getCubemap(), clientProbe->mIrridianceMap->mCubemap); - IBLUtilities::GeneratePrefilterMap(renderTarget, cubeRefl.getCubemap(), prefilterMipLevels, clientProbe->mPrefilterMap->mCubemap); - - renderTarget->destroySelf(); + IBLUtilities::GenerateIrradianceMap(mBakeRenderTarget, cubeRefl.getCubemap(), clientProbe->mIrridianceMap->mCubemap); + IBLUtilities::GeneratePrefilterMap(mBakeRenderTarget, cubeRefl.getCubemap(), prefilterMipLevels, clientProbe->mPrefilterMap->mCubemap); U32 endMSTime = Platform::getRealMilliseconds(); F32 diffTime = F32(endMSTime - startMSTime); @@ -975,12 +977,15 @@ void RenderProbeMgr::bakeProbe(ReflectionProbe *probe, bool writeFiles) IBLUtilities::SaveCubeMap(clientProbe->getIrradianceMapPath(), clientProbe->mIrridianceMap->mCubemap); IBLUtilities::SaveCubeMap(clientProbe->getPrefilterMapPath(), clientProbe->mPrefilterMap->mCubemap); } + + mBakeRenderTarget->zombify(); } else { Con::errorf("RenderProbeMgr::bake() - Didn't generate a valid scene capture cubemap, unable to generate prefilter and irradiance maps!"); } + if (!renderWithProbes) RenderProbeMgr::smRenderReflectionProbes = probeRenderState; diff --git a/Engine/source/renderInstance/renderProbeMgr.h b/Engine/source/renderInstance/renderProbeMgr.h index 281a5d87e..29673e20b 100644 --- a/Engine/source/renderInstance/renderProbeMgr.h +++ b/Engine/source/renderInstance/renderProbeMgr.h @@ -280,6 +280,8 @@ private: GFXTexHandle mBRDFTexture; + GFXTextureTargetRef mBakeRenderTarget; + public: RenderProbeMgr(); RenderProbeMgr(RenderInstType riType, F32 renderOrder, F32 processAddOrder); diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp index 62874f22d..a1c5462e4 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp @@ -841,8 +841,8 @@ Var* ShaderFeatureGLSL::getSurface(Vector& componentList, Mult Var* diffuseColor = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget)); - Var* pbrConfig = (Var*)LangElement::find("PBRConfig"); - if (!pbrConfig) + Var* ormConfig = (Var*)LangElement::find("ORMConfig"); + if (!ormConfig) { Var* metalness = (Var*)LangElement::find("metalness"); if (!metalness) @@ -852,17 +852,17 @@ Var* ShaderFeatureGLSL::getSurface(Vector& componentList, Mult metalness->constSortPos = cspPotentialPrimitive; } - Var* smoothness = (Var*)LangElement::find("smoothness"); - if (!smoothness) + Var* roughness = (Var*)LangElement::find("roughness"); + if (!roughness) { - smoothness = new Var("smoothness", "float"); - smoothness->uniform = true; - smoothness->constSortPos = cspPotentialPrimitive; + roughness = new Var("roughness", "float"); + roughness->uniform = true; + roughness->constSortPos = cspPotentialPrimitive; } - pbrConfig = new Var("PBRConfig", "vec4"); - LangElement* colorDecl = new DecOp(pbrConfig); - meta->addStatement(new GenOp(" @ = vec4(0.0,1.0,@,@);\r\n", colorDecl, smoothness, metalness)); //reconstruct pbrConfig, no ao darkening + ormConfig = new Var("ORMConfig", "vec4"); + LangElement* colorDecl = new DecOp(ormConfig); + meta->addStatement(new GenOp(" @ = vec4(0.0,1.0,@,@);\r\n", colorDecl, roughness, metalness)); //reconstruct ormConfig, no ao darkening } Var* wsNormal = (Var*)LangElement::find("wsNormal"); @@ -899,7 +899,7 @@ Var* ShaderFeatureGLSL::getSurface(Vector& componentList, Mult if (!surface) { surface = new Var("surface", "Surface"); - meta->addStatement(new GenOp(" @ = createForwardSurface(@,@,@,@,@,@);\r\n\n", new DecOp(surface), diffuseColor, normal, pbrConfig, + meta->addStatement(new GenOp(" @ = createForwardSurface(@,@,@,@,@,@);\r\n\n", new DecOp(surface), diffuseColor, normal, ormConfig, wsPosition, wsEyePos, wsView)); } @@ -1922,9 +1922,9 @@ void ReflectCubeFeatGLSL::processPix( Vector &componentList, LangElement *texCube = NULL; Var* matinfo = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); - Var *smoothness = (Var*)LangElement::find("smoothness"); - if (smoothness) //try to grab smoothness directly - texCube = new GenOp("textureLod( @, @, min((1.0 - @)*@ + 1.0, @))", cubeMap, reflectVec, smoothness, cubeMips, cubeMips); + Var *roughness = (Var*)LangElement::find("roughness"); + if (roughness) //try to grab roughness directly + texCube = new GenOp("textureLod( @, @, min((1.0 - @)*@ + 1.0, @))", cubeMap, reflectVec, roughness, cubeMips, cubeMips); else if (glossColor) //failing that, try and find color data texCube = new GenOp("textureLod( @, @, min((1.0 - @.b)*@ + 1.0, @))", cubeMap, reflectVec, glossColor, cubeMips, cubeMips); else //failing *that*, just draw the cubemap @@ -2219,7 +2219,7 @@ void RTLightingFeatGLSL::processPix( Vector &componentList, Con::errorf("ShaderGen::RTLightingFeatGLSL() - failed to generate surface!"); return; } - Var *smoothness = (Var*)LangElement::find("smoothness"); + Var *roughness = (Var*)LangElement::find("roughness"); Var *metalness = (Var*)LangElement::find("metalness"); diff --git a/Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp b/Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp index e1f684280..02b7bafb1 100644 --- a/Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp +++ b/Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp @@ -64,7 +64,7 @@ void _initShaderGenGLSL( ShaderGen *shaderGen ) FEATUREMGR->registerFeature( MFT_DetailMap, new DetailFeatGLSL ); FEATUREMGR->registerFeature( MFT_StaticCubemap, new NamedFeatureGLSL( "Static Cubemap" ) ); FEATUREMGR->registerFeature( MFT_CubeMap, new ReflectCubeFeatGLSL ); - FEATUREMGR->registerFeature( MFT_InvertSmoothness, new NamedFeatureGLSL("Roughest = 1.0")); + FEATUREMGR->registerFeature( MFT_InvertRoughness, new NamedFeatureGLSL("Roughest = 1.0")); FEATUREMGR->registerFeature( MFT_AccuMap, new AccuTexFeatGLSL ); FEATUREMGR->registerFeature( MFT_IsTranslucent, new NamedFeatureGLSL( "Translucent" ) ); FEATUREMGR->registerFeature( MFT_IsTranslucentZWrite, new NamedFeatureGLSL( "Translucent ZWrite" ) ); @@ -99,8 +99,8 @@ void _initShaderGenGLSL( ShaderGen *shaderGen ) // Deferred Shading FEATUREMGR->registerFeature( MFT_isDeferred, new NamedFeatureGLSL( "Deferred Material" ) ); - FEATUREMGR->registerFeature( MFT_PBRConfigMap, new PBRConfigMapGLSL ); - FEATUREMGR->registerFeature( MFT_PBRConfigVars, new PBRConfigVarsGLSL ); + FEATUREMGR->registerFeature( MFT_OrmMap, new DeferredOrmMapGLSL ); + FEATUREMGR->registerFeature( MFT_ORMConfigVars, new ORMConfigVarsGLSL ); FEATUREMGR->registerFeature( MFT_MatInfoFlags, new MatInfoFlagsGLSL ); FEATUREMGR->registerFeature( MFT_GlowMap, new GlowMapGLSL); FEATUREMGR->registerFeature( MFT_isBackground, new NamedFeatureGLSL("Background Object")); diff --git a/Engine/source/shaderGen/HLSL/debugVizFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/debugVizFeatureHLSL.cpp index 4ac85abce..0cc582427 100644 --- a/Engine/source/shaderGen/HLSL/debugVizFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/debugVizFeatureHLSL.cpp @@ -155,9 +155,9 @@ void DebugVizHLSL::processPix(Vector& componentList, Var* irradianceCubemapAR = (Var*)LangElement::find("irradianceCubemapAR"); Var* irradianceCubemapARTex = (Var*)LangElement::find("texture_irradianceCubemapAR"); - Var* matinfo = (Var*)LangElement::find("PBRConfig"); + Var* matinfo = (Var*)LangElement::find("ORMConfig"); Var* metalness = (Var*)LangElement::find("metalness"); - Var* smoothness = (Var*)LangElement::find("smoothness"); + Var* roughness = (Var*)LangElement::find("roughness"); Var* wsEyePos = (Var*)LangElement::find("eyePosWorld"); diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp index 4ebd53024..32c7ddf26 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp @@ -848,8 +848,8 @@ Var* ShaderFeatureHLSL::getSurface(Vector& componentList, Mult Var* diffuseColor = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget)); - Var* pbrConfig = (Var*)LangElement::find("PBRConfig"); - if (!pbrConfig) + Var* ormConfig = (Var*)LangElement::find("ORMConfig"); + if (!ormConfig) { Var* metalness = (Var*)LangElement::find("metalness"); if (!metalness) @@ -859,17 +859,17 @@ Var* ShaderFeatureHLSL::getSurface(Vector& componentList, Mult metalness->constSortPos = cspPotentialPrimitive; } - Var* smoothness = (Var*)LangElement::find("smoothness"); - if (!smoothness) + Var* roughness = (Var*)LangElement::find("roughness"); + if (!roughness) { - smoothness = new Var("smoothness", "float"); - smoothness->uniform = true; - smoothness->constSortPos = cspPotentialPrimitive; + roughness = new Var("roughness", "float"); + roughness->uniform = true; + roughness->constSortPos = cspPotentialPrimitive; } - pbrConfig = new Var("PBRConfig", "float4"); - LangElement* colorDecl = new DecOp(pbrConfig); - meta->addStatement(new GenOp(" @ = float4(0.0,1.0,@,@);\r\n", colorDecl, smoothness, metalness)); //reconstruct matinfo, no ao darkening + ormConfig = new Var("ORMConfig", "float4"); + LangElement* colorDecl = new DecOp(ormConfig); + meta->addStatement(new GenOp(" @ = float4(0.0,1.0,@,@);\r\n", colorDecl, roughness, metalness)); //reconstruct matinfo, no ao darkening } Var* normal = (Var*)LangElement::find("normal"); @@ -902,7 +902,7 @@ Var* ShaderFeatureHLSL::getSurface(Vector& componentList, Mult if (!surface) { surface = new Var("surface", "Surface"); - meta->addStatement(new GenOp(" @ = createForwardSurface(@,@,@,@,@,@);\r\n\n", new DecOp(surface), diffuseColor, normal, pbrConfig, + meta->addStatement(new GenOp(" @ = createForwardSurface(@,@,@,@,@,@);\r\n\n", new DecOp(surface), diffuseColor, normal, ormConfig, wsPosition, wsEyePos, wsView)); } @@ -1327,7 +1327,7 @@ void LightmapFeatHLSL::processPix( Vector &componentList, lightMapTex->texture = true; lightMapTex->constNum = lightMap->constNum; - // argh, PBRConfigMap should prob use this too + // argh, ORMConfigMap should prob use this too if( fd.features[MFT_NormalMap] ) { Var *lmColor = new Var; @@ -1985,11 +1985,11 @@ void ReflectCubeFeatHLSL::processPix( Vector &componentList, LangElement *texCube = NULL; Var* matinfo = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); - Var *smoothness = (Var*)LangElement::find("smoothness"); + Var *roughness = (Var*)LangElement::find("roughness"); - if (smoothness) //try to grab smoothness directly + if (roughness) //try to grab roughness directly { - texCube = new GenOp("@.SampleLevel( @, float3(@).rgb, min((1.0 - @)*@ + 1.0, @))", cubeMapTex, cubeMap, reflectVec, smoothness, cubeMips, cubeMips); + texCube = new GenOp("@.SampleLevel( @, float3(@).rgb, min((1.0 - @)*@ + 1.0, @))", cubeMapTex, cubeMap, reflectVec, roughness, cubeMips, cubeMips); } else if (glossColor)//failing that, try and find color data { @@ -2287,7 +2287,7 @@ void RTLightingFeatHLSL::processPix( Vector &componentList, Con::errorf("ShaderGen::RTLightingFeatHLSL() - failed to generate surface!"); return; } - Var *smoothness = (Var*)LangElement::find("smoothness"); + Var *roughness = (Var*)LangElement::find("roughness"); Var *metalness = (Var*)LangElement::find("metalness"); diff --git a/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp b/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp index da55a7ed5..0b0e6ee85 100644 --- a/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp +++ b/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp @@ -65,7 +65,7 @@ void _initShaderGenHLSL( ShaderGen *shaderGen ) FEATUREMGR->registerFeature( MFT_StaticCubemap, new NamedFeatureHLSL( "Static Cubemap" ) ); FEATUREMGR->registerFeature( MFT_CubeMap, new ReflectCubeFeatHLSL ); FEATUREMGR->registerFeature( MFT_ReflectionProbes, new ReflectionProbeFeatHLSL); - FEATUREMGR->registerFeature( MFT_InvertSmoothness, new NamedFeatureHLSL( "Roughest = 1.0" ) ); + FEATUREMGR->registerFeature( MFT_InvertRoughness, new NamedFeatureHLSL( "Roughest = 1.0" ) ); FEATUREMGR->registerFeature( MFT_IsTranslucent, new NamedFeatureHLSL( "Translucent" ) ); FEATUREMGR->registerFeature( MFT_IsTranslucentZWrite, new NamedFeatureHLSL( "Translucent ZWrite" ) ); FEATUREMGR->registerFeature( MFT_Visibility, new VisibilityFeatHLSL ); @@ -102,8 +102,8 @@ void _initShaderGenHLSL( ShaderGen *shaderGen ) FEATUREMGR->registerFeature( MFT_ImposterVert, new ImposterVertFeatureHLSL ); FEATUREMGR->registerFeature( MFT_isDeferred, new NamedFeatureHLSL( "Deferred Material" ) ); - FEATUREMGR->registerFeature( MFT_PBRConfigMap, new PBRConfigMapHLSL); - FEATUREMGR->registerFeature( MFT_PBRConfigVars, new PBRConfigVarsHLSL); + FEATUREMGR->registerFeature( MFT_OrmMap, new DeferredOrmMapHLSL); + FEATUREMGR->registerFeature( MFT_ORMConfigVars, new ORMConfigVarsHLSL); FEATUREMGR->registerFeature( MFT_MatInfoFlags, new MatInfoFlagsHLSL ); FEATUREMGR->registerFeature( MFT_GlowMap, new GlowMapHLSL); FEATUREMGR->registerFeature( MFT_isBackground, new NamedFeatureHLSL("Background Object")); diff --git a/Engine/source/shaderGen/shaderGenVars.cpp b/Engine/source/shaderGen/shaderGenVars.cpp index 4c75287b4..9ed8db43f 100644 --- a/Engine/source/shaderGen/shaderGenVars.cpp +++ b/Engine/source/shaderGen/shaderGenVars.cpp @@ -73,8 +73,8 @@ const String ShaderGenVars::vectorLightDirection("$vectorLightDirection"); const String ShaderGenVars::vectorLightColor("$vectorLightColor"); const String ShaderGenVars::vectorLightBrightness("$vectorLightBrightness"); -const String ShaderGenVars::pbrConfig("$PBRConfig"); -const String ShaderGenVars::smoothness("$smoothness"); +const String ShaderGenVars::ormConfig("$ORMConfig"); +const String ShaderGenVars::roughness("$roughness"); const String ShaderGenVars::metalness("$metalness"); const String ShaderGenVars::glowMul("$glowMul"); diff --git a/Engine/source/shaderGen/shaderGenVars.h b/Engine/source/shaderGen/shaderGenVars.h index 86055d6eb..db32af16c 100644 --- a/Engine/source/shaderGen/shaderGenVars.h +++ b/Engine/source/shaderGen/shaderGenVars.h @@ -85,8 +85,8 @@ struct ShaderGenVars const static String vectorLightColor; const static String vectorLightBrightness; - const static String pbrConfig; - const static String smoothness; + const static String ormConfig; + const static String roughness; const static String metalness; const static String glowMul; diff --git a/Engine/source/terrain/glsl/terrFeatureGLSL.cpp b/Engine/source/terrain/glsl/terrFeatureGLSL.cpp index 7e7a9045e..0756c6a19 100644 --- a/Engine/source/terrain/glsl/terrFeatureGLSL.cpp +++ b/Engine/source/terrain/glsl/terrFeatureGLSL.cpp @@ -49,7 +49,7 @@ namespace FEATUREMGR->registerFeature( MFT_TerrainLightMap, new TerrainLightMapFeatGLSL ); FEATUREMGR->registerFeature( MFT_TerrainSideProject, new NamedFeatureGLSL( "Terrain Side Projection" ) ); FEATUREMGR->registerFeature( MFT_TerrainAdditive, new TerrainAdditiveFeatGLSL ); - FEATUREMGR->registerFeature( MFT_TerrainCompositeMap, new TerrainCompositeMapFeatGLSL ); + FEATUREMGR->registerFeature( MFT_TerrainORMMap, new TerrainORMMapFeatGLSL ); FEATUREMGR->registerFeature( MFT_DeferredTerrainBlankInfoMap, new TerrainBlankInfoMapFeatGLSL ); } @@ -142,22 +142,22 @@ Var* TerrainFeatGLSL::_getNormalMapTex() return normalMap; } -Var* TerrainFeatGLSL::_getCompositeMapTex() +Var* TerrainFeatGLSL::_getORMConfigMapTex() { - String name(String::ToString("compositeMap%d", getProcessIndex())); - Var *compositeMap = (Var*)LangElement::find(name); + String name(String::ToString("ormConfigMap%d", getProcessIndex())); + Var *ormConfigMap = (Var*)LangElement::find(name); - if (!compositeMap) + if (!ormConfigMap) { - compositeMap = new Var; - compositeMap->setType("sampler2D"); - compositeMap->setName(name); - compositeMap->uniform = true; - compositeMap->sampler = true; - compositeMap->constNum = Var::getTexUnitNum(); + ormConfigMap = new Var; + ormConfigMap->setType("sampler2D"); + ormConfigMap->setName(name); + ormConfigMap->uniform = true; + ormConfigMap->sampler = true; + ormConfigMap->constNum = Var::getTexUnitNum(); } - return compositeMap; + return ormConfigMap; } Var* TerrainFeatGLSL::_getDetailIdStrengthParallax() @@ -1140,7 +1140,7 @@ void TerrainAdditiveFeatGLSL::processPix( Vector &componentLis //.b = specular strength, a= spec power. -void TerrainCompositeMapFeatGLSL::processVert(Vector &componentList, +void TerrainORMMapFeatGLSL::processVert(Vector &componentList, const MaterialFeatureData &fd) { const S32 detailIndex = getProcessIndex(); @@ -1230,12 +1230,12 @@ void TerrainCompositeMapFeatGLSL::processVert(Vector &componen output = meta; } -U32 TerrainCompositeMapFeatGLSL::getOutputTargets(const MaterialFeatureData &fd) const +U32 TerrainORMMapFeatGLSL::getOutputTargets(const MaterialFeatureData &fd) const { return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::RenderTarget1; } -void TerrainCompositeMapFeatGLSL::processPix(Vector &componentList, +void TerrainORMMapFeatGLSL::processPix(Vector &componentList, const MaterialFeatureData &fd) { /// Get the texture coord. @@ -1243,7 +1243,7 @@ void TerrainCompositeMapFeatGLSL::processPix(Vector &component Var *inTex = getVertTexCoord("texCoord"); const S32 compositeIndex = getProcessIndex(); - Var *compositeMap = _getCompositeMapTex(); + Var *ormConfigMap = _getORMConfigMapTex(); // Sample the normal map. // // We take two normal samples and lerp between them for @@ -1253,28 +1253,28 @@ void TerrainCompositeMapFeatGLSL::processPix(Vector &component if (fd.features.hasFeature(MFT_TerrainSideProject, compositeIndex)) { texOp = new GenOp("lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z )", - compositeMap, inDet, compositeMap, inDet, inTex); + ormConfigMap, inDet, ormConfigMap, inDet, inTex); } else - texOp = new GenOp("tex2D(@, @.xy)", compositeMap, inDet); + texOp = new GenOp("tex2D(@, @.xy)", ormConfigMap, inDet); // search for material var - Var * pbrConfig; + Var * ormConfig; OutputTarget targ = RenderTarget1; if (fd.features[MFT_isDeferred]) { targ = RenderTarget2; } - pbrConfig = (Var*)LangElement::find(getOutputTargetVarName(targ)); + ormConfig = (Var*)LangElement::find(getOutputTargetVarName(targ)); MultiLine * meta = new MultiLine; - if (!pbrConfig) + if (!ormConfig) { // create color var - pbrConfig = new Var; - pbrConfig->setType("fragout"); - pbrConfig->setName(getOutputTargetVarName(targ)); - pbrConfig->setStructName("OUT"); + ormConfig = new Var; + ormConfig->setType("fragout"); + ormConfig->setName(getOutputTargetVarName(targ)); + ormConfig->setStructName("OUT"); } Var *detailBlend = (Var*)LangElement::find(String::ToString("detailBlend%d", compositeIndex)); @@ -1287,23 +1287,23 @@ void TerrainCompositeMapFeatGLSL::processPix(Vector &component if (priorComp) { meta->addStatement(new GenOp(" @ = @.rgb*@;\r\n", new DecOp(matinfoCol), texOp, detailBlend)); - meta->addStatement(new GenOp(" @.bga += @;\r\n", pbrConfig, matinfoCol)); + meta->addStatement(new GenOp(" @.gba += @;\r\n", ormConfig, matinfoCol)); } else { - meta->addStatement(new GenOp(" @ = lerp(vec3(0,1,0),@.rgb,@);\r\n", new DecOp(matinfoCol), texOp, detailBlend)); - meta->addStatement(new GenOp(" @ = vec4(0.0,@);\r\n", pbrConfig, matinfoCol)); + meta->addStatement(new GenOp(" @ = lerp(vec3(1.0,1.0,0.0),@.rgb,@);\r\n", new DecOp(matinfoCol), texOp, detailBlend)); + meta->addStatement(new GenOp(" @ = vec4(0.0,@);\r\n", ormConfig, matinfoCol)); } - if (!fd.features[MFT_InvertSmoothness]) + if (fd.features[MFT_InvertRoughness]) { - meta->addStatement(new GenOp(" @.b = 1.0-@.b;\r\n", pbrConfig, pbrConfig)); + meta->addStatement(new GenOp(" @.b = 1.0-@.b;\r\n", ormConfig, ormConfig)); } output = meta; } -ShaderFeature::Resources TerrainCompositeMapFeatGLSL::getResources(const MaterialFeatureData &fd) +ShaderFeature::Resources TerrainORMMapFeatGLSL::getResources(const MaterialFeatureData &fd) { Resources res; res.numTex = 1; @@ -1340,7 +1340,7 @@ void TerrainBlankInfoMapFeatGLSL::processPix(Vector &component material->setStructName("OUT"); } - meta->addStatement(new GenOp(" @ = vec4(0.0,0.0,1.0,0);\r\n", material)); + meta->addStatement(new GenOp(" @ = vec4(0.0,1.0,1.0,0.0);\r\n", material)); output = meta; } diff --git a/Engine/source/terrain/glsl/terrFeatureGLSL.h b/Engine/source/terrain/glsl/terrFeatureGLSL.h index fa024c609..830e396d7 100644 --- a/Engine/source/terrain/glsl/terrFeatureGLSL.h +++ b/Engine/source/terrain/glsl/terrFeatureGLSL.h @@ -46,7 +46,7 @@ public: Var* _getNormalMapTex(); - Var* _getCompositeMapTex(); + Var* _getORMConfigMapTex(); static Var* _getUniformVar( const char *name, const char *type, ConstantSortPosition csp ); @@ -162,7 +162,7 @@ public: virtual String getName() { return "Terrain Additive"; } }; -class TerrainCompositeMapFeatGLSL : public TerrainFeatGLSL +class TerrainORMMapFeatGLSL : public TerrainFeatGLSL { public: diff --git a/Engine/source/terrain/hlsl/terrFeatureHLSL.cpp b/Engine/source/terrain/hlsl/terrFeatureHLSL.cpp index 5cd91c390..9b8b7debb 100644 --- a/Engine/source/terrain/hlsl/terrFeatureHLSL.cpp +++ b/Engine/source/terrain/hlsl/terrFeatureHLSL.cpp @@ -49,7 +49,7 @@ namespace FEATUREMGR->registerFeature( MFT_TerrainLightMap, new TerrainLightMapFeatHLSL ); FEATUREMGR->registerFeature( MFT_TerrainSideProject, new NamedFeatureHLSL( "Terrain Side Projection" ) ); FEATUREMGR->registerFeature( MFT_TerrainAdditive, new TerrainAdditiveFeatHLSL ); - FEATUREMGR->registerFeature( MFT_TerrainCompositeMap, new TerrainCompositeMapFeatHLSL ); + FEATUREMGR->registerFeature( MFT_TerrainORMMap, new TerrainORMMapFeatHLSL ); FEATUREMGR->registerFeature( MFT_DeferredTerrainBlankInfoMap, new TerrainBlankInfoMapFeatHLSL ); } }; @@ -141,22 +141,22 @@ Var* TerrainFeatHLSL::_getNormalMapTex() return normalMap; } -Var* TerrainFeatHLSL::_getCompositeMapTex() +Var* TerrainFeatHLSL::_getORMConfigMapTex() { - String name(String::ToString("compositeMap%d", getProcessIndex())); - Var *compositeMap = (Var*)LangElement::find(name); + String name(String::ToString("ormConfigMap%d", getProcessIndex())); + Var *ormConfigMap = (Var*)LangElement::find(name); - if (!compositeMap) + if (!ormConfigMap) { - compositeMap = new Var; - compositeMap->setType("SamplerState"); - compositeMap->setName(name); - compositeMap->uniform = true; - compositeMap->sampler = true; - compositeMap->constNum = Var::getTexUnitNum(); + ormConfigMap = new Var; + ormConfigMap->setType("SamplerState"); + ormConfigMap->setName(name); + ormConfigMap->uniform = true; + ormConfigMap->sampler = true; + ormConfigMap->constNum = Var::getTexUnitNum(); } - return compositeMap; + return ormConfigMap; } Var* TerrainFeatHLSL::_getDetailIdStrengthParallax() @@ -1148,7 +1148,7 @@ void TerrainAdditiveFeatHLSL::processPix( Vector &componentLis //standard matInfo map contains data of the form .r = bitflags, .g = (will contain AO), //.b = specular strength, a= spec power. -void TerrainCompositeMapFeatHLSL::processVert(Vector &componentList, +void TerrainORMMapFeatHLSL::processVert(Vector &componentList, const MaterialFeatureData &fd) { const S32 detailIndex = getProcessIndex(); @@ -1238,12 +1238,12 @@ void TerrainCompositeMapFeatHLSL::processVert(Vector &componen output = meta; } -U32 TerrainCompositeMapFeatHLSL::getOutputTargets(const MaterialFeatureData &fd) const +U32 TerrainORMMapFeatHLSL::getOutputTargets(const MaterialFeatureData &fd) const { return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::DefaultTarget; } -void TerrainCompositeMapFeatHLSL::processPix(Vector &componentList, +void TerrainORMMapFeatHLSL::processPix(Vector &componentList, const MaterialFeatureData &fd) { /// Get the texture coord. @@ -1251,48 +1251,48 @@ void TerrainCompositeMapFeatHLSL::processPix(Vector &component Var *inTex = getVertTexCoord("texCoord"); const S32 compositeIndex = getProcessIndex(); - Var *compositeMap = _getCompositeMapTex(); + Var *ormConfigMap = _getORMConfigMapTex(); // Sample the normal map. // // We take two normal samples and lerp between them for // side projection layers... else a single sample. LangElement *texOp; - String name(String::ToString("compositeMapTex%d", getProcessIndex())); - Var *compositeMapTex = (Var*)LangElement::find(name); - if (!compositeMapTex) + String name(String::ToString("ormConfigMapTex%d", getProcessIndex())); + Var *ormConfigMapTex = (Var*)LangElement::find(name); + if (!ormConfigMapTex) { - compositeMapTex = new Var; - compositeMapTex->setName(String::ToString("compositeMapTex%d", getProcessIndex())); - compositeMapTex->setType("Texture2D"); - compositeMapTex->uniform = true; - compositeMapTex->texture = true; - compositeMapTex->constNum = compositeMap->constNum; + ormConfigMapTex = new Var; + ormConfigMapTex->setName(String::ToString("ormConfigMapTex%d", getProcessIndex())); + ormConfigMapTex->setType("Texture2D"); + ormConfigMapTex->uniform = true; + ormConfigMapTex->texture = true; + ormConfigMapTex->constNum = ormConfigMap->constNum; } if (fd.features.hasFeature(MFT_TerrainSideProject, compositeIndex)) { texOp = new GenOp("lerp( @.Sample( @, @.yz ), @.Sample( @, @.xz ), @.z )", - compositeMapTex, compositeMap, inDet, compositeMapTex, compositeMap, inDet, inTex); + ormConfigMapTex, ormConfigMap, inDet, ormConfigMapTex, ormConfigMap, inDet, inTex); } else - texOp = new GenOp("@.Sample(@, @.xy)", compositeMapTex, compositeMap, inDet); + texOp = new GenOp("@.Sample(@, @.xy)", ormConfigMapTex, ormConfigMap, inDet); // search for material var - Var * pbrConfig; + Var * ormConfig; OutputTarget targ = DefaultTarget; if (fd.features[MFT_isDeferred]) { targ = RenderTarget2; } - pbrConfig = (Var*)LangElement::find(getOutputTargetVarName(targ)); + ormConfig = (Var*)LangElement::find(getOutputTargetVarName(targ)); MultiLine * meta = new MultiLine; - if (!pbrConfig) + if (!ormConfig) { // create color var - pbrConfig = new Var; - pbrConfig->setType("fragout"); - pbrConfig->setName(getOutputTargetVarName(targ)); - pbrConfig->setStructName("OUT"); + ormConfig = new Var; + ormConfig->setType("fragout"); + ormConfig->setName(getOutputTargetVarName(targ)); + ormConfig->setStructName("OUT"); } Var *detailBlend = (Var*)LangElement::find(String::ToString("detailBlend%d", compositeIndex)); @@ -1305,23 +1305,23 @@ void TerrainCompositeMapFeatHLSL::processPix(Vector &component if (priorComp) { meta->addStatement(new GenOp(" @ = @.rgb*@;\r\n", new DecOp(matinfoCol), texOp, detailBlend)); - meta->addStatement(new GenOp(" @.bga += @;\r\n", pbrConfig, matinfoCol)); + meta->addStatement(new GenOp(" @.gba += @;\r\n", ormConfig, matinfoCol)); } else { - meta->addStatement(new GenOp(" @ = lerp(float3(0,1,0),@.rgb,@);\r\n", new DecOp(matinfoCol), texOp, detailBlend)); - meta->addStatement(new GenOp(" @ = float4(0.0,@);\r\n", pbrConfig, matinfoCol)); + meta->addStatement(new GenOp(" @ = lerp(float3(1.0,1.0,0.0),@.rgb,@);\r\n", new DecOp(matinfoCol), texOp, detailBlend)); + meta->addStatement(new GenOp(" @ = float4(0.0,@);\r\n", ormConfig, matinfoCol)); } - if (!fd.features[MFT_InvertSmoothness]) + if (fd.features[MFT_InvertRoughness]) { - meta->addStatement(new GenOp(" @.b = 1.0-@.b;\r\n", pbrConfig, pbrConfig)); + meta->addStatement(new GenOp(" @.b = 1.0-@.b;\r\n", ormConfig, ormConfig)); } output = meta; } -ShaderFeature::Resources TerrainCompositeMapFeatHLSL::getResources(const MaterialFeatureData &fd) +ShaderFeature::Resources TerrainORMMapFeatHLSL::getResources(const MaterialFeatureData &fd) { Resources res; res.numTex = 1; @@ -1356,7 +1356,7 @@ void TerrainBlankInfoMapFeatHLSL::processPix(Vector &component material->setStructName("OUT"); } - meta->addStatement(new GenOp(" @ = float4(0.0,0.0,1.0,0);\r\n", material)); + meta->addStatement(new GenOp(" @ = float4(0.0,1.0,1.0,0.0);\r\n", material)); output = meta; } diff --git a/Engine/source/terrain/hlsl/terrFeatureHLSL.h b/Engine/source/terrain/hlsl/terrFeatureHLSL.h index d825512c8..e2b5fdb55 100644 --- a/Engine/source/terrain/hlsl/terrFeatureHLSL.h +++ b/Engine/source/terrain/hlsl/terrFeatureHLSL.h @@ -46,7 +46,7 @@ public: Var* _getInMacroCoord(Vector &componentList ); Var* _getNormalMapTex(); - Var* _getCompositeMapTex(); + Var* _getORMConfigMapTex(); static Var* _getUniformVar( const char *name, const char *type, ConstantSortPosition csp ); @@ -162,7 +162,7 @@ public: virtual String getName() { return "Terrain Additive"; } }; -class TerrainCompositeMapFeatHLSL : public TerrainFeatHLSL +class TerrainORMMapFeatHLSL : public TerrainFeatHLSL { public: diff --git a/Engine/source/terrain/terrCellMaterial.cpp b/Engine/source/terrain/terrCellMaterial.cpp index 8897601e7..e945fcc71 100644 --- a/Engine/source/terrain/terrCellMaterial.cpp +++ b/Engine/source/terrain/terrCellMaterial.cpp @@ -60,7 +60,7 @@ Vector _initSamplerNames() samplerNames.push_back(avar("$normalMap%d",i)); samplerNames.push_back(avar("$detailMap%d",i)); //samplerNames.push_back(avar("$macroMap%d", i)); - samplerNames.push_back(avar("$compositeMap%d", i)); + samplerNames.push_back(avar("$ormConfigMap%d", i)); } return samplerNames; @@ -151,9 +151,9 @@ void TerrainCellMaterial::_updateDefaultAnisotropy() desc.samplers[sampler].minFilter = GFXTextureFilterLinear; } - if (matInfo->compositeTexConst->isValid()) + if (matInfo->ormTexConst->isValid()) { - const S32 sampler = matInfo->compositeTexConst->getSamplerRegister(); + const S32 sampler = matInfo->ormTexConst->getSamplerRegister(); if (maxAnisotropy > 1) { @@ -439,15 +439,15 @@ bool TerrainCellMaterial::_createPass( Vector *materials, features.addFeature(MFT_isDeferred, featureIndex); features.addFeature( MFT_TerrainDetailMap, featureIndex ); - if (!(mat->getCompositeMap().isEmpty())) + if (!(mat->getORMConfigMap().isEmpty())) { if (deferredMat) features.addFeature(MFT_isDeferred, featureIndex); - features.addFeature(MFT_TerrainCompositeMap, featureIndex); + features.addFeature(MFT_TerrainORMMap, featureIndex); features.removeFeature(MFT_DeferredTerrainBlankInfoMap); } - if (mat->getInvertSmoothness()) - features.addFeature(MFT_InvertSmoothness); + if (mat->getInvertRoughness()) + features.addFeature(MFT_InvertRoughness); pass->materials.push_back( (*materials)[i] ); normalMaps.increment(); @@ -638,16 +638,16 @@ bool TerrainCellMaterial::_createPass( Vector *materials, &GFXStaticTextureProfile, "TerrainCellMaterial::_createPass() - DetailMap" ); } - matInfo->compositeTexConst = pass->shader->getShaderConstHandle(avar("$compositeMap%d", i)); - if (matInfo->compositeTexConst->isValid()) + matInfo->ormTexConst = pass->shader->getShaderConstHandle(avar("$ormConfigMap%d", i)); + if (matInfo->ormTexConst->isValid()) { GFXTextureProfile* profile = &GFXStaticTextureProfile; if (matInfo->mat->getIsSRGB()) profile = &GFXStaticTextureSRGBProfile; - matInfo->compositeTex.set(matInfo->mat->getCompositeMap(), + matInfo->ormTex.set(matInfo->mat->getORMConfigMap(), profile, "TerrainCellMaterial::_createPass() - CompositeMap"); - const S32 sampler = matInfo->compositeTexConst->getSamplerRegister(); + const S32 sampler = matInfo->ormTexConst->getSamplerRegister(); desc.samplers[sampler] = GFXSamplerStateDesc::getWrapLinear(); desc.samplers[sampler].magFilter = GFXTextureFilterLinear; @@ -859,8 +859,8 @@ bool TerrainCellMaterial::setupPass( const SceneRenderState *state, GFX->setTexture( matInfo->macroTexConst->getSamplerRegister(), matInfo->macroTex ); if ( matInfo->normalTexConst->isValid() ) GFX->setTexture( matInfo->normalTexConst->getSamplerRegister(), matInfo->normalTex ); - if ( matInfo->compositeTexConst->isValid() ) - GFX->setTexture( matInfo->compositeTexConst->getSamplerRegister(), matInfo->compositeTex ); + if ( matInfo->ormTexConst->isValid() ) + GFX->setTexture( matInfo->ormTexConst->getSamplerRegister(), matInfo->ormTex ); } pass.consts->setSafe( pass.layerSizeConst, (F32)mTerrain->mLayerTex.getWidth() ); diff --git a/Engine/source/terrain/terrCellMaterial.h b/Engine/source/terrain/terrCellMaterial.h index a635486ba..91d1f40e3 100644 --- a/Engine/source/terrain/terrCellMaterial.h +++ b/Engine/source/terrain/terrCellMaterial.h @@ -59,7 +59,7 @@ protected: MaterialInfo() :mat(NULL), layerId(0), detailTexConst(NULL), macroTexConst(NULL), normalTexConst(NULL), - compositeTexConst(NULL), detailInfoVConst(NULL), detailInfoPConst(NULL), macroInfoVConst(NULL), macroInfoPConst(NULL) + ormTexConst(NULL), detailInfoVConst(NULL), detailInfoPConst(NULL), macroInfoVConst(NULL), macroInfoPConst(NULL) { } @@ -79,8 +79,8 @@ protected: GFXShaderConstHandle *normalTexConst; GFXTexHandle normalTex; - GFXShaderConstHandle *compositeTexConst; - GFXTexHandle compositeTex; + GFXShaderConstHandle *ormTexConst; + GFXTexHandle ormTex; GFXShaderConstHandle *detailInfoVConst; GFXShaderConstHandle *detailInfoPConst; diff --git a/Engine/source/terrain/terrFeatureTypes.cpp b/Engine/source/terrain/terrFeatureTypes.cpp index 87ad84323..816414cce 100644 --- a/Engine/source/terrain/terrFeatureTypes.cpp +++ b/Engine/source/terrain/terrFeatureTypes.cpp @@ -36,4 +36,4 @@ ImplementFeatureType( MFT_TerrainSideProject, MFG_Texture, 106.0f, false ); ImplementFeatureType( MFT_TerrainAdditive, MFG_PostProcess, 999.0f, false ); //Deferred Shading ImplementFeatureType( MFT_DeferredTerrainBlankInfoMap, MFG_Texture, 104.1f, false); -ImplementFeatureType( MFT_TerrainCompositeMap, MFG_Texture, 104.2f, false); +ImplementFeatureType( MFT_TerrainORMMap, MFG_Texture, 104.2f, false); diff --git a/Engine/source/terrain/terrFeatureTypes.h b/Engine/source/terrain/terrFeatureTypes.h index 930d3fbc3..043e052cf 100644 --- a/Engine/source/terrain/terrFeatureTypes.h +++ b/Engine/source/terrain/terrFeatureTypes.h @@ -36,7 +36,7 @@ DeclareFeatureType( MFT_TerrainLightMap ); DeclareFeatureType( MFT_TerrainSideProject ); DeclareFeatureType( MFT_TerrainAdditive ); //Deferred Shading -DeclareFeatureType( MFT_TerrainCompositeMap ); +DeclareFeatureType( MFT_TerrainORMMap ); DeclareFeatureType( MFT_DeferredTerrainBlankInfoMap ); diff --git a/Engine/source/terrain/terrMaterial.cpp b/Engine/source/terrain/terrMaterial.cpp index 013fca3d0..74a0c51e0 100644 --- a/Engine/source/terrain/terrMaterial.cpp +++ b/Engine/source/terrain/terrMaterial.cpp @@ -69,7 +69,7 @@ TerrainMaterial::TerrainMaterial() mMacroDistance( 500.0f ), mParallaxScale( 0.0f ), mIsSRGB(false), - mInvertSmoothness(false) + mInvertRoughness(false) { initMapSlot(DiffuseMap); initMapSlot(NormalMap); diff --git a/Engine/source/terrain/terrMaterial.h b/Engine/source/terrain/terrMaterial.h index bbfe38063..94e8a180f 100644 --- a/Engine/source/terrain/terrMaterial.h +++ b/Engine/source/terrain/terrMaterial.h @@ -49,13 +49,10 @@ protected: F32 mDiffuseSize; /// - FileName mNormalMap; + DECLARE_TEXTUREMAP(NormalMap); /// - FileName mDetailMap; - - /// - FileName mCompositeMap; + DECLARE_TEXTUREMAP(DetailMap); /// The size of the detail map in meters used /// to generate the texture coordinates for the @@ -68,13 +65,19 @@ protected: /// F32 mDetailDistance; + /// + DECLARE_TEXTUREMAP(ORMConfigMap); + + bool mIsSRGB; + bool mInvertRoughness; + /// Normally the detail is projected on to the xy /// coordinates of the terrain. If this flag is true /// then this detail is projected along the xz and yz /// planes. bool mSideProjection; - FileName mMacroMap; + DECLARE_TEXTUREMAP(MacroMap); F32 mMacroSize; F32 mMacroStrength; F32 mMacroDistance; @@ -82,9 +85,6 @@ protected: /// F32 mParallaxScale; - bool mIsSRGB; - bool mInvertSmoothness; - public: TerrainMaterial(); @@ -124,7 +124,7 @@ public: bool getIsSRGB() const { return mIsSRGB; } - bool getInvertSmoothness() const { return mInvertSmoothness; } + bool getInvertRoughness() const { return mInvertRoughness; } }; diff --git a/Engine/source/ts/assimp/assimpAppMaterial.cpp b/Engine/source/ts/assimp/assimpAppMaterial.cpp index 979cf8318..64f49cd1a 100644 --- a/Engine/source/ts/assimp/assimpAppMaterial.cpp +++ b/Engine/source/ts/assimp/assimpAppMaterial.cpp @@ -195,8 +195,8 @@ void AssimpAppMaterial::initMaterial(const Torque::Path& path, Material* mat) co if (rmName.isNotEmpty()) { mat->mRoughMapFilename[0] = cleanTextureName(rmName, cleanFile, path, false); // Roughness - mat->mSmoothnessChan[0] = 1.0f; - mat->mInvertSmoothness[0] = (floatVal == 1.0f); + mat->mRoughnessChan[0] = 1.0f; + mat->mInvertRoughness[0] = (floatVal == 1.0f); mat->mMetalMapFilename[0] = cleanTextureName(rmName, cleanFile, path, false); // Metallic mat->mMetalChan[0] = 2.0f; } diff --git a/Engine/source/ts/collada/colladaAppMaterial.cpp b/Engine/source/ts/collada/colladaAppMaterial.cpp index 17c1ae492..40bbb9852 100644 --- a/Engine/source/ts/collada/colladaAppMaterial.cpp +++ b/Engine/source/ts/collada/colladaAppMaterial.cpp @@ -64,9 +64,8 @@ ColladaAppMaterial::ColladaAppMaterial(const char* matName) flags |= TSMaterialList::T_Wrap; diffuseColor = LinearColorF::ONE; - specularColor = LinearColorF::ONE; - smoothness = 0.0f; + roughness = 0.0f; metalness = 0.0f; doubleSided = false; } @@ -74,8 +73,7 @@ ColladaAppMaterial::ColladaAppMaterial(const char* matName) ColladaAppMaterial::ColladaAppMaterial(const domMaterial *pMat) : mat(pMat), diffuseColor(LinearColorF::ONE), - specularColor(LinearColorF::ONE), - smoothness(0.0f), + roughness(0.0f), metalness(0.0f), doubleSided(false) { @@ -100,37 +98,33 @@ ColladaAppMaterial::ColladaAppMaterial(const domMaterial *pMat) if (commonProfile->getTechnique()->getConstant()) { const domProfile_COMMON::domTechnique::domConstant* constant = commonProfile->getTechnique()->getConstant(); diffuseColor.set(1.0f, 1.0f, 1.0f, 1.0f); - resolveColor(constant->getReflective(), &specularColor); - resolveFloat(constant->getReflectivity(), &smoothness); + resolveFloat(constant->getReflectivity(), &metalness); resolveTransparency(constant, &transparency); } else if (commonProfile->getTechnique()->getLambert()) { const domProfile_COMMON::domTechnique::domLambert* lambert = commonProfile->getTechnique()->getLambert(); resolveColor(lambert->getDiffuse(), &diffuseColor); - resolveColor(lambert->getReflective(), &specularColor); - resolveFloat(lambert->getReflectivity(), &smoothness); + resolveFloat(lambert->getReflectivity(), &metalness); resolveTransparency(lambert, &transparency); } else if (commonProfile->getTechnique()->getPhong()) { const domProfile_COMMON::domTechnique::domPhong* phong = commonProfile->getTechnique()->getPhong(); resolveColor(phong->getDiffuse(), &diffuseColor); - resolveColor(phong->getSpecular(), &specularColor); - resolveFloat(phong->getShininess(), &metalness); + resolveFloat(phong->getShininess(), &roughness); resolveTransparency(phong, &transparency); } else if (commonProfile->getTechnique()->getBlinn()) { const domProfile_COMMON::domTechnique::domBlinn* blinn = commonProfile->getTechnique()->getBlinn(); resolveColor(blinn->getDiffuse(), &diffuseColor); - resolveColor(blinn->getSpecular(), &specularColor); - resolveFloat(blinn->getShininess(), &metalness); + resolveFloat(blinn->getShininess(), &roughness); resolveTransparency(blinn, &transparency); } // Normalize specularPower (1-128). Values > 1 are assumed to be // already normalized. - if (smoothness <= 1.0f) - smoothness *= 128; - smoothness = mClampF(smoothness, 1.0f, 128.0f); + if (roughness <= 1.0f) + roughness *= 128; + roughness = mClampF(roughness, 1.0f, 128.0f); // Set translucency if (transparency != 0.0f) { @@ -218,7 +212,7 @@ Material *ColladaAppMaterial::createMaterial(const Torque::Path& path) const newMat->mNormalMapFilename[0] = normalMap; newMat->mDiffuse[0] = diffuseColor; - newMat->mSmoothness[0] = smoothness; + newMat->mRoughness[0] = roughness; newMat->mMetalness[0] = metalness; newMat->mDoubleSided = doubleSided; diff --git a/Engine/source/ts/collada/colladaAppMaterial.h b/Engine/source/ts/collada/colladaAppMaterial.h index 624ecdee7..1e175675f 100644 --- a/Engine/source/ts/collada/colladaAppMaterial.h +++ b/Engine/source/ts/collada/colladaAppMaterial.h @@ -45,8 +45,7 @@ public: String normalMap; LinearColorF diffuseColor; - LinearColorF specularColor; - F32 smoothness; + F32 roughness; F32 metalness; bool doubleSided; diff --git a/Templates/BaseGame/game/core/rendering/shaders/brdf.hlsl b/Templates/BaseGame/game/core/rendering/shaders/brdf.hlsl index 050bf82c5..e18d1d0be 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/brdf.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/brdf.hlsl @@ -30,22 +30,15 @@ // Charles de Rousiers - Electronic Arts Frostbite // SIGGRAPH 2014 -float pow5(float x) { - float x2 = x * x; - return x2 * x2 * x; -} +// BRDF from Frostbite presentation: +// Moving Frostbite to Physically Based Rendering +// S“ebastien Lagarde - Electronic Arts Frostbite +// Charles de Rousiers - Electronic Arts Frostbite +// SIGGRAPH 2014 -float3 F_Schlick(in float3 f0, in float f90, in float u) +float3 F_Schlick(float3 f0, float f90, float u) { - return f0 + (f90 - f0) * pow5(1.f - u); -} - -float3 F_Fresnel(float3 SpecularColor, float VoH) -{ - float3 SpecularColorSqrt = sqrt(min(SpecularColor, float3(0.99, 0.99, 0.99))); - float3 n = (1 + SpecularColorSqrt) / (1 - SpecularColorSqrt); - float3 g = sqrt(n*n + VoH*VoH - 1); - return 0.5 * sqr((g - VoH) / (g + VoH)) * (1 + sqr(((g + VoH)*VoH - 1) / ((g - VoH)*VoH + 1))); + return f0 + (f90 - f0) * pow(1.f - u, 5.f); } float3 FresnelSchlickRoughness(float cosTheta, float3 F0, float roughness) @@ -61,57 +54,23 @@ float3 FresnelSchlickRoughness(float cosTheta, float3 F0, float roughness) return ret; } -float Fr_DisneyDiffuse(float NdotV, float NdotL, float LdotH, float linearRoughness) +float V_SmithGGXCorrelated(float NdotL, float NdotV, float alphaRoughnessSq) { - float energyBias = lerp(0, 0.5, linearRoughness); - float energyFactor = lerp(1.0, 1.0 / 1.51, linearRoughness); - float fd90 = energyBias + 2.0 * LdotH*LdotH * linearRoughness; - float3 f0 = float3(1.0f, 1.0f, 1.0f); - float lightScatter = F_Schlick(f0, fd90, NdotL).r; - float viewScatter = F_Schlick(f0, fd90, NdotV).r; + float GGXV = NdotL * sqrt(NdotV * NdotV * (1.0 - alphaRoughnessSq) + alphaRoughnessSq); + float GGXL = NdotV * sqrt(NdotL * NdotL * (1.0 - alphaRoughnessSq) + alphaRoughnessSq); - return lightScatter * viewScatter * energyFactor; + float GGX = GGXV + GGXL; + if (GGX > 0.0f) + { + return 0.5f / GGX; + } + return 0.f; } -float V_SmithGGXCorrelated(float NdotL, float NdotV, float roughness) +float D_GGX(float NdotH, float alphaRoughnessSq) { - // Original formulation of G_SmithGGX Correlated - // lambda_v = (-1 + sqrt(alphaG2 * (1 - NdotL2) / NdotL2 + 1)) * 0.5f; - // lambda_l = (-1 + sqrt(alphaG2 * (1 - NdotV2) / NdotV2 + 1)) * 0.5f; - // G_SmithGGXCorrelated = 1 / (1 + lambda_v + lambda_l); - // V_SmithGGXCorrelated = G_SmithGGXCorrelated / (4.0f * NdotL * NdotV); - - - // This is the optimized version - //float alphaG2 = alphaG * alphaG; - - // Caution: the "NdotL *" and "NdotV *" are explicitely inversed , this is not a mistake. - //float Lambda_GGXV = NdotL * sqrt((-NdotV * alphaG2 + NdotV) * NdotV + alphaG2); - //float Lambda_GGXL = NdotV * sqrt((-NdotL * alphaG2 + NdotL) * NdotL + alphaG2); - - //return 0.5f / (Lambda_GGXV + Lambda_GGXL); - - float a2 = roughness * roughness; - - float lambdaV = NdotL * sqrt((NdotV - a2 * NdotV) * NdotV + a2); - float lambdaL = NdotV * sqrt((NdotL - a2 * NdotL) * NdotL + a2); - float v = 0.5 / (lambdaV + lambdaL); - - return v; -} - -float D_GGX(float NdotH, float roughness) -{ - // Divide by PI is apply later - //float m2 = m * m; - //float f = (NdotH * m2 - NdotH) * NdotH + 1; - //return m2 / (f * f); - - float oneMinusNdotHSquared = 1.0 - NdotH * NdotH; - float a = NdotH * roughness; - float k = roughness / (oneMinusNdotHSquared + a * a); - float d = k * k * M_1OVER_PI_F; - return d; + float f = (NdotH * alphaRoughnessSq - NdotH) * NdotH + 1; + return alphaRoughnessSq / (M_PI_F * f * f); } #endif diff --git a/Templates/BaseGame/game/core/rendering/shaders/gl/brdf.glsl b/Templates/BaseGame/game/core/rendering/shaders/gl/brdf.glsl index b74fcc88c..dbe4d50ac 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/gl/brdf.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/gl/brdf.glsl @@ -30,22 +30,9 @@ // Charles de Rousiers - Electronic Arts Frostbite // SIGGRAPH 2014 -float pow5(float x) { - float x2 = x * x; - return x2 * x2 * x; -} - -vec3 F_Schlick(in vec3 f0, in float f90, in float u) +vec3 F_Schlick(vec3 f0, float f90, float u) { - return f0 + (f90 - f0) * pow5(1.f - u); -} - -vec3 F_Fresnel(vec3 SpecularColor, float VoH) -{ - vec3 SpecularColorSqrt = sqrt(min(SpecularColor, vec3(0.99, 0.99, 0.99))); - vec3 n = (1 + SpecularColorSqrt) / (1 - SpecularColorSqrt); - vec3 g = sqrt(n*n + VoH*VoH - 1); - return 0.5 * sqr((g - VoH) / (g + VoH)) * (1 + sqr(((g + VoH)*VoH - 1) / ((g - VoH)*VoH + 1))); + return f0 + (f90 - f0) * pow(1.f - u, 5.f); } vec3 FresnelSchlickRoughness(float cosTheta, vec3 F0, float roughness) @@ -61,48 +48,23 @@ vec3 FresnelSchlickRoughness(float cosTheta, vec3 F0, float roughness) return ret; } -float Fr_DisneyDiffuse(float NdotV, float NdotL, float LdotH, float linearRoughness) +float V_SmithGGXCorrelated(float NdotL, float NdotV, float alphaRoughnessSq) { - float energyBias = lerp(0.0f, 0.5f, linearRoughness); - float energyFactor = lerp(1.0f, 1.0f / 1.51f, linearRoughness); - float fd90 = energyBias + 2.0 * LdotH*LdotH * linearRoughness; - vec3 f0 = vec3(1.0f, 1.0f, 1.0f); - float lightScatter = F_Schlick(f0, fd90, NdotL).r; - float viewScatter = F_Schlick(f0, fd90, NdotV).r; + float GGXV = NdotL * sqrt(NdotV * NdotV * (1.0 - alphaRoughnessSq) + alphaRoughnessSq); + float GGXL = NdotV * sqrt(NdotL * NdotL * (1.0 - alphaRoughnessSq) + alphaRoughnessSq); - return lightScatter * viewScatter * energyFactor; + float GGX = GGXV + GGXL; + if (GGX > 0.0f) + { + return 0.5f / GGX; + } + return 0.f; } -float V_SmithGGXCorrelated(float NdotL, float NdotV, float roughness) +float D_GGX(float NdotH, float alphaRoughnessSq) { - // Original formulation of G_SmithGGX Correlated - // lambda_v = (-1 + sqrt(alphaG2 * (1 - NdotL2) / NdotL2 + 1)) * 0.5f; - // lambda_l = (-1 + sqrt(alphaG2 * (1 - NdotV2) / NdotV2 + 1)) * 0.5f; - // G_SmithGGXCorrelated = 1 / (1 + lambda_v + lambda_l); - // V_SmithGGXCorrelated = G_SmithGGXCorrelated / (4.0f * NdotL * NdotV); - - - // This is the optimized version - //float alphaG2 = alphaG * alphaG; - - float a2 = roughness * roughness; - - float lambdaV = NdotL * sqrt((NdotV - a2 * NdotV) * NdotV + a2); - float lambdaL = NdotV * sqrt((NdotL - a2 * NdotL) * NdotL + a2); - float v = 0.5f / (lambdaV + lambdaL); - - return v; -} - -float D_GGX(float NdotH, float roughness) -{ - // Divide by PI is apply later - - float oneMinusNdotHSquared = 1.0 - NdotH * NdotH; - float a = NdotH * roughness; - float k = roughness / (oneMinusNdotHSquared + a * a); - float d = k * k * M_1OVER_PI_F; - return d; + float f = (NdotH * alphaRoughnessSq - NdotH) * NdotH + 1; + return alphaRoughnessSq / (M_PI_F * f * f); } #endif diff --git a/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl b/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl index 7412245ce..cb12b1767 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl @@ -22,23 +22,24 @@ #include "./torque.glsl" #include "./brdf.glsl" +#include "./shaderModelAutoGen.glsl" + #ifndef TORQUE_SHADERGEN #line 26 // These are the uniforms used by most lighting shaders. -uniform vec4 inLightPos[3]; -uniform vec4 inLightInvRadiusSq; +uniform vec4 inLightPos[4]; +uniform vec4 inLightConfigData[4]; uniform vec4 inLightColor[4]; #ifndef TORQUE_BL_NOSPOTLIGHT - uniform vec4 inLightSpotDir[3]; + uniform vec4 inLightSpotDir[4]; uniform vec4 inLightSpotAngle; uniform vec4 inLightSpotFalloff; #endif uniform vec4 ambient; -#define ambientCameraFactor 0.3 -uniform float smoothness; +uniform float roughness; uniform float metalness; uniform vec4 albedo; @@ -73,48 +74,53 @@ struct Surface vec3 V; // world space view vector vec4 baseColor; // base color [0 -> 1] (rgba) float metalness; // metalness [0:dielectric -> 1:metal] - float roughness; // roughness: [0:smooth -> 1:rough] (linear) - float roughness_brdf; // roughness remapped from linear to BRDF + float roughness; // material roughness: [0:smooth -> 1:rough] + float linearRoughness; // linear roughness (roughness^2) + float linearRoughnessSq; // (linearRoughness^2) float depth; // depth: [0:near -> 1:far] (linear) float ao; // ambient occlusion [0 -> 1] float matFlag; // material flag - use getFlag to retreive float NdotV; // cos(angle between normal and view vector) vec3 f0; // fresnel value (rgb) - float f90; vec3 albedo; // diffuse light absorbtion value (rgb) vec3 R; // reflection vector vec3 F; // fresnel term computed from f0, N and V + float f90; + }; void updateSurface(inout Surface surface) { surface.NdotV = abs(dot(surface.N, surface.V)) + 1e-5f; // avoid artifact - surface.albedo = surface.baseColor.rgb * (1.0 - surface.metalness); - surface.f0 = lerp(vec3(0.04f), surface.baseColor.rgb, surface.metalness); + surface.linearRoughness = surface.roughness * surface.roughness; + surface.linearRoughnessSq = surface.linearRoughness * surface.linearRoughness; + + surface.albedo = surface.baseColor.rgb * (1.0f - surface.metalness); + surface.f0 = mix(0.04f, surface.baseColor.rgb, surface.metalness); + surface.R = -reflect(surface.V, surface.N); surface.f90 = saturate(50.0 * dot(surface.f0, vec3(0.33,0.33,0.33))); surface.F = F_Schlick(surface.f0, surface.f90, surface.NdotV); } -Surface createSurface(vec4 normDepth, sampler2D colorBuffer, sampler2D matInfoBuffer, in vec2 uv, in vec3 wsEyePos, in vec3 wsEyeRay, in mat4 invView) +Surface createSurface(vec4 gbuffer0, sampler2D gbufferTex1, sampler2D gbufferTex2, in vec2 uv, in vec3 wsEyePos, in vec3 wsEyeRay, in mat4 invView) { Surface surface;// = Surface(); - vec4 gbuffer1 = texture(colorBuffer, uv); - vec4 gbuffer2 = texture(matInfoBuffer, uv); - surface.depth = normDepth.a; + vec4 gbuffer1 = texture(gbufferTex1, uv); + vec4 gbuffer2 = texture(gbufferTex2, uv); + surface.depth = gbuffer0.a; surface.P = wsEyePos + wsEyeRay * surface.depth; - surface.N = tMul(invView, vec4(normDepth.xyz,0)).xyz; + surface.N = tMul(invView, vec4(gbuffer0.xyz,0)).xyz; surface.V = normalize(wsEyePos - surface.P); surface.baseColor = gbuffer1; - const float minRoughness=1e-4; - surface.roughness = 1.0 - (gbuffer2.b*0.8+0.1999); //t3d uses smoothness, so we convert to roughness. - surface.roughness_brdf = surface.roughness * surface.roughness; + surface.roughness = clamp(gbuffer2.b, 0.01f, 1.0f); surface.metalness = gbuffer2.a; surface.ao = gbuffer2.g; surface.matFlag = gbuffer2.r; + updateSurface(surface); return surface; } @@ -128,9 +134,7 @@ Surface createForwardSurface(vec4 baseColor, vec3 normal, vec4 pbrProperties, in surface.N = normal; surface.V = normalize(wsEyePos - surface.P); surface.baseColor = baseColor; - const float minRoughness=1e-4; - surface.roughness = 1.0 - (pbrProperties.b*0.8+0.1999); //t3d uses smoothness, so we convert to roughness. - surface.roughness_brdf = surface.roughness * surface.roughness; + surface.roughness = clamp(pbrProperties.b, 0.01f, 1.0f); surface.metalness = pbrProperties.a; surface.ao = pbrProperties.g; surface.matFlag = pbrProperties.r; @@ -166,16 +170,15 @@ vec3 BRDF_GetDebugSpecular(in Surface surface, in SurfaceToLight surfaceToLight) { //GGX specular vec3 F = F_Schlick(surface.f0, surface.f90, surfaceToLight.HdotV); - float Vis = V_SmithGGXCorrelated(surface.NdotV, surfaceToLight.NdotL, surface.roughness); - float D = D_GGX(surfaceToLight.NdotH, surface.roughness); - vec3 Fr = D * F * Vis; - return Fr*M_1OVER_PI_F; + float Vis = V_SmithGGXCorrelated(surface.NdotV, surfaceToLight.NdotL, surface.linearRoughnessSq); + float D = D_GGX(surfaceToLight.NdotH, surface.linearRoughnessSq); + vec3 Fr = D * F * Vis * M_1OVER_PI_F; + return Fr; } vec3 BRDF_GetDebugDiffuse(in Surface surface, in SurfaceToLight surfaceToLight) { - vec3 Fd = surface.albedo.rgb; - return Fd*M_1OVER_PI_F; + return surface.albedo.rgb * M_1OVER_PI_F; } //attenuations functions from "moving frostbite to pbr paper" @@ -206,15 +209,15 @@ float getDistanceAtt( vec3 unormalizedLightVector , float invSqrAttRadius ) vec3 evaluateStandardBRDF(Surface surface, SurfaceToLight surfaceToLight) { //lambert diffuse - vec3 Fd = surface.albedo.rgb; + vec3 Fd = surface.albedo.rgb * M_1OVER_PI_F; //GGX specular vec3 F = F_Schlick(surface.f0, surface.f90, surfaceToLight.HdotV); - float Vis = V_SmithGGXCorrelated(surface.NdotV, surfaceToLight.NdotL, surface.roughness); - float D = D_GGX(surfaceToLight.NdotH, surface.roughness); + float Vis = V_SmithGGXCorrelated(surface.NdotV, surfaceToLight.NdotL, surface.linearRoughnessSq); + float D = D_GGX(surfaceToLight.NdotH, surface.linearRoughnessSq); vec3 Fr = D * F * Vis; - return (Fd + Fr) * M_1OVER_PI_F; + return Fd + Fr; } vec3 getDirectionalLight(Surface surface, SurfaceToLight surfaceToLight, vec3 lightColor, float lightIntensity, float shadow) @@ -235,6 +238,11 @@ float computeSpecOcclusion( float NdotV , float AO , float roughness ) return saturate (pow( abs(NdotV + AO) , exp2 ( -16.0f * roughness - 1.0f )) - 1.0f + AO ); } +float roughnessToMipLevel(float roughness, float numMips) +{ + return roughness * numMips; +} + vec4 compute4Lights( Surface surface, vec4 shadowMask, vec4 inLightPos[4], @@ -340,7 +348,7 @@ vec3 boxProject(vec3 wsPosition, vec3 wsReflectVec, mat4 worldToObj, vec3 refBox } vec4 computeForwardProbes(Surface surface, - float cubeMips, float numProbes, mat4x4 worldToObjArray[MAX_FORWARD_PROBES], vec4 probeConfigData[MAX_FORWARD_PROBES], + float cubeMips, int numProbes, mat4x4 worldToObjArray[MAX_FORWARD_PROBES], vec4 probeConfigData[MAX_FORWARD_PROBES], vec4 inProbePosArray[MAX_FORWARD_PROBES], vec4 refBoxMinArray[MAX_FORWARD_PROBES], vec4 refBoxMaxArray[MAX_FORWARD_PROBES], vec4 inRefPosArray[MAX_FORWARD_PROBES], float skylightCubemapIdx, sampler2D BRDFTexture, samplerCubeArray irradianceCubemapAR, samplerCubeArray specularCubemapAR) @@ -401,11 +409,43 @@ vec4 computeForwardProbes(Surface surface, } } +#if DEBUGVIZ_ATTENUATION == 1 + float contribAlpha = 1; + for (i = 0; i < numProbes; ++i) + { + contribAlpha -= contribution[i]; + } + + return vec4(1 - contribAlpha, 1 - contribAlpha, 1 - contribAlpha, 1); +#endif + +#if DEBUGVIZ_CONTRIB == 1 + vec3 probeContribColors[4]; + probeContribColors[0] = vec3(1,0,0); + probeContribColors[1] = vec3(0,1,0); + probeContribColors[2] = vec3(0,0,1); + probeContribColors[3] = vec3(1,1,0); + + vec3 finalContribColor = vec3(0, 0, 0); + float contribAlpha = 1; + for (i = 0; i < numProbes; ++i) + { + finalContribColor += contribution[i] *probeContribColors[i].rgb; + contribAlpha -= contribution[i]; + } + + //Skylight coloration for anything not covered by probes above + if(skylightCubemapIdx != -1) + finalContribColor += vec3(0.3, 0.3, 0.3) * contribAlpha; + + return vec4(finalContribColor, 1); +#endif + vec3 irradiance = vec3(0, 0, 0); vec3 specular = vec3(0, 0, 0); // Radiance (Specular) - float lod = surface.roughness*cubeMips; + float lod = roughnessToMipLevel(surface.roughness, cubeMips); for (i = 0; i < numProbes; ++i) { @@ -428,17 +468,182 @@ vec4 computeForwardProbes(Surface surface, } //energy conservation - vec3 kD = 1.0f - surface.F; + vec3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness); + vec3 kD = 1.0f - F; kD *= 1.0f - surface.metalness; float dfgNdotV = max( surface.NdotV , 0.0009765625f ); //0.5f/512.0f (512 is size of dfg/brdf lookup tex) - vec2 envBRDF = textureLod(BRDFTexture, vec2(dfgNdotV, surface.roughness),0).rg; - specular *= surface.F * envBRDF.x + surface.f90 * envBRDF.y; + vec2 envBRDF = texture(BRDFTexture, vec4(dfgNdotV, surface.roughness,0,0)).rg; + specular *= F * envBRDF.x + surface.f90 * envBRDF.y; irradiance *= kD * surface.baseColor.rgb; //AO irradiance *= surface.ao; specular *= computeSpecOcclusion(surface.NdotV, surface.ao, surface.roughness); - return vec4(irradiance + specular, 0);//alpha writes disabled + //http://marmosetco.tumblr.com/post/81245981087 + float horizonOcclusion = 1.3; + float horizon = saturate( 1 + horizonOcclusion * dot(surface.R, surface.N)); + horizon *= horizon; + + return vec4((irradiance + specular) * horizon, 0);//alpha writes disabled } + +vec4 debugVizForwardProbes(Surface surface, + float cubeMips, int numProbes, mat4 worldToObjArray[MAX_FORWARD_PROBES], vec4 probeConfigData[MAX_FORWARD_PROBES], + vec4 inProbePosArray[MAX_FORWARD_PROBES], vec4 refBoxMinArray[MAX_FORWARD_PROBES], vec4 refBoxMaxArray[MAX_FORWARD_PROBES], vec4 inRefPosArray[MAX_FORWARD_PROBES], + float skylightCubemapIdx, sampler2D(BRDFTexture), + samplerCubeArray irradianceCubemapAR, samplerCubeArray specularCubemapAR, int showAtten, int showContrib, int showSpec, int showDiff) +{ + int i = 0; + float alpha = 1; + float blendFactor[MAX_FORWARD_PROBES]; + float blendSum = 0; + float blendFacSum = 0; + float invBlendSum = 0; + float probehits = 0; + //Set up our struct data + float contribution[MAX_FORWARD_PROBES]; + for (i = 0; i < numProbes; ++i) + { + contribution[i] = 0; + + if (probeConfigData[i].r == 0) //box + { + contribution[i] = defineBoxSpaceInfluence(surface.P, worldToObjArray[i], probeConfigData[i].b); + if (contribution[i] > 0.0) + probehits++; + } + else if (probeConfigData[i].r == 1) //sphere + { + contribution[i] = defineSphereSpaceInfluence(surface.P, inProbePosArray[i].xyz, probeConfigData[i].g); + if (contribution[i] > 0.0) + probehits++; + } + + contribution[i] = max(contribution[i], 0); + + blendSum += contribution[i]; + invBlendSum += (1.0f - contribution[i]); + } + + if (probehits > 1.0) + { + for (i = 0; i < numProbes; i++) + { + blendFactor[i] = ((contribution[i] / blendSum)) / probehits; + blendFactor[i] *= ((contribution[i]) / invBlendSum); + blendFactor[i] = saturate(blendFactor[i]); + blendFacSum += blendFactor[i]; + } + + // Normalize blendVal + if (blendFacSum == 0.0f) // Possible with custom weight + { + blendFacSum = 1.0f; + } + + float invBlendSumWeighted = 1.0f / blendFacSum; + for (i = 0; i < numProbes; ++i) + { + blendFactor[i] *= invBlendSumWeighted; + contribution[i] *= blendFactor[i]; + } + } + + if(showAtten == 1) + { + float contribAlpha = 1; + for (i = 0; i < numProbes; ++i) + { + contribAlpha -= contribution[i]; + } + + return vec4(1 - contribAlpha, 1 - contribAlpha, 1 - contribAlpha, 1); + } + + if(showContrib == 1) + { + vec3 probeContribColors[4]; + probeContribColors[0] = vec3(1,0,0); + probeContribColors[1] = vec3(0,1,0); + probeContribColors[2] = vec3(0,0,1); + probeContribColors[3] = vec3(1,1,0); + + vec3 finalContribColor = vec3(0, 0, 0); + float contribAlpha = 1; + for (i = 0; i < numProbes; ++i) + { + finalContribColor += contribution[i] *probeContribColors[i].rgb; + contribAlpha -= contribution[i]; + } + + //Skylight coloration for anything not covered by probes above + if(skylightCubemapIdx != -1) + finalContribColor += vec3(0.3, 0.3, 0.3) * contribAlpha; + + return vec4(finalContribColor, 1); + } + + vec3 irradiance = vec3(0, 0, 0); + vec3 specular = vec3(0, 0, 0); + + // Radiance (Specular) + float lod = roughnessToMipLevel(surface.roughness, cubeMips); + + if(showSpec == 1) + { + lod = 0; + } + + for (i = 0; i < numProbes; ++i) + { + float contrib = contribution[i]; + if (contrib > 0.0f) + { + int cubemapIdx = probeConfigData[i].a; + vec3 dir = boxProject(surface.P, surface.R, worldToObjArray[i], refBoxMinArray[i].xyz, refBoxMaxArray[i].xyz, inRefPosArray[i].xyz); + + irradiance += textureLod(irradianceCubemapAR, dir, cubemapIdx, 0).xyz * contrib; + specular += textureLod(specularCubemapAR, dir, cubemapIdx, lod).xyz * contrib; + alpha -= contrib; + } + } + + if(skylightCubemapIdx != -1 && alpha >= 0.001) + { + irradiance = mix(irradiance,textureLod(irradianceCubemapAR, surface.R, skylightCubemapIdx, 0).xyz,alpha); + specular = mix(specular,textureLod(specularCubemapAR, surface.R, skylightCubemapIdx, lod).xyz,alpha); + } + + if(showSpec == 1) + { + return vec4(specular, 0); + } + + if(showDiff == 1) + { + return vec4(irradiance, 0); + } + + //energy conservation + vec3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness); + vec3 kD = 1.0f - F; + kD *= 1.0f - surface.metalness; + + float dfgNdotV = max( surface.NdotV , 0.0009765625f ); //0.5f/512.0f (512 is size of dfg/brdf lookup tex) + vec2 envBRDF = textureLod(BRDFTexture, vec2(dfgNdotV, surface.roughness),0).rg; + specular *= F * envBRDF.x + surface.f90 * envBRDF.y; + irradiance *= kD * surface.baseColor.rgb; + + //AO + irradiance *= surface.ao; + specular *= computeSpecOcclusion(surface.NdotV, surface.ao, surface.roughness); + + //http://marmosetco.tumblr.com/post/81245981087 + float horizonOcclusion = 1.3; + float horizon = saturate( 1 + horizonOcclusion * dot(surface.R, surface.N)); + horizon *= horizon; + + return vec4((irradiance + specular) * horizon, 0);//alpha writes disabled +} \ No newline at end of file diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl index 9d7d4c19b..25b1212d8 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl @@ -39,7 +39,7 @@ uniform float4 inLightColor[4]; #endif uniform float4 ambient; -uniform float smoothness; +uniform float roughness; uniform float metalness; uniform float4 albedo; @@ -74,8 +74,9 @@ struct Surface float3 V; // world space view vector float4 baseColor; // base color [0 -> 1] (rgba) float metalness; // metalness [0:dielectric -> 1:metal] - float roughness; // roughness: [0:smooth -> 1:rough] (linear) - float roughness_brdf; // roughness remapped from linear to BRDF + float roughness; // material roughness: [0:smooth -> 1:rough] + float linearRoughness; // linear roughness (roughness^2) + float linearRoughnessSq; // (linearRoughness^2) float depth; // depth: [0:near -> 1:far] (linear) float ao; // ambient occlusion [0 -> 1] float matFlag; // material flag - use getFlag to retreive @@ -90,18 +91,19 @@ struct Surface inline void Update() { NdotV = abs(dot(N, V)) + 1e-5f; // avoid artifact + + linearRoughness = roughness * roughness; + linearRoughnessSq = linearRoughness * linearRoughness; - albedo = baseColor.rgb * (1.0 - metalness); - f0 = lerp(0.04.xxx, baseColor.rgb, metalness); + albedo = baseColor.rgb * (1.0f - metalness); + f0 = lerp(0.04f, baseColor.rgb, metalness); R = -reflect(V, N); - f90 = saturate(50.0 * dot(f0, 0.33)); + f90 = saturate(50.0f * dot(f0, 0.33f)); F = F_Schlick(f0, f90, NdotV); } }; - - inline Surface createSurface(float4 gbuffer0, TORQUE_SAMPLER2D(gbufferTex1), TORQUE_SAMPLER2D(gbufferTex2), in float2 uv, in float3 wsEyePos, in float3 wsEyeRay, in float4x4 invView) { Surface surface = (Surface)0; @@ -114,8 +116,7 @@ inline Surface createSurface(float4 gbuffer0, TORQUE_SAMPLER2D(gbufferTex1), TOR surface.N = mul(invView, float4(gbuffer0.xyz,0)).xyz; surface.V = normalize(wsEyePos - surface.P); surface.baseColor = gbuffer1; - surface.roughness = 1.0 - (gbuffer2.b*0.8+0.1999); //t3d uses smoothness, so we convert to roughness. - surface.roughness_brdf = surface.roughness * surface.roughness; + surface.roughness = clamp(gbuffer2.b, 0.01f, 1.0f); surface.metalness = gbuffer2.a; surface.ao = gbuffer2.g; surface.matFlag = gbuffer2.r; @@ -133,8 +134,7 @@ inline Surface createForwardSurface(float4 baseColor, float3 normal, float4 pbrP surface.N = normal; surface.V = normalize(wsEyePos - surface.P); surface.baseColor = baseColor; - surface.roughness = 1.0 - (pbrProperties.b*0.8+0.1999); //t3d uses smoothness, so we convert to roughness. - surface.roughness_brdf = surface.roughness * surface.roughness; + surface.roughness = clamp(pbrProperties.b, 0.01f, 1.0f); surface.metalness = pbrProperties.a; surface.ao = pbrProperties.g; surface.matFlag = pbrProperties.r; @@ -146,7 +146,7 @@ inline Surface createForwardSurface(float4 baseColor, float3 normal, float4 pbrP struct SurfaceToLight { float3 L; // surface to light vector - float3 Lu; // un-normalized surface to light vector + float3 Lu; // un-normalized surface to light vector float3 H; // half-vector between view vector and light vector float NdotL; // cos(angle between N and L) float HdotV; // cos(angle between H and V) = HdotL = cos(angle between H and L) @@ -170,16 +170,15 @@ float3 BRDF_GetDebugSpecular(in Surface surface, in SurfaceToLight surfaceToLigh { //GGX specular float3 F = F_Schlick(surface.f0, surface.f90, surfaceToLight.HdotV); - float Vis = V_SmithGGXCorrelated(surface.NdotV, surfaceToLight.NdotL, surface.roughness); - float D = D_GGX(surfaceToLight.NdotH, surface.roughness); - float3 Fr = D * F * Vis; - return Fr*M_1OVER_PI_F; + float Vis = V_SmithGGXCorrelated(surface.NdotV, surfaceToLight.NdotL, surface.linearRoughnessSq); + float D = D_GGX(surfaceToLight.NdotH, surface.linearRoughnessSq); + float3 Fr = D * F * Vis * M_1OVER_PI_F; + return Fr; } float3 BRDF_GetDebugDiffuse(in Surface surface, in SurfaceToLight surfaceToLight) { - float3 Fd = surface.albedo.rgb; - return Fd*M_1OVER_PI_F; + return surface.albedo.rgb * M_1OVER_PI_F; } //attenuations functions from "moving frostbite to pbr paper" @@ -210,15 +209,15 @@ float getDistanceAtt( float3 unormalizedLightVector , float invSqrAttRadius ) float3 evaluateStandardBRDF(Surface surface, SurfaceToLight surfaceToLight) { //lambert diffuse - float3 Fd = surface.albedo.rgb; + float3 Fd = surface.albedo.rgb * M_1OVER_PI_F; //GGX specular float3 F = F_Schlick(surface.f0, surface.f90, surfaceToLight.HdotV); - float Vis = V_SmithGGXCorrelated(surface.NdotV, surfaceToLight.NdotL, surface.roughness); - float D = D_GGX(surfaceToLight.NdotH, surface.roughness); + float Vis = V_SmithGGXCorrelated(surface.NdotV, surfaceToLight.NdotL, surface.linearRoughnessSq); + float D = D_GGX(surfaceToLight.NdotH, surface.linearRoughnessSq); float3 Fr = D * F * Vis; - return (Fd + Fr) * M_1OVER_PI_F; + return Fd + Fr; } float3 getDirectionalLight(Surface surface, SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity, float shadow) @@ -234,12 +233,16 @@ float3 getPunctualLight(Surface surface, SurfaceToLight surfaceToLight, float3 l return evaluateStandardBRDF(surface,surfaceToLight) * factor; } - float computeSpecOcclusion( float NdotV , float AO , float roughness ) { return saturate (pow( abs(NdotV + AO) , exp2 ( -16.0f * roughness - 1.0f )) - 1.0f + AO ); } +float roughnessToMipLevel(float roughness, float numMips) +{ + return roughness * numMips; +} + float4 compute4Lights( Surface surface, float4 shadowMask, float4 inLightPos[4], @@ -445,7 +448,7 @@ float4 computeForwardProbes(Surface surface, float3 specular = float3(0, 0, 0); // Radiance (Specular) - float lod = surface.roughness*cubeMips; + float lod = roughnessToMipLevel(surface.roughness, cubeMips); for (i = 0; i < numProbes; ++i) { @@ -468,19 +471,25 @@ float4 computeForwardProbes(Surface surface, } //energy conservation - float3 kD = 1.0f - surface.F; + float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness); + float3 kD = 1.0f - F; kD *= 1.0f - surface.metalness; float dfgNdotV = max( surface.NdotV , 0.0009765625f ); //0.5f/512.0f (512 is size of dfg/brdf lookup tex) float2 envBRDF = TORQUE_TEX2DLOD(BRDFTexture, float4(dfgNdotV, surface.roughness,0,0)).rg; - specular *= surface.F * envBRDF.x + surface.f90 * envBRDF.y; + specular *= F * envBRDF.x + surface.f90 * envBRDF.y; irradiance *= kD * surface.baseColor.rgb; //AO irradiance *= surface.ao; specular *= computeSpecOcclusion(surface.NdotV, surface.ao, surface.roughness); - return float4(irradiance + specular, 0);//alpha writes disabled + //http://marmosetco.tumblr.com/post/81245981087 + float horizonOcclusion = 1.3; + float horizon = saturate( 1 + horizonOcclusion * dot(surface.R, surface.N)); + horizon *= horizon; + + return float4((irradiance + specular) * horizon, 0);//alpha writes disabled } float4 debugVizForwardProbes(Surface surface, @@ -583,7 +592,7 @@ float4 debugVizForwardProbes(Surface surface, float3 specular = float3(0, 0, 0); // Radiance (Specular) - float lod = surface.roughness*cubeMips; + float lod = roughnessToMipLevel(surface.roughness, cubeMips); if(showSpec == 1) { @@ -621,17 +630,23 @@ float4 debugVizForwardProbes(Surface surface, } //energy conservation - float3 kD = 1.0f - surface.F; + float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness); + float3 kD = 1.0f - F; kD *= 1.0f - surface.metalness; float dfgNdotV = max( surface.NdotV , 0.0009765625f ); //0.5f/512.0f (512 is size of dfg/brdf lookup tex) float2 envBRDF = TORQUE_TEX2DLOD(BRDFTexture, float4(dfgNdotV, surface.roughness,0,0)).rg; - specular *= surface.F * envBRDF.x + surface.f90 * envBRDF.y; + specular *= F * envBRDF.x + surface.f90 * envBRDF.y; irradiance *= kD * surface.baseColor.rgb; //AO irradiance *= surface.ao; specular *= computeSpecOcclusion(surface.NdotV, surface.ao, surface.roughness); - return float4(irradiance + specular, 0);//alpha writes disabled + //http://marmosetco.tumblr.com/post/81245981087 + float horizonOcclusion = 1.3; + float horizon = saturate( 1 + horizonOcclusion * dot(surface.R, surface.N)); + horizon *= horizon; + + return float4((irradiance + specular) * horizon, 0);//alpha writes disabled } \ No newline at end of file diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl index 5c7d74ffb..a633791c4 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl @@ -3,6 +3,7 @@ #include "../../../gl/torque.glsl" #include "shadergen:/autogenConditioners.h" #include "../../../gl/lighting.glsl" +#include "../../../gl/brdf.glsl" #line 7 @@ -55,11 +56,11 @@ void main() //early out if emissive if (getFlag(surface.matFlag, 0)) { - discard; + return texture(colorBuffer, IN_uv0.xy); } #ifdef USE_SSAO_MASK - float ssao = 1.0 - texture( ssaoMask, viewportCoordToRenderTarget( uv0.xy, rtParams6 ) ).r; + float ssao = 1.0 - texture( ssaoMask, viewportCoordToRenderTarget( IN_uv0.xy, rtParams6 ) ).r; surface.ao = min(surface.ao, ssao); #endif @@ -166,7 +167,7 @@ void main() // Radiance (Specular) #if DEBUGVIZ_SPECCUBEMAP == 0 - float lod = surface.roughness*cubeMips; + float lod = roughnessToMipLevel(surface.roughness, cubeMips); #elif DEBUGVIZ_SPECCUBEMAP == 1 float lod = 0; #endif @@ -177,7 +178,7 @@ void main() float contrib = contribution[i]; if (contrib > 0.0f) { - float cubemapIdx = probeConfigData[i].a; + int cubemapIdx = probeConfigData[i].a; vec3 dir = boxProject(surface.P, surface.R, worldToObjArray[i], refBoxMinArray[i].xyz, refBoxMaxArray[i].xyz, inRefPosArray[i].xyz); irradiance += textureLod(irradianceCubemapAR, vec4(dir, cubemapIdx), 0).xyz * contrib; @@ -189,8 +190,8 @@ void main() if (skylightCubemapIdx != -1 && alpha > 0.001) { - irradiance += textureLod(irradianceCubemapAR, vec4(surface.R, skylightCubemapIdx), 0).xyz * alpha; - specular += textureLod(specularCubemapAR, vec4(surface.R, skylightCubemapIdx), lod).xyz * alpha; + irradiance = lerp(irradiance,textureLod(irradianceCubemapAR, surface.R, skylightCubemapIdx, 0).xyz,alpha); + specular = lerp(specular,textureLod(specularCubemapAR, surface.R, skylightCubemapIdx, lod).xyz,alpha); } #if DEBUGVIZ_SPECCUBEMAP == 1 && DEBUGVIZ_DIFFCUBEMAP == 0 @@ -203,17 +204,23 @@ void main() //energy conservation - vec3 kD = 1.0f - surface.F; + vec3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness); + vec3 kD = 1.0f - F; kD *= 1.0f - surface.metalness; float dfgNdotV = max( surface.NdotV , 0.0009765625f ); //0.5f/512.0f (512 is size of dfg/brdf lookup tex) vec2 envBRDF = textureLod(BRDFTexture, vec2(dfgNdotV, surface.roughness),0).rg; - specular *= surface.F * envBRDF.x + surface.f90 * envBRDF.y; + specular *= F * envBRDF.x + surface.f90 * envBRDF.y; irradiance *= kD * surface.baseColor.rgb; //AO irradiance *= surface.ao; specular *= computeSpecOcclusion(surface.NdotV, surface.ao, surface.roughness); + //http://marmosetco.tumblr.com/post/81245981087 + float horizonOcclusion = 1.3; + float horizon = saturate( 1 + horizonOcclusion * dot(surface.R, surface.N)); + horizon *= horizon; + OUT_col = vec4(irradiance + specular, 0);//alpha writes disabled } diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl index 746c8f1ce..e2345e5df 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl @@ -2,6 +2,7 @@ #include "../../shaderModel.hlsl" #include "../../shaderModelAutoGen.hlsl" #include "../../lighting.hlsl" +#include "../../brdf.hlsl" TORQUE_UNIFORM_SAMPLER2D(deferredBuffer, 0); TORQUE_UNIFORM_SAMPLER2D(colorBuffer, 1); @@ -159,7 +160,7 @@ float4 main(PFXVertToPix IN) : SV_TARGET // Radiance (Specular) #if DEBUGVIZ_SPECCUBEMAP == 0 - float lod = surface.roughness*cubeMips; + float lod = roughnessToMipLevel(surface.roughness, cubeMips); #elif DEBUGVIZ_SPECCUBEMAP == 1 float lod = 0; #endif @@ -193,17 +194,23 @@ float4 main(PFXVertToPix IN) : SV_TARGET #endif //energy conservation - float3 kD = 1.0f - surface.F; + float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness); + float3 kD = 1.0f - F; kD *= 1.0f - surface.metalness; float dfgNdotV = max( surface.NdotV , 0.0009765625f ); //0.5f/512.0f (512 is size of dfg/brdf lookup tex) float2 envBRDF = TORQUE_TEX2DLOD(BRDFTexture, float4(dfgNdotV, surface.roughness,0,0)).rg; - specular *= surface.F * envBRDF.x + surface.f90 * envBRDF.y; + specular *= F * envBRDF.x + surface.f90 * envBRDF.y; irradiance *= kD * surface.baseColor.rgb; //AO irradiance *= surface.ao; specular *= computeSpecOcclusion(surface.NdotV, surface.ao, surface.roughness); - return float4(irradiance + specular, 0);//alpha writes disabled + //http://marmosetco.tumblr.com/post/81245981087 + float horizonOcclusion = 1.3; + float horizon = saturate( 1 + horizonOcclusion * dot(surface.R, surface.N)); + horizon *= horizon; + + return float4((irradiance + specular) * horizon, 0);//alpha writes disabled } diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.cs index ebb9b9c88..57f143de1 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.cs @@ -409,7 +409,7 @@ function AssetBrowser::importMaterialAsset(%this, %assetItem) else if(%childAssetItem.imageType $= "AO") %mapFieldName = "AOMap"; else if(%childAssetItem.imageType $= "Composite") - %mapFieldName = "PBRConfigMap"; + %mapFieldName = "ORMConfigMap"; %path = fileName(%childAssetItem.filePath); %file.writeline(" "@ %mapFieldName @ "[0] = \"" @ %path @"\";"); diff --git a/Templates/BaseGame/game/tools/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui b/Templates/BaseGame/game/tools/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui index ddff7eae4..8882e1728 100644 --- a/Templates/BaseGame/game/tools/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui +++ b/Templates/BaseGame/game/tools/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui @@ -579,7 +579,7 @@ VertSizing = "bottom"; position = "9 4"; Extent = "72 16"; - text = "Smoothness"; + text = "Roughness"; Profile = "ToolsGuiTextProfile"; }; @@ -599,7 +599,7 @@ new GuiSliderCtrl() { canSaveDynamicFields = "0"; - internalName = "SmoothnessSlider"; + internalName = "RoughnessSlider"; Enabled = "1"; isContainer = "0"; Profile = "ToolsGuiSliderProfile"; @@ -610,10 +610,10 @@ MinExtent = "8 2"; canSave = "1"; Visible = "1"; - Command = "MaterialEditorGui.updateActiveMaterial(\"Smoothness[\" @ MaterialEditorGui.currentLayer @ \"]\", $ThisControl.getValue(), true, true);"; - AltCommand = "$ThisControl.getParent().updateFromChild($ThisControl); MaterialEditorGui.updateActiveMaterial(\"Smoothness[\" @ MaterialEditorGui.currentLayer @ \"]\", $ThisControl.getValue(), true, false);"; + Command = "MaterialEditorGui.updateActiveMaterial(\"Roughness[\" @ MaterialEditorGui.currentLayer @ \"]\", $ThisControl.getValue(), true, true);"; + AltCommand = "$ThisControl.getParent().updateFromChild($ThisControl); MaterialEditorGui.updateActiveMaterial(\"Roughness[\" @ MaterialEditorGui.currentLayer @ \"]\", $ThisControl.getValue(), true, false);"; tooltipprofile = "ToolsGuiDefaultProfile"; - ToolTip = "Sets Smoothness."; + ToolTip = "Sets Roughness."; hovertime = "1000"; range = "0 1"; ticks = "0"; @@ -621,7 +621,7 @@ }; new GuiTextEditCtrl() { canSaveDynamicFields = "0"; - internalName = "SmoothnessTextEdit"; + internalName = "RoughnessTextEdit"; Enabled = "1"; isContainer = "0"; Profile = "ToolsGuiTextEditProfile"; @@ -632,7 +632,7 @@ MinExtent = "8 2"; canSave = "1"; Visible = "1"; - Command = "$ThisControl.getParent().updateFromChild($ThisControl); MaterialEditorGui.updateActiveMaterial(\"Smoothness[\" @ MaterialEditorGui.currentLayer @ \"]\", $ThisControl.getValue());"; + Command = "$ThisControl.getParent().updateFromChild($ThisControl); MaterialEditorGui.updateActiveMaterial(\"Roughness[\" @ MaterialEditorGui.currentLayer @ \"]\", $ThisControl.getValue());"; hovertime = "1000"; AnchorTop = "1"; AnchorBottom = "0"; @@ -724,7 +724,7 @@ }; new GuiCheckBoxCtrl() { canSaveDynamicFields = "0"; - internalName = "invertSmoothnessCheckbox"; + internalName = "invertRoughnessCheckbox"; Enabled = "1"; isContainer = "0"; Profile = "ToolsGuiCheckBoxProfile"; @@ -735,11 +735,11 @@ MinExtent = "8 2"; canSave = "1"; Visible = "1"; - Command = "MaterialEditorGui.updateActiveMaterial(\"invertSmoothness[\" @ MaterialEditorGui.currentLayer @ \"]\", $ThisControl.getValue());"; + Command = "MaterialEditorGui.updateActiveMaterial(\"invertRoughness[\" @ MaterialEditorGui.currentLayer @ \"]\", $ThisControl.getValue());"; tooltipprofile = "ToolsGuiDefaultProfile"; ToolTip = "Treat as Roughest = 1.0, not 0.0"; hovertime = "1000"; - text = "Invert Smoothness"; + text = "Invert Roughness"; groupNum = "-1"; buttonType = "ToggleButton"; useMouseEvents = "0"; @@ -772,7 +772,7 @@ new GuiBitmapCtrl() { canSaveDynamicFields = "0"; - internalName = "PBRConfigMapDisplayBitmap"; + internalName = "ORMConfigMapDisplayBitmap"; Enabled = "1"; isContainer = "0"; Profile = "ToolsGuiDefaultProfile"; @@ -806,7 +806,7 @@ AnchorBottom = "0"; AnchorLeft = "1"; AnchorRight = "0"; - text = "PBR Config Map"; + text = "ORM(Config)Map"; maxLength = "1024"; }; new GuiBitmapButtonCtrl() { @@ -821,9 +821,9 @@ MinExtent = "8 2"; canSave = "1"; Visible = "1"; - Command = "MaterialEditorGui.updatePBRConfigMap(1);"; + Command = "MaterialEditorGui.updateORMConfigMap(1);"; tooltipprofile = "ToolsGuiDefaultProfile"; - ToolTip = "Change the packed spec map for this layer. \n Smoothness (R), Ambient Occlusion (G), and Metalness(B))"; + ToolTip = "Change the packed spec map for this layer. \n Roughness (R), Ambient Occlusion (G), and Metalness(B))"; hovertime = "1000"; groupNum = "-1"; buttonType = "PushButton"; @@ -832,7 +832,7 @@ }; new GuiTextCtrl() { canSaveDynamicFields = "0"; - internalName = "PBRConfigMapNameText"; + internalName = "ORMConfigMapNameText"; Enabled = "1"; isContainer = "0"; Profile = "ToolsGuiTextProfile"; @@ -861,7 +861,7 @@ position = "134 34"; Extent = "40 16"; buttonType = "PushButton"; - command="MaterialEditorGui.updatePBRConfigMap(1);"; + command="MaterialEditorGui.updateORMConfigMap(1);"; }; new GuiBitmapButtonCtrl() { canSaveDynamicFields = "0"; @@ -875,7 +875,7 @@ MinExtent = "8 2"; canSave = "1"; Visible = "1"; - Command = "MaterialEditorGui.updatePBRConfigMap(0);"; + Command = "MaterialEditorGui.updateORMConfigMap(0);"; hovertime = "1000"; groupNum = "-1"; buttonType = "PushButton"; @@ -1010,7 +1010,7 @@ canSaveDynamicFields = "0"; }; new GuiTextCtrl() { - text = "Smoothness"; + text = "Roughness"; maxLength = "1024"; margin = "0 0 0 0"; padding = "0 0 0 0"; @@ -1051,7 +1051,7 @@ active = "1"; command = "MaterialEditorGui.updateroughMap(1);"; tooltipProfile = "GuiToolTipProfile"; - tooltip = "Change the Smoothness map for this layer."; + tooltip = "Change the Roughness map for this layer."; hovertime = "1000"; isContainer = "0"; canSave = "1"; diff --git a/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.cs b/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.cs index 76519a9d5..2803f201c 100644 --- a/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.cs +++ b/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.cs @@ -590,9 +590,9 @@ function MaterialEditorGui::convertTextureFields(%this) for(%specI = 0; %specI < 4; %specI++) { - %PBRConfigMap = MaterialEditorGui.currentMaterial.PBRConfigMap[%specI]; - %PBRConfigMap = MaterialEditorGui.searchForTexture(MaterialEditorGui.currentMaterial, %PBRConfigMap); - MaterialEditorGui.currentMaterial.PBRConfigMap[%specI] = %PBRConfigMap; + %ORMConfigMap = MaterialEditorGui.currentMaterial.ORMConfigMap[%specI]; + %ORMConfigMap = MaterialEditorGui.searchForTexture(MaterialEditorGui.currentMaterial, %ORMConfigMap); + MaterialEditorGui.currentMaterial.ORMConfigMap[%specI] = %ORMConfigMap; } for(%roughI = 0; %roughI < 4; %roughI++) @@ -914,17 +914,17 @@ function MaterialEditorGui::guiSync( %this, %material ) MaterialEditorPropertiesWindow-->toneMapDisplayBitmap.setBitmap( (%material).toneMap[%layer] ); } MaterialEditorPropertiesWindow-->isSRGBCheckbox.setValue((%material).isSRGB[%layer]); - MaterialEditorPropertiesWindow-->invertSmoothnessCheckbox.setValue((%material).invertSmoothness[%layer]); + MaterialEditorPropertiesWindow-->invertRoughnessCheckbox.setValue((%material).invertRoughness[%layer]); - if((%material).PBRConfigMap[%layer] $= "") + if((%material).ORMConfigMap[%layer] $= "") { - MaterialEditorPropertiesWindow-->PBRConfigMapNameText.setText( "None" ); - MaterialEditorPropertiesWindow-->PBRConfigMapDisplayBitmap.setBitmap( "tools/materialEditor/gui/unknownImage" ); + MaterialEditorPropertiesWindow-->ORMConfigMapNameText.setText( "None" ); + MaterialEditorPropertiesWindow-->ORMConfigMapDisplayBitmap.setBitmap( "tools/materialEditor/gui/unknownImage" ); } else { - MaterialEditorPropertiesWindow-->PBRConfigMapNameText.setText( (%material).PBRConfigMap[%layer] ); - MaterialEditorPropertiesWindow-->PBRConfigMapDisplayBitmap.setBitmap( (%material).PBRConfigMap[%layer] ); + MaterialEditorPropertiesWindow-->ORMConfigMapNameText.setText( (%material).ORMConfigMap[%layer] ); + MaterialEditorPropertiesWindow-->ORMConfigMapDisplayBitmap.setBitmap( (%material).ORMConfigMap[%layer] ); } if((%material).roughMap[%layer] $= "") @@ -988,8 +988,8 @@ function MaterialEditorGui::guiSync( %this, %material ) MaterialEditorPropertiesWindow-->colorTintSwatch.color = (%material).diffuseColor[%layer]; MaterialEditorPropertiesWindow-->specularColorSwatch.color = (%material).specular[%layer]; - MaterialEditorPropertiesWindow-->SmoothnessTextEdit.setText((%material).Smoothness[%layer]); - MaterialEditorPropertiesWindow-->SmoothnessSlider.setValue((%material).Smoothness[%layer]); + MaterialEditorPropertiesWindow-->RoughnessTextEdit.setText((%material).Roughness[%layer]); + MaterialEditorPropertiesWindow-->RoughnessSlider.setValue((%material).Roughness[%layer]); MaterialEditorPropertiesWindow-->MetalnessTextEdit.setText((%material).Metalness[%layer]); MaterialEditorPropertiesWindow-->MetalnessSlider.setValue((%material).Metalness[%layer]); MaterialEditorPropertiesWindow-->glowMulTextEdit.setText((%material).glowMul[%layer]); @@ -1065,7 +1065,7 @@ function MaterialEditorGui::guiSync( %this, %material ) MaterialEditorPropertiesWindow-->accuCheckbox.setValue((%material).accuEnabled[%layer]); - %this.getRoughChan((%material).SmoothnessChan[%layer]); + %this.getRoughChan((%material).RoughnessChan[%layer]); %this.getAOChan((%material).AOChan[%layer]); %this.getMetalChan((%material).metalChan[%layer]); %this.getGlowChan((%material).glowChan[%layer]); @@ -1276,7 +1276,7 @@ function MaterialEditorGui::updateDetailNormalStrength(%this,%newStrength) MaterialEditorGui.updateActiveMaterial("detailNormalMapStrength[" @ %layer @ "]", %detailStrength); } -function MaterialEditorGui::updatePBRConfigMap(%this,%action) +function MaterialEditorGui::updateORMConfigMap(%this,%action) { %layer = MaterialEditorGui.currentLayer; @@ -1287,20 +1287,20 @@ function MaterialEditorGui::updatePBRConfigMap(%this,%action) { MaterialEditorGui.updateActiveMaterial("pixelSpecular[" @ MaterialEditorGui.currentLayer @ "]", 0); - MaterialEditorPropertiesWindow-->PBRConfigMapDisplayBitmap.setBitmap(%texture); + MaterialEditorPropertiesWindow-->ORMConfigMapDisplayBitmap.setBitmap(%texture); - %bitmap = MaterialEditorPropertiesWindow-->PBRConfigMapDisplayBitmap.bitmap; + %bitmap = MaterialEditorPropertiesWindow-->ORMConfigMapDisplayBitmap.bitmap; %bitmap = strreplace(%bitmap,"tools/materialEditor/scripts/",""); - MaterialEditorPropertiesWindow-->PBRConfigMapDisplayBitmap.setBitmap(%bitmap); - MaterialEditorPropertiesWindow-->PBRConfigMapNameText.setText(%bitmap); - MaterialEditorGui.updateActiveMaterial("PBRConfigMap[" @ %layer @ "]","\"" @ %bitmap @ "\""); + MaterialEditorPropertiesWindow-->ORMConfigMapDisplayBitmap.setBitmap(%bitmap); + MaterialEditorPropertiesWindow-->ORMConfigMapNameText.setText(%bitmap); + MaterialEditorGui.updateActiveMaterial("ORMConfigMap[" @ %layer @ "]","\"" @ %bitmap @ "\""); } } else { - MaterialEditorPropertiesWindow-->PBRConfigMapNameText.setText("None"); - MaterialEditorPropertiesWindow-->PBRConfigMapDisplayBitmap.setBitmap("tools/materialEditor/gui/unknownImage"); - MaterialEditorGui.updateActiveMaterial("PBRConfigMap[" @ %layer @ "]",""); + MaterialEditorPropertiesWindow-->ORMConfigMapNameText.setText("None"); + MaterialEditorPropertiesWindow-->ORMConfigMapDisplayBitmap.setBitmap("tools/materialEditor/gui/unknownImage"); + MaterialEditorGui.updateActiveMaterial("ORMConfigMap[" @ %layer @ "]",""); } MaterialEditorGui.guiSync( materialEd_previewMaterial ); @@ -2524,7 +2524,7 @@ function MaterialEditorGui::updateAccuCheckbox(%this, %value) // channel in selectors function MaterialEditorGui::setRoughChan(%this, %value) { - MaterialEditorGui.updateActiveMaterial("SmoothnessChan[" @ MaterialEditorGui.currentLayer @ "]", %value); + MaterialEditorGui.updateActiveMaterial("RoughnessChan[" @ MaterialEditorGui.currentLayer @ "]", %value); MaterialEditorGui.guiSync( materialEd_previewMaterial ); } @@ -2573,13 +2573,12 @@ function MaterialEditorGui::saveCompositeMap(%this) %metalMap = %material.metalMap[%layer]; %glowMap = %material.glowMap[%layer]; - %smooth = %material.SmoothnessChan[%layer]; + %roughness = %material.RoughnessChan[%layer]; %ao = %material.AOChan[%layer]; %metal = %material.metalChan[%layer]; - %glow = %material.glowChan[%layer]; - %channelKey = %smooth SPC %ao SPC %metal SPC %glow; + %channelKey = %roughness SPC %ao SPC %metal SPC 0; error("Storing: \"" @ %roughMap @"\" \""@ %aoMap @"\" \""@ %metalMap @"\" \""@ %channelKey @"\" \""@ %saveAs @"\""); - saveCompositeTexture(%roughMap,%aoMap,%metalMap,%glowMap,%channelKey, %saveAs); + saveCompositeTexture(%roughMap,%aoMap,%metalMap,"",%channelKey, %saveAs); %dlg.delete(); } diff --git a/Templates/BaseGame/game/tools/resources/materials.cs b/Templates/BaseGame/game/tools/resources/materials.cs index d9c7ea97f..2ba9fec86 100644 --- a/Templates/BaseGame/game/tools/resources/materials.cs +++ b/Templates/BaseGame/game/tools/resources/materials.cs @@ -2,7 +2,7 @@ singleton Material(ReflectProbePreviewMat) { mapTo = "ReflectProbePreviewMat"; diffuseColor[0] = "1 1 1 1"; - smoothness[0] = "1"; + roughness[0] = "0"; metalness[0] = "1"; translucentBlendOp = "None"; }; diff --git a/Templates/BaseGame/game/tools/worldEditor/gui/guiTerrainMaterialDlg.ed.gui b/Templates/BaseGame/game/tools/worldEditor/gui/guiTerrainMaterialDlg.ed.gui index 22a4b0ac6..c50cb370b 100644 --- a/Templates/BaseGame/game/tools/worldEditor/gui/guiTerrainMaterialDlg.ed.gui +++ b/Templates/BaseGame/game/tools/worldEditor/gui/guiTerrainMaterialDlg.ed.gui @@ -767,12 +767,12 @@ tooltipProfile = "ToolsGuiToolTipProfile"; hovertime = "1000"; isContainer = "0"; - internalName = "pbrConfigTexCtrl"; + internalName = "ormConfigTexCtrl"; canSave = "1"; canSaveDynamicFields = "0"; }; new GuiTextCtrl() { - text = "PBR Config"; + text = "ORM Config"; maxLength = "1024"; margin = "0 0 0 0"; padding = "0 0 0 0"; @@ -812,9 +812,9 @@ profile = "ToolsGuiDefaultProfile"; visible = "1"; active = "1"; - command = "TerrainMaterialDlg.changePBRConfig();"; + command = "TerrainMaterialDlg.changeormConfig();"; tooltipProfile = "ToolsGuiDefaultProfile"; - tooltip = "Change the active PBR Config Map for this layer."; + tooltip = "Change the active ORM Config Map for this layer."; hovertime = "1000"; isContainer = "0"; canSave = "1"; @@ -856,7 +856,7 @@ profile = "ToolsGuiButtonProfile"; visible = "1"; active = "1"; - command = "TerrainMaterialDlg.changePBRConfig();"; + command = "TerrainMaterialDlg.changeormConfig();"; tooltipProfile = "ToolsGuiToolTipProfile"; hovertime = "1000"; isContainer = "0"; @@ -881,7 +881,7 @@ profile = "ToolsGuiDefaultProfile"; visible = "1"; active = "1"; - command = "TerrainMaterialDlg-->pbrConfigTexCtrl.setBitmap(\"tools/materialEditor/gui/unknownImage\");"; + command = "TerrainMaterialDlg-->ormConfigTexCtrl.setBitmap(\"tools/materialEditor/gui/unknownImage\");"; tooltipProfile = "ToolsGuiToolTipProfile"; hovertime = "1000"; isContainer = "0"; @@ -909,7 +909,7 @@ canSaveDynamicFields = "0"; }; new GuiCheckBoxCtrl() { - text = " Invert Smoothness"; + text = " Invert Roughness"; groupNum = "-1"; buttonType = "ToggleButton"; useMouseEvents = "0"; @@ -924,7 +924,7 @@ tooltipProfile = "ToolsGuiToolTipProfile"; hovertime = "1000"; isContainer = "0"; - internalName = "invertSmoothness"; + internalName = "invertRoughness"; canSave = "1"; canSaveDynamicFields = "0"; }; diff --git a/Templates/BaseGame/game/tools/worldEditor/scripts/interfaces/terrainMaterialDlg.ed.cs b/Templates/BaseGame/game/tools/worldEditor/scripts/interfaces/terrainMaterialDlg.ed.cs index b89fe3970..ff6209946 100644 --- a/Templates/BaseGame/game/tools/worldEditor/scripts/interfaces/terrainMaterialDlg.ed.cs +++ b/Templates/BaseGame/game/tools/worldEditor/scripts/interfaces/terrainMaterialDlg.ed.cs @@ -307,9 +307,9 @@ function TerrainMaterialDlg::changeNormal( %this ) } //----------------------------------------------------------------------------- -function TerrainMaterialDlg::changePBRConfig( %this ) +function TerrainMaterialDlg::changeormConfig( %this ) { - %ctrl = %this-->pbrConfigTexCtrl; + %ctrl = %this-->ormConfigTexCtrl; %file = %ctrl.bitmap; if( getSubStr( %file, 0 , 6 ) $= "tools/" ) %file = ""; @@ -417,10 +417,10 @@ function TerrainMaterialDlg::setActiveMaterial( %this, %mat ) }else{ %this-->baseTexCtrl.setBitmap( %mat.diffuseMap ); } - if (%mat.pbrConfigMap $= ""){ - %this-->pbrConfigTexCtrl.setBitmap( "tools/materialEditor/gui/unknownImage" ); + if (%mat.ormConfigMap $= ""){ + %this-->ormConfigTexCtrl.setBitmap( "tools/materialEditor/gui/unknownImage" ); }else{ - %this-->pbrConfigTexCtrl.setBitmap( %mat.pbrConfigMap ); + %this-->ormConfigTexCtrl.setBitmap( %mat.ormConfigMap ); } if (%mat.detailMap $= ""){ %this-->detailTexCtrl.setBitmap( "tools/materialEditor/gui/unknownImage" ); @@ -449,7 +449,7 @@ function TerrainMaterialDlg::setActiveMaterial( %this, %mat ) %this-->macroDistanceCtrl.setText( %mat.macroDistance ); %this-->isSRGB.setValue( %mat.isSRGB ); - %this-->invertSmoothness.setValue( %mat.invertSmoothness ); + %this-->invertRoughness.setValue( %mat.invertRoughness ); %this.activateMaterialCtrls( true ); } @@ -483,10 +483,10 @@ function TerrainMaterialDlg::saveDirtyMaterial( %this, %mat ) }else{ %newNormal = %this-->normTexCtrl.bitmap; } - if (%this-->pbrConfigTexCtrl.bitmap $= "tools/materialEditor/gui/unknownImage"){ - %newPBRConfig = ""; + if (%this-->ormConfigTexCtrl.bitmap $= "tools/materialEditor/gui/unknownImage"){ + %newormConfig = ""; }else{ - %newPBRConfig = %this-->pbrConfigTexCtrl.bitmap; + %newormConfig = %this-->ormConfigTexCtrl.bitmap; } if (%this-->detailTexCtrl.bitmap $= "tools/materialEditor/gui/unknownImage"){ %newDetail = ""; @@ -510,7 +510,7 @@ function TerrainMaterialDlg::saveDirtyMaterial( %this, %mat ) %macroDistance = %this-->macroDistanceCtrl.getText(); %isSRGB = %this-->isSRGB.getValue(); - %invertSmoothness = %this-->invertSmoothness.getValue(); + %invertRoughness = %this-->invertRoughness.getValue(); // If no properties of this materials have changed, // return. @@ -519,7 +519,7 @@ function TerrainMaterialDlg::saveDirtyMaterial( %this, %mat ) %mat.diffuseMap $= %newDiffuse && %mat.normalMap $= %newNormal && %mat.detailMap $= %newDetail && - %mat.pbrConfigMap $= %newPBRConfig && + %mat.ormConfigMap $= %newormConfig && %mat.macroMap $= %newMacro && %mat.detailSize == %detailSize && %mat.diffuseSize == %diffuseSize && @@ -531,7 +531,7 @@ function TerrainMaterialDlg::saveDirtyMaterial( %this, %mat ) %mat.macroDistance == %macroDistance && %mat.parallaxScale == %parallaxScale && %mat.isSRGB == %isSRGB && - %mat.invertSmoothness == %invertSmoothness) + %mat.invertRoughness == %invertRoughness) return; // Make sure the material name is unique. @@ -555,7 +555,7 @@ function TerrainMaterialDlg::saveDirtyMaterial( %this, %mat ) %mat.diffuseMap = %newDiffuse; %mat.diffuseMapAsset = ""; %mat.normalMap = %newNormal; - %mat.pbrConfigMap = %newPBRConfig; + %mat.ormConfigMap = %newormConfig; %mat.detailMap = %newDetail; %mat.macroMap = %newMacro; %mat.detailSize = %detailSize; @@ -568,7 +568,7 @@ function TerrainMaterialDlg::saveDirtyMaterial( %this, %mat ) %mat.useSideProjection = %useSideProjection; %mat.parallaxScale = %parallaxScale; %mat.isSRGB = %isSRGB; - %mat.invertSmoothness = %invertSmoothness; + %mat.invertRoughness = %invertRoughness; // Mark the material as dirty and needing saving. @@ -607,7 +607,7 @@ function TerrainMaterialDlg::snapshotMaterials( %this ) internalName = %mat.internalName; diffuseMap = %mat.diffuseMap; normalMap = %mat.normalMap; - pbrConfigMap = %mat.pbrConfigMap; + ormConfigMap = %mat.ormConfigMap; detailMap = %mat.detailMap; macroMap = %mat.macroMap; detailSize = %mat.detailSize; @@ -620,7 +620,7 @@ function TerrainMaterialDlg::snapshotMaterials( %this ) useSideProjection = %mat.useSideProjection; parallaxScale = %mat.parallaxScale; isSRGB = %mat.isSRGB; - invertSmoothness = %mat.invertSmoothness; + invertRoughness = %mat.invertRoughness; }; } } @@ -644,7 +644,7 @@ function TerrainMaterialDlg::restoreMaterials( %this ) %mat.setInternalName( %obj.internalName ); %mat.diffuseMap = %obj.diffuseMap; %mat.normalMap = %obj.normalMap; - %mat.pbrConfigMap = %obj.pbrConfigMap; + %mat.ormConfigMap = %obj.ormConfigMap; %mat.detailMap = %obj.detailMap; %mat.macroMap = %obj.macroMap; %mat.detailSize = %obj.detailSize; @@ -657,7 +657,7 @@ function TerrainMaterialDlg::restoreMaterials( %this ) %mat.useSideProjection = %obj.useSideProjection; %mat.parallaxScale = %obj.parallaxScale; %mat.isSRGB = %obj.isSRGB; - %mat.invertSmoothness = %obj.invertSmoothness; + %mat.invertRoughness = %obj.invertRoughness; } }