Skip to content

Commit

Permalink
Add define to point cloud vertex factory
Browse files Browse the repository at this point in the history
  • Loading branch information
j9liu committed Nov 22, 2024
1 parent 3a205ce commit 4e12866
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
42 changes: 38 additions & 4 deletions Shaders/Private/CesiumPointAttenuationVertexFactory.ush
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -353,7 +385,9 @@ FMaterialVertexParameters GetMaterialVertexParameters(
Result.TexCoords[CoordinateIndex] = TexCoordBuffer[NumTexCoords * Intermediates.PointIndex + ClampedCoordinateIndex];
}
#endif


Result.LWCData = MakeMaterialLWCData(Result);

return Result;
}

Expand All @@ -362,7 +396,7 @@ FMaterialVertexParameters GetMaterialVertexParameters(
FVertexFactoryIntermediates Intermediates,
float3 WorldPosition,
half3x3 TangentToLocal,
bool noIdeaWhatThisIs)
bool bIsPreviousFrame = false)
{
return GetMaterialVertexParameters(Input, Intermediates, WorldPosition, TangentToLocal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4e12866

Please sign in to comment.