public void SetupPerObjectLightIndices(ref CullResults cullResults, ref LightData lightData) { if (lightData.totalAdditionalLightsCount == 0) { return; } List <VisibleLight> visibleLights = lightData.visibleLights; int[] perObjectLightIndexMap = cullResults.GetLightIndexMap(); int directionalLightsCount = 0; int localLightsCount = 0; // Disable all directional lights from the perobject light indices // Pipeline handles them globally. for (int i = 0; i < visibleLights.Count && localLightsCount < maxVisibleLocalLights; ++i) { VisibleLight light = visibleLights[i]; if (light.lightType == LightType.Directional) { perObjectLightIndexMap[i] = -1; ++directionalLightsCount; } else { perObjectLightIndexMap[i] -= directionalLightsCount; ++localLightsCount; } } // Disable all remaining lights we cannot fit into the global light buffer. for (int i = directionalLightsCount + localLightsCount; i < perObjectLightIndexMap.Length; ++i) { perObjectLightIndexMap[i] = -1; } cullResults.SetLightIndexMap(perObjectLightIndexMap); // if not using a compute buffer, engine will set indices in 2 vec4 constants // unity_4LightIndices0 and unity_4LightIndices1 if (useComputeBufferForPerObjectLightIndices) { int lightIndicesCount = cullResults.GetLightIndicesCount(); if (lightIndicesCount > 0) { if (perObjectLightIndices == null) { perObjectLightIndices = new ComputeBuffer(lightIndicesCount, sizeof(int)); } else if (perObjectLightIndices.count < lightIndicesCount) { perObjectLightIndices.Release(); perObjectLightIndices = new ComputeBuffer(lightIndicesCount, sizeof(int)); } cullResults.FillLightIndices(perObjectLightIndices); } } }
private void FillLightIndices(ref CullResults cullResults, int visibleLightsCount) { //int visibleRenderersCount = cullResults.GetVisibleRenderersCount(); // TODO: commenting cullResults.GetVisislbeRenderersCount() to avoid compiler errors as it is not in main SRP trunk yet // For now setting a small amount enough for the test scenes. int visibleRenderersCount = 1024; if (visibleRenderersCount > m_LightIndicesCount) { m_LightIndicesCount = visibleRenderersCount * visibleLightsCount; if (m_LightIndexListBuffer != null) { m_LightIndexListBuffer.Release(); } m_LightIndexListBuffer = new ComputeBuffer(m_LightIndicesCount, sizeof(uint)); } cullResults.FillLightIndices(m_LightIndexListBuffer); }
public void SetupPerObjectLightIndices(ref CullResults cullResults, ref RenderingData lightData) { if (lightShadowParams == null) { lightShadowParams = new ComputeBuffer(lightData.settings.MaxShadowLightsNum, Marshal.SizeOf <shadowparms_t>()); } List <VisibleLight> visibleLights = lightData.lightData.visibleLights; var lightLoop = lightData.lightData.lightLoop; //GC? #if false int[] perObjectLightIndexMap = cullResults.GetLightIndexMap(); int directionalLightsCount = 0; int additionalLightsCount = 0; // Disable all directional lights from the perobject light indices // Pipeline handles them globally. for (int i = 0; i < visibleLights.Count; ++i) { if (additionalLightsCount >= 16) { break; } VisibleLight light = visibleLights[i]; if (light.lightType == LightType.Directional) { perObjectLightIndexMap[i] = -1; ++directionalLightsCount; } else { perObjectLightIndexMap[i] -= directionalLightsCount; ++additionalLightsCount; } } // Disable all remaining lights we cannot fit into the global light buffer. for (int i = directionalLightsCount + additionalLightsCount; i < visibleLights.Count; ++i) { perObjectLightIndexMap[i] = -1; } cullResults.SetLightIndexMap(perObjectLightIndexMap); // if not using a compute buffer, engine will set indices in 2 vec4 constants // unity_4LightIndices0 and unity_4LightIndices1 int lightIndicesCount = cullResults.GetLightIndicesCount(); if (lightIndicesCount > 0) { if (perObjectLightIndices == null) { perObjectLightIndices = new ComputeBuffer(lightIndicesCount, sizeof(int)); } else if (perObjectLightIndices.count < lightIndicesCount) { perObjectLightIndices.Release(); perObjectLightIndices = new ComputeBuffer(lightIndicesCount, sizeof(int)); } cullResults.FillLightIndices(perObjectLightIndices); } #endif }