Ok. then my follow up is that the vertex data I am being given (again, the code is not originally mine, so I am trying to understand it, and the tangent stuff is new to me) My vertices have two TangentBasisComponents that look as follows:
NewData.PositionComponent = STRUCTMEMBER_VERTEXSTREAMCOMPONENT(&VertexBuffer, FBrickVertex, X, VET_UByte4N);
NewData.TextureCoordinates.Add(STRUCTMEMBER_VERTEXSTREAMCOMPONENT(&VertexBuffer, FBrickVertex, X, VET_UByte4N));
NewData.ColorComponent = STRUCTMEMBER_VERTEXSTREAMCOMPONENT(&VertexBuffer, FBrickVertex, X, VET_Color);
// Use a stride of 0 to use the same TangentX/TangentZ for all faces using this vertex factory.
NewData.TangentBasisComponents = FVertexStreamComponent(&TangentBuffer,sizeof(FPackedNormal) * (2 * FaceIndex + 0),0,VET_PackedNormal);
NewData.TangentBasisComponents = FVertexStreamComponent(&TangentBuffer,sizeof(FPackedNormal) * (2 * FaceIndex + 1),0,VET_PackedNormal);
Where tangent data comes from code that looks as follows:
for(int32 FaceIndex = 0;FaceIndex < 6;++FaceIndex)
const FVector UnprojectedTangentX = FVector(+1,-1,0).GetSafeNormal();
const FVector UnprojectedTangentY(-1,-1,-1);
const FVector FaceNormal = FaceNormals[FaceIndex].ToFloat();
const FVector ProjectedFaceTangentX = (UnprojectedTangentX - FaceNormal * (UnprojectedTangentX | FaceNormal)).GetSafeNormal();
*TangentBufferData++ = FPackedNormal(ProjectedFaceTangentX);
*TangentBufferData++ = FPackedNormal(FVector4(FaceNormal, FMath::Sign(UnprojectedTangentY | (FaceNormal ^ ProjectedFaceTangentX))));
I originally thought this was a substitute for regular face normals, but now I am thinking that the tangent basis is actually a separate thing, and if I want my normal maps to work correctly, I need to combine these values with the normal map (in tangent space) before passing the normal map data on to the Material parameters. Could you either explain to me or point me to some documentation that shows up to do this in the UE material shader? There doesn’t seem to be any official documentation on how this is dealt with in UE, and my shader skills are still fairly weak. I appreciate your time and patience.