Files
o3de/Gems/GradientSignal/Code/Include/GradientSignal/Components/LevelsGradientComponent.h
T
Mike Balfour c403fa3db6 More GetValues() overrides (#6896)
* Benchmarks and tests for Image and Constant GetValues

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Verify GetValues for Perlin and Random Gradients

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Standardized the assert format for GetValues().

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* More GetValues unit tests and test cleanup

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Fixed typos

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* GetValues() unit tests for surface gradients.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Benchmarks for ShapeAreaFalloff Gradient

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Added benchmarks for all remaining gradients and cleaned up the helper methods.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Renamed class for better report formatting.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Added missing Mocks dependencies for the Editor tests.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* First batch of specific GetValues() overrides.
Each one is measurably faster than the generic version.  Also, in ShapeAreaFalloffGradient, I optimized and simplified the logic a bit, so GetValue() is marginally faster too.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Change GetValues() to use span and add more overrides.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Convert GetValues() to use AZStd::span and added more overrides.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Add missing include.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* PR feedback - switch to fill

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Fixed the logic and added unit tests and comments.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>
2022-01-14 13:30:45 -06:00

100 lines
3.7 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <LmbrCentral/Dependency/DependencyMonitor.h>
#include <GradientSignal/GradientSampler.h>
#include <AzCore/Component/Component.h>
#include <GradientSignal/Ebuses/GradientRequestBus.h>
#include <GradientSignal/Ebuses/LevelsGradientRequestBus.h>
namespace LmbrCentral
{
template<typename, typename>
class EditorWrappedComponentBase;
}
namespace GradientSignal
{
class LevelsGradientConfig
: public AZ::ComponentConfig
{
public:
AZ_CLASS_ALLOCATOR(LevelsGradientConfig, AZ::SystemAllocator, 0);
AZ_RTTI(LevelsGradientConfig, "{02F01CCC-CA6F-462F-BDEC-9A7EAC730D33}", AZ::ComponentConfig);
static void Reflect(AZ::ReflectContext* context);
GradientSampler m_gradientSampler;
float m_inputMin = 0.0f;
float m_inputMid = 1.0f;
float m_inputMax = 1.0f;
float m_outputMin = 0.0f;
float m_outputMax = 1.0f;
};
static const AZ::Uuid LevelsGradientComponentTypeId = "{F8EF5F6E-6D4A-441B-A5C2-DE1775918C24}";
/**
* calculates a gradient value by converting values from another gradient to another's range
*/
class LevelsGradientComponent
: public AZ::Component
, private GradientRequestBus::Handler
, private LevelsGradientRequestBus::Handler
{
public:
template<typename, typename> friend class LmbrCentral::EditorWrappedComponentBase;
AZ_COMPONENT(LevelsGradientComponent, LevelsGradientComponentTypeId);
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services);
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services);
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& services);
static void Reflect(AZ::ReflectContext* context);
LevelsGradientComponent(const LevelsGradientConfig& configuration);
LevelsGradientComponent() = default;
~LevelsGradientComponent() = default;
//////////////////////////////////////////////////////////////////////////
// AZ::Component interface implementation
void Activate() override;
void Deactivate() override;
bool ReadInConfig(const AZ::ComponentConfig* baseConfig) override;
bool WriteOutConfig(AZ::ComponentConfig* outBaseConfig) const override;
//////////////////////////////////////////////////////////////////////////
// GradientRequestBus
float GetValue(const GradientSampleParams& sampleParams) const override;
void GetValues(AZStd::span<AZ::Vector3> positions, AZStd::span<float> outValues) const override;
bool IsEntityInHierarchy(const AZ::EntityId& entityId) const override;
protected:
//////////////////////////////////////////////////////////////////////////
// LevelsGradientRequestBus
float GetInputMin() const override;
void SetInputMin(float value) override;
float GetInputMid() const override;
void SetInputMid(float value) override;
float GetInputMax() const override;
void SetInputMax(float value) override;
float GetOutputMin() const override;
void SetOutputMin(float value) override;
float GetOutputMax() const override;
void SetOutputMax(float value) override;
GradientSampler& GetGradientSampler() override;
private:
LevelsGradientConfig m_configuration;
LmbrCentral::DependencyMonitor m_dependencyMonitor;
};
}