예제 #1
0
        private unsafe void populateSlice(float *slice, int sliceIndex)
        {
            int   index  = 0;
            float grid4x = GridSize * 4;

            for (int dy = 0; dy < Resolution; dy++)
            {
                float3 position0 = new float3(0, dy * GridSize, sliceIndex * GridSize) + GridCorner;
                float3 position1 = position0 + new float3(GridSize, 0, 0);
                float3 position2 = position1 + new float3(GridSize, 0, 0);
                float3 position3 = position2 + new float3(GridSize, 0, 0);

                for (int dx = 0; dx < Resolution; dx += 4)
                {
                    float4 distances = SDF.Sample(position0, position1, position2, position3);
                    slice[index++] = distances.x;
                    slice[index++] = distances.y;
                    slice[index++] = distances.z;
                    slice[index++] = distances.w;

                    position0.x += grid4x;
                    position1.x += grid4x;
                    position2.x += grid4x;
                    position3.x += grid4x;
                }
            }
        }
예제 #2
0
        public void Execute(int index)
        {
            float x = index % TextureWidth;
            float y = index / TextureWidth;

            float3 pos = RectCorner + x * RectXAxis + y * RectYAxis;

            float dist = SDF.Sample(pos);

            float ring  = smoothstep(0.0f, 0.1f, abs(frac(abs(dist) * 3f) - 0.5f));
            float color = smoothstep(-0.02f, 0.02f, dist);

            Texture[index] = ring * Color.Lerp(new Color(1, 0, 0, 1), new Color(0, 1, 0, 1), color);
        }
예제 #3
0
        private void tryBuildInDirection(int3 cell00, int3 dirA, int3 dirB, int3 normal)
        {
            int3 cell01 = cell00 + dirA;
            int3 cell10 = cell00 + dirB;
            int3 cell11 = cell01 + dirB;

            int index00, index01, index10, index11;

            if (!VertexMap.TryGetValue(cell00, out index00))
            {
                return;
            }
            if (!VertexMap.TryGetValue(cell01, out index01))
            {
                return;
            }
            if (!VertexMap.TryGetValue(cell10, out index10))
            {
                return;
            }
            if (!VertexMap.TryGetValue(cell11, out index11))
            {
                return;
            }

            float3 centerPos0 = (float3)cell11 * GridSize + GridCorner;

            float dist0 = SDF.Sample(centerPos0);

            if (dist0 < 0)
            {
                TriQueue.Enqueue(new int3(index00, index01, index11));
                TriQueue.Enqueue(new int3(index00, index11, index10));
            }
            else
            {
                TriQueue.Enqueue(new int3(index01, index00, index11));
                TriQueue.Enqueue(new int3(index11, index00, index10));
            }
        }