2
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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!

|improve this answer|||||
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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