Reenable LyShine mask support now using Atom (#1218)
* Add option to set stencil ref in Dynamic Draw Context * Add depth/stencil attachment slot to UI pass * Rework mask rendering to use Atom * Add missing circle mask image
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
#include <Atom/Bootstrap/DefaultWindowBus.h>
|
||||
#include <Atom/RPI.Public/ViewportContextBus.h>
|
||||
#include <Atom/RPI.Public/RenderPipeline.h>
|
||||
#include <IRenderer.h> // LYSHINE_ATOM_TODO - remove when GS_DEPTHFUNC_LEQUAL reference is removed with LyShine render target Atom conversion
|
||||
|
||||
#include <AzCore/Math/MatrixUtils.h>
|
||||
#include <AzCore/Debug/Trace.h>
|
||||
@@ -33,9 +32,7 @@
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
UiRenderer::UiRenderer(AZ::RPI::ViewportContextPtr viewportContext)
|
||||
: m_baseState(GS_DEPTHFUNC_LEQUAL)
|
||||
, m_stencilRef(0)
|
||||
, m_viewportContext(viewportContext)
|
||||
: m_viewportContext(viewportContext)
|
||||
{
|
||||
// Use bootstrap scene event to indicate when the RPI has fully
|
||||
// initialized with all assets loaded and is ready to be used
|
||||
@@ -127,6 +124,8 @@ void UiRenderer::CreateDynamicDrawContext(AZ::RPI::ScenePtr scene, AZ::Data::Ins
|
||||
{ "TEXCOORD", AZ::RHI::Format::R32G32_FLOAT },
|
||||
{ "BLENDINDICES", AZ::RHI::Format::R16G16_UINT } }
|
||||
);
|
||||
m_dynamicDraw->AddDrawStateOptions(AZ::RPI::DynamicDrawContext::DrawStateOptions::StencilState
|
||||
| AZ::RPI::DynamicDrawContext::DrawStateOptions::BlendMode);
|
||||
m_dynamicDraw->EndInit();
|
||||
}
|
||||
|
||||
@@ -170,25 +169,24 @@ void UiRenderer::CacheShaderData(const AZ::RHI::Ptr<AZ::RPI::DynamicDrawContext>
|
||||
shaderOptionsDefault.push_back(AZ::RPI::ShaderOption(AZ::Name("o_srgbWrite"), AZ::Name("true")));
|
||||
shaderOptionsDefault.push_back(AZ::RPI::ShaderOption(AZ::Name("o_modulate"), AZ::Name("Modulate::None")));
|
||||
m_uiShaderData.m_shaderVariantDefault = dynamicDraw->UseShaderVariant(shaderOptionsDefault);
|
||||
AZ::RPI::ShaderOptionList shaderOptionsAlphaTest;
|
||||
shaderOptionsAlphaTest.push_back(AZ::RPI::ShaderOption(AZ::Name("o_preMultiplyAlpha"), AZ::Name("false")));
|
||||
shaderOptionsAlphaTest.push_back(AZ::RPI::ShaderOption(AZ::Name("o_alphaTest"), AZ::Name("true")));
|
||||
shaderOptionsAlphaTest.push_back(AZ::RPI::ShaderOption(AZ::Name("o_srgbWrite"), AZ::Name("true")));
|
||||
shaderOptionsAlphaTest.push_back(AZ::RPI::ShaderOption(AZ::Name("o_modulate"), AZ::Name("Modulate::None")));
|
||||
m_uiShaderData.m_shaderVariantAlphaTest = dynamicDraw->UseShaderVariant(shaderOptionsAlphaTest);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void UiRenderer::BeginUiFrameRender()
|
||||
{
|
||||
#ifdef LYSHINE_ATOM_TODO
|
||||
m_renderer = gEnv->pRenderer;
|
||||
|
||||
// we are rendering at the end of the frame, after tone mapping, so we should be writing sRGB values
|
||||
m_renderer->SetSrgbWrite(true);
|
||||
|
||||
#ifndef _RELEASE
|
||||
if (m_debugTextureDataRecordLevel > 0)
|
||||
{
|
||||
m_texturesUsedInFrame.clear();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
// Various platform drivers expect all texture slots used in the shader to be bound
|
||||
BindNullTexture();
|
||||
}
|
||||
@@ -204,18 +202,10 @@ void UiRenderer::EndUiFrameRender()
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void UiRenderer::BeginCanvasRender()
|
||||
{
|
||||
#ifdef LYSHINE_ATOM_TODO
|
||||
m_baseState = GS_NODEPTHTEST;
|
||||
|
||||
m_stencilRef = 0;
|
||||
|
||||
// Set default starting state
|
||||
IRenderer* renderer = gEnv->pRenderer;
|
||||
|
||||
renderer->SetCullMode(R_CULL_DISABLE);
|
||||
renderer->SetColorOp(eCO_MODULATE, eCO_MODULATE, DEF_TEXARG0, DEF_TEXARG0);
|
||||
renderer->SetState(GS_BLSRC_SRCALPHA | GS_BLDST_ONEMINUSSRCALPHA | GS_NODEPTHTEST);
|
||||
#endif
|
||||
// Set base state
|
||||
m_baseState.ResetToDefault();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -229,11 +219,13 @@ AZ::RHI::Ptr<AZ::RPI::DynamicDrawContext> UiRenderer::GetDynamicDrawContext()
|
||||
return m_dynamicDraw;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
const UiRenderer::UiShaderData& UiRenderer::GetUiShaderData()
|
||||
{
|
||||
return m_uiShaderData;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
AZ::Matrix4x4 UiRenderer::GetModelViewProjectionMatrix()
|
||||
{
|
||||
auto viewportContext = GetViewportContext();
|
||||
@@ -253,6 +245,7 @@ AZ::Matrix4x4 UiRenderer::GetModelViewProjectionMatrix()
|
||||
return modelViewProjMat;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
AZ::Vector2 UiRenderer::GetViewportSize()
|
||||
{
|
||||
auto viewportContext = GetViewportContext();
|
||||
@@ -267,17 +260,30 @@ AZ::Vector2 UiRenderer::GetViewportSize()
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
int UiRenderer::GetBaseState()
|
||||
UiRenderer::BaseState UiRenderer::GetBaseState()
|
||||
{
|
||||
return m_baseState;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void UiRenderer::SetBaseState(int state)
|
||||
void UiRenderer::SetBaseState(BaseState state)
|
||||
{
|
||||
m_baseState = state;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
AZ::RPI::ShaderVariantId UiRenderer::GetCurrentShaderVariant()
|
||||
{
|
||||
AZ::RPI::ShaderVariantId variantId = m_uiShaderData.m_shaderVariantDefault;
|
||||
|
||||
if (m_baseState.m_useAlphaTest)
|
||||
{
|
||||
variantId = m_uiShaderData.m_shaderVariantAlphaTest;
|
||||
}
|
||||
|
||||
return variantId;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
uint32 UiRenderer::GetStencilRef()
|
||||
{
|
||||
@@ -354,6 +360,7 @@ void UiRenderer::DebugDisplayTextureData(int recordingOption)
|
||||
{
|
||||
if (recordingOption > 0)
|
||||
{
|
||||
#ifdef LYSHINE_ATOM_TODO // Convert debug to use Atom images
|
||||
// compute the total area of all the textures, also create a vector that we can sort by area
|
||||
AZStd::vector<ITexture*> textures;
|
||||
int totalArea = 0;
|
||||
@@ -431,6 +438,7 @@ void UiRenderer::DebugDisplayTextureData(int recordingOption)
|
||||
texture->GetWidth(), texture->GetHeight(), texture->GetDataSize(), texture->GetFormatName(), texture->GetName());
|
||||
WriteLine(buffer, white);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user