コード例 #1
0
        public override void Draw(Squared.Render.Frame frame)
        {
            const float LightmapScale = 1f;

            LightmapMaterials.ViewportScale    = new Vector2(1f / LightmapScale);
            LightmapMaterials.ProjectionMatrix = Matrix.CreateOrthographicOffCenter(
                0, Width,
                Height, 0,
                0, 1
                );

            ClearBatch.AddNew(frame, 0, Game.ScreenMaterials.Clear, clearColor: Color.Black);

            Renderer.RenderLighting(frame, frame, 1);

            using (var bg = BatchGroup.New(frame, 2)) {
                var dc = new BitmapDrawCall(TestImage, new Vector2(0, 550), 0.55f);

                using (var bb = BitmapBatch.New(bg, 0, Renderer.Materials.ScreenSpaceBitmap))
                    bb.Add(ref dc);

                dc.Position.X += 600;
                dc.Textures    = new TextureSet(dc.Texture, RampTexture);

                using (var bb2 = BitmapBatch.New(bg, 1, Renderer.IlluminantMaterials.ScreenSpaceRampBitmap, samplerState2: SamplerState.LinearClamp))
                    bb2.Add(ref dc);
            }

            if (ShowOutlines)
            {
                Renderer.RenderOutlines(frame, 2, true);
            }
        }
コード例 #2
0
        /// <summary>
        /// Получение сгруппированного по наименованиям списка остатков
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public List <BatchGroup> GetBatches(BatchFilter filter)
        {
            List <BatchGroup> batchGroups = new List <BatchGroup>();
            Guid itemId = filter.ItemId;

            // Получаем все ids всех наименований
            var itemList = _siriusContext.Items.Select(i => new { i.Id, i.Name });

            // Если в фильтре указан itemId, то производим отбор
            var items = itemId != Guid.Empty ? itemList.Where(i => i.Id == filter.ItemId).ToList() : itemList.ToList();

            // Получаем остатки по каждому наименованию
            items.ForEach(i =>
            {
                filter.ItemId = itemId != Guid.Empty ? filter.ItemId : i.Id;

                /** Получаем остатки в зависимости от значения параметра фильтра IsDynamic
                 * Если значение false, то ищем в накопительном регистре StorageRegiter
                 * При значении true высчитываем остатки по всем существующим регистрам проведённых накладных (возможно будет медленно)    */
                BatchGroup batchGroup = new BatchGroup()
                {
                    Name    = i.Name,
                    Batches = filter.IsDynamic == true ? GetDynamicBatchesByFilter(filter).Result : GetStaticBatchesByFilter(filter)
                };
                batchGroups.Add(batchGroup);
            });

            return(batchGroups);
        }
コード例 #3
0
        public IEnumerable <YieldInstruction> RebatchChanges()
        {
            var affectedBatches = new HashSet <BatchScript>();
            var newRenderers    = new HashSet <MeshRenderer>();
            var allRenderers    = getAllMeshRenderers(changedObjects).Distinct();

            foreach (var changedRenderer in allRenderers)
            {
                if (batchLookup.TryGetValue(changedRenderer, out var batch))
                {
                    batch.BatchedRenderers.Remove(changedRenderer);
                    changedRenderer.enabled = true;
                    Object.Destroy(changedRenderer.GetComponent <BatchedMeshScript>());

                    affectedBatches.Add(batch);
                }
                else
                {
                    newRenderers.Add(changedRenderer);
                }
            }

            // Dont do anything with new renderers, but rebatch the old ones
            yield return(null);

            foreach (var f in affectedBatches)
            {
                f.SetMesh(BatchGroup.combineMeshRenderers(f.BatchedRenderers));
            }
        }
コード例 #4
0
        public void RenderOutlines(IBatchContainer container, int layer, bool showLights, Color?lineColor = null, Color?lightColor = null)
        {
            using (var group = BatchGroup.New(container, layer)) {
                using (var gb = GeometryBatch.New(group, 0, IlluminantMaterials.DebugOutlines)) {
                    VisualizerLineWriterInstance.Batch = gb;
                    VisualizerLineWriterInstance.Color = lineColor.GetValueOrDefault(Color.White);

                    foreach (var lo in Environment.Obstructions)
                    {
                        lo.GenerateLines(VisualizerLineWriterInstance);
                    }

                    VisualizerLineWriterInstance.Batch = null;
                }

                int i = 0;

                if (showLights)
                {
                    foreach (var lightSource in Environment.LightSources)
                    {
                        var cMax = lightColor.GetValueOrDefault(Color.White);
                        var cMin = cMax * 0.25f;

                        using (var gb = GeometryBatch.New(group, i + 1, IlluminantMaterials.DebugOutlines)) {
                            gb.AddFilledRing(lightSource.Position, 0f, 2f, cMax, cMax);
                            gb.AddFilledRing(lightSource.Position, lightSource.RampStart - 1f, lightSource.RampStart + 1f, cMax, cMax);
                            gb.AddFilledRing(lightSource.Position, lightSource.RampEnd - 1f, lightSource.RampEnd + 1f, cMin, cMin);
                        }

                        i += 1;
                    }
                }
            }
        }
コード例 #5
0
ファイル: Batching.cs プロジェクト: mmword/MobileFakeLights
    public static void Remove(Transform el, Material mt)
    {
        if (_Instance == null)
        {
            return;
        }

        BatchGroup group = null;

        if (!_Instance.ComponentHasDestroy && _Instance.GroupsByMaterial.TryGetValue(mt, out group))
        {
            int idx = group.Elelemts.FindIndex(x => x.element == el);
            if (idx >= 0)
            {
                group.Elelemts.RemoveAt(idx);
                if (group.Elelemts.Count < 1)
                {
                    group.Release();
                }
                else
                {
                    group.RequireUpdate = true;
                    _Instance.reqToUpdate++;
                }
            }
        }
    }
コード例 #6
0
        public static BatchGroup CreateBatchGroup(string groupId, string serverId)
        {
            BatchGroup batchGroup = new BatchGroup();

            batchGroup.GroupId  = groupId;
            batchGroup.ServerId = serverId;
            return(batchGroup);
        }
コード例 #7
0
ファイル: Batching.cs プロジェクト: mmword/MobileFakeLights
    BatchGroup AllocGroup(string name, Material mat)
    {
        BatchGroup group = null;

        if (!GroupsByMaterial.TryGetValue(mat, out group))
        {
            GroupsByMaterial[mat] = group = new BatchGroup(name, mat);
        }
        return(group);
    }
コード例 #8
0
ファイル: frmWriteOn.cs プロジェクト: radtek/Tradelink
        void SetUp(bool xSel)
        {
            IList <TLKNI_GreigeProduction> Existing = new List <TLKNI_GreigeProduction>();

            formloaded = false;
            CheckFired = false;

            dataGridView2.Rows.Clear();

            using (var context = new TTI2Entities())
            {
                var LNU = context.TLADM_LastNumberUsed.Find(3);
                if (LNU != null)
                {
                    txtNumber.Text = "DA" + LNU.col6.ToString().PadLeft(6, '0');
                }

                if (xSel)
                {
                    var Query = from T1 in context.TLDYE_DyeBatch
                                join T2 in context.TLDYE_DyeBatchDetails on T1.DYEB_Pk equals T2.DYEBD_DyeBatch_FK
                                where !T1.DYEB_Closed && !T1.DYEB_CommissinCust && T1.DYEB_Allocated && T1.DYEB_Transfered && !T2.DYEBO_Rejected && !T2.DYEBO_CutSheet && !T2.DYEBO_WriteOff
                                select new { T1.DYEB_Pk, T1.DYEB_BatchNo, T1.DYEB_DyeOrder_FK, T1.DYEB_Colour_FK, T1.DYEB_Allocated, T1.DYEB_Transfered };

                    var QueryGroup = Query.OrderBy(x => x.DYEB_BatchNo).GroupBy(x => x.DYEB_BatchNo);


                    foreach (var BatchGroup in QueryGroup)
                    {
                        TLDYE_DyeBatch DB = new TLDYE_DyeBatch();
                        DB.DYEB_Pk          = BatchGroup.FirstOrDefault().DYEB_Pk;
                        DB.DYEB_DyeOrder_FK = BatchGroup.FirstOrDefault().DYEB_DyeOrder_FK;
                        DB.DYEB_BatchNo     = BatchGroup.FirstOrDefault().DYEB_BatchNo;
                        DB.DYEB_Colour_FK   = BatchGroup.FirstOrDefault().DYEB_Colour_FK;
                        DB.DYEB_Allocated   = BatchGroup.FirstOrDefault().DYEB_Allocated;
                        DB.DYEB_Transfered  = BatchGroup.FirstOrDefault().DYEB_Transfered;

                        cmboDyeBatches.Items.Add(DB);


                        cmboDyeBatches.ValueMember   = "DYEB_Pk";
                        cmboDyeBatches.DisplayMember = "DYEB_BatchNo";
                    }

                    cmboDyeBatches.SelectedValue = -1;
                }
            }

            MandSelected = core.PopulateArray(MandatoryFields.Length, false);

            formloaded = true;
        }
コード例 #9
0
        public ImperativeRenderer ForRenderTarget(RenderTarget2D renderTarget, Action <DeviceManager, object> before = null, Action <DeviceManager, object> after = null, object userData = null)
        {
            var result = this;
            var group  = BatchGroup.ForRenderTarget(Container, Layer, renderTarget, before, after, userData);

            group.Dispose();
            result.Container = group;
            result.Layer     = 0;

            Layer += 1;

            return(result);
        }
コード例 #10
0
        public ImperativeRenderer MakeSubgroup(bool nextLayer = true, Action <DeviceManager, object> before = null, Action <DeviceManager, object> after = null, object userData = null)
        {
            var result = this;
            var group  = BatchGroup.New(Container, Layer, before: before, after: after, userData: userData);

            group.Dispose();
            result.Container = group;
            result.Layer     = 0;

            if (nextLayer)
            {
                Layer += 1;
            }

            return(result);
        }
コード例 #11
0
        private void frmFabricReversal_Load(object sender, EventArgs e)
        {
            FormLoaded = false;

            dataGridView1.Rows.Clear();

            using (var context = new TTI2Entities())
            {
                var LNU = context.TLADM_LastNumberUsed.Find(3);
                if (LNU != null)
                {
                    txtGrnNumber.Text = "RFREV" + LNU.col7.ToString().PadLeft(6, '0');
                }

                var Query = from T1 in context.TLDYE_DyeBatch
                            join T2 in context.TLDYE_DyeBatchDetails on T1.DYEB_Pk equals T2.DYEBD_DyeBatch_FK
                            where T2.DYEBO_Rejected
                            select new { T1.DYEB_Pk, T1.DYEB_BatchNo, T1.DYEB_DyeOrder_FK, T1.DYEB_Colour_FK };

                var QueryGroup = Query.OrderBy(x => x.DYEB_BatchNo).GroupBy(x => x.DYEB_BatchNo);


                foreach (var BatchGroup in QueryGroup)
                {
                    TLDYE_DyeBatch DB = new TLDYE_DyeBatch();
                    DB.DYEB_Pk          = BatchGroup.FirstOrDefault().DYEB_Pk;
                    DB.DYEB_DyeOrder_FK = BatchGroup.FirstOrDefault().DYEB_DyeOrder_FK;
                    DB.DYEB_BatchNo     = BatchGroup.FirstOrDefault().DYEB_BatchNo;
                    DB.DYEB_Colour_FK   = BatchGroup.FirstOrDefault().DYEB_Colour_FK;

                    cmboBatchNumber.Items.Add(DB);
                }

                cmboBatchNumber.ValueMember   = "DYEB_Pk";
                cmboBatchNumber.DisplayMember = "DYEB_BatchNo";
                cmboBatchNumber.SelectedValue = -1;

                txtBatchFabricKg.Text = "0.0";
                txtBatchGreigeKg.Text = "0.0";

                txtColour.Text          = string.Empty;
                txtCustomerDetails.Text = string.Empty;
                txtDyeOrder.Text        = string.Empty;
            }

            FormLoaded = true;
        }
コード例 #12
0
        void SetUp()
        {
            formloaded = false;
            dataGridView1.Rows.Clear();

            dataGridView1.AllowUserToAddRows  = false;
            dataGridView1.AutoGenerateColumns = false;
            using (var context = new TTI2Entities())
            {
                var LNU = context.TLADM_LastNumberUsed.Find(3);
                if (LNU != null)
                {
                    txtGrnNumber.Text = "RF" + LNU.col7.ToString().PadLeft(6, '0');
                }

                var Query = (from T1 in context.TLDYE_DyeBatch
                             join T2 in context.TLDYE_DyeBatchDetails on T1.DYEB_Pk equals T2.DYEBD_DyeBatch_FK
                             join T3 in context.TLKNI_GreigeProduction on T2.DYEBD_GreigeProduction_FK equals T3.GreigeP_Pk
                             where !T2.DYEBO_Sold && !T2.DYEBO_Rejected && !T2.DYEBO_CutSheet && !T2.DYEBO_QAApproved && T1.DYEB_OutProcess && T1.DYEB_Allocated && !T1.DYEB_CommissinCust && T3.GreigeP_Dye
                             select T1).OrderBy(x => x.DYEB_BatchNo).GroupBy(x => x.DYEB_BatchNo);

                foreach (var BatchGroup in Query)
                {
                    TLDYE_DyeBatch DB = new TLDYE_DyeBatch();
                    DB.DYEB_Pk          = BatchGroup.FirstOrDefault().DYEB_Pk;
                    DB.DYEB_BatchNo     = BatchGroup.FirstOrDefault().DYEB_BatchNo;
                    DB.DYEB_DyeOrder_FK = BatchGroup.FirstOrDefault().DYEB_DyeOrder_FK;
                    DB.DYEB_Colour_FK   = BatchGroup.FirstOrDefault().DYEB_Colour_FK;

                    cmboBatchNumber.Items.Add(DB);
                }

                cmboBatchNumber.ValueMember   = "DYEB_Pk";
                cmboBatchNumber.DisplayMember = "DYEB_BatchNo";
            }

            txtBatchFabricKg.Text = "0.0";
            txtBatchGreigeKg.Text = "0.0";

            txtColour.Text          = string.Empty;
            txtCustomerDetails.Text = string.Empty;
            txtDyeOrder.Text        = string.Empty;

            formloaded = true;
        }
コード例 #13
0
ファイル: Game.cs プロジェクト: sq/FNATest
        public override void Draw(GameTime gameTime, Frame frame)
        {
            using (var rtb = BatchGroup.ForRenderTarget(frame, -1, Rt)) {
                var ir = new ImperativeRenderer(rtb, Materials);
                ir.Clear(color: Color.Transparent);
                ir.SetViewport(new Rectangle(128, 128, 256, 256), true);
                ir.FillRectangle(new Rectangle(0, 0, 512, 512), Color.Black, customMaterial: Vpos);
            }

            {
                var ir = new ImperativeRenderer(frame, Materials)
                {
                    AutoIncrementLayer = true
                };
                ir.SetViewport(null, true);
                ir.Clear(color: Color.SteelBlue);
                const float scale = 0.65f;
                var         pos   = new Vector2(Graphics.PreferredBackBufferWidth, Graphics.PreferredBackBufferHeight) / 2f;
                ir.Draw(
                    Texture, pos, origin: Vector2.One * 0.5f, scale: Vector2.One * scale,
                    blendState: BlendState.Opaque,
                    samplerState: SamplerState.LinearClamp
                    );

                ir.DrawString(
                    Font, "Hello, World!", Vector2.Zero,
                    blendState: BlendState.AlphaBlend,
                    material: Materials.ScreenSpaceShadowedBitmap
                    );

                var sg = ir.MakeSubgroup();
                sg.AutoIncrementLayer = true;
                sg.SetViewport(new Rectangle(128, 128, 512, 512), true);
                sg.FillRectangle(new Rectangle(0, 0, 1024, 1024), Color.Black, customMaterial: Vpos);
                sg.SetViewport(null, true);

                ir.Draw(
                    Rt, new Vector2(1920 - 512, 0)
                    );
            }
        }
コード例 #14
0
ファイル: frmFinalApproval.cs プロジェクト: radtek/Tradelink
        void Setup()
        {
            formloaded = false;

            dataGridView1.Rows.Clear();

            using (var context = new TTI2Entities())
            {
                var Query = from T1 in context.TLDYE_DyeBatch
                            join T2 in context.TLDYE_DyeBatchDetails on T1.DYEB_Pk equals T2.DYEBD_DyeBatch_FK
                            where !T2.DYEBO_QAApproved && !T1.DYEB_OnHold
                            select new { T1.DYEB_Pk, T1.DYEB_BatchNo, T1.DYEB_DyeOrder_FK, T1.DYEB_Colour_FK };

                var QueryGroup = Query.OrderBy(x => x.DYEB_BatchNo).GroupBy(x => x.DYEB_BatchNo);

                foreach (var BatchGroup in QueryGroup)
                {
                    TLDYE_DyeBatch DB = new TLDYE_DyeBatch();
                    DB.DYEB_Pk          = BatchGroup.FirstOrDefault().DYEB_Pk;
                    DB.DYEB_DyeOrder_FK = BatchGroup.FirstOrDefault().DYEB_DyeOrder_FK;
                    DB.DYEB_BatchNo     = BatchGroup.FirstOrDefault().DYEB_BatchNo;
                    DB.DYEB_Colour_FK   = BatchGroup.FirstOrDefault().DYEB_Colour_FK;

                    cmboBatchNumber.Items.Add(DB);
                }

                cmboBatchNumber.ValueMember   = "DYEB_Pk";
                cmboBatchNumber.DisplayMember = "DYEB_BatchNo";
                cmboBatchNumber.SelectedValue = -1;
            }

            txtBatchFabricKg.Text = "0.0";
            txtBatchGreigeKg.Text = "0.0";

            txtColour.Text          = string.Empty;
            txtCustomerDetails.Text = string.Empty;
            txtDyeOrder.Text        = string.Empty;

            formloaded = true;
        }
コード例 #15
0
        public override void Draw(Squared.Render.Frame frame)
        {
            const float LightmapScale = 1f;

            LightmapMaterials.ViewportScale    = new Vector2(1f / LightmapScale);
            LightmapMaterials.ProjectionMatrix = Matrix.CreateOrthographicOffCenter(
                0, Width,
                Height, 0,
                0, 1
                );

            CreateRenderTargets();

            var args = new float[] {
                MagnitudeScale, MiddleGray, AppliedAverageLuminance, MaximumLuminance
            };

            using (var bg = BatchGroup.ForRenderTarget(
                       frame, -1, Lightmap,
                       (dm, _) =>
                       Renderer.IlluminantMaterials.SetGammaCompressionParameters(args[0], args[1], args[2], args[3])
                       )) {
                ClearBatch.AddNew(bg, 0, LightmapMaterials.Clear, clearColor: Color.Black, clearZ: 0, clearStencil: 0);

                Renderer.RenderLighting(frame, bg, 1, intensityScale: 1 / MagnitudeScale);
            };

            ClearBatch.AddNew(frame, 0, Game.ScreenMaterials.Clear, clearColor: Color.Black);

            using (var bb = BitmapBatch.New(
                       frame, 1,
                       Game.ScreenMaterials.Get(Renderer.IlluminantMaterials.ScreenSpaceGammaCompressedBitmap, blendState: BlendState.Opaque)
                       ))
                bb.Add(new BitmapDrawCall(Lightmap, Vector2.Zero));

            if (ShowOutlines)
            {
                Renderer.RenderOutlines(frame, 2, true);
            }
        }
コード例 #16
0
        private void FlushPointLightBatch(ref BatchGroup lightGroup, ref LightSource batchFirstLightSource, ref int layerIndex)
        {
            if (lightGroup == null)
            {
                return;
            }

            Material material;

            if (batchFirstLightSource.RampTexture != null)
            {
                material = batchFirstLightSource.RampMode == LightSourceRampMode.Linear
                    ? IlluminantMaterials.PointLightLinearRampTexture
                    : IlluminantMaterials.PointLightExponentialRampTexture;
            }
            else
            {
                material = batchFirstLightSource.RampMode == LightSourceRampMode.Linear
                    ? IlluminantMaterials.PointLightLinear
                    : IlluminantMaterials.PointLightExponential;
            }

            using (var pb = PrimitiveBatch <PointLightVertex> .New(lightGroup, layerIndex++, material, IlluminationBatchSetup, batchFirstLightSource)) {
                foreach (var record in PointLightBatchBuffer)
                {
                    var pointLightDrawCall = new PrimitiveDrawCall <PointLightVertex>(
                        PrimitiveType.TriangleList, PointLightVertices, record.VertexOffset, record.VertexCount, PointLightIndices, record.IndexOffset, record.IndexCount / 3
                        );
                    pb.Add(pointLightDrawCall);
                }
            }

            lightGroup.Dispose();
            lightGroup            = null;
            batchFirstLightSource = null;
            PointLightBatchBuffer.Clear();
        }
コード例 #17
0
        public async Task UpsertStateAsync(GrainIdentity grainIdentity, object state)
        {
            // for this specific type of grain choose the batch
            // Lazy is used to avoid side effects since valueFactory() may be called multiple times on different threads
            var writeGroup = _writeGroups.GetOrAdd(grainIdentity.GrainType, _ => new Lazy <BatchGroup <WriteEntry> >(() =>
            {
                var group = new BatchGroup <WriteEntry>();

                group.BatchBlock = new BatchBlock <WriteEntry>(BatchSize,
                                                               new GroupingDataflowBlockOptions()
                {
                    Greedy = true, BoundedCapacity = BatchSize * 2
                });
                group.FlushTimer = new Timer(group.FlushBatch, null, TimeSpan.FromSeconds(BatchTimeoutSeconds), TimeSpan.FromSeconds(BatchTimeoutSeconds));
                group.Link       = group.BatchBlock.LinkTo(_writeActionBlock);

                Logger.Info("Created WriteGroup for {0} on {1}", grainIdentity.GrainType, _shard.Location.Database);
                return(group);
            })).Value;

            TaskCompletionSource <int> tcs = new TaskCompletionSource <int>();

            // use SendAsync instead of Post to allow for buffering posted messages
            // Post would retrun false when the Block cannot accept a message
            if (await writeGroup.BatchBlock.SendAsync(new WriteEntry(grainIdentity, state, tcs)))
            {
                InstrumentationContext.WritePosted();
            }
            else
            {
                tcs.SetException(new ApplicationException("SendAsync did not accept the message"));
                Logger.Error("UpsertStateAsync batchBlock.SendAsync did not acccept the message");
                InstrumentationContext.WritePostFailed();
            }

            await tcs.Task;
        }
コード例 #18
0
        /// <summary>
        /// Renders all light sources into the target batch container on the specified layer.
        /// </summary>
        /// <param name="frame">Necessary for bookkeeping.</param>
        /// <param name="container">The batch container to render lighting into.</param>
        /// <param name="layer">The layer to render lighting into.</param>
        /// <param name="intensityScale">A factor to scale the intensity of all light sources. You can use this to rescale the intensity of light values for HDR.</param>
        public void RenderLighting(Frame frame, IBatchContainer container, int layer, float intensityScale = 1.0f)
        {
            // FIXME
            var pointLightVertexCount = Environment.LightSources.Count * 4;
            var pointLightIndexCount  = Environment.LightSources.Count * 6;

            if (PointLightVertices.Length < pointLightVertexCount)
            {
                PointLightVertices = new PointLightVertex[1 << (int)Math.Ceiling(Math.Log(pointLightVertexCount, 2))];
            }

            if ((PointLightIndices == null) || (PointLightIndices.Length < pointLightIndexCount))
            {
                PointLightIndices = new short[pointLightIndexCount];

                int i = 0, j = 0;
                while (i < pointLightIndexCount)
                {
                    PointLightIndices[i++] = (short)(j + 0);
                    PointLightIndices[i++] = (short)(j + 1);
                    PointLightIndices[i++] = (short)(j + 3);
                    PointLightIndices[i++] = (short)(j + 1);
                    PointLightIndices[i++] = (short)(j + 2);
                    PointLightIndices[i++] = (short)(j + 3);

                    j += 4;
                }
            }

            var         needStencilClear = true;
            int         vertexOffset = 0, indexOffset = 0;
            LightSource batchFirstLightSource = null;
            BatchGroup  currentLightGroup     = null;

            int layerIndex = 0;

            using (var sortedLights = BufferPool <LightSource> .Allocate(Environment.LightSources.Count))
                using (var resultGroup = BatchGroup.New(container, layer, before: StoreScissorRect, after: RestoreScissorRect)) {
                    if (Render.Tracing.RenderTrace.EnableTracing)
                    {
                        Render.Tracing.RenderTrace.Marker(resultGroup, -9999, "Frame {0:0000} : LightingRenderer {1:X4} : Begin", frame.Index, this.GetHashCode());
                    }

                    int i          = 0;
                    var lightCount = Environment.LightSources.Count;

                    foreach (var lightSource in Environment.LightSources)
                    {
                        sortedLights.Data[i++] = lightSource;
                    }

                    Array.Sort(sortedLights.Data, 0, lightCount, LightSourceComparerInstance);

                    int lightGroupIndex = 1;

                    for (i = 0; i < lightCount; i++)
                    {
                        var lightSource = sortedLights.Data[i];

                        if (lightSource.Opacity <= 0)
                        {
                            continue;
                        }

                        if (batchFirstLightSource != null)
                        {
                            var needFlush =
                                (needStencilClear) ||
                                (batchFirstLightSource.ClipRegion.HasValue != lightSource.ClipRegion.HasValue) ||
                                (batchFirstLightSource.NeutralColor != lightSource.NeutralColor) ||
                                (batchFirstLightSource.Mode != lightSource.Mode) ||
                                (batchFirstLightSource.RampMode != lightSource.RampMode) ||
                                (batchFirstLightSource.RampTexture != lightSource.RampTexture) ||
                                (batchFirstLightSource.RampTextureFilter != lightSource.RampTextureFilter);

                            if (needFlush)
                            {
                                if (Render.Tracing.RenderTrace.EnableTracing)
                                {
                                    Render.Tracing.RenderTrace.Marker(currentLightGroup, layerIndex++, "Frame {0:0000} : LightingRenderer {1:X4} : Point Light Flush ({2} point(s))", frame.Index, this.GetHashCode(), PointLightBatchBuffer.Count);
                                }
                                FlushPointLightBatch(ref currentLightGroup, ref batchFirstLightSource, ref layerIndex);
                                indexOffset = 0;
                            }
                        }

                        if (batchFirstLightSource == null)
                        {
                            batchFirstLightSource = lightSource;
                        }
                        if (currentLightGroup == null)
                        {
                            currentLightGroup = BatchGroup.New(resultGroup, lightGroupIndex++, before: RestoreScissorRect);
                        }

                        var lightBounds = new Bounds(lightSource.Position - new Vector2(lightSource.RampEnd), lightSource.Position + new Vector2(lightSource.RampEnd));

                        Bounds clippedLightBounds;
                        if (lightSource.ClipRegion.HasValue)
                        {
                            var clipBounds = lightSource.ClipRegion.Value;
                            if (!lightBounds.Intersection(ref lightBounds, ref clipBounds, out clippedLightBounds))
                            {
                                continue;
                            }
                        }
                        else
                        {
                            clippedLightBounds = lightBounds;
                        }

                        if (needStencilClear)
                        {
                            if (Render.Tracing.RenderTrace.EnableTracing)
                            {
                                Render.Tracing.RenderTrace.Marker(currentLightGroup, layerIndex++, "Frame {0:0000} : LightingRenderer {1:X4} : Stencil Clear", frame.Index, this.GetHashCode());
                            }
                            ClearBatch.AddNew(currentLightGroup, layerIndex++, IlluminantMaterials.ClearStencil, clearStencil: StencilFalse);
                            needStencilClear = false;
                        }

                        NativeBatch stencilBatch = null;
                        SpatialCollection <LightObstructionBase> .Sector currentSector;
                        using (var e = Environment.Obstructions.GetSectorsFromBounds(lightBounds))
                            while (e.GetNext(out currentSector))
                            {
                                var cachedSector = GetCachedSector(frame, currentSector.Index);
                                if (cachedSector.VertexCount <= 0)
                                {
                                    continue;
                                }

                                if (stencilBatch == null)
                                {
                                    if (Render.Tracing.RenderTrace.EnableTracing)
                                    {
                                        Render.Tracing.RenderTrace.Marker(currentLightGroup, layerIndex++, "Frame {0:0000} : LightingRenderer {1:X4} : Begin Stencil Shadow Batch", frame.Index, this.GetHashCode());
                                    }

                                    stencilBatch = NativeBatch.New(currentLightGroup, layerIndex++, IlluminantMaterials.Shadow, ShadowBatchSetup, lightSource);
                                    stencilBatch.Dispose();
                                    needStencilClear = true;

                                    if (Render.Tracing.RenderTrace.EnableTracing)
                                    {
                                        Render.Tracing.RenderTrace.Marker(currentLightGroup, layerIndex++, "Frame {0:0000} : LightingRenderer {1:X4} : End Stencil Shadow Batch", frame.Index, this.GetHashCode());
                                    }
                                }

                                stencilBatch.Add(new NativeDrawCall(
                                                     PrimitiveType.TriangleList, cachedSector.ObstructionVertexBuffer, 0, cachedSector.ObstructionIndexBuffer, 0, 0, cachedSector.VertexCount, 0, cachedSector.PrimitiveCount
                                                     ));
                            }

                        PointLightVertex vertex;

                        vertex.LightCenter = lightSource.Position;
                        vertex.Color       = lightSource.Color;
                        vertex.Color.W    *= (lightSource.Opacity * intensityScale);
                        vertex.Ramp        = new Vector2(lightSource.RampStart, lightSource.RampEnd);

                        vertex.Position = clippedLightBounds.TopLeft;
                        PointLightVertices[vertexOffset++] = vertex;

                        vertex.Position = clippedLightBounds.TopRight;
                        PointLightVertices[vertexOffset++] = vertex;

                        vertex.Position = clippedLightBounds.BottomRight;
                        PointLightVertices[vertexOffset++] = vertex;

                        vertex.Position = clippedLightBounds.BottomLeft;
                        PointLightVertices[vertexOffset++] = vertex;

                        var newRecord = new PointLightRecord {
                            VertexOffset = vertexOffset - 4,
                            IndexOffset  = indexOffset,
                            VertexCount  = 4,
                            IndexCount   = 6
                        };

                        if (PointLightBatchBuffer.Count > 0)
                        {
                            var oldRecord = PointLightBatchBuffer[PointLightBatchBuffer.Count - 1];

                            if (
                                (newRecord.VertexOffset == oldRecord.VertexOffset + oldRecord.VertexCount) &&
                                (newRecord.IndexOffset == oldRecord.IndexOffset + oldRecord.IndexCount)
                                )
                            {
                                oldRecord.VertexCount += newRecord.VertexCount;
                                oldRecord.IndexCount  += newRecord.IndexCount;
                                PointLightBatchBuffer[PointLightBatchBuffer.Count - 1] = oldRecord;
                            }
                            else
                            {
                                PointLightBatchBuffer.Add(newRecord);
                            }
                        }
                        else
                        {
                            PointLightBatchBuffer.Add(newRecord);
                        }

                        indexOffset += 6;
                    }

                    if (PointLightBatchBuffer.Count > 0)
                    {
                        if (Render.Tracing.RenderTrace.EnableTracing)
                        {
                            Render.Tracing.RenderTrace.Marker(currentLightGroup, layerIndex++, "Frame {0:0000} : LightingRenderer {1:X4} : Point Light Flush ({2} point(s))", frame.Index, this.GetHashCode(), PointLightBatchBuffer.Count);
                        }

                        FlushPointLightBatch(ref currentLightGroup, ref batchFirstLightSource, ref layerIndex);
                    }

                    if (Render.Tracing.RenderTrace.EnableTracing)
                    {
                        Render.Tracing.RenderTrace.Marker(resultGroup, 9999, "Frame {0:0000} : LightingRenderer {1:X4} : End", frame.Index, this.GetHashCode());
                    }
                }
        }
コード例 #19
0
        public override void Draw(Squared.Render.Frame frame)
        {
            CreateRenderTargets();

            LightmapMaterials.ViewportScale    = new Vector2(1f / LightmapScale);
            LightmapMaterials.ProjectionMatrix = Matrix.CreateOrthographicOffCenter(
                0, BackgroundLightmap.Width,
                BackgroundLightmap.Height, 0,
                0, 1
                );

            using (var backgroundGroup = BatchGroup.ForRenderTarget(frame, 0, Background)) {
                ClearBatch.AddNew(backgroundGroup, 1, Game.ScreenMaterials.Clear, clearColor: Color.Transparent);

                using (var bb = BitmapBatch.New(backgroundGroup, 2, Game.ScreenMaterials.WorldSpaceBitmap)) {
                    for (var i = 0; i < 1; i++)
                    {
                        var layer = Layers[i];
                        var dc    = new BitmapDrawCall(layer, Vector2.Zero);
                        dc.SortKey = i;
                        bb.Add(dc);
                    }
                }
            }

            using (var foregroundGroup = BatchGroup.ForRenderTarget(frame, 1, Foreground)) {
                ClearBatch.AddNew(foregroundGroup, 1, Game.ScreenMaterials.Clear, clearColor: Color.Transparent);

                using (var bb = BitmapBatch.New(foregroundGroup, 2, Game.ScreenMaterials.WorldSpaceBitmap)) {
                    for (var i = 1; i < Layers.Length; i++)
                    {
                        var layer = Layers[i];
                        var dc    = new BitmapDrawCall(layer, Vector2.Zero);
                        dc.SortKey = i;
                        bb.Add(dc);
                    }
                }
            }

            using (var backgroundLightGroup = BatchGroup.ForRenderTarget(frame, 4, BackgroundLightmap)) {
                ClearBatch.AddNew(backgroundLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(32, 32, 32, 255), clearZ: 0, clearStencil: 0);
                BackgroundRenderer.RenderLighting(frame, backgroundLightGroup, 2);
            }

            using (var foregroundLightGroup = BatchGroup.ForRenderTarget(frame, 5, ForegroundLightmap)) {
                ClearBatch.AddNew(foregroundLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(96, 96, 96, 255), clearZ: 0, clearStencil: 0);
                ForegroundRenderer.RenderLighting(frame, foregroundLightGroup, 2);
            }

            SetRenderTargetBatch.AddNew(frame, 49, null);
            ClearBatch.AddNew(frame, 50, Game.ScreenMaterials.Clear, clearColor: Color.Black, clearZ: 0, clearStencil: 0);

            if (ShowLightmap)
            {
                using (var bb = BitmapBatch.New(frame, 55, Game.ScreenMaterials.WorldSpaceBitmap)) {
                    var dc = new BitmapDrawCall(BackgroundLightmap, Vector2.Zero, LightmapScale);
                    bb.Add(dc);
                }

                ParticleRenderer.Draw(frame, 56);
            }
            else
            {
                var dc = new BitmapDrawCall(Background, Vector2.Zero);

                var material = LightmapMaterials.Get(LightmapMaterials.WorldSpaceLightmappedBitmap, blendState: BlendState.AlphaBlend);

                using (var bb = BitmapBatch.New(frame, 55, material)) {
                    dc.Textures = new TextureSet(Background, BackgroundLightmap);
                    dc.SortKey  = 0;

                    bb.Add(dc);
                }

                ParticleRenderer.Draw(frame, 56);

                using (var bb = BitmapBatch.New(frame, 57, material)) {
                    dc.Textures = new TextureSet(Foreground, ForegroundLightmap);
                    dc.SortKey  = 1;

                    bb.Add(dc);
                }
            }

            if (ShowOutlines || (Dragging != null))
            {
                BackgroundRenderer.RenderOutlines(frame, 59, true);
            }
        }
コード例 #20
0
        public override void Draw(Squared.Render.Frame frame)
        {
            CreateRenderTargets();

            LightmapMaterials.ViewportScale    = new Vector2(1f / LightmapScale);
            LightmapMaterials.ProjectionMatrix = Matrix.CreateOrthographicOffCenter(
                0, BackgroundLightmap.Width,
                BackgroundLightmap.Height, 0,
                0, 1
                );

            using (var backgroundGroup = BatchGroup.ForRenderTarget(frame, 0, Background)) {
                ClearBatch.AddNew(backgroundGroup, 1, Game.ScreenMaterials.Clear, clearColor: Color.Transparent);

                using (var bb = BitmapBatch.New(backgroundGroup, 2, Game.ScreenMaterials.WorldSpaceBitmap)) {
                    for (var i = 0; i < 1; i++)
                    {
                        var layer = Layers[i];
                        var dc    = new BitmapDrawCall(layer, Vector2.Zero);
                        dc.SortKey = i;
                        bb.Add(dc);
                    }
                }
            }

            using (var foregroundGroup = BatchGroup.ForRenderTarget(frame, 1, Foreground)) {
                ClearBatch.AddNew(foregroundGroup, 1, Game.ScreenMaterials.Clear, clearColor: Color.Transparent);

                using (var bb = BitmapBatch.New(foregroundGroup, 2, Game.ScreenMaterials.WorldSpaceBitmap)) {
                    for (var i = 1; i < Layers.Length; i++)
                    {
                        var layer = Layers[i];
                        var dc    = new BitmapDrawCall(layer, Vector2.Zero);
                        dc.SortKey = i;
                        bb.Add(dc);
                    }
                }
            }

            if (ShowBrickSpecular)
            {
                using (var bricksLightGroup = BatchGroup.ForRenderTarget(frame, 2, ForegroundLightmap)) {
                    ClearBatch.AddNew(bricksLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(0, 0, 0, 255), clearZ: 0, clearStencil: 0);
                    ForegroundRenderer.RenderLighting(frame, bricksLightGroup, 2);
                }
            }

            if (ShowAOShadow)
            {
                using (var aoShadowFirstPassGroup = BatchGroup.ForRenderTarget(frame, 3, AOShadowScratch)) {
                    ClearBatch.AddNew(aoShadowFirstPassGroup, 1, LightmapMaterials.Clear, clearColor: Color.Transparent);

                    using (var bb = BitmapBatch.New(aoShadowFirstPassGroup, 2, Game.ScreenMaterials.ScreenSpaceHorizontalGaussianBlur5Tap)) {
                        bb.Add(new BitmapDrawCall(Foreground, Vector2.Zero, 1f / LightmapScale));
                    }
                }
            }

            using (var backgroundLightGroup = BatchGroup.ForRenderTarget(frame, 4, BackgroundLightmap)) {
                ClearBatch.AddNew(backgroundLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(40, 40, 40, 255), clearZ: 0, clearStencil: 0);

                BackgroundRenderer.RenderLighting(frame, backgroundLightGroup, 2);

                if (ShowBrickSpecular)
                {
                    using (var foregroundLightBatch = BitmapBatch.New(backgroundLightGroup, 3, MaskedForegroundMaterial)) {
                        var dc = new BitmapDrawCall(
                            ForegroundLightmap, Vector2.Zero
                            );
                        dc.Textures = new TextureSet(dc.Textures.Texture1, BricksLightMask);
                        foregroundLightBatch.Add(dc);
                    }
                }
                else
                {
                    ForegroundRenderer.RenderLighting(frame, backgroundLightGroup, 3);
                }

                if (ShowAOShadow)
                {
                    using (var aoShadowBatch = BitmapBatch.New(backgroundLightGroup, 4, AOShadowMaterial)) {
                        var dc = new BitmapDrawCall(
                            AOShadowScratch, new Vector2(0, 4)
                            );
                        dc.MultiplyColor = Color.Black;
                        dc.AddColor      = Color.White;

                        aoShadowBatch.Add(dc);
                    }
                }
            }

            using (var foregroundLightGroup = BatchGroup.ForRenderTarget(frame, 5, ForegroundLightmap)) {
                ClearBatch.AddNew(foregroundLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(127, 127, 127, 255), clearZ: 0, clearStencil: 0);
                ForegroundRenderer.RenderLighting(frame, foregroundLightGroup, 2);
            }

            SetRenderTargetBatch.AddNew(frame, 49, null);
            ClearBatch.AddNew(frame, 50, Game.ScreenMaterials.Clear, clearColor: Color.Black, clearZ: 0, clearStencil: 0);

            if (ShowLightmap)
            {
                using (var bb = BitmapBatch.New(frame, 55, Game.ScreenMaterials.WorldSpaceBitmap)) {
                    var dc = new BitmapDrawCall(BackgroundLightmap, Vector2.Zero, LightmapScale);
                    bb.Add(dc);
                }
            }
            else
            {
                var dc = new BitmapDrawCall(Background, Vector2.Zero);

                var material = LightmapMaterials.Get(LightmapMaterials.WorldSpaceLightmappedBitmap, blendState: BlendState.AlphaBlend);

                using (var bb = BitmapBatch.New(frame, 55, material)) {
                    dc.Textures = new TextureSet(Background, BackgroundLightmap);
                    dc.SortKey  = 0;

                    bb.Add(dc);
                }

                ParticleRenderer.Draw(frame, 56);

                using (var bb = BitmapBatch.New(frame, 57, material)) {
                    dc.Textures = new TextureSet(Foreground, ForegroundLightmap);
                    dc.SortKey  = 1;

                    bb.Add(dc);
                }
            }

            if (ShowOutlines || (Dragging != null))
            {
                BackgroundRenderer.RenderOutlines(frame, 59, true);
            }
        }