浏览代码

Merge remote-tracking branch 'refs/remotes/origin/master' into Refactor-lightloop

/main
sebastienlagarde 8 年前
当前提交
d0ebdb4a
共有 8 个文件被更改,包括 221 次插入147 次删除
  1. 103
      Assets/ScriptableRenderLoop/HDRenderLoop/Debug/Resources/DebugViewTiles.shader
  2. 4
      Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs
  3. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/Resources/lightlistbuild-bigtile.compute
  4. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/Resources/lightlistbuild-clustered.compute
  5. 26
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/Resources/lightlistbuild.compute
  6. 171
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.cs
  7. 29
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.cs.hlsl
  8. 21
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePassLoop.hlsl

103
Assets/ScriptableRenderLoop/HDRenderLoop/Debug/Resources/DebugViewTiles.shader


Shader "Hidden/HDRenderLoop/DebugViewTiles"
{
SubShader
{
SubShader
{
Pass
{
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
HLSLPROGRAM
HLSLPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev

#pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST
//-------------------------------------------------------------------------------------
// Include
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
// Include
//-------------------------------------------------------------------------------------
// Note: We have fix as guidelines that we have only one deferred material (with control of GBuffer enabled). Mean a users that add a new
// deferred material must replace the old one here. If in the future we want to support multiple layout (cause a lot of consistency problem),
// the deferred shader will require to use multicompile.
// Note: We have fix as guidelines that we have only one deferred material (with control of GBuffer enabled). Mean a users that add a new
// deferred material must replace the old one here. If in the future we want to support multiple layout (cause a lot of consistency problem),
// the deferred shader will require to use multicompile.
//-------------------------------------------------------------------------------------
// variable declaration
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
// variable declaration
//-------------------------------------------------------------------------------------
uint _ViewTilesFlags;
uint _ViewTilesFlags;
TEXTURE2D(_CameraDepthTexture);
SAMPLER2D(sampler_CameraDepthTexture);

float4 Vert(float3 positionOS : POSITION): SV_POSITION
{
return TransformWorldToHClip(TransformObjectToWorld(positionOS));
}
float4 Vert(float3 positionOS : POSITION): SV_POSITION
{
return TransformWorldToHClip(TransformObjectToWorld(positionOS));
}
float4 OverlayHeatMap(uint2 pixCoord, uint numLights)
{

return color;
}
float4 Frag(float4 positionCS : SV_POSITION) : SV_Target
{
Coordinate coord = GetCoordinate(positionCS.xy, _ScreenSize.zw);
float4 Frag(float4 positionCS : SV_POSITION) : SV_Target
{
Coordinate coord = GetCoordinate(positionCS.xy, _ScreenSize.zw);
#ifdef USE_CLUSTERED_LIGHTLIST
// Perform same calculation than in deferred.shader

float linearDepth = 0.0; // unused
#endif
int n = 0;
if (_ViewTilesFlags & DEBUGVIEWTILESFLAGS_DIRECT_LIGHTING)
{
uint punctualLightStart;
uint punctualLightCount;
GetCountAndStart(coord, DIRECT_LIGHT, linearDepth, punctualLightStart, punctualLightCount);
n += punctualLightCount;
}
int n = 0;
for(int category = 0; category < NR_LIGHT_CATEGORIES; category++)
{
uint mask = 1u << category;
uint start;
uint count;
GetCountAndStart(coord, category, linearDepth, start, count);
n += count;
}
if (n > 0)
{
return OverlayHeatMap(int2(coord.unPositionSS.xy) & 15, n);
}
else
{
return 0.0;
}
}
if (_ViewTilesFlags & DEBUGVIEWTILESFLAGS_REFLECTION)
{
uint envLightStart;
uint envLightCount;
GetCountAndStart(coord, REFLECTION_LIGHT, linearDepth, envLightStart, envLightCount);
n += envLightCount;
}
if (n > 0)
{
return OverlayHeatMap(int2(coord.unPositionSS.xy) & 15, n);
}
else
{
return 0.0;
}
}
ENDHLSL
}
}
Fallback Off
}
ENDHLSL
}
}
Fallback Off
}

4
Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs


public readonly GUIContent shadowsCascades = new GUIContent("Cascade values");
public readonly GUIContent tileLightLoopSettings = new GUIContent("Tile Light Loop settings");
public readonly GUIContent tileLightLoopDebugMode = new GUIContent("Enable Debug mode", "Toggle overheat map mode");
public readonly string[] tileLightLoopDebugTileFlagStrings = new string[] { "Direct Light", "Reflection Light", "Area Light"};
public readonly GUIContent directIndirectSinglePass = new GUIContent("Enable direct and indirect lighting in single pass", "Toggle");
public readonly GUIContent bigTilePrepass = new GUIContent("Enable big tile prepass", "Toggle");
public readonly GUIContent clustered = new GUIContent("Enable clustered", "Toggle");

EditorGUI.indentLevel++;
EditorGUI.BeginChangeCheck();
renderLoop.tilePassLightLoop.debugViewTilesFlags = (TilePass.DebugViewTilesFlags)EditorGUILayout.EnumMaskField("DebugView Tiles", renderLoop.tilePassLightLoop.debugViewTilesFlags);
renderLoop.tilePassLightLoop.debugViewTilesFlags = EditorGUILayout.MaskField("DebugView Tiles", renderLoop.tilePassLightLoop.debugViewTilesFlags, styles.tileLightLoopDebugTileFlagStrings);
renderLoop.tilePassLightLoop.enableDirectIndirectSinglePass = EditorGUILayout.Toggle(styles.directIndirectSinglePass, renderLoop.tilePassLightLoop.enableDirectIndirectSinglePass);
renderLoop.tilePassLightLoop.enableBigTilePrepass = EditorGUILayout.Toggle(styles.bigTilePrepass, renderLoop.tilePassLightLoop.enableBigTilePrepass);
renderLoop.tilePassLightLoop.enableClustered = EditorGUILayout.Toggle(styles.clustered, renderLoop.tilePassLightLoop.enableClustered);

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


for(int l=0; l<iNrCoarseLights; l++)
{
const uint idxCoarse = lightsListLDS[l];
[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.
[branch]if (idxCoarse<(uint)g_iNrVisibLights && _LightShapeData[idxCoarse].lightVolume != SPHERE_VOLUME) // don't bother doing edge tests for sphere lights since these have camera aligned bboxes.
{
SFiniteLightBound lgtDat = g_data[idxCoarse];

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


InterlockedAdd(g_LayeredSingleIdxBuffer[0], (uint) iSpaceAvail, start); // alloc list memory
}
int modelListCount[NR_LIGHT_MODELS]={0,0}; // direct light count and reflection lights
int categoryListCount[NR_LIGHT_CATEGORIES]={0,0,0}; // direct light count and reflection lights
uint offs = start;
for(int ll=0; ll<iNrCoarseLights; ll+=4)
{

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

uint localOffs=0;
offs = i*nrTilesX*nrTilesY + tileIDX.y*nrTilesX + tileIDX.x;
for(int m=0; m<NR_LIGHT_MODELS; m++)
for(int category=0; category<NR_LIGHT_CATEGORIES; category++)
int numLights = min(modelListCount[m],31); // only allow 5 bits
int numLights = min(categoryListCount[category],31); // only allow 5 bits
localOffs += modelListCount[m]; // use unclamped count for localOffs
localOffs += categoryListCount[category]; // use unclamped count for localOffs
}
}

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

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


#endif
groupshared int ldsNrLightsFinal;
groupshared int ldsModelListCount[NR_LIGHT_MODELS]; // since NR_LIGHT_MODELS is 2
groupshared int ldsCategoryListCount[NR_LIGHT_CATEGORIES]; // since NR_LIGHT_CATEGORIES is 3
#ifdef PERFORM_SPHERICAL_INTERSECTION_TESTS
groupshared uint lightOffsSph;

#endif
//
if(t<NR_LIGHT_MODELS) ldsModelListCount[t]=0;
if(t<NR_LIGHT_CATEGORIES) ldsCategoryListCount[t]=0;
#if !defined(SHADER_API_XBOXONE) && !defined(SHADER_API_PSSL)
GroupMemoryBarrierWithGroupSync();

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

int localOffs=0;
int offs = tileIDX.y*nrTilesX + tileIDX.x;
for(int m=0; m<NR_LIGHT_MODELS; m++)
for(int category=0; category<NR_LIGHT_CATEGORIES; category++)
int nrLightsFinal = ldsModelListCount[ m ];
int nrLightsFinal = ldsCategoryListCount[category];
int nrLightsFinalClamped = nrLightsFinal<MAX_NR_PRUNED_ENTRIES ? nrLightsFinal : MAX_NR_PRUNED_ENTRIES;

{
// fetch light
int idxCoarse = l<iNrCoarseLights ? coarseList[l] : 0;
uint uLgtType = l<iNrCoarseLights ? _LightShapeData[idxCoarse].lightType : 0;
uint uLightVolume = l<iNrCoarseLights ? _LightShapeData[idxCoarse].lightVolume : 0;
while(l<iNrCoarseLights && uLgtType==SPOT_LIGHT)
while(l<iNrCoarseLights && uLightVolume==SPOT_VOLUME)
{
LightShapeData lightData = _LightShapeData[idxCoarse];
// TODO: Change by SebL

uLightsFlags[l<32 ? 0 : 1] |= (uVal<<(l&31));
++l; idxCoarse = l<iNrCoarseLights ? coarseList[l] : 0;
uLgtType = l<iNrCoarseLights ? _LightShapeData[idxCoarse].lightType : 0;
uLightVolume = l<iNrCoarseLights ? _LightShapeData[idxCoarse].lightVolume : 0;
while(l<iNrCoarseLights && uLgtType==SPHERE_LIGHT)
while(l<iNrCoarseLights && uLightVolume==SPHERE_VOLUME)
{
LightShapeData lightData = _LightShapeData[idxCoarse];

uLightsFlags[l<32 ? 0 : 1] |= (uVal<<(l&31));
++l; idxCoarse = l<iNrCoarseLights ? coarseList[l] : 0;
uLgtType = l<iNrCoarseLights ? _LightShapeData[idxCoarse].lightType : 0;
uLightVolume = l<iNrCoarseLights ? _LightShapeData[idxCoarse].lightVolume : 0;
while(l<iNrCoarseLights && uLgtType==BOX_LIGHT)
while(l<iNrCoarseLights && uLightVolume==BOX_VOLUME)
{
LightShapeData lightData = _LightShapeData[idxCoarse];

uLightsFlags[l<32 ? 0 : 1] |= (uVal<<(l&31));
++l; idxCoarse = l<iNrCoarseLights ? coarseList[l] : 0;
uLgtType = l<iNrCoarseLights ? _LightShapeData[idxCoarse].lightType : 0;
uLightVolume = l<iNrCoarseLights ? _LightShapeData[idxCoarse].lightVolume : 0;
if(uLgtType>=MAX_TYPES) ++l;
if(uLightVolume >=MAX_VOLUME_TYPES) ++l;
}
InterlockedOr(ldsDoesLightIntersect[0], uLightsFlags[0]);

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


// types
public static int MAX_TYPES = 3;
public static int MAX_VOLUME_TYPES = 3;
public static int SPOT_LIGHT = 0;
public static int SPHERE_LIGHT = 1;
public static int BOX_LIGHT = 2;
public static int DIRECTIONAL_LIGHT = 3;
public static int SPOT_VOLUME = 0;
public static int SPHERE_VOLUME = 1;
public static int BOX_VOLUME = 2;
public static int DIRECTIONAL_VOLUME = 3;
public static int NR_LIGHT_MODELS = 2;
public static int DIRECT_LIGHT = 0;
public static int REFLECTION_LIGHT = 1;
public static int NR_LIGHT_CATEGORIES = 3;
public static int DIRECT_LIGHT_CATEGORY = 0;
public static int REFLECTION_LIGHT_CATEGORY = 1;
public static int AREA_LIGHT_CATEGORY = 2;
public enum DebugViewTilesFlags
{
DirectLighting = 1,
Reflection = 2
};
[GenerateHLSL]
public struct SFiniteLightBound
{
public Vector3 boxAxisX;

public uint lightIndex; // Index in light tabs like LightData / EnvLightData
public Vector3 lightAxisX;
public uint lightType;
public uint lightVolume;
public Vector3 lightAxisY;
public float radiusSq;

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

private static int s_GenListPerBigTileKernel;
// clustered light list specific buffers and data begin
public DebugViewTilesFlags debugViewTilesFlags = 0;
public int debugViewTilesFlags = 0;
public bool enableClustered = false;
public bool disableFptlWhenClustered = true; // still useful on opaques. Should be false by default to force tile on opaque.
public bool enableBigTilePrepass = true;

const int capacityUShortsPerTile = 32;
const int dwordsPerTile = (capacityUShortsPerTile + 1) >> 1; // room for 31 lights and a nrLights value.
s_LightList = new ComputeBuffer(LightDefinitions.NR_LIGHT_MODELS * dwordsPerTile * nrTiles, sizeof(uint)); // enough list memory for a 4k x 4k display
s_LightList = new ComputeBuffer(LightDefinitions.NR_LIGHT_CATEGORIES * dwordsPerTile * nrTiles, sizeof(uint)); // enough list memory for a 4k x 4k display
s_PerVoxelOffset = new ComputeBuffer(LightDefinitions.NR_LIGHT_MODELS * (1 << k_Log2NumClusters) * nrTiles, sizeof(uint));
s_PerVoxelOffset = new ComputeBuffer(LightDefinitions.NR_LIGHT_CATEGORIES * (1 << k_Log2NumClusters) * nrTiles, sizeof(uint));
s_PerVoxelLightLists = new ComputeBuffer(NumLightIndicesPerClusteredTile() * nrTiles, sizeof(uint));
if (k_UseDepthBuffer)

public void PrepareLightsForGPU(CullResults cullResults, Camera camera, HDRenderLoop.LightList lightList)
{
var numModels = (int)LightDefinitions.NR_LIGHT_MODELS;
var numVolTypes = (int)LightDefinitions.MAX_TYPES;
var numCategories = (int)LightDefinitions.NR_LIGHT_CATEGORIES;
var numVolTypes = (int)LightDefinitions.MAX_VOLUME_TYPES;
var numEntries = new int[numModels, numVolTypes];
var offsets = new int[numModels, numVolTypes];
var numEntries = new int[numCategories, numVolTypes];
var offsets = new int[numCategories, numVolTypes];
var numEntries2nd = new int[numModels, numVolTypes];
var numEntries2nd = new int[numCategories, numVolTypes];
// TODO manage area lights
var volType = punctualLight.lightType == GPULightType.Spot ? LightDefinitions.SPOT_LIGHT : (punctualLight.lightType == GPULightType.Point ? LightDefinitions.SPHERE_LIGHT : -1);
var volType = punctualLight.lightType == GPULightType.Spot ? LightDefinitions.SPOT_VOLUME : (punctualLight.lightType == GPULightType.Point ? LightDefinitions.SPHERE_VOLUME : -1);
++numEntries[LightDefinitions.DIRECT_LIGHT, volType];
++numEntries[LightDefinitions.DIRECT_LIGHT_CATEGORY, volType];
var volType = LightDefinitions.BOX_LIGHT; // always a box for now
++numEntries[LightDefinitions.REFLECTION_LIGHT, volType];
var volType = LightDefinitions.BOX_VOLUME; // always a box for now
++numEntries[LightDefinitions.REFLECTION_LIGHT_CATEGORY, volType];
foreach (var areaLight in lightList.areaLights)
{
var volType = LightDefinitions.BOX_VOLUME;
++numEntries[LightDefinitions.AREA_LIGHT_CATEGORY, volType];
}
for (int m = 0; m < numModels; m++)
for (int category = 0; category < numCategories; category++)
offsets[m, 0] = m == 0 ? 0 : (numEntries[m - 1, numVolTypes - 1] + offsets[m - 1, numVolTypes - 1]);
offsets[category, 0] = category == 0 ? 0 : (numEntries[category - 1, numVolTypes - 1] + offsets[category - 1, numVolTypes - 1]);
offsets[m, v] = numEntries[m, v - 1] + offsets[m, v - 1];
offsets[category, v] = numEntries[category, v - 1] + offsets[category, v - 1];
}
}

var lightShapeData = new LightShapeData();
int index = -1;
lightShapeData.lightCategory = (uint)LightDefinitions.DIRECT_LIGHT;
lightShapeData.lightCategory = (uint)LightDefinitions.DIRECT_LIGHT_CATEGORY;
lightShapeData.lightIndex = (uint)lightIndex;
if (punctualLightData.lightType == GPULightType.Spot || punctualLightData.lightType == GPULightType.ProjectorPyramid)

lightShapeData.lightAxisX = vx;
lightShapeData.lightAxisY = vy;
lightShapeData.lightAxisZ = vz;
lightShapeData.lightType = (uint)LightDefinitions.SPOT_LIGHT;
lightShapeData.lightVolume = (uint)LightDefinitions.SPOT_VOLUME;
int i = LightDefinitions.DIRECT_LIGHT, j = LightDefinitions.SPOT_LIGHT;
int i = LightDefinitions.DIRECT_LIGHT_CATEGORY, j = LightDefinitions.SPOT_VOLUME;
index = numEntries2nd[i, j] + offsets[i, j]; ++numEntries2nd[i, j];
}
else // if (punctualLightData.lightType == GPULightType.Point)

lightShapeData.lightAxisX = vx;
lightShapeData.lightAxisY = vy;
lightShapeData.lightAxisZ = vz;
lightShapeData.lightType = (uint)LightDefinitions.SPHERE_LIGHT;
lightShapeData.lightVolume = (uint)LightDefinitions.SPHERE_VOLUME;
int i = LightDefinitions.DIRECT_LIGHT, j = LightDefinitions.SPHERE_LIGHT;
int i = LightDefinitions.DIRECT_LIGHT_CATEGORY, j = LightDefinitions.SPHERE_VOLUME;
index = numEntries2nd[i, j] + offsets[i, j]; ++numEntries2nd[i, j];
}

//Vector3 C = bnds.center; // P + boxOffset;
var C = mat.MultiplyPoint(boxOffset); // same as commented out line above when rot is identity
var combinedExtent = e + new Vector3(blendDistance, blendDistance, blendDistance);
var combinedExtent = e + new Vector3(blendDistance, blendDistance, blendDistance);
Vector3 vx = mat.GetColumn(0);
Vector3 vy = mat.GetColumn(1);

bound.radius = combinedExtent.magnitude;
var lightShapeData = new LightShapeData();
lightShapeData.lightType = (uint)LightDefinitions.BOX_LIGHT;
lightShapeData.lightCategory = (uint)LightDefinitions.REFLECTION_LIGHT;
lightShapeData.lightVolume = (uint)LightDefinitions.BOX_VOLUME;
lightShapeData.lightCategory = (uint)LightDefinitions.REFLECTION_LIGHT_CATEGORY;
lightShapeData.lightIndex = (uint)envIndex;
lightShapeData.lightPos = Cw;

lightShapeData.boxInnerDist = e;
lightShapeData.boxInvRange.Set(1.0f / delta.x, 1.0f / delta.y, 1.0f / delta.z);
int i = LightDefinitions.REFLECTION_LIGHT, j = LightDefinitions.BOX_LIGHT;
int i = LightDefinitions.REFLECTION_LIGHT_CATEGORY, j = LightDefinitions.BOX_VOLUME;
int index = numEntries2nd[i, j] + offsets[i, j]; ++numEntries2nd[i, j];
m_boundData[index] = bound;
m_lightShapeData[index] = lightShapeData;
}
for (int areaLightIndex = 0; areaLightIndex < lightList.areaLights.Count; areaLightIndex++)
{
LightData areaLightData = lightList.areaLights[areaLightIndex];
// Fill bounds
var bound = new SFiniteLightBound();
var lightShapeData = new LightShapeData();
lightShapeData.lightVolume = (uint)LightDefinitions.BOX_VOLUME;
lightShapeData.lightCategory = (uint)LightDefinitions.AREA_LIGHT_CATEGORY;
lightShapeData.lightIndex = (uint)areaLightIndex;
if (areaLightData.lightType == GPULightType.Rectangle)
{
Vector3 centerVS = worldToView.MultiplyPoint(areaLightData.positionWS);
Vector3 xAxisVS = worldToView.MultiplyVector(areaLightData.right);
Vector3 yAxisVS = worldToView.MultiplyVector(areaLightData.up);
Vector3 zAxisVS = worldToView.MultiplyVector(areaLightData.forward);
float radius = 1.0f / Mathf.Sqrt(areaLightData.invSqrAttenuationRadius);
Vector3 dimensions = new Vector3(areaLightData.size.x * 0.5f + radius, areaLightData.size.y * 0.5f + radius, radius);
if(!areaLightData.twoSided)
{
centerVS -= zAxisVS * radius * 0.5f;
dimensions.z *= 0.5f;
}
bound.center = centerVS;
bound.boxAxisX = dimensions.x * xAxisVS;
bound.boxAxisY = dimensions.y * yAxisVS;
bound.boxAxisZ = dimensions.z * zAxisVS;
bound.scaleXY.Set(1.0f, 1.0f);
bound.radius = dimensions.magnitude;
lightShapeData.lightPos = centerVS;
lightShapeData.lightAxisX = xAxisVS;
lightShapeData.lightAxisY = yAxisVS;
lightShapeData.lightAxisZ = zAxisVS;
lightShapeData.boxInnerDist = dimensions;
lightShapeData.boxInvRange.Set(1e5f, 1e5f, 1e5f);
}
else if (areaLightData.lightType == GPULightType.Line)
{
Vector3 centerVS = worldToView.MultiplyPoint(areaLightData.positionWS);
Vector3 xAxisVS = worldToView.MultiplyVector(areaLightData.right);
Vector3 yAxisVS = worldToView.MultiplyVector(areaLightData.up);
Vector3 zAxisVS = worldToView.MultiplyVector(areaLightData.forward);
float radius = 1.0f / Mathf.Sqrt(areaLightData.invSqrAttenuationRadius);
Vector3 dimensions = new Vector3(areaLightData.size.x * 0.5f + radius, radius, radius);
bound.center = centerVS;
bound.boxAxisX = dimensions.x * xAxisVS;
bound.boxAxisY = dimensions.y * yAxisVS;
bound.boxAxisZ = dimensions.z * zAxisVS;
bound.scaleXY.Set(1.0f, 1.0f);
bound.radius = dimensions.magnitude;
lightShapeData.lightPos = centerVS;
lightShapeData.lightAxisX = xAxisVS;
lightShapeData.lightAxisY = yAxisVS;
lightShapeData.lightAxisZ = zAxisVS;
lightShapeData.boxInnerDist = new Vector3(areaLightData.size.x * 0.5f, 0.01f, 0.01f);
lightShapeData.boxInvRange.Set(1.0f / radius, 1.0f / radius, 1.0f / radius);
}
else
{
Debug.Assert(false);
}
int i = LightDefinitions.AREA_LIGHT_CATEGORY, j = LightDefinitions.BOX_VOLUME;
for (var m = 0; m < numModels; m++)
for (var category = 0; category < numCategories; category++)
Debug.Assert(numEntries[m, v] == numEntries2nd[m, v], "count mismatch on second pass!");
Debug.Assert(numEntries[category, v] == numEntries2nd[category, v], "count mismatch on second pass!");
m_lightCount = lightList.punctualLights.Count + lightList.envLights.Count;
m_lightCount = lightList.punctualLights.Count + lightList.envLights.Count + lightList.areaLights.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_LightShapeDataBuffer.SetData(m_lightShapeData);
}

m_DebugViewTilesMaterial.SetMatrix("_InvViewProjMatrix", invViewProj);
m_DebugViewTilesMaterial.SetVector("_ScreenSize", screenSize);
m_DebugViewTilesMaterial.SetInt("_ViewTilesFlags", (int)debugViewTilesFlags);
m_DebugViewTilesMaterial.SetInt("_ViewTilesFlags", debugViewTilesFlags);
m_DebugViewTilesMaterial.EnableKeyword(bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
m_DebugViewTilesMaterial.DisableKeyword(!bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");

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


#define HAS_COOKIE_TEXTURE (2)
#define IS_BOX_PROJECTED (4)
#define HAS_SHADOW (8)
#define MAX_TYPES (3)
#define SPOT_LIGHT (0)
#define SPHERE_LIGHT (1)
#define BOX_LIGHT (2)
#define DIRECTIONAL_LIGHT (3)
#define NR_LIGHT_MODELS (2)
#define DIRECT_LIGHT (0)
#define REFLECTION_LIGHT (1)
//
// UnityEngine.Experimental.ScriptableRenderLoop.TilePass.DebugViewTilesFlags: static fields
//
#define DEBUGVIEWTILESFLAGS_DIRECT_LIGHTING (1)
#define DEBUGVIEWTILESFLAGS_REFLECTION (2)
#define MAX_VOLUME_TYPES (3)
#define SPOT_VOLUME (0)
#define SPHERE_VOLUME (1)
#define BOX_VOLUME (2)
#define DIRECTIONAL_VOLUME (3)
#define NR_LIGHT_CATEGORIES (3)
#define DIRECT_LIGHT_CATEGORY (0)
#define REFLECTION_LIGHT_CATEGORY (1)
#define AREA_LIGHT_CATEGORY (2)
// Generated from UnityEngine.Experimental.ScriptableRenderLoop.TilePass.SFiniteLightBound
// PackingRules = Exact

float3 lightPos;
uint lightIndex;
float3 lightAxisX;
uint lightType;
uint lightVolume;
float3 lightAxisY;
float radiusSq;
float3 lightAxisZ;

{
return value.lightAxisX;
}
uint GetLightType(LightShapeData value)
uint GetLightVolume(LightShapeData value)
return value.lightType;
return value.lightVolume;
}
float3 GetLightAxisY(LightShapeData value)
{

21
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePassLoop.hlsl


#ifdef PROCESS_PUNCTUAL_LIGHT
uint punctualLightStart;
uint punctualLightCount;
GetCountAndStart(coord, DIRECT_LIGHT, linearDepth, punctualLightStart, punctualLightCount);
GetCountAndStart(coord, DIRECT_LIGHT_CATEGORY, linearDepth, punctualLightStart, punctualLightCount);
for (i = 0; i < punctualLightCount; ++i)
{
float3 localDiffuseLighting, localSpecularLighting;

#endif
#ifdef PROCESS_AREA_LIGHT
/*
GetCountAndStart(coord, LightCatergory.AreaLight, linearDepth, areaLightStart, areaLightCount);
GetCountAndStart(coord, AREA_LIGHT_CATEGORY, linearDepth, areaLightStart, areaLightCount);
EvaluateBSDF_Area( context, V, positionWS, prelightData, _AreaLightList[FetchIndex(areaLightStart, i)], bsdfData,
localDiffuseLighting, localSpecularLighting);
if(_AreaLightList[i].lightType == GPULIGHTTYPE_LINE)
{
EvaluateBSDF_Line(context, V, positionWS, prelightData, _AreaLightList[FetchIndex(areaLightStart, i)], bsdfData,
localDiffuseLighting, localSpecularLighting);
}
else
{
EvaluateBSDF_Area(context, V, positionWS, prelightData, _AreaLightList[FetchIndex(areaLightStart, i)], bsdfData,
localDiffuseLighting, localSpecularLighting);
}
*/
GetCountAndStart(coord, REFLECTION_LIGHT, linearDepth, envLightStart, envLightCount);
GetCountAndStart(coord, REFLECTION_LIGHT_CATEGORY, linearDepth, envLightStart, envLightCount);
float3 iblDiffuseLighting = float3(0.0, 0.0, 0.0);
float3 iblSpecularLighting = float3(0.0, 0.0, 0.0);

正在加载...
取消
保存