Browse Source
Merge branch 'master' into ww1dev/hdrp17/staging
Merge branch 'master' into ww1dev/hdrp17/staging
# Conflicts: # Packages/com.unity.rendering.light-transport/Runtime/UnifiedRayTracing/Common/TerrainToMesh.cs # Packages/com.unity.rendering.light-transport/Tests/Editor/UnifiedRayTracing/AccelStructTests.cs # Packages/com.unity.rendering.light-transport/package.jsonww1dev/hdrp17/staging
60 changed files with 1331 additions and 908 deletions
-
19Packages/com.unity.render-pipelines.core/Editor/Volume/VolumeComponentEditor.cs
-
5Packages/com.unity.render-pipelines.core/Editor/Volume/VolumeComponentListEditor.cs
-
156Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/Debug/DebugDisplayGPUResidentDrawer.cs
-
126Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/GPUResidentDrawer.cs
-
80Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/GPUResidentDrawerBurst.cs
-
2Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/GPUResidentDrawerBurst.cs.meta
-
49Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/GPUResidentDrawerDebug.cs
-
75Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/InstanceCuller.cs
-
19Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/InstanceCullerBurst.cs
-
2Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/InstanceCullerBurst.cs.meta
-
278Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/InstanceCullingBatcher.cs
-
301Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/InstanceCullingBatcherBurst.cs
-
2Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/InstanceCullingBatcherBurst.cs.meta
-
207Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/InstanceData/InstanceDataSystem.Jobs.cs
-
17Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/InstanceData/InstanceDataSystem.cs
-
191Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/InstanceData/InstanceDataSystemBurst.cs
-
2Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/InstanceData/InstanceDataSystemBurst.cs.meta
-
8Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/InstanceOcclusionCuller.cs
-
10Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/InstanceOcclusionCuller.cs.hlsl
-
106Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/LODGroupDataPool.cs
-
72Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/LODGroupDataPoolBurst.cs
-
2Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/LODGroupDataPoolBurst.cs.meta
-
3Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeReferenceVolume.cs
-
1Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeVolume.hlsl
-
1Packages/com.unity.render-pipelines.core/Runtime/PostProcessing/LensFlareDataSRP.cs
-
4Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/IRenderGraphBuilder.cs
-
19Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs
-
22Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphBuilders.cs
-
49Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphUtilsBlit.cs
-
25Packages/com.unity.render-pipelines.core/Runtime/RenderPipelineResources/GPUDriven/InstanceOcclusionCullingKernels.compute
-
45Packages/com.unity.render-pipelines.core/Runtime/Volume/VolumeManager.cs
-
18Packages/com.unity.render-pipelines.core/Runtime/XR/XRPass.cs
-
1Packages/com.unity.render-pipelines.core/Runtime/XR/XRSystem.cs
-
2Packages/com.unity.render-pipelines.core/package.json
-
62Packages/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs
-
4Packages/com.unity.render-pipelines.high-definition/Editor/Material/FogVolume/FogVolumePropertyBlock.cs
-
8Packages/com.unity.render-pipelines.high-definition/Editor/Material/FogVolume/ShaderGraph/FogVolumeSubTarget.cs
-
2Packages/com.unity.render-pipelines.high-definition/Editor/Material/FogVolume/ShaderGraph/OverdrawDebug.hlsl
-
2Packages/com.unity.render-pipelines.high-definition/Editor/Material/FogVolume/ShaderGraph/ShaderPassPreview.hlsl
-
13Packages/com.unity.render-pipelines.high-definition/Editor/Material/FogVolume/ShaderGraph/ShaderPassVoxelize.hlsl
-
36Packages/com.unity.render-pipelines.high-definition/Editor/Material/FogVolume/ShaderGraph/VoxelizationTransforms.hlsl
-
7Packages/com.unity.render-pipelines.high-definition/Editor/Material/FogVolume/ShaderGraph/VoxelizationTransforms.hlsl.meta
-
8Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/Pixel.template.hlsl
-
6Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Debug.cs
-
1Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs
-
1Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingLightLoop.hlsl
-
3Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs
-
3Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl
-
8Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs
-
2Packages/com.unity.render-pipelines.high-definition/package.json
-
39Packages/com.unity.rendering.light-transport/Runtime/UnifiedRayTracing/Common/TerrainToMesh.cs
-
1Packages/com.unity.rendering.light-transport/Tests/Editor/UnifiedRayTracing/AccelStructTests.cs
-
2Packages/com.unity.rendering.light-transport/package.json
-
2Packages/com.unity.shadergraph/package.json
-
16Packages/com.unity.ugui/Runtime/UGUI/UI/Core/Image.cs
-
1Packages/com.unity.ugui/Runtime/UGUI/UI/Core/Slider.cs
-
2Packages/com.unity.ugui/package.json
-
1Packages/com.unity.visualeffectgraph/Editor/Inspector/VFXSlotContainerEditor.cs
-
2Packages/com.unity.visualeffectgraph/package.json
@ -0,0 +1,80 @@ |
|||
using Unity.Collections; |
|||
using UnityEngine.Rendering; |
|||
using Unity.Burst; |
|||
|
|||
namespace UnityEngine.Rendering |
|||
{ |
|||
[BurstCompile] |
|||
internal static class GPUResidentDrawerBurst |
|||
{ |
|||
[BurstCompile(DisableSafetyChecks = true, OptimizeFor = OptimizeFor.Performance)] |
|||
public static void ClassifyMaterials(in NativeArray<int> materialIDs, in NativeParallelHashMap<int, BatchMaterialID>.ReadOnly batchMaterialHash, |
|||
ref NativeList<int> supportedMaterialIDs, ref NativeList<int> unsupportedMaterialIDs, ref NativeList<GPUDrivenPackedMaterialData> supportedPackedMaterialDatas) |
|||
{ |
|||
var usedMaterialIDs = new NativeList<int>(4, Allocator.Temp); |
|||
|
|||
foreach (var materialID in materialIDs) |
|||
{ |
|||
if (batchMaterialHash.ContainsKey(materialID)) |
|||
usedMaterialIDs.Add(materialID); |
|||
} |
|||
|
|||
if (usedMaterialIDs.IsEmpty) |
|||
{ |
|||
usedMaterialIDs.Dispose(); |
|||
return; |
|||
} |
|||
|
|||
unsupportedMaterialIDs.Resize(usedMaterialIDs.Length, NativeArrayOptions.UninitializedMemory); |
|||
supportedMaterialIDs.Resize(usedMaterialIDs.Length, NativeArrayOptions.UninitializedMemory); |
|||
supportedPackedMaterialDatas.Resize(usedMaterialIDs.Length, NativeArrayOptions.UninitializedMemory); |
|||
|
|||
int unsupportedMaterialCount = GPUDrivenProcessor.ClassifyMaterials(usedMaterialIDs.AsArray(), unsupportedMaterialIDs.AsArray(), supportedMaterialIDs.AsArray(), supportedPackedMaterialDatas.AsArray()); |
|||
|
|||
unsupportedMaterialIDs.Resize(unsupportedMaterialCount, NativeArrayOptions.ClearMemory); |
|||
supportedMaterialIDs.Resize(usedMaterialIDs.Length - unsupportedMaterialCount, NativeArrayOptions.ClearMemory); |
|||
supportedPackedMaterialDatas.Resize(supportedMaterialIDs.Length, NativeArrayOptions.ClearMemory); |
|||
|
|||
usedMaterialIDs.Dispose(); |
|||
} |
|||
|
|||
[BurstCompile(DisableSafetyChecks = true, OptimizeFor = OptimizeFor.Performance)] |
|||
public static void FindUnsupportedRenderers(in NativeArray<int> unsupportedMaterials, in NativeArray<SmallIntegerArray>.ReadOnly materialIDArrays, in NativeArray<int>.ReadOnly rendererGroups, |
|||
ref NativeList<int> unsupportedRenderers) |
|||
{ |
|||
for (int arrayIndex = 0; arrayIndex < materialIDArrays.Length; arrayIndex++) |
|||
{ |
|||
var materialIDs = materialIDArrays[arrayIndex]; |
|||
int rendererID = rendererGroups[arrayIndex]; |
|||
|
|||
for (int i = 0; i < materialIDs.Length; i++) |
|||
{ |
|||
int materialID = materialIDs[i]; |
|||
|
|||
if (unsupportedMaterials.Contains(materialID)) |
|||
{ |
|||
unsupportedRenderers.Add(rendererID); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
[BurstCompile(DisableSafetyChecks = true, OptimizeFor = OptimizeFor.Performance)] |
|||
public static void GetMaterialsWithChangedPackedMaterial(in NativeArray<int> materialIDs, in NativeArray<GPUDrivenPackedMaterialData> packedMaterialDatas, |
|||
in NativeParallelHashMap<int, GPUDrivenPackedMaterialData>.ReadOnly packedMaterialHash, ref NativeHashSet<int> filteredMaterials) |
|||
{ |
|||
for (int index = 0; index < materialIDs.Length ; index++) |
|||
{ |
|||
var materialID = materialIDs[index]; |
|||
var newPackedMaterialData = packedMaterialDatas[index]; |
|||
|
|||
// Has its packed material changed? If the material isn't in the packed material cache, consider the material has changed.
|
|||
if (packedMaterialHash.TryGetValue(materialID, out var packedMaterial) && packedMaterial.Equals(newPackedMaterialData)) |
|||
continue; |
|||
|
|||
filteredMaterials.Add(materialID); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,2 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 2f50a3b1f0997d342837e27ab3b95e6f |
|||
@ -0,0 +1,19 @@ |
|||
using Unity.Collections; |
|||
using Unity.Burst; |
|||
|
|||
namespace UnityEngine.Rendering |
|||
{ |
|||
[BurstCompile] |
|||
internal static class InstanceCullerBurst |
|||
{ |
|||
[BurstCompile(DisableSafetyChecks = true, OptimizeFor = OptimizeFor.Performance)] |
|||
public static unsafe void SetupCullingJobInput(float lodBias, BatchCullingContext* context, ReceiverPlanes* receiverPlanes, |
|||
ReceiverSphereCuller* receiverSphereCuller, FrustumPlaneCuller* frustumPlaneCuller, float* screenRelativeMetric) |
|||
{ |
|||
*receiverPlanes = ReceiverPlanes.Create(*context, Allocator.TempJob); |
|||
*receiverSphereCuller = ReceiverSphereCuller.Create(*context, Allocator.TempJob); |
|||
*frustumPlaneCuller = FrustumPlaneCuller.Create(*context, receiverPlanes->planes.AsArray(), *receiverSphereCuller, Allocator.TempJob); |
|||
*screenRelativeMetric = LODGroupRenderingUtils.CalculateScreenRelativeMetric(context->lodParameters, lodBias); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,2 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 99f3de5decfa27b47a4ab725fc059f50 |
|||
@ -0,0 +1,301 @@ |
|||
using System; |
|||
using Unity.Collections; |
|||
using Unity.Burst; |
|||
using Unity.Collections.LowLevel.Unsafe; |
|||
using Unity.Jobs; |
|||
using Unity.Mathematics; |
|||
using UnityEngine.Assertions; |
|||
|
|||
namespace UnityEngine.Rendering |
|||
{ |
|||
[BurstCompile] |
|||
internal static class InstanceCullingBatcherBurst |
|||
{ |
|||
private static void RemoveDrawRange(in RangeKey key, ref NativeParallelHashMap<RangeKey, int> rangeHash, ref NativeList<DrawRange> drawRanges) |
|||
{ |
|||
int drawRangeIndex = rangeHash[key]; |
|||
|
|||
ref DrawRange lastDrawRange = ref drawRanges.ElementAt(drawRanges.Length - 1); |
|||
rangeHash[lastDrawRange.key] = drawRangeIndex; |
|||
|
|||
rangeHash.Remove(key); |
|||
drawRanges.RemoveAtSwapBack(drawRangeIndex); |
|||
} |
|||
|
|||
private static void RemoveDrawBatch(in DrawKey key, ref NativeList<DrawRange> drawRanges, ref NativeParallelHashMap<RangeKey, int> rangeHash, |
|||
ref NativeParallelHashMap<DrawKey, int> batchHash, ref NativeList<DrawBatch> drawBatches) |
|||
{ |
|||
int drawBatchIndex = batchHash[key]; |
|||
|
|||
int drawRangeIndex = rangeHash[key.range]; |
|||
ref DrawRange drawRange = ref drawRanges.ElementAt(drawRangeIndex); |
|||
|
|||
Assert.IsTrue(drawRange.drawCount > 0); |
|||
|
|||
if (--drawRange.drawCount == 0) |
|||
RemoveDrawRange(drawRange.key, ref rangeHash, ref drawRanges); |
|||
|
|||
ref DrawBatch lastDrawBatch = ref drawBatches.ElementAt(drawBatches.Length - 1); |
|||
batchHash[lastDrawBatch.key] = drawBatchIndex; |
|||
|
|||
batchHash.Remove(key); |
|||
drawBatches.RemoveAtSwapBack(drawBatchIndex); |
|||
} |
|||
|
|||
[BurstCompile(DisableSafetyChecks = true, OptimizeFor = OptimizeFor.Performance)] |
|||
public static unsafe void RemoveDrawInstanceIndices(in NativeArray<int> drawInstanceIndices, ref NativeList<DrawInstance> drawInstances, ref NativeParallelHashMap<RangeKey, int> rangeHash, |
|||
ref NativeParallelHashMap<DrawKey, int> batchHash, ref NativeList<DrawRange> drawRanges, ref NativeList<DrawBatch> drawBatches) |
|||
{ |
|||
var drawInstancesPtr = (DrawInstance*)drawInstances.GetUnsafePtr(); |
|||
var drawInstancesNewBack = drawInstances.Length - 1; |
|||
|
|||
for (int indexRev = drawInstanceIndices.Length - 1; indexRev >= 0; --indexRev) |
|||
{ |
|||
int indexToRemove = drawInstanceIndices[indexRev]; |
|||
DrawInstance* drawInstance = drawInstancesPtr + indexToRemove; |
|||
|
|||
int drawBatchIndex = batchHash[drawInstance->key]; |
|||
ref DrawBatch drawBatch = ref drawBatches.ElementAt(drawBatchIndex); |
|||
|
|||
Assert.IsTrue(drawBatch.instanceCount > 0); |
|||
|
|||
if (--drawBatch.instanceCount == 0) |
|||
RemoveDrawBatch(drawBatch.key, ref drawRanges, ref rangeHash, ref batchHash, ref drawBatches); |
|||
|
|||
UnsafeUtility.MemCpy(drawInstance, drawInstancesPtr + drawInstancesNewBack--, sizeof(DrawInstance)); |
|||
} |
|||
|
|||
drawInstances.ResizeUninitialized(drawInstancesNewBack + 1); |
|||
} |
|||
|
|||
private static ref DrawRange EditDrawRange(in RangeKey key, NativeParallelHashMap<RangeKey, int> rangeHash, NativeList<DrawRange> drawRanges) |
|||
{ |
|||
int drawRangeIndex; |
|||
|
|||
if (!rangeHash.TryGetValue(key, out drawRangeIndex)) |
|||
{ |
|||
var drawRange = new DrawRange { key = key, drawCount = 0, drawOffset = 0 }; |
|||
drawRangeIndex = drawRanges.Length; |
|||
rangeHash.Add(key, drawRangeIndex); |
|||
drawRanges.Add(drawRange); |
|||
} |
|||
|
|||
ref DrawRange data = ref drawRanges.ElementAt(drawRangeIndex); |
|||
Assert.IsTrue(data.key.Equals(key)); |
|||
|
|||
return ref data; |
|||
} |
|||
|
|||
private static ref DrawBatch EditDrawBatch(in DrawKey key, in SubMeshDescriptor subMeshDescriptor, NativeParallelHashMap<DrawKey, int> batchHash, NativeList<DrawBatch> drawBatches) |
|||
{ |
|||
var procInfo = new MeshProceduralInfo(); |
|||
procInfo.topology = subMeshDescriptor.topology; |
|||
procInfo.baseVertex = (uint)subMeshDescriptor.baseVertex; |
|||
procInfo.firstIndex = (uint)subMeshDescriptor.indexStart; |
|||
procInfo.indexCount = (uint)subMeshDescriptor.indexCount; |
|||
|
|||
int drawBatchIndex; |
|||
|
|||
if (!batchHash.TryGetValue(key, out drawBatchIndex)) |
|||
{ |
|||
var drawBatch = new DrawBatch() { key = key, instanceCount = 0, instanceOffset = 0, procInfo = procInfo }; |
|||
drawBatchIndex = drawBatches.Length; |
|||
batchHash.Add(key, drawBatchIndex); |
|||
drawBatches.Add(drawBatch); |
|||
} |
|||
|
|||
ref DrawBatch data = ref drawBatches.ElementAt(drawBatchIndex); |
|||
Assert.IsTrue(data.key.Equals(key)); |
|||
|
|||
return ref data; |
|||
} |
|||
|
|||
private static void ProcessRenderer(int i, bool implicitInstanceIndices, in GPUDrivenRendererGroupData rendererData, |
|||
NativeParallelHashMap<int, BatchMeshID> batchMeshHash, NativeParallelHashMap<int, GPUDrivenPackedMaterialData> packedMaterialDataHash, |
|||
NativeParallelHashMap<int, BatchMaterialID> batchMaterialHash, NativeArray<InstanceHandle> instances, NativeList<DrawInstance> drawInstances, |
|||
NativeParallelHashMap<RangeKey, int> rangeHash, NativeList<DrawRange> drawRanges, NativeParallelHashMap<DrawKey, int> batchHash, |
|||
NativeList<DrawBatch> drawBatches) |
|||
{ |
|||
var meshIndex = rendererData.meshIndex[i]; |
|||
var meshID = rendererData.meshID[meshIndex]; |
|||
var submeshCount = rendererData.subMeshCount[meshIndex]; |
|||
var subMeshDescOffset = rendererData.subMeshDescOffset[meshIndex]; |
|||
var batchMeshID = batchMeshHash[meshID]; |
|||
var rendererGroupID = rendererData.rendererGroupID[i]; |
|||
var startSubMesh = rendererData.subMeshStartIndex[i]; |
|||
var gameObjectLayer = rendererData.gameObjectLayer[i]; |
|||
var renderingLayerMask = rendererData.renderingLayerMask[i]; |
|||
var materialsOffset = rendererData.materialsOffset[i]; |
|||
var materialsCount = rendererData.materialsCount[i]; |
|||
var lightmapIndex = rendererData.lightmapIndex[i]; |
|||
var packedRendererData = rendererData.packedRendererData[i]; |
|||
var rendererPriority = rendererData.rendererPriority[i]; |
|||
|
|||
int instanceCount; |
|||
int instanceOffset; |
|||
|
|||
if (implicitInstanceIndices) |
|||
{ |
|||
instanceCount = 1; |
|||
instanceOffset = i; |
|||
} |
|||
else |
|||
{ |
|||
instanceCount = rendererData.instancesCount[i]; |
|||
instanceOffset = rendererData.instancesOffset[i]; |
|||
} |
|||
|
|||
if (instanceCount == 0) |
|||
return; |
|||
|
|||
const int kLightmapIndexMask = 0xffff; |
|||
const int kLightmapIndexInfluenceOnly = 0xfffe; |
|||
|
|||
var overridenComponents = InstanceComponentGroup.Default; |
|||
|
|||
// Add per-instance wind parameters
|
|||
if(packedRendererData.hasTree) |
|||
overridenComponents |= InstanceComponentGroup.Wind; |
|||
|
|||
var lmIndexMasked = lightmapIndex & kLightmapIndexMask; |
|||
|
|||
// Object doesn't have a valid lightmap Index, -> uses probes for lighting
|
|||
if (lmIndexMasked >= kLightmapIndexInfluenceOnly) |
|||
{ |
|||
// Only add the component when needed to store blended results (shader will use the ambient probe when not present)
|
|||
if (packedRendererData.lightProbeUsage == LightProbeUsage.BlendProbes) |
|||
overridenComponents |= InstanceComponentGroup.LightProbe; |
|||
} |
|||
else |
|||
{ |
|||
// Add per-instance lightmap parameters
|
|||
overridenComponents |= InstanceComponentGroup.Lightmap; |
|||
} |
|||
|
|||
// Scan all materials once to retrieve whether this renderer is indirect-compatible or not (and store it in the RangeKey).
|
|||
Span<GPUDrivenPackedMaterialData> packedMaterialDatas = stackalloc GPUDrivenPackedMaterialData[materialsCount]; |
|||
|
|||
var supportsIndirect = true; |
|||
for (int matIndex = 0; matIndex < materialsCount; ++matIndex) |
|||
{ |
|||
if (matIndex >= submeshCount) |
|||
{ |
|||
Debug.LogWarning("Material count in the shared material list is higher than sub mesh count for the mesh. Object may be corrupted."); |
|||
continue; |
|||
} |
|||
|
|||
var materialIndex = rendererData.materialIndex[materialsOffset + matIndex]; |
|||
GPUDrivenPackedMaterialData packedMaterialData; |
|||
|
|||
if (rendererData.packedMaterialData.Length > 0) |
|||
{ |
|||
packedMaterialData = rendererData.packedMaterialData[materialIndex]; |
|||
} |
|||
else |
|||
{ |
|||
var materialID = rendererData.materialID[materialIndex]; |
|||
bool isFound = packedMaterialDataHash.TryGetValue(materialID, out packedMaterialData); |
|||
Assert.IsTrue(isFound, "Packed material data not found."); |
|||
} |
|||
supportsIndirect &= packedMaterialData.isIndirectSupported; |
|||
|
|||
packedMaterialDatas[matIndex] = packedMaterialData; |
|||
} |
|||
|
|||
var rangeKey = new RangeKey |
|||
{ |
|||
layer = (byte)gameObjectLayer, |
|||
renderingLayerMask = renderingLayerMask, |
|||
motionMode = packedRendererData.motionVecGenMode, |
|||
shadowCastingMode = packedRendererData.shadowCastingMode, |
|||
staticShadowCaster = packedRendererData.staticShadowCaster, |
|||
rendererPriority = rendererPriority, |
|||
supportsIndirect = supportsIndirect |
|||
}; |
|||
|
|||
ref DrawRange drawRange = ref EditDrawRange(rangeKey, rangeHash, drawRanges); |
|||
|
|||
for (int matIndex = 0; matIndex < materialsCount; ++matIndex) |
|||
{ |
|||
if (matIndex >= submeshCount) |
|||
{ |
|||
Debug.LogWarning("Material count in the shared material list is higher than sub mesh count for the mesh. Object may be corrupted."); |
|||
continue; |
|||
} |
|||
|
|||
var materialIndex = rendererData.materialIndex[materialsOffset + matIndex]; |
|||
var materialID = rendererData.materialID[materialIndex]; |
|||
var packedMaterialData = packedMaterialDatas[matIndex]; |
|||
|
|||
if (materialID == 0) |
|||
{ |
|||
Debug.LogWarning("Material in the shared materials list is null. Object will be partially rendered."); |
|||
continue; |
|||
} |
|||
|
|||
batchMaterialHash.TryGetValue(materialID, out BatchMaterialID batchMaterialID); |
|||
|
|||
// We always provide crossfade value packed in instance index. We don't use None even if there is no LOD to not split the batch.
|
|||
var flags = BatchDrawCommandFlags.LODCrossFadeValuePacked; |
|||
|
|||
// Let the engine know if we've opted out of lightmap texture arrays
|
|||
flags |= BatchDrawCommandFlags.UseLegacyLightmapsKeyword; |
|||
|
|||
// assume that a custom motion vectors pass contains deformation motion, so should always output motion vectors
|
|||
// (otherwise this flag is set dynamically during culling only when the transform is changing)
|
|||
if (packedMaterialData.isMotionVectorsPassEnabled) |
|||
flags |= BatchDrawCommandFlags.HasMotion; |
|||
|
|||
if (packedMaterialData.isTransparent) |
|||
flags |= BatchDrawCommandFlags.HasSortingPosition; |
|||
|
|||
{ |
|||
var submeshIndex = startSubMesh + matIndex; |
|||
var subMeshDesc = rendererData.subMeshDesc[subMeshDescOffset + submeshIndex]; |
|||
var drawKey = new DrawKey |
|||
{ |
|||
materialID = batchMaterialID, |
|||
meshID = batchMeshID, |
|||
submeshIndex = submeshIndex, |
|||
flags = flags, |
|||
transparentInstanceId = packedMaterialData.isTransparent ? rendererGroupID : 0, |
|||
range = rangeKey, |
|||
overridenComponents = (uint)overridenComponents, |
|||
// When we've opted out of lightmap texture arrays, we
|
|||
// need to pass in a valid lightmap index. The engine
|
|||
// uses this index for sorting and for breaking the
|
|||
// batch when lightmaps change across draw calls, and
|
|||
// for binding the correct light map.
|
|||
lightmapIndex = lightmapIndex |
|||
}; |
|||
|
|||
ref DrawBatch drawBatch = ref EditDrawBatch(drawKey, subMeshDesc, batchHash, drawBatches); |
|||
|
|||
if (drawBatch.instanceCount == 0) |
|||
++drawRange.drawCount; |
|||
|
|||
drawBatch.instanceCount += instanceCount; |
|||
|
|||
for (int j = 0; j < instanceCount; ++j) |
|||
{ |
|||
var instanceIndex = instanceOffset + j; |
|||
InstanceHandle instance = instances[instanceIndex]; |
|||
drawInstances.Add(new DrawInstance { key = drawKey, instanceIndex = instance.index }); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
[BurstCompile(DisableSafetyChecks = true, OptimizeFor = OptimizeFor.Performance)] |
|||
public static void CreateDrawBatches(bool implicitInstanceIndices, in NativeArray<InstanceHandle> instances, in GPUDrivenRendererGroupData rendererData, |
|||
in NativeParallelHashMap<int, BatchMeshID> batchMeshHash, in NativeParallelHashMap<int, BatchMaterialID> batchMaterialHash, |
|||
in NativeParallelHashMap<int, GPUDrivenPackedMaterialData> packedMaterialDataHash, |
|||
ref NativeParallelHashMap<RangeKey, int> rangeHash, ref NativeList<DrawRange> drawRanges, ref NativeParallelHashMap<DrawKey, int> batchHash, ref NativeList<DrawBatch> drawBatches, |
|||
ref NativeList<DrawInstance> drawInstances) |
|||
{ |
|||
for (int i = 0; i < rendererData.rendererGroupID.Length; ++i) |
|||
ProcessRenderer(i, implicitInstanceIndices, rendererData, batchMeshHash, packedMaterialDataHash, batchMaterialHash, instances, |
|||
drawInstances, rangeHash, drawRanges, batchHash, drawBatches); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,2 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 07b72b6a7afa9b448b3103bb66d57ca0 |
|||
@ -0,0 +1,191 @@ |
|||
using Unity.Collections; |
|||
using Unity.Burst; |
|||
using UnityEngine.Assertions; |
|||
|
|||
namespace UnityEngine.Rendering |
|||
{ |
|||
[BurstCompile] |
|||
internal static class InstanceDataSystemBurst |
|||
{ |
|||
[BurstCompile(DisableSafetyChecks = true, OptimizeFor = OptimizeFor.Performance)] |
|||
public static void ReallocateInstances(bool implicitInstanceIndices, in NativeArray<int> rendererGroupIDs, in NativeArray<GPUDrivenPackedRendererData> packedRendererData, |
|||
in NativeArray<int> instanceOffsets, in NativeArray<int> instanceCounts, ref InstanceAllocators instanceAllocators, ref CPUInstanceData instanceData, |
|||
ref CPUSharedInstanceData sharedInstanceData, ref NativeArray<InstanceHandle> instances, |
|||
ref NativeParallelMultiHashMap<int, InstanceHandle> rendererGroupInstanceMultiHash) |
|||
{ |
|||
for (int i = 0; i < rendererGroupIDs.Length; ++i) |
|||
{ |
|||
var rendererGroupID = rendererGroupIDs[i]; |
|||
var hasTree = packedRendererData[i].hasTree; |
|||
|
|||
int instanceCount; |
|||
int instanceOffset; |
|||
|
|||
if (implicitInstanceIndices) |
|||
{ |
|||
instanceCount = 1; |
|||
instanceOffset = i; |
|||
} |
|||
else |
|||
{ |
|||
instanceCount = instanceCounts[i]; |
|||
instanceOffset = instanceOffsets[i]; |
|||
} |
|||
|
|||
SharedInstanceHandle sharedInstance; |
|||
|
|||
if (rendererGroupInstanceMultiHash.TryGetFirstValue(rendererGroupID, out var instance, out var it)) |
|||
{ |
|||
sharedInstance = instanceData.Get_SharedInstance(instance); |
|||
|
|||
int currentInstancesCount = sharedInstanceData.Get_RefCount(sharedInstance); |
|||
int instancesToFreeCount = currentInstancesCount - instanceCount; |
|||
|
|||
if (instancesToFreeCount > 0) |
|||
{ |
|||
bool success = true; |
|||
int freedInstancesCount = 0; |
|||
|
|||
for (int j = 0; j < instanceCount; ++j) |
|||
success = rendererGroupInstanceMultiHash.TryGetNextValue(out instance, ref it); |
|||
|
|||
Assert.IsTrue(success); |
|||
|
|||
while (success) |
|||
{ |
|||
var idx = instanceData.InstanceToIndex(instance); |
|||
instanceData.Remove(instance); |
|||
|
|||
instanceAllocators.FreeInstance(instance); |
|||
|
|||
rendererGroupInstanceMultiHash.Remove(it); |
|||
++freedInstancesCount; |
|||
success = rendererGroupInstanceMultiHash.TryGetNextValue(out instance, ref it); |
|||
} |
|||
|
|||
Assert.AreEqual(instancesToFreeCount, freedInstancesCount); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
sharedInstance = instanceAllocators.AllocateSharedInstance(); |
|||
sharedInstanceData.AddNoGrow(sharedInstance); |
|||
} |
|||
|
|||
if (instanceCount > 0) |
|||
{ |
|||
sharedInstanceData.Set_RefCount(sharedInstance, instanceCount); |
|||
|
|||
for (int j = 0; j < instanceCount; ++j) |
|||
{ |
|||
int instanceIndex = instanceOffset + j; |
|||
|
|||
if (instances[instanceIndex].valid) |
|||
continue; |
|||
|
|||
InstanceHandle newInstance; |
|||
|
|||
if (!hasTree) |
|||
newInstance = instanceAllocators.AllocateInstance(InstanceType.MeshRenderer); |
|||
else |
|||
newInstance = instanceAllocators.AllocateInstance(InstanceType.SpeedTree); |
|||
|
|||
instanceData.AddNoGrow(newInstance); |
|||
int index = instanceData.InstanceToIndex(newInstance); |
|||
instanceData.sharedInstances[index] = sharedInstance; |
|||
instanceData.movedInCurrentFrameBits.Set(index, false); |
|||
instanceData.movedInPreviousFrameBits.Set(index, false); |
|||
instanceData.visibleInPreviousFrameBits.Set(index, false); |
|||
|
|||
rendererGroupInstanceMultiHash.Add(rendererGroupID, newInstance); |
|||
instances[instanceIndex] = newInstance; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
sharedInstanceData.Remove(sharedInstance); |
|||
instanceAllocators.FreeSharedInstance(sharedInstance); |
|||
} |
|||
} |
|||
} |
|||
|
|||
[BurstCompile(DisableSafetyChecks = true, OptimizeFor = OptimizeFor.Performance)] |
|||
public static void FreeRendererGroupInstances(in NativeArray<int>.ReadOnly rendererGroupsID, ref InstanceAllocators instanceAllocators, ref CPUInstanceData instanceData, |
|||
ref CPUSharedInstanceData sharedInstanceData, ref NativeParallelMultiHashMap<int, InstanceHandle> rendererGroupInstanceMultiHash) |
|||
{ |
|||
foreach (var rendererGroupID in rendererGroupsID) |
|||
{ |
|||
for (bool success = rendererGroupInstanceMultiHash.TryGetFirstValue(rendererGroupID, out var instance, out var it); success;) |
|||
{ |
|||
SharedInstanceHandle sharedInstance = instanceData.Get_SharedInstance(instance); |
|||
int sharedInstanceIndex = sharedInstanceData.SharedInstanceToIndex(sharedInstance); |
|||
int refCount = sharedInstanceData.refCounts[sharedInstanceIndex]; |
|||
|
|||
Assert.IsTrue(refCount > 0); |
|||
|
|||
if (refCount > 1) |
|||
{ |
|||
sharedInstanceData.refCounts[sharedInstanceIndex] = refCount - 1; |
|||
} |
|||
else |
|||
{ |
|||
sharedInstanceData.Remove(sharedInstance); |
|||
instanceAllocators.FreeSharedInstance(sharedInstance); |
|||
} |
|||
|
|||
var idx = instanceData.InstanceToIndex(instance); |
|||
instanceData.Remove(instance); |
|||
instanceAllocators.FreeInstance(instance); |
|||
|
|||
success = rendererGroupInstanceMultiHash.TryGetNextValue(out instance, ref it); |
|||
} |
|||
|
|||
rendererGroupInstanceMultiHash.Remove(rendererGroupID); |
|||
} |
|||
} |
|||
|
|||
|
|||
[BurstCompile(DisableSafetyChecks = true, OptimizeFor = OptimizeFor.Performance)] |
|||
public static void FreeInstances(in NativeArray<InstanceHandle>.ReadOnly instances, ref InstanceAllocators instanceAllocators, ref CPUInstanceData instanceData, |
|||
ref CPUSharedInstanceData sharedInstanceData, ref NativeParallelMultiHashMap<int, InstanceHandle> rendererGroupInstanceMultiHash) |
|||
{ |
|||
foreach (var instance in instances) |
|||
{ |
|||
if (!instanceData.IsValidInstance(instance)) |
|||
continue; |
|||
|
|||
int instanceIndex = instanceData.InstanceToIndex(instance); |
|||
SharedInstanceHandle sharedInstance = instanceData.sharedInstances[instanceIndex]; |
|||
int sharedInstanceIndex = sharedInstanceData.SharedInstanceToIndex(sharedInstance); |
|||
int refCount = sharedInstanceData.refCounts[sharedInstanceIndex]; |
|||
var rendererGroupID = sharedInstanceData.rendererGroupIDs[sharedInstanceIndex]; |
|||
|
|||
Assert.IsTrue(refCount > 0); |
|||
|
|||
if (refCount > 1) |
|||
{ |
|||
sharedInstanceData.refCounts[sharedInstanceIndex] = refCount - 1; |
|||
} |
|||
else |
|||
{ |
|||
sharedInstanceData.Remove(sharedInstance); |
|||
instanceAllocators.FreeSharedInstance(sharedInstance); |
|||
} |
|||
|
|||
instanceData.Remove(instance); |
|||
instanceAllocators.FreeInstance(instance); |
|||
|
|||
//@ This will have quadratic cost. Optimize later.
|
|||
for (bool success = rendererGroupInstanceMultiHash.TryGetFirstValue(rendererGroupID, out var i, out var it); success;) |
|||
{ |
|||
if (instance.Equals(i)) |
|||
{ |
|||
rendererGroupInstanceMultiHash.Remove(it); |
|||
break; |
|||
} |
|||
success = rendererGroupInstanceMultiHash.TryGetNextValue(out i, ref it); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,2 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 302f596d55264be4ba359e52ec407766 |
|||
@ -0,0 +1,72 @@ |
|||
using Unity.Collections; |
|||
using Unity.Burst; |
|||
using UnityEngine.Assertions; |
|||
|
|||
namespace UnityEngine.Rendering |
|||
{ |
|||
[BurstCompile] |
|||
internal static class LODGroupDataPoolBurst |
|||
{ |
|||
[BurstCompile(DisableSafetyChecks = true, OptimizeFor = OptimizeFor.Performance)] |
|||
public static int FreeLODGroupData(in NativeArray<int> destroyedLODGroupsID, ref NativeList<LODGroupData> lodGroupsData, |
|||
ref NativeParallelHashMap<int, GPUInstanceIndex> lodGroupDataHash, ref NativeList<GPUInstanceIndex> freeLODGroupDataHandles) |
|||
{ |
|||
int removedRendererCount = 0; |
|||
|
|||
foreach (int lodGroupID in destroyedLODGroupsID) |
|||
{ |
|||
if (lodGroupDataHash.TryGetValue(lodGroupID, out var lodGroupInstance)) |
|||
{ |
|||
Assert.IsTrue(lodGroupInstance.valid); |
|||
|
|||
lodGroupDataHash.Remove(lodGroupID); |
|||
freeLODGroupDataHandles.Add(lodGroupInstance); |
|||
|
|||
ref LODGroupData lodGroupData = ref lodGroupsData.ElementAt(lodGroupInstance.index); |
|||
Assert.IsTrue(lodGroupData.valid); |
|||
|
|||
removedRendererCount += lodGroupData.rendererCount; |
|||
lodGroupData.valid = false; |
|||
} |
|||
} |
|||
|
|||
return removedRendererCount; |
|||
} |
|||
|
|||
[BurstCompile(DisableSafetyChecks = true, OptimizeFor = OptimizeFor.Performance)] |
|||
public static int AllocateOrGetLODGroupDataInstances(in NativeArray<int> lodGroupsID, ref NativeList<LODGroupData> lodGroupsData, ref NativeList<LODGroupCullingData> lodGroupCullingData, |
|||
ref NativeParallelHashMap<int, GPUInstanceIndex> lodGroupDataHash, ref NativeList<GPUInstanceIndex> freeLODGroupDataHandles, ref NativeArray<GPUInstanceIndex> lodGroupInstances) |
|||
{ |
|||
int freeHandlesCount = freeLODGroupDataHandles.Length; |
|||
int lodDataLength = lodGroupsData.Length; |
|||
int previousRendererCount = 0; |
|||
|
|||
for (int i = 0; i < lodGroupsID.Length; ++i) |
|||
{ |
|||
int lodGroupID = lodGroupsID[i]; |
|||
|
|||
if (!lodGroupDataHash.TryGetValue(lodGroupID, out var lodGroupInstance)) |
|||
{ |
|||
if (freeHandlesCount == 0) |
|||
lodGroupInstance = new GPUInstanceIndex() { index = lodDataLength++ }; |
|||
else |
|||
lodGroupInstance = freeLODGroupDataHandles[--freeHandlesCount]; |
|||
|
|||
lodGroupDataHash.TryAdd(lodGroupID, lodGroupInstance); |
|||
} |
|||
else |
|||
{ |
|||
previousRendererCount += lodGroupsData.ElementAt(lodGroupInstance.index).rendererCount; |
|||
} |
|||
|
|||
lodGroupInstances[i] = lodGroupInstance; |
|||
} |
|||
|
|||
freeLODGroupDataHandles.ResizeUninitialized(freeHandlesCount); |
|||
lodGroupsData.ResizeUninitialized(lodDataLength); |
|||
lodGroupCullingData.ResizeUninitialized(lodDataLength); |
|||
|
|||
return previousRendererCount; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,2 @@ |
|||
fileFormatVersion: 2 |
|||
guid: ad57195e4230c9344a64d902de871991 |
|||
@ -0,0 +1,36 @@ |
|||
#pragma once |
|||
|
|||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/HDRenderPipeline.VolumetricLighting.cs.hlsl" |
|||
|
|||
// Overrides the transform functions that would use object matrices in the fog as they are not available due to the indirect draw |
|||
// Instead we can re-build the object matrix from the OBB of the fog object |
|||
|
|||
float4x4 BuildWorldToObjectMatrixFromLocalFogOBB() |
|||
{ |
|||
float3x3 rotation = float3x3( |
|||
_VolumetricMaterialObbRight.xyz, |
|||
_VolumetricMaterialObbUp.xyz, |
|||
cross(_VolumetricMaterialObbRight.xyz, _VolumetricMaterialObbUp.xyz) |
|||
); |
|||
|
|||
// inverse rotation |
|||
rotation = transpose(rotation); |
|||
|
|||
// inverse translation |
|||
float3 inverseTranslation = -(mul(_VolumetricMaterialObbCenter.xyz, rotation)); |
|||
|
|||
// Build matrix |
|||
float4x4 objectMatrix = 0; |
|||
objectMatrix._m00_m10_m20 = rotation[0]; |
|||
objectMatrix._m01_m11_m21 = rotation[1]; |
|||
objectMatrix._m02_m12_m22 = rotation[2]; |
|||
objectMatrix._m03_m13_m23_m33 = float4(inverseTranslation, 1); |
|||
|
|||
return objectMatrix; |
|||
} |
|||
|
|||
float3 TransformWorldToObjectFog(float3 positionRWS) |
|||
{ |
|||
float3 posWS = GetAbsolutePositionWS(positionRWS); |
|||
return mul(BuildWorldToObjectMatrixFromLocalFogOBB(), float4(posWS, 1)).xyz; |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 623770b432f006f49af1b65f726bf86f |
|||
ShaderIncludeImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue