浏览代码

HDRenderLoop: Fix issue with tile list index + Rename SFiniteLightData to LightShapeData

/main
sebastienlagarde 8 年前
当前提交
610894d8
共有 5 个文件被更改,包括 86 次插入82 次删除
  1. 4
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/Resources/lightlistbuild-bigtile.compute
  2. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/Resources/lightlistbuild-clustered.compute
  3. 27
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/Resources/lightlistbuild.compute
  4. 92
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.cs
  5. 37
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.cs.hlsl

4
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/Resources/lightlistbuild-bigtile.compute


uniform float g_fFarPlane;
StructuredBuffer<float3> g_vBoundsBuffer : register( t1 );
StructuredBuffer<SFiniteLightData> g_vLightData : register( t2 );
StructuredBuffer<LightShapeData> _LightShapeData : register(t2);
StructuredBuffer<SFiniteLightBound> g_data : register( t3 );

for(int l=0; l<iNrCoarseLights; l++)
{
const uint idxCoarse = lightsListLDS[l];
[branch]if(idxCoarse<(uint) g_iNrVisibLights && g_vLightData[idxCoarse].lightType!=SPHERE_LIGHT) // don't bother doing edge tests for sphere lights since these have camera aligned bboxes.
[branch]if (idxCoarse<(uint)g_iNrVisibLights && _LightShapeData[idxCoarse].lightType != SPHERE_LIGHT) // don't bother doing edge tests for sphere lights since these have camera aligned bboxes.
{
SFiniteLightBound lgtDat = g_data[idxCoarse];

8
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/Resources/lightlistbuild-clustered.compute


Texture2D g_depth_tex : register( t0 );
#endif
StructuredBuffer<float3> g_vBoundsBuffer : register( t1 );
StructuredBuffer<SFiniteLightData> g_vLightData : register( t2 );
StructuredBuffer<LightShapeData> _LightShapeData : register(t2);
StructuredBuffer<SFiniteLightBound> g_data : register( t3 );
#ifdef USE_TWO_PASS_TILED_LIGHTING

{
if(offs<(start+iSpaceAvail) && i<nrClusters && CheckIntersection(l, i, viTilLL.xy, viTilUR.xy, suggestedBase) )
{
uint lightModel = g_vLightData[ coarseList[l] ].lightModel;
++modelListCount[ lightModel==REFLECTION_LIGHT ? 1 : 0];
uint lightCategory = _LightShapeData[coarseList[l]].lightCategory;
++modelListCount[lightCategory == REFLECTION_LIGHT ? 1 : 0];
g_vLayeredLightList[offs++] = coarseList[l]; // reflection lights will be last since we sorted
}
}

GroupMemoryBarrierWithGroupSync();
#endif
const int idxCoarse = coarseList[l];
[branch]if(g_vLightData[idxCoarse].lightType!=SPHERE_LIGHT) // don't bother doing edge tests for sphere lights since these have camera aligned bboxes.
[branch]if (_LightShapeData[idxCoarse].lightType != SPHERE_LIGHT) // don't bother doing edge tests for sphere lights since these have camera aligned bboxes.
{
SFiniteLightBound lgtDat = g_data[idxCoarse];

27
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/Resources/lightlistbuild.compute


uniform int g_iNrVisibLights;
uniform int _PunctualLightCount;
uniform uint2 g_viDimensions;
uniform float4x4 g_mInvScrProjection;
uniform float4x4 g_mScrProjection;

StructuredBuffer<float3> g_vBoundsBuffer : register( t1 );
StructuredBuffer<SFiniteLightData> g_vLightData : register( t2 );
StructuredBuffer<LightShapeData> _LightShapeData : register(t2);
StructuredBuffer<SFiniteLightBound> g_data : register( t3 );
#ifdef USE_TWO_PASS_TILED_LIGHTING

int nrLightsCombinedList = min(ldsNrLightsFinal,MAX_NR_COARSE_ENTRIES);
for(int i=t; i<nrLightsCombinedList; i+=NR_THREADS)
{
InterlockedAdd(ldsModelListCount[ g_vLightData[ prunedList[i] ].lightModel ], 1);
InterlockedAdd(ldsModelListCount[_LightShapeData[prunedList[i]].lightCategory], 1);
}

// write lights to global buffers
int localOffs=0;
int offs = tileIDX.y*nrTilesX + tileIDX.x;
// This should thow a warning if NR_LIGHT_MODELS change
int indicesShift[NR_LIGHT_MODELS] = {0, _PunctualLightCount};
for(int m=0; m<NR_LIGHT_MODELS; m++)
{

const int nrDWords = ((nrLightsFinalClamped+1)+1)>>1;
for(int l=(int) t; l<(int) nrDWords; l += NR_THREADS)
{
uint uLow = l==0 ? nrLightsFinalClamped : prunedList[2*l-1+localOffs] - indicesShift[m];
uint uHigh = prunedList[2*l+0+localOffs] - indicesShift[m];
// We remap the prunedList index to the original LightData / EnvLightData indices
uint uLow = l==0 ? nrLightsFinalClamped : _LightShapeData[prunedList[2*l-1+localOffs]].lightIndex;
uint uHigh = _LightShapeData[prunedList[2 * l + 0 + localOffs]].lightIndex;
g_vLightList[16*offs + l] = (uLow&0xffff) | (uHigh<<16);
}

{
// fetch light
int idxCoarse = l<iNrCoarseLights ? coarseList[l] : 0;
uint uLgtType = l<iNrCoarseLights ? g_vLightData[idxCoarse].lightType : 0;
uint uLgtType = l<iNrCoarseLights ? _LightShapeData[idxCoarse].lightType : 0;
SFiniteLightData lightData = g_vLightData[idxCoarse];
LightShapeData lightData = _LightShapeData[idxCoarse];
// TODO: Change by SebL
const bool bIsSpotDisc = true; // (lightData.flags&IS_CIRCULAR_SPOT_SHAPE) != 0;

uLightsFlags[l<32 ? 0 : 1] |= (uVal<<(l&31));
++l; idxCoarse = l<iNrCoarseLights ? coarseList[l] : 0;
uLgtType = l<iNrCoarseLights ? g_vLightData[idxCoarse].lightType : 0;
uLgtType = l<iNrCoarseLights ? _LightShapeData[idxCoarse].lightType : 0;
SFiniteLightData lightData = g_vLightData[idxCoarse];
LightShapeData lightData = _LightShapeData[idxCoarse];
// serially check 4 pixels
uint uVal = 0;

uLightsFlags[l<32 ? 0 : 1] |= (uVal<<(l&31));
++l; idxCoarse = l<iNrCoarseLights ? coarseList[l] : 0;
uLgtType = l<iNrCoarseLights ? g_vLightData[idxCoarse].lightType : 0;
uLgtType = l<iNrCoarseLights ? _LightShapeData[idxCoarse].lightType : 0;
SFiniteLightData lightData = g_vLightData[idxCoarse];
LightShapeData lightData = _LightShapeData[idxCoarse];
// serially check 4 pixels
uint uVal = 0;

uLightsFlags[l<32 ? 0 : 1] |= (uVal<<(l&31));
++l; idxCoarse = l<iNrCoarseLights ? coarseList[l] : 0;
uLgtType = l<iNrCoarseLights ? g_vLightData[idxCoarse].lightType : 0;
uLgtType = l<iNrCoarseLights ? _LightShapeData[idxCoarse].lightType : 0;
}
// in case we have some corrupt data make sure we terminate

92
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.cs


};
[GenerateHLSL]
public struct SFiniteLightData
public struct LightShapeData
public uint lightIndex; // Index in light tabs like LightData / EnvLightData
public Vector3 lightAxisX;
public uint lightType;

public float cotan;
public Vector3 boxInnerDist;
public uint lightModel; // DIRECT_LIGHT=0, REFLECTION_LIGHT=1
public uint lightCategory; // DIRECT_LIGHT=0, REFLECTION_LIGHT=1
public Vector3 boxInvRange;
public float unused2;

private static int s_GenListPerTileKernel;
private static int s_GenListPerVoxelKernel;
private static int s_ClearVoxelAtomicKernel;
private static ComputeBuffer s_LightDataBuffer;
private static ComputeBuffer s_LightShapeDataBuffer;
private static ComputeBuffer s_ConvexBoundsBuffer;
private static ComputeBuffer s_AABBBoundsBuffer;
private static ComputeBuffer s_LightList;

// clustered light list specific buffers and data end
SFiniteLightBound[] m_boundData;
SFiniteLightData[] m_lightData;
LightShapeData[] m_lightShapeData;
int m_lightCount;
bool usingFptl

if (s_ConvexBoundsBuffer != null)
s_ConvexBoundsBuffer.Release();
if (s_LightDataBuffer != null)
s_LightDataBuffer.Release();
if (s_LightShapeDataBuffer != null)
s_LightShapeDataBuffer.Release();
if (enableClustered)
{

s_GenListPerTileKernel = buildPerTileLightListShader.FindKernel(enableBigTilePrepass ? "TileLightListGen_SrcBigTile" : "TileLightListGen");
s_AABBBoundsBuffer = new ComputeBuffer(2 * MaxNumLights, 3 * sizeof(float));
s_ConvexBoundsBuffer = new ComputeBuffer(MaxNumLights, System.Runtime.InteropServices.Marshal.SizeOf(typeof(SFiniteLightBound)));
s_LightDataBuffer = new ComputeBuffer(MaxNumLights, System.Runtime.InteropServices.Marshal.SizeOf(typeof(SFiniteLightData)));
s_LightShapeDataBuffer = new ComputeBuffer(MaxNumLights, System.Runtime.InteropServices.Marshal.SizeOf(typeof(LightShapeData)));
buildPerTileLightListShader.SetBuffer(s_GenListPerTileKernel, "g_vLightData", s_LightDataBuffer);
buildPerTileLightListShader.SetBuffer(s_GenListPerTileKernel, "_LightShapeData", s_LightShapeDataBuffer);
buildPerTileLightListShader.SetBuffer(s_GenListPerTileKernel, "g_data", s_ConvexBoundsBuffer);
if (enableClustered)

s_ClearVoxelAtomicKernel = buildPerVoxelLightListShader.FindKernel("ClearAtomic");
buildPerVoxelLightListShader.SetBuffer(s_GenListPerVoxelKernel, "g_vBoundsBuffer", s_AABBBoundsBuffer);
buildPerVoxelLightListShader.SetBuffer(s_GenListPerVoxelKernel, "g_vLightData", s_LightDataBuffer);
buildPerVoxelLightListShader.SetBuffer(s_GenListPerVoxelKernel, "_LightShapeData", s_LightShapeDataBuffer);
buildPerVoxelLightListShader.SetBuffer(s_GenListPerVoxelKernel, "g_data", s_ConvexBoundsBuffer);
s_GlobalLightListAtomic = new ComputeBuffer(1, sizeof(uint));

{
s_GenListPerBigTileKernel = buildPerBigTileLightListShader.FindKernel("BigTileLightListGen");
buildPerBigTileLightListShader.SetBuffer(s_GenListPerBigTileKernel, "g_vBoundsBuffer", s_AABBBoundsBuffer);
buildPerBigTileLightListShader.SetBuffer(s_GenListPerBigTileKernel, "g_vLightData", s_LightDataBuffer);
buildPerBigTileLightListShader.SetBuffer(s_GenListPerBigTileKernel, "_LightShapeData", s_LightShapeDataBuffer);
m_lightData = new SFiniteLightData[MaxNumLights];
m_lightShapeData = new LightShapeData[MaxNumLights];
m_lightCount = 0;
s_DirectionalLights = new ComputeBuffer(HDRenderLoop.k_MaxDirectionalLightsOnSCreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(DirectionalLightData)));

s_AABBBoundsBuffer.Release();
s_ConvexBoundsBuffer.Release();
s_LightDataBuffer.Release();
s_LightShapeDataBuffer.Release();
ReleaseResolutionDependentBuffers();
if (enableClustered)

// add decals here too similar to the above
// establish offsets
for (var m = 0; m < numModels; m++)
for (int m = 0; m < numModels; m++)
for (var v = 1; v < numVolTypes; v++)
for (int v = 1; v < numVolTypes; v++)
{
offsets[m, v] = numEntries[m, v - 1] + offsets[m, v - 1];
}

// Fill bounds
var bound = new SFiniteLightBound();
var lightData = new SFiniteLightData();
var lightShapeData = new LightShapeData();
lightData.lightModel = (uint)LightDefinitions.DIRECT_LIGHT;
lightShapeData.lightCategory = (uint)LightDefinitions.DIRECT_LIGHT;
lightShapeData.lightIndex = (uint)lightIndex;
if (punctualLightData.lightType == GPULightType.Spot || punctualLightData.lightType == GPULightType.ProjectorPyramid)
{

bound.scaleXY = squeeze ? new Vector2(0.01f, 0.01f) : new Vector2(1.0f, 1.0f);
lightData.lightAxisX = vx;
lightData.lightAxisY = vy;
lightData.lightAxisZ = vz;
lightData.lightType = (uint)LightDefinitions.SPOT_LIGHT;
lightData.lightPos = worldToView.MultiplyPoint(lightPos);
lightData.radiusSq = range * range;
lightData.cotan = cota;
lightShapeData.lightAxisX = vx;
lightShapeData.lightAxisY = vy;
lightShapeData.lightAxisZ = vz;
lightShapeData.lightType = (uint)LightDefinitions.SPOT_LIGHT;
lightShapeData.lightPos = worldToView.MultiplyPoint(lightPos);
lightShapeData.radiusSq = range * range;
lightShapeData.cotan = cota;
int i = LightDefinitions.DIRECT_LIGHT, j = LightDefinitions.SPOT_LIGHT;
index = numEntries2nd[i, j] + offsets[i, j]; ++numEntries2nd[i, j];

Vector3 vz = lightToView.GetColumn(2);
// fill up ldata
lightData.lightAxisX = vx;
lightData.lightAxisY = vy;
lightData.lightAxisZ = vz;
lightData.lightType = (uint)LightDefinitions.SPHERE_LIGHT;
lightData.lightPos = bound.center;
lightData.radiusSq = range * range;
lightShapeData.lightAxisX = vx;
lightShapeData.lightAxisY = vy;
lightShapeData.lightAxisZ = vz;
lightShapeData.lightType = (uint)LightDefinitions.SPHERE_LIGHT;
lightShapeData.lightPos = bound.center;
lightShapeData.radiusSq = range * range;
int i = LightDefinitions.DIRECT_LIGHT, j = LightDefinitions.SPHERE_LIGHT;
index = numEntries2nd[i, j] + offsets[i, j]; ++numEntries2nd[i, j];

m_lightData[index] = lightData;
m_lightShapeData[index] = lightShapeData;
}
for (int envIndex = 0; envIndex < lightList.envLights.Count; envIndex++)

var bound = new SFiniteLightBound();
var lightData = new SFiniteLightData();
var bound = new SFiniteLightBound();
var bnds = probe.bounds;
var boxOffset = probe.center; // reflection volume offset relative to cube map capture point

bound.scaleXY.Set(1.0f, 1.0f);
bound.radius = combinedExtent.magnitude;
lightData.lightPos = Cw;
lightData.lightAxisX = vx;
lightData.lightAxisY = vy;
lightData.lightAxisZ = vz;
var delta = combinedExtent - e;
lightData.boxInnerDist = e;
lightData.boxInvRange.Set(1.0f / delta.x, 1.0f / delta.y, 1.0f / delta.z);
var lightShapeData = new LightShapeData();
lightShapeData.lightType = (uint)LightDefinitions.BOX_LIGHT;
lightShapeData.lightCategory = (uint)LightDefinitions.REFLECTION_LIGHT;
lightShapeData.lightIndex = (uint)envIndex;
lightData.lightType = (uint)LightDefinitions.BOX_LIGHT;
lightData.lightModel = (uint)LightDefinitions.REFLECTION_LIGHT;
lightShapeData.lightPos = Cw;
lightShapeData.lightAxisX = vx;
lightShapeData.lightAxisY = vy;
lightShapeData.lightAxisZ = vz;
var delta = combinedExtent - e;
lightShapeData.boxInnerDist = e;
lightShapeData.boxInvRange.Set(1.0f / delta.x, 1.0f / delta.y, 1.0f / delta.z);
m_lightData[index] = lightData;
m_lightShapeData[index] = lightShapeData;
}
// Sanity check

m_lightCount = lightList.punctualLights.Count + lightList.envLights.Count;
s_ConvexBoundsBuffer.SetData(m_boundData); // TODO: check with Vlad what is happening here, do we copy 1024 element always ? Could we setup the size we want to copy ?
s_LightDataBuffer.SetData(m_lightData);
s_LightShapeDataBuffer.SetData(m_lightShapeData);
}
void VoxelLightListGeneration(CommandBuffer cmd, Camera camera, Matrix4x4 projscr, Matrix4x4 invProjscr, RenderTargetIdentifier cameraDepthBufferRT)

{
cmd.SetComputeIntParams(buildPerTileLightListShader, "g_viDimensions", new int[2] { w, h });
cmd.SetComputeIntParam(buildPerTileLightListShader, "g_iNrVisibLights", m_lightCount);
cmd.SetComputeIntParam(buildPerTileLightListShader, "_PunctualLightCount", lightList.punctualLights.Count);
Utilities.SetMatrixCS(cmd, buildPerTileLightListShader, "g_mScrProjection", projscr);
Utilities.SetMatrixCS(cmd, buildPerTileLightListShader, "g_mInvScrProjection", invProjscr);
cmd.SetComputeTextureParam(buildPerTileLightListShader, s_GenListPerTileKernel, "g_depth_tex", cameraDepthBufferRT);

cmd.SetComputeTextureParam(deferredComputeShader, kernel, "_LightTextureB0", m_LightAttentuationTexture);
cmd.SetComputeBufferParam(deferredComputeShader, kernel, "g_vLightListGlobal", bUseClusteredForDeferred ? s_PerVoxelLightLists : s_LightList);
cmd.SetComputeBufferParam(deferredComputeShader, kernel, "g_vLightData", s_LightDataBuffer);
cmd.SetComputeBufferParam(deferredComputeShader, kernel, "_LightShapeData", s_LightShapeDataBuffer);
cmd.SetComputeBufferParam(deferredComputeShader, kernel, "g_dirLightData", s_DirLightList);
var defdecode = ReflectionProbe.GetDefaultTextureHDRDecodeValues();

37
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.cs.hlsl


float radius;
};
// Generated from UnityEngine.Experimental.ScriptableRenderLoop.TilePass.SFiniteLightData
// Generated from UnityEngine.Experimental.ScriptableRenderLoop.TilePass.LightShapeData
struct SFiniteLightData
struct LightShapeData
uint lightIndex;
float3 lightAxisX;
uint lightType;
float3 lightAxisY;

float3 boxInnerDist;
uint lightModel;
uint lightCategory;
float3 boxInvRange;
float unused2;
};

}
//
// Accessors for UnityEngine.Experimental.ScriptableRenderLoop.TilePass.SFiniteLightData
// Accessors for UnityEngine.Experimental.ScriptableRenderLoop.TilePass.LightShapeData
float3 GetLightPos(SFiniteLightData value)
float3 GetLightPos(LightShapeData value)
float3 GetLightAxisX(SFiniteLightData value)
uint GetLightIndex(LightShapeData value)
{
return value.lightIndex;
}
float3 GetLightAxisX(LightShapeData value)
uint GetLightType(SFiniteLightData value)
uint GetLightType(LightShapeData value)
float3 GetLightAxisY(SFiniteLightData value)
float3 GetLightAxisY(LightShapeData value)
float GetRadiusSq(SFiniteLightData value)
float GetRadiusSq(LightShapeData value)
float3 GetLightAxisZ(SFiniteLightData value)
float3 GetLightAxisZ(LightShapeData value)
float GetCotan(SFiniteLightData value)
float GetCotan(LightShapeData value)
float3 GetBoxInnerDist(SFiniteLightData value)
float3 GetBoxInnerDist(LightShapeData value)
uint GetLightModel(SFiniteLightData value)
uint GetLightCategory(LightShapeData value)
return value.lightModel;
return value.lightCategory;
float3 GetBoxInvRange(SFiniteLightData value)
float3 GetBoxInvRange(LightShapeData value)
float GetUnused2(SFiniteLightData value)
float GetUnused2(LightShapeData value)
{
return value.unused2;
}

正在加载...
取消
保存