// A standard square grid 2D blobby Truchet routine: Render circles
        // in opposite corners of a tile, reverse the pattern on alternate
        // checker tiles, and randomly rotate.
        private static float Truchet(Float2 p)
        {
            const float sc = 0.5f;
            Float2      ip = Hlsl.Floor(p / sc) + 0.5f;

            p -= ip * sc;

            float rnd = Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(ip, new Float2(1, 113))) * 45758.5453f);

            if (rnd < .5)
            {
                p.Y = -p.Y;
            }

            float d = Hlsl.Min(Distance(p - 0.5f * sc), Distance(p + 0.5f * sc)) - 0.5f * sc;

            if (SHAPE == 4)
            {
                d += (0.5f - 0.5f / Hlsl.Sqrt(2.0f)) * sc;
            }

            if (rnd < 0.5f)
            {
                d = -d;
            }
            if (Mod(ip.X + ip.Y, 2.0f) < 0.5f)
            {
                d = -d;
            }

            return(d - 0.03f);
        }
Ejemplo n.º 2
0
    /// <inheritdoc/>
    public float4 Execute()
    {
        float2 position = ((float2)(256 * ThreadIds.XY)) / DispatchSize.X + time;
        float4 color    = 0;

        for (int i = 0; i < 6; i++)
        {
            float2 a = Hlsl.Floor(position);
            float2 b = Hlsl.Frac(position);
            float4 w = Hlsl.Frac(
                (Hlsl.Sin(a.X * 7 + 31.0f * a.Y + 0.01f * time) +
                 new float4(0.035f, 0.01f, 0, 0.7f))
                * 13.545317f);

            color.XYZ += w.XYZ *
                         2.0f * Hlsl.SmoothStep(0.45f, 0.55f, w.W) *
                         Hlsl.Sqrt(16.0f * b.X * b.Y * (1.0f - b.X) * (1.0f - b.Y));

            position /= 2.0f;
            color    /= 2.0f;
        }

        color.XYZ = Hlsl.Pow(color.XYZ, new float3(0.7f, 0.8f, 0.5f));
        color.W   = 1.0f;

        return(color);
    }
        public void Execute(ThreadIds id)
        {
            var currentMax = 0;

            for (var j = 0; j < iterations; j++)
            {
                var i = (id.X * iterations) + j;
                if (i * 3 >= coordinatesSize)
                {
                    return;
                }
                var pX = (int)Hlsl.Floor(((coordinates[i * 3] - left) / (right - left)) * width);
                var pY = (int)Hlsl.Floor(((coordinates[(i * 3) + 2] - top) / (bottom - top)) * height);
                if (pX < 0 || pX >= width || pY < 0 || pY >= height)
                {
                    continue;
                }
                var denIndex = pX + (pY * width);
                density[denIndex]++;
                if (density[denIndex] > currentMax)
                {
                    currentMax = density[denIndex];
                }
            }

            Hlsl.InterlockedMax(maxDensity[0], currentMax);
            //if (currentMax > maxDensity[0]) { maxDensity[0] = currentMax; }
        }
Ejemplo n.º 4
0
    /// <inheritdoc/>
    public float4 Execute()
    {
        float2 position = D2D.GetScenePosition().XY;
        uint   x        = (uint)Hlsl.Floor(position.X);
        uint   y        = (uint)Hlsl.Floor(position.Y);

        uint cellX = (uint)(int)Hlsl.Floor(x / cellSize);
        uint cellY = (uint)(int)Hlsl.Floor(y / cellSize);

        if ((cellX % 2 == 0 && cellY % 2 == 0) ||
            (cellX % 2 == 1 && cellY % 2 == 1))
        {
            Hlsl.Clip(-1);
        }

        return(D2D.GetInput(0));
    }
Ejemplo n.º 5
0
    // Based on IQ's gradient noise formula.
    private float Noise2D3G(float2 p)
    {
        float2 i = Hlsl.Floor(p);

        p -= i;

        float4 v = default;

        v.X = Hlsl.Dot(Hash22(i), p);
        v.Y = Hlsl.Dot(Hash22(i + float2.UnitX), p - float2.UnitX);
        v.Z = Hlsl.Dot(Hash22(i + float2.UnitY), p - float2.UnitY);
        v.W = Hlsl.Dot(Hash22(i + 1.0f), p - 1.0f);

        p = p * p * p * (p * (p * 6.0f - 15.0f) + 10.0f);

        return(Hlsl.Lerp(Hlsl.Lerp(v.X, v.Y, p.X), Hlsl.Lerp(v.Z, v.W, p.X), p.Y));
    }
Ejemplo n.º 6
0
    // Smooth 2D noise
    private static float Noise2D(float2 p)
    {
        float2 i = Hlsl.Floor(p);

        p -= i;

        float4 v = default;

        v.X = Hlsl.Dot(Hash22B(i), p);
        v.Y = Hlsl.Dot(Hash22B(i + float2.UnitX), p - float2.UnitX);
        v.Z = Hlsl.Dot(Hash22B(i + float2.UnitY), p - float2.UnitY);
        v.W = Hlsl.Dot(Hash22B(i + 1.0f), p - 1.0f);

        p = p * p * (3.0f - 2.0f * p);

        return(Hlsl.Lerp(Hlsl.Lerp(v.X, v.Y, p.X), Hlsl.Lerp(v.Z, v.W, p.X), p.Y));
    }
        // 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));
        }
Ejemplo n.º 8
0
 // HLSL's port of the GLSL mod intrinsic
 static float Mod(float x, float y)
 {
     return(x - y * Hlsl.Floor(x / y));
 }