Example #1
0
        public void Stroke(Path2D path)
        {
            PendingDrawCall call = new PendingDrawCall();

            call.effect          = VertigoEffect.Default;
            call.effectDataIndex = call.effect.StoreState(instanceId);
            call.isStroke        = true;
            call.state           = state;
            call.shapeRange      = currentShapeRange;
            pendingDrawCalls.Add(call);
        }
Example #2
0
        public void Fill(VertigoEffect effect)
        {
            if (currentShapeRange.length == 0)
            {
                return;
            }

            PendingDrawCall call = new PendingDrawCall();

            call.state           = state;
            call.isStroke        = false;
            call.shapeRange      = currentShapeRange;
            call.effect          = effect ?? VertigoEffect.Default;
            call.effectDataIndex = effect.StoreState(instanceId);
            pendingDrawCalls.Add(call);
        }
Example #3
0
        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);
            }
        }