Files
UnrealEngineUWP/Engine/Shaders/LPVInject_AccumulateVplLists.usf
2014-03-14 14:13:41 -04:00

79 lines
2.4 KiB
Plaintext

//-----------------------------------------------------------------------------
// File: LPVInject_AccumulateVplLists.usf
//
// Summary: LPVInject_AccumulateVplLists.usf: Compute shader to inject lists
// of VPLs into into an LPV
//
// Runs once per LPV
//
// Created: 2013-03-01
//
// Author: mailto:benwood@microsoft.com
//
// Copyright (C) Microsoft. All rights reserved.
//-----------------------------------------------------------------------------
/*------------------------------------------------------------------------------
Compile time parameters:
------------------------------------------------------------------------------*/
#include "Common.usf"
#include "LPVWriteCommon.usf"
#define LIGHT_INJECTION_ENABLED 1
#define LIGHT_INJECTION_DEBUG_TEST 0
//------------------------------------------------------------------------------
StructuredBuffer<VplListEntry> gVplListBuffer;
ByteAddressBuffer gVplListHeadBuffer;
//------------------------------------------------------------------------------
[numthreads(4,4,4)]
void CSAccumulateVplLists(uint3 DTid : SV_DispatchThreadID)
{
int index = GetGridAddress( DTid );
uint listIndex = gVplListHeadBuffer.Load( index*4 );
#if !LIGHT_INJECTION_ENABLED
return;
#endif
#if LPV_VOLUME_TEXTURE
LPVCell cell = ReadLpvCell( index );
#else
LPVCell cell = ReadLpvCell( index, true );
#endif
#if LIGHT_INJECTION_DEBUG_TEST
float3 testPos = float3(989,-684,565);
int testIndex = GetGridIndex( testPos );
if ( testIndex == index )
{
float3 col = float3(0.0f, 10000.0f, 0.0f);
float solidAngle = 3.14; // TODO: adjust for splat size
AccumulateLighting( col, float3(-1, 0, 0 ), solidAngle, cell );
AccumulateLighting( col, float3( 1, 0, 0 ), solidAngle, cell );
AccumulateLighting( col, float3( 0,-1, 0 ), solidAngle, cell );
AccumulateLighting( col, float3( 0, 1, 0 ), solidAngle, cell );
AccumulateLighting( col, float3( 0, 0,-1 ), solidAngle, cell );
AccumulateLighting( col, float3( 0, 0, 1 ), solidAngle, cell );
}
WriteLpvCell( cell, index );
return;
#else
uint count = 0;
while ( listIndex != -1 )
{
VplListEntry listEntry = gVplListBuffer[ listIndex ];
Vpl vpl = UnpackVpl( listEntry );
float solidAngle = 3.14; // TODO: adjust for splat size
AccumulateLighting( vpl.flux, -vpl.normal, solidAngle, cell );
listIndex = listEntry.nextIndex;
count++;
}
WriteLpvCell( cell, index );
#endif
}