浏览代码

Merge pull request #484 from Unity-Technologies/Recreate-light-list-PR

Recreate light list pr
/main
GitHub 7 年前
当前提交
59c35fd3
共有 5 个文件被更改,包括 68 次插入28 次删除
  1. 27
      SampleScenes/FPTL/FPTL.unity
  2. 20
      SampleScenes/FPTL/Materials/FwdMat.mat
  3. 2
      TestbedPipelines/Fptl/FPTLRenderPipeline.asset
  4. 39
      TestbedPipelines/Fptl/FptlLighting.cs
  5. 8
      TestbedPipelines/Fptl/RegularForwardLightingUtils.hlsl

27
SampleScenes/FPTL/FPTL.unity


m_EnableBakedLightmaps: 0
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 9
serializedVersion: 10
m_TextureWidth: 1024
m_TextureHeight: 1024
m_AtlasSize: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 0

m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_RenderingLayerMask: 4294967295
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_RenderingLayerMask: 4294967295
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_RenderingLayerMask: 4294967295
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_RenderingLayerMask: 4294967295
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_RenderingLayerMask: 4294967295
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_RenderingLayerMask: 4294967295
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_RenderingLayerMask: 4294967295
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_RenderingLayerMask: 4294967295
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1713034008}
m_Enabled: 1
m_ExtensionPropertyValues: []
--- !u!124 &1713034010
Behaviour:
m_ObjectHideFlags: 0

m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
m_StereoMirrorMode: 0
--- !u!4 &1713034013
Transform:
m_ObjectHideFlags: 0

m_Script: {fileID: 11500000, guid: 92bb16b4ee20841929b24d6bd771738d, type: 3}
m_Name:
m_EditorClassIdentifier:
m_RenderLoop: {fileID: 11400000, guid: 4dc14083116279a438e1b2de3830999f, type: 2}
--- !u!114 &1713034015
MonoBehaviour:
m_ObjectHideFlags: 0

m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_RenderingLayerMask: 4294967295
- {fileID: 2100000, guid: cb6536d04ba24874981eb01dfd87479e, type: 2}
- {fileID: 2100000, guid: 24e6a15bf9d2c0944b380d860a738528, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0

m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_RenderingLayerMask: 4294967295
- {fileID: 2100000, guid: cb6536d04ba24874981eb01dfd87479e, type: 2}
- {fileID: 2100000, guid: 24e6a15bf9d2c0944b380d860a738528, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0

m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_RenderingLayerMask: 4294967295
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_RenderingLayerMask: 4294967295
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_RenderingLayerMask: 4294967295
- {fileID: 2100000, guid: cb6536d04ba24874981eb01dfd87479e, type: 2}
- {fileID: 2100000, guid: 24e6a15bf9d2c0944b380d860a738528, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0

20
SampleScenes/FPTL/Materials/FwdMat.mat


m_PrefabInternal: {fileID: 0}
m_Name: FwdMat
m_Shader: {fileID: 4800000, guid: 8f28d6dbfdba66d4dbae80224aca5669, type: 3}
m_ShaderKeywords: _EMISSION
m_ShaderKeywords: _ALPHAPREMULTIPLY_ON _EMISSION
m_CustomRenderQueue: -1
stringTagMap: {}
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3

- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _DstBlend: 10
- _Glossiness: 0.5
- _Glossiness: 0.806
- _Metallic: 0
- _Mode: 0
- _Metallic: 0.891
- _Mode: 3
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0

- _ZWrite: 1
- _ZWrite: 0
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 0.559}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}

2
TestbedPipelines/Fptl/FPTLRenderPipeline.asset


type: 3}
buildPerVoxelLightListShader: {fileID: 7200000, guid: 4c2d6eb0553e2514bba3ea9a85d8c53c,
type: 3}
enableClustered: 0
enableClustered: 1
disableFptlWhenClustered: 0
enableBigTilePrepass: 1
enableDrawLightBoundsDebug: 0

39
TestbedPipelines/Fptl/FptlLighting.cs


private static ComputeBuffer s_AABBBoundsBuffer;
private static ComputeBuffer s_LightList;
private static ComputeBuffer s_DirLightList;
private static ComputeBuffer s_LightIndices;
private static ComputeBuffer s_BigTileLightList; // used for pre-pass coarse culling on 64x64 tiles
private static int s_GenListPerBigTileKernel;

s_AABBBoundsBuffer.Release();
s_ConvexBoundsBuffer.Release();
s_LightDataBuffer.Release();
s_LightIndices.Release();
ReleaseResolutionDependentBuffers();
s_DirLightList.Release();

if (s_LightDataBuffer != null)
s_LightDataBuffer.Release();
if (s_LightIndices != null)
s_LightIndices.Release();
ReleaseResolutionDependentBuffers();

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_DirLightList = new ComputeBuffer(MaxNumDirLights, System.Runtime.InteropServices.Marshal.SizeOf(typeof(DirectionalLight)));
s_LightIndices = null; // only used in traditional forward, will be created on demand
buildScreenAABBShader.SetBuffer(s_GenAABBKernel, "g_data", s_ConvexBoundsBuffer);
//m_BuildScreenAABBShader.SetBuffer(kGenAABBKernel, "g_vBoundsBuffer", m_aabbBoundsBuffer);

{
sorting = { flags = SortFlags.CommonOpaque },
//@TODO: need to get light probes + LPPV too?
rendererConfiguration = RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbe
rendererConfiguration = RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbe | RendererConfiguration.ProvideLightIndices | RendererConfiguration.ProvideReflectionProbeIndices
};
var filterSettings = new FilterRenderersSettings(true){renderQueueRange = RenderQueueRange.opaque};
loop.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings);

bool haveTiledSolution = opaquesOnly || enableClustered;
cmd.EnableShaderKeyword(haveTiledSolution ? "TILED_FORWARD" : "REGULAR_FORWARD");
cmd.SetViewProjectionMatrices(camera.worldToCameraMatrix, camera.projectionMatrix);
cmd.SetGlobalBuffer("g_vLightListMeshInst", s_LightIndices);
loop.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);

var drawSettings = new DrawRendererSettings(camera, new ShaderPassName("ForwardSinglePass"))
{
sorting = { flags = SortFlags.CommonOpaque },
rendererConfiguration = RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbe
sorting = { flags = opaquesOnly ? SortFlags.CommonOpaque : SortFlags.CommonTransparent },
rendererConfiguration = RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbe | RendererConfiguration.ProvideLightIndices | RendererConfiguration.ProvideReflectionProbeIndices
};
var filterSettings = new FilterRenderersSettings(true) { renderQueueRange = opaquesOnly ? RenderQueueRange.opaque : RenderQueueRange.transparent };

var boundData = new SFiniteLightBound[numVolumes];
var worldToView = WorldToCamera(camera);
var lightIndexMap = inputs.GetLightIndexMap();
for (int i = 0; i < lightIndexMap.Length; i++)
{
lightIndexMap[i] = -1;
}
int lightIndexCount = inputs.GetLightIndicesCount();
if (s_LightIndices == null || lightIndexCount > s_LightIndices.count)
{
// The light indices buffer is too small, resize
if (s_LightIndices != null)
s_LightIndices.Release();
s_LightIndices = new ComputeBuffer(lightIndexCount, System.Runtime.InteropServices.Marshal.SizeOf(typeof(int)));
}
uint lightIndex = 0;
foreach (var cl in inputs.visibleLights)
{
var range = cl.range;

{
boundData[idxOut] = bound;
lightData[idxOut] = light;
lightIndexMap[lightIndex] = idxOut;
lightIndex++;
}
int numLightsOut = 0;
for(int v=0; v<numVolTypes; v++) numLightsOut += numEntries[LightDefinitions.DIRECT_LIGHT, v];

idxOut = numEntries2nd[i, j] + offsets[i, j]; ++numEntries2nd[i, j];
boundData[idxOut] = bndData;
lightData[idxOut] = lgtData;
lightIndexMap[lightIndex] = idxOut;
lightIndex++;
inputs.SetLightIndexMap(lightIndexMap);
int numProbesOut = 0;
for(int v=0; v<numVolTypes; v++) numProbesOut += numEntries[LightDefinitions.REFLECTION_LIGHT, v];

s_ConvexBoundsBuffer.SetData(boundData);
s_LightDataBuffer.SetData(lightData);
inputs.FillLightIndices(s_LightIndices);
return numLightsOut + numProbesOut;
}

{
VoxelLightListGeneration(cmd, camera, numLights, projscr, invProjscr);
}
}
void PushGlobalParams(Camera camera, ScriptableRenderContext loop, Matrix4x4 viewToWorld, Matrix4x4 scrProj, Matrix4x4 incScrProj, int numDirLights)

8
TestbedPipelines/Fptl/RegularForwardLightingUtils.hlsl


StructuredBuffer<SFiniteLightData> g_vLightData;
StructuredBuffer<uint> g_vLightListMeshInst; // build on CPU if in use. direct lights first, then reflection probes. (don't support Buffer yet in unity, so using structured)
uniform int g_numLights;
uniform int g_numReflectionProbes;
uniform uint4 unity_LightIndicesOffsetAndCount;
uniform uint4 unity_ReflectionProbeIndicesOffsetAndCount;
start = model==REFLECTION_LIGHT ? g_numLights : 0; // offset by numLights entries
nrLights = model==REFLECTION_LIGHT ? g_numReflectionProbes : g_numLights;
start = model==REFLECTION_LIGHT ? unity_ReflectionProbeIndicesOffsetAndCount.x : unity_LightIndicesOffsetAndCount.x;
nrLights = model==REFLECTION_LIGHT ? unity_ReflectionProbeIndicesOffsetAndCount.y : unity_LightIndicesOffsetAndCount.y;
}
uint FetchIndex(const uint start, const uint l)

正在加载...
取消
保存