Exemple #1
0
        public void Execute(int vi)
        {
            // Number of the segments
            var scount = P.Length / R.Length;

            // Per-filament random segment length
            var seg = new XXHash(seed).Float((uint)vi);

            seg = (1 - seg * prof.lengthRandomness) * prof.length / scount;

            // Noise field settings
            noffs1 = math.float3(0, 1, 0) * prof.noiseSpeed * t;
            noffs2 = math.float3(3, 1, 7) * math.PI - noffs1.zyx;

            // Offset in the position/velocity buffer.
            var offs = vi * scount;

            // The first vertex (root point, transform only)
            var p = math.mul(tf, math.float4(R[vi].position, 1)).xyz;

            P[offs++] = math.float4(p, 1);

            // The second vertex (no dynamics)
            p        += math.mul(tf, math.float4(R[vi].normal, 0)).xyz *seg;
            P[offs++] = math.float4(p, 1);

            // Following vertices
            for (var si = 2; si < scount; si++, offs++)
            {
                // Target position
                var p4  = P[offs - math.min(si, 4)].xyz;
                var p_t = p + math.normalizesafe(p - p4) * seg;

                // -- Position update

                // Newtonian motion
                var p_n = P[offs].xyz + V[offs] * dt;

                // Segment length constraint
                p += math.normalize(p_n - p) * seg;

                // -- Velocity Update

                // Damping
                var v = V[offs] * math.exp(-prof.damping * dt);

                // Acceleration (spring model)
                v += (p_t - p) * dt * prof.spring;

                // Gravity
                v += (float3)prof.gravity * dt;

                // Noise field
                v += NoiseField(p) * dt;

                // Output
                P[offs] = math.float4(p, 1);
                V[offs] = v;
            }
        }
Exemple #2
0
        public static Bullet Spawn(float2 position, int seed, int bulletTypeIndex = 0)
        {
            var hash     = new Klak.Math.XXHash((uint)seed);
            var rotation = hash.Float(math.PI * 2, 0u);
            var speed    = hash.Float(0.1f, 0.5f, 1u);

            return(new Bullet(position, rotation, speed, bulletTypeIndex));
        }
Exemple #3
0
        public static Bullet Spawn(float2 position, int seed)
        {
            var hash  = new Klak.Math.XXHash((uint)seed);
            var angle = hash.Float(math.PI * 2, 0u);
            var speed = hash.Float(0.05f, 0.2f, 1u);

            return(new Bullet(position,
                              math.float2(math.cos(angle),
                                          math.sin(angle)) * speed));
        }
Exemple #4
0
            public void Execute(int i)
            {
                var hash = new Klak.Math.XXHash((uint)i);

                // Indices
                var i1 = (int)Idx[i * 3 + 0];
                var i2 = (int)Idx[i * 3 + 1];
                var i3 = (int)Idx[i * 3 + 2];

                // Vertex positions with transformation
                var p1 = math.mul(Xfm, math.float4(Pos[i1], 1)).xyz;
                var p2 = math.mul(Xfm, math.float4(Pos[i2], 1)).xyz;
                var p3 = math.mul(Xfm, math.float4(Pos[i3], 1)).xyz;

                // Triangle centroid
                var pc = (p1 + p2 + p3) / 3;

                // Effect select
                var sel = hash.Float(8394) < 0.1f;

                // Effect parameter
                var eff = math.mul(Eff, math.float4(pc, 1)).z;

                eff = math.saturate(eff + hash.Float(0, 0.1f, 2058));

                // Deformation parameter
                var mod = (1 - math.cos(eff * math.PI * 4)) / 2;

                // Triangle scaling
                if (sel)
                {
                    var scale = math.pow(hash.Float(84792), 8);
                    scale = 1 + mod * math.lerp(5, 25, scale);
                    p1    = math.lerp(pc, p1, scale);
                    p2    = math.lerp(pc, p2, scale);
                    p3    = math.lerp(pc, p3, scale);
                }

                // Normal/Tangent
                var nrm = MathUtil.UnitOrtho(p2 - p1, p3 - p1);
                var tan = MathUtil.AdHocTangent(nrm);

                // UV coordinates
                var mat = (eff > 0.25f && eff < 0.75f) ? 1.0f : 0.0f;
                var emm = (sel ? math.pow(mod, 20) * 2 : 0) - mat;
                var uv1 = math.float4(UV0[i1], mat, math.clamp(emm, -1, 1));
                var uv2 = math.float4(UV0[i2], uv1.zw);
                var uv3 = math.float4(UV0[i3], uv1.zw);

                // Output
                Out[i] = new Triangle(new Vertex(p1, nrm, tan, uv1),
                                      new Vertex(p2, nrm, tan, uv2),
                                      new Vertex(p3, nrm, tan, uv3));
            }
Exemple #5
0
        public void Execute()
        {
            var seed = _info[0].SpawnCount + 1;

            var actives = _info[0].ActiveCount;
            var spawns  = math.min(_bullets.Length - actives, _count);

            var hash = new Klak.Math.XXHash((uint)seed);

            for (var i = 0; i < spawns; i++)
            {
                var bulletTypeIndex = hash.Int(0, 6, 0u);

                _bullets[actives + i] = Bullet.Spawn(_position, seed + i, bulletTypeIndex);
            }

            _info[0] = BulletGroupInfo.AddActiveAndSpawnCount(_info[0], spawns);
        }