Files
UnrealEngineUWP/Engine/Shaders/Private/LocalVertexFactoryCommon.ush
charles derousiers 1b45feaaea Add material attributes support for hair cards & meshes.
This CLs add transfer (through voxelization or software raytracing) of strands material properties (base color, roughness), in order to get parity between the different geometric representation.

#rb none
#jira none
#preflight 61e9125cc32d25dadc28058f

#ROBOMERGE-OWNER: charles.derousiers
#ROBOMERGE-AUTHOR: charles.derousiers
#ROBOMERGE-SOURCE: CL 18672329 in //UE5/Release-5.0/... via CL 18672343 via CL 18672345
#ROBOMERGE-BOT: UE5 (Release-Engine-Test -> Main) (v901-18665521)

[CL 18672348 by charles derousiers in ue5-main branch]
2022-01-20 03:30:37 -05:00

201 lines
7.0 KiB
Plaintext

// Copyright Epic Games, Inc. All Rights Reserved.
/*=============================================================================
LocalVertexFactoryCommon.usf: Local vertex factory common functionality
=============================================================================*/
struct FVertexFactoryInterpolantsVSToPS
{
TANGENTTOWORLD_INTERPOLATOR_BLOCK
#if INTERPOLATE_VERTEX_COLOR
half4 Color : COLOR0;
#endif
#if USE_INSTANCING || USE_INSTANCE_CULLING
// x = per-instance random, y = per-instance fade out amount, z = hide/show flag, w dither fade cutoff
float4 PerInstanceParams : COLOR1;
#endif
#if NUM_TEX_COORD_INTERPOLATORS
float4 TexCoords[(NUM_TEX_COORD_INTERPOLATORS+1)/2] : TEXCOORD0;
#elif USE_PARTICLE_SUBUVS
float4 TexCoords[1] : TEXCOORD0;
#endif
#if NEEDS_LIGHTMAP_COORDINATE
float4 LightMapCoordinate : TEXCOORD4;
#endif
#if INSTANCED_STEREO
nointerpolation uint EyeIndex : PACKED_EYE_INDEX;
#endif
#if VF_USE_PRIMITIVE_SCENE_DATA
nointerpolation uint PrimitiveId : PRIMITIVE_ID;
#if NEEDS_LIGHTMAP_COORDINATE
nointerpolation uint LightmapDataIndex : LIGHTMAP_ID;
#endif
#endif
#if HAIR_STRAND_MESH_FACTORY
nointerpolation uint HairPrimitiveId : HAIR_PRIMITIVE_ID; // Control point ID
float2 HairPrimitiveUV : HAIR_PRIMITIVE_UV; // U: parameteric distance between the two surrounding control points. V: parametric distance along the width.
#endif
#if HAIR_CARD_MESH_FACTORY
float2 HairPrimitiveUV : HAIR_PRIMITIVE_UV; // Atlas UV
float2 HairPrimitiveRootUV : HAIR_PRIMITIVE_ROOTUV;// UV at the root point of the cards
float4 HairPrimitiveMaterial : HAIR_PRIMITIVE_MATERIAL;
float HairPrimitiveLength : HAIR_PRIMITIVE_LENGTH;
nointerpolation float HairPrimitiveGroupIndex : HAIR_PRIMITIVE_GROUPINDEX;
#endif
#if HAS_INSTANCE_LOCAL_TO_WORLD_PS
nointerpolation float4 InstanceLocalToWorld[3] : INSTANCE_LOCAL_TO_WORLD;
#endif
#if HAS_INSTANCE_WORLD_TO_LOCAL_PS
nointerpolation float4 InstanceWorldToLocal[3] : INSTANCE_WORLD_TO_LOCAL;
#endif
};
#if NUM_TEX_COORD_INTERPOLATORS || USE_PARTICLE_SUBUVS
float2 GetUV(FVertexFactoryInterpolantsVSToPS Interpolants, int UVIndex)
{
float4 UVVector = Interpolants.TexCoords[UVIndex / 2];
return UVIndex % 2 ? UVVector.zw : UVVector.xy;
}
void SetUV(inout FVertexFactoryInterpolantsVSToPS Interpolants, int UVIndex, float2 InValue)
{
FLATTEN
if (UVIndex % 2)
{
Interpolants.TexCoords[UVIndex / 2].zw = InValue;
}
else
{
Interpolants.TexCoords[UVIndex / 2].xy = InValue;
}
}
#endif
float4 GetColor(FVertexFactoryInterpolantsVSToPS Interpolants)
{
#if INTERPOLATE_VERTEX_COLOR
return Interpolants.Color;
#else
return 0;
#endif
}
void SetColor(inout FVertexFactoryInterpolantsVSToPS Interpolants, float4 InValue)
{
#if INTERPOLATE_VERTEX_COLOR
Interpolants.Color = InValue;
#endif
}
#if NEEDS_LIGHTMAP_COORDINATE
void GetLightMapCoordinates(FVertexFactoryInterpolantsVSToPS Interpolants, out float2 LightmapUV0, out float2 LightmapUV1, out uint LightmapDataIndex)
{
LightmapUV0 = Interpolants.LightMapCoordinate.xy * float2( 1, 0.5 );
LightmapUV1 = LightmapUV0 + float2( 0, 0.5 );
#if VF_USE_PRIMITIVE_SCENE_DATA && NEEDS_LIGHTMAP_COORDINATE
LightmapDataIndex = Interpolants.LightmapDataIndex;
#else
LightmapDataIndex = 0;
#endif
}
void GetShadowMapCoordinate(FVertexFactoryInterpolantsVSToPS Interpolants, out float2 ShadowMapCoordinate, out uint LightmapDataIndex)
{
#if VF_USE_PRIMITIVE_SCENE_DATA && NEEDS_LIGHTMAP_COORDINATE
LightmapDataIndex = Interpolants.LightmapDataIndex;
#else
LightmapDataIndex = 0;
#endif
ShadowMapCoordinate = Interpolants.LightMapCoordinate.zw;
}
void SetLightMapCoordinate(inout FVertexFactoryInterpolantsVSToPS Interpolants, float2 InLightMapCoordinate, float2 InShadowMapCoordinate)
{
Interpolants.LightMapCoordinate.xy = InLightMapCoordinate;
Interpolants.LightMapCoordinate.zw = InShadowMapCoordinate;
}
#endif
float4 GetTangentToWorld2(FVertexFactoryInterpolantsVSToPS Interpolants)
{
return Interpolants.TangentToWorld2;
}
float4 GetTangentToWorld0(FVertexFactoryInterpolantsVSToPS Interpolants)
{
return Interpolants.TangentToWorld0;
}
void SetTangents(inout FVertexFactoryInterpolantsVSToPS Interpolants, float3 InTangentToWorld0, float3 InTangentToWorld2, float InTangentToWorldSign)
{
Interpolants.TangentToWorld0 = float4(InTangentToWorld0,0);
Interpolants.TangentToWorld2 = float4(InTangentToWorld2,InTangentToWorldSign);
#if USE_WORLDVERTEXNORMAL_CENTER_INTERPOLATION
Interpolants.TangentToWorld2_Center = Interpolants.TangentToWorld2;
#endif
}
uint GetPrimitiveId(FVertexFactoryInterpolantsVSToPS Interpolants)
{
#if VF_USE_PRIMITIVE_SCENE_DATA
return Interpolants.PrimitiveId;
#else
return 0;
#endif
}
void SetPrimitiveId(inout FVertexFactoryInterpolantsVSToPS Interpolants, uint PrimitiveId)
{
#if VF_USE_PRIMITIVE_SCENE_DATA
Interpolants.PrimitiveId = PrimitiveId;
#endif
}
void SetLightmapDataIndex(inout FVertexFactoryInterpolantsVSToPS Interpolants, uint LightmapDataIndex)
{
#if VF_USE_PRIMITIVE_SCENE_DATA && NEEDS_LIGHTMAP_COORDINATE
Interpolants.LightmapDataIndex = LightmapDataIndex;
#endif
}
#if HAS_INSTANCE_LOCAL_TO_WORLD_PS
void SetInstanceLocalToWorld(inout FVertexFactoryInterpolantsVSToPS Interpolants, FLWCMatrix InstanceLocalToWorld)
{
float4x4 InstanceLocalToTranslatedWorld = LWCMultiplyTranslation(InstanceLocalToWorld, ResolvedView.PrevPreViewTranslation);
float4x4 InstanceLocalToTranslatedWorldT = transpose(InstanceLocalToTranslatedWorld);
Interpolants.InstanceLocalToWorld[0] = InstanceLocalToTranslatedWorldT[0];
Interpolants.InstanceLocalToWorld[1] = InstanceLocalToTranslatedWorldT[1];
Interpolants.InstanceLocalToWorld[2] = InstanceLocalToTranslatedWorldT[2];
}
FLWCMatrix GetInstanceLocalToWorld(FVertexFactoryInterpolantsVSToPS Interpolants)
{
float4x4 InstanceLocalToTranslatedWorld = transpose(float4x4(Interpolants.InstanceLocalToWorld[0], Interpolants.InstanceLocalToWorld[1], Interpolants.InstanceLocalToWorld[2], float4(0.0f, 0.0f, 0.0f, 1.0f)));
return LWCMultiplyTranslation(InstanceLocalToTranslatedWorld, LWCNegate(ResolvedView.PrevPreViewTranslation));
}
#endif
#if HAS_INSTANCE_WORLD_TO_LOCAL_PS
void SetInstanceWorldToLocal(inout FVertexFactoryInterpolantsVSToPS Interpolants, FLWCInverseMatrix InstanceWorldToLocal)
{
float4x4 InstanceTranslatedWorldToLocal = LWCMultiplyTranslation(LWCNegate(ResolvedView.PrevPreViewTranslation), InstanceWorldToLocal);
float4x4 InstanceTranslatedWorldToLocalT = transpose(InstanceTranslatedWorldToLocal);
Interpolants.InstanceWorldToLocal[0] = InstanceTranslatedWorldToLocalT[0];
Interpolants.InstanceWorldToLocal[1] = InstanceTranslatedWorldToLocalT[1];
Interpolants.InstanceWorldToLocal[2] = InstanceTranslatedWorldToLocalT[2];
}
FLWCInverseMatrix GetInstanceWorldToLocal(FVertexFactoryInterpolantsVSToPS Interpolants)
{
float4x4 InstanceTranslatedWorldToLocal = transpose(float4x4(Interpolants.InstanceWorldToLocal[0], Interpolants.InstanceWorldToLocal[1], Interpolants.InstanceWorldToLocal[2], float4(0.0f, 0.0f, 0.0f, 1.0f)));
return LWCMultiplyTranslation(ResolvedView.PrevPreViewTranslation, InstanceTranslatedWorldToLocal);
}
#endif