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>
209 lines
8.0 KiB
C++
209 lines
8.0 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 <AtomCore/Instance/InstanceData.h>
|
|
|
|
#include <Atom/RHI/ImagePool.h>
|
|
|
|
#include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
|
|
#include <Atom/RPI.Public/Image/StreamingImage.h>
|
|
#include <Atom/RPI.Public/Image/AttachmentImage.h>
|
|
#include <Atom/RPI.Public/Shader/Shader.h>
|
|
|
|
// Hair specific
|
|
#include <Rendering/SharedBuffer.h>
|
|
|
|
namespace AZ
|
|
{
|
|
namespace RHI
|
|
{
|
|
class BufferAssetView;
|
|
}
|
|
|
|
namespace RPI
|
|
{
|
|
class Buffer;
|
|
}
|
|
|
|
namespace Data
|
|
{
|
|
/**
|
|
* This is an alias of intrusive_ptr designed for any class which inherits from
|
|
* InstanceData. You're not required to use Instance<> over AZStd::intrusive_ptr<>,
|
|
* but it provides symmetry with Asset<>.
|
|
*/
|
|
template <typename T>
|
|
using Instance = AZStd::intrusive_ptr<T>;
|
|
}
|
|
|
|
namespace Render
|
|
{
|
|
namespace Hair
|
|
{
|
|
class UtilityClass
|
|
{
|
|
public:
|
|
UtilityClass() = default;
|
|
|
|
static Data::Instance<RPI::ShaderResourceGroup> CreateShaderResourceGroup(
|
|
Data::Instance<RPI::Shader> shader,
|
|
const char* shaderResourceGroupId,
|
|
const char* moduleName
|
|
);
|
|
|
|
static Data::Instance<RPI::Buffer> CreateBuffer(
|
|
const char* warningHeader,
|
|
SrgBufferDescriptor& bufferDesc,
|
|
Data::Instance<RPI::ShaderResourceGroup> srg
|
|
);
|
|
|
|
static Data::Instance<RPI::Buffer> CreateBufferAndBindToSrg(
|
|
const char* warningHeader,
|
|
SrgBufferDescriptor& bufferDesc,
|
|
Data::Instance<RPI::ShaderResourceGroup> srg
|
|
);
|
|
|
|
static bool BindBufferToSrg(
|
|
const char* warningHeader,
|
|
Data::Instance<RPI::Buffer> buffer,
|
|
SrgBufferDescriptor& bufferDesc,
|
|
Data::Instance<RPI::ShaderResourceGroup> srg=nullptr
|
|
);
|
|
|
|
static Data::Instance<RPI::StreamingImage> LoadStreamingImage(
|
|
const char* textureFilePath, [[maybe_unused]] const char* sampleName
|
|
);
|
|
|
|
static Data::Instance<RHI::ImagePool> CreateImagePool(
|
|
RHI::ImagePoolDescriptor& imagePoolDesc);
|
|
|
|
static Data::Instance<RHI::Image> CreateImage2D(
|
|
RHI::ImagePool* imagePool, RHI::ImageDescriptor& imageDesc);
|
|
};
|
|
|
|
//! The following class matches between a constant buffer structure in CPU and its counter
|
|
//! part on the GPU. It is the equivalent Atom class for TressFXUniformBuffer.
|
|
template<class TYPE>
|
|
class HairUniformBuffer
|
|
{
|
|
public:
|
|
TYPE* operator->()
|
|
{
|
|
return &m_cpuBuffer;
|
|
}
|
|
|
|
TYPE* get()
|
|
{
|
|
return &m_cpuBuffer;
|
|
}
|
|
|
|
Render::SrgBufferDescriptor& GetBufferDescriptor() { return m_bufferDesc; }
|
|
|
|
//! Use this method only if the buffer will be attached to a single Srg.
|
|
//! If this is not the case use InitForUndefinedSrg
|
|
bool InitForUniqueSrg(
|
|
Data::Instance<RPI::ShaderResourceGroup> srg,
|
|
Render::SrgBufferDescriptor& srgDesc)
|
|
{
|
|
m_srg = srg;
|
|
m_bufferDesc = srgDesc;
|
|
|
|
AZ_Error("HairUniformBuffer", m_srg, "Critical Error - no Srg was provided to bind buffer to [%s]",
|
|
m_bufferDesc.m_bufferName.GetCStr());
|
|
|
|
RHI::ShaderInputConstantIndex indexHandle = m_srg->FindShaderInputConstantIndex(m_bufferDesc.m_paramNameInSrg);
|
|
if (indexHandle.IsNull())
|
|
{
|
|
AZ_Error("HairUniformBuffer", false,
|
|
"Failed to find shader constant buffer index for [%s] in the SRG.",
|
|
m_bufferDesc.m_paramNameInSrg.GetCStr());
|
|
return false;
|
|
}
|
|
|
|
m_bufferDesc.m_resourceShaderIndex = indexHandle.GetIndex();
|
|
return true;
|
|
}
|
|
|
|
//! Updates and binds the data to the Srg and copies it to the GPU side.
|
|
//! Assumes that the buffer is uniquely attached to the saved srg.
|
|
bool UpdateGPUData()
|
|
{
|
|
if (!m_srg.get())
|
|
{
|
|
AZ_Error("HairUniformBuffer", false, "Critical Error - no Srg was provided to bind buffer to [%s]",
|
|
m_bufferDesc.m_bufferName.GetCStr());
|
|
return false;
|
|
}
|
|
|
|
RHI::ShaderInputConstantIndex constantIndex = RHI::ShaderInputConstantIndex(m_bufferDesc.m_resourceShaderIndex);
|
|
if (constantIndex.IsNull())
|
|
{
|
|
AZ_Error("HairUniformBuffer", false, "Critical Error - Srg index is not valide for [%s]",
|
|
m_bufferDesc.m_paramNameInSrg.GetCStr());
|
|
return false;
|
|
}
|
|
|
|
if (!m_srg->SetConstantRaw(constantIndex, &m_cpuBuffer, m_bufferDesc.m_elementSize))
|
|
{
|
|
AZ_Error("HairUniformBuffer", false, "Failed to bind Constant Buffer for [%s]", m_bufferDesc.m_bufferName.GetCStr());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
//! Updates Binds the data to the Srg and copies it to the GPU side.
|
|
//! Assumes that the buffer can be associated with various srgs.
|
|
bool UpdateGPUData(
|
|
Data::Instance<RPI::ShaderResourceGroup> srg,
|
|
Render::SrgBufferDescriptor& srgDesc)
|
|
{
|
|
if (!srg)
|
|
{
|
|
AZ_Error("HairUniformBuffer", srg, "Critical Error - no Srg was provided to bind buffer to [%s]",
|
|
srgDesc.m_bufferName.GetCStr());
|
|
return false;
|
|
}
|
|
|
|
RHI::ShaderInputConstantIndex indexHandle = srg->FindShaderInputConstantIndex(srgDesc.m_paramNameInSrg);
|
|
if (indexHandle.IsNull())
|
|
{
|
|
AZ_Error("HairUniformBuffer", false,
|
|
"Failed to find shader constant buffer index for [%s] in the SRG.",
|
|
srgDesc.m_paramNameInSrg.GetCStr());
|
|
return false;
|
|
}
|
|
|
|
if (!srg->SetConstantRaw(indexHandle, &m_cpuBuffer, srgDesc.m_elementSize))
|
|
{
|
|
AZ_Error("HairUniformBuffer", false, "Failed to bind Constant Buffer for [%s]", srgDesc.m_bufferName.GetCStr());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
private:
|
|
TYPE m_cpuBuffer;
|
|
|
|
//! When this srg is set as nullptr, we assume that the buffer can be shared
|
|
//! between several passes (as done for PerView and PerScene).
|
|
Data::Instance<RPI::ShaderResourceGroup> m_srg = nullptr;
|
|
|
|
Render::SrgBufferDescriptor m_bufferDesc = Render::SrgBufferDescriptor(
|
|
RPI::CommonBufferPoolType::Constant,
|
|
RHI::Format::Unknown, sizeof(TYPE), 1,
|
|
Name{"BufferNameUndefined"}, Name{"BufferNameUndefined"}, 0, 0
|
|
);
|
|
};
|
|
|
|
} // namespace Hair
|
|
} // namespace Render
|
|
} // namespace AZ
|