Shader: Where to start?

I searched all over the net and I found this.

http://www.lighthouse3d.com/opengl/glsl/
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=47
http://nehe.gamedev.net/data/articles/article.asp?article=21
http://www.clockworkcoders.com/oglsl/tutorials.html
http://zach.in.tu-clausthal.de/teaching/cg2_07/literatur/glsl_tutorial/index.html
http://developer.nvidia.com/page/cg_main.html

My question is, should I use GLSL or CG(Nvidia only?) ? I don’t have any experience with those because this is the first time I’m going to study shaders and I’m going to use it on my 3d renderer(soon to become a game engine). I want to support both ATI and Nvidia and I want to have the best graphics that I can do…

I also found this OpenGL Shader Designer and I think this one helps you to create shader effects or maybe I’m wrong

GLSL

not being into advertisement of some sort i would recommend the Orange book on GLSL. What you could benefit from using CgFX from Cg are some technique definitions in the shader file which ease the use of shaders and renderstate changes.
http://http.developer.nvidia.com/CgTutorial/cg_tutorial_appendix_c.html

GLSL

GLSL!

Unfortunately there is no “perfect” shader editor to be found.

I would suggest implementing a “shader reload/compile” functionality into your own code for updating shadercode on the fly.
All you need is a text editor and you have your own “shader editor”.
:smiley:

“Unfortunately there is no “perfect” shader editor to be found.”

RenderMonkey - dont know if its perfect but decent enough.
Mental Mill - visual shader editor exports straight to GLSL vp/fp.

Not a question of better or worse, just a matter of what you’re looking to do and how much time you’re willing to spend doing it.

Go with Cg, if say you’re looking to make using GL shamefully simple. Cg wraps up the more tedious aspects of getting things up and running, like creating shaders, setting shader variables and the whole state management business. With CgFX, it’s all a full blown breeze, and then some.

Anyone here can recommend a good book about shader programming? I found this book OpenGL Shading Language. Is this the best book for beginner and advanced?

OpenGL Shading Language, also known as the Orange Book ?
It is a very good book, and it has a good reference website too :
http://www.3dshaders.com/home/

Your latter statement suggests GLSL. With Cg, it at least used to be that you effectively drop back to ARB_vertex_program/ARB_fragment_program (arbvp1 and arbfp1 in Cg profile lingo) functionality on ATI as NVidia (as the Cg author/maintainer) doesn’t support any newer shader extensions on ATI hardware (AFAIK).

HOWEVER, the one thing I’m not sure about (added since I last worked thoroughly with Cg) is Cg cross-compile to GLSL. I know Cg can now cross-compile to GLSL – I’ve used this from the command-line to help debug/optimize GLSL shaders. But I’m unsure as to whether you can tell the Cg API to transparently use GLSL as a back-end profile – that is, as the way it feeds shaders to the GPU and drives it – or not. It looks like you can though! The fact that there are specific profile macros in the Cg header files for GLSL (glslv, glslf, glslg, glslc) suggests you can.

In which case (if this is really supported), you could code your shaders in Cg, use the Cg run-time to make things easier, and then tell Cg to cross-compile to GLSL behind the scenes and drive the GPU using GLSL shaders, and get access to most (if not all) of the latest GPU features. That is, not be limited to arbvp1/arbfp1-level functionality.

However for getting started, I’d suggest learning shaders in GLSL. Less software in between you and the GPU, and GLSL and Cg are very similar until you get into advanced features. Just a few syntactic quirks and a few built-in functions have different names (mix vs. lerp, etc.). Right now you just need to latch the concept.

Then once you’re up on that, you’ll know enough to make the call as to whether you’d benefit from using Cg or not.

In which case (if this is really supported), you could code your shaders in Cg, use the Cg run-time to make things easier, and then tell Cg to cross-compile to GLSL behind the scenes and drive the GPU using GLSL shaders, and get access to most (if not all) of the latest GPU features. That is, not be limited to arbvp1/arbfp1-level functionality.

That would be very nice but I find it difficult to rely on this. I would always want look through the glsl output as soon as I would come upon a weird bug in my Cg code… :slight_smile: but this is my way of thinking.

One good point for Cg shaders is that it is also supported by the d3d API though it may not be your concern.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.