Log in

View Full Version : State of the Shader


ggambett
02-05-2004, 07:56 AM
This is actually embarrasing to admit, but I've allowed myself to lag behind, mostly because I didn't have time for anything. Now that I've graduated, I want to plug some of the holes.

Therefore, vertex and fragment shaders. I know assembler, I know algebra and 3D math, so every example I've read makes perfect sense. But I've never got to implement and try a shader.

I'm mostly concerned about compatibility. What shader language should I use? I'd like to use the most portable and compatible language, not necesarily the most powerful or fancy. Something that can be used in OpenGL and Direct3D, and that works with most of the cards. Is Cg that? Is there any practical reason to not use a high level language?

I haven't found any complete and consistent online reference... everything it's either too proprietary or too specific. Any recomendations?

Thanks!
--Gabriel

Impossible
02-05-2004, 01:41 PM
This is probably a better question for gamedev, flipcode, or one of the other multitude of sites out there with a strong graphics community (cgshaders, mrgamemaker, opengl.org, etc.)

I'm assuming this is just for learning purposes, but here on Dexterity people have long arguments about whether relying on 3D acceleration will hurt your sales. Considering the installed base with some kind of 3D acceleration vs. the amount of users with even vs\ps 1.1 level shader support, most people on Dexterity would tell you that requiring shaders will completely kill any chances of your game selling and that adding shader support to a 3D game is probably a waste of time. This could be true, at least if you're making a casual game, but there is a possiblity that a cool indie 3D game or benchmark would sell well.

The only commercial shading language that can be used with both OpenGL and D3D (to my knowledge) is Cg, so if you need something that works with both you'll have to go with that. HLSL is very similar (basically the same) as Cg but it integrates with D3D a lot better. There may be a few more complex academic research based alternatives (the Stanford shading language?) and some other beta stuff out there but Cg is probably the most practical.

If you want to learn Cg I suggest you go to nvidia's developer site and www.cgshaders.org. On those sites you can download the SDK, the documentation, and tons of examples. Note, although Cg works with both OpenGL and Direct3D there are two very different interfaces for each of them. Alternatively you could just use Cg as a compiler. I'm also not sure how well Cg works with ATI hardware right now. In the past the compatibility has been pretty bad.

As far as I know the only reason to not use a high level shader language is with ps 1.1 and perhaps ps 1.4. Because the instruction set and instruction counts are so limited trying to get all but the simpliest high level code to compile to those targets will be very annoying. The shader highlevel shader compilers out there are supposedly very good and often produce better output than hand optimized assembly would.

If you just want to play with shaders and not have to worry about APIs and writting a framework or an engine, I suggest you go to the ATI developer website and download render monkey. It will quickly get you started with experimenting with writting shader code without having to deal with all the set up mess, and it's a pretty good way to prototype shaders.

Kai-Peter
02-06-2004, 03:21 AM
Many engines (and DirectX 8.1 and up) also support "technique" scripts for materials. What this means is that you define maybe 2-3 different ways of producing a material and the engine falls back to the one that is supported by the target hardware. Some engines (e.g. OGRE) also allow you to LOD by the material forcing the engine to drop quality as the model gets further away from the viewer.

If you have a fallback mechanism like this it might actually be a boost to sales if you support better graphics on more modern hardware. I have given this a lot of tought lately, and one of the good things with short dev cycles (3-12 months) is that you target reasonably current hardware, this in contrast to longer project (retail) where you have to target "future" or non-existent hardware. It is pretty cheap to add new material definitions (it does take time) and the fact is that most people upgrade at some point anyhow, making your game shine for those extra few years.

Anthony Flack
02-06-2004, 04:18 AM
I think the main problem would be that with an online-distributed game, you can't simply bundle the latest directX with it. You have to rely on people already having installed it.

ggambett
02-06-2004, 05:39 AM
Thanks for your replies. That's exactly what I needed.

Impossible, I ask here and not in those forums to avoid gratuitous insults ("you don't know shaders? J00 5uxx0rz!") and to have answers with a business perspective (not "use ps 5.0 which will be released on 2005 because it's 1337!")

Impossible
02-06-2004, 07:10 AM
Originally posted by ggambett
Impossible, I ask here and not in those forums to avoid gratuitous insults ("you don't know shaders? J00 5uxx0rz!") and to have answers with a business perspective (not "use ps 5.0 which will be released on 2005 because it's 1337!") [/B]
Yeah, I understand that. You may or may not be insulted depending on where you post and who feels like answering. You definitely wouldn't get a business perspective though.

Kai-Peter
02-06-2004, 08:28 AM
Originally posted by Anthony Flack
I think the main problem would be that with an online-distributed game, you can't simply bundle the latest directX with it. You have to rely on people already having installed it.

The fallback method doesn't rely on you having the latest DirectX. To take OGRE as an example, it contains a DirectX7 fallback that provides basic rendering capability. That way you can write Cg scripts using the absolutely latest shaders and still have a reliable fallback for older computers. With broadband slowly taking over the download is also becoming less of a problem.

Because your game is small, it doesn't neccessarily have to use only 2D hardware. The business side is the most important factor after all. For example Space Station Manager requires 3D acceleration of some sort to be playable. If you put your baseline at DX7 there is still a lot of people who have substantially better hardware and more updated drivers. Why not cater something nice for them as well.. :)

Anthony Flack
02-06-2004, 06:14 PM
If it actually falls back on older DX versions too, then that is pretty cool for sure.

Larry Hastings
02-07-2004, 12:31 AM
I hope this is relevant to your discussion. If not, my apologies.

From what I could tell, support for shaders in DX8 and above is wunderbar. First you write your shader; in DX8 you had to use shader assembly, in DX9 you can use High-Level Shader Language (HLSL). Both of those are video-card agnostic. (Cg is nVidia-only. ATi's ASHLI looks like it's just a preprocessor which can spit out HLSL or OpenGL's shader language.) Second, at runtime you determine whether the card supports shaders at all, and if so what version. If the native hardware supports your shader you're home free. If it doesn't, you switch on software vertex processing. DX8 JIT recompiles your shader into native code at runtime, using whatever processor extensions (MMX, SSE, 3DNow) are available (I've seen this described in detail, but all I could find was a passing mention here (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndrive/html/directx01152001.asp)). I've seen MS claim that it's not really all that much slower to do it in software, but I guess it depends on how heavily you used it.

I know OpenGL has a portable shader language too; perhaps someone who knows more can post here and describe it.

Personally I'm not ready to start using shaders. Programmable graphics pipelines didn't hit hardware until the GeForce 3, which means any previous part will require software vertex processing to use vertex shaders. I might use 'em in a game or two (depending on how long these things take me to squeeze out), but perhaps only in a small way, not enough to kill framerates on old parts.

Finally, I don't really want to rekindle the "don't use DX8! no sales!" arguments, but: DirectX 8.0 shipped in November of 2000. It's over three years old now. It's built in to Windows XP, and every retail game sold in the last, say, 2.5 years has come with DX8 or above. I don't use shaders, but my game does require DX8, and I feel pretty confident about it.

Cornutopia
02-07-2004, 11:43 AM
Finally, I don't really want to rekindle the "don't use DX8! no sales!" arguments, but...

As a general information point, my latest game so far has sold about one per day, pricepoint $21. It requires DirectX9 and uses vertex shaders v1.1.

I think that if shaders will add something cool to a game, use them. Simple as that. A lot of indie games simply don't use a lot of the fancy effects you get in console games or AAA titles. Alien Flux has just about everything you could want. I use shaders because I like the concept and the efficient way they render.

Mark
Cornutopia Games
http://www.cornutopia.net

elias
02-08-2004, 06:17 AM
Larry Hastings: I don't think Cg is nvidia only. It might optimize for nvidia cards, but that's all.

If I were to use a shading language with support for directx and opengl at the same time, Cg would be it.

- elias

Larry Hastings
02-08-2004, 09:44 AM
Ah, you're right about that. On this page (http://www.bjorn3d.com/_preview.php?articleID=22&pageID=65) I found the following:NVIDIA will optimize the compiler for their own hardware. (Big surprise.) The Cg Compiler will also work with other hardware, like the ATI Radion 8500, which is good news for graphics programmers.Also, yes, I agree with you; HLSL would be a poor choice for someone using OpenGL :p

I'm a bit chagrined to see that the Cg toolkit hasn't changed for more than a year. In a market as fast-moving as graphics, I would have expected it to get constant updates. Are shaders really that stable?

Cheers,

elias
02-08-2004, 10:05 AM
Yeah well, Cg already supports directx shaders and all OpenGL assembly language shaders (ARB_vp/fp and NV_fp/vp). Only the new OpenGL shading language is missing, but nvidia hasn't even got around to implementing that in their drivers yet....

- elias

Nutter
02-08-2004, 10:45 AM
I'm a bit chagrined to see that the Cg toolkit hasn't changed for more than a year. In a market as fast-moving as graphics, I would have expected it to get constant updates. Are shaders really that stable?There's a new beta of Cg on NVidia's registered developer site.

Only the new OpenGL shading language is missing, but nvidia hasn't even got around to implementing that in their drivers yet....The 55-series drivers and beyond will support GLSL (simply by packaging Cg with the drivers), and there's also a beta of these on the NVidia registered developer site (however you have to enable GLSL support manually, and they haven't made that information public yet).

Impossible
02-10-2004, 07:48 AM
Originally posted by Cornutopia
As a general information point, my latest game so far has sold about one per day, pricepoint $21. It requires DirectX9 and uses vertex shaders v1.1.

Very interesting... This is an argument against a lot of what you hear on Dexterity. Not only does it require DX9, but it uses vertex shaders. Sure, vertex shaders aren't a big deal because they run very quickly on a decent processor, but it's interesting to hear. One sale a day isn't incredible but it's not bad either.

How many tech support emails do you get with this game? It would be nice to have a general number on the amount of people that download it and find out they can't play it.