1

我在实例化模型上设置背景颜色时遇到问题。我可以改变纹理但不能改变颜色。有没有改变颜色的参数?或者改变不透明度?我正在寻找一种突出模型的方法。

太感谢了

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

//不起作用

effect.Parameters["Color"].SetValue(new Vector3(0,1,0)); effect.Parameters["Opacity"].SetValue(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);
                        }
                    }
               ........
}
4

0 回答 0