Пример #1
0
ELightMapInteractionType UStaticMeshComponent::GetStaticLightingType() const
{
	bool bUseTextureMap = false;
	if( HasValidSettingsForStaticLighting() )
	{
		// Process each LOD separately.
		TArray<FStaticMeshStaticLightingMesh*> StaticLightingMeshes;
		for(int32 LODIndex = 0;LODIndex < StaticMesh->RenderData->LODResources.Num();LODIndex++)
		{
			const FStaticMeshLODResources& LODRenderData = StaticMesh->RenderData->LODResources[LODIndex];

			// Figure out whether we are storing the lighting/ shadowing information in a texture or vertex buffer.
			int32		LightMapWidth	= 0;
			int32		LightMapHeight	= 0;
			GetLightMapResolution( LightMapWidth, LightMapHeight );

			if ((LightMapWidth > 0) && (LightMapHeight > 0) &&	
				(StaticMesh->LightMapCoordinateIndex >= 0) &&
				((uint32)StaticMesh->LightMapCoordinateIndex < LODRenderData.VertexBuffer.GetNumTexCoords())
				)
			{
				bUseTextureMap = true;
				break;
			}
		}
	}

	return (bUseTextureMap == true) ? LMIT_Texture : LMIT_None;
}
void UStaticMeshComponent::GetStaticLightingInfo(FStaticLightingPrimitiveInfo& OutPrimitiveInfo,const TArray<ULightComponent*>& InRelevantLights,const FLightingBuildOptions& Options)
{
	if( HasValidSettingsForStaticLighting() )
	{
		int32		BaseLightMapWidth	= 0;
		int32		BaseLightMapHeight	= 0;
		GetLightMapResolution( BaseLightMapWidth, BaseLightMapHeight );

		TArray<FStaticMeshStaticLightingMesh*> StaticLightingMeshes;
		bool bCanLODsShareStaticLighting = StaticMesh->CanLODsShareStaticLighting();
		int32 NumLODs = bCanLODsShareStaticLighting ? 1 : StaticMesh->RenderData->LODResources.Num();
		for(int32 LODIndex = 0;LODIndex < NumLODs;LODIndex++)
		{
			const FStaticMeshLODResources& LODRenderData = StaticMesh->RenderData->LODResources[LODIndex];
			// Figure out whether we are storing the lighting/ shadowing information in a texture or vertex buffer.
			bool bUseTextureMap;
			if( (BaseLightMapWidth > 0) && (BaseLightMapHeight > 0) 
				&& StaticMesh->LightMapCoordinateIndex >= 0 
				&& (uint32)StaticMesh->LightMapCoordinateIndex < LODRenderData.VertexBuffer.GetNumTexCoords())
			{
				bUseTextureMap = true;
			}
			else
			{
				bUseTextureMap = false;
			}

			if(bUseTextureMap)
			{
				// Create a static lighting mesh for the LOD.
				FStaticMeshStaticLightingMesh* StaticLightingMesh = AllocateStaticLightingMesh(LODIndex,InRelevantLights);
				OutPrimitiveInfo.Meshes.Add(StaticLightingMesh);
				StaticLightingMeshes.Add(StaticLightingMesh);

				// Shrink LOD texture lightmaps by half for each LOD level
				const int32 LightMapWidth = LODIndex > 0 ? FMath::Max(BaseLightMapWidth / (2 << (LODIndex - 1)), 32) : BaseLightMapWidth;
				const int32 LightMapHeight = LODIndex > 0 ? FMath::Max(BaseLightMapHeight / (2 << (LODIndex - 1)), 32) : BaseLightMapHeight;
				// Create a static lighting texture mapping for the LOD.
				OutPrimitiveInfo.Mappings.Add(new FStaticMeshStaticLightingTextureMapping(
					this,LODIndex,StaticLightingMesh,LightMapWidth,LightMapHeight,StaticMesh->LightMapCoordinateIndex,true));
			}
		}

		// Give each LOD's static lighting mesh a list of the other LODs of this primitive, so they can disallow shadow casting between LODs.
		for(int32 MeshIndex = 0;MeshIndex < StaticLightingMeshes.Num();MeshIndex++)
		{
			for(int32 OtherMeshIndex = 0;OtherMeshIndex < StaticLightingMeshes.Num();OtherMeshIndex++)
			{
				if(MeshIndex != OtherMeshIndex)
				{
					StaticLightingMeshes[MeshIndex]->OtherLODs.Add(StaticLightingMeshes[OtherMeshIndex]);
				}
			}
		}
	}
}