Files
UnrealEngineUWP/Engine/Shaders/DistanceFieldLightingShared.usf
Daniel Wright 09b9524d83 Distance Field AO optimizations profiling on Nvidia
Objects with no distance field representation (character) no longer receive DFAO, that was causing a huge amount of interpolation cost
Interpolation splat uses depth testing, splat bounding geometry is moved to front, with clamping to avoid near plane clipping
Background is stenciled out from interpolation splat pass
Experimental tiled compute interpolation implementation, disabled as it's slower
Covered over NaNs in interpolation pass which were getting expanded during filtering
Surface cache resources are allocated based on worst case of the current resolution, saves memory and prevents overflow

[CL 2311600 by Daniel Wright in Main branch]
2014-09-26 17:07:59 -04:00

103 lines
3.1 KiB
Plaintext

// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
/*=============================================================================
DistanceFieldLightingShared.usf
=============================================================================*/
#ifndef THREADGROUP_SIZEX
#define THREADGROUP_SIZEX 1
#endif
#ifndef THREADGROUP_SIZEY
#define THREADGROUP_SIZEY 1
#endif
#define THREADGROUP_TOTALSIZE (THREADGROUP_SIZEX * THREADGROUP_SIZEY)
#ifndef MAX_OBJECTS_PER_TILE
#define MAX_OBJECTS_PER_TILE 1
#endif
#ifndef DOWNSAMPLE_FACTOR
#define DOWNSAMPLE_FACTOR 1
#endif
float3 DistanceFieldVolumePositionToUV(float3 VolumePosition, float3 UVScale, float3 UVAdd)
{
float3 VolumeUV = VolumePosition * UVScale + UVAdd;
return VolumeUV;
}
Texture3D DistanceFieldTexture;
SamplerState DistanceFieldSampler;
float3 DistanceFieldAtlasTexelSize;
uint NumObjects;
// In float4's. Must match equivalent C++ variables.
#define OBJECT_DATA_STRIDE 8
#define OBJECT_DATA2_STRIDE 4
#define OBJECT_BOX_BOUNDS_STRIDE 5
Buffer<float4> ObjectBounds;
Buffer<float4> ObjectData;
Buffer<float4> ObjectData2;
Buffer<float4> ObjectBoxBounds;
float4 LoadObjectPositionAndRadius(uint ObjectIndex)
{
return ObjectBounds.Load(ObjectIndex);
}
float4x4 LoadObjectWorldToVolume(uint ObjectIndex)
{
float4 M0 = ObjectData.Load(ObjectIndex * OBJECT_DATA_STRIDE + 0);
float4 M1 = ObjectData.Load(ObjectIndex * OBJECT_DATA_STRIDE + 1);
float4 M2 = ObjectData.Load(ObjectIndex * OBJECT_DATA_STRIDE + 2);
float4 M3 = ObjectData.Load(ObjectIndex * OBJECT_DATA_STRIDE + 3);
return float4x4(M0, M1, M2, M3);
}
float3 LoadObjectLocalPositionExtent(uint ObjectIndex)
{
return ObjectData.Load(ObjectIndex * OBJECT_DATA_STRIDE + 4).xyz;
}
float4 LoadObjectLocalPositionExtentAndTwoSided(uint ObjectIndex)
{
return ObjectData.Load(ObjectIndex * OBJECT_DATA_STRIDE + 4).xyzw;
}
float4 LoadObjectUVScale(uint ObjectIndex)
{
return ObjectData.Load(ObjectIndex * OBJECT_DATA_STRIDE + 5).xyzw;
}
float3 LoadObjectUVAdd(uint ObjectIndex)
{
return ObjectData.Load(ObjectIndex * OBJECT_DATA_STRIDE + 6).xyz;
}
float4x4 LoadObjectVolumeToWorld(uint ObjectIndex)
{
float4 M0 = ObjectData2.Load(ObjectIndex * OBJECT_DATA2_STRIDE + 0);
float4 M1 = ObjectData2.Load(ObjectIndex * OBJECT_DATA2_STRIDE + 1);
float4 M2 = ObjectData2.Load(ObjectIndex * OBJECT_DATA2_STRIDE + 2);
float4 M3 = ObjectData2.Load(ObjectIndex * OBJECT_DATA2_STRIDE + 3);
return float4x4(M0, M1, M2, M3);
}
void LoadObjectViewSpaceBox(uint ObjectIndex, out float3 ObjectViewSpaceMin, out float3 ObjectViewSpaceMax)
{
ObjectViewSpaceMin = ObjectBoxBounds.Load(ObjectIndex * OBJECT_BOX_BOUNDS_STRIDE + 0).xyz;
ObjectViewSpaceMax = ObjectBoxBounds.Load(ObjectIndex * OBJECT_BOX_BOUNDS_STRIDE + 1).xyz;
}
void LoadObjectAxes(uint ObjectIndex, out float3 ObjectAxisX, out float3 ObjectAxisY, out float3 ObjectAxisZ)
{
ObjectAxisX = ObjectBoxBounds.Load(ObjectIndex * OBJECT_BOX_BOUNDS_STRIDE + 2).xyz;
ObjectAxisY = ObjectBoxBounds.Load(ObjectIndex * OBJECT_BOX_BOUNDS_STRIDE + 3).xyz;
ObjectAxisZ = ObjectBoxBounds.Load(ObjectIndex * OBJECT_BOX_BOUNDS_STRIDE + 4).xyz;
}