Files
UnrealEngineUWP/Engine/Shaders/Private/LightmapData.ush
Dmitriy Dyomin 762b48e011 Mobile specific implementation for auto-instancing. (disabled by default atm)
Run a compute job that packs most commonly used instance data (LocalToWorld matrix and some other bits - 80 bytes) into per-instance vertex buffer. Vertex shader does not have access to GPUScene and instead loads instance data from a per-instance vertex buffer. If it needs more primitive/instance data than available then it will load it from Primitive UB, binding unique uniform buffer and breaking auto-instancing. Pixel shader has a full access to a GPUScene
There are 3 ways how FSceneDataIntermediates gets populated
 1. PrimitiveId + GPUScene (Desktop)
 2. Per-Instance data + Primitive UB (Mobile)
 3. Primitive UB (auto-instancing disabled)
Details for GPUScene specific vertex inputs and access to FSceneDataIntermediates are hidden behind a macro:
VF_GPUSCENE_DECLARE_INPUT_BLOCK
VF_GPUSCENE_GET_INTERMEDIATES
FSceneDataIntermediates is now stored in FVertexFactoryIntermediates, FMaterialVertexParameters. Added a few GetPrimitiveData() overloads that allows you to access PrimitiveData depending on current context. Removed most of the cases where GetPrimitiveData() gets used with PrimitiveId.
#rb Ola.Ollson

[CL 17093848 by Dmitriy Dyomin in ue5-main branch]
2021-08-07 07:16:17 -04:00

79 lines
2.6 KiB
Plaintext

// Copyright Epic Games, Inc. All Rights Reserved.
/**
* LightmapData.ush
*/
#pragma once
#ifndef USE_GLOBAL_GPU_LIGHTMAP_DATA
#define USE_GLOBAL_GPU_LIGHTMAP_DATA 0
#endif
#if VF_USE_PRIMITIVE_SCENE_DATA
// Must match FPrecomputedLightingUniformParameters in C++
struct FLightmapSceneData
{
float4 StaticShadowMapMasks;
float4 InvUniformPenumbraSizes;
float4 LightMapCoordinateScaleBias;
float4 ShadowMapCoordinateScaleBias;
float4 LightMapScale[2];
float4 LightMapAdd[2];
uint4 LightmapVTPackedPageTableUniform[2];
uint4 LightmapVTPackedUniform[5];
};
// Stride of a single lightmap data entry in float4's, must match C++
#define LIGHTMAP_SCENE_DATA_STRIDE 15
#if USE_GLOBAL_GPU_LIGHTMAP_DATA
StructuredBuffer<float4> GPUSceneLightmapData;
#endif
float4 LoadLightmapDataElement(uint Index)
{
#if USE_GLOBAL_GPU_LIGHTMAP_DATA
checkStructuredBufferAccessSlow(GPUSceneLightmapData, Index);
return GPUSceneLightmapData[Index];
#else
checkStructuredBufferAccessSlow(View.LightmapSceneData, Index);
return View.LightmapSceneData[Index];
#endif
}
// Fetch from scene lightmap data buffer
FLightmapSceneData GetLightmapData(uint LightmapDataIndex)
{
// Note: layout must match FLightmapSceneShaderData in C++
// Relying on optimizer to remove unused loads
FLightmapSceneData LightmapData;
uint LightmapDataBaseOffset = LightmapDataIndex * LIGHTMAP_SCENE_DATA_STRIDE;
LightmapData.StaticShadowMapMasks = LoadLightmapDataElement(LightmapDataBaseOffset + 0);
LightmapData.InvUniformPenumbraSizes = LoadLightmapDataElement(LightmapDataBaseOffset + 1);
LightmapData.LightMapCoordinateScaleBias = LoadLightmapDataElement(LightmapDataBaseOffset + 2);
LightmapData.ShadowMapCoordinateScaleBias = LoadLightmapDataElement(LightmapDataBaseOffset + 3);
LightmapData.LightMapScale[0] = LoadLightmapDataElement(LightmapDataBaseOffset + 4);
LightmapData.LightMapScale[1] = LoadLightmapDataElement(LightmapDataBaseOffset + 5);
LightmapData.LightMapAdd[0] = LoadLightmapDataElement(LightmapDataBaseOffset + 6);
LightmapData.LightMapAdd[1] = LoadLightmapDataElement(LightmapDataBaseOffset + 7);
LightmapData.LightmapVTPackedPageTableUniform[0] = asuint(LoadLightmapDataElement(LightmapDataBaseOffset + 8));
LightmapData.LightmapVTPackedPageTableUniform[1] = asuint(LoadLightmapDataElement(LightmapDataBaseOffset + 9));
UNROLL
for (uint i = 0u; i < 5u; ++i)
{
LightmapData.LightmapVTPackedUniform[i] = asuint(LoadLightmapDataElement(LightmapDataBaseOffset + 10 + i));
}
return LightmapData;
}
#else
// Route to uniform buffer
#define GetLightmapData(x) PrecomputedLightingBuffer
#endif