Archived

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

skow

Does any one use Nvidia's Cg?

Recommended Posts

Ive been thinking about triing it out. But to learn it takes quite an investment. Has any one tried it? Any reasion not to use it? Is it worth triing? Thanks

Share this post


Link to post
Share on other sites
i use Cg. u are right though, it does take a long time to learn it. if u know c++ then you are ready to go. it just takes a while to get your head around the semantics and a lot of the effects it covers.
there is a forum that i found thats called cgshaders.org. everyone there programs with it.
one thing to remember... make sure you have ALL OF THE SEMICOLONS ( ; ) IN THE RIGHT PLACES!!! trust me. i thought my application was not loading the shader right. o well thats just me.
quick answer for you learn it. its much easier than using assembly.

[edited by - adam17 on October 12, 2003 1:42:44 AM]

Share this post


Link to post
Share on other sites
well u can do it one of two ways. you can run the vertex or fragment program through the cg compiler and get either a .vp or .fp file out of it which you load into your application. the other way is to compile the code at run time. doing it at run time you must include a lot of other files for the release.

Share this post


Link to post
Share on other sites
Ok cool. Is there a prefered tutorial for using cg? There is that one book, but i would like to try cg before investing money to get a book on it.

Poor college student syndrome

Share this post


Link to post
Share on other sites
I learned Cg, now I use HLSL. The two are based on the same syntax and libraries. DirectX takes care of the compilation for you. Other problem was that Cg wouldn''t compile any fragment shaders on my Radeon 9200 but HLSL would.

Tom

Share this post


Link to post
Share on other sites
I''m also using Cg. It''s very good and much easier than using ASM code. It''s just like normal C but with new data types such as vector floats and matrix floats and some graphics specific functions.
If you compile Cg code using the runtime method (you have to include header files and libraries) the runtime-compiler tries to improve the performance of your Cg shaders based on the hardware it runs on.
I bought NVidia''s "The Cg Tutorial" book and it is really helpful if you want to get into shader programming (using Cg), but you should already be familiar with C/C++. So you should get ahead with it even if you are a beginner (though I wouldn''t suggest beginners to start with shaders ) But I believe there are some tutorials on the net, too (check NVidia and Google for Cg/HLSL). adam17 already mentioned www.cgshaders.org, they have a good forum and some shader samples for you.

Share this post


Link to post
Share on other sites
its taken me a while to learn how to use them, but let me tell you this, its taken me a LONG time to learn it. i bought the book when it came out in early may. im still having a hard time getting some basics. of course the reason for that could be i have not spent day after day grinding it into my head. o well.

Share this post


Link to post
Share on other sites
quote:
Original post by skow
Any reasion not to use it?


Yes there is a 'reasion' at least : with Cg you can't fully control the GL state changes. That's a good point as well as a bad point.
The good point is that Cg handles everything for you (well, almost everything ). The bad point is that you can't fully optimize your engine since you don't know which GL calls are performed inside the Cg functions.

[edited by - vincoof on October 13, 2003 3:37:33 PM]

Share this post


Link to post
Share on other sites
quote:
Yes there is a ''reasion'' at least : with Cg you can''t fully control the GL state changes. That''s a good point as well as a bad point.

I don''t understand this one... looks like it can do everything I need to do in the fragment pipe. Can you please explain me what do you mean?
quote:
The good point is that Cg handles everything for you (well, almost everything ). The bad point is that you can''t fully optimize your engine since you don''t know which GL calls are performed inside the Cg functions.

Ack. This is a very unfortunate thing. Maybe CgFX helps here but for now I really need to parse out the Cg shader to understand what''s going on (for example, separate multiple passes, set up texcoords accordingly and so on).
Looks like in a totally data-driven world Cg takes a lot of time to fully integrate in a scalable technology.

For simple programs I must say it''s a definite step over ARB_vp and ARB_fp. If you have only register combiners that there''s a real gain anyway (I wasn''t able to get nvParse anyway ).

Share this post


Link to post
Share on other sites
quote:
Original post by Krohm
I don''t understand this one... looks like it can do everything I need to do in the fragment pipe. Can you please explain me what do you mean?



I mean that in Cg you basically use a shader by calling something like :
shader.setup();
and in that call you never know exactly what happens inside, so it''s hard to optimize state changes with other shaders you may have made yourself for other objects.

Share this post


Link to post
Share on other sites
Well, you group by shader instead of specific state changes. Though, since Cg compiles down into ARB_VP and ARB_FP/NV_parse code anyway, you know pretty much exactly what it''s doing.

You have to remember that you''re unique, just like everybody else.

Share this post


Link to post
Share on other sites
Indeed, the problem is that "pretty much exactly" part.
When you write your own 3D engine, you need to know "absolutely exactly" which GL state changed. However, you still can push/pop states but it kills performance.

[edited by - vincoof on October 17, 2003 6:12:04 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by vincoof
I mean that in Cg you basically use a shader by calling something like :
shader.setup();
and in that call you never know exactly what happens inside, so it''s hard to optimize state changes with other shaders you may have made yourself for other objects.

Mh, I agree, this may be a problem but every VP/FP pair is pretty "self contained" in itself so I personally don''t think this is a real problem. If you do your VP/FP combo well enough I think there will be just few things to mind about (blendFunc,depthFunc and polyOffset comes to mind) which are the things which VP/FP cannot control.

My two cents on not optimizing state changes too much.

Share this post


Link to post
Share on other sites