ue4 lightmass研究
Exporter.cpp文件中:导出shadowDepthMap:
void FLightmassSolverExporter::ExportStaticShadowDepthMap(const FGuid& LightGuid, const FStaticShadowDepthMap& StaticShadowDepthMap) const { const FString ChannelName = CreateChannelName(LightGuid, LM_DOMINANTSHADOW_VERSION, LM_DOMINANTSHADOW_EXTENSION); const int32 ErrorCode = Swarm->OpenChannel(*ChannelName, LM_DOMINANTSHADOW_CHANNEL_FLAGS, true); if( ErrorCode >= 0 ) { Swarm->Write(&StaticShadowDepthMap, sizeof(FStaticShadowDepthMapData)); static_assert(sizeof(FStaticShadowDepthMapSample) == sizeof(FStaticShadowDepthMapSampleData), "ShadowDerivedSizeMustMatch"); WriteArray(StaticShadowDepthMap.ShadowMap); Swarm->CloseCurrentChannel(); } else { UE_LOG(LogLightmass, Log, TEXT("Failed to open static shadow depth map channel!")); } }
WriteArray函数是将TArray中的数据写道swarm栈的顶:
/** Writes a TArray to the channel on the top of the Swarm stack. */ template<class T> void FLightmassSolverExporter::WriteArray(const TArray<T>& Array) const { const int32 ArrayNum = Array.Num(); Swarm->Write((void*)&ArrayNum, sizeof(ArrayNum)); if (ArrayNum > 0) { Swarm->Write(Array.GetData(), Array.GetTypeSize() * ArrayNum); } }
输出staticLightData:
int32 FLightmassSolverExporter::BeginExportResults(struct FTextureMappingStaticLightingData& LightingData, uint32 NumMappings) const { const FString ChannelName = CreateChannelName(LightingData.Mapping->Guid, LM_TEXTUREMAPPING_VERSION, LM_TEXTUREMAPPING_EXTENSION); const int32 ErrorCode = Swarm->OpenChannel(*ChannelName, LM_TEXTUREMAPPING_CHANNEL_FLAGS, true); if( ErrorCode < 0 ) { UE_LOG(LogLightmass, Log, TEXT("Failed to open texture mapping channel %s!"), *ChannelName); } else { // Write out the number of mappings this channel will contain Swarm->Write(&NumMappings, sizeof(NumMappings)); } return ErrorCode; }
这个函数被ExportResults函数挪用:
void FLightmassSolverExporter::ExportResults( FTextureMappingStaticLightingData& LightingData, bool bUseUniqueChannel ) const { UE_LOG(LogLightmass, Verbose, TEXT("Exporting texture lighting %s [%.3fs]"), *(LightingData.Mapping->Guid.ToString()), LightingData.ExecutionTime); // If requested, use a unique channel for this mapping, otherwise, just use the one that is already open if (bUseUniqueChannel) { if (BeginExportResults(LightingData, 1) < 0) { return; } } const int32 PaddedOffset = LightingData.Mapping->bPadded ? 1 : 0; const int32 DebugSampleIndex = LightingData.Mapping == Scene.DebugMapping ? (Scene.DebugInput.LocalY + PaddedOffset) * LightingData.Mapping->SizeX + Scene.DebugInput.LocalX + PaddedOffset : INDEX_NONE; if (bDumpTextures) { WriteBitmap<4>(*(LightingData.Mapping->Guid.ToString() + TEXT("_LM")), LightingData.LightMapData->GetData(), LightingData.LightMapData->GetSizeX(), LightingData.LightMapData->GetSizeY()); } // If we need to compress the data before writing out, do it now LightingData.LightMapData->Compress(DebugSampleIndex); // UE_LOG(LogLightmass, Log, TEXT("LM data went from %d to %d bytes"), LightingData.LightMapData->UncompressedDataSize, LightingData.LightMapData->CompressedDataSize); const int32 ShadowMapCount = LightingData.ShadowMaps.Num(); const int32 SignedDistanceFieldShadowMapCount = LightingData.SignedDistanceFieldShadowMaps.Num(); const int32 NumLights = LightingData.LightMapData->Lights.Num(); #pragma pack (push,1) struct FTextureHeader { FTextureHeader(FGuid& InGuid, double InExecutionTime, FLightMapData2DData& InData, int32 InShadowMapCount, int32 InSignedDistanceFieldShadowMapCount, int32 InLightCount) : Guid(InGuid), ExecutionTime(InExecutionTime), Data(InData), ShadowMapCount(InShadowMapCount), SignedDistanceFieldShadowMapCount(InSignedDistanceFieldShadowMapCount), LightCount(InLightCount) {} FGuid Guid; double ExecutionTime; FLightMapData2DData Data; int32 ShadowMapCount; int32 SignedDistanceFieldShadowMapCount; int32 LightCount; }; #pragma pack (pop) FTextureHeader Header(LightingData.Mapping->Guid, LightingData.ExecutionTime, *(FLightMapData2DData*)LightingData.LightMapData, LightingData.ShadowMaps.Num(), LightingData.SignedDistanceFieldShadowMaps.Num(), NumLights); Swarm->Write(&Header, sizeof(Header)); for (int32 LightIndex = 0; LightIndex < NumLights; LightIndex++) { FGuid CurrentGuid = LightingData.LightMapData->Lights[LightIndex]->Guid; Swarm->Write(&CurrentGuid, sizeof(CurrentGuid)); } // Write out compressed data if supported Swarm->Write(LightingData.LightMapData->GetCompressedData(), LightingData.LightMapData->CompressedDataSize ? LightingData.LightMapData->CompressedDataSize : LightingData.LightMapData->UncompressedDataSize); // The resulting light GUID --> shadow map data int32 ShadowIndex = 0; for (TMap<const FLight*,FSignedDistanceFieldShadowMapData2D*>::TIterator It(LightingData.SignedDistanceFieldShadowMaps); It; ++It, ++ShadowIndex) { FGuid OutGuid = It.Key()->Guid; FSignedDistanceFieldShadowMapData2D* OutData = It.Value(); // If we need to compress the data before writing out, do it now OutData->Compress(INDEX_NONE); Swarm->Write(&OutGuid, sizeof(FGuid)); Swarm->Write((FSignedDistanceFieldShadowMapData2DData*)OutData, sizeof(FSignedDistanceFieldShadowMapData2DData)); // Write out compressed data if supported Swarm->Write(OutData->GetCompressedData(), OutData->CompressedDataSize ? OutData->CompressedDataSize : OutData->UncompressedDataSize); } WriteDebugLightingOutput(LightingData.DebugOutput); // free up the calculated data delete LightingData.LightMapData; LightingData.ShadowMaps.Empty(); LightingData.SignedDistanceFieldShadowMaps.Empty(); // Only close the channel if we opened it if (bUseUniqueChannel) { EndExportResults(); } }
一个贴图映射的静态光照数据:
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/30482.html
- 上一篇:HttpResponse和JsonResponse
- 下一篇:CMS代码审计(1)