Toon Shader

Mar 20, 2010 at 9:49 PM
Edited Mar 20, 2010 at 9:50 PM

Has anyone got Toon Shader working with GoblinXNA? I have it working with normal XNA from a sample i got online. I am not able to get it to work with GoblinXNA.

This is what i'm doing

                  graphics.GraphicsDevice.Clear(Color.CornflowerBlue);


// Normal Render
                  graphics.GraphicsDevice.SetRenderTarget(0, normalDepthRenderTarget);
                  graphics.GraphicsDevice.Clear(Color.Black);
                  graphics.GraphicsDevice.RenderState.AlphaBlendEnable = false;
                  graphics.GraphicsDevice.RenderState.AlphaTestEnable = false;
                  graphics.GraphicsDevice.RenderState.DepthBufferEnable = true;

                  Toon.Parameters["World"].SetValue(model.LocalWorld);
                  Toon.Parameters["View"].SetValue(scene.CameraNode.Camera.View);
                  Toon.Parameters["Projection"].SetValue(scene.CameraNode.Camera.Projection);
                  Toon.CurrentTechnique = Toon.Techniques["NormalDepth"];

                                  
                  
                  foreach (ModelMesh meshes in model.Model.Mesh)
                  {
                      foreach (ModelMeshPart parts in meshes.MeshParts)
                          parts.Effect = Toon;
                      meshes.Draw();
                  }
//Render
                  graphics.GraphicsDevice.SetRenderTarget(0, sceneRenderTarget);
                  graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
                  graphics.GraphicsDevice.RenderState.AlphaBlendEnable = false;
                  graphics.GraphicsDevice.RenderState.AlphaTestEnable = false;
                  graphics.GraphicsDevice.RenderState.DepthBufferEnable = true;

                  Toon.Parameters["World"].SetValue(model.LocalWorld);
                  Toon.Parameters["View"].SetValue(scene.CameraNode.Camera.View);
                  Toon.Parameters["Projection"].SetValue(scene.CameraNode.Camera.Projection);
                  Toon.CurrentTechnique = Toon.Techniques["Toon"];

                  foreach (ModelMesh meshes in model.Model.Mesh)
                  {
                      foreach (ModelMeshPart parts in meshes.MeshParts)
                      {
                          Toon.Parameters["Texture"].SetValue(model.effectMapping[parts]);
                          parts.Effect = Toon;
                      }
                      meshes.Draw();
                  }
//Render Post Processing
                  graphics.GraphicsDevice.SetRenderTarget(0, null);
                  graphics.GraphicsDevice.Clear(Color.Black);
                  postprocessEffect.Parameters["ScreenResolution"].SetValue(new Vector2(sceneRenderTarget.Width,
                                                                                          sceneRenderTarget.Height));
                  postprocessEffect.Parameters["NormalDepthTexture"].SetValue(normalDepthRenderTarget.GetTexture());
                  postprocessEffect.CurrentTechnique = postprocessEffect.Techniques["EdgeDetect"];

                  // Draw a fullscreen sprite to apply the postprocessing effect.
                  spriteBatch.Begin(SpriteBlendMode.None,
                                    SpriteSortMode.Immediate,
                                    SaveStateMode.None);

                  postprocessEffect.Begin();
                  postprocessEffect.CurrentTechnique.Passes[0].Begin();

                  spriteBatch.Draw(sceneRenderTarget.GetTexture(), Vector2.Zero, Color.White);

                  spriteBatch.End();

                  postprocessEffect.CurrentTechnique.Passes[0].End();
                  postprocessEffect.End();

 

I either get a completely black model or a texture-less model.

The sample program i got had the following:

foreach (ModelMesh meshes in model.Model.Meshes)
            {
                foreach (ModelMeshPart parts in meshes.MeshParts)
                    parts.Effect = Toon;
                meshes.Draw();
            }

which is changed to:

foreach (ModelMesh meshes in model.Model.Mesh)
                  {
                      foreach (ModelMeshPart parts in meshes.MeshParts)
                          parts.Effect = Toon;
                      meshes.Draw();
                  }

i think the ModelMesh part is causing the problem. Does anyone know how I can get a ModelMesh collection from a given model that uses Goblin XNA? another question is it possible to explicity convert a goblin XNA model to a Microsoft XNA model? I tried many ways but I always got an error. I know i'm missing something simple but I'm not able to see it. Please help me out. Thanks in advance