|
@@ -3,6 +3,7 @@ using Unity.Collections;
|
|
|
using Unity.Mathematics;
|
|
|
using UnityEngine;
|
|
|
using UnityEngine.Rendering;
|
|
|
+using Utility;
|
|
|
|
|
|
namespace Core.BRG
|
|
|
{
|
|
@@ -20,6 +21,8 @@ namespace Core.BRG
|
|
|
|
|
|
private List<BatchShaderBind> m_batchShaderBinds = new List<BatchShaderBind>();
|
|
|
|
|
|
+ private Map<string, BatchShaderBind> m_batchShaderBindMap = new Map<string, BatchShaderBind>();
|
|
|
+
|
|
|
public void InitRender(BRGSamples samples, List<T> gameObjectInfos)
|
|
|
{
|
|
|
this.m_gameObjectInfos = gameObjectInfos;
|
|
@@ -29,23 +32,29 @@ namespace Core.BRG
|
|
|
UploadGpuData(gameObjectInfos.Count);
|
|
|
}
|
|
|
|
|
|
- protected override NativeArray<MetadataValue> ProInitBatchMetadata(int startOffset,int m_maxInstancePerWindow)
|
|
|
+ protected override NativeArray<MetadataValue> ProInitBatchMetadata(int startOffset, int m_maxInstancePerWindow)
|
|
|
{
|
|
|
NativeArray<MetadataValue> metadataValues =
|
|
|
- new NativeArray<MetadataValue>(m_samples.AllShaderValues.Count,Allocator.Temp, NativeArrayOptions.UninitializedMemory);
|
|
|
+ new NativeArray<MetadataValue>(m_samples.AllShaderValues.Count, Allocator.Temp,
|
|
|
+ NativeArrayOptions.UninitializedMemory);
|
|
|
m_batchShaderBinds.Clear();
|
|
|
- int count= m_gameObjectInfos.Count;
|
|
|
+ // int count= m_maxInstancePerWindow;
|
|
|
for (int i = 0; i < m_samples.AllShaderValues.Count; i++)
|
|
|
{
|
|
|
- // BRGShaderValue shaderValue = m_samples.AllShaderValues[i];
|
|
|
- // int shaderId = Shader.PropertyToID(shaderValue.);
|
|
|
- // BatchShaderBind batchShaderBind = new BatchShaderBind();
|
|
|
- // batchMetadata[0] = CreateMetadataValue(objectToWorldID, 0, true);
|
|
|
+ BRGShaderValue shaderValue = m_samples.AllShaderValues[i];
|
|
|
+ int shaderId = Shader.PropertyToID(shaderValue.key);
|
|
|
+ BatchShaderBind batchShaderBind = new BatchShaderBind();
|
|
|
+ metadataValues[i] = CreateMetadataValue(shaderId, startOffset, true);
|
|
|
+ batchShaderBind.shaderValue = shaderValue;
|
|
|
+ batchShaderBind.offset = startOffset;
|
|
|
+ batchShaderBind.InitBuffer(m_maxInstancePerWindow);
|
|
|
+ startOffset += shaderValue.GetSize() * m_maxInstancePerWindow;
|
|
|
+ m_batchShaderBinds.Add(batchShaderBind);
|
|
|
+ m_batchShaderBindMap.Add(shaderValue.key, batchShaderBind);
|
|
|
}
|
|
|
- return base.ProInitBatchMetadata(startOffset,m_maxInstancePerWindow);
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
+ return metadataValues;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
public void UpdatePos()
|
|
@@ -68,6 +77,7 @@ namespace Core.BRG
|
|
|
}
|
|
|
|
|
|
int m_itemCount = m_gameObjectInfos.Count;
|
|
|
+ m_batchShaderBindMap.TryGetValue("_MainColor", out var baseColorBind);
|
|
|
for (int i = 0; i < m_gameObjectInfos.Count; i++)
|
|
|
{
|
|
|
BGRGameObjectInfo info = m_gameObjectInfos[i];
|
|
@@ -86,10 +96,14 @@ namespace Core.BRG
|
|
|
inverse.c0.xyz, inverse.c1.xyz,
|
|
|
inverse.c2.xyz, inverse.c3.xyz
|
|
|
);
|
|
|
+ if (baseColorBind != null)
|
|
|
+ {
|
|
|
+ baseColorBind.SetData(i, info.color);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 每帧更新后重新上传数据到GPU
|
|
|
- UploadTransformData(m_itemCount);
|
|
|
+ UploadGpuData(m_itemCount, m_batchShaderBinds);
|
|
|
}
|
|
|
}
|
|
|
}
|