shaders: directx/opengl

This is a discussion on shaders: directx/opengl within the Game Programming forums, part of the General Programming Boards category; i've eventually started doing shaders (something i wanted to do years ago ). so now i wonder if there is ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    244

    shaders: directx/opengl

    i've eventually started doing shaders (something i wanted to do years ago ).
    so now i wonder if there is a way to make shaders portable between e.g. open gl, directx, some software renderer, ....
    is there a standard?

    as far as ive understood this, you can specify a shader by some source file/string and then compile it.
    so my questions are basically:
    is there a standard already for the source language?
    or is there at least a standard for the format of the compiled shader?

    also those of you who have done shaders in both, opengl and directx: is access to those uniform variables similar? or are there major differences?

    if you know some good links, plz give me some.

    the reason i ask this, is because i want to write my own render-device class, which abstracts from the actual lib used (so opengl and directx). it is pretty easy to do so for textures, vertex buffers and index buffers, but since i have basically no experience with shaders (xept that they are basically ordinary assembler programs) i'm not sure, of how complex it is to make up an interface which works well with both apis (and possibly others)
    signature under construction

  2. #2
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    I'm not real familier with Direct3D (Bubba could probably tell you more about shaders on that platform), but I know D3D uses HLSL as it's shading language. On OpenGL, you can use GLSL (which is now part of the OpenGL 2.0 spec), or Cg (an nVidia technology, which is pretty much been replaced by GLSL on the PC).

    I can't say how similar they are as I only use GLSL. I know the syntax between HLSL and GLSL is pretty different, but that's about it. I also know Cg and GLSL are very similar.

    As for the format of the compiled shader, there is no standard (ie, GLSL and HLSL aren't interpreted the same by the GPU). However the uncompiled shader (input form) will most commonly be in text/ASCII format.

    www.humus.ca: contains many many excellent demos of HLSL, GLSL, and assembly shader effects. Lighthouse3D is where I learned GLSL.
    Memorial University of Newfoundland
    Computer Science

    Mac and OpenGL evangelist.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    hehe, so i'd have to write a EHLSL (even higher level shader language) which is then compiled either to hlsl or glsl nah, thats too much work for now.
    hm... this is somewhat sucky - so it seems all shader-sources would have to come in a render-device-specific versions

    well at least i can still define a common interface for shaders in opengl and directx - just the source code passed to it must be the right one for now. well i guess i can live with that for now. i just don't want to mess up the interfaces since the graphics-engine should be independent of the implementation of the render device (as far as possible). (i just hope that all those virtual functions (and interfaces) don't slow things down too much :/ )

    well thx 4 the links though
    signature under construction

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    HLSL is as high level as you need for right now as far as DX goes. I'm sure GLSL is the same.

    HLSL is like C++ for shaders, at least a C++ in it's infancy stages. Look for much more support in the future.

    Amazing how everything ends up being like C++ eh.

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    >> HLSL is as high level as you need for right now as far as DX goes.

    yes, i just would have liked shader sources which can be compiled either with directx or opengl. so in case i (or someone) does a directx port of the render-device i made (for whatever reasons) doesn't have to port the shaders too.

    so if there is no standard shader language, then i'd want at least a compiler that compiles glsl to hlsl. hmm... ill google if maybe someone already did such thing...
    signature under construction

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    >> Amazing how everything ends up being like C++ eh.

    well actually c++ is just a convenience extension to c (c++ can be rather easily compiled to c), and c is basically a better macro assembler, so c++ is just a convenient macro assembler, uh...
    signature under construction

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Where to get started with directx shaders
    By Tonto in forum Game Programming
    Replies: 8
    Last Post: 03-14-2009, 12:59 PM
  2. Compiling shaders
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 01-18-2006, 12:45 PM
  3. 2 pixel shaders
    By Magos in forum Game Programming
    Replies: 8
    Last Post: 06-13-2005, 06:51 PM
  4. Pixel Shaders.
    By Cheeze-It in forum Game Programming
    Replies: 1
    Last Post: 05-21-2002, 01:16 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21