Exemplo n.º 1
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.º 2
0
 public VelocitySimulation(ComputeShader compute, VelocityService v, ConstantService c)
 {
     _kernelSimulate = compute.FindKernel(ShaderConst.KERNEL_SIMULATE_VELOCITY);
     _compute = compute;
     _velocities = v;
     _constants = c;
 }
Exemplo n.º 3
0
 public PositionSimulation(ComputeShader compute, VelocityService v, PositionService p)
 {
     _kernelSimulate = compute.FindKernel(ShaderConst.KERNEL_SIMULATE_POSITION);
     _compute        = compute;
     _velocities     = v;
     _positions      = p;
 }
Exemplo n.º 4
0
 public PositionSimulation(ComputeShader compute, VelocityService v, PositionService p)
 {
     _kernelSimulate = compute.FindKernel(ShaderConst.KERNEL_SIMULATE_POSITION);
     _compute = compute;
     _velocities = v;
     _positions = p;
 }
Exemplo n.º 5
0
 public VelocitySimulation(ComputeShader compute, VelocityService v, ConstantService c)
 {
     _kernelSimulate = compute.FindKernel(ShaderConst.KERNEL_SIMULATE_VELOCITY);
     _compute        = compute;
     _velocities     = v;
     _constants      = c;
 }
 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
 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.º 8
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.º 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 RotationService(ComputeShader c, VelocityService v, LifeService l, float radius, Vector2 angularSpeedRange)
    {
        Count = v.V0.count;
        _compute = c;
        _velocities = v;
        _lifes = l;
        _kernelVelocityBasedRotate = c.FindKernel(KERNEL_VELOCITY_BASED_ROTATE);
        _data = new Vector4[Count];
        _rotations = new ComputeBuffer(Count, Marshal.SizeOf(typeof(Vector4)));

        for (var i = 0; i < Count; i++)
            _data[i] = QuaternionExtension.IDENTITY;
        Upload();
        ShaderUtil.CalcWorkSize(Count, out SimSizeX, out SimSizeY, out SimSizeZ);

        _angularSpeedData = new float[ShaderConst.WARP_SIZE];
        _angularSpeed = new ComputeBuffer(_angularSpeedData.Length, Marshal.SizeOf(typeof(float)));
        UpdateAngularSpeed(angularSpeedRange);
    }
Exemplo n.º 14
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.º 15
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.º 16
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;
        }