Jump to content
  • Advertisement
Sign in to follow this  
Great_White

Cg Semantics ??

This topic is 3627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What's the purpose of using semantics in shading languages? Are they hardware gpu releated storage locations ? Any help would be appreciated.

Share this post


Link to post
Share on other sites
Advertisement
I use them to specify the hardware registers to be used. Here's a bit docs that I copied from the cg reference pdf into a neat table, putting it in a header, to look it up easily.


2) making textures take a specific unit:
Units are TEXUNIT0... TEXUNIT15
uniform texture2D myTex : TEXUNIT7;
uniform textureRect myRect : TEXUNIT3;


3) binding semantics for Uniform data:
uniform vec4 data1 : C0;
uniform vec3 data2 : register(c1);
uniform vec4 data3 : C2;

Constants are c0...c255

4) binding semantics for attribute Input:
attribute vec4 myAtt : ATTR7;

POSITION, ATTR0 Input Vertex, Generic Attribute 0
BLENDWEIGHT, ATTR1 Input vertex weight, Generic Attribute 1
NORMAL, ATTR2 Input normal, Generic Attribute 2
COLOR0, DIFFUSE, ATTR3 Input primary color, Generic Attribute 3
COLOR1, SPECULAR, ATTR4 Input secondary color, Generic Attribute 4
TESSFACTOR, FOGCOORD,ATTR5 Input fog coordinate, Generic Attribute 5
PSIZE, ATTR6 Input point size, Generic Attribute 6
BLENDINDICES, ATTR7 Generic Attribute 7
TEXCOORD0-TEXCOORD7,
ATTR8-ATTR15 Input texture coordinates (texcoord0- texcoord7), Generic Attributes 8–15
TANGENT, ATTR14 Generic Attribute 14
BINORMAL, ATTR15 Generic Attribute 15

5) binding semantics for varying Output/Input:
varying vec4 myVar1 : TEX0;

POSITION, HPOS Output position
PSIZE, PSIZ Output point size
FOG, FOGC Output fog coordinate
COLOR0, COL0 Output primary color
COLOR1, COL1 Output secondary color
BCOL0 Output backface primary color
BCOL1 Output backface secondary color
TEXCOORD0-TEXCOORD7,
TEX0-TEX7 Output texture coordinates
CLP0-CL5 Output Clip distances


For instance, in my glsl code, that I will compile with cgc.exe, if I want one of my textures to be exactly using unit 7, just specify:

uniform texture2D myTex : TEXUNIT7;

It is very useful, as I can skip setting-up some special textures again and again (env cubemap, global noise texture, etc). Also, it's vital when I develop shaders, that I will be compiling and passing them as ARB (asm) shaders, because if I don't use some varying in both the vtx-shader and frag-shader, their order is messed-up. For instance, if I have 3 varyings: "v1,v2,v3", and I don't use v1 in the frag-shader, then the data I expect in v2 will be actually in v3. Once I specify which registers to be used, I can be sure my data will be properly passed. Also, I can know the address of uniforms easily :).
I use ARB shaders, because I don't want to recompile 500 shaders at runtime and I don't want to make it easy for the driver to decide to recompile shaders if I set some uniform to "0.0f".

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!