当前位置:   article > 正文

UE5 Lightmap使用

UE5 Lightmap使用

在BasePass阶段使用

DefferredShadingRenderer:Render()

  1. if (bRenderDeferredLighting)
  2. {
  3. RDG_GPU_STAT_SCOPE(GraphBuilder, RenderDeferredLighting);
  4. RDG_CSV_STAT_EXCLUSIVE_SCOPE(GraphBuilder, RenderLighting);
  5. SCOPE_CYCLE_COUNTER(STAT_FDeferredShadingSceneRenderer_Lighting);
  6. FRDGTextureRef DynamicBentNormalAOTexture = nullptr;
  7. RenderDiffuseIndirectAndAmbientOcclusion(
  8. GraphBuilder,
  9. SceneTextures,
  10. LumenFrameTemporaries,
  11. LightingChannelsTexture,
  12. bHasLumenLights,
  13. /* bCompositeRegularLumenOnly = */ false,
  14. /* bIsVisualizePass = */ false,
  15. AsyncLumenIndirectLightingOutputs);
  16. // These modulate the scenecolor output from the basepass, which is assumed to be indirect lighting
  17. if (bAllowStaticLighting)
  18. {
  19. RenderIndirectCapsuleShadows(GraphBuilder, SceneTextures);
  20. }
  21. // These modulate the scene color output from the base pass, which is assumed to be indirect lighting
  22. RenderDFAOAsIndirectShadowing(GraphBuilder, SceneTextures, DynamicBentNormalAOTexture);
  23. // Clear the translucent lighting volumes before we accumulate
  24. if ((GbEnableAsyncComputeTranslucencyLightingVolumeClear && GSupportsEfficientAsyncCompute) == false)
  25. {
  26. TranslucencyLightingVolumeTextures.Init(GraphBuilder, Views, ERDGPassFlags::Compute);
  27. }
  28. #if RHI_RAYTRACING
  29. if (IsRayTracingEnabled())
  30. {
  31. RenderDitheredLODFadingOutMask(GraphBuilder, Views[0], SceneTextures.Depth.Target);
  32. }
  33. #endif
  34. GraphBuilder.SetCommandListStat(GET_STATID(STAT_CLM_Lighting));
  35. RenderLights(GraphBuilder, SceneTextures, TranslucencyLightingVolumeTextures, LightingChannelsTexture, SortedLightSet);
  36. GraphBuilder.SetCommandListStat(GET_STATID(STAT_CLM_AfterLighting));
  37. InjectTranslucencyLightingVolumeAmbientCubemap(GraphBuilder, Views, TranslucencyLightingVolumeTextures);
  38. FilterTranslucencyLightingVolume(GraphBuilder, Views, TranslucencyLightingVolumeTextures);
  39. // Do DiffuseIndirectComposite after Lights so that async Lumen work can overlap
  40. RenderDiffuseIndirectAndAmbientOcclusion(
  41. GraphBuilder,
  42. SceneTextures,
  43. LumenFrameTemporaries,
  44. LightingChannelsTexture,
  45. bHasLumenLights,
  46. /* bCompositeRegularLumenOnly = */ true,
  47. /* bIsVisualizePass = */ false,
  48. AsyncLumenIndirectLightingOutputs);
  49. // Render diffuse sky lighting and reflections that only operate on opaque pixels
  50. RenderDeferredReflectionsAndSkyLighting(GraphBuilder, SceneTextures, DynamicBentNormalAOTexture);
  51. #if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
  52. // Renders debug visualizations for global illumination plugins
  53. RenderGlobalIlluminationPluginVisualizations(GraphBuilder, LightingChannelsTexture);
  54. #endif
  55. AddSubsurfacePass(GraphBuilder, SceneTextures, Views);
  56. Strata::AddStrataOpaqueRoughRefractionPasses(GraphBuilder, SceneTextures, Views);
  57. {
  58. RenderHairStrandsSceneColorScattering(GraphBuilder, SceneTextures.Color.Target, Scene, Views);
  59. }
  60. #if RHI_RAYTRACING
  61. if (ShouldRenderRayTracingSkyLight(Scene->SkyLight)
  62. //@todo - integrate RenderRayTracingSkyLight into RenderDiffuseIndirectAndAmbientOcclusion
  63. && GetViewPipelineState(Views[0]).DiffuseIndirectMethod != EDiffuseIndirectMethod::Lumen
  64. && ViewFamily.EngineShowFlags.GlobalIllumination)
  65. {
  66. FRDGTextureRef SkyLightTexture = nullptr;
  67. FRDGTextureRef SkyLightHitDistanceTexture = nullptr;
  68. RenderRayTracingSkyLight(GraphBuilder, SceneTextures.Color.Target, SkyLightTexture, SkyLightHitDistanceTexture);
  69. CompositeRayTracingSkyLight(GraphBuilder, SceneTextures, SkyLightTexture, SkyLightHitDistanceTexture);
  70. }
  71. #endif
  72. }

RenderDiffuseIndirectAndAmbientOcclusion

 

RenderDeferredReflectionsAndSkyLighting

Final Image :

 

基础结构

  1. struct VTPageTableResult
  2. {
  3. float2 UV;
  4. float2 dUVdx;
  5. float2 dUVdy;
  6. uint4 PageTableValue[2];
  7. uint PackedRequest;
  8. };
  9. struct FLightmapSceneData
  10. {
  11. float4 StaticShadowMapMasks;
  12. float4 InvUniformPenumbraSizes;
  13. float4 LightMapCoordinateScaleBias;
  14. float4 ShadowMapCoordinateScaleBias;
  15. float4 LightMapScale[2];
  16. float4 LightMapAdd[2];
  17. uint4 LightmapVTPackedPageTableUniform[2];
  18. uint4 LightmapVTPackedUniform[5];
  19. };

Shader测具体过程:

BasePathPixelShader.usf

  1. void GetPrecomputedIndirectLightingAndSkyLight(
  2. FMaterialPixelParameters MaterialParameters,
  3. FVertexFactoryInterpolantsVSToPS Interpolants,
  4. FBasePassInterpolantsVSToPS BasePassInterpolants,
  5. VTPageTableResult LightmapVTPageTableResult,
  6. bool bEvaluateBackface,
  7. float3 DiffuseDir,
  8. float3 VolumetricLightmapBrickTextureUVs,
  9. out float3 OutDiffuseLighting,
  10. out float3 OutSubsurfaceLighting,
  11. out float OutIndirectIrradiance)
  12. {
  13. OutIndirectIrradiance = 0;
  14. OutDiffuseLighting = 0;
  15. OutSubsurfaceLighting = 0;
  16. LightmapUVType SkyOcclusionUV = (LightmapUVType)0;
  17. uint SkyOcclusionDataIndex = 0u;
  18. // High quality texture lightmaps
  19. #elif HQ_TEXTURE_LIGHTMAP
  20. LightmapUVType LightmapUV0, LightmapUV1;
  21. uint LightmapDataIndex;
  22. GetLightMapCoordinates(Interpolants, LightmapUV0, LightmapUV1, LightmapDataIndex);
  23. SkyOcclusionUV = LightmapUV0;
  24. SkyOcclusionDataIndex = LightmapDataIndex;
  25. GetLightMapColorHQ(LightmapVTPageTableResult, LightmapUV0, LightmapUV1, LightmapDataIndex, DiffuseDir, MaterialParameters.SvPosition.xy, bEvaluateBackface, OutDiffuseLighting, OutSubsurfaceLighting);
  26. // Low quality texture lightmaps
  27. #elif LQ_TEXTURE_LIGHTMAP
  28. LightmapUVType LightmapUV0, LightmapUV1;
  29. uint LightmapDataIndex;
  30. GetLightMapCoordinates(Interpolants, LightmapUV0, LightmapUV1, LightmapDataIndex);
  31. GetLightMapColorLQ(LightmapVTPageTableResult, LightmapUV0, LightmapUV1, LightmapDataIndex, DiffuseDir, bEvaluateBackface, OutDiffuseLighting, OutSubsurfaceLighting, OutIndirectIrradiance);
  32. #endif
  33. // Apply indirect lighting scale while we have only accumulated lightmaps
  34. OutDiffuseLighting *= View.PrecomputedIndirectLightingColorScale;
  35. OutSubsurfaceLighting *= View.PrecomputedIndirectLightingColorScale;
  36. float3 SkyDiffuseLighting;
  37. float3 SkySubsurfaceLighting;
  38. GetSkyLighting(MaterialParameters, LightmapVTPageTableResult, bEvaluateBackface, DiffuseDir, SkyOcclusionUV, SkyOcclusionDataIndex, VolumetricLightmapBrickTextureUVs, SkyDiffuseLighting, SkySubsurfaceLighting);
  39. OutSubsurfaceLighting += SkySubsurfaceLighting;
  40. // Sky lighting must contribute to IndirectIrradiance for ReflectionEnvironment lightmap mixing
  41. OutDiffuseLighting += SkyDiffuseLighting;
  42. #if HQ_TEXTURE_LIGHTMAP || LQ_TEXTURE_LIGHTMAP || CACHED_VOLUME_INDIRECT_LIGHTING || CACHED_POINT_INDIRECT_LIGHTING || PRECOMPUTED_IRRADIANCE_VOLUME_LIGHTING
  43. OutIndirectIrradiance = Luminance(OutDiffuseLighting);
  44. #endif
  45. }
  46. void GetLightMapColorHQ( VTPageTableResult LightmapVTPageTableResult, LightmapUVType LightmapUV0, LightmapUVType LightmapUV1, uint LightmapDataIndex, half3 WorldNormal, float2 SvPositionXY, bool bEvaluateBackface, out half3 OutDiffuseLighting, out half3 OutSubsurfaceLighting )
  47. {
  48. OutSubsurfaceLighting = 0;
  49. half4 Lightmap0;
  50. half4 Lightmap1;
  51. #if LIGHTMAP_VT_ENABLED
  52. Lightmap0 = SampleLightmapVT( LightmapVTPageTableResult, 0u, LightmapDataIndex, LightmapResourceCluster.VTLightMapTexture, LightmapResourceCluster.LightMapSampler);
  53. Lightmap1 = SampleLightmapVT( LightmapVTPageTableResult, 1u, LightmapDataIndex, LightmapResourceCluster.VTLightMapTexture_1, LightmapResourceCluster.LightMapSampler);
  54. #else
  55. Lightmap0 = Texture2DSample( LightmapResourceCluster.LightMapTexture, LightmapResourceCluster.LightMapSampler, LightmapUV0 );
  56. Lightmap1 = Texture2DSample( LightmapResourceCluster.LightMapTexture, LightmapResourceCluster.LightMapSampler, LightmapUV1 );
  57. #endif
  58. half LogL = Lightmap0.w;
  59. // Add residual
  60. LogL += Lightmap1.w * (1.0 / 255) - (0.5 / 255);
  61. // Range scale LogL
  62. LogL = LogL * GetLightmapData(LightmapDataIndex).LightMapScale[0].w + GetLightmapData(LightmapDataIndex).LightMapAdd[0].w;
  63. // Range scale UVW
  64. half3 UVW = Lightmap0.rgb * Lightmap0.rgb * GetLightmapData(LightmapDataIndex).LightMapScale[0].rgb + GetLightmapData(LightmapDataIndex).LightMapAdd[0].rgb;
  65. // LogL -> L
  66. const half LogBlackPoint = 0.01858136;
  67. half L = exp2( LogL ) - LogBlackPoint;
  68. #if USE_LM_DIRECTIONALITY
  69. // Range scale SH. Alpha doesn't matter, will scale with zero
  70. float4 SH = Lightmap1 * GetLightmapData(LightmapDataIndex).LightMapScale[1] + GetLightmapData(LightmapDataIndex).LightMapAdd[1];
  71. // Sample SH with normal
  72. half Directionality = max( 0.0, dot( SH, float4(WorldNormal.yzx, 1) ) );
  73. #if SHADINGMODEL_REQUIRES_BACKFACE_LIGHTING
  74. if (bEvaluateBackface)
  75. {
  76. half SubsurfaceDirectionality = max(0.0, dot(SH, float4(-WorldNormal.yzx, 1)));
  77. OutSubsurfaceLighting = L * SubsurfaceDirectionality * UVW;
  78. }
  79. #endif
  80. #else
  81. half Directionality = 0.6;
  82. #if SHADINGMODEL_REQUIRES_BACKFACE_LIGHTING
  83. if (bEvaluateBackface)
  84. {
  85. OutSubsurfaceLighting = L * Directionality * UVW;
  86. }
  87. #endif
  88. #endif
  89. half Luma = L * Directionality;
  90. half3 Color = Luma * UVW;
  91. OutDiffuseLighting = Color;
  92. }

  1. VTPageTableResult LightmapVTPageTableResult = (VTPageTableResult)0.0f;
  2. #if LIGHTMAP_VT_ENABLED
  3. {
  4. LightmapUVType LightmapUV0, LightmapUV1;
  5. uint LightmapDataIndex;
  6. GetLightMapCoordinates(Interpolants, LightmapUV0, LightmapUV1, LightmapDataIndex);
  7. LightmapVTPageTableResult = LightmapGetVTSampleInfo(LightmapUV0, LightmapDataIndex, In.SvPosition.xy);
  8. }
  9. #endif
  10. #if NEEDS_LIGHTMAP_COORDINATE
  11. void GetLightMapCoordinates(FVertexFactoryInterpolantsVSToPS Interpolants, out float2 LightmapUV0, out float2 LightmapUV1, out uint LightmapDataIndex)
  12. {
  13. LightmapUV0 = Interpolants.LightMapCoordinate.xy * float2( 1, 0.5 );
  14. LightmapUV1 = LightmapUV0 + float2( 0, 0.5 );
  15. #if VF_USE_PRIMITIVE_SCENE_DATA && NEEDS_LIGHTMAP_COORDINATE
  16. LightmapDataIndex = Interpolants.LightmapDataIndex;
  17. #else
  18. LightmapDataIndex = 0;
  19. #endif
  20. }
  21. VTPageTableResult LightmapGetVTSampleInfo(float2 UV, uint LightmapDataIndex, float2 SvPositionXY)
  22. {
  23. UV = ScaleLightmapUV(UV, float2(1.0f, 2.0f)); // Undo transform used to pack 2 lightmap coeffs in 1 texture for the non-VT default case
  24. return TextureLoadVirtualPageTable(LightmapResourceCluster.LightmapVirtualTexturePageTable0, LightmapResourceCluster.LightmapVirtualTexturePageTable1,
  25. VTPageTableUniform_Unpack(GetLightmapData(LightmapDataIndex).LightmapVTPackedPageTableUniform[0], GetLightmapData(LightmapDataIndex).LightmapVTPackedPageTableUniform[1]),
  26. UV, LIGHTMAP_VTADDRESSMODE, LIGHTMAP_VTADDRESSMODE, 0, SvPositionXY);
  27. }
  28. VTPageTableResult TextureLoadVirtualPageTable(
  29. Texture2D<uint4> PageTable0, Texture2D<uint4> PageTable1,
  30. VTPageTableUniform PageTableUniform,
  31. float2 UV, uint AddressU, uint AddressV,
  32. MaterialFloat MipBias, float2 SvPositionXY)
  33. {
  34. VTPageTableResult Result = (VTPageTableResult)0;
  35. UV = UV * PageTableUniform.UVScale;
  36. int vLevel = GetGlobalVirtualTextureMipBias();
  37. #if PIXELSHADER
  38. vLevel = TextureComputeVirtualMipLevel(Result, ddx(UV), ddy(UV), MipBias, SvPositionXY, PageTableUniform);
  39. #endif // PIXELSHADER
  40. UV = ApplyAddressMode(UV, AddressU, AddressV);
  41. TextureLoadVirtualPageTableInternal(Result, PageTable0, PageTable1, PageTableUniform, UV, vLevel);
  42. return Result;
  43. }
  44. void TextureLoadVirtualPageTableInternal(
  45. in out VTPageTableResult OutResult,
  46. Texture2D<uint4> PageTable0, Texture2D<uint4> PageTable1,
  47. VTPageTableUniform PageTableUniform,
  48. float2 UV, int vLevel)
  49. {
  50. OutResult.UV = UV * PageTableUniform.SizeInPages;
  51. const uint vLevelClamped = clamp(vLevel, 0, int(PageTableUniform.MaxLevel));
  52. const uint vPageX = (uint(OutResult.UV.x) + PageTableUniform.XOffsetInPages) >> vLevelClamped;
  53. const uint vPageY = (uint(OutResult.UV.y) + PageTableUniform.YOffsetInPages) >> vLevelClamped;
  54. OutResult.PageTableValue[0] = PageTable0.Load(int3(vPageX, vPageY, vLevelClamped));
  55. OutResult.PageTableValue[1] = PageTable1.Load(int3(vPageX, vPageY, vLevelClamped));
  56. // PageTableID packed in upper 4 bits of 'PackedPageTableUniform', which is the bit position we want it in for PackedRequest as well, just need to mask off extra bits
  57. OutResult.PackedRequest = PageTableUniform.ShiftedPageTableID;
  58. OutResult.PackedRequest |= vPageX;
  59. OutResult.PackedRequest |= vPageY << 12;
  60. // Feedback always encodes vLevel+1, and subtracts 1 on the CPU side.
  61. // This allows the CPU code to know when we requested a negative vLevel which indicates that we don't have sufficient virtual texture resolution.
  62. const uint vLevelPlusOneClamped = clamp(vLevel + 1, 0, int(PageTableUniform.MaxLevel + 1));
  63. OutResult.PackedRequest |= vLevelPlusOneClamped << 24;
  64. }
  65. FLightmapSceneData GetLightmapData(uint LightmapDataIndex)
  66. {
  67. // Note: layout must match FLightmapSceneShaderData in C++
  68. // Relying on optimizer to remove unused loads
  69. FLightmapSceneData LightmapData;
  70. uint LightmapDataBaseOffset = LightmapDataIndex * LIGHTMAP_SCENE_DATA_STRIDE;
  71. LightmapData.StaticShadowMapMasks = LoadLightmapDataElement(LightmapDataBaseOffset + 0);
  72. LightmapData.InvUniformPenumbraSizes = LoadLightmapDataElement(LightmapDataBaseOffset + 1);
  73. LightmapData.LightMapCoordinateScaleBias = LoadLightmapDataElement(LightmapDataBaseOffset + 2);
  74. LightmapData.ShadowMapCoordinateScaleBias = LoadLightmapDataElement(LightmapDataBaseOffset + 3);
  75. LightmapData.LightMapScale[0] = LoadLightmapDataElement(LightmapDataBaseOffset + 4);
  76. LightmapData.LightMapScale[1] = LoadLightmapDataElement(LightmapDataBaseOffset + 5);
  77. LightmapData.LightMapAdd[0] = LoadLightmapDataElement(LightmapDataBaseOffset + 6);
  78. LightmapData.LightMapAdd[1] = LoadLightmapDataElement(LightmapDataBaseOffset + 7);
  79. LightmapData.LightmapVTPackedPageTableUniform[0] = asuint(LoadLightmapDataElement(LightmapDataBaseOffset + 8));
  80. LightmapData.LightmapVTPackedPageTableUniform[1] = asuint(LoadLightmapDataElement(LightmapDataBaseOffset + 9));
  81. UNROLL
  82. for (uint i = 0u; i < 5u; ++i)
  83. {
  84. LightmapData.LightmapVTPackedUniform[i] = asuint(LoadLightmapDataElement(LightmapDataBaseOffset + 10 + i));
  85. }
  86. return LightmapData;
  87. }
  88. #define LIGHTMAP_SCENE_DATA_STRIDE 15
  89. #if USE_GLOBAL_GPU_LIGHTMAP_DATA
  90. StructuredBuffer<float4> GPUSceneLightmapData;
  91. #endif
  92. float4 LoadLightmapDataElement(uint Index)
  93. {
  94. #if USE_GLOBAL_GPU_LIGHTMAP_DATA
  95. checkStructuredBufferAccessSlow(GPUSceneLightmapData, Index);
  96. return GPUSceneLightmapData[Index];
  97. #else
  98. checkStructuredBufferAccessSlow(View.LightmapSceneData, Index);
  99. return View.LightmapSceneData[Index];
  100. #endif
  101. }

C++测具体过程:

GPUScene.cpp

  1. template<typename FUploadDataSourceAdapter>
  2. void FGPUScene::UpdateBufferState(FRDGBuilder& GraphBuilder, FScene& Scene, const FUploadDataSourceAdapter& UploadDataSourceAdapter)
  3. {
  4. LLM_SCOPE_BYTAG(GPUScene);
  5. ensure(bInBeginEndBlock);
  6. ensure(bIsEnabled == UseGPUScene(GMaxRHIShaderPlatform, Scene.GetFeatureLevel()));
  7. ensure(NumScenePrimitives == Scene.Primitives.Num());
  8. // Multi-GPU support : Updating on all GPUs is inefficient for AFR. Work is wasted
  9. // for any primitives that update on consecutive frames.
  10. RDG_GPU_MASK_SCOPE(GraphBuilder, FRHIGPUMask::All());
  11. constexpr int32 InitialBufferSize = 256;
  12. const uint32 LightMapDataBufferSize = FMath::RoundUpToPowerOfTwo(FMath::Max(LightmapDataAllocator.GetMaxSize(), InitialBufferSize));
  13. BufferState.LightmapDataBuffer = ResizeStructuredBufferIfNeeded(GraphBuilder, LightmapDataBuffer, LightMapDataBufferSize * sizeof(FLightmapSceneShaderData::Data), TEXT("GPUScene.LightmapData"));
  14. BufferState.LightMapDataBufferSize = LightMapDataBufferSize;
  15. ShaderParameters.GPUSceneInstanceSceneData = GraphBuilder.CreateSRV(BufferState.InstanceSceneDataBuffer);
  16. ShaderParameters.GPUSceneInstancePayloadData = GraphBuilder.CreateSRV(BufferState.InstancePayloadDataBuffer);
  17. ShaderParameters.GPUScenePrimitiveSceneData = GraphBuilder.CreateSRV(BufferState.PrimitiveBuffer);
  18. ShaderParameters.GPUSceneLightmapData = GraphBuilder.CreateSRV(BufferState.LightmapDataBuffer);
  19. ShaderParameters.InstanceDataSOAStride = InstanceSceneDataSOAStride;
  20. ShaderParameters.NumScenePrimitives = NumScenePrimitives;
  21. ShaderParameters.NumInstances = InstanceSceneDataAllocator.GetMaxSize();
  22. ShaderParameters.GPUSceneFrameNumber = GetSceneFrameNumber();
  23. }

GPUScene.h

  1. template<typename FUploadDataSourceAdapter>
  2. void FGPUScene::UploadGeneral(FRDGBuilder& GraphBuilder, FScene& Scene, FRDGExternalAccessQueue& ExternalAccessQueue, const FUploadDataSourceAdapter& UploadDataSourceAdapter)
  3. {
  4. LLM_SCOPE_BYTAG(GPUScene);
  5. ensure(bIsEnabled == UseGPUScene(GMaxRHIShaderPlatform, Scene.GetFeatureLevel()));
  6. ensure(NumScenePrimitives == Scene.Primitives.Num());
  7. const int32 NumPrimitiveDataUploads = UploadDataSourceAdapter.NumPrimitivesToUpload();
  8. if (!NumPrimitiveDataUploads)
  9. {
  10. return;
  11. }
  12. const bool bExecuteInParallel = GGPUSceneParallelUpdate != 0 && FApp::ShouldUseThreadingForPerformance();
  13. const bool bNaniteEnabled = DoesPlatformSupportNanite(GMaxRHIShaderPlatform);
  14. SCOPED_NAMED_EVENT(UpdateGPUScene, FColor::Green);
  15. // Multi-GPU support : Updating on all GPUs is inefficient for AFR. Work is wasted
  16. // for any primitives that update on consecutive frames.
  17. RDG_GPU_MASK_SCOPE(GraphBuilder, FRHIGPUMask::All());
  18. RDG_EVENT_SCOPE(GraphBuilder, "UpdateGPUScene NumPrimitiveDataUploads %u", NumPrimitiveDataUploads);
  19. struct FTaskContext
  20. {
  21. TArray<FPrimitiveUploadInfoHeader, FSceneRenderingArrayAllocator> PrimitiveUploadInfos;
  22. FRDGScatterUploader* PrimitiveUploader = nullptr;
  23. FRDGScatterUploader* InstancePayloadUploader = nullptr;
  24. FRDGScatterUploader* InstanceSceneUploader = nullptr;
  25. FRDGScatterUploader* InstanceBVHUploader = nullptr;
  26. FRDGScatterUploader* LightmapUploader = nullptr;
  27. TStaticArray<FNaniteMaterialCommands::FUploader*, ENaniteMeshPass::Num> NaniteMaterialUploaders{ InPlace, nullptr };
  28. int32 NumPrimitiveDataUploads = 0;
  29. int32 NumLightmapDataUploads = 0;
  30. int32 NumInstanceSceneDataUploads = 0;
  31. int32 NumInstancePayloadDataUploads = 0; // Count of float4s
  32. uint32 InstanceSceneDataSOAStride = 1;
  33. bool bUseNaniteMaterialUploaders = false;
  34. };
  35. FTaskContext& TaskContext = *GraphBuilder.AllocObject<FTaskContext>();
  36. TaskContext.NumPrimitiveDataUploads = NumPrimitiveDataUploads;
  37. TaskContext.InstanceSceneDataSOAStride = BufferState.InstanceSceneDataSOAStride;
  38. TaskContext.PrimitiveUploadInfos.SetNumUninitialized(NumPrimitiveDataUploads);
  39. for (int32 ItemIndex = 0; ItemIndex < NumPrimitiveDataUploads; ++ItemIndex)
  40. {
  41. FPrimitiveUploadInfoHeader& UploadInfo = TaskContext.PrimitiveUploadInfos[ItemIndex];
  42. UploadDataSourceAdapter.GetPrimitiveInfoHeader(ItemIndex, UploadInfo);
  43. TaskContext.NumLightmapDataUploads += UploadInfo.LightmapUploadCount; // Not thread safe
  44. TaskContext.NumInstanceSceneDataUploads += UploadInfo.NumInstanceUploads; // Not thread safe
  45. TaskContext.NumInstancePayloadDataUploads += UploadInfo.NumInstancePayloadDataUploads; // Not thread safe
  46. }
  47. TaskContext.PrimitiveUploader = PrimitiveUploadBuffer.Begin(GraphBuilder, BufferState.PrimitiveBuffer, UploadDataSourceAdapter.GetItemPrimitiveIds().Num(), sizeof(FPrimitiveSceneShaderData::Data), TEXT("PrimitiveUploadBuffer"));
  48. if (TaskContext.NumLightmapDataUploads > 0)
  49. {
  50. TaskContext.LightmapUploader = LightmapUploadBuffer.Begin(GraphBuilder, BufferState.LightmapDataBuffer, TaskContext.NumLightmapDataUploads, sizeof(FLightmapSceneShaderData::Data), TEXT("LightmapUploadBuffer"));
  51. }
  52. if (UploadDataSourceAdapter.bUpdateNaniteMaterialTables && bNaniteEnabled)
  53. {
  54. for (int32 NaniteMeshPassIndex = 0; NaniteMeshPassIndex < ENaniteMeshPass::Num; ++NaniteMeshPassIndex)
  55. {
  56. TaskContext.NaniteMaterialUploaders[NaniteMeshPassIndex] = Scene.NaniteMaterials[NaniteMeshPassIndex].Begin(GraphBuilder, Scene.Primitives.Num(), NumPrimitiveDataUploads);
  57. }
  58. TaskContext.bUseNaniteMaterialUploaders = true;
  59. }
  60. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/133144
推荐阅读
相关标签
  

闽ICP备14008679号