9786d63596
* Hair - First introduction of Hair gem to Atom and O3DE - The hair technology is based off TressFX 4.1 - These are some of the areas we enhanced the original TressFX implementation: - Lighting model was replaced and we now use a modified Marschner model - Blending is done directly with the back buffer removing the silhouette of the original implementation - Hair depth / thickness is now calculated to remove incorrect back lighting (TT lobe in the Marschner model) - Thickness corrected to handle hair gaps hence introducing better light passage for the TT - The hair is fully integrated into the Atom pipeline and structure design - Usage of single shared buffer for the computer buffers reduces barriers sync overhead Remarks: - Collisions via SDF compute are to be introduced soon - Improved shortcut rendering method ala Eidos Montreal to be introduced soon Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - code clean pass Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - EMFX Actor visibility implementation Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - COnnecting hair passes to Atom's MainPipeline.pass Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - adding dedicated thumbnail pipeline that does not include the hair gem Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - changed Atom shader files to allow hooking the hair to the lighting data structures Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - fixed a few headers to have the latest O3DE license + verification fixes Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - enabling editor component only when tool pipline is built + default texture add Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - fixing Linux and Android compilation builds Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - another files change to make Linux compile Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - more Linux and Android build fixes Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - Adding usage of fallback white texture - Removing invalid null assignments into vectors - Removing redundant mutex preventing deletion on some platforms Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - Shame: removed forgoten #pragma optimize - Adding header complained by Android Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - removing the Hair Gem connection in the active project. - This submission removes the connection to the active project hence allowing to run without the Gem. Enable the passes in MainPipeline.pass and declare them again when you want to use the Gem. Remark: the gem file PassTemplates.azasset was renamed and will be connected via code in the future to avoid the need to declare in the global pass template. Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - registrating gem pass templates through the gem templates file (#198) * Hair - registrating gem pass templates through the gem templates file Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - adding handler disconnect for the pass template registration. Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - PPLLIndexCounter buffer going data driven via the pass declarations (#202) * Hair - PPLLIndexCounter buffer going data driven via the pass declaration - Moving PPLLIndexCounter from code allocation and attachment to be data driven - Fixed RPI typo bug that can prevent using buffers like that Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - fixing UI Editor (LYShine) crash (#209) Signed-off-by: Adi-Amazon <barlev@amazon.com> * [Hair - resolved the multi pipeline mismatches and crashes + cleaned initialization & leftovers (#222) * [Hair] - multiple render pipelines handling Signed-off-by: Adi-Amazon <barlev@amazon.com> * [Hair] - Shut down order is handle to allow hair feature processor be deregistered only after the bootstrap component has disabled it Signed-off-by: Adi-Amazon <barlev@amazon.com> * [Hair] - minor cleanups Signed-off-by: Adi-Amazon <barlev@amazon.com> * [Hair] - followups from review nits Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - code fixes based on the CR remarks for the Hair merge to Dev (#248) * Hair - First introduction of Hair gem to Atom and O3DE - The hair technology is based off TressFX 4.1 - These are some of the areas we enhanced the original TressFX implementation: - Lighting model was replaced and we now use a modified Marschner model - Blending is done directly with the back buffer removing the silhouette of the original implementation - Hair depth / thickness is now calculated to remove incorrect back lighting (TT lobe in the Marschner model) - Thickness corrected to handle hair gaps hence introducing better light passage for the TT - The hair is fully integrated into the Atom pipeline and structure design - Usage of single shared buffer for the computer buffers reduces barriers sync overhead Remarks: - Collisions via SDF compute are to be introduced soon - Improved shortcut rendering method ala Eidos Montreal to be introduced soon Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - code clean pass Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - EMFX Actor visibility implementation Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - COnnecting hair passes to Atom's MainPipeline.pass Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - adding dedicated thumbnail pipeline that does not include the hair gem Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - changed Atom shader files to allow hooking the hair to the lighting data structures Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - fixed a few headers to have the latest O3DE license + verification fixes Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - enabling editor component only when tool pipline is built + default texture add Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - fixing Linux and Android compilation builds Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - another files change to make Linux compile Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - more Linux and Android build fixes Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - Adding usage of fallback white texture - Removing invalid null assignments into vectors - Removing redundant mutex preventing deletion on some platforms Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - Shame: removed forgoten #pragma optimize - Adding header complained by Android Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - removing the Hair Gem connection in the active project. - This submission removes the connection to the active project hence allowing to run without the Gem. Enable the passes in MainPipeline.pass and declare them again when you want to use the Gem. Remark: the gem file PassTemplates.azasset was renamed and will be connected via code in the future to avoid the need to declare in the global pass template. Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - registrating gem pass templates through the gem templates file (#198) * Hair - registrating gem pass templates through the gem templates file Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - adding handler disconnect for the pass template registration. Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - PPLLIndexCounter buffer going data driven via the pass declarations (#202) * Hair - PPLLIndexCounter buffer going data driven via the pass declaration - Moving PPLLIndexCounter from code allocation and attachment to be data driven - Fixed RPI typo bug that can prevent using buffers like that Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - fixing UI Editor (LYShine) crash (#209) Signed-off-by: Adi-Amazon <barlev@amazon.com> * [Hair - resolved the multi pipeline mismatches and crashes + cleaned initialization & leftovers (#222) * [Hair] - multiple render pipelines handling Signed-off-by: Adi-Amazon <barlev@amazon.com> * [Hair] - Shut down order is handle to allow hair feature processor be deregistered only after the bootstrap component has disabled it Signed-off-by: Adi-Amazon <barlev@amazon.com> * [Hair] - minor cleanups Signed-off-by: Adi-Amazon <barlev@amazon.com> * [Hair] - followups from review nits Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - last fixes based on CR remarks Signed-off-by: Adi-Amazon <barlev@amazon.com> * Hair - fixing AR Signed-off-by: Adi-Amazon <barlev@amazon.com>
129 lines
4.9 KiB
C++
129 lines
4.9 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 <AzCore/std/smart_ptr/intrusive_ptr.h>
|
|
#include <AzCore/std/smart_ptr/intrusive_base.h>
|
|
#include <AzCore/Interface/Interface.h>
|
|
#include <AzCore/Asset/AssetCommon.h>
|
|
#include <AzCore/EBus/Event.h>
|
|
|
|
#include <AtomCore/Instance/Instance.h>
|
|
#include <Atom/RHI/Allocator.h>
|
|
|
|
namespace AZ
|
|
{
|
|
namespace RHI
|
|
{
|
|
class Buffer;
|
|
class BufferView;
|
|
}
|
|
|
|
namespace RPI
|
|
{
|
|
class BufferAsset;
|
|
class Buffer;
|
|
}
|
|
|
|
namespace Render
|
|
{
|
|
class HairSharedBufferAllocation;
|
|
|
|
//! A class for allocating memory for skinning buffers
|
|
class HairSharedBufferInterface
|
|
{
|
|
public:
|
|
AZ_RTTI(AZ::Render::HairSharedBufferInterface, "{3CCB13CB-16FF-43F5-98DC-F36B2A9F8E5E}");
|
|
|
|
HairSharedBufferInterface()
|
|
{
|
|
Interface<HairSharedBufferInterface>::Register(this);
|
|
}
|
|
|
|
virtual ~HairSharedBufferInterface()
|
|
{
|
|
Interface<HairSharedBufferInterface>::Unregister(this);
|
|
}
|
|
|
|
static HairSharedBufferInterface* Get()
|
|
{
|
|
return Interface<HairSharedBufferInterface>::Get();
|
|
}
|
|
|
|
//! Returns the shared buffer asset used for all Hair objects and passes
|
|
virtual Data::Asset<RPI::BufferAsset> GetBufferAsset() const = 0;
|
|
|
|
//! Returns the buffer that is used for all skinned mesh outputs
|
|
virtual Data::Instance<RPI::Buffer> GetBuffer() = 0;
|
|
|
|
//! If the allocation succeeds, returns a ref-counted pointer to a VirtualAddress which will be automatically freed if the ref-count drops to zero
|
|
//! If the allocation fails, returns nullptr
|
|
virtual AZStd::intrusive_ptr<HairSharedBufferAllocation> Allocate(size_t byteCount) = 0;
|
|
|
|
//! Mark the memory as available and queue garbage collection to recycle it later (see RHI::Allocator::DeAllocate)
|
|
//! After garbage collection is done signal handlers that memory has been freed
|
|
virtual void DeAllocate(RHI::VirtualAddress allocation) = 0;
|
|
|
|
//! Same as DeAllocate, but the signal after garbage collection is ignored
|
|
//! If multiple allocations succeeded before one failed, use this to release the successful allocations
|
|
//! without triggering new events indicating that new memory has been freed
|
|
virtual void DeAllocateNoSignal(RHI::VirtualAddress allocation) = 0;
|
|
|
|
//! Update buffer's content with sourceData at an offset of bufferByteOffset
|
|
virtual bool UpdateData(const void* sourceData, uint64_t sourceDataSizeInBytes, uint64_t bufferByteOffset = 0) = 0;
|
|
|
|
// Note that you have to delete these for safety reasons, you will trip a static_assert if you do not
|
|
AZ_DISABLE_COPY_MOVE(HairSharedBufferInterface);
|
|
};
|
|
|
|
class HairSharedBufferNotifications
|
|
: public AZ::EBusTraits
|
|
{
|
|
public:
|
|
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
|
|
|
|
//! This event will fire if memory is freed up, so a listener can wait for there to be free space
|
|
//! and attempt to allocate memory again if it failed initially
|
|
virtual void OnSharedBufferMemoryAvailable() = 0;
|
|
};
|
|
using SharedBufferNotificationBus = AZ::EBus<HairSharedBufferNotifications>;
|
|
|
|
//! An intrusive_ptr wrapper around an RHI::Allocation that will automatically free the memory
|
|
//! from the SharedBuffer when the ref count drops to zero
|
|
class HairSharedBufferAllocation
|
|
: public AZStd::intrusive_base
|
|
{
|
|
public:
|
|
AZ_CLASS_ALLOCATOR(HairSharedBufferAllocation, AZ::SystemAllocator, 0);
|
|
explicit HairSharedBufferAllocation(RHI::VirtualAddress virtualAddress)
|
|
: m_virtualAddress(virtualAddress)
|
|
{}
|
|
|
|
~HairSharedBufferAllocation()
|
|
{
|
|
if (!m_suppressSignalOnDeallocate)
|
|
{
|
|
HairSharedBufferInterface::Get()->DeAllocate(m_virtualAddress);
|
|
}
|
|
else
|
|
{
|
|
HairSharedBufferInterface::Get()->DeAllocateNoSignal(m_virtualAddress);
|
|
}
|
|
}
|
|
|
|
//! If this function is called, the SharedBuffer will not signal when the memory is freed
|
|
void SuppressSignalOnDeallocate() { m_suppressSignalOnDeallocate = true; }
|
|
RHI::VirtualAddress GetVirtualAddress() const { return m_virtualAddress; }
|
|
private:
|
|
RHI::VirtualAddress m_virtualAddress;
|
|
bool m_suppressSignalOnDeallocate = false;
|
|
};
|
|
} // namespace Render
|
|
} // namespace AZ
|