Hair - fixing per object UI control per object (#4507)

- Deferred material array index was not passed every frame (the objects' material array is built during the frame)

Signed-off-by: Adi-Amazon <barlev@amazon.com>
monroegm-disable-blank-issue-2
Adi Bar-Lev 4 years ago committed by GitHub
parent 8f1a589fcf
commit 15ecf3c65a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -226,27 +226,34 @@ namespace AZ
// Prepare materials array for the per pass srg
std::vector<const AMD::TressFXRenderParams*> hairObjectsRenderMaterials;
uint32_t obj = 0;
for (auto objIter = m_hairRenderObjects.begin(); objIter != m_hairRenderObjects.end(); ++objIter, ++obj)
uint32_t objectIndex = 0;
for (auto& renderObject : m_hairRenderObjects)
{
HairRenderObject* renderObject = objIter->get();
if (!renderObject->IsEnabled())
{
continue;
}
renderObject->Update();
renderObject->SetRenderIndex(objectIndex);
// [To Do] Hair - update the following parameters for dynamic LOD control
// should change or when parameters are being changed on the editor side.
// float Distance = sqrtf( m_activeScene.scene->GetCameraPos().x * m_activeScene.scene->GetCameraPos().x +
// m_activeScene.scene->GetCameraPos().y * m_activeScene.scene->GetCameraPos().y +
// m_activeScene.scene->GetCameraPos().z * m_activeScene.scene->GetCameraPos().z);
// objIter->get()->UpdateRenderingParameters(
// renderingSettings, m_nScreenWidth * m_nScreenHeight * AVE_FRAGS_PER_PIXEL, m_deltaTime, Distance);
const float distanceFromCamera = 1.0f; // fixed distance until LOD mechanism is worked on
const float updateShadows = false; // same here - currently cheap self shadow approx
renderObject->UpdateRenderingParameters( nullptr, RESERVED_PIXELS_FOR_OIT, distanceFromCamera, updateShadows);
// this will be used for the constant buffer
// this will be used in the constant buffer to set the material array used by the resolve pass
hairObjectsRenderMaterials.push_back(renderObject->GetHairRenderParams());
// The data update for the GPU bind - this should be the very last thing done after the
// data has been read and / or altered on the CPU side.
renderObject->Update();
++objectIndex;
}
FillHairMaterialsArray(hairObjectsRenderMaterials);
}
@ -532,4 +539,3 @@ namespace AZ
} // namespace Hair
} // namespace Render
} // namespace AZ

@ -878,6 +878,11 @@ namespace AZ
const AMD::TressFXRenderingSettings* parameters, const int nodePoolSize,
float distance, bool shadowUpdate /*= false*/)
{
if (!parameters)
{
parameters = m_renderSettings;
}
// Update Render Parameters
// If you alter FiberRadius make sure to change it also in the material properties
// passed by the Feature Processor for the shading.
@ -888,7 +893,7 @@ namespace AZ
// original TressFX lighting parameters - two specular lobes approximating
// the Marschner R and and TRT lobes + diffuse component.
m_renderCB->MatKValue = {{{0.f, parameters->m_HairKDiffuse, parameters->m_HairKSpec1, parameters->m_HairSpecExp1}}};
m_renderCB->MatKValue = { {{0.f, parameters->m_HairKDiffuse, parameters->m_HairKSpec1, parameters->m_HairSpecExp1}} };
m_renderCB->HairKs2 = parameters->m_HairKSpec2;
m_renderCB->HairEx2 = parameters->m_HairSpecExp2;
@ -903,11 +908,13 @@ namespace AZ
m_strandCB->TipPercentage = parameters->m_TipPercentage;
m_strandCB->StrandUVTilingFactor = parameters->m_StrandUVTilingFactor;
m_strandCB->FiberRatio = parameters->m_FiberRatio;
m_strandCB->EnableThinTip = parameters->m_EnableThinTip;
m_strandCB->EnableStrandUV = parameters->m_EnableStrandUV;
// Reset LOD hair density for the frame
m_LODHairDensity = 1.f;
float fiberRadius = parameters->m_FiberRadius;
float FiberRadius = parameters->m_FiberRadius;
if (parameters->m_EnableHairLOD)
{
float MinLODDist = shadowUpdate ?
@ -922,23 +929,18 @@ namespace AZ
float DistanceRatio = AZStd::min((distance - MinLODDist) / AZStd::max(MaxLODDist - MinLODDist, 0.00001f), 1.f);
// Lerp: x + s(y-x)
float MaxLODFiberRadius = FiberRadius * (shadowUpdate ? parameters->m_ShadowLODWidthMultiplier : parameters->m_LODWidthMultiplier);
FiberRadius = FiberRadius + (DistanceRatio * (MaxLODFiberRadius - FiberRadius));
float MaxLODFiberRadius = fiberRadius * (shadowUpdate ? parameters->m_ShadowLODWidthMultiplier : parameters->m_LODWidthMultiplier);
fiberRadius = fiberRadius + (DistanceRatio * (MaxLODFiberRadius - fiberRadius));
// Lerp: x + s(y-x)
m_LODHairDensity = 1.f + (DistanceRatio * ((shadowUpdate ? parameters->m_ShadowLODPercent : parameters->m_LODPercent) - 1.f));
}
}
m_strandCB->FiberRadius = FiberRadius;
m_strandCB->NumVerticesPerStrand = m_NumVerticesPerStrand; // Always constant
m_strandCB->EnableThinTip = parameters->m_EnableThinTip;
m_strandCB->FiberRadius = fiberRadius;
m_strandCB->NumVerticesPerStrand = m_NumVerticesPerStrand; // Constant through the run per object
m_strandCB->NodePoolSize = nodePoolSize;
m_strandCB->RenderParamsIndex = m_RenderIndex; // Always constant
m_strandCB->EnableStrandUV = parameters->m_EnableStrandUV;
m_strandCB->EnableStrandTangent = parameters->m_EnableStrandTangent;
m_strandCB->RenderParamsIndex = m_RenderIndex; // Per Objects specific according to its index in the FP
}
//!=====================================================================================
@ -977,8 +979,10 @@ namespace AZ
UpdateSimulationParameters(simSettings, SIMULATION_TIME_STEP);
// [To Do] Hair - change to be dynamically calculated
const float distanceFromCamera = 1.0;
const float distanceFromCamera = 1.0f;
const float updateShadows = false;
m_renderSettings = renderSettings;
m_simSettings = simSettings;
UpdateRenderingParameters(renderSettings, RESERVED_PIXELS_FOR_OIT, distanceFromCamera, updateShadows);
if (!GetShaders())

@ -269,6 +269,7 @@ namespace AZ
void UpdateSimulationParameters(const AMD::TressFXSimulationSettings* settings, float timeStep);
void SetWind(const Vector3& windDir, float windMag, int frame);
void SetRenderIndex(uint32_t renderIndex) { m_RenderIndex = renderIndex; }
void ResetPositions() { m_simCB->g_ResetPositions = 1.0f; }
void IncreaseSimulationFrame()
@ -315,6 +316,10 @@ namespace AZ
float m_frameDeltaTime = 0.02;
//! The following are the configuration settings that might be required during the update.
AMD::TressFXSimulationSettings* m_simSettings = nullptr;
AMD::TressFXRenderingSettings* m_renderSettings = nullptr;
//! Hair asset information
uint32_t m_TotalIndices = 0;
uint32_t m_NumTotalVertices = 0;
@ -331,7 +336,7 @@ namespace AZ
//! Controls reset / copy base hair state
uint32_t m_SimulationFrame = 0;
// [To Do] - verify if still required
//! The index used as a look up into the material array during the resolve pass
uint32_t m_RenderIndex = 0;
//!-----------------------------------------------------------------

Loading…
Cancel
Save