Hi,
I'm fairly new to shaders, and would like some how on the best way to implement them. I've read heaps of tutorials on how to put a texture on a model using an effect, but no good way of how to implement the effect.
An example of what I mean...
I am trying to render a chess board.
For each tile,
If it is the selected tile, I want to blend the tiles texture with a selected tile texture,
or if it's a tile where there's a possible move, I want to blend the tile and the possible move texture
etc.
Do I do something like...
| foreach (ModelMesh boardMesh in m_board.Meshes) |
| { |
| foreach (ModelMeshPart meshPart in boardMesh.MeshParts) |
| { |
| //check if tile |
| if (isTile) |
| { |
| if ((x + y) % 2 == 0) |
| { |
| m_tileEffect.Parameters["myTexture"].SetValue(Game.Content.Load<Texture>(@"Models\WhiteTile")); |
| } |
| else |
| { |
| m_tileEffect.Parameters["myTexture"].SetValue(Game.Content.Load<Texture>(@"Models\BlackTile")); |
| } |
| |
| if (tile == m_selectedTile) |
| { |
| //Add a second texture to effect |
| } |
| else if (tile == m_possibleMoveTile) |
| { |
| //Add a second texture to effect |
| } |
| meshPart.Effect = m_tileEffect; |
| } |
| |
| meshPart.Effect.Parameters["Projection"].SetValue(m_camera.ProjectionMatrix); |
| meshPart.Effect.Parameters["View"].SetValue(m_camera.ViewMatrix); |
| meshPart.Effect.Parameters["World"].SetValue(boardTransforms[boardMesh.ParentBone.Index] * m_boardWorld); |
| } |
(I have mixed a little pseudo code in there, but I want help more with structure than syntax)
This seems stupid to me (as I'm sure it does to you :). What if I wanted to use 2 completely different effects for selected tiles and possible move tiles, or possible attack tiles etc.
What if I wanted a slightly different texture for each tile? Using this approach I would need a switch statement with 64 parts (8 * 8).
Instead of having the tiles in the boards mesh, should I have them as seperate onjects and have an effect for each tile?
Any other suggestions?
Thanks heaps.