C# 如何在XNA项目的模型上动态(更新、设置、应用)颜色?

C# 如何在XNA项目的模型上动态(更新、设置、应用)颜色?,c#,colors,xna,drawing,effects,C#,Colors,Xna,Drawing,Effects,我遇到了在实例化的模型上设置背景色的问题。我可以改变纹理,但不能改变颜色。 是否有用于更改颜色的参数?或者改变不透明度?我正在寻找一种方式来突出一个模型 多谢各位 以下是我使用的代码: 除了最后两行之外,一切都正常。我搜索了颜色和不透明度的名称参数,但找不到 //不起作用 效果。参数[“颜色”]。设置值(新矢量3(0,1,0)); 影响。参数[“不透明度”]。设定值(0.5f) void DrawModelHardwareInstancing(Model model, Matri

我遇到了在实例化的模型上设置背景色的问题。我可以改变纹理,但不能改变颜色。 是否有用于更改颜色的参数?或者改变不透明度?我正在寻找一种方式来突出一个模型

多谢各位

以下是我使用的代码: 除了最后两行之外,一切都正常。我搜索了颜色和不透明度的名称参数,但找不到

//不起作用

效果。参数[“颜色”]。设置值(新矢量3(0,1,0)); 影响。参数[“不透明度”]。设定值(0.5f)

        void DrawModelHardwareInstancing(Model model, Matrix[] modelBones,
                                             Matrix[] instances, Matrix view, Matrix projection)
            {
                 .......


                foreach (ModelMesh mesh in model.Meshes)
                {
                    foreach (ModelMeshPart meshPart in mesh.MeshParts)
                    {
                        // Tell the GPU to read from both the model vertex buffer plus our instanceVertexBuffer.
                        Game.GraphicsDevice.SetVertexBuffers(
                            new VertexBufferBinding(meshPart.VertexBuffer, meshPart.VertexOffset, 0),
                            new VertexBufferBinding(instanceVertexBuffer, 0, 1)
                        );

                        Game.GraphicsDevice.Indices = meshPart.IndexBuffer;


                        // Set up the instance rendering effect.
                        Effect effect = meshPart.Effect;
                        //effect.CurrentTechnique = effect.Techniques["HardwareInstancing"];
                        effect.Parameters["World"].SetValue(modelBones[mesh.ParentBone.Index]);

                        //Work perfect
                        effect.Parameters["View"].SetValue(view);
                        effect.Parameters["Projection"].SetValue(projection);
                        effect.Parameters["Texture"].SetValue(textureInstancedModel);
                        /* ***************************** */
                        //Does not work
                        effect.Parameters["Color"].SetValue(new Vector3(0,1,0));
                        effect.Parameters["Opacity"].SetValue(0.5f);
                        /* ***************************** */

                        // Draw all the instance copies in a single call.
                        foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                        {
                            pass.Apply();

                            Game.GraphicsDevice.DrawInstancedPrimitives(PrimitiveType.TriangleList, 0, 0,
                                                                   meshPart.NumVertices, meshPart.StartIndex,
                                                                   meshPart.PrimitiveCount, instances.Length);
                        }
                    }
               ........
}

您需要创建定义效果中颜色的HLSL效果文件,以便可以通过参数更改颜色。