/// <inheritdoc/>
            public void Execute()
            {
                float value             = buffer[ThreadIds.X];
                ExternalStructType type = ExternalStructType.New((int)value, Hlsl.Abs(value));

                buffer[ThreadIds.X] = ExternalStructType.Sum(type);
            }
示例#2
0
        static float SDBox(float3 p, float3 b)
        {
            float3 q = Hlsl.Abs(p) - b;

            return(Hlsl.Length(Hlsl.Max(q, 0.0f)) +
                   Hlsl.Min(Hlsl.Max(q.X, Hlsl.Max(q.Y, q.Z)), 0.0f));
        }
示例#3
0
    /// <summary>
    /// Makes some magic happen.
    /// </summary>
    private float4 Tex(float3 p)
    {
        float  t   = time + 78.0f;
        float4 o   = new(p.X, p.Y, p.Z, 3.0f * Hlsl.Sin(t * 0.1f));
        float4 dec =
            new float4(1.0f, 0.9f, 0.1f, 0.15f) +
            new float4(0.06f * Hlsl.Cos(t * 0.1f), 0, 0, 0.14f * Hlsl.Cos(t * 0.23f));

        for (int i = 0; i++ < NumberOfIterations;)
        {
            o.XZYW = Hlsl.Abs(o / Hlsl.Dot(o, o) - dec);
        }

        return(o);
    }
        // Various distance metrics.
        private static float Distance(Float2 p)
        {
            if (SHAPE == 0)
            {
                return(Hlsl.Length(p));
            }
            else
            {
                p = Hlsl.Abs(p);
            }

            switch (SHAPE)
            {
            case 1: return(Hlsl.Max(Hlsl.Length(p), (p.X + p.Y) * 0.7071f + 0.015f));

            case 2: return(Hlsl.Max((p.X + p.Y) * 0.7071f, Hlsl.Max(p.X, p.Y)));

            case 3: return(Hlsl.Pow(Hlsl.Dot(Hlsl.Pow(p, 3), 1), 1.0f / 3.0f));

            default: return((p.X + p.Y) * 0.7071f);
            }
        }
        // The scene's distance function: There'd be faster ways to do this, but it's
        // more readable this way. Plus, this  is a pretty simple scene, so it's
        // efficient enough.
        private static float M(Float3 p)
        {
            float fl  = -p.Z;
            float obj = Truchet(p.XY);

            obj = Hlsl.Max(obj, Hlsl.Abs(p.Z) - 0.125f) - Hlsl.SmoothStep(0.03f, 0.25f, -obj) * 0.1f;

            float       studs = 1e5f;
            const float sc    = 0.5f;
            Float2      q     = p.XY + 0.5f * sc;
            Float2      iq    = Hlsl.Floor(q / sc) + 0.5f;

            q -= iq * sc;

            if (Mod(iq.X + iq.Y, 2.0f) > 0.5f)
            {
                studs = Hlsl.Max(Hlsl.Length(q) - 0.1f * sc - 0.02f, Hlsl.Abs(p.Z) - 0.26f);
            }

            objID = fl < obj && fl < studs ? 0 : obj < studs ? 1 : 2;

            return(Hlsl.Min(Hlsl.Min(fl, obj), studs));
        }