修改水
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
public class ComputeParticleCollisionConstraints : ComputeConstraintsImpl<ComputeParticleCollisionConstraintsBatch>
|
||||
{
|
||||
public ComputeShader constraintsShader;
|
||||
public int initializeKernel;
|
||||
public int projectKernel;
|
||||
public int applyKernel;
|
||||
|
||||
public ComputeParticleCollisionConstraints(ComputeSolverImpl solver) : base(solver, Oni.ConstraintType.ParticleCollision)
|
||||
{
|
||||
constraintsShader = GameObject.Instantiate(Resources.Load<ComputeShader>("Compute/ParticleCollisionConstraints"));
|
||||
initializeKernel = constraintsShader.FindKernel("Initialize");
|
||||
projectKernel = constraintsShader.FindKernel("Project");
|
||||
applyKernel = constraintsShader.FindKernel("Apply");
|
||||
}
|
||||
|
||||
public override IConstraintsBatchImpl CreateConstraintsBatch()
|
||||
{
|
||||
var dataBatch = new ComputeParticleCollisionConstraintsBatch(this);
|
||||
batches.Add(dataBatch);
|
||||
return dataBatch;
|
||||
}
|
||||
|
||||
public override void RemoveBatch(IConstraintsBatchImpl batch)
|
||||
{
|
||||
batches.Remove(batch as ComputeParticleCollisionConstraintsBatch);
|
||||
batch.Destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0039bc61ce4bc4aaa952b7bf1463c8b5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,112 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
public class ComputeParticleCollisionConstraintsBatch : ComputeConstraintsBatchImpl, IParticleCollisionConstraintsBatchImpl
|
||||
{
|
||||
|
||||
public ComputeParticleCollisionConstraintsBatch(ComputeParticleCollisionConstraints constraints)
|
||||
{
|
||||
m_Constraints = constraints;
|
||||
m_ConstraintType = Oni.ConstraintType.ParticleCollision;
|
||||
}
|
||||
|
||||
public override void Initialize(float stepTime, float substepTime, int steps, float timeLeft)
|
||||
{
|
||||
var shader = ((ComputeParticleCollisionConstraints)m_Constraints).constraintsShader;
|
||||
int initializeKernel = ((ComputeParticleCollisionConstraints)m_Constraints).initializeKernel;
|
||||
|
||||
if (solverImplementation.simplexCounts.simplexCount > 0)
|
||||
{
|
||||
shader.SetInt("pointCount", solverAbstraction.simplexCounts.pointCount);
|
||||
shader.SetInt("edgeCount", solverAbstraction.simplexCounts.edgeCount);
|
||||
shader.SetInt("triangleCount", solverAbstraction.simplexCounts.triangleCount);
|
||||
shader.SetFloat("shockPropagation", solverAbstraction.parameters.shockPropagation);
|
||||
shader.SetVector("gravity", solverAbstraction.parameters.gravity);
|
||||
|
||||
shader.SetBuffer(initializeKernel, "simplices", this.solverImplementation.simplices);
|
||||
shader.SetBuffer(initializeKernel, "particleContacts", solverAbstraction.particleContacts.computeBuffer);
|
||||
shader.SetBuffer(initializeKernel, "effectiveMasses", solverAbstraction.particleContactEffectiveMasses.computeBuffer);
|
||||
shader.SetBuffer(initializeKernel, "dispatchBuffer", this.solverImplementation.particleGrid.dispatchBuffer);
|
||||
shader.SetBuffer(initializeKernel, "collisionMaterials", this.solverImplementation.colliderGrid.materialsBuffer);
|
||||
|
||||
shader.SetBuffer(initializeKernel, "positions", solverImplementation.positionsBuffer);
|
||||
shader.SetBuffer(initializeKernel, "prevPositions", solverImplementation.prevPositionsBuffer);
|
||||
shader.SetBuffer(initializeKernel, "orientations", solverImplementation.orientationsBuffer);
|
||||
shader.SetBuffer(initializeKernel, "prevOrientations", solverImplementation.prevOrientationsBuffer);
|
||||
shader.SetBuffer(initializeKernel, "principalRadii", solverImplementation.principalRadiiBuffer);
|
||||
shader.SetBuffer(initializeKernel, "velocities", solverImplementation.velocitiesBuffer);
|
||||
shader.SetBuffer(initializeKernel, "positionConstraintCounts", solverImplementation.positionConstraintCountBuffer);
|
||||
shader.SetBuffer(initializeKernel, "collisionMaterialIndices", solverImplementation.collisionMaterialIndexBuffer);
|
||||
shader.SetBuffer(initializeKernel, "deltasAsInt", solverImplementation.positionDeltasIntBuffer);
|
||||
shader.SetBuffer(initializeKernel, "invMasses", solverImplementation.invMassesBuffer);
|
||||
shader.SetBuffer(initializeKernel, "invRotationalMasses", solverImplementation.invMassesBuffer);
|
||||
|
||||
shader.SetFloat("substepTime", substepTime);
|
||||
|
||||
shader.DispatchIndirect(initializeKernel, this.solverImplementation.particleGrid.dispatchBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Evaluate(float stepTime, float substepTime, int steps, float timeLeft)
|
||||
{
|
||||
if (solverImplementation.simplexCounts.simplexCount > 0)
|
||||
{
|
||||
var shader = ((ComputeParticleCollisionConstraints)m_Constraints).constraintsShader;
|
||||
int projectKernel = ((ComputeParticleCollisionConstraints)m_Constraints).projectKernel;
|
||||
|
||||
shader.SetBuffer(projectKernel, "particleContacts", solverAbstraction.particleContacts.computeBuffer);
|
||||
shader.SetBuffer(projectKernel, "effectiveMasses", solverAbstraction.particleContactEffectiveMasses.computeBuffer);
|
||||
shader.SetBuffer(projectKernel, "dispatchBuffer", this.solverImplementation.particleGrid.dispatchBuffer);
|
||||
shader.SetBuffer(projectKernel, "collisionMaterials", this.solverImplementation.colliderGrid.materialsBuffer);
|
||||
|
||||
shader.SetBuffer(projectKernel, "simplices", this.solverImplementation.simplices);
|
||||
shader.SetBuffer(projectKernel, "positions", solverImplementation.positionsBuffer);
|
||||
shader.SetBuffer(projectKernel, "prevPositions", solverImplementation.prevPositionsBuffer);
|
||||
shader.SetBuffer(projectKernel, "orientations", solverImplementation.orientationsBuffer);
|
||||
shader.SetBuffer(projectKernel, "prevOrientations", solverImplementation.prevOrientationsBuffer);
|
||||
shader.SetBuffer(projectKernel, "principalRadii", solverImplementation.principalRadiiBuffer);
|
||||
shader.SetBuffer(projectKernel, "fluidInterface", solverImplementation.fluidInterfaceBuffer);
|
||||
shader.SetBuffer(projectKernel, "userData", solverImplementation.userDataBuffer);
|
||||
shader.SetBuffer(projectKernel, "positionConstraintCounts", solverImplementation.positionConstraintCountBuffer);
|
||||
shader.SetBuffer(projectKernel, "orientationConstraintCounts", solverImplementation.orientationConstraintCountBuffer);
|
||||
shader.SetBuffer(projectKernel, "collisionMaterialIndices", solverImplementation.collisionMaterialIndexBuffer);
|
||||
shader.SetBuffer(projectKernel, "deltasAsInt", solverImplementation.positionDeltasIntBuffer);
|
||||
shader.SetBuffer(projectKernel, "orientationDeltasAsInt", solverImplementation.orientationDeltasIntBuffer);
|
||||
shader.SetBuffer(projectKernel, "invMasses", solverImplementation.invMassesBuffer);
|
||||
|
||||
shader.SetFloat("maxDepenetration", solverAbstraction.parameters.maxDepenetration);
|
||||
shader.SetFloat("collisionMargin", solverAbstraction.parameters.collisionMargin);
|
||||
shader.SetVector("diffusionMask", solverAbstraction.parameters.diffusionMask);
|
||||
shader.SetFloat("substepTime", substepTime);
|
||||
|
||||
shader.DispatchIndirect(projectKernel, this.solverImplementation.particleGrid.dispatchBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Apply(float substepTime)
|
||||
{
|
||||
var shader = ((ComputeParticleCollisionConstraints)m_Constraints).constraintsShader;
|
||||
int applyKernel = ((ComputeParticleCollisionConstraints)m_Constraints).applyKernel;
|
||||
|
||||
if (solverImplementation.activeParticleCount > 0)
|
||||
{
|
||||
var parameters = solverAbstraction.GetConstraintParameters(m_ConstraintType);
|
||||
|
||||
shader.SetBuffer(applyKernel, "particleIndices", this.solverImplementation.activeParticlesBuffer);
|
||||
shader.SetBuffer(applyKernel, "positions", solverImplementation.positionsBuffer);
|
||||
shader.SetBuffer(applyKernel, "userData", solverImplementation.userDataBuffer);
|
||||
shader.SetBuffer(applyKernel, "positionConstraintCounts", solverImplementation.positionConstraintCountBuffer);
|
||||
shader.SetBuffer(applyKernel, "deltasAsInt", solverImplementation.positionDeltasIntBuffer);
|
||||
shader.SetBuffer(applyKernel, "orientationConstraintCounts", solverImplementation.orientationConstraintCountBuffer);
|
||||
shader.SetBuffer(applyKernel, "orientationDeltasAsInt", solverImplementation.orientationDeltasIntBuffer);
|
||||
|
||||
shader.SetInt("particleCount", this.solverAbstraction.activeParticleCount);
|
||||
shader.SetFloat("sorFactor", parameters.SORFactor);
|
||||
|
||||
int threadGroups = ComputeMath.ThreadGroupCount(this.solverAbstraction.activeParticleCount, 128);
|
||||
shader.Dispatch(applyKernel, threadGroups, 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 425e2aa73a5f746039203ce1c0ac3a00
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,32 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
public class ComputeParticleFrictionConstraints : ComputeConstraintsImpl<ComputeParticleFrictionConstraintsBatch>
|
||||
{
|
||||
public ComputeShader constraintsShader;
|
||||
public int projectKernel;
|
||||
public int applyKernel;
|
||||
|
||||
public ComputeParticleFrictionConstraints(ComputeSolverImpl solver) : base(solver, Oni.ConstraintType.ParticleFriction)
|
||||
{
|
||||
constraintsShader = GameObject.Instantiate(Resources.Load<ComputeShader>("Compute/ParticleFrictionConstraints"));
|
||||
projectKernel = constraintsShader.FindKernel("Project");
|
||||
applyKernel = constraintsShader.FindKernel("Apply");
|
||||
}
|
||||
|
||||
public override IConstraintsBatchImpl CreateConstraintsBatch()
|
||||
{
|
||||
var dataBatch = new ComputeParticleFrictionConstraintsBatch(this);
|
||||
batches.Add(dataBatch);
|
||||
return dataBatch;
|
||||
}
|
||||
|
||||
public override void RemoveBatch(IConstraintsBatchImpl batch)
|
||||
{
|
||||
batches.Remove(batch as ComputeParticleFrictionConstraintsBatch);
|
||||
batch.Destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41b95f7aa768148b38a09f35bee8efce
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,79 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
public class ComputeParticleFrictionConstraintsBatch : ComputeConstraintsBatchImpl, IParticleCollisionConstraintsBatchImpl
|
||||
{
|
||||
|
||||
public ComputeParticleFrictionConstraintsBatch(ComputeParticleFrictionConstraints constraints)
|
||||
{
|
||||
m_Constraints = constraints;
|
||||
m_ConstraintType = Oni.ConstraintType.ParticleFriction;
|
||||
}
|
||||
|
||||
public override void Evaluate(float stepTime, float substepTime, int steps, float timeLeft)
|
||||
{
|
||||
//if (m_ConstraintCount > 0)
|
||||
if (solverImplementation.simplexCounts.simplexCount > 0 && solverImplementation.activeParticleCount > 0)
|
||||
{
|
||||
var shader = ((ComputeParticleFrictionConstraints)m_Constraints).constraintsShader;
|
||||
int projectKernel = ((ComputeParticleFrictionConstraints)m_Constraints).projectKernel;
|
||||
|
||||
shader.SetInt("pointCount", solverAbstraction.simplexCounts.pointCount);
|
||||
shader.SetInt("edgeCount", solverAbstraction.simplexCounts.edgeCount);
|
||||
shader.SetInt("triangleCount", solverAbstraction.simplexCounts.triangleCount);
|
||||
|
||||
shader.SetBuffer(projectKernel, "particleContacts", solverAbstraction.particleContacts.computeBuffer);
|
||||
shader.SetBuffer(projectKernel, "effectiveMasses", solverAbstraction.particleContactEffectiveMasses.computeBuffer);
|
||||
shader.SetBuffer(projectKernel, "dispatchBuffer", solverImplementation.particleGrid.dispatchBuffer);
|
||||
shader.SetBuffer(projectKernel, "collisionMaterials", solverImplementation.colliderGrid.materialsBuffer);
|
||||
|
||||
shader.SetBuffer(projectKernel, "simplices", solverImplementation.simplices);
|
||||
shader.SetBuffer(projectKernel, "collisionMaterialIndices", solverImplementation.collisionMaterialIndexBuffer);
|
||||
shader.SetBuffer(projectKernel, "positions", solverImplementation.positionsBuffer);
|
||||
shader.SetBuffer(projectKernel, "orientations", solverImplementation.orientationsBuffer);
|
||||
shader.SetBuffer(projectKernel, "prevPositions", solverImplementation.prevPositionsBuffer);
|
||||
shader.SetBuffer(projectKernel, "prevOrientations", solverImplementation.prevOrientationsBuffer);
|
||||
shader.SetBuffer(projectKernel, "principalRadii", solverImplementation.principalRadiiBuffer);
|
||||
shader.SetBuffer(projectKernel, "invMasses", solverImplementation.invMassesBuffer);
|
||||
shader.SetBuffer(projectKernel, "invRotationalMasses", solverImplementation.invRotationalMassesBuffer);
|
||||
|
||||
shader.SetBuffer(projectKernel, "positionConstraintCounts", solverImplementation.positionConstraintCountBuffer);
|
||||
shader.SetBuffer(projectKernel, "deltasAsInt", solverImplementation.positionDeltasIntBuffer);
|
||||
shader.SetBuffer(projectKernel, "orientationConstraintCounts", solverImplementation.orientationConstraintCountBuffer);
|
||||
shader.SetBuffer(projectKernel, "orientationDeltasAsInt", solverImplementation.orientationDeltasIntBuffer);
|
||||
|
||||
shader.SetFloat("stepTime", stepTime);
|
||||
shader.SetFloat("substepTime", substepTime);
|
||||
|
||||
shader.DispatchIndirect(projectKernel, this.solverImplementation.particleGrid.dispatchBuffer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void Apply(float substepTime)
|
||||
{
|
||||
var shader = ((ComputeParticleFrictionConstraints)m_Constraints).constraintsShader;
|
||||
int applyKernel = ((ComputeParticleFrictionConstraints)m_Constraints).applyKernel;
|
||||
|
||||
if (solverImplementation.activeParticleCount > 0)
|
||||
{
|
||||
var parameters = solverAbstraction.GetConstraintParameters(m_ConstraintType);
|
||||
|
||||
shader.SetBuffer(applyKernel, "particleIndices", this.solverImplementation.activeParticlesBuffer);
|
||||
shader.SetBuffer(applyKernel, "positions", solverImplementation.positionsBuffer);
|
||||
shader.SetBuffer(applyKernel, "orientations", solverImplementation.orientationsBuffer);
|
||||
shader.SetBuffer(applyKernel, "positionConstraintCounts", solverImplementation.positionConstraintCountBuffer);
|
||||
shader.SetBuffer(applyKernel, "deltasAsInt", solverImplementation.positionDeltasIntBuffer);
|
||||
shader.SetBuffer(applyKernel, "orientationConstraintCounts", solverImplementation.orientationConstraintCountBuffer);
|
||||
shader.SetBuffer(applyKernel, "orientationDeltasAsInt", solverImplementation.orientationDeltasIntBuffer);
|
||||
|
||||
shader.SetInt("particleCount", this.solverAbstraction.activeParticleCount);
|
||||
shader.SetFloat("sorFactor", parameters.SORFactor);
|
||||
|
||||
int threadGroups = ComputeMath.ThreadGroupCount(this.solverAbstraction.activeParticleCount, 128);
|
||||
shader.Dispatch(applyKernel, threadGroups, 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 12275bbeff9604bb393a365d8442161a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user