Browse Source

Merging latest

Signed-off-by: Ken Pruiksma <[email protected]>
Ken Pruiksma 2 years ago
parent
commit
33c5947c64

+ 16 - 8
Gem/Code/Include/DecalBus.h

@@ -19,14 +19,15 @@ namespace MultiplayerSample
         AZ_RTTI(MultiplayerSample::SpawnDecalConfig, "{FC3DA616-174B-48FD-9BFB-BC277132FB47}");
         AZ_RTTI(MultiplayerSample::SpawnDecalConfig, "{FC3DA616-174B-48FD-9BFB-BC277132FB47}");
         inline static void Reflect(AZ::ReflectContext* context);
         inline static void Reflect(AZ::ReflectContext* context);
 
 
-        float m_scale = 1.0f;             // Scale in meters.
-        float m_opacity = 1.0f;           // How visible the decal is.
-        float m_attenuationAngle = 1.0f;  // How much to attenuate based on the angle of the geometry vs the decal.
+        AZ::Data::AssetId m_materialAssetId; // Asset Id of the material.
+        float m_scale = 1.0f;                // Scale in meters.
+        float m_opacity = 1.0f;              // How visible the decal is.
+        float m_attenuationAngle = 1.0f;     // How much to attenuate based on the angle of the geometry vs the decal.
         float m_lifeTimeSec = 0.0f;          // Length of time the decal lives between fading in and out, in seconds.
         float m_lifeTimeSec = 0.0f;          // Length of time the decal lives between fading in and out, in seconds.
         float m_fadeInTimeSec = 0.1f;        // Time it takes the decal to fade in, in seconds.
         float m_fadeInTimeSec = 0.1f;        // Time it takes the decal to fade in, in seconds.
         float m_fadeOutTimeSec = 1.0f;       // Time it takes the decal to fade out, in seconds.
         float m_fadeOutTimeSec = 1.0f;       // Time it takes the decal to fade out, in seconds.
-        float m_thickness = 1.0f;         // How thick the decal should be on the z axis.
-        uint8_t m_sortKey = 0;            // Higher numbers sort in front of lower numbers.
+        float m_thickness = 1.0f;            // How thick the decal should be on the z axis.
+        uint8_t m_sortKey = 0;               // Higher numbers sort in front of lower numbers.
     };
     };
 
 
     void SpawnDecalConfig::Reflect(AZ::ReflectContext* context)
     void SpawnDecalConfig::Reflect(AZ::ReflectContext* context)
@@ -35,6 +36,7 @@ namespace MultiplayerSample
         {
         {
             serializeContext->Class<MultiplayerSample::SpawnDecalConfig>()
             serializeContext->Class<MultiplayerSample::SpawnDecalConfig>()
                 ->Version(0)
                 ->Version(0)
+                ->Field("MaterialAssetId", &SpawnDecalConfig::m_materialAssetId)
                 ->Field("Scale", &SpawnDecalConfig::m_scale)
                 ->Field("Scale", &SpawnDecalConfig::m_scale)
                 ->Field("Opacity", &SpawnDecalConfig::m_opacity)
                 ->Field("Opacity", &SpawnDecalConfig::m_opacity)
                 ->Field("AttenuationAngle", &SpawnDecalConfig::m_attenuationAngle)
                 ->Field("AttenuationAngle", &SpawnDecalConfig::m_attenuationAngle)
@@ -50,11 +52,16 @@ namespace MultiplayerSample
                 editContext->Class<SpawnDecalConfig>("SpawnDecalConfig", "Configuration settings for spawning a decal.")
                 editContext->Class<SpawnDecalConfig>("SpawnDecalConfig", "Configuration settings for spawning a decal.")
                     ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
                     ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
                     ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
                     ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
-                    ->DataElement(AZ::Edit::UIHandlers::Default, &SpawnDecalConfig::m_scale, "Scale", "The scale of the decal.")
+                    ->DataElement(AZ::Edit::UIHandlers::Default, &SpawnDecalConfig::m_materialAssetId, "Material", "The material for the decal.")
+                    ->DataElement(AZ::Edit::UIHandlers::Slider, &SpawnDecalConfig::m_scale, "Scale", "The scale of the decal.")
+                        ->Attribute(AZ::Edit::Attributes::Min, 0.01f)
+                        ->Attribute(AZ::Edit::Attributes::Max, 100.0f)
+                        ->Attribute(AZ::Edit::Attributes::SoftMin, 0.01f)
+                        ->Attribute(AZ::Edit::Attributes::SoftMax, 5.0f)
                     ->DataElement(AZ::Edit::UIHandlers::Slider, &SpawnDecalConfig::m_opacity, "Opacity", "The opacity of the decal.")
                     ->DataElement(AZ::Edit::UIHandlers::Slider, &SpawnDecalConfig::m_opacity, "Opacity", "The opacity of the decal.")
                         ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
                         ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
                         ->Attribute(AZ::Edit::Attributes::Max, 1.0f)
                         ->Attribute(AZ::Edit::Attributes::Max, 1.0f)
-                    ->DataElement(AZ::Edit::UIHandlers::Default, &SpawnDecalConfig::m_attenuationAngle, "Angle attenuation", "How much to attenuate the opacity of the decal based on the different in the angle between the decal and the surface.")
+                    ->DataElement(AZ::Edit::UIHandlers::Slider, &SpawnDecalConfig::m_attenutationAngle, "Angle attenuation", "How much to attenuate the opacity of the decal based on the different in the angle between the decal and the surface.")
                         ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
                         ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
                         ->Attribute(AZ::Edit::Attributes::Max, 1.0f)
                         ->Attribute(AZ::Edit::Attributes::Max, 1.0f)
                     ->DataElement(AZ::Edit::UIHandlers::Default, &SpawnDecalConfig::m_lifeTimeSec, "Life time", "Length of time the decal lives between fading in and out, in seconds")
                     ->DataElement(AZ::Edit::UIHandlers::Default, &SpawnDecalConfig::m_lifeTimeSec, "Life time", "Length of time the decal lives between fading in and out, in seconds")
@@ -78,6 +85,7 @@ namespace MultiplayerSample
                 ->Attribute(AZ::Script::Attributes::Module, "decals")
                 ->Attribute(AZ::Script::Attributes::Module, "decals")
                 ->Constructor()
                 ->Constructor()
                 ->Constructor<const SpawnDecalConfig&>()
                 ->Constructor<const SpawnDecalConfig&>()
+                ->Property("material", BehaviorValueProperty(&SpawnDecalConfig::m_materialAssetId))
                 ->Property("scale", BehaviorValueProperty(&SpawnDecalConfig::m_scale))
                 ->Property("scale", BehaviorValueProperty(&SpawnDecalConfig::m_scale))
                 ->Property("opacity", BehaviorValueProperty(&SpawnDecalConfig::m_opacity))
                 ->Property("opacity", BehaviorValueProperty(&SpawnDecalConfig::m_opacity))
                 ->Property("attenuationAngle", BehaviorValueProperty(&SpawnDecalConfig::m_attenuationAngle))
                 ->Property("attenuationAngle", BehaviorValueProperty(&SpawnDecalConfig::m_attenuationAngle))
@@ -107,7 +115,7 @@ namespace MultiplayerSample
          * \param materialAssetId The asset ID of the material to use for the decal
          * \param materialAssetId The asset ID of the material to use for the decal
          * \param config The configuration of the decal to spawn (opacity, scale, etc).
          * \param config The configuration of the decal to spawn (opacity, scale, etc).
          */
          */
-        virtual void SpawnDecal(const AZ::Transform& worldTm, AZ::Data::AssetId materialAssetId, const SpawnDecalConfig& config) = 0;
+        virtual void SpawnDecal(const AZ::Transform& worldTm, const SpawnDecalConfig& config) = 0;
     };
     };
 
 
     using DecalRequestBus = AZ::EBus<DecalRequests>;
     using DecalRequestBus = AZ::EBus<DecalRequests>;

+ 9 - 2
Gem/Code/Source/Components/ScriptableDecalComponent.cpp

@@ -97,14 +97,21 @@ namespace MultiplayerSample
         m_decalFeatureProcessor = nullptr;
         m_decalFeatureProcessor = nullptr;
     }
     }
 
 
-    void ScriptableDecalComponent::SpawnDecal(const AZ::Transform& worldTm, AZ::Data::AssetId materialAssetId, const SpawnDecalConfig& config)
+    void ScriptableDecalComponent::SpawnDecal(const AZ::Transform& worldTm, const SpawnDecalConfig& config)
     {
     {
         DecalHandle handle = m_decalFeatureProcessor->AcquireDecal();
         DecalHandle handle = m_decalFeatureProcessor->AcquireDecal();
 
 
         AZ::Vector3 scale = AZ::Vector3(config.m_scale, config.m_scale, config.m_scale * config.m_thickness);
         AZ::Vector3 scale = AZ::Vector3(config.m_scale, config.m_scale, config.m_scale * config.m_thickness);
 
 
+        // Check for bad state.
+        if (config.m_scale <= 0.0f || !config.m_materialAssetId.IsValid() || config.m_opacity <= 0.0f ||
+            (config.m_fadeInTime + config.m_lifeTime + config.m_fadeOutTime <= 0.0f))
+        {
+            return;
+        }
+
         m_decalFeatureProcessor->SetDecalTransform(handle, worldTm, scale);
         m_decalFeatureProcessor->SetDecalTransform(handle, worldTm, scale);
-        m_decalFeatureProcessor->SetDecalMaterial(handle, materialAssetId);
+        m_decalFeatureProcessor->SetDecalMaterial(handle, config.m_materialAssetId);
         m_decalFeatureProcessor->SetDecalOpacity(handle, config.m_opacity);
         m_decalFeatureProcessor->SetDecalOpacity(handle, config.m_opacity);
         m_decalFeatureProcessor->SetDecalAttenuationAngle(handle, config.m_attenuationAngle);
         m_decalFeatureProcessor->SetDecalAttenuationAngle(handle, config.m_attenuationAngle);
         m_decalFeatureProcessor->SetDecalSortKey(handle, config.m_sortKey);
         m_decalFeatureProcessor->SetDecalSortKey(handle, config.m_sortKey);

+ 1 - 1
Gem/Code/Source/Components/ScriptableDecalComponent.h

@@ -46,7 +46,7 @@ namespace MultiplayerSample
         };
         };
 
 
         // DecalRequestBus::Handler...
         // DecalRequestBus::Handler...
-        void SpawnDecal(const AZ::Transform& worldTm, AZ::Data::AssetId materialAssetId, const SpawnDecalConfig& config) override;
+        void SpawnDecal(const AZ::Transform& worldTm, const SpawnDecalConfig& config) override;
 
 
         // TickBus::Handler...
         // TickBus::Handler...
         virtual void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
         virtual void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;

+ 4 - 0
Prefabs/Player.prefab

@@ -275,9 +275,13 @@
                                         "isNullPointer": false,
                                         "isNullPointer": false,
                                         "$type": "MultiplayerSample::SpawnDecalConfig",
                                         "$type": "MultiplayerSample::SpawnDecalConfig",
                                         "value": {
                                         "value": {
+                                            "MaterialAssetId": {
+                                                "guid": "{FD203077-616F-53C5-9553-660CCB88DB7B}"
+                                            },
                                             "Scale": 0.25,
                                             "Scale": 0.25,
                                             "LifeTimeSec": 12.0,
                                             "LifeTimeSec": 12.0,
                                             "FadeOutTimeSec": 4.0
                                             "FadeOutTimeSec": 4.0
+                                            "Thickness": 0.10000000149011612
                                         }
                                         }
                                     },
                                     },
                                     "InputControlVisibility": {
                                     "InputControlVisibility": {