Пример #1
0
        private static void HitSpheres(float3 p, ref float curDist, ref float3 normal, ref Material mat)
        {
            float interval = 2f;

            float3 pos = p + new float3(100f, 0f, 100f);

            int2 period = new int2(
                ((int)(pos.x / interval)) % 7,
                ((int)(pos.z / interval)) % 17);

            pos = SDF.ModXZ(pos, new float2(interval, interval)); // Todo: how to make consistent for negative quadrants?

            /*  Todo:
             *  doing the following makes the field discontinuous as the modular boundary is crossed
             *  float3 spherePos = new float3(0f, period % 2, 0f);
             *  need a different way of thinking about instance parameters in repeated space
             *
             *  dont' calculate material/color/normal calculation until after hit is found
             *  do them in a separate function
             */

            float3 spherePos = new float3(0f, 0f, 0f); // location in worldmodxspace
            float  sphereRad = 0.5f;

            pos = pos - spherePos;

            float dist = SDF.Sphere(pos, sphereRad);

            if (dist < curDist)
            {
                curDist = dist;
                normal  = pos / sphereRad;
                mat     = new Material(MaterialType.Metal, new float3(period.x / 7f, 0.75f, period.y / 17f));
            }
        }
Пример #2
0
        private static void HitSphere(float3 p, ref float curDist, ref float3 normal, ref Material mat)
        {
            float3 spherePos = new float3(0f, 21f, -40f);
            float  sphereRad = 20f;
            float3 pos       = p - spherePos;

            float dist = SDF.Sphere(pos, sphereRad);

            if (dist < curDist)
            {
                curDist = dist;
                normal  = pos / sphereRad;
                mat     = new Material(MaterialType.Metal, new float3(0.33f));
            }
        }