Files
UnrealEngineUWP/Engine/Shaders/Private/VirtualShadowMaps/VirtualShadowMapProjectionStructs.ush
charles derousiers 2a2828c8a4 Add VirtualShadowMap prefix to all shaders related to virtual shadow map.
#rb andrew.lauritzen
#jira none
#preflight 620a2a37015ab8f37a3e2d2c
#lockdown juan.canada

#ROBOMERGE-AUTHOR: charles.derousiers
#ROBOMERGE-SOURCE: CL 18977253 in //UE5/Release-5.0/... via CL 18977320 via CL 18977399
#ROBOMERGE-BOT: UE5 (Release-Engine-Test -> Main) (v917-18934589)

[CL 18977416 by charles derousiers in ue5-main branch]
2022-02-14 05:44:50 -05:00

85 lines
4.1 KiB
Plaintext

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "../LargeWorldCoordinates.ush"
// Rougly the same structure as in VirtualShadowMapArray.h, with some logic around LWC values
struct FVirtualShadowMapProjectionShaderData
{
float4x4 TranslatedWorldToShadowViewMatrix;
float4x4 ShadowViewToClipMatrix;
float4x4 TranslatedWorldToShadowUVMatrix;
float4x4 TranslatedWorldToShadowUVNormalMatrix;
FLWCVector3 PreViewTranslation;
uint LightType; // Matches ELightComponentType via defines in SSDDefinitions.ush
float LightSourceRadius;
FLWCVector3 ClipmapWorldOrigin;
int2 ClipmapCornerOffset;
int ClipmapIndex; // 0..ClipmapLevelCount-1
int ClipmapLevel;
int ClipmapLevelCount;
float ClipmapResolutionLodBias;
// Derived data for convenience when passing the structure around
int VirtualShadowMapId;
};
FVirtualShadowMapProjectionShaderData DecodeVirtualShadowMapProjectionData(ByteAddressBuffer ProjectionData, int VirtualShadowMapId)
{
FVirtualShadowMapProjectionShaderData Result;
Result.VirtualShadowMapId = VirtualShadowMapId;
// Seems the FMatrix forces 16-byte alignment, so ensure padding matches the C++ structure size
const uint Stride = 16 * 21;
const uint Base = VirtualShadowMapId * Stride;
Result.TranslatedWorldToShadowViewMatrix[0] = asfloat(ProjectionData.Load4(Base + 16*0));
Result.TranslatedWorldToShadowViewMatrix[1] = asfloat(ProjectionData.Load4(Base + 16*1));
Result.TranslatedWorldToShadowViewMatrix[2] = asfloat(ProjectionData.Load4(Base + 16*2));
Result.TranslatedWorldToShadowViewMatrix[3] = asfloat(ProjectionData.Load4(Base + 16*3));
Result.ShadowViewToClipMatrix[0] = asfloat(ProjectionData.Load4(Base + 16*4));
Result.ShadowViewToClipMatrix[1] = asfloat(ProjectionData.Load4(Base + 16*5));
Result.ShadowViewToClipMatrix[2] = asfloat(ProjectionData.Load4(Base + 16*6));
Result.ShadowViewToClipMatrix[3] = asfloat(ProjectionData.Load4(Base + 16*7));
Result.TranslatedWorldToShadowUVMatrix[0] = asfloat(ProjectionData.Load4(Base + 16*8));
Result.TranslatedWorldToShadowUVMatrix[1] = asfloat(ProjectionData.Load4(Base + 16*9));
Result.TranslatedWorldToShadowUVMatrix[2] = asfloat(ProjectionData.Load4(Base + 16*10));
Result.TranslatedWorldToShadowUVMatrix[3] = asfloat(ProjectionData.Load4(Base + 16*11));
Result.TranslatedWorldToShadowUVNormalMatrix[0] = asfloat(ProjectionData.Load4(Base + 16*12));
Result.TranslatedWorldToShadowUVNormalMatrix[1] = asfloat(ProjectionData.Load4(Base + 16*13));
Result.TranslatedWorldToShadowUVNormalMatrix[2] = asfloat(ProjectionData.Load4(Base + 16*14));
Result.TranslatedWorldToShadowUVNormalMatrix[3] = asfloat(ProjectionData.Load4(Base + 16*15));
// NOTE: Stick with struct-element-sized loads for the moment since we may only be using subsets
// of the data in the calling code and we want to ensure the compiler has simple DCE options.
float3 PreViewTranslationTile = asfloat(ProjectionData.Load3(Base + (16*16 + 4*0)));
Result.LightType = (ProjectionData.Load (Base + (16*16 + 4*3)));
float3 PreViewTranslationOffset = asfloat(ProjectionData.Load3(Base + (16*17 + 4*0)));
Result.LightSourceRadius = asfloat(ProjectionData.Load (Base + (16*17 + 4*3)));
float3 NegativeClipmapWorldOriginOffset = asfloat(ProjectionData.Load3(Base + (16*18 + 4*0)));
Result.ClipmapResolutionLodBias = asfloat(ProjectionData.Load (Base + (16*18 + 4*3)));
Result.ClipmapCornerOffset = asint (ProjectionData.Load2(Base + (16*19 + 4*0)));
Result.ClipmapIndex = asint (ProjectionData.Load (Base + (16*19 + 4*2)));
Result.ClipmapLevel = asint (ProjectionData.Load (Base + (16*19 + 4*3)));
Result.ClipmapLevelCount = asint (ProjectionData.Load (Base + (16*20 + 4*0)));
Result.PreViewTranslation = MakeLWCVector3(PreViewTranslationTile, PreViewTranslationOffset);
Result.ClipmapWorldOrigin = LWCNegate(MakeLWCVector3(PreViewTranslationTile, NegativeClipmapWorldOriginOffset));
return Result;
}
FVirtualShadowMapProjectionShaderData GetVirtualShadowMapProjectionData(int VirtualShadowMapId)
{
return DecodeVirtualShadowMapProjectionData(VirtualShadowMap.ProjectionData, VirtualShadowMapId);
}