예제 #1
0
    public static float4x2 sincos(this Vector4 f4)
    {
        var f = new float4x2();

        math.sincos(f4, out f.c0, out f.c1);
        return(f);
    }
예제 #2
0
 public void Execute()
 {
     for (int i = 0; i < datas.Length; i++)
     {
         matrix[i] = new float4x2(datas[i].transform, datas[i].uv);
     }
 }
예제 #3
0
        public Point4 GetPoint4(int i, float resolution, float invResolution)
        {
            float4x2 uv = IndexTo4UV(i, resolution, invResolution);
            Point4   p;

            p.positions.c0 = uv.c0 - 0.5f;
            p.positions.c1 = uv.c1 - 0.5f;
            p.positions.c2 = 0.5f - abs(p.positions.c0) - abs(p.positions.c1);
            float4 offset = max(-p.positions.c2, 0f);

            p.positions.c0 += select(-offset, offset, p.positions.c0 < 0f);
            p.positions.c1 += select(-offset, offset, p.positions.c1 < 0f);

            float4 scale = 0.5f * rsqrt(
                p.positions.c0 * p.positions.c0 +
                p.positions.c1 * p.positions.c1 +
                p.positions.c2 * p.positions.c2
                );

            p.positions.c0 *= scale;
            p.positions.c1 *= scale;
            p.positions.c2 *= scale;
            p.normals       = p.positions;
            return(p);
        }
예제 #4
0
파일: Ray.cs 프로젝트: DominicMaas/Graphics
    public static Ray CreatePrime(int x, int y, Scene scene, int sample, float4x2 jitterMatrix)
    {
        // Determine X and Y
        var sensorX = (2f * (x + jitterMatrix[sample][0]) / scene.Width) - 1f;
        var sensorY = 1f - (2f * (y + jitterMatrix[sample][1]) / scene.Height);

        // Adjust for the aspect ratio
        var aspectRatio = (float)scene.Width / (float)scene.Height;

        sensorX *= aspectRatio;

        // Adjust for the FOV
        var fovAdjustment = Hlsl.Tan((scene.Camera.FOV * (MathF.PI / 180f)) / 2f);

        sensorX *= fovAdjustment;
        sensorY *= fovAdjustment;

#pragma warning disable IDE0017 // Simplify object initialization
        var ray = new Ray();
        ray.Origin    = new Vector3();
        ray.Direction = Hlsl.Normalize(new float3(sensorX, sensorY, -1.0f));
#pragma warning restore IDE0017 // Simplify object initialization

        return(ray);
    }
 private static void CustomVisit(ref float4x2 f)
 {
     LogVisit(f);
     GUILayout.Label(name);
     EditorGUI.indentLevel++;
     f[0] = EditorGUILayout.Vector4Field("", (Vector4)f[0]);
     f[1] = EditorGUILayout.Vector4Field("", (Vector4)f[1]);
     EditorGUI.indentLevel--;
 }
예제 #6
0
        public Point4 GetPoint4(int i, float resolution, float invResolution)
        {
            float4x2 uv = IndexTo4UV(i, resolution, invResolution);

            return(new Point4
            {
                positions = float4x3(uv.c0 - 0.5f, 0f, uv.c1 - 0.5f),
                normals = float4x3(0f, 1f, 0f)
            });
        }
예제 #7
0
        public Point4 GetPoint4(int i, float resolution, float invResolution)
        {
            float4x2 uv = IndexTo4UV(i, resolution, invResolution);

            float  r1 = 0.375f;
            float  r2 = 0.125f;
            float4 s  = r1 + r2 * cos(2f * PI * uv.c1);

            Point4 p;

            p.positions.c0 = s * sin(2f * PI * uv.c0);
            p.positions.c1 = r2 * sin(2f * PI * uv.c1);
            p.positions.c2 = s * cos(2f * PI * uv.c0);
            p.normals      = p.positions;
            p.normals.c0  -= r1 * sin(2f * PI * uv.c0);
            p.normals.c2  -= r1 * cos(2f * PI * uv.c0);
            return(p);
        }
예제 #8
0
 public static void AreEqual(float4x2 a, float4x2 b, int maxUlp, bool signedZeroEqual)
 {
     AreEqual(a.c0, b.c0, maxUlp, signedZeroEqual);
     AreEqual(a.c1, b.c1, maxUlp, signedZeroEqual);
 }
예제 #9
0
 public static void AreEqual(float4x2 a, float4x2 b, float delta = 0.0f)
 {
     AreEqual(a.c0, b.c0, delta);
     AreEqual(a.c1, b.c1, delta);
 }
예제 #10
0
 public static void AreEqual(float4x2 expected, float4x2 actual, int maxUlp, bool signedZeroEqual)
 {
     AreEqual(expected.c0, actual.c0, maxUlp, signedZeroEqual);
     AreEqual(expected.c1, actual.c1, maxUlp, signedZeroEqual);
 }
예제 #11
0
 public static void AreEqual(float4x2 expected, float4x2 actual, float delta = 0.0f)
 {
     AreEqual(expected.c0, actual.c0, delta);
     AreEqual(expected.c1, actual.c1, delta);
 }
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            var bounds       = chunk.GetNativeArray(BoundsComponent);
            var localToWorld = chunk.GetNativeArray(LocalToWorld);
            var tests        = chunk.GetNativeArray(OcclusionTest);

            var verts = stackalloc float4[16];

            var edges = stackalloc int2[]
            {
                new int2(0, 1), new int2(1, 3), new int2(3, 2), new int2(2, 0),
                new int2(4, 6), new int2(6, 7), new int2(7, 5), new int2(5, 4),
                new int2(4, 0), new int2(2, 6), new int2(1, 5), new int2(7, 3)
            };

            for (var entityIndex = 0; entityIndex < chunk.Count; entityIndex++)
            {
                var aabb          = bounds[entityIndex].Value;
                var occlusionTest = tests[entityIndex];
                var local         = localToWorld[entityIndex].Value;

                // TODO:  optimize
                occlusionTest.screenMin = float.MaxValue;
                occlusionTest.screenMax = -float.MaxValue;

                var mvp = math.mul(ViewProjection, local);

                float4x2 u = new float4x2(mvp.c0 * aabb.Min.x, mvp.c0 * aabb.Max.x);
                float4x2 v = new float4x2(mvp.c1 * aabb.Min.y, mvp.c1 * aabb.Max.y);
                float4x2 w = new float4x2(mvp.c2 * aabb.Min.z, mvp.c2 * aabb.Max.z);

                for (int corner = 0; corner < 8; corner++)
                {
                    float4 p = u[corner & 1] + v[(corner & 2) >> 1] + w[(corner & 4) >> 2] + mvp.c3;
                    p.y           = -p.y;
                    verts[corner] = p;
                }

                int   vertexCount = 8;
                float clipW       = 0.00001f;
                for (int i = 0; i < 12; i++)
                {
                    var e = edges[i];
                    var a = verts[e.x];
                    var b = verts[e.y];

                    if ((a.w < clipW) != (b.w < clipW))
                    {
                        var p = math.lerp(a, b, (clipW - a.w) / (b.w - a.w));
                        verts[vertexCount++] = p;
                    }
                }

                for (int i = 0; i < vertexCount; i++)
                {
                    float4 p = verts[i];
                    if (p.w < clipW)
                    {
                        continue;
                    }

                    p.xyz /= p.w;
                    occlusionTest.screenMin = math.min(occlusionTest.screenMin, p);
                    occlusionTest.screenMax = math.max(occlusionTest.screenMax, p);
                }

                tests[entityIndex] = occlusionTest;
            }
        }
    }
예제 #13
0
 ///Self Dot
 public static float dot(this float4x2 f) => math.dot(f.c0, f.c1);
예제 #14
0
 public static float distancesq(this float4x2 f) => math.distancesq(f.c0, f.c1);