You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#rb none Should be just copyright updates [CL 4680440 by Marcus Wassmer in Dev-Rendering branch]
101 lines
3.5 KiB
C++
101 lines
3.5 KiB
C++
// Copyright 1998-2019 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 !IsConsolePlatform(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)
|
|
{
|
|
FPixelShaderRHIParamRef PixelShaderRHI = GetPixelShader();
|
|
SetTextureParameter(RHICmdList, PixelShaderRHI,Texture,TextureSampler,NormalMapTexture);
|
|
}
|
|
|
|
/**
|
|
* Serialization.
|
|
* @param Ar - The archive with which to serialize.
|
|
*/
|
|
virtual bool Serialize(FArchive& Ar) override
|
|
{
|
|
bool bShaderHasOutdatedParameters = FGlobalShader::Serialize(Ar);
|
|
Ar << Texture;
|
|
Ar << TextureSampler;
|
|
return bShaderHasOutdatedParameters;
|
|
}
|
|
|
|
private:
|
|
/** The texture to sample. */
|
|
FShaderResourceParameter Texture;
|
|
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 = GETSAFERHISHADER_VERTEX(*VertexShader);
|
|
GraphicsPSOInit.BoundShaderState.PixelShaderRHI = GETSAFERHISHADER_PIXEL(*PixelShader);
|
|
GraphicsPSOInit.PrimitiveType = PT_TriangleList;
|
|
|
|
GraphicsPSOInit.BlendState = TStaticBlendState<>::GetRHI();
|
|
|
|
SetGraphicsPipelineState(RHICmdList, GraphicsPSOInit, EApplyRendertargetOption::ForceApply);
|
|
|
|
VertexShader->SetParameters(RHICmdList, InTransform);
|
|
PixelShader->SetParameters(RHICmdList, Texture);
|
|
}
|
|
|