コード例 #1
0
        // 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);
        }
コード例 #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);
    }
コード例 #3
0
    // float2 to float2 hash.
    private float2 Hash22(float2 p)
    {
        float n = Hlsl.Sin(Hlsl.Dot(p, new float2(1, 113)));

        p = Hlsl.Frac(new float2(262144, 32768) * n);

        return(Hlsl.Sin(p * 6.2831853f + time));
    }
コード例 #4
0
    /// <inheritdoc/>
    public float4 Execute()
    {
        float2 uv  = (ThreadIds.XY - (float2)DispatchSize.XY * 0.5f) / DispatchSize.Y;
        float3 col = 0;
        float  t   = time * 0.3f;

        for (float i = 0.0f; i <= 1.0f; i += 1.0f / NumberOfLayers)
        {
            float d = Hlsl.Frac(i + t);
            float s = Hlsl.Lerp(5.0f, 0.5f, d);
            float f = d * Hlsl.SmoothStep(1.0f, 0.9f, d);

            col += Tex(new float3(uv.X * s, uv.Y * s, i * 4.0f)).XYZ *f;
        }

        col /= NumberOfLayers;
        col *= new float3(2, 1.0f, 2.0f);
        col  = Hlsl.Pow(col, 0.5f);

        return(new(col.X, col.Y, col.Z, 1.0f));
    }
コード例 #5
0
 // Fast hash for a pair of floats
 static float Hash21(float2 p)
 {
     return(Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(p, new float2(27.619f, 57.583f))) * 43758.5453f));
 }
コード例 #6
0
    // float2 to float2 hash.
    private static float2 Hash22B(float2 p)
    {
        float n = Hlsl.Sin(Hlsl.Dot(p, new float2(41, 289)));

        return(Hlsl.Frac(new float2(262144, 32768) * n) * 2.0f - 1.0f);
    }
コード例 #7
0
 // float3 to float hash.
 private static float Hash21(float2 p)
 {
     return(Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(p, new float2(41, 289))) * 45758.5453f));
 }