12,399,362 members (60,379 online)
Rate this:
See more:
I'm beginner in HLSL(High Level Shader Language XNA 4.0). Write code HLSL is very hard beause it's not have function Visual Intelligence and formula's optical is very hard . Write code HLSL in Visual Studio like write in notepad. Can you tell me program write code HLSL best and explain formula's optical . Thanks!
Posted 14-Oct-12 9:20am
Updated 15-Oct-12 1:24am
v4

Rate this:

## Solution 1

Sorry, but it's not quite clear what you are looking for. My best guess is that you want a visual editor for shaders that gives you a sample of what the result looks like.

Wow. I just searched for HLSL editors and only got results for text editors with syntax highlighting or intellisense. This is probably for a very good reason. While it's possible to display the code of a shader as some kind of graph with editable properties, this would not take away the need for the user to understand the algorithm that is implemented by the shader. The ability to edit some values and see the results would only by luck lead to anything useful without that understanding.

I'm afraid you have little choice than going the hard way like everybody else. Shaders are short and usually linear procedures. In most cases there are no loops or other confusing things.

Vertex shaders are used to transform the data from 3D object space to 3D world space and then to 2D view space. Those things usually are explained in a good book about computer graphics, along with the basics of linear algebra. The code of the shader by itself may be simple, but you will have little chance of understanding its purpose without knowing about those 3D and 2D spaces and the math which is involved.

Pixel shaders are about determining the color of each pixel of a polygon. The polygons are actually triangles, formed by three of the vertices. At this point we already know the 2D screen coordinates of the vertices, thanks to the vertex shader. But the vertices are only the corner points. What about the pixels inside this triangle?

The color of a pixel may be a constant, interpolated between color values attached to each vertex, sampled from a texture map and in many more ways. You can even combine those techniques or invent new ones. Again I would suggest you start by consulting a book about computer graphics and understanding some of the basic techniques. Then you will be able to understand vertex shaders that implement them and eventually also be able to modify them.

The same goes for light calculations, which are also done in the pixel shader. Basically it's just making the calculated color for the pixel lighter or darker, according to how much light from one or more light sources reaches that pixel. But once again there are many simple or more advanced ways to accomplish this and only studying them will help you.

Bottom line: Get yourself a good book that covers the basics of 3D graphics. It does not matter if the book is a little older. Those things have not really changed since the days when all this was still done in software. Those powerful graphics processors only allow us to do much more of it every second.

Take your knowledge from the book (like how to apply a texture to a polygon) and get yourself a sample shader that implements exactly this technique. Once you have understood the theory, the shader will not be mysterious at all for you anymore.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 ppolymorphe 380 OriginalGriff 355 Vincent Maverick Durano 265 0x01AA 195 Karthik Bangalore 135
 OriginalGriff 6,723 ppolymorphe 2,835 Karthik Bangalore 2,707 Richard MacCutchan 2,057 F-ES Sitecore 2,052

Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 15 Oct 2012