You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
- Renaming SetAllShaderParametersXX to SetShaderParametersLegacyXX. - Renaming UnsetAllShaderParametersXX to UnsetShaderParametersLegacyXX. - Adding SetShaderParametersMixedXX which sets both legacy and new style (struct) shader parameters. - Converted NaniteCullRaster to use SetShaderParametersMixed. #preflight 63e537846f2d2f619ac39f07 [CL 24103864 by christopher waters in ue5-main branch]
91 lines
3.2 KiB
C++
91 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"
|
|
#include "RHIStaticStates.h"
|
|
#include "DataDrivenShaderPlatformInfo.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(FRHIBatchedShaderParameters& BatchedParameters, const FTexture* NormalMapTexture)
|
|
{
|
|
SetTextureParameter(BatchedParameters, 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);
|
|
|
|
SetShaderParametersLegacyVS(RHICmdList, VertexShader, InTransform);
|
|
SetShaderParametersLegacyPS(RHICmdList, PixelShader, Texture);
|
|
}
|
|
|