Beispiel #1
0
 public void Render()
 {
     for (int i = 0; i < Material.PassCount; i++)
     {
         Material.Apply(i);
         PlatformRenderer.DrawTriangles(mesh, StartIndex, LastIndex - StartIndex);
     }
 }
Beispiel #2
0
        public override void Render()
        {
            if (SkipRender)
            {
                return;
            }

            bool lightningEnabled = ProcessLightning && Viewport != null && Viewport.LightSource != null && Viewport.LightSource.Visible;
            bool shadowsEnabled   = lightningEnabled && Viewport.LightSource.ShadowMappingEnabled;

            Renderer.World    = GlobalTransform;
            Renderer.CullMode = CullMode;
            var invWorld = GlobalTransform.CalcInverted();

            foreach (var sm in Submeshes)
            {
                var skin = sm.Material as IMaterialSkin;
                if (skin != null && sm.Bones.Count > 0)
                {
                    skin.SkinEnabled = sm.Bones.Count > 0;
                    if (skin.SkinEnabled)
                    {
                        if (sharedBoneTransforms.Length < sm.Bones.Count)
                        {
                            sharedBoneTransforms = new Matrix44[sm.Bones.Count];
                        }
                        for (var i = 0; i < sm.Bones.Count; i++)
                        {
                            sharedBoneTransforms[i] = sm.BoneBindPoses[i] * sm.Bones[i].GlobalTransform * invWorld;
                        }
                        skin.SetBones(sharedBoneTransforms, sm.Bones.Count);
                    }
                }
                var lightningMaterial = sm.Material as IMaterialLightning;
                if (lightningMaterial != null)
                {
                    lightningMaterial.ProcessLightning = lightningEnabled;
                    if (lightningEnabled)
                    {
                        lightningMaterial.SetLightData(Viewport.LightSource);
                    }
                }

                var shadowMaterial = sm.Material as IMaterialShadowReciever;
                if (shadowMaterial != null)
                {
                    shadowMaterial.RecieveShadows = shadowsEnabled && RecieveShadow;
                }

                for (int i = 0; i < sm.Material.PassCount; i++)
                {
                    sm.Material.Apply(i);
                    PlatformRenderer.DrawTriangles(sm.Mesh, 0, sm.Mesh.IndexBuffer.Data.Length);
                }
                Renderer.PolyCount3d += sm.Mesh.IndexBuffer.Data.Length / 3;
            }
        }
Beispiel #3
0
        public void RenderDepthBuffer(IMaterial mat)
        {
            if (SkipRender)
            {
                return;
            }

            Renderer.World    = GlobalTransform;
            Renderer.CullMode = CullMode;

            var invWorld = GlobalTransform.CalcInverted();

            foreach (var sm in Submeshes)
            {
                var def = sm.Material;

                sm.Material = mat;

                var skin = sm.Material as IMaterialSkin;
                if (skin != null && sm.Bones.Count > 0)
                {
                    if (sharedBoneTransforms.Length < sm.Bones.Count)
                    {
                        sharedBoneTransforms = new Matrix44[sm.Bones.Count];
                    }
                    for (var i = 0; i < sm.Bones.Count; i++)
                    {
                        sharedBoneTransforms[i] = sm.BoneBindPoses[i] * sm.Bones[i].GlobalTransform * invWorld;
                    }

                    skin.SkinEnabled = true;
                    skin.SetBones(sharedBoneTransforms, sm.Bones.Count);
                }
                else
                {
                    skin.SkinEnabled = false;
                }

                for (int i = 0; i < sm.Material.PassCount; i++)
                {
                    sm.Material.Apply(i);
                    PlatformRenderer.DrawTriangles(sm.Mesh, 0, sm.Mesh.IndexBuffer.Data.Length);
                }
                Renderer.PolyCount3d += sm.Mesh.IndexBuffer.Data.Length / 3;

                sm.Material = def;
            }
        }
Beispiel #4
0
        public void Render(Widget parentWidget)
        {
            Renderer.Flush();
            var animationTime = parentWidget.AnimationTime;
            // Find the morph targets to interpolate in between.
            MorphTarget target0, target1;

            if (MorphTargets.Count == 1)
            {
                target0 = target1 = MorphTargets[0];
            }
            else
            {
                while (true)
                {
                    target0 = MorphTargets[currentTarget];
                    target1 = MorphTargets[currentTarget + 1];
                    if (animationTime < target0.Timestamp)
                    {
                        if (currentTarget == 0)
                        {
                            break;
                        }
                        currentTarget--;
                    }
                    else if (animationTime <= target1.Timestamp)
                    {
                        break;
                    }
                    else if (currentTarget >= MorphTargets.Count - 2)
                    {
                        // We got across the rightmost target.
                        target0 = target1;
                        break;
                    }
                    else
                    {
                        currentTarget++;
                    }
                }
            }
            // Create the mesh if there is no any.
            if (target0.Mesh == null)
            {
                target0.Mesh = new Mesh {
                    VertexBuffers = new IVertexBuffer[] { UVBuffer, target0.PosColorBuffer, target1.PosColorBuffer },
                    Attributes    = new[] {
                        new[] { ShaderPrograms.Attributes.UV1 },
                        new[] { ShaderPrograms.Attributes.Pos1, ShaderPrograms.Attributes.Color1 },
                        new[] { ShaderPrograms.Attributes.Pos2, ShaderPrograms.Attributes.Color2 }
                    },
                    IndexBuffer = IndexBuffer
                };
            }
            // Calculate the interpolation koefficient.
            float t;

            if (animationTime <= target0.Timestamp)
            {
                t = 0;
            }
            else if (animationTime >= target1.Timestamp)
            {
                t = 1;
            }
            else
            {
                t = (float)((animationTime - target0.Timestamp) / (target1.Timestamp - target0.Timestamp));
            }
            // Render all of it.
            if (shaderProgram == null)
            {
                var options = ShaderOptions.VertexAnimation;
                shaderProgram      = ShaderPrograms.Instance.GetShaderProgram(ShaderId.Diffuse, 1, options);
                morphKoeffUid      = shaderProgram.GetUniformId("morphKoeff");
                globalColorUid     = shaderProgram.GetUniformId("globalColor");
                globalTransformUid = shaderProgram.GetUniformId("globalTransform");
            }
            PlatformRenderer.SetBlending(Blending.Alpha);
            PlatformRenderer.SetShaderProgram(shaderProgram);
            var globalColor = parentWidget.GlobalColor;

            shaderProgram.LoadFloat(morphKoeffUid, t);
            if (loadedGlobalColor.ABGR != globalColor.ABGR)
            {
                loadedGlobalColor = globalColor;
                var globalColorVec4 = (globalColor.ABGR == 0xFFFFFFFF) ?
                                      Vector4.One : new Vector4(
                    globalColor.R / 255f,
                    globalColor.G / 255f,
                    globalColor.B / 255f,
                    globalColor.A / 255f);
                shaderProgram.LoadVector4(globalColorUid, globalColorVec4);
            }
            shaderProgram.LoadMatrix(globalTransformUid, (Matrix44)parentWidget.LocalToWorldTransform);
            foreach (var sm in Batches)
            {
                PlatformRenderer.SetTexture(sm.Texture, 0);
                PlatformRenderer.DrawTriangles(target0.Mesh, sm.StartIndex, sm.IndexCount);
            }
        }