I want to learn GLSL

Okay, I’ve just started learning GLSL now but still I did not find very good resources to learn it. I was reading an article about GLSL on NeHe productions site and in have done this copy-pasta job from there:

There are four main types: float, int, bool and sampler. For the first three types, vector types are available:
vec2, vec3, vec4 2D, 3D and 4D floating point vector
ivec2, ivec3, ivec4 2D, 3D and 4D integer vector
bvec2, bvec3, bvec4 2D, 3D and 4D boolean vectors
For floats here are also matrix types:
mat2, mat3, mat4 2x2, 3x3, 4x4 floating point matrix
Samplers are types representing textures. They are used for texture sampling. Sampler types have to be uniform. They are not allowed to be declared as a non-uniform type. Here are the different sampler types:
sampler1D, sampler2D, sampler3D 1D, 2D and 3D texture
samplerCube Cube Map texture
sampler1Dshadow, sampler2Dshadow 1D and 2D depth-component texture

Now to be honest I did not understand anything except a few lines of explianation.

  1. I’ve learnt about float, int, Boolean data type in my little study of C++ as well as in Action script but what is Sampler?

  2. What is vector and what are these 2d, 3d and 4d floating vector points are they something like multidimensional arrays. Integer and Boolean vectors???

  3. 1D, 2d and 3d texture ? aren’t textures only 2d?

  4. Is cube map texture something like the way in which cube gets unwrapped in UV editor?

  5. What are matrixes? Are they matrix of math if yes then still me what they are because matrix is in 11th class syllabus and I’m still in 10th. So the conclusion is Matrix was a good movie.

  6. 1d and and 2d shadow? I’ve never seen a width less shadow.

  7. what else I can do with GLSL except bump mapping.

I still have 100s of question to ask but I’m tired now. Good Night.


There are 6 official versions of GLSL, which gradually add and remove grammar and features/objects.

  1. samplers are handles to texture-units. There are 16-32 slots, which you specify by glActiveTexture(GL_TEXTURE0+UnitID) and glBindTexture(GL_TEXTURE_2D,texHandle).

struct vec2{
   float x,y;
struct vec3{
   float x,y,z;
struct vec4{
   float x,y,z,w;
struct mat4{
   float m[4][4];

struct mat3{
   float m[3][3];

Textures are 1D,2D and 3D. 1D is simply a texture type with height=1. 3D is a volume WidthHeightDepth.
A cubemap is a special sampler, that contains 6 2D textures. Fetching a texel from it is done via a 3D normal-vector, instead of a 2D vector. The gpu contains silicon that calculates which of the 6 textures you want to fetch from, and at what 2D coordinates. It’s a very optimized way to do environment-reflections.
Matrices are extremely useful maths-objects: they can concatenate a complex series of transformations. Instead of repeating all transformations individually for every vertex, you concatenate the transforms and multiply all vertices with that matrix.

  1. 2D shadow-textures simply contain depth-info. That depth-info is compared with another calculated value, to determine if there’s a shadow or not. The hardware supports 1D textures, so the object is made available even if only a few developers may need it.

  2. almost everything. It’s software, with some limitations in comparison to general-purpose cpus. The major limitation is that you can’t output result-data at random locations, and you can’t have read+write arrays. But you can compute skeletal-animation, make your own code to compute shading, calculate physics, process+draw strings, do AI, … . Some types of algorithms don’t run well on a gpu, others run extremely well.

thanks for help. can anybody tell me a good source to learn GLSL ?

Look at Ilian Dinev’s link, it is a good tutorial for starters though most of the glsl code is deprecated now, you can learn the api.

Ilian’s link is certainly a good one.

It’s also worth picking up a copy of The Orange Book IMO.
You can check out their web site at http://3dshaders.com


I cant buy a book as i dont have credit card as well as 1$ is around 45 Rs so it really proves to be too costly for me. even 20$ would be around 900 Rs.

any FREE e-book?

The GLSL spec isn’t exactly a book, but it does have the virtue of being free, e-free or whatever… :wink:

no no not that. i already have that thing with me. :frowning: i wanted something that should cover the whole language from beginning and in detail so that i dont feel everything becoming an OVER HEAD TRANSMISSION… :wink:

Freak 120% : in french we have a saying that applies to you :slight_smile:
Here is the fully extended version :
“You can’t have the butter, and the money for the butter, and a smile from the milkmaid, and a reputation of being an honnest man”.

Anyway, reading the lighthouse 3D tutorials had helped me a lot, before I bought the orange book :
The link was already posted above, so I repost just in case you missed it.

ZbuffeR i am not looking for butter, milkmaid or reputation or whatever :wink: but i got what u mean :frowning:

never mind i’ll still won’t give up as long as i have intellectual people like u to help me out on every step.

i had already checked out the lighthouse3d link, i was just looking
for something more but never mind…

oh yes!mmmmmm…

do i need to know c++ to learn GLSL?

No, GLSL syntax is very similar to C one. However, about the opengl API, you can use the implementation of your choice: C, java, python, Lisp, …

lighthouse3d link did worked out.

i also found ozone3d.net cool website.

thanks everybody for help i am at least learning glsl slowly-slowly.

Try these tutorials. Now they are a vit outdated, because they relies on first GLS version, but they are usable and you can understand the whole thing using them.


thanks Ffelagund ill try these out!

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.