浏览代码

Working implementation of stereo big tile

Need to clean up comments, but wanted to leave them in here for posterity (useful dev notes in there)
/main
Robert Srinivasiah 7 年前
当前提交
1dbc76c2
共有 2 个文件被更改,包括 48 次插入14 次删除
  1. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
  2. 60
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/lightlistbuild-bigtile.compute

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs


cmd.SetComputeBufferParam(buildPerBigTileLightListShader, s_GenListPerBigTileKernel, HDShaderIDs.g_data, s_ConvexBoundsBuffer);
int tgZ = m_FrameSettings.enableStereo ? 2 : 1;
tgZ = 1;
//cmd.DispatchCompute(buildPerBigTileLightListShader, s_GenListPerBigTileKernel, numBigTilesX, numBigTilesY, 1);
cmd.DispatchCompute(buildPerBigTileLightListShader, s_GenListPerBigTileKernel, numBigTilesX, numBigTilesY, tgZ);
}

60
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/lightlistbuild-bigtile.compute


#include "LightLoop.cs.hlsl"
#include "LightingConvexHullUtils.hlsl"
#include "SortingComputeUtils.hlsl"
#include "LightCullUtils.hlsl"
#pragma only_renderers d3d11 ps4 xboxone vulkan metal

uint iWidth = g_viDimensions.x;
uint iHeight = g_viDimensions.y;
// TODO: Should we be re-calculating this?
uint nrBigTilesX = (iWidth+63)/64;
uint nrBigTilesY = (iHeight+63)/64;

// build coarse list using AABB
for(int l=(int) t; l<(int) g_iNrVisibLights; l += NR_THREADS)
{
// XRTODO: generate a 'real' index into the correct half of g_vBoundsBuffer
// XRTODO - DONE: generate a 'real' index into the correct half of g_vBoundsBuffer
const float2 vMi = g_vBoundsBuffer[l].xy;
const float2 vMa = g_vBoundsBuffer[l+g_iNrVisibLights].xy;
// Actually, g_vBoundsBuffer will be significantly different than _LightVolumeData/g_data
// but I solved this by using helper function
// In the monoscopic mode, there is one set of bounds (min,max -> 2 * g_iNrVisibLights)
// In stereo, there are two sets of bounds (leftMin, leftMax, rightMin, rightMax -> 4 * g_iNrVisibLights)
// Might be worth creating helper functions for this
//const int eyeRelativeBase = 2 * eyeIndex * (int)g_iNrVisibLights;
//const int minBoundsIndex = eyeRelativeBase + l;
//const int maxBoundsIndex = eyeRelativeBase + l + (int)g_iNrVisibLights;
//const int2 boundsIndices = GenerateScreenSpaceBoundsIndices(l, g_iNrVisibLights, eyeIndex);
const ScreenSpaceBoundsIndices boundsIndices = GenerateScreenSpaceBoundsIndices(l, g_iNrVisibLights, eyeIndex);
//const float2 vMi = g_vBoundsBuffer[l].xy;
//const float2 vMa = g_vBoundsBuffer[l+g_iNrVisibLights].xy;
//const float2 vMi = g_vBoundsBuffer[minBoundsIndex].xy;
//const float2 vMa = g_vBoundsBuffer[maxBoundsIndex].xy;
//const float2 vMi = g_vBoundsBuffer[boundsIndices.x].xy;
//const float2 vMa = g_vBoundsBuffer[boundsIndices.y].xy;
const float2 vMi = g_vBoundsBuffer[boundsIndices.min].xy;
const float2 vMa = g_vBoundsBuffer[boundsIndices.max].xy;
if( all(vMa>vTileLL) && all(vMi<vTileUR))
{

// XRTODO - DONE: We store the 'plain' light list index, not stereo-adjusted
if(uIndex<MAX_NR_BIGTILE_LIGHTS) lightsListLDS[uIndex] = l; // add to light list
}
}

if(t==0) lightOffs = 0;
GroupMemoryBarrierWithGroupSync();
int i;
// XRTODO: Fix up check against g_iNrVisibLights to account for stereo
// XRTODO - DONE: Fix up check against g_iNrVisibLights to account for stereo
// If we store the un-adjusted index, we are safe to compare against g_iNrVisibLights
// XRTODO: Fix up the offset into the stereo-ized big tile list
int offs = tileIDX.y*nrBigTilesX + tileIDX.x;
// XRTODO - DONE: Fix up the offset into the stereo-ized big tile list
//int offs = tileIDX.y*nrBigTilesX + tileIDX.x;
int offs = tileIDX.y*nrBigTilesX + tileIDX.x + (eyeIndex * nrBigTilesX * nrBigTilesY);
// XRTODO: Do I want to encode the global index, or per-eye-relative index? The light list code later on
// XRTODO - DONE: Do I want to encode the global index, or per-eye-relative index? The light list code later on
// I think I want to encode the per-eye-relative-index (the normal one). This helps with tests against g_iNrVisibLights
for(i=t; i<(iNrCoarseLights+1); i+=NR_THREADS)
g_vLightList[MAX_NR_BIG_TILE_LIGHTS_PLUS_ONE*offs + i] = i==0 ? iNrCoarseLights : lightsListLDS[max(i-1, 0)];
}

for(int l=threadID; l<iNrCoarseLights; l+=NR_THREADS)
{
SFiniteLightBound lgtDat = g_data[lightsListLDS[l]];
// XRTODO - DONE: Is the value in lightsListLDS[l] stereo-corrected?
// It is not, so we need to correct it before using it in g_data
//SFiniteLightBound lgtDat = g_data[lightsListLDS[l]];
const int boundIndex = GenerateLightCullDataIndex(lightsListLDS[l], g_iNrVisibLights, eyeIndex);
SFiniteLightBound lgtDat = g_data[boundIndex];
if( !DoesSphereOverlapTile(V, halfTileSizeAtZDistOne, lgtDat.center.xyz, lgtDat.radius, g_isOrthographic!=0) )
lightsListLDS[l]=UINT_MAX;

const int totNrEdgePairs = 12*nrFrustEdges;
for(int l=0; l<iNrCoarseLights; l++)
{
// XRTODO - DONE: Where does this need to be corrected?
// One index for comparing against g_iNrVisibLights, one index for buffer lookups
const int bufIdxCoarse = GenerateLightCullDataIndex(idxCoarse, g_iNrVisibLights, eyeIndex);
// XRTODO: This will fail for stereo right eye, because it can't be compared against the count for one
// eye.
// XRTODO - DONE: This is safe with uncorrected indices
if(canEnter) canEnter = _LightVolumeData[idxCoarse].lightVolume != LIGHTVOLUMETYPE_SPHERE; // don't bother doing edge tests for sphere lights since these have camera aligned bboxes.
// XRTODO - DONE: We need to correct before indexing into _LightVolumeData
//if (canEnter) canEnter = _LightVolumeData[idxCoarse].lightVolume != LIGHTVOLUMETYPE_SPHERE; // don't bother doing edge tests for sphere lights since these have camera aligned bboxes.
if(canEnter) canEnter = _LightVolumeData[bufIdxCoarse].lightVolume != LIGHTVOLUMETYPE_SPHERE; // don't bother doing edge tests for sphere lights since these have camera aligned bboxes.
SFiniteLightBound lgtDat = g_data[idxCoarse];
// XRTODO - DONE: We need to correct before indexing into g_data
//SFiniteLightBound lgtDat = g_data[idxCoarse];
SFiniteLightBound lgtDat = g_data[bufIdxCoarse];
const float3 boxX = lgtDat.boxAxisX.xyz;
const float3 boxY = lgtDat.boxAxisY.xyz;

正在加载...
取消
保存