public void OnFrame()
        {
            if (mSkipRendering)
            {
                return;
            }

            if (mIsSyncLoaded == false)
            {
                SyncLoad();
            }

            mAnimator.Update();

            Mesh.BeginDraw();
            Mesh.Program.SetPixelSampler(0, Sampler);

            Mesh.UpdateIndexBuffer(mIndexBuffer);
            Mesh.UpdateVertexBuffer(mVertexBuffer);

            if (mAnimator.GetBones(mAnimationMatrices))
            {
                mAnimBuffer.UpdateData(mAnimationMatrices);
            }

            Mesh.Program.SetVertexConstantBuffer(2, mAnimBuffer);
            Mesh.Program.SetVertexConstantBuffer(3, mPerPassBuffer);

            foreach (var pass in mModel.Passes)
            {
                var cullingDisabled = (pass.RenderFlag & 0x04) != 0;
                Mesh.UpdateRasterizerState(cullingDisabled ? gNoCullState : gCullState);
                Mesh.UpdateBlendState(BlendStates[pass.BlendMode]);

                var oldProgram = Mesh.Program;
                Mesh.Program = (pass.BlendMode > 0 ? gBlendProgram : gNoBlendProgram);
                if (Mesh.Program != oldProgram)
                {
                    Mesh.Program.Bind();
                }

                var unlit    = ((pass.RenderFlag & 0x01) != 0) ? 0.0f : 1.0f;
                var unfogged = ((pass.RenderFlag & 0x02) != 0) ? 0.0f : 1.0f;

                Matrix uvAnimMat;
                mAnimator.GetUvAnimMatrix(pass.TexAnimIndex, out uvAnimMat);

                mPerPassBuffer.UpdateData(new PerModelPassBuffer()
                {
                    uvAnimMatrix    = uvAnimMat,
                    modelPassParams = new Vector4(unlit, unfogged, 0.0f, 0.0f)
                });

                Mesh.StartVertex = 0;
                Mesh.StartIndex  = pass.StartIndex;
                Mesh.IndexCount  = pass.IndexCount;
                Mesh.Program.SetPixelTexture(0, pass.Textures.First());
                Mesh.Draw();
            }
        }
Exemple #2
0
        private void UpdateAnimations(M2RenderInstance instance)
        {
            var camera = WorldFrame.Instance.ActiveCamera;

            mAnimator.Update(new BillboardParameters
            {
                Forward         = camera.Forward,
                Right           = camera.Right,
                Up              = camera.Up,
                InverseRotation = instance.InverseRotation
            });

            if (mAnimator.GetBones(mAnimationMatrices))
            {
                mAnimBuffer.UpdateData(mAnimationMatrices);
            }
        }
Exemple #3
0
        public void OnFrame()
        {
            if (mIsSyncLoaded == false)
            {
                if (mIsSyncLoadRequested)
                {
                    return;
                }

                if (WorldFrame.Instance.MapManager.IsInitialLoad)
                {
                    SyncLoad();
                }
                else
                {
                    WorldFrame.Instance.Dispatcher.BeginInvoke(SyncLoad);
                    mIsSyncLoadRequested = true;
                    return;
                }
            }

            if (mSkipRendering)
            {
                return;
            }

            if (WorldFrame.Instance.HighlightModelsInBrush)
            {
                var brushPosition   = Editing.EditManager.Instance.MousePosition;
                var highlightRadius = Editing.EditManager.Instance.OuterRadius;
                UpdateBrushHighlighting(brushPosition, highlightRadius);
            }

            UpdateVisibleInstances();
            if (mInstanceCount == 0)
            {
                return;
            }

            Mesh.UpdateIndexBuffer(mIndexBuffer);
            Mesh.UpdateVertexBuffer(mVertexBuffer);
            Mesh.UpdateInstanceBuffer(mInstanceBuffer);

            if (mAnimator.GetBones(mAnimationMatrices))
            {
                mAnimBuffer.UpdateData(mAnimationMatrices);
            }

            Mesh.Program.SetVertexConstantBuffer(2, mAnimBuffer);
            Mesh.Program.SetVertexConstantBuffer(3, mPerPassBuffer);

            foreach (var pass in mModel.Passes)
            {
                var cullingDisabled = (pass.RenderFlag & 0x04) != 0;
                Mesh.UpdateRasterizerState(cullingDisabled ? gNoCullState : gCullState);
                Mesh.UpdateBlendState(BlendStates[pass.BlendMode]);

                var oldProgram = Mesh.Program;
                if (pass.BlendMode == 1)
                {
                    Mesh.Program = gBlendTestProgram;
                }
                else
                {
                    Mesh.Program = (pass.BlendMode > 0 ? gBlendProgram : gNoBlendProgram);
                }
                if (Mesh.Program != oldProgram)
                {
                    Mesh.Program.Bind();
                }

                var unlit    = ((pass.RenderFlag & 0x01) != 0) ? 0.0f : 1.0f;
                var unfogged = ((pass.RenderFlag & 0x02) != 0) ? 0.0f : 1.0f;

                Matrix uvAnimMat;
                mAnimator.GetUvAnimMatrix(pass.TexAnimIndex, out uvAnimMat);

                mPerPassBuffer.UpdateData(new PerModelPassBuffer()
                {
                    uvAnimMatrix    = uvAnimMat,
                    modelPassParams = new Vector4(unlit, unfogged, 0.0f, 0.0f)
                });

                Mesh.StartVertex = 0;
                Mesh.StartIndex  = pass.StartIndex;
                Mesh.IndexCount  = pass.IndexCount;
                Mesh.Program.SetPixelTexture(0, pass.Textures.First());
                Mesh.Draw(mInstanceCount);
            }
        }