You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
This represents UE4/Main @17638339 and Dev-PerfTest @17636504 [CL 17668579 by aurel cordonnier in ue5-main branch]
90 lines
3.2 KiB
C++
90 lines
3.2 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
/*==============================================================================
|
|
NormalMapPreview.h: Implementation for previewing normal maps.
|
|
==============================================================================*/
|
|
|
|
#include "NormalMapPreview.h"
|
|
#include "Shader.h"
|
|
#include "GlobalShader.h"
|
|
#include "SimpleElementShaders.h"
|
|
#include "ShaderParameterUtils.h"
|
|
#include "PipelineStateCache.h"
|
|
|
|
/*------------------------------------------------------------------------------
|
|
Batched element shaders for previewing normal maps.
|
|
------------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
* Simple pixel shader that reconstructs a normal for the purposes of visualization.
|
|
*/
|
|
class FSimpleElementNormalMapPS : public FGlobalShader
|
|
{
|
|
DECLARE_SHADER_TYPE(FSimpleElementNormalMapPS,Global);
|
|
public:
|
|
|
|
/** Should the shader be cached? Always. */
|
|
static bool ShouldCompilePermutation(const FGlobalShaderPermutationParameters& Parameters)
|
|
{
|
|
return IsPCPlatform(Parameters.Platform);
|
|
}
|
|
|
|
/** Default constructor. */
|
|
FSimpleElementNormalMapPS() {}
|
|
|
|
/**
|
|
* Initialization constructor.
|
|
* @param Initializer - Shader initialization container.
|
|
*/
|
|
FSimpleElementNormalMapPS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
|
|
: FGlobalShader(Initializer)
|
|
{
|
|
Texture.Bind(Initializer.ParameterMap,TEXT("NormalMapTexture"));
|
|
TextureSampler.Bind(Initializer.ParameterMap,TEXT("NormalMapTextureSampler"));
|
|
}
|
|
|
|
/**
|
|
* Set shader parameters.
|
|
* @param NormalMapTexture - The normal map texture to sample.
|
|
*/
|
|
void SetParameters(FRHICommandList& RHICmdList, const FTexture* NormalMapTexture)
|
|
{
|
|
FRHIPixelShader* PixelShaderRHI = RHICmdList.GetBoundPixelShader();
|
|
SetTextureParameter(RHICmdList, PixelShaderRHI,Texture,TextureSampler,NormalMapTexture);
|
|
}
|
|
|
|
private:
|
|
/** The texture to sample. */
|
|
LAYOUT_FIELD(FShaderResourceParameter, Texture);
|
|
LAYOUT_FIELD(FShaderResourceParameter, TextureSampler);
|
|
};
|
|
IMPLEMENT_SHADER_TYPE(,FSimpleElementNormalMapPS,TEXT("/Engine/Private/SimpleElementNormalMapPixelShader.usf"),TEXT("Main"),SF_Pixel);
|
|
|
|
/** Binds vertex and pixel shaders for this element */
|
|
void FNormalMapBatchedElementParameters::BindShaders(
|
|
FRHICommandList& RHICmdList,
|
|
FGraphicsPipelineStateInitializer& GraphicsPSOInit,
|
|
ERHIFeatureLevel::Type InFeatureLevel,
|
|
const FMatrix& InTransform,
|
|
const float InGamma,
|
|
const FMatrix& ColorWeights,
|
|
const FTexture* Texture)
|
|
{
|
|
TShaderMapRef<FSimpleElementVS> VertexShader(GetGlobalShaderMap(InFeatureLevel));
|
|
TShaderMapRef<FSimpleElementNormalMapPS> PixelShader(GetGlobalShaderMap(InFeatureLevel));
|
|
|
|
GraphicsPSOInit.BoundShaderState.VertexDeclarationRHI = GSimpleElementVertexDeclaration.VertexDeclarationRHI;
|
|
GraphicsPSOInit.BoundShaderState.VertexShaderRHI = VertexShader.GetVertexShader();
|
|
GraphicsPSOInit.BoundShaderState.PixelShaderRHI = PixelShader.GetPixelShader();
|
|
GraphicsPSOInit.PrimitiveType = PT_TriangleList;
|
|
|
|
GraphicsPSOInit.BlendState = TStaticBlendState<>::GetRHI();
|
|
|
|
RHICmdList.ApplyCachedRenderTargets(GraphicsPSOInit);
|
|
SetGraphicsPipelineState(RHICmdList, GraphicsPSOInit, 0);
|
|
|
|
VertexShader->SetParameters(RHICmdList, InTransform);
|
|
PixelShader->SetParameters(RHICmdList, Texture);
|
|
}
|
|
|