Files
UnrealEngineUWP/Engine/Source/Runtime/Renderer/Private/RequiredTextureResolutionRendering.cpp
danny couture 9332b64809 Prepare for the deprecation of direct access to the Resource member of UTexture in favor of the GetResource() accessor.
#rb Francis.Hurteau
#preflight 609e5182ef86d30001ad0a18
#rnx

[CL 16328103 by danny couture in ue5-main branch]
2021-05-14 07:17:32 -04:00

90 lines
3.7 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
/*=============================================================================
RequiredTextureResolutionRendering.cpp: Contains definitions for rendering the viewmode.
=============================================================================*/
#include "RequiredTextureResolutionRendering.h"
#include "RendererPrivate.h"
#include "ScenePrivate.h"
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
IMPLEMENT_MATERIAL_SHADER_TYPE(,FRequiredTextureResolutionPS,TEXT("/Engine/Private/RequiredTextureResolutionPixelShader.usf"),TEXT("Main"),SF_Pixel);
void FRequiredTextureResolutionInterface::GetDebugViewModeShaderBindings(
const FDebugViewModePS& ShaderBase,
const FPrimitiveSceneProxy* RESTRICT PrimitiveSceneProxy,
const FMaterialRenderProxy& RESTRICT MaterialRenderProxy,
const FMaterial& RESTRICT Material,
EDebugViewShaderMode DebugViewMode,
const FVector& ViewOrigin,
int32 VisualizeLODIndex,
int32 VisualizeElementIndex,
int32 NumVSInstructions,
int32 NumPSInstructions,
int32 ViewModeParam,
FName ViewModeParamName,
FMeshDrawSingleShaderBindings& ShaderBindings
) const
{
const FRequiredTextureResolutionPS& Shader = static_cast<const FRequiredTextureResolutionPS&>(ShaderBase);
int32 AnalysisIndex = INDEX_NONE;
int32 TextureResolution = 64;
FMaterialRenderContext MaterialContext(&MaterialRenderProxy, Material, nullptr);
const FUniformExpressionSet& UniformExpressions = Material.GetUniformExpressions();
if (ViewModeParam != INDEX_NONE && ViewModeParamName == NAME_None) // If displaying texture per texture indices
{
AnalysisIndex = ViewModeParam;
for (int32 ParameterIndex = 0; ParameterIndex < UniformExpressions.GetNumTextures(EMaterialTextureParameterType::Standard2D); ++ParameterIndex)
{
const FMaterialTextureParameterInfo& Parameter = UniformExpressions.GetTextureParameter(EMaterialTextureParameterType::Standard2D, ParameterIndex);
if (Parameter.TextureIndex == ViewModeParam)
{
const UTexture* Texture = nullptr;
UniformExpressions.GetTextureValue(EMaterialTextureParameterType::Standard2D, ParameterIndex, MaterialContext, Material, Texture);
if (Texture && Texture->GetResource())
{
if (Texture->IsStreamable())
{
TextureResolution = 1 << (Texture->GetResource()->GetCurrentMipCount() - 1);
}
else
{
TextureResolution = FMath::Max(Texture->GetResource()->GetSizeX(), Texture->GetResource()->GetSizeY());
}
}
}
}
}
else if (ViewModeParam != INDEX_NONE) // Otherwise show only texture matching the given name
{
AnalysisIndex = 1024; // Make sure not to find anything by default.
for (int32 ParameterIndex = 0; ParameterIndex < UniformExpressions.GetNumTextures(EMaterialTextureParameterType::Standard2D); ++ParameterIndex)
{
const UTexture* Texture = nullptr;
UniformExpressions.GetTextureValue(EMaterialTextureParameterType::Standard2D, ParameterIndex, MaterialContext, Material, Texture);
if (Texture && Texture->GetResource() && Texture->GetFName() == ViewModeParamName)
{
if (Texture->IsStreamable())
{
const FMaterialTextureParameterInfo& Parameter = UniformExpressions.GetTextureParameter(EMaterialTextureParameterType::Standard2D, ParameterIndex);
AnalysisIndex = Parameter.TextureIndex;
TextureResolution = 1 << (Texture->GetResource()->GetCurrentMipCount() - 1);
}
else
{
TextureResolution = FMath::Max(Texture->GetResource()->GetSizeX(), Texture->GetResource()->GetSizeY());
}
}
}
}
ShaderBindings.Add(Shader.AnalysisParamsParameter, FIntPoint(AnalysisIndex, TextureResolution));
ShaderBindings.Add(Shader.PrimitiveAlphaParameter, (!PrimitiveSceneProxy || PrimitiveSceneProxy->IsSelected()) ? 1.f : .2f);
}
#endif // !(UE_BUILD_SHIPPING || UE_BUILD_TEST)