Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There are tutorials about applying shaders to 3D models, but I would like to know how to use shaders on primitives. I have a world with a lot of vertices and I would like to apply a shader to it without adding any texture to it or loading any model. I'm working with XNA and HSLS.

share|improve this question
up vote 1 down vote accepted

All of the primitive stuff I've seen so far for XNA was actually building the object out of verts during run time and passing them in as a Triangle list of Vertexes (or VertexNormals if you want to do lighting stuff) You may wish to consider getting some basic shape models for traditional primitives.

That being said, the terrain in the current game I'm working on is all generated run-time with no models (though we do apply textures), and if you already have your verts set up and want to get them to draw into a shader, all you have to do is set up a VertexBuffer and an IndexBuffer, then set the Indicies and Vertices on your GraphicsDevice to each of them. After that, you use the GraphicsDevice's DrawIndexedPrimitives to draw the data you've buffered. Start an effect before you do so just like with a model and voila. Has a good starting point for this as the terrain is generated from a heightmap instead of a model, and the lighting/coloring is done with normal/height data in hlsl.

Warning: all of this is in regards to XNA 3.1, I would imagine most of it would carry over to XNA 4.0 or be easily translatable, but there may be a better way in the current version.

Anyway, hope this helps!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.