Files
UnrealEngineUWP/Engine/Shaders/Private/VisualizeShadingModels.usf
jeannoe morissette 2c1265818e Fix all cases of single scalar in shader parameter arrays to respect 16 byte alignment for Vulkan.
Add static_assert to prevent the creation of new ones moving forward.
Used SHADER_PARAMETER_SCALAR_ARRAY/GET_SCALAR_ARRAY_ELEMENT for single parameters, or packed them with surrounding parameters when possible.

#rb Guillaume.Abadie,Daniel.Wright,Charles.deRousiers
#robomerge 5.0
#preflight 61577bf15631d900011d59a1

[CL 17707027 by jeannoe morissette in ue5-main branch]
2021-10-04 09:13:24 -04:00

60 lines
1.7 KiB
Plaintext

// Copyright Epic Games, Inc. All Rights Reserved.
#include "DeferredShadingCommon.ush"
#include "PostProcessCommon.ush"
Texture2D SceneColorTexture;
SamplerState SceneColorSampler;
DECLARE_SCALAR_ARRAY(uint, ShadingModelMaskInView, 16);
void MainPS(noperspective float4 UVAndScreenPos : TEXCOORD0, float4 SvPosition : SV_POSITION, out float4 OutColor : SV_Target0)
{
float2 UV = UVAndScreenPos.xy;
int2 PixelPos = (int2)SvPosition.xy;
float3 SceneColor = Texture2DSample(SceneColorTexture, SceneColorSampler, UV).rgb;
FGBufferData GBufferData = GetGBufferData(UV);
float3 ShadingModelColor = GetShadingModelColor(GBufferData.ShadingModelID);
OutColor.xyz = ShadingModelColor * lerp(0.8f, 1.0f, Luminance(SceneColor));
{
const int2 LegendLeftTop = int2(32, 160);
const int YStep = 20;
const int ShadingModelCount = SHADINGMODELID_NUM;
const int2 LegendSize = int2(220, ShadingModelCount * YStep);
// (0, 0) .. (1, 1)
float2 InsetPx = PixelPos - LegendLeftTop;
float BorderDistance = ComputeDistanceToRect(PixelPos, LegendLeftTop, LegendSize);
float3 LegendColor = 0.25f; // dark grey
const int ShadingModelID = (InsetPx.y * ShadingModelCount) / LegendSize.y;
if (ShadingModelID < ShadingModelCount)
{
const bool bValue = GET_SCALAR_ARRAY_ELEMENT(ShadingModelMaskInView, ShadingModelID) != 0;
float3 LegendShadingModelColor = GetShadingModelColor(ShadingModelID);
if(InsetPx.x < 20)
{
LegendColor = LegendShadingModelColor;
}
else
{
LegendColor = bValue ? 0.5f : 0.2f;
}
}
// thin black border around the legend
OutColor.xyz = lerp(float3(0, 0, 0), OutColor.xyz, saturate(BorderDistance - 20));
OutColor.xyz = lerp(LegendColor, OutColor.xyz, saturate(BorderDistance - 1));
OutColor.w = 1.0f;
}
}