From 2457bc3108c7bb2de4f986544f92c186b6058771 Mon Sep 17 00:00:00 2001 From: Unity Technologies <@unity> Date: Mon, 13 Feb 2023 00:00:00 +0000 Subject: [PATCH] com.unity.entities.graphics@1.0.0-pre.44 ## [1.0.0-pre.44] - 2023-02-13 ### Added * Optimize OnPerformCulling by computing the CullingSplits from a main thread Burst job. * EntitiesGraphicsSystem.GetMesh and EntitiesGraphicsSystem.GetMaterial are now public. * Warning in-editor when using Entities.Graphics and URP that Forward+ rendering path should be used. ### Changed * Removed async readback from deformations and replaced with fixed number of frames. * The built-in properties for URP has been changed so that they have a slider for most values between 0-1. Relevant properties have also been changed from using a float4 for color in the inspector to use a color property instead. * `PushBlendWeightSystem.cs`, `PushSkinMatrixSystem.cs`, `MeshRendererBaking.cs` script files have been updated to the latest idiomatic `foreach()`. * Changed skin matrix / blend shape weight access in CopyBlendShapeWeightsToGPUJob and CopySkinMatricesToGPUJob to readonly. * Improved `SkinnedMeshRenderer` baking performance * Updated com.unity.render-pipelines.core dependency from 14.0.4 to 14.0.6 ### Removed * Removed RemapMaterialMeshIndexJob. Both array indices and runtime IDs are now directly supported for MaterialMeshInfo. ### Fixed * Occlusion browser not being updated properly in play mode. * Only call UpdateAllBatches if there are entities graphics chunks * Fixed a bug with Baked Lights inside subscenes, where the bakingOutput of such Lights was not updated correctly. * Fixed global ambient probe when multiple cameras are present with HDRP * Light baking will cause the MeshRenderers to bake, thus automatically updating the light map in the entities scene. This previously required forcing the reimport of the entity scene. * 'GraphicsDeviceType.OpenGLES2' is obsolete: 'OpenGL ES 2.0 is no longer supported in Unity 2023.1' --- CHANGELOG.md | 40 +- Documentation~/material-overrides-code.md | 4 +- Documentation~/runtime-entity-creation.md | 8 +- Documentation~/sample-projects.md | 4 +- .../Systems/PushBlendWeightSystem.cs | 90 +++-- .../Systems/PushMeshDataSystem.cs | 100 +++-- .../Systems/PushSkinMatrixSystem.cs | 91 +++-- .../DrawCommandGeneration.cs | 49 ++- .../EntitiesGraphicsConversion.cs | 25 +- .../EntitiesGraphicsCulling.cs | 73 ++-- .../EntitiesGraphicsLightBakingDataSystem.cs | 36 +- .../EntitiesGraphicsSystem.cs | 365 ++++++++++-------- ...HDRPMaterialPropertyAORemapMaxAuthoring.cs | 2 +- ...HDRPMaterialPropertyAORemapMinAuthoring.cs | 2 +- ...DRPMaterialPropertyAlphaCutoffAuthoring.cs | 2 +- .../HDRPMaterialPropertyBaseColorAuthoring.cs | 5 +- .../HDRPMaterialPropertyMetallicAuthoring.cs | 2 +- ...HDRPMaterialPropertySmoothnessAuthoring.cs | 2 +- .../HDRPMaterialPropertyThicknessAuthoring.cs | 2 +- ...HDRPMaterialPropertyUnlitColorAuthoring.cs | 5 +- Unity.Entities.Graphics/MeshRendererBaking.cs | 36 +- .../MeshRendererBakingUtility.cs | 4 - .../Occlusion/Masked/BufferGroup.cs | 8 +- .../Occlusion/UI/OcclusionBrowserView.cs | 11 + .../Occlusion/UI/OcclusionBrowserView.uxml | 2 +- .../Occlusion/UnityOcclusion.cs | 8 + .../Probes/LightProbeUpdateSystem.cs | 13 - .../SkinnedMeshRendererBaking.cs | 3 +- Unity.Entities.Graphics/SparseUploader.cs | 9 +- .../URPMaterialPropertyBaseColorAuthoring.cs | 14 +- .../URPMaterialPropertyBumpScaleAuthoring.cs | 2 +- .../URPMaterialPropertyCutoffAuthoring.cs | 3 +- ...PMaterialPropertyEmissionColorAuthoring.cs | 16 +- .../URPMaterialPropertyMetallicAuthoring.cs | 3 +- .../URPMaterialPropertySmoothnessAuthoring.cs | 3 +- .../URPMaterialPropertySpecColorAuthoring.cs | 14 +- package.json | 16 +- 37 files changed, 653 insertions(+), 419 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb84fc3..cb8b33f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,37 @@ uid: changelog --- # Changelog +## [1.0.0-pre.44] - 2023-02-13 + +### Added + +* Optimize OnPerformCulling by computing the CullingSplits from a main thread Burst job. +* EntitiesGraphicsSystem.GetMesh and EntitiesGraphicsSystem.GetMaterial are now public. +* Warning in-editor when using Entities.Graphics and URP that Forward+ rendering path should be used. + +### Changed + +* Removed async readback from deformations and replaced with fixed number of frames. +* The built-in properties for URP has been changed so that they have a slider for most values between 0-1. Relevant properties have also been changed from using a float4 for color in the inspector to use a color property instead. +* `PushBlendWeightSystem.cs`, `PushSkinMatrixSystem.cs`, `MeshRendererBaking.cs` script files have been updated to the latest idiomatic `foreach()`. +* Changed skin matrix / blend shape weight access in CopyBlendShapeWeightsToGPUJob and CopySkinMatricesToGPUJob to readonly. +* Improved `SkinnedMeshRenderer` baking performance +* Updated com.unity.render-pipelines.core dependency from 14.0.4 to 14.0.6 + +### Removed + + * Removed RemapMaterialMeshIndexJob. Both array indices and runtime IDs are now directly supported for MaterialMeshInfo. + +### Fixed + +* Occlusion browser not being updated properly in play mode. +* Only call UpdateAllBatches if there are entities graphics chunks +* Fixed a bug with Baked Lights inside subscenes, where the bakingOutput of such Lights was not updated correctly. +* Fixed global ambient probe when multiple cameras are present with HDRP +* Light baking will cause the MeshRenderers to bake, thus automatically updating the light map in the entities scene. This previously required forcing the reimport of the entity scene. +* 'GraphicsDeviceType.OpenGLES2' is obsolete: 'OpenGL ES 2.0 is no longer supported in Unity 2023.1' + + ## [1.0.0-pre.15] - 2022-11-16 ### Added @@ -22,19 +53,16 @@ uid: changelog * Blend shapes not working on certain GPUs. * Improved error behavior when null Meshes or Materials are used with Entities. +### Security ## [1.0.0-exp.14] - 2022-10-19 - ### Changed - * Updated documentation for mesh deformations. * Removed async readback from deformations and replaced with fixed number of frames. - ### Fixed - -* Fixed a bug in the BatchingBenchmark sample scene where it would only spawn entities the first time it was dynamically loaded. +* Fixed a bug in the BatchingBenchmark sample scene where it would only spawn entites the first time it was dynamically loaded. * Fixed an issue where Entities Graphics would cause issues with the device being able to idle. @@ -59,7 +87,6 @@ uid: changelog * DeformationsInPresentation and SkinnedMeshRendererConversion are now sealed. * RegisterMaterialMeshSystem is now internal instead of public. - ### Removed * PushMeshDataSystem, PushSkinMatrixSystem, PushBlendWeightSystem, InstantiateDeformationSystem, BlendShapeDeformationSystem and SkinningDeformationSystem are no longer part of the public API. Use DeformationsInPresentation instead. @@ -71,6 +98,7 @@ uid: changelog * Improved multi threaded load balancing of the Entities Graphics frustum culling Burst job * Guard against overflow of static readonly int k_MaxSize for the deformation buffers. + ## [0.14.0] - 2021-09-17 ### Added diff --git a/Documentation~/material-overrides-code.md b/Documentation~/material-overrides-code.md index 910bfce..7170c57 100644 --- a/Documentation~/material-overrides-code.md +++ b/Documentation~/material-overrides-code.md @@ -54,14 +54,14 @@ You can create your own custom Shader Graph properties, and expose them to DOTS For the DOTS IComponentData struct, use the `MaterialProperty` Attribute, passing in the **Reference** and type for the Shader Graph property. For example, the IComponentData for the color (float4) property in the above step would be: ``` -[MaterialProperty("_Color", MaterialPropertyFormat.Float4)] +[MaterialProperty("_Color")] public struct MyOwnColor : IComponentData { public float4 Value; } ``` -Ensure that the *Reference* name in Shader Graph and the string name in MaterialProperty attribute match exactly. The type declared in the MaterialPropertyFormat should also be compatible with both the Shader Graph and the struct data layout. If the binary size doesn't match, you will see an error message in the console window. +Ensure that the **Reference** name in Shader Graph and the string name in MaterialProperty attribute match exactly. ### Burst C# system diff --git a/Documentation~/runtime-entity-creation.md b/Documentation~/runtime-entity-creation.md index aba7f29..9181d07 100644 --- a/Documentation~/runtime-entity-creation.md +++ b/Documentation~/runtime-entity-creation.md @@ -5,6 +5,7 @@ To render an entity, Entities Graphics requires that the entity contains a speci ## RenderMeshUtility - AddComponents This API takes an entity and adds the components Entities Graphics requires based on the given mesh and material, and a `RenderMeshDescription`, which is a struct that describes additional rendering settings. There are two versions of the API: + - One version accepts a `RenderMesh`. For information on the structure of a `RenderMesh`, see [RenderMesh](#rendermesh). Entities Graphics only uses this version during the GameObject conversion process; using this version at runtime doesn't produce rendering entities. - A second version accepts a `RenderMeshArray`. For information on the structure of a `RenderMeshArray`, see [RenderMeshArray](#rendermesharray). Use this version of `AddComponents` at runtime. @@ -26,8 +27,8 @@ A `RenderMeshArray` contains a list of meshes and materials that a collection of The `MaterialMeshInfo` is a Burst-compatible plain data component that you can use to efficiently select or change an entity's mesh and material. This component supports two methods of selecting or changing an entity's mesh or material: -* Referring to array indices inside a `RenderMeshArray` shared component on the same entity. -* Referring directly to mesh and material IDs that you registered with the Entities Graphics beforehand. +- Referring to array indices inside a `RenderMeshArray` shared component on the same entity. +- Referring directly to mesh and material IDs that you registered with the Entities Graphics beforehand. ### Usage instructions @@ -95,7 +96,7 @@ public class AddComponentsExample : MonoBehaviour receiveShadows: false); // Create an array of mesh and material required for runtime rendering. - var renderMeshArray = new RenderMeshArray(new List { Material }, new List { Mesh }); + var renderMeshArray = new RenderMeshArray(new Material[] { Material }, new Mesh[] { Mesh }); // Create empty base entity var prototype = entityManager.CreateEntity(); @@ -129,4 +130,3 @@ public class AddComponentsExample : MonoBehaviour } } ``` - diff --git a/Documentation~/sample-projects.md b/Documentation~/sample-projects.md index da6da20..02c4a90 100644 --- a/Documentation~/sample-projects.md +++ b/Documentation~/sample-projects.md @@ -8,8 +8,8 @@ When you clone the Project's repository, make sure to use git or a git client. T The Entities Graphics sample projects can be found at: -- **HDRP**: [HybridHDRPSamples](https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/HybridHDRPSamples) -- **URP**: [HybridURPSamples](https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/HybridURPSamples) +- **HDRP**: [HDRPSamples](https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/GraphicsSamples/HDRPSamples) +- **URP**: [URPSamples](https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/GraphicsSamples/URPSamples) Project folder structure: diff --git a/Unity.Entities.Graphics/Deformations/Systems/PushBlendWeightSystem.cs b/Unity.Entities.Graphics/Deformations/Systems/PushBlendWeightSystem.cs index e26c288..9078eee 100644 --- a/Unity.Entities.Graphics/Deformations/Systems/PushBlendWeightSystem.cs +++ b/Unity.Entities.Graphics/Deformations/Systems/PushBlendWeightSystem.cs @@ -35,6 +35,49 @@ protected override void OnCreate() ); } + [WithAll(typeof(SharedMeshTracker))] + partial struct ConstructHashMapJob : IJobEntity + { + public NativeParallelMultiHashMap.ParallelWriter DeformedEntityToComputeIndexParallel; + + private void Execute(in BlendWeightBufferIndex index, in DeformedEntity deformedEntity) + { + // Skip if we have an invalid index. + if (index.Value == BlendWeightBufferIndex.Null) + return; + + DeformedEntityToComputeIndexParallel.Add(deformedEntity.Value, index.Value); + } + } + + partial struct CopyBlendShapeWeightsToGPUJob : IJobEntity + { + [NativeDisableContainerSafetyRestriction] public NativeArray BlendShapeWeightsBuffer; + [ReadOnly] public NativeParallelMultiHashMap DeformedEntityToComputeIndex; + + private void Execute(in DynamicBuffer weights, in Entity entity) + { + // Not all deformed entities in the world will have a renderer attached to them. + if (!DeformedEntityToComputeIndex.ContainsKey(entity)) + return; + + var length = weights.Length * UnsafeUtility.SizeOf(); + var indices = DeformedEntityToComputeIndex.GetValuesForKey(entity); + + foreach (var index in indices) + { + unsafe + { + UnsafeUtility.MemCpy( + (float*)BlendShapeWeightsBuffer.GetUnsafePtr() + index, + weights.GetUnsafeReadOnlyPtr(), + length + ); + } + } + } + } + protected override void OnUpdate() { if (m_PushMeshDataSystem.BlendShapeWeightCount == 0) @@ -42,46 +85,19 @@ protected override void OnUpdate() k_Marker.Begin(); - var deformedEntityToComputeIndex = new NativeMultiHashMap(m_BlendShapedEntityQuery.CalculateEntityCount(), Allocator.TempJob); + var deformedEntityToComputeIndex = new NativeParallelMultiHashMap(m_BlendShapedEntityQuery.CalculateEntityCount(), Allocator.TempJob); var deformedEntityToComputeIndexParallel = deformedEntityToComputeIndex.AsParallelWriter(); - Dependency = Entities - .WithName("ConstructHashMap") - .WithAll() - .ForEach((in BlendWeightBufferIndex index, in DeformedEntity deformedEntity) => - { - // Skip if we have an invalid index. - if (index.Value == BlendWeightBufferIndex.Null) - return; - - deformedEntityToComputeIndexParallel.Add(deformedEntity.Value, index.Value); - }).ScheduleParallel(Dependency); + Dependency = new ConstructHashMapJob + { + DeformedEntityToComputeIndexParallel = deformedEntityToComputeIndexParallel + }.ScheduleParallel(Dependency); var blendShapeWeightsBuffer = m_PushMeshDataSystem.BlendShapeBufferManager.LockBlendWeightBufferForWrite(m_PushMeshDataSystem.BlendShapeWeightCount); - Dependency = Entities - .WithName("CopyBlendShapeWeightsToGPU") - .WithNativeDisableContainerSafetyRestriction(blendShapeWeightsBuffer) - .WithReadOnly(deformedEntityToComputeIndex) - .ForEach((ref DynamicBuffer weights, in Entity entity) => - { - // Not all deformed entities in the world will have a renderer attached to them. - if (!deformedEntityToComputeIndex.ContainsKey(entity)) - return; - - var length = weights.Length * UnsafeUtility.SizeOf(); - var indices = deformedEntityToComputeIndex.GetValuesForKey(entity); - - foreach (var index in indices) - { - unsafe - { - UnsafeUtility.MemCpy( - (float*)blendShapeWeightsBuffer.GetUnsafePtr() + index, - weights.GetUnsafePtr(), - length - ); - } - } - }).ScheduleParallel(Dependency); + Dependency = new CopyBlendShapeWeightsToGPUJob + { + BlendShapeWeightsBuffer = blendShapeWeightsBuffer, + DeformedEntityToComputeIndex = deformedEntityToComputeIndex + }.ScheduleParallel(Dependency); Dependency = deformedEntityToComputeIndex.Dispose(Dependency); diff --git a/Unity.Entities.Graphics/Deformations/Systems/PushMeshDataSystem.cs b/Unity.Entities.Graphics/Deformations/Systems/PushMeshDataSystem.cs index 7e8e599..f1c937d 100644 --- a/Unity.Entities.Graphics/Deformations/Systems/PushMeshDataSystem.cs +++ b/Unity.Entities.Graphics/Deformations/Systems/PushMeshDataSystem.cs @@ -117,7 +117,7 @@ protected override void OnDestroy() m_MeshVertexCount.Dispose(); if (m_BlendShapeWeightCount.IsCreated) m_BlendShapeWeightCount.Dispose(); - if(m_SkinMatrixCount.IsCreated) + if (m_SkinMatrixCount.IsCreated) m_SkinMatrixCount.Dispose(); m_MeshBufferManager?.Dispose(); @@ -304,16 +304,33 @@ private void AddRemoveTrackedMeshes() rmvMeshes.Add(tracked.VersionHash); }).Run(); + var brgRenderMeshArrays = World.GetExistingSystemManaged()?.BRGRenderMeshArrays ?? new NativeParallelHashMap(); + var renderMeshArrayHandle = GetSharedComponentTypeHandle(); + Entities .WithName("AddComponents") .WithAll() .WithNone() .WithStructuralChanges() - .ForEach((Entity e, in MaterialMeshInfo renderData) => + .ForEach((Entity e, in MaterialMeshInfo materialMeshInfo) => { - var meshID = renderData.MeshID; + // If the chunk has a RenderMeshArray, get access to the corresponding registered + // Material and Mesh IDs + BRGRenderMeshArray brgRenderMeshArray = default; + if (!brgRenderMeshArrays.IsEmpty) + { + int renderMeshArrayIndex = EntityManager.GetChunk(e).GetSharedComponentIndex(renderMeshArrayHandle); + bool hasRenderMeshArray = renderMeshArrayIndex >= 0; + if (hasRenderMeshArray) + brgRenderMeshArrays.TryGetValue(renderMeshArrayIndex, out brgRenderMeshArray); + } - Assert.IsFalse(meshID == BatchMeshID.Null); + BatchMeshID meshID = materialMeshInfo.IsRuntimeMesh + ? materialMeshInfo.MeshID + : brgRenderMeshArray.GetMeshID(materialMeshInfo); + + if (meshID == BatchMeshID.Null) + return; // Mesh is already registered. if (TryGetSharedMeshData(meshID, out var data)) @@ -433,27 +450,44 @@ private void LayoutOutputBuffer() var meshes = m_MeshIDs; var count = new NativeArray(meshes.Length, Allocator.TempJob); + var sharedMeshes = m_SharedMeshData; - Dependency = Entities + // For now assume every mesh is visible & active. + Dependency = Job .WithName("CountActiveMeshes") - .WithAll().WithAll() - .WithReadOnly(meshes) - .WithNativeDisableParallelForRestriction(count) - .ForEach((in MaterialMeshInfo id) => + .WithReadOnly(meshes).WithReadOnly(sharedMeshes) + .WithCode(() => { - if (id.MeshID == BatchMeshID.Null) - return; + for (int i = 0; i < sharedMeshes.Length; i++) + { + var sharedMesh = sharedMeshes[i]; + var meshId = sharedMesh.MeshID; + var index = meshes.IndexOf(meshId); + count[index] = sharedMesh.RefCount; + } + }).Schedule(Dependency); - var meshID = id.MeshID; - var index = meshes.IndexOf(meshID); + //Dependency = Entities + // .WithName("CountActiveMeshes") + // .WithAll().WithAll() + // .WithReadOnly(meshes) + // .WithNativeDisableParallelForRestriction(count) + // .ForEach((in MaterialMeshInfo id) => + // { + // var meshID = id.MeshID; - // For now assume every mesh is visible & active. + // if (meshID == BatchMeshID.Null) + // return; - unsafe - { - Interlocked.Increment(ref UnsafeUtility.ArrayElementAsRef(count.GetUnsafePtr(), index)); - } - }).ScheduleParallel(Dependency); + // var index = meshes.IndexOf(meshID); + + // // For now assume every mesh is visible & active. + + // unsafe + // { + // Interlocked.Increment(ref UnsafeUtility.ArrayElementAsRef(count.GetUnsafePtr(), index)); + // } + // }).ScheduleParallel(Dependency); k_CollectActiveMeshes.End(); k_OutputCountBuffer.Begin(); @@ -461,7 +495,6 @@ private void LayoutOutputBuffer() var vertexCountRef = m_MeshVertexCount; var shapeWeightCountRef = m_BlendShapeWeightCount; var skinMatrixCountRef = m_SkinMatrixCount; - var sharedMeshes = m_SharedMeshData; var batches = DeformationBatches; batches.Clear(); @@ -511,13 +544,18 @@ private void LayoutOutputBuffer() m_BatchConstructionHandle = Dependency; + var brgRenderMeshArrays = World.GetExistingSystemManaged()?.BRGRenderMeshArrays ?? new NativeParallelHashMap(); + var renderMeshArrayHandle = GetSharedComponentTypeHandle(); + Dependency = new LayoutDeformedMeshJob { DeformedMeshIndexHandle = GetComponentTypeHandle(), BlendWeightBufferIndexHandle = GetComponentTypeHandle(), SkinMatrixBufferIndexHandle = GetComponentTypeHandle(), + RenderMeshArrayHandle = renderMeshArrayHandle, MaterialMeshInfoHandle = GetComponentTypeHandle(), BatchData = DeformationBatches, + BRGRenderMeshArrays = brgRenderMeshArrays, SharedMeshData = m_SharedMeshData.AsArray(), MeshIDs = m_MeshIDs.AsArray(), MeshCounts = count, @@ -547,11 +585,13 @@ struct LayoutDeformedMeshJob : IJobChunk public ComponentTypeHandle BlendWeightBufferIndexHandle; public ComponentTypeHandle SkinMatrixBufferIndexHandle; + [ReadOnly] public SharedComponentTypeHandle RenderMeshArrayHandle; [ReadOnly] public ComponentTypeHandle MaterialMeshInfoHandle; [NativeDisableContainerSafetyRestriction] public NativeArray MeshCounts; [ReadOnly] public NativeParallelHashMap BatchData; + [ReadOnly] public NativeParallelHashMap BRGRenderMeshArrays; [ReadOnly] public NativeArray SharedMeshData; [ReadOnly] public NativeArray MeshIDs; #if ENABLE_DOTS_DEFORMATION_MOTION_VECTORS @@ -568,11 +608,27 @@ public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useE var skinMatrixIndices = chunk.GetNativeArray(ref SkinMatrixBufferIndexHandle); var meshInfos = chunk.GetNativeArray(ref MaterialMeshInfoHandle); + // If the chunk has a RenderMeshArray, get access to the corresponding registered + // Material and Mesh IDs + BRGRenderMeshArray brgRenderMeshArray = default; + if (!BRGRenderMeshArrays.IsEmpty) + { + int renderMeshArrayIndex = chunk.GetSharedComponentIndex(RenderMeshArrayHandle); + bool hasRenderMeshArray = renderMeshArrayIndex >= 0; + if (hasRenderMeshArray) + BRGRenderMeshArrays.TryGetValue(renderMeshArrayIndex, out brgRenderMeshArray); + } + for (int i = 0, chunkEntityCount = chunk.Count; i < chunkEntityCount; i++) { - var meshID = meshInfos[i].MeshID; + var materialMeshInfo = meshInfos[i]; + + var meshID = materialMeshInfo.IsRuntimeMesh + ? materialMeshInfo.MeshID + : brgRenderMeshArray.GetMeshID(materialMeshInfo); - Assert.IsFalse(meshID == BatchMeshID.Null); + if (meshID == BatchMeshID.Null) + continue; var batchRange = BatchData[meshID]; var meshIndex = MeshIDs.IndexOf(meshID); diff --git a/Unity.Entities.Graphics/Deformations/Systems/PushSkinMatrixSystem.cs b/Unity.Entities.Graphics/Deformations/Systems/PushSkinMatrixSystem.cs index e2c6491..6e12db1 100644 --- a/Unity.Entities.Graphics/Deformations/Systems/PushSkinMatrixSystem.cs +++ b/Unity.Entities.Graphics/Deformations/Systems/PushSkinMatrixSystem.cs @@ -36,6 +36,49 @@ protected override void OnCreate() ); } + [WithAll(typeof(SharedMeshTracker))] + partial struct ConstructHashMapJob : IJobEntity + { + public NativeParallelMultiHashMap.ParallelWriter DeformedEntityToComputeIndexParallel; + + private void Execute(in SkinMatrixBufferIndex index, in DeformedEntity deformedEntity) + { + // Skip if we have an invalid index. + if (index.Value == SkinMatrixBufferIndex.Null) + return; + + DeformedEntityToComputeIndexParallel.Add(deformedEntity.Value, index.Value); + } + } + + partial struct CopySkinMatricesToGPUJob : IJobEntity + { + [ReadOnly] public NativeParallelMultiHashMap DeformedEntityToComputeIndex; + [NativeDisableContainerSafetyRestriction] public NativeArray SkinMatricesBuffer; + + private void Execute(in DynamicBuffer skinMatrices, in Entity entity) + { + // Not all deformed entities in the world will have a renderer attached to them. + if (!DeformedEntityToComputeIndex.ContainsKey(entity)) + return; + + long length = (long)skinMatrices.Length * UnsafeUtility.SizeOf(); + var indices = DeformedEntityToComputeIndex.GetValuesForKey(entity); + + foreach (var index in indices) + { + unsafe + { + UnsafeUtility.MemCpy( + (float3x4*)SkinMatricesBuffer.GetUnsafePtr() + index, + skinMatrices.GetUnsafeReadOnlyPtr(), + length + ); + } + } + } + } + protected override void OnUpdate() { if (m_PushMeshDataSystem.SkinMatrixCount == 0) @@ -43,47 +86,19 @@ protected override void OnUpdate() k_Marker.Begin(); - var deformedEntityToComputeIndex = new NativeMultiHashMap(m_SkinningEntityQuery.CalculateEntityCount(), Allocator.TempJob); + var deformedEntityToComputeIndex = new NativeParallelMultiHashMap(m_SkinningEntityQuery.CalculateEntityCount(), Allocator.TempJob); var deformedEntityToComputeIndexParallel = deformedEntityToComputeIndex.AsParallelWriter(); - - Dependency = Entities - .WithName("ConstructHashMap") - .WithAll() - .ForEach((in SkinMatrixBufferIndex index, in DeformedEntity deformedEntity) => - { - // Skip if we have an invalid index. - if (index.Value == SkinMatrixBufferIndex.Null) - return; - - deformedEntityToComputeIndexParallel.Add(deformedEntity.Value, index.Value); - }).ScheduleParallel(Dependency); + Dependency = new ConstructHashMapJob + { + DeformedEntityToComputeIndexParallel = deformedEntityToComputeIndexParallel + }.ScheduleParallel(Dependency); var skinMatricesBuffer = m_PushMeshDataSystem.SkinningBufferManager.LockSkinMatrixBufferForWrite(m_PushMeshDataSystem.SkinMatrixCount); - Dependency = Entities - .WithName("CopySkinMatricesToGPU") - .WithNativeDisableContainerSafetyRestriction(skinMatricesBuffer) - .WithReadOnly(deformedEntityToComputeIndex) - .ForEach((ref DynamicBuffer skinMatrices, in Entity entity) => - { - // Not all deformed entities in the world will have a renderer attached to them. - if (!deformedEntityToComputeIndex.ContainsKey(entity)) - return; - - long length = (long)skinMatrices.Length * UnsafeUtility.SizeOf(); - var indices = deformedEntityToComputeIndex.GetValuesForKey(entity); - - foreach (var index in indices) - { - unsafe - { - UnsafeUtility.MemCpy( - (float3x4*)skinMatricesBuffer.GetUnsafePtr() + index, - skinMatrices.GetUnsafePtr(), - length - ); - } - } - }).ScheduleParallel(Dependency); + Dependency = new CopySkinMatricesToGPUJob() + { + DeformedEntityToComputeIndex = deformedEntityToComputeIndex, + SkinMatricesBuffer = skinMatricesBuffer + }.ScheduleParallel(Dependency); Dependency = deformedEntityToComputeIndex.Dispose(Dependency); diff --git a/Unity.Entities.Graphics/DrawCommandGeneration.cs b/Unity.Entities.Graphics/DrawCommandGeneration.cs index 30221cb..367f780 100644 --- a/Unity.Entities.Graphics/DrawCommandGeneration.cs +++ b/Unity.Entities.Graphics/DrawCommandGeneration.cs @@ -1,4 +1,3 @@ - using System; using System.Collections.Generic; using System.Runtime.InteropServices; @@ -778,8 +777,8 @@ public static unsafe JobHandle ScheduleWithIndirectList( IndirectList list, int innerLoopBatchCount = 1, JobHandle dependencies = default) - where T : struct, IJobParallelForDefer - where U : unmanaged + where T : struct, IJobParallelForDefer + where U : unmanaged { return jobData.Schedule(&list.List->m_length, innerLoopBatchCount, dependencies); } @@ -997,8 +996,8 @@ public void Execute(int index) { for (int i = index; i < ChunkDrawCommandOutput.NumThreads; i += NumThreads) { - DrawCommandOutput.ThreadLocalDrawCommands[i].Dispose(); - DrawCommandOutput.ThreadLocalCollectBuffers[i].Dispose(); + DrawCommandOutput.ThreadLocalDrawCommands[i].Dispose(); + DrawCommandOutput.ThreadLocalCollectBuffers[i].Dispose(); } } } @@ -1013,9 +1012,11 @@ internal unsafe struct EmitDrawCommandsJob : IJobParallelForDefer [ReadOnly] public ComponentTypeHandle LocalToWorld; [ReadOnly] public ComponentTypeHandle DepthSorted; [ReadOnly] public ComponentTypeHandle DeformedMeshIndex; + [ReadOnly] public SharedComponentTypeHandle RenderMeshArray; [ReadOnly] public SharedComponentTypeHandle RenderFilterSettings; [ReadOnly] public SharedComponentTypeHandle LightMaps; [ReadOnly] public NativeParallelHashMap FilterSettings; + [ReadOnly] public NativeParallelHashMap BRGRenderMeshArrays; public ChunkDrawCommandOutput DrawCommandOutput; @@ -1028,14 +1029,12 @@ internal unsafe struct EmitDrawCommandsJob : IJobParallelForDefer #if UNITY_EDITOR [ReadOnly] public SharedComponentTypeHandle EditorDataComponentHandle; - [ReadOnly] public NativeParallelHashMap BatchEditorData; #endif public void Execute(int index) { var visibilityItem = VisibilityItems.ElementAt(index); - var chunk = visibilityItem.Chunk; var chunkVisibility = visibilityItem.Visibility; @@ -1044,6 +1043,17 @@ public void Execute(int index) if (((1 << filterSettings.layer) & CullingLayerMask) == 0) return; + // If the chunk has a RenderMeshArray, get access to the corresponding registered + // Material and Mesh IDs + BRGRenderMeshArray brgRenderMeshArray = default; + if (!BRGRenderMeshArrays.IsEmpty) + { + int renderMeshArrayIndex = chunk.GetSharedComponentIndex(RenderMeshArray); + bool hasRenderMeshArray = renderMeshArrayIndex >= 0; + if (hasRenderMeshArray) + BRGRenderMeshArrays.TryGetValue(renderMeshArrayIndex, out brgRenderMeshArray); + } + DrawCommandOutput.InitializeForEmitThread(); { @@ -1108,9 +1118,17 @@ public void Execute(int index) var materialMeshInfo = materialMeshInfos[entityIndex]; + BatchMaterialID materialID = materialMeshInfo.IsRuntimeMaterial + ? materialMeshInfo.MaterialID + : brgRenderMeshArray.GetMaterialID(materialMeshInfo); + + BatchMeshID meshID = materialMeshInfo.IsRuntimeMesh + ? materialMeshInfo.MeshID + : brgRenderMeshArray.GetMeshID(materialMeshInfo); + // Null materials are handled internally by Unity using the error material if available. // Invalid meshes at this point will be skipped. - if (materialMeshInfo.Mesh <= 0) + if (meshID == BatchMeshID.Null) continue; bool flipWinding = (chunkCullingData.FlippedWinding[j] & entityMask) != 0; @@ -1119,8 +1137,8 @@ public void Execute(int index) { FilterIndex = filterIndex, BatchID = new BatchID { value = (uint)batchIndex }, - MaterialID = materialMeshInfo.MaterialID, - MeshID = materialMeshInfo.MeshID, + MaterialID = materialID, + MeshID = meshID, SplitMask = chunkVisibility->SplitMasks[entityIndex], SubmeshIndex = (ushort)materialMeshInfo.Submesh, Flags = 0 @@ -1155,18 +1173,13 @@ public void Execute(int index) private bool TestSceneCullingMask(ArchetypeChunk chunk) { #if UNITY_EDITOR - int editorRenderDataIndex = chunk.GetSharedComponentIndex(EditorDataComponentHandle); - // If we can't find a culling mask, use the default ulong chunkSceneCullingMask = EditorSceneManager.DefaultSceneCullingMask; - if (editorRenderDataIndex >= 0) + if (chunk.Has(EditorDataComponentHandle)) { - BatchEditorRenderData data; - if (BatchEditorData.TryGetValue(editorRenderDataIndex, out data)) - { - chunkSceneCullingMask = data.SceneCullingMask; - } + var editorRenderData = chunk.GetSharedComponent(EditorDataComponentHandle); + chunkSceneCullingMask = editorRenderData.SceneCullingMask; } // Cull the chunk if the scene mask intersection is empty. diff --git a/Unity.Entities.Graphics/EntitiesGraphicsConversion.cs b/Unity.Entities.Graphics/EntitiesGraphicsConversion.cs index f3b8cd0..6141ce0 100644 --- a/Unity.Entities.Graphics/EntitiesGraphicsConversion.cs +++ b/Unity.Entities.Graphics/EntitiesGraphicsConversion.cs @@ -125,13 +125,18 @@ class HDAdditionalLightDataCompanionBaker : Baker public override void Bake(HDAdditionalLightData authoring) { var light = GetComponent(); + // A disabled light component won't be added to the companion GameObject, + // other components that require the light component should not be added either. + if (light.enabled) + { #if UNITY_EDITOR - var isBaking = light.lightmapBakeType == LightmapBakeType.Baked; - if(!isBaking) - AddComponentObject(authoring); + var isBaking = light.lightmapBakeType == LightmapBakeType.Baked; + if(!isBaking) + AddComponentObject(authoring); #else - AddComponentObject(authoring); + AddComponentObject(authoring); #endif + } } } @@ -183,13 +188,19 @@ class UniversalAdditionalLightDataCompanionBaker : Baker(); + + // A disabled light component won't be added to the companion GameObject, + // other components that require the light component should not be added either. + if (light.enabled) + { #if UNITY_EDITOR - var isBaking = light.lightmapBakeType == LightmapBakeType.Baked; - if(!isBaking) - AddComponentObject(authoring); + var isBaking = light.lightmapBakeType == LightmapBakeType.Baked; + if (!isBaking) + AddComponentObject(authoring); #else AddComponentObject(authoring); #endif + } } } #endif diff --git a/Unity.Entities.Graphics/EntitiesGraphicsCulling.cs b/Unity.Entities.Graphics/EntitiesGraphicsCulling.cs index fb23a56..9ef7b4d 100644 --- a/Unity.Entities.Graphics/EntitiesGraphicsCulling.cs +++ b/Unity.Entities.Graphics/EntitiesGraphicsCulling.cs @@ -265,21 +265,53 @@ internal static NativeArray GetSubNativeArray(this UnsafeList list, int internal unsafe struct CullingSplits { - [ReadOnly] public UnsafeList BackfacingReceiverPlanes; - [ReadOnly] public UnsafeList SplitPlanePackets; - [ReadOnly] public UnsafeList ReceiverPlanePackets; - [ReadOnly] public UnsafeList CombinedSplitAndReceiverPlanePackets; - [ReadOnly] public UnsafeList Splits; - [ReadOnly] public SOASphereTest SplitSOASphereTest; + public UnsafeList BackfacingReceiverPlanes; + public UnsafeList SplitPlanePackets; + public UnsafeList ReceiverPlanePackets; + public UnsafeList CombinedSplitAndReceiverPlanePackets; + public UnsafeList Splits; + public SOASphereTest SplitSOASphereTest; public float3 LightAxisX; public float3 LightAxisY; public bool SphereTestEnabled; - public CullingSplits( - ref BatchCullingContext cullingContext, + public static CullingSplits Create(BatchCullingContext* cullingContext, ShadowProjection shadowProjection, AllocatorManager.AllocatorHandle allocator) + { + CullingSplits cullingSplits = default; + + var createJob = new CreateJob + { + cullingContext = cullingContext, + shadowProjection = shadowProjection, + allocator = allocator, + Splits = &cullingSplits + }; + createJob.Run(); + + return cullingSplits; + } + + [BurstCompile] + private struct CreateJob : IJob + { + [NativeDisableUnsafePtrRestriction] + [ReadOnly] public BatchCullingContext* cullingContext; + [ReadOnly] public ShadowProjection shadowProjection; + [ReadOnly] public AllocatorManager.AllocatorHandle allocator; + + [NativeDisableUnsafePtrRestriction] + public CullingSplits* Splits; + + public void Execute() + { + *Splits = new CullingSplits(ref *cullingContext, shadowProjection, allocator); + } + } + + private CullingSplits(ref BatchCullingContext cullingContext, ShadowProjection shadowProjection, - RewindableAllocator* allocator) + AllocatorManager.AllocatorHandle allocator) { BackfacingReceiverPlanes = default; SplitPlanePackets = default; @@ -292,13 +324,11 @@ public CullingSplits( LightAxisY = default; SphereTestEnabled = false; - var allocatorHandle = allocator->Handle; - // Initialize receiver planes first, so they are ready to be combined in // InitializeSplits - InitializeReceiverPlanes(ref cullingContext, allocatorHandle); - InitializeSplits(ref cullingContext, allocatorHandle); - InitializeSphereTest(ref cullingContext, shadowProjection, allocatorHandle); + InitializeReceiverPlanes(ref cullingContext, allocator); + InitializeSplits(ref cullingContext, allocator); + InitializeSphereTest(ref cullingContext, shadowProjection, allocator); } private void InitializeReceiverPlanes(ref BatchCullingContext cullingContext, AllocatorManager.AllocatorHandle allocator) @@ -403,10 +433,6 @@ private void InitializeSplits(ref BatchCullingContext cullingContext, AllocatorM int planeIndex = 0; int combinedPlaneIndex = 0; - // In the special case where there is only a single split with zero planes, compute culling planes - // based on the culling matrix. - bool noSplitPlanes = numSplits == 1 && cullingSplits[0].cullingPlaneCount == 0; - for (int i = 0; i < numSplits; ++i) { int splitIndex = i; @@ -423,9 +449,6 @@ private void InitializeSplits(ref BatchCullingContext cullingContext, AllocatorM var splitCullingPlanes = cullingPlanes.GetSubArray(s.cullingPlaneOffset, s.cullingPlaneCount); - if (noSplitPlanes) - splitCullingPlanes = CullingPlanesFromMatrix(s.cullingMatrix); - var planePackets = FrustumPlanes.BuildSOAPlanePackets( splitCullingPlanes, allocator); @@ -468,14 +491,6 @@ private void InitializeSplits(ref BatchCullingContext cullingContext, AllocatorM } } - private static Plane[] s_CullingPlanes = new Plane[6]; - private static NativeArray CullingPlanesFromMatrix(Matrix4x4 cullingMatrix) - { - GeometryUtility.CalculateFrustumPlanes(cullingMatrix, s_CullingPlanes); - var planeArray = new NativeArray(s_CullingPlanes, Allocator.Temp); - return planeArray; - } - private void InitializeSphereTest(ref BatchCullingContext cullingContext, ShadowProjection shadowProjection, AllocatorManager.AllocatorHandle allocator) { // Receiver sphere testing is only enabled if the cascade projection is stable diff --git a/Unity.Entities.Graphics/EntitiesGraphicsLightBakingDataSystem.cs b/Unity.Entities.Graphics/EntitiesGraphicsLightBakingDataSystem.cs index 76d5356..78acd04 100644 --- a/Unity.Entities.Graphics/EntitiesGraphicsLightBakingDataSystem.cs +++ b/Unity.Entities.Graphics/EntitiesGraphicsLightBakingDataSystem.cs @@ -1,3 +1,4 @@ +using Unity.Collections; using Unity.Entities; using UnityEngine; @@ -18,12 +19,6 @@ public struct LightBakingOutputData : IComponentData public LightBakingOutput Value; } - /// - /// A tag component that HybridLightBakingDataSystem uses to assign a LightBakingOutput to the bakingOutput of the Light component. - /// - public struct LightBakingOutputDataRestoredTag : IComponentData - {} - /// /// Represents a light baking system that assigns a LightBakingOutput to the bakingOutput of the Light component. /// @@ -31,21 +26,28 @@ public struct LightBakingOutputDataRestoredTag : IComponentData [UpdateInGroup(typeof(PresentationSystemGroup))] public partial class HybridLightBakingDataSystem : SystemBase { + private EntityQuery m_LightBakingQuery; + + protected override void OnCreate() + { + m_LightBakingQuery = SystemAPI.QueryBuilder() + .WithAll() + .Build(); + m_LightBakingQuery.SetChangedVersionFilter(ComponentType.ReadOnly()); + } + /// protected override void OnUpdate() { - Entities - .WithStructuralChanges() - .WithNone() - .ForEach((Entity e, in LightBakingOutputData bakingOutput) => - { - var light = EntityManager.GetComponentObject(e); - - if (light != null) - light.bakingOutput = bakingOutput.Value; + var entities = m_LightBakingQuery.ToEntityArray(Allocator.Temp); + foreach (var e in entities) + { + var bakingOutput = EntityManager.GetComponentData(e); + var light = EntityManager.GetComponentObject(e); - EntityManager.AddComponent(e); - }).Run(); + if (light != null) + light.bakingOutput = bakingOutput.Value; + } } } } diff --git a/Unity.Entities.Graphics/EntitiesGraphicsSystem.cs b/Unity.Entities.Graphics/EntitiesGraphicsSystem.cs index 0228e53..ee1115b 100644 --- a/Unity.Entities.Graphics/EntitiesGraphicsSystem.cs +++ b/Unity.Entities.Graphics/EntitiesGraphicsSystem.cs @@ -23,6 +23,7 @@ // #define PROFILE_BURST_JOB_INTERNALS // #define DISABLE_HYBRID_RENDERER_ERROR_LOADING_SHADER // #define DISABLE_INCLUDE_EXCLUDE_LIST_FILTERING +// #define DISABLE_MATERIALMESHINFO_BOUNDS_CHECKING // Entities Graphics is disabled if SRP 10 is not found, unless an override define is present // It is also disabled if -nographics is given from the command line. @@ -46,6 +47,10 @@ #define ENABLE_PICKING #endif +#if (ENABLE_UNITY_COLLECTIONS_CHECKS || DEVELOPMENT_BUILD) && !DISABLE_MATERIALMESHINFO_BOUNDS_CHECKING +#define ENABLE_MATERIALMESHINFO_BOUNDS_CHECKING +#endif + using System; using System.Collections.Generic; using System.Text; @@ -65,6 +70,11 @@ using UnityEngine.Profiling; using UnityEngine.Rendering; +#if URP_10_0_0_OR_NEWER && UNITY_EDITOR +using System.Reflection; +using UnityEngine.Rendering.Universal; +#endif + #if UNITY_EDITOR using UnityEditor; #endif @@ -75,13 +85,6 @@ namespace Unity.Rendering { -#if UNITY_EDITOR - internal struct BatchEditorRenderData - { - public ulong SceneCullingMask; - } -#endif - // Describes a single material property that can be mapped to an ECS type. // Contains the name as a string, unlike the other types. internal struct NamedPropertyMapping @@ -144,14 +147,36 @@ internal struct BRGRenderMeshArray public UnsafeList Materials; public UnsafeList Meshes; public uint4 Hash128; + + public BatchMaterialID GetMaterialID(MaterialMeshInfo materialMeshInfo) + { + int materialIndex = materialMeshInfo.MaterialArrayIndex; + + if (!Materials.IsCreated || materialIndex >= Materials.Length) + return BatchMaterialID.Null; + else + return Materials[materialIndex]; + } + + public BatchMeshID GetMeshID(MaterialMeshInfo materialMeshInfo) + { + int meshIndex = materialMeshInfo.MeshArrayIndex; + + if (!Meshes.IsCreated || meshIndex >= Meshes.Length) + return BatchMeshID.Null; + else + return Meshes[meshIndex]; + } } [BurstCompile] - internal struct RemapMaterialMeshIndexJob : IJobChunk + internal struct BoundsCheckMaterialMeshIndexJob : IJobChunk { [ReadOnly] public SharedComponentTypeHandle RenderMeshArrayHandle; - public ComponentTypeHandle MaterialMeshInfoHandle; [ReadOnly] public NativeParallelHashMap BRGRenderMeshArrays; + [ReadOnly] public ComponentTypeHandle MaterialMeshInfoHandle; + public EntityTypeHandle EntityHandle; + public NativeList.ParallelWriter EntitiesWithOutOfBoundsMMI; public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) { @@ -160,6 +185,7 @@ public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useE var sharedComponentIndex = chunk.GetSharedComponentIndex(RenderMeshArrayHandle); var materialMeshInfos = chunk.GetNativeArray(ref MaterialMeshInfoHandle); + var entities = chunk.GetNativeArray(EntityHandle); BRGRenderMeshArray brgRenderMeshArray; bool found = BRGRenderMeshArrays.TryGetValue(sharedComponentIndex, out brgRenderMeshArray); @@ -172,14 +198,16 @@ public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useE for (int i = 0, chunkEntityCount = chunk.Count; i < chunkEntityCount; i++) { var materialMeshInfo = materialMeshInfos[i]; + bool outOfBounds = false; if (!materialMeshInfo.IsRuntimeMaterial) - materialMeshInfo.Material = (int)materials[materialMeshInfo.MaterialArrayIndex].value; + outOfBounds = outOfBounds || materialMeshInfo.MaterialArrayIndex >= materials.Length; if (!materialMeshInfo.IsRuntimeMesh) - materialMeshInfo.Mesh = (int)meshes[materialMeshInfo.MeshArrayIndex].value; + outOfBounds = outOfBounds || materialMeshInfo.MeshArrayIndex >= meshes.Length; - materialMeshInfos[i] = materialMeshInfo; + if (outOfBounds) + EntitiesWithOutOfBoundsMMI.AddNoResize(entities[i]); } } } @@ -240,14 +268,11 @@ internal struct MaterialPropertyType /// /// A system that registers Materials and meshes with the BatchRendererGroup. /// - /// - /// Schedule any changes to materials and meshes before this system runs if you want automatic registration and conversion to runtime IDs. - /// After this system runs, all information on MaterialMeshInfo is assumed to be using runtime IDs only. - /// //@TODO: Updating always necessary due to empty component group. When Component group and archetype chunks are unified, [RequireMatchingQueriesForUpdate] can be added. [WorldSystemFilter(WorldSystemFilterFlags.Default | WorldSystemFilterFlags.Editor)] [UpdateInGroup(typeof(PresentationSystemGroup))] [UpdateBefore(typeof(EntitiesGraphicsSystem))] + [CreateAfter(typeof(EntitiesGraphicsSystem))] partial class RegisterMaterialsAndMeshesSystem : SystemBase { // Reuse Lists used for GetAllUniqueSharedComponentData to avoid GC allocs every frame @@ -256,10 +281,15 @@ partial class RegisterMaterialsAndMeshesSystem : SystemBase private List m_SharedComponentVersions = new List(); NativeParallelHashMap m_BRGRenderMeshArrays; + internal NativeParallelHashMap BRGRenderMeshArrays => m_BRGRenderMeshArrays; EntitiesGraphicsSystem m_RendererSystem; - private EntityQuery m_ChangedMaterialMeshQuery; +#if ENABLE_MATERIALMESHINFO_BOUNDS_CHECKING + private EntityQuery m_ChangedMaterialMeshQuery = default; + private NativeList m_EntitiesWithOutOfBoundsMMI; + private JobHandle m_BoundsCheckHandle = default; +#endif /// protected override void OnCreate() @@ -271,8 +301,9 @@ protected override void OnCreate() } m_BRGRenderMeshArrays = new NativeParallelHashMap(256, Allocator.Persistent); - m_RendererSystem = World.GetOrCreateSystemManaged(); + m_RendererSystem = World.GetExistingSystemManaged(); +#if ENABLE_MATERIALMESHINFO_BOUNDS_CHECKING m_ChangedMaterialMeshQuery = GetEntityQuery(new EntityQueryDesc { All = new[] @@ -283,6 +314,7 @@ protected override void OnCreate() Options = EntityQueryOptions.IncludeDisabledEntities, }); m_ChangedMaterialMeshQuery.SetChangedVersionFilter(ComponentType.ReadWrite()); +#endif } /// @@ -471,16 +503,97 @@ private JobHandle RegisterMaterialsAndMeshes(JobHandle inputDeps) brgRenderArray.Meshes.Dispose(); } +#if ENABLE_MATERIALMESHINFO_BOUNDS_CHECKING // Fire jobs to remap offline->runtime indices - var remapMaterialMeshIndexHandle = new RemapMaterialMeshIndexJob + m_EntitiesWithOutOfBoundsMMI = new NativeList( + m_ChangedMaterialMeshQuery.CalculateEntityCount(), + WorldUpdateAllocator); + m_BoundsCheckHandle = new BoundsCheckMaterialMeshIndexJob + { + RenderMeshArrayHandle = GetSharedComponentTypeHandle(), + MaterialMeshInfoHandle = GetComponentTypeHandle(true), + EntityHandle = GetEntityTypeHandle(), + BRGRenderMeshArrays = m_BRGRenderMeshArrays, + EntitiesWithOutOfBoundsMMI = m_EntitiesWithOutOfBoundsMMI.AsParallelWriter(), + } + .ScheduleParallel(m_ChangedMaterialMeshQuery, inputDeps); + + return m_BoundsCheckHandle; +#else + return default; +#endif + } + + internal void LogBoundsCheckErrorMessages() + { +#if ENABLE_MATERIALMESHINFO_BOUNDS_CHECKING + m_BoundsCheckHandle.Complete(); + + foreach (Entity e in m_EntitiesWithOutOfBoundsMMI) { - RenderMeshArrayHandle = GetSharedComponentTypeHandle(), - MaterialMeshInfoHandle = GetComponentTypeHandle(), - BRGRenderMeshArrays = m_BRGRenderMeshArrays, - } - .ScheduleParallel(m_ChangedMaterialMeshQuery, inputDeps); + if (!EntityManager.Exists(e)) + continue; + + var rma = EntityManager.GetSharedComponentManaged(e); + var mmi = EntityManager.GetComponentData(e); + + UnityEngine.Object authoring = null; +#if UNITY_EDITOR + authoring = EntityManager.Debug.GetAuthoringObjectForEntity(e); +#endif + int numMeshes = rma.Meshes?.Length ?? 0; + int numMaterials = rma.Materials?.Length ?? 0; - return remapMaterialMeshIndexHandle; + bool meshValid = mmi.IsRuntimeMesh || mmi.MeshArrayIndex < numMeshes; + bool materialValid = mmi.IsRuntimeMaterial || mmi.MaterialArrayIndex < numMaterials; + + string meshMsg; + string materialMsg; + + if (meshValid) + { + if (mmi.IsRuntimeMesh) + { + meshMsg = $"MeshID: {mmi.Mesh} (runtime registered)"; + } + else + { + Mesh mesh = rma.GetMesh(mmi); + meshMsg = $"MeshID: {mmi.Mesh} (array index: {mmi.MeshArrayIndex}, \"{mesh}\")"; + } + } + else + { + meshMsg = $"MeshID: {mmi.Mesh} (invalid out of bounds array index: {mmi.MeshArrayIndex})"; + } + + if (materialValid) + { + if (mmi.IsRuntimeMaterial) + { + materialMsg = $"MaterialID: {mmi.Material} (runtime registered)"; + } + else + { + Material material = rma.GetMaterial(mmi); + materialMsg = $"MaterialID: {mmi.Material} (array index: {mmi.MaterialArrayIndex}, \"{material}\")"; + } + } + else + { + materialMsg = + $"MaterialID: {mmi.Material} (invalid out of bounds array index: {mmi.MaterialArrayIndex})"; + } + + string entityDebugString = authoring is null + ? e.ToString() + : authoring.ToString(); + + Debug.LogError( + $"Entity \"{entityDebugString}\" has an invalid out of bounds index to a Mesh or Material, and will not render correctly at runtime. {meshMsg}. Number of Meshes in RenderMeshArray: {numMeshes}. {materialMsg}. Number of Materials in RenderMeshArray: {numMaterials}.", + authoring); + } +#endif } } @@ -557,10 +670,6 @@ public unsafe partial class EntitiesGraphicsSystem : SystemBase private HeapAllocator m_GPUPersistentAllocator; private HeapBlock m_SharedZeroAllocation; - private GraphicsBuffer m_GlobalValuesCbuffer; - private BatchRendererGroupGlobals m_GlobalValues; - private bool m_GlobalValuesDirty; - private HeapAllocator m_ChunkMetadataAllocator; private NativeList m_BatchInfos; @@ -622,6 +731,34 @@ private void ComputeStats() Profiler.EndSample(); } +#if URP_10_0_0_OR_NEWER + private void ValidateUsingURPForwardPlus() + { + // If using URP, display and warning indicating that Forward+ is the preferred rendering mode + RenderPipelineAsset pipelineAsset = GraphicsSettings.renderPipelineAsset; + if (pipelineAsset is UniversalRenderPipelineAsset) + { + UniversalRenderPipelineAsset settings = pipelineAsset as UniversalRenderPipelineAsset; + var rendererDataListField = typeof(UniversalRenderPipelineAsset).GetField("m_RendererDataList", BindingFlags.NonPublic | BindingFlags.Instance); + var defaultRendererIndexField = typeof(UniversalRenderPipelineAsset).GetField("m_DefaultRendererIndex", BindingFlags.NonPublic | BindingFlags.Instance); + if (rendererDataListField != null && defaultRendererIndexField != null) + { + ScriptableRendererData[] rendererDatas = rendererDataListField.GetValue(settings) as ScriptableRendererData[]; + int defaultRendererDataIndex = (int)defaultRendererIndexField.GetValue(settings); + UniversalRendererData universalRendererData = rendererDatas[defaultRendererDataIndex] as UniversalRendererData; + var renderingModeField = typeof(UniversalRendererData).GetField("m_RenderingMode", BindingFlags.NonPublic | BindingFlags.Instance); + if (renderingModeField != null) + { + RenderingMode renderingMode = (RenderingMode)renderingModeField.GetValue(universalRendererData); + if (renderingMode != RenderingMode.ForwardPlus) + { + Debug.LogWarning("Entities.Graphics should be used with URP Forward+. Change Rendering Path on " + universalRendererData.name + " for best compatibility."); + } + } + } + } + } +#endif #endif private bool m_ResetLod; @@ -630,7 +767,7 @@ private void ComputeStats() float3 m_PrevCameraPos; float m_PrevLodDistanceScale; - NativeMultiHashMap m_NameIDToMaterialProperties; + NativeParallelMultiHashMap m_NameIDToMaterialProperties; NativeParallelHashMap m_TypeIndexToMaterialProperty; static Dictionary s_TypeToPropertyMappings = new Dictionary(); @@ -650,10 +787,6 @@ private void ComputeStats() // Burst accessible filter settings for each RenderFilterSettings shared component index private NativeParallelHashMap m_FilterSettings; -#if UNITY_EDITOR - private List m_EditorRenderDatas = new List(); - private NativeParallelHashMap m_BatchEditorDatas; -#endif #if ENABLE_PICKING Material m_PickingMaterial; @@ -679,6 +812,11 @@ protected override void OnCreate() return; } + +#if URP_10_0_0_OR_NEWER && UNITY_EDITOR + ValidateUsingURPForwardPlus(); +#endif + m_FirstFrameAfterInit = true; m_PersistentInstanceDataSize = kGPUBufferSizeInitial; @@ -774,15 +912,12 @@ protected override void OnCreate() #endif // Collect all components with [MaterialProperty] attribute - m_NameIDToMaterialProperties = new NativeMultiHashMap(256, Allocator.Persistent); + m_NameIDToMaterialProperties = new NativeParallelMultiHashMap(256, Allocator.Persistent); m_TypeIndexToMaterialProperty = new NativeParallelHashMap(256, Allocator.Persistent); m_GraphicsArchetypes = new EntitiesGraphicsArchetypes(256); m_FilterSettings = new NativeParallelHashMap(256, Allocator.Persistent); -#if UNITY_EDITOR - m_BatchEditorDatas = new NativeParallelHashMap(256, Allocator.Persistent); -#endif // Some hardcoded mappings to avoid dependencies to Hybrid from DOTS #if SRP_10_0_0_OR_NEWER @@ -797,9 +932,6 @@ protected override void OnCreate() RegisterMaterialPropertyType(typeof(Entity), "unity_EntityId"); #endif - m_GlobalValues = BatchRendererGroupGlobals.Default; - m_GlobalValuesDirty = true; - foreach (var typeInfo in TypeManager.AllTypes) { var type = typeInfo.Type; @@ -825,11 +957,6 @@ protected override void OnCreate() m_GPUPersistentInstanceBufferHandle = m_GPUPersistentInstanceData.bufferHandle; - m_GlobalValuesCbuffer = new GraphicsBuffer( - GraphicsBuffer.Target.Constant, - 1, - UnsafeUtility.SizeOf()); - m_GPUUploader = new SparseUploader(m_GPUPersistentInstanceData, kGPUUploaderChunkSize); #if USE_UNITY_OCCLUSION @@ -977,8 +1104,7 @@ private JobHandle UpdateEntitiesGraphicsBatches(JobHandle inputDependencies) { JobHandle done = default; Profiler.BeginSample("UpdateAllBatches"); - using (var entitiesGraphicsChunks = - m_EntitiesGraphicsRenderedQuery.ToArchetypeChunkArray(Allocator.TempJob)) + if (m_EntitiesGraphicsRenderedQuery.CalculateChunkCount() > 0) { done = UpdateAllBatches(inputDependencies); } @@ -1037,34 +1163,6 @@ private static BatchFilterSettings MakeFilterSettings(RenderFilterSettings filte }; } - private JobHandle UpdateSceneCullingMasks(JobHandle inputDeps) - { -#if UNITY_EDITOR - m_EditorRenderDatas.Clear(); - m_SharedComponentIndices.Clear(); - - // TODO: Maybe this could be partially jobified? - - EntityManager.GetAllUniqueSharedComponentsManaged(m_EditorRenderDatas, m_SharedComponentIndices); - - m_BatchEditorDatas.Clear(); - for (int i = 0; i < m_SharedComponentIndices.Count; ++i) - { - int sharedIndex = m_SharedComponentIndices[i]; - var editorData = m_EditorRenderDatas[i]; - - var batchData = new BatchEditorRenderData(); - batchData.SceneCullingMask = editorData.SceneCullingMask; - - m_BatchEditorDatas[sharedIndex] = batchData; - } - - m_EditorRenderDatas.Clear(); - m_SharedComponentIndices.Clear(); -#endif - return new JobHandle(); - } - /// protected override void OnUpdate() { @@ -1100,16 +1198,6 @@ protected override void OnUpdate() inputDeps = JobHandle.CombineDependencies(inputDeps, updateFilterSettingsHandle); -#if UNITY_EDITOR - Profiler.BeginSample("UpdateSceneCullingMasks"); - var updateSceneCullingMasks = UpdateSceneCullingMasks(inputDeps); - Profiler.EndSample(); - - inputDeps = JobHandle.CombineDependencies(inputDeps, updateSceneCullingMasks); -#endif - - UpdateSpecCubeHDRDecode(ReflectionProbe.defaultTextureHDRDecodeValues); - var done = new JobHandle(); try { @@ -1174,7 +1262,6 @@ private void Dispose() { m_GPUUploader.Dispose(); m_GPUPersistentInstanceData.Dispose(); - m_GlobalValuesCbuffer.Dispose(); #if UNITY_EDITOR Memory.Unmanaged.Free(m_PerThreadStats, Allocator.Persistent); @@ -1216,9 +1303,6 @@ private void Dispose() m_GraphicsArchetypes.Dispose(); m_FilterSettings.Dispose(); -#if UNITY_EDITOR - m_BatchEditorDatas.Dispose(); -#endif m_CullingJobReleaseDependency.Complete(); m_ThreadLocalAllocators.Dispose(); } @@ -1358,7 +1442,7 @@ private JobHandle OnPerformCulling(BatchRendererGroup rendererGroup, BatchCullin var frustumCullingJob = new FrustumCullingJob { - Splits = new CullingSplits(ref cullingContext, QualitySettings.shadowProjection, m_ThreadLocalAllocators.GeneralAllocator), + Splits = CullingSplits.Create(&cullingContext, QualitySettings.shadowProjection, m_ThreadLocalAllocators.GeneralAllocator->Handle), CullingViewType = cullingContext.viewType, EntitiesGraphicsChunkInfo = GetComponentTypeHandle(true), ChunkWorldRenderBounds = GetComponentTypeHandle(true), @@ -1392,6 +1476,12 @@ private JobHandle OnPerformCulling(BatchRendererGroup rendererGroup, BatchCullin m_ThreadLocalAllocators, cullingOutput); + // To be able to access the material/mesh IDs, we need access to the registered material/mesh + // arrays. If we can't get them, then we simply skip in those cases. + var brgRenderMeshArrays = + World.GetExistingSystemManaged()?.BRGRenderMeshArrays + ?? new NativeParallelHashMap(); + var emitDrawCommandsJob = new EmitDrawCommandsJob { VisibilityItems = visibilityItems, @@ -1404,9 +1494,10 @@ private JobHandle OnPerformCulling(BatchRendererGroup rendererGroup, BatchCullin FilterSettings = m_FilterSettings, CullingLayerMask = cullingContext.cullingLayerMask, LightMaps = GetSharedComponentTypeHandle(), + RenderMeshArray = GetSharedComponentTypeHandle(), + BRGRenderMeshArrays = brgRenderMeshArrays, #if UNITY_EDITOR EditorDataComponentHandle = GetSharedComponentTypeHandle(), - BatchEditorData = m_BatchEditorDatas, #endif DrawCommandOutput = chunkDrawCommandOutput, SceneCullingMask = cullingContext.sceneCullingMask, @@ -1608,13 +1699,13 @@ private JobHandle UpdateAllBatches(JobHandle inputDependencies) NativeArrayOptions.UninitializedMemory); var classifyNewChunksJob = new ClassifyNewChunksJob - { - EntitiesGraphicsChunkInfo = entitiesGraphicsRenderedChunkTypeRO, - ChunkHeader = chunkHeadersRO, - NumNewChunks = numNewChunksArray, - NewChunks = newChunks - } - .ScheduleParallel(m_MetaEntitiesForHybridRenderableChunksQuery, inputDependencies); + { + EntitiesGraphicsChunkInfo = entitiesGraphicsRenderedChunkTypeRO, + ChunkHeader = chunkHeadersRO, + NumNewChunks = numNewChunksArray, + NewChunks = newChunks + } + .ScheduleParallel(m_MetaEntitiesForHybridRenderableChunksQuery, inputDependencies); JobHandle entitiesGraphicsCompleted = new JobHandle(); @@ -1752,10 +1843,6 @@ private JobHandle UpdateAllBatches(JobHandle inputDependencies) int numGpuUploadOperations = numGpuUploadOperationsArray[0]; Debug.Assert(numGpuUploadOperations <= gpuUploadOperations.Length, "Maximum GPU upload operation count exceeded"); - Profiler.BeginSample("BlitDirtyGlobalValues"); - BlitDirtyGlobalValues(); - Profiler.EndSample(); - ComputeUploadSizeRequirements( numGpuUploadOperations, gpuUploadOperations, out int numOperations, out int totalUploadBytes, out int biggestUploadBytes); @@ -1800,18 +1887,6 @@ private JobHandle UpdateAllBatches(JobHandle inputDependencies) return outputDeps; } - private static BatchRendererGroupGlobals[] s_GlobalsArray = new BatchRendererGroupGlobals[1] { default }; - private void BlitDirtyGlobalValues() - { - if (m_GlobalValuesDirty) - { - // SetData needs an array, so put the data in a helper array - s_GlobalsArray[0] = m_GlobalValues; - m_GlobalValuesCbuffer.SetData(s_GlobalsArray); - m_GlobalValuesDirty = false; - } - } - private void UpdateGlobalAABB(NativeArray threadLocalAABBs) { MinMaxAABB aabb = MinMaxAABB.Empty; @@ -1919,7 +1994,7 @@ static void CreateBatchCreateInfo( ref NativeArray newChunks, ref NativeArray sortedNewChunks, out MaterialPropertyType failureProperty - ) + ) { failureProperty = default; failureProperty.TypeIndex = -1; @@ -2030,7 +2105,7 @@ internal static MetadataValue CreateMetadataValue(int nameID, int gpuAddress, bo { NameID = nameID, Value = (uint) gpuAddress - | (isOverridden ? kPerInstanceDataBit : 0), + | (isOverridden ? kPerInstanceDataBit : 0), }; } @@ -2315,13 +2390,6 @@ private void EndUpdate() { m_GPUUploader.EndAndCommit(m_ThreadedGPUUploader); - // Globally bind the BRG globals cbuffer so all shaders can access it. - Shader.SetGlobalConstantBuffer( - BatchRendererGroupGlobals.kGlobalsPropertyId, - m_GlobalValuesCbuffer, - 0, - m_GlobalValuesCbuffer.stride); - #if DEBUG_LOG_MEMORY_USAGE if (m_GPUPersistentAllocator.UsedSpace != PrevUsedSpace) { @@ -2329,6 +2397,10 @@ private void EndUpdate() PrevUsedSpace = m_GPUPersistentAllocator.UsedSpace; } #endif + +#if ENABLE_MATERIALMESHINFO_BOUNDS_CHECKING + World.GetExistingSystemManaged()?.LogBoundsCheckErrorMessages(); +#endif } internal static NativeList NewNativeListResized(int length, Allocator allocator, NativeArrayOptions resizeOptions = NativeArrayOptions.ClearMemory) where T : unmanaged @@ -2339,35 +2411,6 @@ internal static NativeList NewNativeListResized(int length, Allocator allo return list; } - internal void UpdateSpecCubeHDRDecode(Vector4 specCubeHDRDecode) - { - if (!Enabled) return; - - bool hdrDecodeDirty = specCubeHDRDecode != m_GlobalValues.SpecCube0_HDR; - if (hdrDecodeDirty) - { - m_GlobalValues.SpecCube0_HDR = specCubeHDRDecode; - m_GlobalValues.SpecCube1_HDR = specCubeHDRDecode; - m_GlobalValuesDirty = true; - } - } - - internal void UpdateGlobalAmbientProbe(SHCoefficients globalAmbientProbe) - { - if (!Enabled) return; - - bool globalAmbientProbeDirty = globalAmbientProbe != m_GlobalValues.SHCoefficients; - if (globalAmbientProbeDirty) - { - m_GlobalValues.SHCoefficients = globalAmbientProbe; - m_GlobalValuesDirty = true; - -#if DEBUG_LOG_AMBIENT_PROBE - Debug.Log($"Global Ambient probe: {globalAmbientProbe.SHAr} {globalAmbientProbe.SHAg} {globalAmbientProbe.SHAb} {globalAmbientProbe.SHBr} {globalAmbientProbe.SHBg} {globalAmbientProbe.SHBb} {globalAmbientProbe.SHC}"); -#endif - } - } - /// /// Registers a material with the Entities Graphics System. /// @@ -2394,8 +2437,19 @@ internal void UpdateGlobalAmbientProbe(SHCoefficients globalAmbientProbe) /// A mesh ID received from . public void UnregisterMesh(BatchMeshID mesh) => m_BatchRendererGroup.UnregisterMesh(mesh); - internal Mesh GetMesh(BatchMeshID mesh) => m_BatchRendererGroup.GetRegisteredMesh(mesh); - internal Material GetMaterial(BatchMaterialID material) => m_BatchRendererGroup.GetRegisteredMaterial(material); + /// + /// Returns the that corresponds to the given registered mesh ID, or null if no such mesh exists. + /// + /// A mesh ID received from . + /// The object corresponding to the given mesh ID if the ID is valid, or null if it's not valid. + public Mesh GetMesh(BatchMeshID mesh) => m_BatchRendererGroup.GetRegisteredMesh(mesh); + + /// + /// Returns the that corresponds to the given registered material ID, or null if no such material exists. + /// + /// A material ID received from . + /// The object corresponding to the given material ID if the ID is valid, or null if it's not valid. + public Material GetMaterial(BatchMaterialID material) => m_BatchRendererGroup.GetRegisteredMaterial(material); /// /// Converts a type index into a type name. @@ -2447,3 +2501,4 @@ internal static string NameIDFormatted(int nameID) } } } + diff --git a/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyAORemapMaxAuthoring.cs b/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyAORemapMaxAuthoring.cs index 61c080d..f46d5ba 100644 --- a/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyAORemapMaxAuthoring.cs +++ b/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyAORemapMaxAuthoring.cs @@ -9,7 +9,7 @@ public struct HDRPMaterialPropertyAORemapMax : IComponentData { public float Va [UnityEngine.DisallowMultipleComponent] public class HDRPMaterialPropertyAORemapMaxAuthoring : UnityEngine.MonoBehaviour { - [RegisterBinding(typeof(HDRPMaterialPropertyAORemapMax), "Value")] + [RegisterBinding(typeof(HDRPMaterialPropertyAORemapMax), nameof(HDRPMaterialPropertyAORemapMax.Value))] public float Value; class HDRPMaterialPropertyAORemapMaxBaker : Baker diff --git a/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyAORemapMinAuthoring.cs b/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyAORemapMinAuthoring.cs index dc5b405..e285831 100644 --- a/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyAORemapMinAuthoring.cs +++ b/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyAORemapMinAuthoring.cs @@ -9,7 +9,7 @@ public struct HDRPMaterialPropertyAORemapMin : IComponentData { public float Va [UnityEngine.DisallowMultipleComponent] public class HDRPMaterialPropertyAORemapMinAuthoring : UnityEngine.MonoBehaviour { - [RegisterBinding(typeof(HDRPMaterialPropertyAORemapMin), "Value")] + [RegisterBinding(typeof(HDRPMaterialPropertyAORemapMin), nameof(HDRPMaterialPropertyAORemapMin.Value))] public float Value; class HDRPMaterialPropertyAORemapMinBaker : Baker diff --git a/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyAlphaCutoffAuthoring.cs b/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyAlphaCutoffAuthoring.cs index 0040912..b57568d 100644 --- a/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyAlphaCutoffAuthoring.cs +++ b/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyAlphaCutoffAuthoring.cs @@ -9,7 +9,7 @@ public struct HDRPMaterialPropertyAlphaCutoff : IComponentData { public float V [UnityEngine.DisallowMultipleComponent] public class HDRPMaterialPropertyAlphaCutoffAuthoring : UnityEngine.MonoBehaviour { - [RegisterBinding(typeof(HDRPMaterialPropertyAlphaCutoff), "Value")] + [RegisterBinding(typeof(HDRPMaterialPropertyAlphaCutoff), nameof(HDRPMaterialPropertyAlphaCutoff.Value))] public float Value; class HDRPMaterialPropertyAlphaCutoffBaker : Baker diff --git a/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyBaseColorAuthoring.cs b/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyBaseColorAuthoring.cs index f98d3b1..4833280 100644 --- a/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyBaseColorAuthoring.cs +++ b/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyBaseColorAuthoring.cs @@ -10,10 +10,7 @@ public struct HDRPMaterialPropertyBaseColor : IComponentData { public float4 Val [UnityEngine.DisallowMultipleComponent] public class HDRPMaterialPropertyBaseColorAuthoring : UnityEngine.MonoBehaviour { - [RegisterBinding(typeof(HDRPMaterialPropertyBaseColor), "Value.x", true)] - [RegisterBinding(typeof(HDRPMaterialPropertyBaseColor), "Value.y", true)] - [RegisterBinding(typeof(HDRPMaterialPropertyBaseColor), "Value.z", true)] - [RegisterBinding(typeof(HDRPMaterialPropertyBaseColor), "Value.w", true)] + [RegisterBinding(typeof(HDRPMaterialPropertyBaseColor), nameof(HDRPMaterialPropertyBaseColor.Value))] public float4 Value; class HDRPMaterialPropertyBaseColorBaker : Baker diff --git a/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyMetallicAuthoring.cs b/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyMetallicAuthoring.cs index f90d8ac..0df9c14 100644 --- a/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyMetallicAuthoring.cs +++ b/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyMetallicAuthoring.cs @@ -9,7 +9,7 @@ public struct HDRPMaterialPropertyMetallic : IComponentData { public float Valu [UnityEngine.DisallowMultipleComponent] public class HDRPMaterialPropertyMetallicAuthoring : UnityEngine.MonoBehaviour { - [RegisterBinding(typeof(HDRPMaterialPropertyMetallic), "Value")] + [RegisterBinding(typeof(HDRPMaterialPropertyMetallic), nameof(HDRPMaterialPropertyMetallic.Value))] public float Value; class HDRPMaterialPropertyMetallicBaker : Baker diff --git a/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertySmoothnessAuthoring.cs b/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertySmoothnessAuthoring.cs index 5fb7f37..14bf4df 100644 --- a/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertySmoothnessAuthoring.cs +++ b/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertySmoothnessAuthoring.cs @@ -9,7 +9,7 @@ public struct HDRPMaterialPropertySmoothness : IComponentData { public float Va [UnityEngine.DisallowMultipleComponent] public class HDRPMaterialPropertySmoothnessAuthoring : UnityEngine.MonoBehaviour { - [RegisterBinding(typeof(HDRPMaterialPropertySmoothness), "Value")] + [RegisterBinding(typeof(HDRPMaterialPropertySmoothness), nameof(HDRPMaterialPropertySmoothness.Value))] public float Value; class HDRPMaterialPropertySmoothnessBaker : Baker diff --git a/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyThicknessAuthoring.cs b/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyThicknessAuthoring.cs index 7197511..c10dd15 100644 --- a/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyThicknessAuthoring.cs +++ b/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyThicknessAuthoring.cs @@ -9,7 +9,7 @@ public struct HDRPMaterialPropertyThickness : IComponentData { public float Val [UnityEngine.DisallowMultipleComponent] public class HDRPMaterialPropertyThicknessAuthoring : UnityEngine.MonoBehaviour { - [RegisterBinding(typeof(HDRPMaterialPropertyThickness), "Value")] + [RegisterBinding(typeof(HDRPMaterialPropertyThickness), nameof(HDRPMaterialPropertyThickness.Value))] public float Value; class HDRPMaterialPropertyThicknessBaker : Baker diff --git a/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyUnlitColorAuthoring.cs b/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyUnlitColorAuthoring.cs index c41b790..b5fa841 100644 --- a/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyUnlitColorAuthoring.cs +++ b/Unity.Entities.Graphics/HDRPMaterialProperties/HDRPMaterialPropertyUnlitColorAuthoring.cs @@ -10,10 +10,7 @@ public struct HDRPMaterialPropertyUnlitColor : IComponentData { public float4 Va [UnityEngine.DisallowMultipleComponent] public class HDRPMaterialPropertyUnlitColorAuthoring : UnityEngine.MonoBehaviour { - [RegisterBinding(typeof(HDRPMaterialPropertyUnlitColor), "Value.x", true)] - [RegisterBinding(typeof(HDRPMaterialPropertyUnlitColor), "Value.y", true)] - [RegisterBinding(typeof(HDRPMaterialPropertyUnlitColor), "Value.z", true)] - [RegisterBinding(typeof(HDRPMaterialPropertyUnlitColor), "Value.w", true)] + [RegisterBinding(typeof(HDRPMaterialPropertyUnlitColor), nameof(HDRPMaterialPropertyUnlitColor.Value))] public float4 Value; class HDRPMaterialPropertyUnlitColorBaker : Baker diff --git a/Unity.Entities.Graphics/MeshRendererBaking.cs b/Unity.Entities.Graphics/MeshRendererBaking.cs index c10d1b6..5e0444b 100644 --- a/Unity.Entities.Graphics/MeshRendererBaking.cs +++ b/Unity.Entities.Graphics/MeshRendererBaking.cs @@ -8,7 +8,6 @@ namespace Unity.Rendering { - [TemporaryBakingType] struct MeshRendererBakingData : IComponentData { @@ -37,6 +36,8 @@ public override void Bake(MeshRenderer authoring) MeshRendererBakingUtility.Convert(this, authoring, mesh, sharedMaterials, true, out var additionalEntities); + DependsOnLightBaking(); + if(additionalEntities.Count == 0) AddComponent(new MeshRendererBakingData{ MeshRenderer = authoring }); @@ -109,40 +110,35 @@ protected override void OnUpdate() if (m_LightMapBakingContext != null) { - Entities.ForEach((in MeshRendererBakingData authoring) => + foreach (var authoring in SystemAPI.Query>() + .WithOptions(EntityQueryOptions.IncludePrefab | EntityQueryOptions.IncludeDisabledEntities)) { - context.CollectLightMapUsage(authoring.MeshRenderer); - }) - .WithEntityQueryOptions(EntityQueryOptions.IncludePrefab | EntityQueryOptions.IncludeDisabledEntities) - .WithoutBurst() - .WithStructuralChanges() - .Run(); + context.CollectLightMapUsage(authoring.ValueRO.MeshRenderer); + } } context.ProcessLightMapsForConversion(); var ecb = new EntityCommandBuffer(Allocator.TempJob); - Entities.ForEach((Entity entity, RenderMesh renderMesh, in MeshRendererBakingData authoring) => + foreach (var (renderMesh, authoring, entity) in SystemAPI.Query>() + .WithEntityAccess() + .WithOptions(EntityQueryOptions.IncludePrefab | EntityQueryOptions.IncludeDisabledEntities)) { - Renderer renderer = authoring.MeshRenderer; + Renderer renderer = authoring.ValueRO.MeshRenderer; + var sharedComponentRenderMesh = renderMesh; var lightmappedMaterial = context.ConfigureHybridLightMapping( entity, ecb, renderer, - renderMesh.material); + sharedComponentRenderMesh.material); if (lightmappedMaterial != null) { - renderMesh.material = lightmappedMaterial; - ecb.SetSharedComponentManaged(entity, renderMesh); + sharedComponentRenderMesh.material = lightmappedMaterial; + ecb.SetSharedComponentManaged(entity, sharedComponentRenderMesh); } - - }) - .WithEntityQueryOptions(EntityQueryOptions.IncludePrefab | EntityQueryOptions.IncludeDisabledEntities) - .WithoutBurst() - .WithStructuralChanges() - .Run(); + } context.EndConversion(); @@ -244,6 +240,8 @@ protected override void OnUpdate() Renderer authoring = null; if (EntityManager.HasComponent(e)) authoring = EntityManager.GetComponentData(e).MeshRenderer.Value; + else if (EntityManager.HasComponent(e)) + authoring = EntityManager.GetComponentData(e).SkinnedMeshRenderer.Value; string entityDebugString = authoring is null ? e.ToString() diff --git a/Unity.Entities.Graphics/MeshRendererBakingUtility.cs b/Unity.Entities.Graphics/MeshRendererBakingUtility.cs index fb2852d..0d03cee 100644 --- a/Unity.Entities.Graphics/MeshRendererBakingUtility.cs +++ b/Unity.Entities.Graphics/MeshRendererBakingUtility.cs @@ -141,8 +141,6 @@ static void ConvertToSingleEntity( var lodComponent = new MeshLODComponent { Group = lodState.LodGroupEntity, LODMask = 1 << lodState.LodGroupIndex }; baker.AddComponent(entity, lodComponent); } - - baker.ConfigureEditorRenderData(entity, renderer.gameObject, true); } internal static void ConvertToMultipleEntities( @@ -209,8 +207,6 @@ internal static void ConvertToMultipleEntities( var lodComponent = new MeshLODComponent { Group = lodState.LodGroupEntity, LODMask = 1 << lodState.LodGroupIndex }; baker.AddComponent(meshEntity, lodComponent); } - - baker.ConfigureEditorRenderData(meshEntity, renderer.gameObject, true); } } } diff --git a/Unity.Entities.Graphics/Occlusion/Masked/BufferGroup.cs b/Unity.Entities.Graphics/Occlusion/Masked/BufferGroup.cs index c6f74a8..dbd7457 100644 --- a/Unity.Entities.Graphics/Occlusion/Masked/BufferGroup.cs +++ b/Unity.Entities.Graphics/Occlusion/Masked/BufferGroup.cs @@ -165,7 +165,8 @@ public void RenderToTextures(EntityQuery testQuery, EntityQuery meshQuery, JobHa return; } - if (m_DebugView == null) + bool refresh = (m_DebugView == null); + if (refresh) { m_DebugView = new DebugView(); } @@ -177,6 +178,11 @@ public void RenderToTextures(EntityQuery testQuery, EntityQuery meshQuery, JobHa Profiler.BeginSample("Occlusion.Debug.RenderView"); m_DebugView.RenderToTextures(testQuery, meshQuery, this, mode, OcclusionBrowseWindow.IsVisible); Profiler.EndSample(); + + if (refresh) + { + OcclusionBrowseWindow.Refresh(); + } #endif } diff --git a/Unity.Entities.Graphics/Occlusion/UI/OcclusionBrowserView.cs b/Unity.Entities.Graphics/Occlusion/UI/OcclusionBrowserView.cs index a6b57c9..3879dff 100644 --- a/Unity.Entities.Graphics/Occlusion/UI/OcclusionBrowserView.cs +++ b/Unity.Entities.Graphics/Occlusion/UI/OcclusionBrowserView.cs @@ -159,6 +159,11 @@ private void OnMouseMoveEvent(MouseMoveEvent evt) var bg = BufferGroups[currentSelection]; var tex = bg.GetVisualizationTexture(); + if (tex == null) + { + return; + } + float2 pos = evt.localMousePosition; pos.x /= viewData.localBound.width; pos.y /= viewData.localBound.height; @@ -207,6 +212,12 @@ private void OnGenerateVisualContent(MeshGenerationContext mgc) vertices[2].tint = vertices[3].tint = Color.white; + if (CurrentSliceTexture == null) + { + mgc.DrawText("Inactive view", new Vector2(5, 5), 12, Color.white); + return; + } + MeshWriteData mwd = mgc.Allocate(vertices.Length, indices.Length, CurrentSliceTexture); // Since the texture may be stored in an atlas, the UV coordinates need to be diff --git a/Unity.Entities.Graphics/Occlusion/UI/OcclusionBrowserView.uxml b/Unity.Entities.Graphics/Occlusion/UI/OcclusionBrowserView.uxml index db64794..09be82a 100644 --- a/Unity.Entities.Graphics/Occlusion/UI/OcclusionBrowserView.uxml +++ b/Unity.Entities.Graphics/Occlusion/UI/OcclusionBrowserView.uxml @@ -10,7 +10,7 @@ - + diff --git a/Unity.Entities.Graphics/Occlusion/UnityOcclusion.cs b/Unity.Entities.Graphics/Occlusion/UnityOcclusion.cs index fbd0721..b0b0ce1 100644 --- a/Unity.Entities.Graphics/Occlusion/UnityOcclusion.cs +++ b/Unity.Entities.Graphics/Occlusion/UnityOcclusion.cs @@ -414,6 +414,14 @@ internal void UpdateSettings(OcclusionView occlusionView) } else { +#if UNITY_EDITOR + if (bufferGroup.NumPixelsX != occlusionView.OcclusionBufferWidth || + bufferGroup.NumPixelsY != occlusionView.OcclusionBufferHeight) + { + OcclusionBrowseWindow.Refresh(); + } +#endif + bufferGroup.SetResolutionAndClip( (int)occlusionView.OcclusionBufferWidth, (int)occlusionView.OcclusionBufferHeight, diff --git a/Unity.Entities.Graphics/Probes/LightProbeUpdateSystem.cs b/Unity.Entities.Graphics/Probes/LightProbeUpdateSystem.cs index e19b50d..0586984 100644 --- a/Unity.Entities.Graphics/Probes/LightProbeUpdateSystem.cs +++ b/Unity.Entities.Graphics/Probes/LightProbeUpdateSystem.cs @@ -41,23 +41,10 @@ internal static bool IsValidLightProbeGrid() /// protected override void OnUpdate() { - var ambientProbe = RenderSettings.ambientProbe; - if (IsValidLightProbeGrid()) { UpdateEntitiesFromGrid(); } - - // Update the global ambient probe. If there is no valid grid, BlendProbeTag - // entities will have their SH components deleted and will also fall back - // to this. - UpdateGlobalAmbientProbe(ambientProbe); - } - - private void UpdateGlobalAmbientProbe(SphericalHarmonicsL2 ambientProbe) - { - var entitiesGraphicsSystem = World.GetExistingSystemManaged(); - entitiesGraphicsSystem?.UpdateGlobalAmbientProbe(new SHCoefficients(ambientProbe)); } private static void UpdateEntitiesFromAmbientProbe( diff --git a/Unity.Entities.Graphics/SkinnedMeshRendererBaking.cs b/Unity.Entities.Graphics/SkinnedMeshRendererBaking.cs index fa6540b..2d4f0da 100644 --- a/Unity.Entities.Graphics/SkinnedMeshRendererBaking.cs +++ b/Unity.Entities.Graphics/SkinnedMeshRendererBaking.cs @@ -88,6 +88,7 @@ public override void Bake(SkinnedMeshRenderer authoring) var skinMatrices = AddBuffer(deformedEntity); skinMatrices.ResizeUninitialized(bones.Length); + var bindposes = mesh.GetBindposes(); for (int i = 0; i < bones.Length; ++i) { @@ -99,7 +100,7 @@ public override void Bake(SkinnedMeshRenderer authoring) Assert.IsTrue(i < authoring.sharedMesh.bindposeCount, $"No corresponding bindpose found for the bone ({bones[i].name}) at index {i}."); - var bindPose = mesh.bindposes[i]; + var bindPose = bindposes[i]; var boneMatRootSpace = math.mul(rootMatrixInv, bones[i].localToWorldMatrix); var skinMatRootSpace = math.mul(boneMatRootSpace, bindPose); skinMatrices[i] = new SkinMatrix diff --git a/Unity.Entities.Graphics/SparseUploader.cs b/Unity.Entities.Graphics/SparseUploader.cs index c0f9a01..47f21c7 100644 --- a/Unity.Entities.Graphics/SparseUploader.cs +++ b/Unity.Entities.Graphics/SparseUploader.cs @@ -582,7 +582,12 @@ internal static int NumFramesInFlight case GraphicsDeviceType.GameCoreXboxOne: case GraphicsDeviceType.GameCoreXboxSeries: case GraphicsDeviceType.OpenGLCore: + + // OpenGL ES 2.0 is no longer supported in Unity 2023.1 and later +#if !UNITY_2023_1_OR_NEWER case GraphicsDeviceType.OpenGLES2: +#endif + case GraphicsDeviceType.OpenGLES3: case GraphicsDeviceType.PlayStation5NGGC: numFrames = 3; @@ -744,7 +749,9 @@ public void EndAndCommit(ThreadedSparseUploader tsu) m_FrameData.Add(frameData); - m_MappedBuffers.Dispose(); + if (m_MappedBuffers.IsCreated) + m_MappedBuffers.Dispose(); + StepFrame(); } diff --git a/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertyBaseColorAuthoring.cs b/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertyBaseColorAuthoring.cs index 6bb519f..fb43e72 100644 --- a/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertyBaseColorAuthoring.cs +++ b/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertyBaseColorAuthoring.cs @@ -13,18 +13,20 @@ public struct URPMaterialPropertyBaseColor : IComponentData [UnityEngine.DisallowMultipleComponent] public class URPMaterialPropertyBaseColorAuthoring : UnityEngine.MonoBehaviour { - [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertyBaseColor), "Value.x", true)] - [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertyBaseColor), "Value.y", true)] - [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertyBaseColor), "Value.z", true)] - [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertyBaseColor), "Value.w", true)] - public Unity.Mathematics.float4 Value; + [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertyBaseColor), nameof(URPMaterialPropertyBaseColor.Value))] + public UnityEngine.Color color; class URPMaterialPropertyBaseColorBaker : Unity.Entities.Baker { public override void Bake(URPMaterialPropertyBaseColorAuthoring authoring) { Unity.Rendering.URPMaterialPropertyBaseColor component = default(Unity.Rendering.URPMaterialPropertyBaseColor); - component.Value = authoring.Value; + float4 colorValues; + colorValues.x = authoring.color.linear.r; + colorValues.y = authoring.color.linear.g; + colorValues.z = authoring.color.linear.b; + colorValues.w = authoring.color.linear.a; + component.Value = colorValues; AddComponent(component); } } diff --git a/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertyBumpScaleAuthoring.cs b/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertyBumpScaleAuthoring.cs index 41709b8..6b25576 100644 --- a/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertyBumpScaleAuthoring.cs +++ b/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertyBumpScaleAuthoring.cs @@ -12,7 +12,7 @@ public struct URPMaterialPropertyBumpScale : IComponentData [UnityEngine.DisallowMultipleComponent] public class URPMaterialPropertyBumpScaleAuthoring : UnityEngine.MonoBehaviour { - [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertyBumpScale), "Value")] + [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertyBumpScale), nameof(URPMaterialPropertyBumpScale.Value))] public float Value; class URPMaterialPropertyBumpScaleBaker : Unity.Entities.Baker diff --git a/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertyCutoffAuthoring.cs b/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertyCutoffAuthoring.cs index 38fadbd..d76446e 100644 --- a/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertyCutoffAuthoring.cs +++ b/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertyCutoffAuthoring.cs @@ -12,7 +12,8 @@ public struct URPMaterialPropertyCutoff : IComponentData [UnityEngine.DisallowMultipleComponent] public class URPMaterialPropertyCutoffAuthoring : UnityEngine.MonoBehaviour { - [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertyCutoff), "Value")] + [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertyCutoff), nameof(URPMaterialPropertyCutoff.Value))] + [UnityEngine.Range(0,1)] public float Value; class URPMaterialPropertyCutoffBaker : Unity.Entities.Baker diff --git a/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertyEmissionColorAuthoring.cs b/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertyEmissionColorAuthoring.cs index a7357ce..7b02d87 100644 --- a/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertyEmissionColorAuthoring.cs +++ b/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertyEmissionColorAuthoring.cs @@ -1,6 +1,7 @@ #if URP_10_0_0_OR_NEWER using Unity.Entities; using Unity.Mathematics; +using UnityEngine; namespace Unity.Rendering { @@ -13,18 +14,21 @@ public struct URPMaterialPropertyEmissionColor : IComponentData [UnityEngine.DisallowMultipleComponent] public class URPMaterialPropertyEmissionColorAuthoring : UnityEngine.MonoBehaviour { - [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertyEmissionColor), "Value.x", true)] - [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertyEmissionColor), "Value.y", true)] - [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertyEmissionColor), "Value.z", true)] - [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertyEmissionColor), "Value.w", true)] - public Unity.Mathematics.float4 Value; + [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertyEmissionColor), nameof(URPMaterialPropertyEmissionColor.Value))] + [ColorUsage(true, true)] + public UnityEngine.Color color; class URPMaterialPropertyEmissionColorBaker : Unity.Entities.Baker { public override void Bake(URPMaterialPropertyEmissionColorAuthoring authoring) { Unity.Rendering.URPMaterialPropertyEmissionColor component = default(Unity.Rendering.URPMaterialPropertyEmissionColor); - component.Value = authoring.Value; + float4 colorValues; + colorValues.x = authoring.color.r; + colorValues.y = authoring.color.g; + colorValues.z = authoring.color.b; + colorValues.w = authoring.color.a; + component.Value = colorValues; AddComponent(component); } } diff --git a/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertyMetallicAuthoring.cs b/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertyMetallicAuthoring.cs index 6c0069a..103411c 100644 --- a/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertyMetallicAuthoring.cs +++ b/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertyMetallicAuthoring.cs @@ -12,7 +12,8 @@ public struct URPMaterialPropertyMetallic : IComponentData [UnityEngine.DisallowMultipleComponent] public class URPMaterialPropertyMetallicAuthoring : UnityEngine.MonoBehaviour { - [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertyMetallic), "Value")] + [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertyMetallic), nameof(URPMaterialPropertyMetallic.Value))] + [UnityEngine.Range(0,1)] public float Value; class URPMaterialPropertyMetallicBaker : Unity.Entities.Baker diff --git a/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertySmoothnessAuthoring.cs b/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertySmoothnessAuthoring.cs index fbb6dea..9d0faf0 100644 --- a/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertySmoothnessAuthoring.cs +++ b/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertySmoothnessAuthoring.cs @@ -12,7 +12,8 @@ public struct URPMaterialPropertySmoothness : IComponentData [UnityEngine.DisallowMultipleComponent] public class URPMaterialPropertySmoothnessAuthoring : UnityEngine.MonoBehaviour { - [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertySmoothness), "Value")] + [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertySmoothness), nameof(URPMaterialPropertySmoothness.Value))] + [UnityEngine.Range(0,1)] public float Value; class URPMaterialPropertySmoothnessBaker : Unity.Entities.Baker diff --git a/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertySpecColorAuthoring.cs b/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertySpecColorAuthoring.cs index 9412cba..dcbb92a 100644 --- a/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertySpecColorAuthoring.cs +++ b/Unity.Entities.Graphics/URPMaterialProperties/URPMaterialPropertySpecColorAuthoring.cs @@ -13,18 +13,20 @@ public struct URPMaterialPropertySpecColor : IComponentData [UnityEngine.DisallowMultipleComponent] public class URPMaterialPropertySpecColorAuthoring : UnityEngine.MonoBehaviour { - [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertySpecColor), "Value.x", true)] - [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertySpecColor), "Value.y", true)] - [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertySpecColor), "Value.z", true)] - [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertySpecColor), "Value.w", true)] - public Unity.Mathematics.float4 Value; + [Unity.Entities.RegisterBinding(typeof(URPMaterialPropertySpecColor), nameof(URPMaterialPropertySpecColor.Value))] + public UnityEngine.Color color; class URPMaterialPropertySpecColorBaker : Unity.Entities.Baker { public override void Bake(URPMaterialPropertySpecColorAuthoring authoring) { Unity.Rendering.URPMaterialPropertySpecColor component = default(Unity.Rendering.URPMaterialPropertySpecColor); - component.Value = authoring.Value; + float4 colorValues; + colorValues.x = authoring.color.linear.r; + colorValues.y = authoring.color.linear.g; + colorValues.z = authoring.color.linear.b; + colorValues.w = authoring.color.linear.a; + component.Value = colorValues; AddComponent(component); } } diff --git a/package.json b/package.json index e605144..abef83d 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,14 @@ { "name": "com.unity.entities.graphics", "displayName": "Entities Graphics", - "version": "1.0.0-pre.15", + "version": "1.0.0-pre.44", "unity": "2022.2", - "unityRelease": "0f1", + "unityRelease": "2f1", "description": "The Entities Graphics package provides systems and components for drawing meshes using DOTS, including support for instanced mesh rendering and LOD.", "dependencies": { - "com.unity.entities": "1.0.0-pre.15", + "com.unity.entities": "1.0.0-pre.44", "com.unity.modules.particlesystem": "1.0.0", - "com.unity.render-pipelines.core": "14.0.3" + "com.unity.render-pipelines.core": "14.0.6" }, "keywords": [ "dots", @@ -16,12 +16,16 @@ "rendering", "unity" ], + "_upm": { + "changelog": "### Added\n\n* Optimize OnPerformCulling by computing the CullingSplits from a main thread Burst job.\n* EntitiesGraphicsSystem.GetMesh and EntitiesGraphicsSystem.GetMaterial are now public.\n* Warning in-editor when using Entities.Graphics and URP that Forward+ rendering path should be used.\n\n### Changed\n\n* Removed async readback from deformations and replaced with fixed number of frames.\n* The built-in properties for URP has been changed so that they have a slider for most values between 0-1. Relevant properties have also been changed from using a float4 for color in the inspector to use a color property instead.\n* `PushBlendWeightSystem.cs`, `PushSkinMatrixSystem.cs`, `MeshRendererBaking.cs` script files have been updated to the latest idiomatic `foreach()`.\n* Changed skin matrix / blend shape weight access in CopyBlendShapeWeightsToGPUJob and CopySkinMatricesToGPUJob to readonly.\n* Improved `SkinnedMeshRenderer` baking performance\n* Updated com.unity.render-pipelines.core dependency from 14.0.4 to 14.0.6\n\n### Removed\n\n * Removed RemapMaterialMeshIndexJob. Both array indices and runtime IDs are now directly supported for MaterialMeshInfo.\n\n### Fixed\n\n* Occlusion browser not being updated properly in play mode.\n* Only call UpdateAllBatches if there are entities graphics chunks\n* Fixed a bug with Baked Lights inside subscenes, where the bakingOutput of such Lights was not updated correctly.\n* Fixed global ambient probe when multiple cameras are present with HDRP\n* Light baking will cause the MeshRenderers to bake, thus automatically updating the light map in the entities scene. This previously required forcing the reimport of the entity scene.\n* 'GraphicsDeviceType.OpenGLES2' is obsolete: 'OpenGL ES 2.0 is no longer supported in Unity 2023.1'" + }, "upmCi": { - "footprint": "570c3cbc27016e27affe6689bd55ea9265069836" + "footprint": "36cf9c3e9000b35de661843f4e4d150f99fbca3c" }, + "documentationUrl": "https://docs.unity3d.com/Packages/com.unity.entities.graphics@1.0/manual/index.html", "repository": { "url": "https://github.cds.internal.unity3d.com/unity/dots.git", "type": "git", - "revision": "82387d7cb4bc4aee07e94656ef8103860ef6ec55" + "revision": "0e572178431e16c09c6c434c873bf0c60e52a5e9" } }