예제 #1
0
파일: MeshSlice.cs 프로젝트: weichx/Vertigo
        internal MeshSlice(ShapeBatch batch, int shapeIdx)
        {
            ShapeMeshData[] array     = batch.shapeList.Array;
            MeshRange       meshRange = array[shapeIdx].meshRange;

            this.batch         = batch;
            this.bounds        = array[shapeIdx].bounds;
            this.type          = array[shapeIdx].shapeType;
            this.vertexCount   = meshRange.vertexRange.length;
            this.triangleCount = meshRange.triangleRange.length;
            this.vertexStart   = meshRange.vertexRange.start;
            this.triangleStart = meshRange.triangleRange.start;
        }
예제 #2
0
파일: Vertigo.cs 프로젝트: weichx/Vertigo
        public void Render(Camera camera, RenderTexture targetTexture = null, bool clear = true)
        {
            for (int i = 0; i < issuedDrawCalls.Count; i++)
            {
                issuedDrawCalls[i].effect.ReleaseMaterial(issuedDrawCalls[i].drawCallId, issuedDrawCalls[i].material);
            }

            issuedDrawCalls.Clear();

            int drawCallId = instanceId;

            shapeBatchPool.ReleaseAll();

            ShapeBatch shapeBatch = shapeBatchPool.Get(parameterTexture);

            Vector3 offset = camera.transform.position;

            offset.z = -2;
            Matrix4x4 rootMatrix = Matrix4x4.TRS(offset, Quaternion.identity, Vector3.one);

            int drawCallCount = this.pendingDrawCalls.Count;

            PendingDrawCall[] pendingCalls = pendingDrawCalls.Array;

            VertigoEffect  currentEffect  = VertigoEffect.Default;
            IssuedDrawCall issuedDrawCall = default;

            issuedDrawCalls.EnsureCapacity(drawCallCount);

            for (int i = 0; i < drawCallCount; i++)
            {
                PendingDrawCall pendingDrawCall = pendingCalls[i];

                // do culling unless current effect wants to do culling itself (for things like shadow which render outside shape's bounds)
                // should maybe handle culling for masking if using aligned rect mask w/o texture

                // Cull(drawCall)

                if (pendingDrawCall.isStroke)
                {
                    Geometry.CreateStrokeGeometry(shapeBatch, pendingDrawCall.shapeRange, shapes, shapeData);
                }
                else
                {
                    Geometry.CreateFillGeometry(shapeBatch, pendingDrawCall.shapeRange, shapes, shapeData);
                }

                // draw current effect now if we need to
                // change this to a vertex check
                if (currentEffect != pendingDrawCall.effect && shapeBatch.finalPositionList.Count > 0)
                {
                    issuedDrawCall            = new IssuedDrawCall();
                    issuedDrawCall.drawCallId = drawCallId++;
                    issuedDrawCall.effect     = currentEffect;
                    issuedDrawCall.batch      = shapeBatch;
                    issuedDrawCall.state      = state;
                    issuedDrawCalls.AddUnsafe(issuedDrawCall);

                    shapeBatch = shapeBatchPool.Get(parameterTexture);
                }

                currentEffect = pendingDrawCall.effect;
                int start = pendingDrawCall.shapeRange.start;
                int end   = pendingDrawCall.shapeRange.end;

                for (int j = start; j < end; j++)
                {
                    MeshSlice slice = new MeshSlice(shapeBatch, j);
                    pendingDrawCall.effect.Apply(shapeBatch, slice, state, pendingDrawCall.effectDataIndex);
                    slice.batch = null;
                }
            }

            issuedDrawCall            = new IssuedDrawCall();
            issuedDrawCall.drawCallId = drawCallId++;
            issuedDrawCall.effect     = currentEffect;
            issuedDrawCall.batch      = shapeBatch;
            issuedDrawCall.state      = state;
            issuedDrawCalls.AddUnsafe(issuedDrawCall);

            shapeBatchPool.Release(shapeBatch);

            shapeBatch = null;

            IssuedDrawCall[] issuedCalls = issuedDrawCalls.array;
            int issuedCount = issuedDrawCalls.size;

            parameterTexture.Upload();

            for (int i = 0; i < issuedCount; i++)
            {
                drawCallId = issuedCalls[i].drawCallId;
                Mesh     mesh     = issuedCalls[i].batch.GetBakedMesh();
                Material material = issuedCalls[i].effect.GetMaterialToDraw(drawCallId, issuedCalls[i].state, issuedCalls[i].batch, block);
                Graphics.DrawMesh(mesh, rootMatrix, material, 0, camera, 0, block, ShadowCastingMode.Off, false, null, LightProbeUsage.Off);
            }
        }