Exemplo n.º 1
0
 public PositionSimulation(ComputeShader compute, VelocityService v, PositionService p)
 {
     _kernelSimulate = compute.FindKernel(ShaderConst.KERNEL_SIMULATE_POSITION);
     _compute = compute;
     _velocities = v;
     _positions = p;
 }
Exemplo n.º 2
0
 public BoundsChecker(ComputeShader compute, LifeService l, PositionService p)
 {
     _kernel    = compute.FindKernel(ShaderConst.KERNEL_CHECK_BOUNDS);
     _compute   = compute;
     _lifes     = l;
     _positions = p;
 }
Exemplo n.º 3
0
        void Start()
        {
            Positions      = new PositionService(compute, capacity);
            Velocities     = new VelocityService(compute, capacity);
            Lifes          = new LifeService(compute, capacity);
            Constants      = new ConstantService(constants);
            VelSimulation  = new VelocitySimulation(compute, Velocities);
            PosSimulation  = new PositionSimulation(compute, Velocities, Positions);
            Broadphase     = new BroadPhase(compute, computeSort, Lifes, Positions);
            ParticleSolver = new ParticleCollisionSolver(compute, Velocities, Positions, Lifes, Broadphase);
            BoundsChecker  = new BoundsChecker(compute, Lifes, Positions);
            Walls          = BuildWalls(wallColliders);
            WallSolver     = new WallCollisionSolver(compute, Velocities, Positions, Walls);

            var particles = new GameObject[capacity];

            foreach (var p in particlefabs)
            {
                p.transform.localScale = 2f * constants.radius * Vector3.one;
            }
            for (var i = 0; i < capacity; i++)
            {
                particles[i] = particlefabs[Random.Range(0, particlefabs.Length)];
            }
            Combiner = new MeshCombiner(containerfab);
            Combiner.Rebuild(particles);
            Combiner.SetParent(transform, false);

            UpdateConstantData();
        }
Exemplo n.º 4
0
 public BoundsChecker(ComputeShader compute, LifeService l, PositionService p)
 {
     _kernel = compute.FindKernel(ShaderConst.KERNEL_CHECK_BOUNDS);
     _compute = compute;
     _lifes = l;
     _positions = p;
 }
Exemplo n.º 5
0
 public PositionSimulation(ComputeShader compute, VelocityService v, PositionService p)
 {
     _kernelSimulate = compute.FindKernel(ShaderConst.KERNEL_SIMULATE_POSITION);
     _compute        = compute;
     _velocities     = v;
     _positions      = p;
 }
 public WallCollisionSolver(ComputeShader compute, VelocityService v, PositionService p, WallService w)
 {
     _kernel = compute.FindKernel(ShaderConst.KERNEL_SOLVE_WALL_COLLISION);
     _compute = compute;
     _velocities = v;
     _positions = p;
     _walls = w;
 }
Exemplo n.º 7
0
 void Start()
 {
     _positions = new PositionService(compute, capacity);
     _velocities = new VelocityService(compute, capacity);
     _lifes = new LifeService(compute, capacity);
     _velSimulation = new VelocitySimulation(compute, _velocities);
     _posSimulation = new PositionSimulation(compute, _velocities, _positions);
 }
Exemplo n.º 8
0
 public WallCollisionSolver(ComputeShader compute, VelocityService v, PositionService p, WallService w)
 {
     _kernel     = compute.FindKernel(ShaderConst.KERNEL_SOLVE_WALL_COLLISION);
     _compute    = compute;
     _velocities = v;
     _positions  = p;
     _walls      = w;
 }
Exemplo n.º 9
0
 public ParticleCollisionSolver(ComputeShader compute, VelocityService v, PositionService p, LifeService l, ICollisionDetection b)
 {
     _kernel     = compute.FindKernel(ShaderConst.KERNEL_SOLVE_PARTICLE_COLLISION);
     _compute    = compute;
     _velocities = v;
     _positions  = p;
     _lifes      = l;
     _broadphase = b;
 }
 public ParticleCollisionSolver(ComputeShader compute, VelocityService v, PositionService p, LifeService l, BroadPhase b)
 {
     _kernel = compute.FindKernel(ShaderConst.KERNEL_SOLVE_PARTICLE_COLLISION);
     _compute = compute;
     _velocities = v;
     _positions = p;
     _lifes = l;
     _broadphase = b;
 }
 public PolygonCollisionSolver(ComputeShader c, VelocityService v, PositionService p, LifeService l, PolygonColliderService poly)
 {
     _compute = c;
     _kernel = c.FindKernel(ShaderConst.KERNEL_SOLVE_POLYGON_COLLISION);
     _velocities = v;
     _positions = p;
     _lifes = l;
     _polygons = poly;
 }
Exemplo n.º 12
0
 public PolygonCollisionSolver(ComputeShader c, VelocityService v, PositionService p, LifeService l, PolygonColliderService poly)
 {
     _compute    = c;
     _kernel     = c.FindKernel(ShaderConst.KERNEL_SOLVE_POLYGON_COLLISION);
     _velocities = v;
     _positions  = p;
     _lifes      = l;
     _polygons   = poly;
 }
Exemplo n.º 13
0
 public HashService(ComputeShader compute, LifeService l, PositionService p)
 {
     _compute          = compute;
     _lifes            = l;
     _positions        = p;
     _kernelInitHashes = compute.FindKernel(ShaderConst.KERNEL_INIT_HASHES);
     HashData          = new int[l.Lifes.count];
     Hashes            = new ComputeBuffer(l.Lifes.count, Marshal.SizeOf(typeof(int)));
     Hashes.SetData(HashData);
 }
Exemplo n.º 14
0
 public HashService(ComputeShader compute, LifeService l, PositionService p)
 {
     _compute = compute;
     _lifes = l;
     _positions = p;
     _kernelInitHashes = compute.FindKernel(ShaderConst.KERNEL_INIT_HASHES);
     HashData = new int[l.Lifes.count];
     Hashes = new ComputeBuffer(l.Lifes.count, Marshal.SizeOf(typeof(int)));
     Hashes.SetData (HashData);
 }
Exemplo n.º 15
0
 public BroadPhase(ComputeShader compute, ComputeShader computeSort, LifeService l, PositionService p)
 {
     var capacity = l.Lifes.count;
     _lifes = l;
     _positions = p;
     _kernelInitYs = compute.FindKernel(ShaderConst.KERNEL_INIT_BROADPHASE);
     _kernelSolve = compute.FindKernel (ShaderConst.KERNEL_SOVLE_BROADPHASE);
     _compute = compute;
     _sort = new BitonicMergeSort(computeSort);
     Keys = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(uint)));
     _ys = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(float)));
     Bands = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(Band)));
 }
Exemplo n.º 16
0
        public BroadPhase(ComputeShader compute, ComputeShader computeSort, LifeService l, PositionService p)
        {
            var capacity = l.Lifes.count;

            _lifes        = l;
            _positions    = p;
            _kernelInitYs = compute.FindKernel(ShaderConst.KERNEL_INIT_BROADPHASE);
            _kernelSolve  = compute.FindKernel(ShaderConst.KERNEL_SOVLE_BROADPHASE);
            _compute      = compute;
            _sort         = new BitonicMergeSort(computeSort);
            Keys          = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(uint)));
            _ys           = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(float)));
            Bands         = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(Band)));
        }
Exemplo n.º 17
0
        public HashGrid(ComputeShader compute, ComputeShader computeSort, LifeService l, PositionService p, GridService.Grid g)
        {
            var capacity = l.Lifes.count;
            _compute = compute;
            _lifes = l;
            _positions = p;

            _kernelSolve = compute.FindKernel (ShaderConst.KERNEL_SOVLE_COLLISION_DETECTION);
            _sort = new BitonicMergeSort(computeSort);
            _keys = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(uint)));
            CollisionData = new Collision[capacity];
            Collisions = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(Collision)));
            _hashes = new HashService(compute, l, p);
            _grid = new GridService(compute, g, _hashes);
        }
Exemplo n.º 18
0
        public HashGrid(ComputeShader compute, ComputeShader computeSort, LifeService l, PositionService p, GridService.Grid g)
        {
            var capacity = l.Lifes.count;

            _compute   = compute;
            _lifes     = l;
            _positions = p;

            _kernelSolve  = compute.FindKernel(ShaderConst.KERNEL_SOVLE_COLLISION_DETECTION);
            _sort         = new BitonicMergeSort(computeSort);
            _keys         = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(uint)));
            CollisionData = new Collision[capacity];
            Collisions    = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(Collision)));
            _hashes       = new HashService(compute, l, p);
            _grid         = new GridService(compute, g, _hashes);
        }
Exemplo n.º 19
0
        void Start()
        {
            capacity = ShaderUtil.PowerOfTwo(capacity);

            Positions      = new PositionService(compute, capacity);
            Velocities     = new VelocityService(compute, capacity);
            Lifes          = new LifeService(compute, capacity);
            Constants      = new ConstantService(capacity, constants);
            VelSimulation  = new VelocitySimulation(compute, Velocities, Constants);
            PosSimulation  = new PositionSimulation(compute, Velocities, Positions);
            Collisions     = new HashGrid(compute, computeSort, Lifes, Positions, GenerateGrid());
            ParticleSolver = new ParticleCollisionSolver(compute, Velocities, Positions, Lifes, Collisions);
            BoundsChecker  = new BoundsChecker(compute, Lifes, Positions);
            Polygons       = new PolygonColliderService();
            PolygonSolver  = new PolygonCollisionSolver(compute, Velocities, Positions, Lifes, Polygons);

            var particles = new GameObject[capacity];

            foreach (var pfab in particlefabs)
            {
                pfab.transform.localScale = 2f * constants.radius * Vector3.one;
            }
            Profiler.BeginSample("Instantiate Particles");
            for (var i = 0; i < capacity; i++)
            {
                var pfab = particlefabs[Random.Range(0, particlefabs.Length)];
                particles[i] = (GameObject)Instantiate(pfab, Vector3.zero, Random.rotationUniform);
            }
            Profiler.EndSample();
            Combiner = new MeshCombiner(containerfab);
            Combiner.Rebuild(particles);
            Combiner.SetParent(transform, false);
            for (var i = 0; i < capacity; i++)
            {
                Destroy(particles[i]);
            }

            UpdateConstantData();
            _initialized = true;
        }
Exemplo n.º 20
0
 void Start()
 {
     _positions = new PositionService (compute, capacity);
     _lifes = new LifeService(compute, capacity);
 }
Exemplo n.º 21
0
        void Start()
        {
            capacity = ShaderUtil.PowerOfTwo(capacity);

            Positions = new PositionService(compute, capacity);
            Velocities = new VelocityService(compute, capacity);
            Lifes = new LifeService(compute, capacity);
            Constants = new ConstantService(capacity, constants);
            VelSimulation = new VelocitySimulation(compute, Velocities, Constants);
            PosSimulation = new PositionSimulation(compute, Velocities, Positions);
            Collisions = new HashGrid(compute, computeSort, Lifes, Positions, GenerateGrid());
            ParticleSolver = new ParticleCollisionSolver(compute, Velocities, Positions, Lifes, Collisions);
            BoundsChecker = new BoundsChecker(compute, Lifes, Positions);
            Polygons = new PolygonColliderService();
            PolygonSolver = new PolygonCollisionSolver(compute, Velocities, Positions, Lifes, Polygons);

            var particles = new GameObject[capacity];
            foreach (var pfab in particlefabs)
                pfab.transform.localScale = 2f * constants.radius * Vector3.one;
            Profiler.BeginSample("Instantiate Particles");
            for (var i = 0; i < capacity; i++) {
                var pfab = particlefabs[Random.Range(0, particlefabs.Length)];
                particles[i] = (GameObject)Instantiate(pfab, Vector3.zero, Random.rotationUniform);
            }
            Profiler.EndSample();
            Combiner = new MeshCombiner(containerfab);
            Combiner.Rebuild(particles);
            Combiner.SetParent(transform, false);
            for (var i = 0; i < capacity; i++)
                Destroy(particles[i]);

            UpdateConstantData();
            _initialized = true;
        }
Exemplo n.º 22
0
        void Start()
        {
            Positions = new PositionService(compute, capacity);
            Velocities = new VelocityService(compute, capacity);
            Lifes = new LifeService(compute, capacity);
            Constants = new ConstantService(constants);
            VelSimulation = new VelocitySimulation(compute, Velocities);
            PosSimulation = new PositionSimulation(compute, Velocities, Positions);
            Broadphase = new BroadPhase(compute, computeSort, Lifes, Positions);
            ParticleSolver = new ParticleCollisionSolver(compute, Velocities, Positions, Lifes, Broadphase);
            BoundsChecker = new BoundsChecker(compute, Lifes, Positions);
            Walls = BuildWalls(wallColliders);
            WallSolver = new WallCollisionSolver(compute, Velocities, Positions, Walls);

            var particles = new GameObject[capacity];
            foreach (var p in particlefabs)
                p.transform.localScale = 2f * constants.radius * Vector3.one;
            for (var i = 0; i < capacity; i++)
                particles[i] = particlefabs[Random.Range(0, particlefabs.Length)];
            Combiner = new MeshCombiner(containerfab);
            Combiner.Rebuild(particles);
            Combiner.SetParent(transform, false);

            UpdateConstantData();
        }