From a8bb1a5ead4535dd5df35adbbce2a5b5e1abb917 Mon Sep 17 00:00:00 2001 From: Jan Date: Sun, 7 Aug 2022 15:45:40 +0200 Subject: [PATCH] Load particle cloud materials --- .../IW4/AssetLoaders/AssetLoaderMaterial.cpp | 76 ++++++++++++++++++- .../IW4/AssetDumpers/AssetDumperMaterial.cpp | 3 + 2 files changed, 75 insertions(+), 4 deletions(-) diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMaterial.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMaterial.cpp index 9e3ccf0a..bab86434 100644 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMaterial.cpp +++ b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMaterial.cpp @@ -172,14 +172,82 @@ namespace IW4 void mtl_distortion_template() { - // TODO - throw SkipMaterialException(); + commonsetup_template(); + + const auto uvAnim = ReadBoolProperty("uvAnim"); + if (uvAnim) + SetTechniqueSet("distortion_scale_ua_zfeather"); + else + SetTechniqueSet("distortion_scale_zfeather"); + + const auto colorMapName = ReadStringProperty("colorMap"); + const auto tileColor = ReadEnumProperty("tileColor", GdtTileModeNames, std::extent_v); + const auto filterColor = ReadEnumProperty("filterColor", GdtSamplerFilterNames, std::extent_v); + + if (!colorMapName.empty()) + AddMapTexture("colorMap", tileColor, filterColor, TS_COLOR_MAP, colorMapName); + else + throw GdtReadingException("ColorMap may not be blank in tools materials"); + + const auto distortionScaleX = ReadFloatProperty("distortionScaleX"); + const auto distortionScaleY = ReadFloatProperty("distortionScaleY"); + AddConstant("distortionScale", Vector4f(distortionScaleX, distortionScaleY, 0, 0)); + + if (uvAnim) + { + const auto uvScrollX = ReadFloatProperty("uvScrollX"); + const auto uvScrollY = ReadFloatProperty("uvScrollY"); + const auto uvScrollRotate = ReadFloatProperty("uvScrollRotate"); + AddConstant("uvAnimParms", Vector4f(uvScrollX, uvScrollY, uvScrollRotate, 0)); + } } void mtl_particlecloud_template() { - // TODO - throw SkipMaterialException(); + refblend_template(); + sort_template(); + clamp_template(); + + SetTextureAtlas(1, 1); + // tessSize(0) + + // hasEditorMaterial + // allocLightmap + + statebits_template(); + + std::string outdoorSuffix; + const auto outdoorOnly = ReadBoolProperty("outdoorOnly"); + if (outdoorOnly) + outdoorSuffix = "_outdoor"; + + std::string addSuffix; + const auto blendFunc = ReadStringProperty("blendFunc"); + if (blendFunc == GDT_BLEND_FUNC_ADD || blendFunc == GDT_BLEND_FUNC_SCREEN_ADD) + addSuffix = "_add"; + + std::string spotSuffix; + const auto useSpotLight = ReadBoolProperty("useSpotLight"); + if (useSpotLight) + spotSuffix = "_spot"; + + if(outdoorOnly && useSpotLight) + throw GdtReadingException("Outdoor and spot aren't supported on particle cloud materials"); + + std::ostringstream ss; + ss << "particle_cloud" << outdoorSuffix << addSuffix << spotSuffix; + SetTechniqueSet(ss.str()); + + const auto colorMapName = ReadStringProperty("colorMap"); + const auto tileColor = ReadEnumProperty("tileColor", GdtTileModeNames, std::extent_v); + const auto filterColor = ReadEnumProperty("filterColor", GdtSamplerFilterNames, std::extent_v); + + if (!colorMapName.empty()) + AddMapTexture("colorMap", tileColor, filterColor, TS_COLOR_MAP, colorMapName); + else + throw GdtReadingException("ColorMap may not be blank in particle cloud materials"); + + std::cout << "Using particlecloud for \"" << m_material->info.name << "\"\n"; } void mtl_tools_template() diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperMaterial.cpp b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperMaterial.cpp index d5cf1a3a..ca7481fd 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperMaterial.cpp +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperMaterial.cpp @@ -1343,6 +1343,9 @@ namespace IW4 SetValue("waterColor", m_constants_info.m_water_color); SetValue("flagSpeed", m_constants_info.m_flag_speed); SetValue("flagPhase", m_constants_info.m_flag_phase); + SetValue("uvScrollX", m_constants_info.m_uv_scroll_x); + SetValue("uvScrollY", m_constants_info.m_uv_scroll_y); + SetValue("uvScrollRotate", m_constants_info.m_uv_rotate); } void SetTextureTableValues()