Esempio n. 1
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));
        }
Esempio n. 2
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));
        }
Esempio n. 3
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));
            }