Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Are there major differences between shader languages?

Asked 13 years, 9 months ago Modified 12 years, 9 months ago Viewed 4k times

I am currently learning GLSL. It would seem that once you learn one of the shader languages, learning
one of the others would not be too difficult. Is it something analogous to learning a widget toolset like
2 wxWidgets and then switching to Qt? Once you get the idea of what is happening within one widget
toolset, another toolset will do something similar since they are ultimately doing almost the same thing at
some point? What are your experiences with going from one shader language to another?

opengl graphics directx glsl hlsl

Share Improve this question Follow edited Jun 24, 2011 at 14:34 asked Jun 25, 2010 at 17:49
skaffman Paul Kelly
401k 96 821 773 3,989 8 40 63

5 Answers Sorted by: Highest score (default)

Cg and HLSL are almost the same (same builtin function names). GLSL looks and feels a bit different
(i.e. mix instead of lerp , use of a main -like function), but the overall transition is still easy. The only
6 differences are in the details and in the respective APIs (i.e. stuff like matrix storage order).

Switching between shading languages is way easier than switching between GUI toolkits…

Share Improve this answer Follow answered Jun 25, 2010 at 17:51
Alexander Gessler
46.2k 7 84 124

HLSL has some differences from GLSL. Nothing too different from what I've read. There are some
translation tools out there. There is a SourceForge project HLSL To GLSL tool. Also, I believe that the
4 NVidia Cg toolkit can generate HLSL or GLSL.

Share Improve this answer Follow edited Jun 29, 2010 at 22:01 answered Jun 28, 2010 at 19:57
Walt Ritscher
7,017 1 28 35

In my slightly limited experience, I'd agree with everyone here that they are very, very similar and it's not
a problem to switch between them. However, do beware that, as seems to be the case with most
1 OpenGL/DirectX clashes, I find HLSl to have a few more nice convenience functions that make it a little
more fun to use. I'm talking small things, like saturate, here. However, beyond minor structural
differences, like passing around inputs, the basic concepts are one hundred percent the same.

Enjoy! Shaders are a lot of fun.


Share Improve this answer Follow answered Jul 22, 2010 at 6:44
Perrako
778 4 12

You are right - GLSL/HLSL/Cg shading languages are subset of C programming language, so they are
very similar.
1
Share Improve this answer Follow answered Sep 1, 2010 at 8:45
Agnius Vasiliauskas
11.1k 5 52 71

the origin of directx 3d lies in opengl. microsoft reprogrammed the opengl api to a certain point, because
of this the languages should be similiar.
-3
Share Improve this answer Follow answered Jun 25, 2010 at 23:45
M3t0r
182 9

TBH the ARB have been consistently behind microsoft ont he introduction of all these technologies. GLSL was part
of the modification brought in by 3D Labs into OpenGL 2. Furthermore the driving forward of GL has been as a
direct result of Microsoft telling graphics card manufacturers what the next API level is (Even if they do back down
on certain parts at times). Open GL has thus far only been able to react to trends in graphics cards. MS have the
clout to try, at least, to define the way things are going. – Goz Jun 27, 2010 at 7:25

@Goz that's only sort of true, NVIDIA exported lower level shader functionality to OpenGL before DirectX could
support it, basically whenever the hardware manufactures make something new they can export it to OpenGL as
an extension right away, while DirectX has to wait for MS to bump the API. The NVIDA shader stuff wasn't as easy
to code for as HLSL/GLSL but it WAS there pretty much from the moment the cards that supported it shipped. (This
is where OpenGL shines, it was designed with vendor extensions in mind, DirectX wasn't) – Spudd86 Jun 27, 2010
at 18:01

@spudd: while i get your point GL has done little to drive forward innovation. They almost did. The original GL3
spec would have done just that but Khronos, like everyone before them, bottled it. The extension functionality is a
huge bonus but it is, equally, GL's biggest weakness. It detracts from the cross-platform-ness of it all by forcing
people to write card specific code paths. If you need to do that why not just write platform specific code paths? As it
is I personally have a DirectX, OpenGL and OpenGL ES code path in my engine. Its not that hard but god it makes
life easier :) – Goz Jun 27, 2010 at 20:19

@Goz, yep everyone was disappointed with GL3 (Especially NVIDIA I think), but I think the plan is that GL3 serves
as a stepping stone (dropping lots of old crud, cleaning things up, etc) then they do the nice stuff incrementally,
IIRC GL3.2 is a step towards the original GL3 plan, so there's hope yet that OpenGL could get to the point of being
the leader again :) – Spudd86 Jun 27, 2010 at 20:56

1 @m3t0r The origins of Direct 3D lies in RenderMorph's Reality Lab API which Microsoft bought and renamed to
Direct3D. en.wikipedia.org/wiki/Direct3D – Michaelangel007 Jan 27, 2015 at 2:32

You might also like