Archived

This topic is now archived and is closed to further replies.

Where do I start with shaders?

This topic is 5153 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m so confused there is asm, HLSL and a whole bunch of different thing. Like if I have a radeon 9800 and I program a shader in asm will it work on a geforce fx? Can someone explain to me all the different languages that you write a shader in? Also I downloaded RenderMonkey and I read through the documentation it shows you how to use the IDE but not how to use HLSL are there any good books out there(preferably) but if not what about tutorials or good documentation?

Share this post


Link to post
Share on other sites
The ASM has several versions (1.0 (never used in any HW), 1.1, 2.0, 3.0). Various cards support different versions of ASM. Cards that support a higher version of ASM *MUST* support the older versions too.

HLSL is DX only.

GSLANG is an OpenGL Shader Language, supposed to be in OGL 2.0.

CG is DX and OpenGL, though some people suggest nVidia places oddities into the output that negatively affect ATI cards, but don''t affect nVidia''s cards.

Currently CG and HLSL are similar enough that code for one apparently works in the other (according to nVidia... I have no idea.) nVidia waiting for DX9 to be finalized before releasing CG to ensure this.

There are also two different shaders... pixel (or fragment) shaders, and vertex shaders. Some cards support vertex shaders, but not pixel shaders. Some cards don''t support shaders at all. Vertex shaders can be efficiently emulated by the CPU, while emulating a pixel shader will be slow on all but the latest 3.0GHz chips.

Everyone used ASM in DX8, as it was the only choice. If you grew up coding ASM, you probably won''t mind too much... Even if ASM is new, shader ASM is a fairly simple ASM, plus it''s not like you''re ever going to have a huge application in shader ASM.

Not everyone grew up coding ASM though, and they wanted something easier to program, thus CG and HLSL were born. An advantage of CG and HLSL is that they may optimize your shader (though DX does attempt to optimize shader ASM too to some extent). The familiar C like syntax, and the idea of functions (rather than stitching bits of ASM together), and not having to manage your registers manually are the benefits. But CG and HLSL often let the underlying assembly show though... Like the specular calculations using ''lit''. CG still requires data to be laid out in a certain format rather than handling it for you.

Personally, I still use vertex shader ASM 1.1, and avoid pixel shader ASM. Pixel shader 1.1 is quite limited, and using the DirectX fixed pipeline offers a similar level of control. To get a newer version of pixel shader requires too new of a card. It''s useful as an optional effect for highend systems, but should be avoided for anything core to the game... atleast for now.

Share this post


Link to post
Share on other sites
Very informative post Namethatnobodyelsetook!

Between the time I first posted it and read your responce I had spent all that time at the bookstore looking through all the pixel/vertex shader books. The best one I found that introduced everything very slowly and easily was The Cg Tutorial.

My question is since I'm using Direct3D and an ATI Radeon 9800 PRO card to do programming in would it be better to learn the HLSL directly instead of Cg? Because Cg was made by nVidia and HLSL was made by Microsoft? Or will the Cg language suit me fine? Also if I used Cg would I be able to use the RenderMonkey IDE to test out all my Cg code?

Sorry for all the annoying newbie questions this post probaly would of been better in the Begginers forum.

[edited by - ph33r on November 6, 2003 9:14:37 PM]

Share this post


Link to post
Share on other sites
If CG and HLSL are compatible as nVidia claims, then yes, you could write CG code in RenderMonkey by telling RenderMonkey that you''re writing HLSL code.

Even if they''re not 100% compatible, the differences should be minor. They''re close enough that nVidia is willing to make the claim that they''re currently compatible, and they''re both C syntax for the same operations on the same data, both based on the same other shader language (RenderMan).

Even if you DO have to write code in CG to learn, once you have the concepts down from that, you should be able to make the switch to HLSL fairly easily. Currently I don''t think the choice of CG or HLSL is a big deal. The big choice is high level or ASM, and it looks like you''ve made that choice.

Look for which books people have recommended for CG and HLSL. Try to get an idea of whether the people recommending the book at beginners or experts. A book that''s useful to an expert may be frustrating to a beginner. A book that''s useful to a beginner may be a waste of $50 to an expert.

Hopefully someone who''s actually used either CG or HLSL will post their ideas in this thread. I''ve got a CG book (free from nVidia for filling out a survey) that I''ve glanced at, but I''m usually too busy to actually try to learn it.

Share this post


Link to post
Share on other sites