Tutorials Request: Cg Shaders

EDIT: There is a need in someone who is native English-speaker and could do proof-reading. Contact me or Azraiyl.
EDIT2: Thanks to ZeroByte for help!

Dear friends,
After a lot of reading I still can’t program a Cg shader :frowning:
So, I would like to ask for your kind help. Could someone skilled in this area write a set of step-by-step Cg tutorials for newbies, simple and comprehensible? Something Panda-oriented, without difficult technical words, and in plain English :slight_smile: This would be of great help.

May I ask what you want to do in Cg? Cg as itself is not that hard to understand, but the things you normally do with Cg can be quiet complex e.g. if you don’t know for what matrices are for. Panda3D pretty well tries to hide the math behind the things, but with shaders you have to care about this math.

My best starting point was: http.developer.nvidia.com/CgTuto … atter.html

If you still think you need a tutorial I can write about 2 - 3 basic examples, but I will not write anything about fancy effects or shadows. But I’ll only do it if you correct all my spelling mistakes :slight_smile:

Thanks, Azraiyl!

This book was a starting point for my Cg studies but after many tries I gave up: it was too complicated for me. It has lots of practically useless info, while the important stuff is deeply buried under unreadable technical terminology (of course, it’s from the point of view of a newbie like me, for somebody with better education it makes more sense, probably).

What concerns the purpose of learning Cg, reason #1 is finally adding shadows to the shader generator :smiley: It really upsets me that it doesn’t have shadows. Of course, it is a long-term goal, I don’t expect such things from the tutorials. We can say, it is letter “O” in the alphabet, and the tutorials should cover first “A”, then “B”, then “C”…

Of course, there is a lot of samples and white papers in the internet. But, at first, I must learn to understand how Cg works, how to read this code, what means this, what means that. Something basic and related to Panda. Something, like “let’s make this and that, then run Panda… and voilà ! our object is now red!” :smiley: Something on this level, and maybe a little more advanced.

you have to know very many complex details in order to write shades correctly. You can just say add shadows because well there is 10s of different ways to do it and 100 different ways it can be implemented each having trade offs,

Unfortunately treeform is right. There are tons of extrem technical papers out there (the NVidia Cg tutorial is a piece of cake compared to them) that only care about shadowing. In most games that I’ve played (ok that aren’t that many) shadowing wasn’t implemented correctly for every case (the fancy thing is as a coder you see such things), even the pros out there need to simplify most of the times. One more thing that sux is that all shadow mapping algorithms I know (ok that aren’t that many once more) need tweaking or else they look really strange or you don’t see shadows at all.

Back to your question. Here my proprosal:

Tutorial 1: Simplest possible (almost useless) shader.
Tutorial 2: Simplest possible (usefull) shader.
Tutorial 3: Start to play around with the vertex/fragment shader and apply some colors.
Tutorial 4: Colorize your objects with the objects predefined colors.
Tutorial 5: Start to feed your shader with input from Panda3D.
Tutorial 6: Apply one texture to an object.
Tutorial 7: Apply two textures to an object and do some fancy stuff with them.

Nothing about normals, nothing about lighting, …

Do you know a little bit about the language C?

Of course, I understand that there are numerous nuances. I would think of it as about learning to run. Making shadows is “running”. The tutorials are needed to learn to walk. When I can walk, I can find a way to running myself :smiley:
About your plan: that would be really awesome!
What concerns C, no, never touched it. This was one of the reasons I gave up with the book: it assumes that the reader knows it, but for me it was just double Dutch…

Then please do me a favor while I write the tutorials. Get in touch with C only for the basics.

en.wikibooks.org/wiki/C_Programming

You (only) need to read till the chapter preprocessing.

If you don’t have a C compiler handy try delorie.com/djgpp/compile/.

If you understand “Simple Math in C” and “Procedures and Functions” than you are ready to get to the next level.

Learning C is anyway a good idea, not because it is an great language (I would say the opposite but that doesn’t matter here), because it is quite a bit different than Python. C would open a new world for you. You even may connect to the Panda3D IRC channel and ask me any question about C, but please do not let me repeat what thousand tutorials already have explained.

irc://irc.freenode.net/panda3d

Started reading :slight_smile:

Because of the lack of criticism (questioner and irc), I don’t know if all tutorials are useable or not, so here they are:

code.google.com/p/p3dst/source/browse/trunk

Azraiyl,

oh wow thats quite good. It would be cool to add standard readout to the app like all the other tutorials that come with panda3d. Then we can even include it int he distribution. Its the best explanation we have of manual shaders so far.

It would also be cool to get to normal maps and lighting - even just touch a little bit on it because they would want to go that direction anyways.

Lack of criticism? The tutorial is just awesome! The most comprehensible guide to Cg shaders I have ever seen!
I have just been a little bit overloaded with C book/tutorial/work/home stuff, but I am digging into it now :slight_smile:

I know that there is more than one typo remaining. And I bet that there is more than one question unanswered.

When I understand drwr correctly, add this to the distribution means that someone has to care about the code. But (based on the feedback) I think either there are people like treeform who don’t need any tutorial at all, and then there are the poeple who never like to write a shader manually and prefer to wait till anything is included. Then there is this one man group (birukoff is the leader) that needs a something to start with. Is it really worth the effort to continue this samples?

I suspect that most of the people who you think are in your second group–people who prefer not to write shaders–are actually in your last group–people who would write shaders if they had some helpful instruction.

So, yes, good tutorials and manuals are almost always useful additions.

David

I don’t know about others, but I imagine that when I want to start working with shaders a tutorial could be pretty useful - but since I’m not working with them at the moment, and am concentrating on other things, I haven’t yet looked at your tutorial, I’m afraid.

Nevertheless, thank you - I’ll probably want to at least take a look at your tutorial should I get around to starting in on shader-work. :slight_smile:

There are four new tutorials about:

  • normals and normalization issues
  • model, world, view, clip spaces
  • per vertex and per pixel point light
  • some more Cg basics

Hmm, the tutorials are really helpful and easy to understand.
drwr, do you think we should include this in the Sample Programs?

The tutorials are absolutely awesome and must be included into Panda’s manual (at least). I think it would great to have someone who is native English-speaker to make proofreading (for the first tutorials, since the last parts are still regularly updated), and then we could incorporate them into wiki and eventually into Samples.
To my mind this is the best and the most comprehensible Cg tutorial in the Internet. Really BIG thing!

I’m all in favor of including them in the distribution. Great work, Azraiyl! Do you mind if we do?

David

I agree that these tutorials are pretty fantastic. I haven’t gone through all of them yet but I’d be willing to proofread them as I do the tuts.

Sure, you can add or move them wherever you want. I only have chosen google code because you can setup a project in < 5 min. It would great if someone with english grammer knowledge looks through the samples. I don’t know how many times I (miss)fixed some minor typos and I know that there are still some flaws.
The only thing that I don’t know if I’m already finished. I’ve learned once more when you start to explain something, you have to answer yourself some question.