Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
add comment

1 Answer

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.

http://www.riemers.net/eng/Tutorials/XNA/Csharp/series1.php 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
add comment

Your Answer

 
discard

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.