View Full Version : cg experiences
im looking at supporting cg in my game but first would like to hear other ppls experiences good or bad
does it have true global uniforms? (glsl doesnt but u can use the builtin fixed function stuff to messy-ily emulate them)
half data types just work right? eg half X = 1.0;
i assume with the vast majority of rendering u will be hard precessed to visually tell the difference between half + float
cg allows precompilation of the shaders? thus i can read the shader exe straight off the disk (save development time)
10-23-2006, 01:56 PM
Cg compiles to assembly text for various OpenGL extensions and I believe if the extension supports it, you'll be able to use global uniforms.
Half data types just work for profiles that support them.
Precompilation is supported. You can for example compile a shader with cgc.exe, save the output to a text file, then pass that to cgCreateProgramFromFile with the appropriate arguments.
thanks, ive downloaded cg1.5 + will try it out today (download was only ~10mb, i was a bit worried it was gonna be like nvperfkit ~80mb which i downloaded at the start of the month when my monthly bandwidth limit was reset, only to find it would freeze during installation twice, anyways i see 2.1 is out now + it mentions something about installation so maybe thats fixed, could be just my gffx though, im gonna have to bite the bullet + buy a gf7600gs soon)
i assume theres no probs running glsl + cg programs in the same app, well ill find out today
ive been experimenting a bit with cg (had no problems so far)
WRT syntax/feel, somethings are better than glsl + some are worse
not strictly cg but one thing that i dont understand now if i query the glsl shader language version I get the following
opengl shading_language = 1.10 NVIDIA via Cg 1.3 compiler
i assume the cg version is in the drivers? ( i have 91.xx ) I dont see any cg dlls in the windows directory
thus why such a lag? ie ive just downloaded cg 1.5
btw just ordered a gf 7600GS, should be fun, my only worry is the passive cooler, i record music thus want silence, but im worried about how i use it (wrt graphics programming, i dont play games)
flatout for a minute + then rest for 5 minutes flatout for a couple of minutes + then rest etc. I know for some machines ive worked with, this is the easiest way to kaput them,
its better to leave them running flat out all the time, instead of heat cool heat cool heat cool
having a good conversation with myself
heres my results of testing with a runof the mill shader ie normalmap + diffuse textures with blinn shader model with specular as half vector
cg float vs glsl = same speed
cg half vs glsl = cg ~18% quicker ( no visual difference between the two )
oddly in cg using lit( .. ) can actually slow it down, contrary to the doc's
thus not to bad ~18% speedup with no quality loss, this is with a gffx though, with other hardware the difference oprolly wont be as great
why do i have to use a variable that i export from the vert shader in the frag shader?
sure its logical that u want to do this but during testing u often wanna just test out a subset of a shader,
at the moment to do this i have to do a bad hack eg result = result + the_var * 0.000001
btw is there a specific cg forum?
10-27-2006, 10:06 PM
Zed, why use Cg when there's GLSL?
I mean, we've already got HLSL, which is what Cg is, more or less. Sure, Cg is cross platform, but then so is GLSL, and it's not tied to a particular IHV (though with the state of the current ARB I'm not so sure that can be qualified definitively).
I think if you want to promote OpenGL you need to promote GLSL, since the shading language, as I see it, is the real future of the API at large.
im not looking at dumping glsl ( in fact i say i prefer the glsl syntax cause ironically it more resembles c )
supporting both is also good since it helps u structure your app more (word for not so tied to a particluar style) so is potenetually more stable
theres also performance benifits (on gffx at least) of cg being about 18% quicker, plus the precompilation is a plus when youre developing an app + contually starting + stopping the app (thus app startup times are faster)
cg is also is the main shading language on the ps3
11-01-2006, 09:37 PM
FWIW, using 'half' type is possible in GLSL on NVidia, it's part of its GLSL "improvements". There's a define allowing to check if 'half' is available, such as :
# define half2 vec2
# define half3 vec3
# define half4 vec4
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.