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)
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.
hehe, so i'd have to write a EHLSL (even higher level shader language) which is then compiled either to hlsl or glsl :D 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 :)
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.
>> 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... :)
>> 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... :D