Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: One shader that does everything or multiple shaders?

  1. #1
    Intern Contributor
    Join Date
    Oct 2005
    Location
    Belgium, Liège
    Posts
    70

    One shader that does everything or multiple shaders?

    Hi all,

    I was wondering what could be the best solution performance-wise:

    > to use one shader which does my blinn-lighting OR bump-mapping, according to a parameter, or
    > to use one shader per specific use-case, keeping in mind changing shaders at render-time is really time-consuming?

    I guess you're all going to tell me "render the blinn faces first, change your shader, then render the bump ones", but my file-format provides objects in which there are faces, some maybe blinn and some bump... So I can't definately sort them by "shader-type".

    What could be the most interesting solution?

    Thanks!

    HardTop

    www.hardtopnet.net
    Don't tell me what's in, tell me how to write
    Don't tell me how to win this fight
    Isn't your life, it isn't your right to take the only thing that's
    Mine

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    3,115

    Re: One shader that does everything or multiple shaders?

    If the file format tells you which faces have a certain shader, how can you NOT sort by shader?

  3. #3
    Intern Contributor
    Join Date
    Oct 2005
    Location
    Belgium, Liège
    Posts
    70

    Re: One shader that does everything or multiple shaders?

    Because I don't actually loop on the faces, but on the objects, each containing a list of faces...
    Don't tell me what's in, tell me how to write
    Don't tell me how to win this fight
    Isn't your life, it isn't your right to take the only thing that's
    Mine

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    3,115

    Re: One shader that does everything or multiple shaders?

    And you can't transform the object into a data structure that allows you to do it?

  5. #5
    Junior Member Regular Contributor Zulfiqar Malik's Avatar
    Join Date
    Jun 2004
    Location
    London, UK
    Posts
    247

    Re: One shader that does everything or multiple shaders?

    Originally posted by hardtop

    > to use one shader which does my blinn-lighting OR bump-mapping, according to a parameter, or
    The OR part won't serve much purpose if you want to support hardware that does not provide dynamic branching support, in which case the entire heavy shader will be executed.
    I would really advise you to sort if your meshes can contain triangles that need to be rendered with different shaders (which is not a recommended scenario altogether). Supposing that you will be rendering multiple meshes in any given scene and that you can extract material information from each mesh then i would recommend batching triangles together in the form of triangle lists and rendering them in one go with a particular shader. For example you can batch all the faces of all the meshes using shader A and render them in one go. Similarly you can batch all the triangles of all the meshes using shader B and render them in one go. Although the technique can be restrictive for a relatively general purpose scene graph such as those used in game engines, it can work well enough for smaller, more focused scene graphs.
    Zulfiqar Inayat Malik.
    Senior Developer, The Foundry.

  6. #6
    Intern Contributor
    Join Date
    Oct 2005
    Location
    Belgium, Liège
    Posts
    70

    Re: One shader that does everything or multiple shaders?

    Yes, I know that the OR part will still execute the whole shader on pre-SM3.0 boards, such as mine.

    So you all mean the main idea is to (basically) loop through all the scene, render faces with shader A, then re-loop through all the scene, and render faces with shader B?

    This is a first idea, I guess if I do this, I'll have to perform some optimizationto reduce CPU consumption because of the loops. But could this be the point?

    Thanks
    Don't tell me what's in, tell me how to write
    Don't tell me how to win this fight
    Isn't your life, it isn't your right to take the only thing that's
    Mine

Posting Permissions

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