Files
UnrealEngineUWP/Engine/Source/Editor/UnrealEd/Private/NormalMapPreview.cpp
Ben Marsh 149375b14b Update copyright notices to 2015.
[CL 2379638 by Ben Marsh in Main branch]
2014-12-07 19:09:38 -05:00

98 lines
3.1 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
/*==============================================================================
NormalMapPreview.h: Implementation for previewing normal maps.
==============================================================================*/
#include "UnrealEd.h"
#include "NormalMapPreview.h"
#include "SimpleElementShaders.h"
#include "GlobalShader.h"
#include "ShaderParameters.h"
#include "ShaderParameterUtils.h"
#include "RHIStaticStates.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 ShouldCache(EShaderPlatform Platform)
{
return true;
}
/** 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("SimpleElementNormalMapPixelShader"),TEXT("Main"),SF_Pixel);
/** Binds vertex and pixel shaders for this element */
void FNormalMapBatchedElementParameters::BindShaders(
FRHICommandList& RHICmdList,
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));
static FGlobalBoundShaderState BoundShaderState;
SetGlobalBoundShaderState(RHICmdList, InFeatureLevel, BoundShaderState, GSimpleElementVertexDeclaration.VertexDeclarationRHI, *VertexShader, *PixelShader);
VertexShader->SetParameters(RHICmdList, InTransform);
PixelShader->SetParameters(RHICmdList, Texture);
RHICmdList.SetBlendState(TStaticBlendState<>::GetRHI());
}