The Cg Tutorial
The first half of the book teaches the basic language constructs of the Cg shading language and shows how to use them in concrete example shaders, whereas the second half concentrates on more advanced techniques that can be achieved on today's programmable GPUs with Cg, such as environment or bump mapping. Even these more advanced techniques are explained in a clear and easy-to-understand manner, but the authors do not neglect to present the mathematics behind the techniques in detail. Especially the more serious 3D programmer will appreciate this fact. The explanation of texture space bump mapping must be the easiest-to-understand explanation of the technique I have read to date, which alone makes it worth to have this book on my shelf. At this point it is important to note that the book does not discuss the Cg runtime which is used by applications to compile and upload shaders to the GPU. The book focuses exclusively on the Cg language itself. So if you're already familiar with Cg and want to learn how to use the Cg runtime, this book is not for you and you should rather read the freely available Cg Users Manual.
The book contains many diagrams and figures to illustrate the discussed equations and show the rendered images produced by the presented shaders. Note that most figures in the book are in black and white which sometimes leads to funny situations, such as in chapter 2.4.3 where the resulting image of a shader that renders a green triangle is shown. Since the figure is not in color the triangle that is supposed to be solid green ends up being solid gray. However, in the middle of the book there are sixteen pages with color plates that depict most of the important color images and also show some additional images of various applications, NVIDIA demos, and shaders written for Cg shader contests at www.cgshaders.org.
Accompanying the book on CD-ROM is an application framework that allows you to modify, compile, and run all the example shaders in the book without having to worry about setting up a 3D graphics API, such as OpenGL or Direct3D. The application framework uses configuration files to load meshes and textures and set up the graphics pipeline appropriately for the shaders. This way the Cg shaders can be examined and modified in isolation with the results being immediately visible in the render window of the application. Thanks to this framework application even readers that are not yet familiar with a 3D graphics API or even 3D artists interested in programmable shading on modern GPUs can begin to learn Cg and experiment with real-time shaders.
A final note for programmers using Direct3D 9: The high-level shading language included with the latest version of Direct3D, simply called HLSL for High-Level Shader Language, is syntactically equivalent to Cg. Everything written in the book about Cg equally applies to HLSL. Thus, the book is also an excellent guide for programmers that only intend to work with HLSL.
This book truly is the definitive guide for all beginners with the Cg language, and also more advanced 3D programmers will find the chapters about vertex skinning, environment mapping, bump mapping, and other advanced techniques interesting. Once you've started writing shaders in Cg you will never want to go back to writing them in low-level assembly shading languages ever again.
You can purchase The Cg Tutorial: The Definitive Guide to Programmable Real-Time Graphics from bn.com. The book's official website has additional information and ordering options besides. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
I just hope it's not too little too late. Nvidia seems to be going the way of Voodoo. Taking the same card and clocking it faster with a bigger fan. It's not bad enough that the athlon's are toasters, we have to have 2 of them in a box with enough fans to have a tornado.
nforce looks pretty cool though.
"I can not bring myself to believe that if knowledge presents danger, the solution is ignorance" - Isaac Asimov
I'm sick of NVIDIA trying to control the graphics market by controlling the language developers have to use.
...That's like someone trying to control Java
...Never mind...(Come to think of it, I can't even think of a counter-example where someone didn't try to control a market through control of the programming language.)
Suicide Booth: You are now dead! Thank you for using Stop and Drop, America's favorite since 2008.
I couldn't get the official site's link to the NVIDIA Gear Store to work. It says the link won't work if it's out of stock, but it's hard to believe it's out of stock already! I thought this book was pretty new and this is before the /. crowd even knew about ordering it. It's only like 50 cents cheaper than ordering from BN anyway, but I wanted to check it out.
Most people would die sooner than think; in fact, they do.
A copy of 3ds Max 5, and a team of artists, and I can start coding graphics stuff for fun again! Uh oh, this is /. and I said DX9, hello Troll demod!
Seriously, I really would like someone to debunk this idea if possible, because I have picked up an interest in graphics programming and am just starting out - would like to know more. It seems like an easier / pragmatic route (due to code reusability) to go the other route ...
-- (Score:i, Imaginary)
This is the most important question.
Also anyone have a bittorrent link?
Control makes it easier to implement standards. Standards make it easier to develop. Development makes it easier to profit. Your argument makes no sense. Of course NVIDIA is trying to control the graphics market - that's their job. If controlling the language is one of the best ways to go about doing that, why shouldn't they try? I smell a big fat commie rat.. and it's you.
One half of the posts will argue against nVidia because ATI currently holds the lead. The other half will argue in nVidia's favor because of the Linux & FreeBSD drivers.
A Definitive Guide not by O'Reilly? That's it, the gloves are off!
Karma: Marginal (mostly due to the border around the website)
I've been thinking the C standard needs native support for vector data types for some time. Sure, I have Vec3, Vec4 and M4x4 classes that I wrote, but they don't take advantage of SSE instructions and such. Intel has a compiler that supposedly works with these instruction sets, but I haven't tried it. Wider support would be available if Cg was a real standard extension to C. When is GCC going to handle Cg? This will allow all those shaders to be used in software renderers (Mesa for example) unchanged. I'm not sure Cg as defined is the correct way to extend C, but you get my point.
Don't let the title foo you -- it contains high level descriptions of the algorithms as well as the mathematical concepts. They cover some advanced realtime techniques that older books don't (since the processing power wasn't there even 4 years ago), but also discuss optimizing for low-end systems.
I do recommend this book if you ahve any interest in graphic programming (whether you use Cg or not). If you use it with Coputer Graphics (3rd edition), you should have access to pretty much all graphic algorithms. (at least until TAOP volume 7: Computer Graphics is written
The 9700 is the fastest card on the open market currently (The FX hasn't been released yet, right?), yes. However, having the current best card doesn't mean you control the majority of the market. nVidia is still a major player these days, possibly still moreso than ATI.
I see what you're saying... nvidia's latest video card with the super loud fan and only marginal performs gains reminds me of the voodoo3 to a certain extent. But they are still my video card of choice and that's because a) their drivers rock and b) they try to provide full access to all of the video cards new features in linux (usually by openGL extensions). I admit, i have a hard time understanding how to use these extensions, but at least I know that if I did know how to use them, I'd be able to in linux. (at least.. I hope I could! hehe)
...
Now in fairness, I haven't checked out ATI's linux drivers in much detail, but from what I understand they only provide very specific support to a few of their cards and you can't just download one set of unified drivers like you can with nvidia.
So until ATI produces better linux drivers than nvidia, I am going to stick with nvidia (unless nvidia becomes like 50% slower or something drastic)
Cg is a high level shader language. You only use it for shaders not for your real program. You write your stuff in C, C++ or every other language where you got OpenGL or Direct3D bindings.
Cg is only used for shaders, tiny little specialiced code fragments that run directly on the graphic card and manipulate vertexes (vertex shader) or shade the inside of the triangles in new ways. (pixel shaders)
Before Nvidia created Cg, the only way creating new shaders was using low-level assembly like language. With Cg you can write shaders in a high-level c like language. Using real C(++) for shaders wouldn't work cause the video card isn't a full featured cpu.
Jan
Actually the latest refresh of the R300, ATI's 9800(R350) is the fastest card. Also features improvements in z-buffer, shadow stencils (for doom 3). And an F-buffer that helps avoid shader length limitations of the R300.
But what a lot of us need before we get heavy into the CG and workings of the card - is a knowledge of the more basic 3d programming principles. Does anyone have some basic, well-written code snippets for GL or something else linux-friendly.
Personally, I've found directX a nice language to work with, but it's MS and somewhat restricted to the OS. Why not a good GL wrapper for CG, does one exist? How about some good GL samples, period? Can anyone help here?
First, i dont understand why some people think its a bad idea nvidia are doing Cg. One of the goals of Cg is easier crossplatform development.. thats a noble cause if any =D
Secondly, my bet is OpenGLs shading language and Cg will eventually merge.
check: this
and notice this part:
Compatibility with DX is very important, but they're willing to weigh advantages of changes vs. cost. Cg and the proposed "OpenGL 2.0" language are similar but not identical; both look like C, and both target multiple underlying execution units. Interfaces, communication between nodes, and accessing state across nodes are different. It's very late, but not too late to contemplate merging the two languages.
Unless the language is truly platform independent, it's not worth any serious learning investment. As it will be completly worthless when you don't have access to that.. propietary thing.
.. :)
So when the language works consistently defined and works across vendors of gpu's it will be something.
I guess Cg won't work on ATI
V for Vengeance
C for Craphics? Well, at least that how I first read it.
Stop worrying about the risks of nuclear power and start worrying about the risks of not using nuclear power.
The world needs another proprietary language like a hole in the head. Cg was created to reinforce NVIDIA's (then) lock on high-end consumer 3D and to abstract away the wildly differing capabilities of underlying hardware (thus encouraging developers to support the top-of-the-line, high-profit-margin chips without shutting out the huge installed base of older chips).
The first of these is in nobody's interest except NVIDIA. The second is a noble ideal, but very hard to pull off; the range of capability is just too great. It would have made more sense to wait a couple of years until the massmarket went fully-programmable. And there are STANDARD, vendor-neutral alternatives coming in the very very near future, notably the high-level OpenGL glslang.
Whatever their marketing may say, Cg will *never* be a level playing field for other IHVs. Thanks all the same, but we do not need, or want, another GLIDE.
Sure Cg was developed and supported by NVIDIA but it works on a higer level than that. It compiles Programs down to either the DX shader language or the OpenGL ARB standards. The only vendor specific part is support for older hardware (NV_vertex_program extension and the like) but nothing is holding back someone from creating a profile to support ATI's proprietary extensions.
It is another layer and a nice one to boot. There is no performance loss running it on ATI's cards, infact the few demos I have written have run better on my friends radeon than on my Geforce3 by a long shot.
Quit trying to demonize nVidia for bringing some peace to the hectic world of writing shaders nine thousand different ways so some guy with an obscure video card doesn't complain.
-bort
Forgive my ignorance, but is Cg made for NVIDIA only? Or is it even optimized for NVIDIA chips?
If it is one of the above, I think that this is another gimmick for NVIDIA to get a greater market share
I remember back in the days when some of the more elite among us would do some very elegant demonstrations of the graphical capabilities of the tiny computer systems at the time.
Where have they gone?
I'd like to see what can be done with today's hardware when it's really pushed to the limits, along with the same style of creativity that these guys had.
Even just some individual demonstrations of what is possible by doing some clever hacking in the Cg context would be awesome.
I miss the Amiga. =(
Please consider making an automatic monthly recurring donation to the EFF
And thats's what Carmack thinks of it.
If he writes Quake 4 in Cg - it's in.
It's Christmas everyday with BitTorrent.
Cg was developed, designed, and created by nvidia. While one of their claims is that it can be made to run on any card and is multiplatform, don't let that fool you. Cg is, at its worst, a thinly veiled attempt to convince developers to produce optimal code for nvidia cards at the expense of broad hardware support. ATI has already said that they will not be supporting Cg (in order for it to work best on ATI cards, someone needs to create profiles for it) and will instead be supporting HLSL. I doubt S3/Via or SIS have the resources to commit to 2 different projects, so I bet they're going to go with HLSL.
If you don't understand why nvidia might be looking for code that works best only on its cards (it's almost a "duh" question), look at it a different way. Look at the GFFX. In almost every instance, it's a failure. Sure, it can stick to 32-bit precision, but it runs really, really slow when you do (just look at the 3dmark03 scores recently released and john carmack's .plan comments). When it runs at 16-bit precision, it's still damn slow, almost always losing out to the Radeon 9700/9800s, but it's a little more competitive (DX9's minimum spec appears to require 24bit precision, but rumor says the jury's still out on that). It's in nvidia's best interest to make the FX appear to be fast (which it isn't), and so they're relegated to make Cg code that optimizes for nvidia cards their best interest.
Sorry I don't have links, but the beyond3d.com forums have a lot of information on this subject.
His $20 kickback arrived late.
Just a thought. I would rather have a program that runs well in both Linux and MS but requires an NVIDIA card than one that runs in Windows only but can use any card. Top all this off with the fact that there are indications that routines written in CG work well on modern ATI cards and what is the problem?
If a company, Nvidia in this case, makes an effort to make their product work better in Linux than I consider this a good thing. OpenGL is a fine thing but at the rate in which it is evolving I will be jacking in before it get's ratified. CG can be used today, and it offers some benefits.
Try http://www.cgshaders.org if you are looking for factual information about Cg. The forums there have accurate information about what Cg is and are pretty helpful.
- Anonymous Coward