浏览代码

more random fixes to new clustered implementation (still disabled)

more random fixes to new clustered implementation (still disabled)
/main
mmikk 8 年前
当前提交
bdf1c521
共有 3 个文件被更改,包括 42 次插入24 次删除
  1. 5
      Assets/ScriptableRenderLoop/common/ShaderBase.h
  2. 20
      Assets/ScriptableRenderLoop/fptl/FptlLighting.cs
  3. 41
      Assets/ScriptableRenderLoop/fptl/lightlistbuild-clustered.compute

5
Assets/ScriptableRenderLoop/common/ShaderBase.h


return 1 - depthTexture.Load(uint3(pixCoord.xy, 0)).x;
}
float FetchDepthMSAA(Texture2DMS<float> depthTexture, uint2 pixCoord, uint sampleIdx)
{
return 1 - depthTexture.Load(uint3(pixCoord.xy, 0), sampleIdx).x;
}
#endif

20
Assets/ScriptableRenderLoop/fptl/FptlLighting.cs


static private int kGenAABBKernel;
static private int kGenListPerTileKernel;
static private int kGenListPerVoxelKernel;
static private int kClearVoxelAtomicKernel;
static private ComputeBuffer m_lightDataBuffer;
static private ComputeBuffer m_convexBoundsBuffer;
static private ComputeBuffer m_aabbBoundsBuffer;

static private ComputeBuffer m_perVoxelLightLists;
static private ComputeBuffer m_perVoxelOffset;
static private ComputeBuffer m_globalLightListAtomic;
static private ComputeBuffer m_singleZeroUInt; // lazy way to clear m_globalLightListAtomic once per frame
// clustered light list specific buffers and data end
static private int m_WidthOnRecord;

{
if(m_globalLightListAtomic!=null)
m_globalLightListAtomic.Release();
if(m_singleZeroUInt!=null)
m_singleZeroUInt.Release();
}
}

if(gEnableClustered)
{
kGenListPerVoxelKernel = m_BuildPerVoxelLightListShader.FindKernel("TileLightListGen");
kGenListPerVoxelKernel = m_BuildPerVoxelLightListShader.FindKernel("TileLightListGen_NoDepthRT");
kClearVoxelAtomicKernel = m_BuildPerVoxelLightListShader.FindKernel("ClearAtomic");
m_singleZeroUInt = new ComputeBuffer(1, sizeof(uint));
}
m_cookieTexArray = new TextureCache2D();

if(gEnableClustered)
{
m_globalLightListAtomic.Release();
m_singleZeroUInt.Release();
}
}

void VoxelLightListGeneration(CommandBuffer cmd, Camera camera, int numLights, Matrix4x4 projscr, Matrix4x4 invProjscr)
{
// copy resource m_globalLightListAtomic <-- m_singleZeroUInt
// clear atomic offset index
cmd.SetComputeBufferParam(m_BuildPerVoxelLightListShader, kClearVoxelAtomicKernel, "g_LayeredSingleIdxBuffer", m_globalLightListAtomic);
cmd.ComputeDispatch(m_BuildPerVoxelLightListShader, kClearVoxelAtomicKernel, 1, 1, 1);
cmd.SetComputeIntParam(m_BuildPerVoxelLightListShader, "g_iNrVisibLights", numLights);
SetMatrixCS(cmd, m_BuildPerVoxelLightListShader, "g_mScrProjection", projscr);
SetMatrixCS(cmd, m_BuildPerVoxelLightListShader, "g_mInvScrProjection", invProjscr);

cmd.SetComputeBufferParam(m_BuildPerVoxelLightListShader, kGenListPerVoxelKernel, "g_vLayeredLightList", m_perVoxelLightLists);
cmd.SetComputeBufferParam(m_BuildPerVoxelLightListShader, kGenListPerVoxelKernel, "g_LayeredOffset", m_perVoxelOffset);
cmd.SetComputeBufferParam(m_BuildPerVoxelLightListShader, kGenListPerVoxelKernel, "g_LayeredSingleIdxBuffer", m_globalLightListAtomic);
//cmd.ComputeDispatch(m_BuildPerVoxelLightListShader, kGenListPerVoxelKernel, nrTilesX, nrTilesY, 1);
int nrTilesX = (camera.pixelWidth + 15) / 16;
int nrTilesY = (camera.pixelHeight + 15) / 16;
cmd.ComputeDispatch(m_BuildPerVoxelLightListShader, kGenListPerVoxelKernel, nrTilesX, nrTilesY, 1);
}
}
}

41
Assets/ScriptableRenderLoop/fptl/lightlistbuild-clustered.compute


#pragma kernel TileLightListGen
#pragma kernel TileLightListGen_NoDepthRT
#pragma kernel TileLightListGen_DepthRT ENABLE_DEPTH_TEXTURE_BACKPLANE
#pragma kernel TileLightListGen_DepthRT_MSAA ENABLE_DEPTH_TEXTURE_BACKPLANE MSAA_ENABLED
#pragma kernel ClearAtomic
#include "..\common\ShaderBase.h"
#include "LightDefinitions.cs.hlsl"

bool CheckIntersection(int l, int k, uint2 viTilLL, uint2 viTilUR, float fModulUserScale)
{
unsigned int val = (clusterIdxs[l>>1]>>(16*(l&1)))&0xffff;
bool bIsHit = ((val>>0)&0xff)<=k && k<=((val>>8)&0xff);
bool bIsHit = ((val>>0)&0xff)<=((uint) k) && ((uint) k)<=((val>>8)&0xff);
if(bIsHit)
{
#ifdef CONV_HULL_TEST_ENABLED

bool CheckIntersectionBasic(int l, int k)
{
unsigned int val = (clusterIdxs[l>>1]>>(16*(l&1)))&0xffff;
return ((val>>0)&0xff)<=k && k<=((val>>8)&0xff);
return ((val>>0)&0xff)<=((uint) k) && ((uint) k)<=((val>>8)&0xff);
}

#endif
//////////// cell specific code
for(int l=(int) t; l<((iNrCoarseLights+1)>>1); l += NR_THREADS)
const int l0 = coarseList[2*l+0], l1 = coarseList[min(2*l+1,iNrCoarseLights)];
const unsigned int clustIdxMi0 = (const unsigned int) min(255,SnapToClusterIdx(GetLinearDepth(g_vBoundsBuffer[l0].z), fModulUserScale));
const unsigned int clustIdxMa0 = (const unsigned int) min(255,SnapToClusterIdx(GetLinearDepth(g_vBoundsBuffer[l0+g_iNrVisibLights].z), fModulUserScale));
const unsigned int clustIdxMi1 = (const unsigned int) min(255,SnapToClusterIdx(GetLinearDepth(g_vBoundsBuffer[l1].z), fModulUserScale));
const unsigned int clustIdxMa1 = (const unsigned int) min(255,SnapToClusterIdx(GetLinearDepth(g_vBoundsBuffer[l1+g_iNrVisibLights].z), fModulUserScale));
for(int l=(int) t; l<((iNrCoarseLights+1)>>1); l += NR_THREADS)
{
const int l0 = coarseList[2*l+0], l1 = coarseList[min(2*l+1,iNrCoarseLights)];
const unsigned int clustIdxMi0 = (const unsigned int) min(255,SnapToClusterIdx(GetLinearDepth(g_vBoundsBuffer[l0].z), fModulUserScale));
const unsigned int clustIdxMa0 = (const unsigned int) min(255,SnapToClusterIdx(GetLinearDepth(g_vBoundsBuffer[l0+g_iNrVisibLights].z), fModulUserScale));
const unsigned int clustIdxMi1 = (const unsigned int) min(255,SnapToClusterIdx(GetLinearDepth(g_vBoundsBuffer[l1].z), fModulUserScale));
const unsigned int clustIdxMa1 = (const unsigned int) min(255,SnapToClusterIdx(GetLinearDepth(g_vBoundsBuffer[l1+g_iNrVisibLights].z), fModulUserScale));
clusterIdxs[l] = (clustIdxMa1<<24) | (clustIdxMi1<<16) | (clustIdxMa0<<8) | (clustIdxMi0<<0);
clusterIdxs[l] = (clustIdxMa1<<24) | (clustIdxMi1<<16) | (clustIdxMa0<<8) | (clustIdxMi0<<0);
}
}
#if !defined(XBONE) && !defined(PLAYSTATION4)

}
uint localOffs=0;
uint idx = i*nrTilesX*nrTilesY + tileIDX.y*nrTilesX + tileIDX.x;
offs = i*nrTilesX*nrTilesY + tileIDX.y*nrTilesX + tileIDX.x;
g_LayeredOffset[idx] = (start+localOffs) | (((uint) numLights)<<27);
idx += (nrClusters*nrTilesX*nrTilesY);
g_LayeredOffset[offs] = (start+localOffs) | (((uint) numLights)<<27);
offs += (nrClusters*nrTilesX*nrTilesY);
localOffs += modelListCount[m]; // use unclamped count for localOffs
}
}

#endif
return lightOffs2;
}
#endif
#endif
[numthreads(1, 1, 1)]
void ClearAtomic(uint threadID : SV_GroupIndex, uint3 u3GroupID : SV_GroupID)
{
g_LayeredSingleIdxBuffer[0]=0;
}
正在加载...
取消
保存