You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
optimized shaders to use SvPosition where possible, following change could remove some unused interpolator [CL 2697164 by Martin Mittring in Main branch]
94 lines
3.9 KiB
Plaintext
94 lines
3.9 KiB
Plaintext
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
|
|
|
|
/*=============================================================================
|
|
BasePassVertexShader.usf: Base pass vertex shader
|
|
=============================================================================*/
|
|
|
|
#include "BasePassVertexCommon.usf"
|
|
|
|
#if WRITES_VELOCITY_TO_GBUFFER
|
|
//@todo-rco: Move to pixel shader
|
|
float SkipOutputVelocity;
|
|
#endif
|
|
|
|
/** Entry point for the base pass vertex shader. */
|
|
void Main(
|
|
FVertexFactoryInput Input,
|
|
OPTIONAL_VertexID
|
|
out FBasePassVSOutput Output
|
|
)
|
|
{
|
|
FVertexFactoryIntermediates VFIntermediates = GetVertexFactoryIntermediates(Input);
|
|
float4 WorldPositionExcludingWPO = VertexFactoryGetWorldPosition(Input, VFIntermediates);
|
|
float4 WorldPosition = WorldPositionExcludingWPO;
|
|
|
|
float3x3 TangentToLocal = VertexFactoryGetTangentToLocal(Input, VFIntermediates);
|
|
FMaterialVertexParameters VertexParameters = GetMaterialVertexParameters(Input, VFIntermediates, WorldPosition.xyz, TangentToLocal);
|
|
|
|
// Isolate instructions used for world position offset
|
|
// As these cause the optimizer to generate different position calculating instructions in each pass, resulting in self-z-fighting.
|
|
// This is only necessary for shaders used in passes that have depth testing enabled.
|
|
ISOLATE
|
|
{
|
|
WorldPosition.xyz += GetMaterialWorldPositionOffset(VertexParameters);
|
|
}
|
|
|
|
#if USING_TESSELLATION
|
|
// We let the Domain Shader convert to post projection when tessellating
|
|
Output.Position = WorldPosition;
|
|
|
|
#if USE_WORLD_POSITION_EXCLUDING_SHADER_OFFSETS
|
|
Output.BasePassInterpolants.WorldPositionExcludingWPO = WorldPositionExcludingWPO.xyz;
|
|
#endif
|
|
#else
|
|
ISOLATE
|
|
{
|
|
float4 RasterizedWorldPosition = VertexFactoryGetRasterizedWorldPosition(Input, VFIntermediates, WorldPosition);
|
|
Output.Position = mul(RasterizedWorldPosition, View.TranslatedWorldToClip);
|
|
}
|
|
|
|
#if USE_WORLD_POSITION_EXCLUDING_SHADER_OFFSETS
|
|
Output.BasePassInterpolants.PixelPositionExcludingWPO = WorldPositionExcludingWPO;
|
|
#endif
|
|
#endif // USING_TESSELLATION
|
|
|
|
Output.FactoryInterpolants = VertexFactoryGetInterpolants(Input, VFIntermediates, VertexParameters);
|
|
|
|
// Calculate the fog needed for translucency
|
|
#if NEEDS_BASEPASS_FOGGING
|
|
#if BASEPASS_ATMOSPHERIC_FOG
|
|
Output.BasePassInterpolants.VertexFog = CalculateVertexAtmosphericFog(WorldPosition.xyz, View.TranslatedWorldCameraOrigin);
|
|
#else
|
|
Output.BasePassInterpolants.VertexFog = CalculateVertexHeightFog(WorldPosition.xyz, float4(View.TranslatedWorldCameraOrigin, 1));
|
|
#endif
|
|
#endif
|
|
|
|
#if WRITES_VELOCITY_TO_GBUFFER
|
|
{
|
|
float4 PrevTranslatedWorldPosition = VertexFactoryGetPreviousWorldPosition( Input, VFIntermediates );
|
|
VertexParameters = GetMaterialVertexParameters(Input, VFIntermediates, PrevTranslatedWorldPosition.xyz, TangentToLocal);
|
|
PrevTranslatedWorldPosition.xyz += GetMaterialPreviousWorldPositionOffset(VertexParameters);
|
|
|
|
#if USING_TESSELLATION
|
|
// We let the Domain Shader convert to post projection when tessellating
|
|
Output.BasePassInterpolants.VelocityPrevScreenPosition = PrevTranslatedWorldPosition;
|
|
// Store the mask in .w when doing tessellation as we need the world space Z
|
|
Output.BasePassInterpolants.VelocityPrevScreenPosition.w = 1 - SkipOutputVelocity;
|
|
#if WRITES_VELOCITY_TO_GBUFFER_USE_POS_INTERPOLATOR
|
|
Output.BasePassInterpolants.VelocityScreenPosition = WorldPosition;
|
|
#endif
|
|
#else
|
|
// compute the old screen pos with the old world position and the old camera matrix
|
|
Output.BasePassInterpolants.VelocityPrevScreenPosition = mul(float4(PrevTranslatedWorldPosition.xyz, 1), View.PrevTranslatedWorldToClip);
|
|
// Store the mask in .z when as we don't need the clip space Z
|
|
Output.BasePassInterpolants.VelocityPrevScreenPosition.z = 1 - SkipOutputVelocity;
|
|
#if WRITES_VELOCITY_TO_GBUFFER_USE_POS_INTERPOLATOR
|
|
Output.BasePassInterpolants.VelocityScreenPosition = Output.Position;
|
|
#endif
|
|
#endif // USING_TESSELLATION
|
|
}
|
|
#endif // WRITES_VELOCITY_TO_GBUFFER
|
|
|
|
OutputVertexID( Output );
|
|
}
|