diff --git a/Runtime/HairInstance.cs b/Runtime/HairInstance.cs index aacd518..9026574 100644 --- a/Runtime/HairInstance.cs +++ b/Runtime/HairInstance.cs @@ -1689,14 +1689,17 @@ namespace Unity.DemoTeam.Hair using (var alignedRootDirection = new NativeArray(strandGroupAsset.strandCount, Allocator.Temp, NativeArrayOptions.ClearMemory)) using (var alignedParticlePosition = new NativeArray(strandGroupParticleCount, Allocator.Temp, NativeArrayOptions.ClearMemory)) + using (var alignedParticleDiameter = new NativeArray(strandGroupParticleCount, Allocator.Temp, NativeArrayOptions.ClearMemory)) { unsafe { fixed (void* rootDirectionPtr = strandGroupAsset.rootDirection) fixed (void* particlePositionPtr = strandGroupAsset.particlePosition) + fixed (void* particleDiameterPtr = strandGroupAsset.particleDiameter) { UnsafeUtility.MemCpyStride(alignedRootDirection.GetUnsafePtr(), sizeof(Vector4), rootDirectionPtr, sizeof(Vector3), sizeof(Vector3), strandGroupAsset.strandCount); UnsafeUtility.MemCpyStride(alignedParticlePosition.GetUnsafePtr(), sizeof(Vector4), particlePositionPtr, sizeof(Vector3), sizeof(Vector3), strandGroupParticleCount); + UnsafeUtility.MemCpyStride(alignedParticleDiameter.GetUnsafePtr(), sizeof(float), particleDiameterPtr, sizeof(float), sizeof(float), strandGroupParticleCount); } } @@ -1709,6 +1712,7 @@ namespace Unity.DemoTeam.Hair uploadCtx.SetData(solverData[i].initialRootDirection, alignedRootDirection); uploadCtx.SetData(solverData[i].particlePosition, alignedParticlePosition); + uploadCtx.SetData(solverData[i].particleDiameter, alignedParticleDiameter); uploadCtx.SetData(solverData[i].lodGuideCount, strandGroupAsset.lodGuideCount); uploadCtx.SetData(solverData[i].lodGuideIndex, strandGroupAsset.lodGuideIndex); diff --git a/Runtime/HairSim.cs b/Runtime/HairSim.cs index 71644e5..6b20fc2 100644 --- a/Runtime/HairSim.cs +++ b/Runtime/HairSim.cs @@ -108,6 +108,7 @@ namespace Unity.DemoTeam.Hair public static int _ParticlePositionCorr; public static int _ParticleVelocity; public static int _ParticleVelocityPrev; + public static int _ParticleDiameter; public static int _LODGuideCount; public static int _LODGuideIndex; @@ -704,7 +705,8 @@ namespace Unity.DemoTeam.Hair changed |= CreateBuffer(ref solverData.particlePositionPrevPrev, "ParticlePosition_2", (Conf.SECOND_ORDER_UPDATE != 0) ? particleCount : 1, particleStrideVector4); changed |= CreateBuffer(ref solverData.particleVelocity, "ParticleVelocity_0", particleCount, particleStrideVector4); changed |= CreateBuffer(ref solverData.particleVelocityPrev, "ParticleVelocity_1", (Conf.SECOND_ORDER_UPDATE != 0) ? particleCount : 1, particleStrideVector4); - + changed |= CreateBuffer(ref solverData.particleDiameter, "ParticleDiameter", particleCount, particleStrideScalar); + changed |= CreateBuffer(ref solverData.lodGuideCount, "LODGuideCount", Mathf.Max(1, lodCount), particleStrideIndex); changed |= CreateBuffer(ref solverData.lodGuideIndex, "LODGuideIndex", Mathf.Max(1, lodCount) * strandCount, particleStrideIndex); changed |= CreateBuffer(ref solverData.lodGuideCarry, "LODGuideCarry", Mathf.Max(1, lodCount) * strandCount, particleStrideScalar); @@ -819,6 +821,7 @@ namespace Unity.DemoTeam.Hair ReleaseBuffer(ref solverData.particlePositionCorr); ReleaseBuffer(ref solverData.particleVelocity); ReleaseBuffer(ref solverData.particleVelocityPrev); + ReleaseBuffer(ref solverData.particleDiameter); ReleaseBuffer(ref solverData.lodGuideCount); ReleaseBuffer(ref solverData.lodGuideIndex); @@ -906,6 +909,7 @@ namespace Unity.DemoTeam.Hair target.BindComputeBuffer(UniformIDs._ParticlePositionCorr, solverData.particlePositionCorr); target.BindComputeBuffer(UniformIDs._ParticleVelocity, solverData.particleVelocity); target.BindComputeBuffer(UniformIDs._ParticleVelocityPrev, solverData.particleVelocityPrev); + target.BindComputeBuffer(UniformIDs._ParticleDiameter, solverData.particleDiameter); target.BindComputeBuffer(UniformIDs._LODGuideCount, solverData.lodGuideCount); target.BindComputeBuffer(UniformIDs._LODGuideIndex, solverData.lodGuideIndex); diff --git a/Runtime/HairSimData.cs b/Runtime/HairSimData.cs index 8c722b2..2fd70f6 100644 --- a/Runtime/HairSimData.cs +++ b/Runtime/HairSimData.cs @@ -38,7 +38,8 @@ namespace Unity.DemoTeam.Hair public ComputeBuffer particlePositionCorr; // xyz: ftl correction, w: - public ComputeBuffer particleVelocity; // xyz: velocity, w: splatting weight public ComputeBuffer particleVelocityPrev; // xyz: velocity, w: splatting weight - + public ComputeBuffer particleDiameter; // x: diameter (mm) + public ComputeBuffer lodGuideCount; // n: lod index -> num. guides public ComputeBuffer lodGuideIndex; // i: lod index * strand count + strand index -> guide index public ComputeBuffer lodGuideCarry; // f: lod index * strand count + strand index -> guide carry