Exemple #1
0
        private void Update()
        {
            float       spinAngleDelta = 0.125f * PI * Time.deltaTime;
            FractalPart rootPart       = parts[0][0];

            rootPart.spinAngle    += spinAngleDelta;
            rootPart.worldRotation = mul(transform.rotation,
                                         mul(rootPart.rotation, quaternion.RotateY(rootPart.spinAngle))
                                         );
            rootPart.worldPosition = transform.position;
            parts[0][0]            = rootPart;
            float    objectScale = transform.lossyScale.x;
            float3x3 r           = float3x3(rootPart.worldRotation) * objectScale;

            matrices[0][0] = float3x4(r.c0, r.c1, r.c2, rootPart.worldPosition);

            float     scale     = objectScale;
            JobHandle jobHandle = default;

            for (int li = 1; li < parts.Length; li++)
            {
                scale    *= 0.5f;
                jobHandle = new UpdateFractalLevelJob {
                    spinAngleDelta = spinAngleDelta,
                    scale          = scale,
                    parents        = parts[li - 1],
                    parts          = parts[li],
                    matrices       = matrices[li]
                }.ScheduleParallel(parts[li].Length, 5, jobHandle);
                // job을 계속 등록.
            }
            jobHandle.Complete();             // 등록된 job을 일괄 계산.

            var bounds = new Bounds(rootPart.worldPosition, 3f * objectScale * Vector3.one);

            bounds.extents = Vector3.one * 0.5f;
            for (int i = 0; i < matricesBuffers.Length; i++)
            {
                ComputeBuffer buffer = matricesBuffers[i];
                buffer.SetData(matrices[i]);
                propertyBlock.SetBuffer(matricesId, buffer);
                Graphics.DrawMeshInstancedProcedural(
                    mesh, 0, material, bounds, buffer.count, propertyBlock
                    );
            }
        }
Exemple #2
0
    void Update()
    {
        float spinAngleDelta = 0.125f * PI * Time.deltaTime;

        FractalPart rootPart = parts[0][0];

        rootPart.spinAngle += spinAngleDelta;

        rootPart.worldRotation = mul(transform.rotation,
                                     mul(rootPart.rotation, quaternion.RotateY(rootPart.spinAngle))
                                     );

        parts[0][0] = rootPart;

        float     scale     = ObjectScale;
        JobHandle jobHandle = default;

        for (int li = 1; li < parts.Length; li++)
        {
            scale *= 0.5f;

            jobHandle = new UpdateFractalLevelJob
            {
                spinAngleDelta = spinAngleDelta,
                scale          = scale,
                parents        = parts[li - 1],
                parts          = parts[li],
                matrices       = matrices[li]
            }.ScheduleParallel(parts[li].Length, 1, jobHandle);
        }
        jobHandle.Complete();


        var bounds = new Bounds(Vector3.zero, 3f * ObjectScale * Vector3.one);

        for (int i = 0; i < matricesBuffers.Length; i++)
        {
            ComputeBuffer buffer = matricesBuffers[i];
            buffer.SetData(matrices[i]);
            propertyBlock.SetBuffer(matricesId, buffer);
            material.SetBuffer(matricesId, buffer);
            Graphics.DrawMeshInstancedProcedural(mesh, 0, material, bounds, buffer.count, propertyBlock);
        }
    }
    private void Update()
    {
        float       spinAngleDelta = 0.125f * PI * Time.deltaTime;
        FractalPart rootPart       = parts[0][0];

        rootPart.spinAngle    += spinAngleDelta;
        rootPart.worldRotation = mul(transform.rotation, mul(rootPart.rotation, quaternion.RotateY(rootPart.spinAngle)));
        parts[0][0]            = rootPart; // FractalPart is struct, thus have to reassign to copy the value

        float    objectScale = transform.localScale.x;
        float3x3 r           = float3x3(rootPart.worldRotation) * objectScale;

        matrices[0][0] = float3x4(r.c0, r.c1, r.c2, rootPart.worldPosition);

        float     scale     = objectScale;
        JobHandle jobHandle = default;

        for (int li = 1; li != depth; ++li)
        {
            scale *= 0.5f;

            jobHandle = new UpdateFractalLevelJob()
            {
                spinAngleDelta = spinAngleDelta,
                scale          = scale,
                parents        = parts[li - 1],
                parts          = parts[li],
                matrices       = matrices[li]
            }.ScheduleParallel(parts[li].Length, 10, jobHandle);
        }

        jobHandle.Complete();

        Bounds bounds = new Bounds(rootPart.worldPosition, 3f * objectScale * Vector3.one);

        for (int i = 0; i < matricesBuffers.Length; ++i)
        {
            ComputeBuffer buffer = matricesBuffers[i];
            buffer.SetData(matrices[i]);
            propertyBlock.SetBuffer(matricesId, buffer);
            Graphics.DrawMeshInstancedProcedural(mesh, 0, material, bounds, buffer.count, propertyBlock);
        }
    }
Exemple #4
0
    private void Update()
    {
        float       spinAngleDelta = 0.125f * PI * Time.deltaTime;
        FractalPart rootPart       = parts[0][0];

        rootPart.spinAngle    += spinAngleDelta;
        rootPart.worldRotation = mul(transform.rotation, mul(rootPart.rotation, quaternion.RotateY(rootPart.spinAngle)));
        parts[0][0]            = rootPart; // FractalPart is struct, thus have to reassign to copy the value

        float    objectScale = transform.localScale.x;
        float3x3 r           = float3x3(rootPart.worldRotation) * objectScale;

        matrices[0][0] = float3x4(r.c0, r.c1, r.c2, rootPart.worldPosition);

        float     scale     = objectScale;
        JobHandle jobHandle = default;

        for (int li = 1; li != depth; ++li)
        {
            scale *= 0.5f;

            jobHandle = new UpdateFractalLevelJob()
            {
                spinAngleDelta = spinAngleDelta,
                scale          = scale,
                parents        = parts[li - 1],
                parts          = parts[li],
                matrices       = matrices[li]
            }.ScheduleParallel(parts[li].Length, 10, jobHandle);
        }

        jobHandle.Complete();

        int    leafIndex = matricesBuffers.Length - 1;
        Bounds bounds    = new Bounds(rootPart.worldPosition, 3f * objectScale * Vector3.one);

        for (int i = 0; i < matricesBuffers.Length; ++i)
        {
            Color colorA, colorB = default;
            Mesh  instanceMesh = null;
            if (i == leafIndex)
            {
                colorA       = leafColorA;
                colorB       = leafColorB;
                instanceMesh = leafMesh;
            }
            else
            {
                float gradientInterpolate = i / (matricesBuffers.Length - 1.0f);
                colorA       = gradientA.Evaluate(gradientInterpolate);
                colorB       = gradientB.Evaluate(gradientInterpolate);
                instanceMesh = mesh;
            }

            ComputeBuffer buffer = matricesBuffers[i];
            buffer.SetData(matrices[i]);
            propertyBlock.SetColor(colorAID, colorA);
            propertyBlock.SetColor(colorBID, colorB);
            propertyBlock.SetBuffer(matricesId, buffer);
            propertyBlock.SetVector(sequenceNumbersId, sequenceNumbers[i]);
            Graphics.DrawMeshInstancedProcedural(instanceMesh, 0, material, bounds, buffer.count, propertyBlock);
        }
    }
Exemple #5
0
    void Update()
    {
        float       deltaTime = Time.deltaTime;
        FractalPart rootPart  = parts[0][0];

        rootPart.spinAngle    += rootPart.spinVelocity * deltaTime;
        rootPart.worldRotation = mul(transform.rotation,
                                     mul(rootPart.rotation, quaternion.RotateY(rootPart.spinAngle)));
        rootPart.worldPosition = transform.position;
        parts[0][0]            = rootPart;
        float objectScale = transform.lossyScale.x;

        float3x3 r = float3x3(rootPart.worldRotation) * objectScale;

        matrices[0][0] = float3x4(r.c0, r.c1, r.c2, rootPart.worldPosition);

        float scale = objectScale;

        JobHandle jobHandle = default;

        for (int li = 1; li < parts.Length; li++)
        {
            scale    *= 0.5f;
            jobHandle = new UpdateFractalLevelJob
            {
                deltaTime = deltaTime,
                scale     = scale,
                parents   = parts[li - 1],
                parts     = parts[li],
                matrices  = matrices[li]
            }.ScheduleParallel(parts[li].Length, 5, jobHandle);
        }
        jobHandle.Complete();

        var bounds    = new Bounds(Vector3.zero, 3f * objectScale * Vector3.one);
        int leafIndex = matricesBuffers.Length - 1;

        for (int i = 0; i < matricesBuffers.Length; i++)
        {
            ComputeBuffer buffer = matricesBuffers[i];
            buffer.SetData(matrices[i]);

            Color colorA, colorB;
            Mesh  instanceMesh;
            if (i == leafIndex)
            {
                colorA       = leafColorA;
                colorB       = leafColorB;
                instanceMesh = leafMesh;
            }
            else
            {
                float gradientInterpolator = i / (matricesBuffers.Length - 2f);
                colorA       = gradientA.Evaluate(gradientInterpolator);
                colorB       = gradientB.Evaluate(gradientInterpolator);
                instanceMesh = mesh;
            }
            propertyBlock.SetColor(colorAId, colorA);
            propertyBlock.SetColor(colorBId, colorB);
            propertyBlock.SetBuffer(matricesId, buffer);
            propertyBlock.SetVector(sequenceNumbersId, sequenceNumbers[i]);
            Graphics.DrawMeshInstancedProcedural(
                instanceMesh, 0, material, bounds, buffer.count, propertyBlock);
        }
    }