コード例 #1
0
ファイル: SPWorld.cs プロジェクト: flufy3d/SpmdParticle
        void UpdateKernelParams()
        {
            m_texture_needs_update = true;

            m_particle_num = SPAPI.spGetNumParticles(GetContext());

            SPKernelParams p = default(SPKernelParams);

            SPAPI.spGetKernelParams(GetContext(), ref p);
            p.world_center         = transform.position;
            p.world_size           = transform.localScale;
            p.world_div_x          = m_world_div_x;
            p.world_div_y          = m_world_div_y;
            p.world_div_z          = m_world_div_z;
            p.active_region_center = transform.position + m_active_region_center;
            p.active_region_extent = m_active_region_extent;
            p.enable_interaction   = m_enable_interaction ? 1 : 0;
            p.enable_colliders     = m_enable_colliders ? 1 : 0;
            p.enable_forces        = m_enable_forces ? 1 : 0;
            p.id_as_float          = m_id_as_float ? 1 : 0;
            p.timestep             = Time.deltaTime * m_timescale;
            p.damping            = m_damping;
            p.advection          = m_advection;
            p.pressure_stiffness = m_pressure_stiffness;
            p.scaler             = m_coord_scale;
            p.particle_size      = m_particle_size;
            p.max_particles      = m_max_particle_num;
            SPAPI.spSetKernelParams(GetContext(), ref p);
        }
コード例 #2
0
ファイル: SPWorld.cs プロジェクト: flufy3d/SpmdParticle
        static void ActualUpdate()
        {
            if (s_instances.Count == 0)
            {
                return;
            }

            foreach (SPWorld w in s_instances)
            {
                SPAPI.spEndUpdate(w.GetContext());
            }
            foreach (SPWorld w in s_instances)
            {
                s_current = w;
                SPAPI.spCallHandlers(w.GetContext());
                SPAPI.spClearCollidersAndForces(w.GetContext());
                w.CallUpdateRoutines();
                w.UpdateKernelParams();
                s_current = null;
            }
            UpdateSPObjects();
            foreach (SPWorld w in s_instances)
            {
                SPAPI.spBeginUpdate(w.GetContext(), Time.deltaTime);
            }
        }
コード例 #3
0
ファイル: SPCollider.cs プロジェクト: flufy3d/SpmdParticle
 void OnDisable()
 {
     s_instances.Remove(this);
     EachTargets((w) =>
     {
         SPAPI.spRemoveCollider(w.GetContext(), ref m_cprops);
     });
 }
コード例 #4
0
ファイル: SPWorld.cs プロジェクト: flufy3d/SpmdParticle
 void OnDestroy()
 {
     SPAPI.spDestroyContext(GetContext());
     if (m_instance_texture != null)
     {
         m_instance_texture.Release();
         m_instance_texture = null;
     }
 }
コード例 #5
0
ファイル: SPBoxCollider.cs プロジェクト: flufy3d/SpmdParticle
        public override void SPUpdate()
        {
            base.SPUpdate();

            Matrix4x4 mat = m_trans.localToWorldMatrix;

            EachTargets((w) =>
            {
                SPAPI.spAddBoxCollider(w.GetContext(), ref m_cprops, ref mat, ref m_center, ref m_size);
            });
        }
コード例 #6
0
ファイル: SPCollider.cs プロジェクト: flufy3d/SpmdParticle
        public unsafe void PropagateHit(ref SPParticle particle)
        {
            Vector3 f = SPAPI.spGetIntermediateData(SPWorld.GetCurrentContext())->accel *SPWorld.GetCurrent().m_particle_mass;

            if (m_rigid3d != null)
            {
                m_rigid3d.AddForceAtPosition(f, particle.position);
            }
            if (m_rigid2d != null)
            {
                m_rigid2d.AddForceAtPosition(f, particle.position);
            }
        }
コード例 #7
0
ファイル: SPWorld.cs プロジェクト: flufy3d/SpmdParticle
 public void UpdateInstanceTexture()
 {
     if (m_instance_texture == null)
     {
         m_instance_texture            = new RenderTexture(SPWorld.DataTextureWidth, SPWorld.DataTextureHeight, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Default);
         m_instance_texture.filterMode = FilterMode.Point;
         m_instance_texture.Create();
     }
     if (m_texture_needs_update)
     {
         m_texture_needs_update = false;
         SPAPI.spUpdateDataTexture(GetContext(), m_instance_texture.GetNativeTexturePtr(), m_instance_texture.width, m_instance_texture.height);
     }
 }
コード例 #8
0
        public void SPUpdate()
        {
            if (m_emit_count_prev != m_emit_count)
            {
                m_emit_count_prev = m_emit_count;
                m_total_emit      = Mathf.FloorToInt(m_local_time * m_emit_count);
            }
            m_local_time += Time.deltaTime;
            int emit_total      = Mathf.FloorToInt(m_local_time * m_emit_count);
            int emit_this_frame = emit_total - m_total_emit;

            if (emit_this_frame == 0)
            {
                return;
            }
            m_total_emit = emit_total;

            m_params.velocity = m_velosity_base;
            m_params.velocity_random_diffuse = m_velosity_random_diffuse;
            m_params.lifetime = m_lifetime;
            m_params.lifetime_random_diffuse = m_lifetime_random_diffuse;
            m_params.userdata = m_userdata;
            m_params.handler  = m_spawn_handler;
            Matrix4x4 mat = transform.localToWorldMatrix;

            switch (m_shape)
            {
            case Shape.Sphere:
                EachTargets((w) =>
                {
                    SPAPI.spScatterParticlesSphereTransform(w.GetContext(), ref mat, emit_this_frame, ref m_params);
                });
                break;

            case Shape.Box:
                EachTargets((w) =>
                {
                    SPAPI.spScatterParticlesBoxTransform(w.GetContext(), ref mat, emit_this_frame, ref m_params);
                });
                break;
            }
        }
コード例 #9
0
ファイル: SPForce.cs プロジェクト: flufy3d/SpmdParticle
        public void SPUpdate()
        {
            m_mpprops.dir_type        = m_direction_type;
            m_mpprops.shape_type      = m_shape_type;
            m_mpprops.strength_near   = m_strength_near;
            m_mpprops.strength_far    = m_strength_far;
            m_mpprops.rcp_range       = 1.0f / (m_strength_far - m_strength_near);
            m_mpprops.range_inner     = m_range_inner;
            m_mpprops.range_outer     = m_range_outer;
            m_mpprops.attenuation_exp = m_attenuation_exp;
            m_mpprops.random_seed     = m_random_seed;
            m_mpprops.random_diffuse  = m_random_diffuse;
            m_mpprops.direction       = m_direction;
            m_mpprops.center          = transform.position;
            m_mpprops.rcp_cellsize    = new Vector3(1.0f / m_cellsize.x, 1.0f / m_cellsize.y, 1.0f / m_cellsize.z);
            Matrix4x4 mat = transform.localToWorldMatrix;

            EachTargets((w) =>
            {
                SPAPI.spAddForce(w.GetContext(), ref m_mpprops, ref mat);
            });
        }
コード例 #10
0
ファイル: SPWorld.cs プロジェクト: flufy3d/SpmdParticle
 void Awake()
 {
     m_context = SPAPI.spCreateContext();
 }