Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Semantics for GLSL?

Hybrid View

  1. #1
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Semantics for GLSL?

    I can't see any support for annotation and semantics for parameters in GLSL. When your parameters are only the plain light parameters (direction, etc) you can pass them in as lighting, but when you do things like spherical harmonics, or, worse, arbitrary effects, the set of input parameters really needs rich markup to work well in a production/tool pipeline.

    Cg and HLSL solve this with annotations and semantics -- but what's the GLSL equivalent? I can't find it in the language specification.
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    3,768

    Re: Semantics for GLSL?

    I can't see any support for annotation and semantics for parameters in GLSL.
    Can you explain what "annotation and semantics for parameters" is?

  3. #3
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,444

    Re: Semantics for GLSL?

    You mean like in HLSL,
    Code :
    float4 main(float2 texCoord: TEXCOORD0, float3 lightVec: TEXCOORD1, float3 viewVec: TEXCOORD2) : COLOR {
    // ...
    }
    ?

    If so, then it's just that semantics isn't needed in GLSL. The reason is that a vertex and fragment shader is linked together into a single program object. It can then link the correct parameters to each other and leaves the option up to the driver to decide which texture coordinate gets what parameter. So:

    Vertex Shader:
    Code :
    varying vec2 texCoord;
    varying vec3 lightVec;
    varying vec3 viewVec;
     
    void main(){
      texCoord = ...;
      lightVec = ...;
      viewVec = ...;
    }
    Fragment shader:
    Code :
    varying vec2 texCoord;
    varying vec3 lightVec;
    varying vec3 viewVec;
     
    void main(){
       gl_FragColor = ...;
    }
    [This message has been edited by Humus (edited 01-14-2004).]

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Re: Semantics for GLSL?

    I understand that I can take one of the defined OpenGL semantics and translate that to "something else" in my own application.

    However, Direct3D allows me to define MY OWN semantics. There is no semantic for "camera position" for a parameters. However, I can decide to declare a:

    Code :
    float3 camPos : CAMPOS < string uiTitle = "Camera Position"; string type = "WorldPos" > = { 0, 0, 0 };
    If I have to take some parameter I'm not using (say, light[7].position) then something is missing in the middle to make an application using the program know that this parameter should have the value "camera positoin". I could make this re-definition globally, but then there's a limitation to the number of GLOBAL parameters available, rather on the number of parameters available per shader invocation.

    Also, making these assumptions implicit makes program portability even harder.

    Last, the annotations (the stuff in <> brackets in my sample) are very useful for both documenting what the parameters are, and telling the host program about special-nesses of the parameters. Such as whether they should be exposed in an artist UI, and if so, using what widget (color picker, direction, etc) and using what units (meters, pixels, lumen, ...).

    So, I take it that neither of these requirements are actually met by GLSL? That's a shame. Cg has it, but doesn't have universal vendor support, especially not on the content creation side. It's sad that everything just steps backward as it's being ARB-ized.
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

  5. #5
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,444

    Re: Semantics for GLSL?

    Honestly I don't understand really. The point is that defining semantics in GLSL isn't needed. It serves no purpose there. In DirectX it's neccesary since vertex and fragment shaders are compiled as separate units and you don't know at compile time which vertex shader goes with which fragment shader. Therefore, you need semantics for the driver to know where to map all inputs and outputs. This is not neccesary in GLSL though, and also reduces the likelyness of bugs, allows the compiler to give more informative warnings and errors, and might also lower the shader switching load slightly.

    I don't get at all why you'd use light[7].position or something like that for a camera position? Makes no sense whatsoever. You should be using a shader constant of course.

    uniform vec3 camPos;

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Re: Semantics for GLSL?

    OK, for uniforms, looking it up by name makes sense. Except you can't tag names with annotations to make sense of them in an artist-friendly parameter-tweaker UI.

    But what if you want to supply a per-vertex blorgification factor. Or perhaps a per-vertex slappy-doo level? How would the source code, which is fully capable of supplying either, know where to supply it? At a minimum, you need some way of mapping arbitrary semantic name to vertex attribute channel.

    And, again, meta data makes a lot of sense when you want to build an artist pipe. Perhaps I'm missing it somewhere? I only read through the spec once, and went back once to look for these things, so I could miss something.
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    Jan 2001
    Location
    NVIDIA, Austin, TX
    Posts
    591

    Re: Semantics for GLSL?

    You can map arbitrary semantic names to a vertex attribute channel using the attribute keyword:

    Code :
    attribute float blorgification;
    ...
    void main()
    {
        gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
        gl_FrontColor = vec4(blorgification);
    }
    Then using glGetAttribLocation and glVertexAttrib/glVertexAttribPointer to set the attribute.

    [This message has been edited by jra101 (edited 01-19-2004).]

  8. #8
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    3,768

    Re: Semantics for GLSL?

    Such as whether they should be exposed in an artist UI, and if so, using what widget (color picker, direction, etc) and using what units (meters, pixels, lumen, ...).
    And, again, meta data makes a lot of sense when you want to build an artist pipe.
    Sounds like a job for the almighty comment block.

    Metadata, really, has no buisness being part of the language. You don't need it to bind arbitrary attributes to the language; the GetLocation mechanism takes care of that. The function, then, of metadata becomes solely for non-language purposes. At which point, a comment block is no more or less useful than actual inline "metadata".

  9. #9
    Advanced Member Frequent Contributor
    Join Date
    Jan 2001
    Location
    NVIDIA, Austin, TX
    Posts
    591

    Re: Semantics for GLSL?

    Originally posted by Korval:
    Sounds like a job for the almighty comment block.
    Which would mean you would need to write a parser to scan your shader for specific comments, then inside these comments for the user specified annotations/semantics.

    The benefit of having the langauge and API support user defined annotations and semantics is that there will be a standard way to query/set these values.

  10. #10
    Junior Member Regular Contributor
    Join Date
    Jun 2001
    Posts
    198

    Re: Semantics for GLSL?

    Originally posted by jra101:
    Which would mean you would need to write a parser to scan your shader for specific comments, then inside these comments for the user specified annotations/semantics.

    The benefit of having the langauge and API support user defined annotations and semantics is that there will be a standard way to query/set these values.
    Alternatively you only need to have some extra file which maps your attributes to whatever extra metainformation you want to have .
    That way you don't need to parse any glsl (and if you use xml you don't even have to write any parser at all). You may even embed your glsl inside that file (ala d3dx effects files).

    There's little sense in polluting your shaders' code (which will have to be parsed at production time and it may influence your compilation speed if you piecewise build shaders at runtime from the ones you load at startup) with artist/game design information (IMHO) and there's even less sense in speccing that into a graphics language spec.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •