You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
87 lines
2.8 KiB
Plaintext
87 lines
2.8 KiB
Plaintext
//-----------------------------------------------------------------------------
|
|
// File: LPVWriteVPLCommmon.usf
|
|
//
|
|
// Summary: Common functionality for LPV vpl list write
|
|
//
|
|
// Created: 2013-03-01
|
|
//
|
|
// Author: mailto:benwood@microsoft.com
|
|
//
|
|
// Copyright (C) Microsoft. All rights reserved.
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
|
#include "LPVWriteCommon.usf"
|
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
|
RWStructuredBuffer<VplListEntry> gGvListBufferRW; // 0
|
|
RWByteAddressBuffer gGvListHeadBufferRW; // 1
|
|
|
|
RWStructuredBuffer<VplListEntry> gVplListBufferRW; // 2
|
|
RWByteAddressBuffer gVplListHeadBufferRW; // 3
|
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
// Functions
|
|
//-------------------------------------------------------------------------------------------------
|
|
int AddToVplList( float3 worldPos, float3 flux, float3 direction, const bool emissiveInjection )
|
|
{
|
|
int gridIndex = GetGridIndex( worldPos );
|
|
[branch]
|
|
if ( gridIndex >= 0 )
|
|
{
|
|
// Allocate a new list entry
|
|
uint newHeadIndex = gVplListBufferRW.IncrementCounter();
|
|
uint oldHeadIndex;
|
|
gVplListHeadBufferRW.InterlockedExchange( gridIndex*4, newHeadIndex, oldHeadIndex );
|
|
|
|
if ( emissiveInjection )
|
|
{
|
|
// Weight according to projected texel size 1 / N dot L
|
|
float nDotL = abs( dot( LpvWrite.GeometryVolumeCaptureLightDirection.xyz, direction ) );
|
|
nDotL = max( nDotL, 0.25f ); // Clamp to prevent divBy0 and and general weirdness due to undersampling
|
|
flux *= 1.0f / nDotL;
|
|
}
|
|
|
|
// Fill in the new list node
|
|
Vpl vpl;
|
|
vpl.normal = direction;
|
|
vpl.flux = flux;
|
|
|
|
VplListEntry listNode = PackVpl( vpl );
|
|
listNode.nextIndex = oldHeadIndex;
|
|
gVplListBufferRW[ newHeadIndex ] = listNode;
|
|
}
|
|
return gridIndex;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
|
int AddToGvList( float3 worldPos, float3 flux, float3 direction )
|
|
{
|
|
// Gv is offset by half
|
|
float3 offset = ( LpvWrite.LpvScale * 0.5f ).xxx;
|
|
int gridIndex = GetGridIndex( worldPos + offset );
|
|
[branch]
|
|
if ( gridIndex >= 0 )
|
|
{
|
|
// Allocate a new list entry
|
|
uint newHeadIndex = gGvListBufferRW.IncrementCounter();
|
|
uint oldHeadIndex;
|
|
gGvListHeadBufferRW.InterlockedExchange( gridIndex*4, newHeadIndex, oldHeadIndex );
|
|
|
|
// Fill in the new list node
|
|
Vpl vpl;
|
|
vpl.normal = direction;
|
|
vpl.flux = flux;
|
|
|
|
VplListEntry listNode = PackVpl( vpl );
|
|
listNode.nextIndex = oldHeadIndex;
|
|
gGvListBufferRW[ newHeadIndex ] = listNode;
|
|
}
|
|
return gridIndex;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------------------------
|