You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
75 lines
2.2 KiB
Plaintext
75 lines
2.2 KiB
Plaintext
//-----------------------------------------------------------------------------
|
|
// File: LPVBuildGeometryVolume.usf
|
|
//
|
|
// Summary: Compute shader to build a geometry volume from a VPL list
|
|
//
|
|
// Created: 2013-03-01
|
|
//
|
|
// Author: mailto:benwood@microsoft.com
|
|
//
|
|
// Copyright (C) Microsoft. All rights reserved.
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/*------------------------------------------------------------------------------
|
|
Compile time parameters:
|
|
------------------------------------------------------------------------------*/
|
|
|
|
#include "Common.usf"
|
|
#include "LPVWriteCommon.usf"
|
|
#include "LPVGeometryVolumeCommon.usf"
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
#define LPV_MULTIPLE_BOUNCES_ENABLED LPV_MULTIPLE_BOUNCES
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
StructuredBuffer<VplListEntry> gGvListBuffer;
|
|
ByteAddressBuffer gGvListHeadBuffer;
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
[numthreads(4,4,4)]
|
|
void CSBuildGeometryVolume(uint3 DTid : SV_DispatchThreadID)
|
|
{
|
|
int index = GetGridAddress( DTid );
|
|
if ( index == -1 ) return;
|
|
|
|
uint listIndex = gGvListHeadBuffer.Load( index*4 );
|
|
|
|
GeometryVolumeEntry cell;
|
|
[unroll]
|
|
for ( int i=0; i<9; i++ ) cell.SH[i] = 0;
|
|
|
|
#if LPV_MULTIPLE_BOUNCES_ENABLED
|
|
// cell.color records the average color for the cell (it is not cumulative)
|
|
cell.color = 0.0f;
|
|
#endif
|
|
|
|
uint count = 0;
|
|
while (listIndex != -1 )
|
|
{
|
|
VplListEntry listEntry = gGvListBuffer[ listIndex ];
|
|
Vpl vpl = UnpackVpl( listEntry );
|
|
|
|
// Weight according to projected texel size 1 / N dot L
|
|
float nDotL = abs( dot( LpvWrite.GeometryVolumeCaptureLightDirection.xyz, vpl.normal ) );
|
|
nDotL = max( nDotL, 0.25f ); // Clamp to prevent divBy0 and and general weirdness due to undersampling
|
|
float weight = 0.15 / nDotL;
|
|
|
|
#if LPV_MULTIPLE_BOUNCES_ENABLED
|
|
cell.color += vpl.flux;
|
|
#endif
|
|
AccumulateCoeffsScalar( weight, vpl.normal, cell.SH );
|
|
count++;
|
|
if ( count > 32 ) break; // Prevent huge spikes in this shader on PC
|
|
listIndex = listEntry.nextIndex;
|
|
}
|
|
|
|
#if LPV_MULTIPLE_BOUNCES_ENABLED
|
|
count = max(count,1);
|
|
cell.color /= (float)(count);
|
|
#endif
|
|
|
|
WriteGvCell( index, cell );
|
|
} |