diff --git a/Shaders/Private/CesiumPointAttenuationVertexFactory.ush b/Shaders/Private/CesiumPointAttenuationVertexFactory.ush index 7ec41bed4..0d639b6ff 100644 --- a/Shaders/Private/CesiumPointAttenuationVertexFactory.ush +++ b/Shaders/Private/CesiumPointAttenuationVertexFactory.ush @@ -4,6 +4,10 @@ CesiumPointAttenuationVertexFactory.ush: point attenuation vertex factory shader code. =============================================================================*/ +#ifndef ENGINE_VERSION_5_5_OR_HIGHER +#define ENGINE_VERSION_5_5_OR_HIGHER 0 +#endif + #include "/Engine/Private/Common.ush" #include "/Engine/Private/VertexFactoryCommon.ush" @@ -253,6 +257,13 @@ float4 VertexFactoryGetWorldPosition(FPositionAndNormalOnlyVertexFactoryInput In return GetWorldPosition(Input.VertexId); } +// local position relative to instance +float3 VertexFactoryGetInstanceSpacePosition(FVertexFactoryInput Input, FVertexFactoryIntermediates Intermediates) +{ + // No support for instancing, so instance == primitive + return Intermediates.Position; +} + float3 VertexFactoryGetWorldNormal(FPositionAndNormalOnlyVertexFactoryInput Input) { float3 PointNormal = GetPointNormal(Input.VertexId); @@ -275,6 +286,13 @@ float4 VertexFactoryGetPreviousWorldPosition(FVertexFactoryInput Input, FVertexF #endif } +// local position relative to instance +float3 VertexFactoryGetPreviousInstanceSpacePosition(FVertexFactoryInput Input, FVertexFactoryIntermediates Intermediates) +{ + // No support for instancing, so instance == primitive + return Intermediates.Position; +} + float4 ApplyAttenuation(float4 WorldPosition, uint CornerIndex) { // These offsets generate the quad like so: // 1 --- 2 @@ -333,9 +351,23 @@ FMaterialVertexParameters GetMaterialVertexParameters( FVertexFactoryInput Input, FVertexFactoryIntermediates Intermediates, float3 WorldPosition, - half3x3 TangentToLocal) -{ + half3x3 TangentToLocal, + bool bIsPreviousFrame = false) +{ +#if ENGINE_VERSION_5_5_OR_HIGHER + FMaterialVertexParameters Result = MakeInitializedMaterialVertexParameters(); + if (bIsPreviousFrame) + { + Result.PositionInstanceSpace = VertexFactoryGetPreviousInstanceSpacePosition(Input, Intermediates); + } + else + { + Result.PositionInstanceSpace = VertexFactoryGetInstanceSpacePosition(Input, Intermediates); + } + Result.PositionPrimitiveSpace = Result.PositionInstanceSpace; // No support for instancing, so instance == primitive +#else FMaterialVertexParameters Result = (FMaterialVertexParameters)0; +#endif Result.SceneData = Intermediates.SceneData; Result.WorldPosition = WorldPosition; @@ -353,7 +385,9 @@ FMaterialVertexParameters GetMaterialVertexParameters( Result.TexCoords[CoordinateIndex] = TexCoordBuffer[NumTexCoords * Intermediates.PointIndex + ClampedCoordinateIndex]; } #endif - + + Result.LWCData = MakeMaterialLWCData(Result); + return Result; } @@ -362,7 +396,7 @@ FMaterialVertexParameters GetMaterialVertexParameters( FVertexFactoryIntermediates Intermediates, float3 WorldPosition, half3x3 TangentToLocal, - bool noIdeaWhatThisIs) + bool bIsPreviousFrame = false) { return GetMaterialVertexParameters(Input, Intermediates, WorldPosition, TangentToLocal); } diff --git a/Source/CesiumRuntime/Private/CesiumPointAttenuationVertexFactory.cpp b/Source/CesiumRuntime/Private/CesiumPointAttenuationVertexFactory.cpp index dcf34fcbc..f62abe9f3 100644 --- a/Source/CesiumRuntime/Private/CesiumPointAttenuationVertexFactory.cpp +++ b/Source/CesiumRuntime/Private/CesiumPointAttenuationVertexFactory.cpp @@ -171,6 +171,15 @@ bool FCesiumPointAttenuationVertexFactory::ShouldCompilePermutation( Parameters.MaterialParameters.bIsSpecialEngineMaterial; } +void FCesiumPointAttenuationVertexFactory::ModifyCompilationEnvironment( + const FVertexFactoryShaderPermutationParameters& Parameters, + FShaderCompilerEnvironment& OutEnvironment) { + FLocalVertexFactory::ModifyCompilationEnvironment(Parameters, OutEnvironment); +#if ENGINE_VERSION_5_5_OR_HIGHER + OutEnvironment.SetDefine(TEXT("ENGINE_VERSION_5_5_OR_HIGHER"), TEXT("1")); +#endif +} + void FCesiumPointAttenuationVertexFactory::INIT_RHI_SIGNATURE { FVertexDeclarationElementList Elements; Elements.Add(AccessStreamComponent( diff --git a/Source/CesiumRuntime/Private/CesiumPointAttenuationVertexFactory.h b/Source/CesiumRuntime/Private/CesiumPointAttenuationVertexFactory.h index 2afe0cab6..0b09a7900 100644 --- a/Source/CesiumRuntime/Private/CesiumPointAttenuationVertexFactory.h +++ b/Source/CesiumRuntime/Private/CesiumPointAttenuationVertexFactory.h @@ -70,6 +70,10 @@ class FCesiumPointAttenuationVertexFactory : public FLocalVertexFactory { static bool ShouldCompilePermutation( const FVertexFactoryShaderPermutationParameters& Parameters); + static void ModifyCompilationEnvironment( + const FVertexFactoryShaderPermutationParameters& Parameters, + FShaderCompilerEnvironment& OutEnvironment); + private: virtual void INIT_RHI_SIGNATURE override; virtual void ReleaseRHI() override;