Archived

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

biovenger

Shaders

Recommended Posts

Alright, I''ve heard a lot about the enigma and need to know how. Of course, I don''t want any code or such, just a few precious links, maybe a few pointers in the right direction. I know the theory behind the shaders, somewhat anyway. A shader is an alternate way to render things through the normal "pipe", right? Well anyhow, I am using OGL right now and just need to see an article or a quick tip on how to initialize shaders and preferably a list over the existing shaders. If it is possible.

Share this post


Link to post
Share on other sites
OK, links to shader resources:

Humus's Site - This lucky guy spent a lot of time at ATi recently, and has some truly cutting edge demos on his site.
NVIDIA's CG Language - C for Graphics, a high-level language for creating impressive shaders which run on a very wide range of hardware.
ARB_fragment_shader - A full description (from the SGI Extensions Repository) of the ARB_fragment_shader extension.



Coding Stuff ->  [ iNsAn1tY Games | DarkVertex | How To Do CSG | Direct3D Vs. OpenGL | Google ]
Fun Stuff    ->  [ Evil T-Shirts | Stick-Based Comedy | You're Already Here | The Best Film Reviews ]


[edited by - iNsAn1tY on September 2, 2003 11:21:58 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by iNsAn1tY
OK, links to shader resources:

Humus''s Site - This lucky guy spent a lot of time at ATi recently, and has some truly cutting edge demos on his site.



What do I need to run the demos of the site above?? I have a GeForce4Ti 128Mb.

LizardCPP

Share this post


Link to post
Share on other sites
I believe that you''ll need a GeforceFX or a Radeon 5900 to run some of Humus''s demos. They really are the very latest stuff. Most of the demos on the main page don''t work on my Geforce 3. You need support for ARB_fragment_shader.

One thing you could try is NV30 emulation. It''ll run slow as hell, but it''ll work. Head over to NVIDIA''s site and look it up...



Coding Stuff ->  [ iNsAn1tY Games | DarkVertex | How To Do CSG | Direct3D Vs. OpenGL | Google ]
Fun Stuff    ->  [ Evil T-Shirts | Stick-Based Comedy | You''re Already Here | The Best Film Reviews ]

Share this post


Link to post
Share on other sites
Insanity: I think you mean ARB_fragment_program. ARB_fragment_shader is part of the new OGLSL specification, and it's not supported yet except on high end 3Dlabs cards.

ARB_vertex_program would probably be a good thing to learn too.

Both of these are supported on all DirectX 9 capable hardware AFAIK.

[edited by - benjamin bunny on September 3, 2003 8:53:02 AM]

Share this post


Link to post
Share on other sites
Programs written in Cg are compiled using the Cg runtime lib, or alternatively compiled to fragment programs before execution.

You can specify uniform parameters such as light position, shininess etc with Cg or OpenGL functions from your C++ program.

Varying parameters such as depth, position and colour are sent along the pipeline in the usual way, with values output from vertex programs being interpolated between vertices to give the fragment_program input values. You just set these using glColorf or whatever when you specify the vertices.

AFAIK the Cg runtime is the best option, since it makes setting parameters easier, and allows you to compile a program for specific hardware if necessary.

____________________________________________________________
www.elf-stone.com | Automated GL Extension Loading: GLee

Share this post


Link to post
Share on other sites
quote:
Original post by benjamin bunny
Insanity: I think you mean ARB_fragment_program. ARB_fragment_shader is part of the new OGLSL specification, and it''s not supported yet except on high end 3Dlabs card.
Bugger. Note to self: check extension wording.

Another good thing about Cg is that if you download Everything.zip from the Cg Downloads Page, you get the compiler, a viewer, and a whole bunch of ready-made shaders which demonstrate everything from bumpmapping to cel shading to shadowmapping. They''ve been very useful to me in understanding how Cg works. It''s a huge download (around 263MB), but like it''s name suggests, it has everything you need. If that download''s too big, you can download just the bits you need...



Coding Stuff ->  [ iNsAn1tY Games | DarkVertex | How To Do CSG | Direct3D Vs. OpenGL | Google ]
Fun Stuff    ->  [ Evil T-Shirts | Stick-Based Comedy | You''re Already Here | The Best Film Reviews ]

Share this post


Link to post
Share on other sites
Thanks for all the replies, there is however one last thing I don''t understand...

If I compile a program with the Cg runtime library, what kind of output does that provide? Also, how would I then call the program from my engine to alter the pipeline?

Another thing... It is a question that has been nagging me, but probably is very stupid. What is the advantage in coding shaders in Cg, aren''t programs in normal C++ just as efficent? All the code in the Cg examples seems just like normal C++ code with a little different syntax.

Share this post


Link to post
Share on other sites
Cg isn't C or C++. It's a language developed by NVIDIA which just happens to use the C/C++ specification to aid developers. Cg shaders work like textures. You don't load a texture every frame using glTexImage2D(). You create a texture object, bind it, then load the texture into it. The same is true for a Cg shader. You create a shader object, bind it, then load in the shader from a text file. It's compiled as it's loaded. Then, when you want to use a shader, you bind it again, just like a texture, and render your scene.

A note: I'm not 100% about the above. It might apply to ARB_fragment_program, not Cg. However, I think this is the way it's done...



Coding Stuff ->  [ iNsAn1tY Games | DarkVertex | How To Do CSG | Direct3D Vs. OpenGL | Google ]
Fun Stuff    ->  [ Evil T-Shirts | Stick-Based Comedy | You're Already Here | The Best Film Reviews ]


[edited by - iNsAn1tY on September 4, 2003 8:22:31 AM]

Share this post


Link to post
Share on other sites
I understand the semantics of Cg and that it is a programming language that compiles to GPU instructions, etc... That was not my question, sorry for not being clear.

What I need to know, is after compiling a shader, how do I use it from any language that can access OpenGL? Do I execute the shader binary from my program or do I load in a procedure or somewhat? That is the only part that is very unclear and ironically, seemingly impossible to get any information about. There are tons of articles and tutorials about Cg, but none that tell one how to use the shaders from some other API (such as OGL).

Share this post


Link to post
Share on other sites
I''m pretty sure the Cg docs say...

There''s an extra library for using Cg with OpenGL which allows you to load/compile Cg source into shaders then use them while you''re using OpenGL.

I can''t remember the exact workings of it, but the docs are all there.


Why you shouldn''t use iostream.h - ever! | A Good free online C++ book

Share this post


Link to post
Share on other sites
An interesting article appeared in the GameDev articles today: Cg Shadow Volumes. This linked to a document I was quite unaware of, and which I'll be using to understand Cg a bit more. It's an introduction to Cg, using bumpmapping as an example, and it's here: Cg Bumpmapping. It shows exactly how to initialize Cg and load shaders, and will come in very handy, I'm sure...



Coding Stuff ->  [ iNsAn1tY Games | DarkVertex | How To Do CSG | Direct3D Vs. OpenGL | Google ]
Fun Stuff    ->  [ Evil T-Shirts | Stick-Based Comedy | You're Already Here | The Best Film Reviews ]


[edited by - iNsAn1tY on September 5, 2003 6:32:38 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by iNsAn1tY
I believe that you''ll need a GeforceFX or a Radeon 5900 to run some of Humus''s demos. They really are the very latest stuff. Most of the demos on the main page don''t work on my Geforce 3. You need support for ARB_fragment_shader.




Yes you will need a GeForce FX (any) or Radeon 9500 or higher (9000/9100/9200 are DirectX 8.1 cards) for Fragement programs.

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

Share this post


Link to post
Share on other sites