Exemple #1
0
        /// <summary>
        /// Method to set the texture values within the effect class and render the model.
        /// </summary>
        /// <param name="num">The index into the list of models.</param>
        private void RenderModel(Model mesh, bool shadows, int num)
        {
            // Set the technique being used for this particular model.
            if (shadows)
            {
                if (mesh.Normal.Enable && !mesh.Normal.Path.Equals(""))
                {
                    if (Manager.GetDeviceCaps(0, DeviceType.Hardware).PixelShaderVersion > new Version(2, 0))
                        effect.Technique = "NormalMapShadows";
                    else
                    {
                        MessageBox.Show("Error: Your graphics card does not support pixel shader 2.0b", "Error",
                                             MessageBoxButtons.OK, MessageBoxIcon.Error);
                        effect.Technique = "PerPixelShadows";
                    }
                }
                else
                    effect.Technique = "PerPixelShadows";
            }
            else
                effect.Technique = mesh.Normal.Technique;

            // Set the Ambient Occlusion texture.
            effect.SetValue(mesh.Ambient.EffectName, mesh.Ambient.Texture);
            effect.SetValue(mesh.Ambient.EffectBool, mesh.Ambient.Enable);

            // Set the Diffuse texture.
            effect.SetValue(mesh.Diffuse.EffectName, mesh.Diffuse.Texture);
            effect.SetValue(mesh.Diffuse.EffectBool, mesh.Diffuse.Enable);

            // Set the Normal/Parallax texture.
            effect.SetValue(mesh.Normal.EffectName, mesh.Normal.Texture);
            effect.SetValue(mesh.Normal.EffectBool, mesh.Normal.Enable);

            // Set the Specular texture.
            effect.SetValue(mesh.Specular.EffectName, mesh.Specular.Texture);
            effect.SetValue(mesh.Specular.EffectBool, mesh.Specular.Enable);

            // Begin rendering with the hlsl shader.
            int numPasses = effect.Begin(FX.None);

            for (int i = 0; i < numPasses; i++)
            {
                if (shadows)
                {
                    switch (num)
                    {
                        case 0:
                            effect.SetValue("shadowMapLight1", shadowMap);
                            break;

                        case 1:
                            effect.SetValue("shadowMapLight2", shadowMap2);
                            break;

                        case 2:
                            effect.SetValue("shadowMapLight3", shadowMap3);
                            break;
                    }
                }

                effect.BeginPass(i);

                // Draw the model.
                mesh.Mesh.DrawSubset(0);

                // End drawing with the hlsl shader.
                effect.EndPass();
            }

            effect.End();
        }
Exemple #2
0
 /// <summary>
 /// Method to add a new model.
 /// </summary>
 /// <param name="newModel">New model to add.</param>
 public void addNewModel(Model newModel)
 {
     mesh.Add(newModel);
 }