2019-12-26 23:06:02 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
#include "Landscape.h"
|
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3209340 on 2016/11/23 by Ben.Marsh
Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h.
Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms.
* Every header now includes everything it needs to compile.
* There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first.
* There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h.
* Every .cpp file includes its matching .h file first.
* This helps validate that each header is including everything it needs to compile.
* No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more.
* You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there.
* There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible.
* No engine code explicitly includes a precompiled header any more.
* We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies.
* PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files.
Tool used to generate this transform is at Engine\Source\Programs\IncludeTool.
[CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
|
|
|
#include "Importer.h"
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
namespace Lightmass
|
|
|
|
|
{
|
|
|
|
|
// Accessors from FLandscapeDataInterface
|
|
|
|
|
void FLandscapeStaticLightingMesh::VertexIndexToXY(int32 VertexIndex, int32& OutX, int32& OutY) const
|
|
|
|
|
{
|
|
|
|
|
OutX = VertexIndex % NumVertices;
|
|
|
|
|
OutY = VertexIndex / NumVertices;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FLandscapeStaticLightingMesh::QuadIndexToXY(int32 QuadIndex, int32& OutX, int32& OutY) const
|
|
|
|
|
{
|
|
|
|
|
OutX = QuadIndex % NumQuads;
|
|
|
|
|
OutY = QuadIndex / NumQuads;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FColor* FLandscapeStaticLightingMesh::GetHeightData( int32 LocalX, int32 LocalY ) const
|
|
|
|
|
{
|
|
|
|
|
return &HeightMap[LocalX + LocalY * NumVertices ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FLandscapeStaticLightingMesh::GetTriangleIndices(int32 QuadIndex,int32 TriNum,int32& OutI0,int32& OutI1,int32& OutI2) const
|
|
|
|
|
{
|
|
|
|
|
//OutI0 = 0; OutI1 = 1; OutI2 = 2;
|
|
|
|
|
int32 QuadX, QuadY;
|
|
|
|
|
QuadIndexToXY( QuadIndex, QuadX, QuadY );
|
|
|
|
|
switch(TriNum)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
OutI0 = (QuadX + 0) + (QuadY + 0) * NumVertices;
|
|
|
|
|
OutI1 = (QuadX + 1) + (QuadY + 1) * NumVertices;
|
|
|
|
|
OutI2 = (QuadX + 1) + (QuadY + 0) * NumVertices;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
OutI0 = (QuadX + 0) + (QuadY + 0) * NumVertices;
|
|
|
|
|
OutI1 = (QuadX + 0) + (QuadY + 1) * NumVertices;
|
|
|
|
|
OutI2 = (QuadX + 1) + (QuadY + 1) * NumVertices;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-08-13 09:48:15 -04:00
|
|
|
|
|
|
|
|
if (bReverseWinding)
|
|
|
|
|
{
|
|
|
|
|
Swap(OutI1, OutI2);
|
|
|
|
|
}
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// from FStaticLightMesh....
|
|
|
|
|
void FLandscapeStaticLightingMesh::GetStaticLightingVertex(int32 VertexIndex, FStaticLightingVertex& OutVertex) const
|
|
|
|
|
{
|
|
|
|
|
int32 X, Y;
|
|
|
|
|
VertexIndexToXY(VertexIndex, X, Y);
|
|
|
|
|
|
2015-01-29 11:45:50 -05:00
|
|
|
const int32 LocalX = X - ExpandQuadsX;
|
|
|
|
|
const int32 LocalY = Y - ExpandQuadsY;
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
const FColor* Data = GetHeightData( X, Y );
|
|
|
|
|
|
2015-01-29 11:45:50 -05:00
|
|
|
OutVertex.WorldTangentZ.X = 2.0f / 255.f * (float)Data->B - 1.0f;
|
|
|
|
|
OutVertex.WorldTangentZ.Y = 2.0f / 255.f * (float)Data->A - 1.0f;
|
|
|
|
|
OutVertex.WorldTangentZ.Z = FMath::Sqrt(FMath::Max(1.0f - (FMath::Square(OutVertex.WorldTangentZ.X) + FMath::Square(OutVertex.WorldTangentZ.Y)), 0.f));
|
2021-11-22 22:06:39 -05:00
|
|
|
OutVertex.WorldTangentX = FVector4f(OutVertex.WorldTangentZ.Z, 0.0f, -OutVertex.WorldTangentZ.X);
|
2014-03-14 14:13:41 -04:00
|
|
|
OutVertex.WorldTangentY = OutVertex.WorldTangentZ ^ OutVertex.WorldTangentX;
|
|
|
|
|
|
2015-01-29 11:45:50 -05:00
|
|
|
// Copied (vaguely) from FLandscapeComponentDataInterface::GetWorldPositionTangents to fix bad lighting when rotated
|
2021-11-22 22:06:39 -05:00
|
|
|
const FMatrix44f LtWNoScale = LocalToWorld.GetMatrixWithoutScale();
|
2015-01-29 11:45:50 -05:00
|
|
|
OutVertex.WorldTangentX = LtWNoScale.TransformVector(OutVertex.WorldTangentX);
|
|
|
|
|
OutVertex.WorldTangentY = LtWNoScale.TransformVector(OutVertex.WorldTangentY);
|
|
|
|
|
OutVertex.WorldTangentZ = LtWNoScale.TransformVector(OutVertex.WorldTangentZ);
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2015-01-29 11:45:50 -05:00
|
|
|
const uint16 Height = (Data->R << 8) + Data->G;
|
2021-11-22 22:06:39 -05:00
|
|
|
OutVertex.WorldPosition = LocalToWorld.TransformPosition( FVector4f( LocalX, LocalY, ((float)Height - 32768.f) * LANDSCAPE_ZSCALE ) );
|
2015-01-29 11:45:50 -05:00
|
|
|
//UE_LOG(LogLightmass, Log, TEXT("%d, %d, %d, %d, %d, %d, X:%f, Y:%f, Z:%f "), SectionBaseX + LocalX - ExpandQuadsX, SectionBaseY + LocalY - ExpandQuadsY, ClampedLocalX, ClampedLocalY, SectionBaseX, SectionBaseY, WorldPos.X, WorldPos.Y, WorldPos.Z);
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2015-01-29 11:45:50 -05:00
|
|
|
const int32 LightmapUVIndex = 1;
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2021-11-22 22:06:39 -05:00
|
|
|
OutVertex.TextureCoordinates[0] = FVector2f((float)X / NumVertices, (float)Y / NumVertices);
|
2014-03-14 14:13:41 -04:00
|
|
|
OutVertex.TextureCoordinates[LightmapUVIndex].X = X * UVFactor;
|
|
|
|
|
OutVertex.TextureCoordinates[LightmapUVIndex].Y = Y * UVFactor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FStaticLightingMesh interface.
|
|
|
|
|
void FLandscapeStaticLightingMesh::GetTriangle(int32 TriangleIndex,FStaticLightingVertex& OutV0,FStaticLightingVertex& OutV1,FStaticLightingVertex& OutV2,int32& ElementIndex) const
|
|
|
|
|
{
|
|
|
|
|
int32 I0, I1, I2;
|
|
|
|
|
//GetTriangleIndices(TriangleIndex,I0, I1, I2);
|
|
|
|
|
I0 = I1 = I2 = 0;
|
|
|
|
|
int32 QuadIndex = TriangleIndex >> 1;
|
|
|
|
|
int32 QuadTriIndex = TriangleIndex & 1;
|
|
|
|
|
|
|
|
|
|
GetTriangleIndices(QuadIndex, QuadTriIndex, I0, I1, I2);
|
|
|
|
|
GetStaticLightingVertex(I0,OutV0);
|
|
|
|
|
GetStaticLightingVertex(I1,OutV1);
|
|
|
|
|
GetStaticLightingVertex(I2,OutV2);
|
|
|
|
|
|
|
|
|
|
ElementIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FLandscapeStaticLightingMesh::GetTriangleIndices(int32 TriangleIndex,int32& OutI0,int32& OutI1,int32& OutI2) const
|
|
|
|
|
{
|
|
|
|
|
//OutI0 = OutI1 = OutI2 = 0;
|
|
|
|
|
int32 QuadIndex = TriangleIndex >> 1;
|
|
|
|
|
int32 QuadTriIndex = TriangleIndex & 1;
|
|
|
|
|
|
|
|
|
|
GetTriangleIndices(QuadIndex, QuadTriIndex, OutI0, OutI1, OutI2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FLandscapeStaticLightingMesh::Import( class FLightmassImporter& Importer )
|
|
|
|
|
{
|
|
|
|
|
// import super class
|
|
|
|
|
FStaticLightingMesh::Import( Importer );
|
|
|
|
|
Importer.ImportData((FLandscapeStaticLightingMeshData*) this);
|
|
|
|
|
|
|
|
|
|
// we have the guid for the mesh, now hook it up to the actual static mesh
|
|
|
|
|
int32 ReadSize = FMath::Square(ComponentSizeQuads + 2*ExpandQuadsX + 1);
|
|
|
|
|
checkf(ReadSize > 0, TEXT("Failed to import Landscape Heightmap data!"));
|
|
|
|
|
Importer.ImportArray(HeightMap, ReadSize);
|
|
|
|
|
check(HeightMap.Num() == ReadSize);
|
|
|
|
|
|
|
|
|
|
NumVertices = ComponentSizeQuads + 2*ExpandQuadsX + 1;
|
|
|
|
|
NumQuads = NumVertices - 1;
|
|
|
|
|
UVFactor = LightMapRatio / NumVertices;
|
2014-08-13 09:48:15 -04:00
|
|
|
bReverseWinding = (LocalToWorld.RotDeterminant() < 0.0f);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FLandscapeStaticLightingTextureMapping::Import( class FLightmassImporter& Importer )
|
|
|
|
|
{
|
|
|
|
|
FStaticLightingTextureMapping::Import(Importer);
|
|
|
|
|
|
|
|
|
|
// Can't use the FStaticLightingMapping Import functionality for this
|
|
|
|
|
// as it only looks in the StaticMeshInstances map...
|
|
|
|
|
Mesh = Importer.GetLandscapeMeshInstances().FindRef(Guid);
|
|
|
|
|
check(Mesh);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} //namespace Lightmass
|