Questions tagged [glsl]

The OpenGL Shading Language (GLSL) is the standard programming language for shaders in OpenGL. There are many versions of the language, with each version corresponding to a version of OpenGL. OpenGL ES 2.0 and above have separate versions of GLSL.

The OpenGL Shading Language (GLSL) is the standard programming language for shaders in OpenGL. There are many versions of the language, with each version corresponding to a version of OpenGL. OpenGL ES 2.0 and above have separate versions of GLSL.

Information about GLSL (for desktops) can be found on the OpenGL Wiki

Versions

GLSL

OpenGL Shading Language 1.10 Specification, #version 110, OpenGL 2.0
OpenGL Shading Language 1.20 Specification, #version 120, OpenGL 2.1
OpenGL Shading Language 1.30 Specification, #version 130, OpenGL 3.0
OpenGL Shading Language 1.40 Specification, #version 140, OpenGL 3.1
OpenGL Shading Language 1.50 Specification, #version 150, OpenGL 3.2
OpenGL Shading Language 3.30 Specification, #version 330, OpenGL 3.3
OpenGL Shading Language 4.00 Specification, #version 400, OpenGL 4.0
OpenGL Shading Language 4.10 Specification, #version 410, OpenGL 4.1
OpenGL Shading Language 4.20 Specification, #version 420, OpenGL 4.2
OpenGL Shading Language 4.30 Specification, #version 430, OpenGL 4.3
OpenGL Shading Language 4.40 Specification, #version 440, OpenGL 4.4
OpenGL Shading Language 4.50 Specification, #version 450, OpenGL 4.5
OpenGL Shading Language 4.60 Specification, #version 460, OpenGL 4.6

GLSL ES

OpenGL ES Shading Language 1.00 Specification, #version 100 es, OpenGL ES 1.0
OpenGL ES Shading Language 3.00 Specification, #version 300 es, OpenGL ES 3.0
OpenGL ES Shading Language 3.10 Specification, #version 310 es, OpenGL ES 3.2
OpenGL ES Shading Language 3.20 Specification, #version 320 es, OpenGL ES 3.2

8020 questions
236
votes
13 answers

How to debug a GLSL shader?

I need to debug a GLSL program but I don't know how to output intermediate result. Is it possible to make some debug traces (like with printf) with GLSL without using external software like glslDevil?
Franck Freiburger
  • 26,310
  • 20
  • 70
  • 95
228
votes
14 answers

Random / noise functions for GLSL

As the GPU driver vendors don't usually bother to implement noiseX in GLSL, I'm looking for a "graphics randomization swiss army knife" utility function set, preferably optimised to use within GPU shaders. I prefer GLSL, but code any language will…
Kos
  • 70,399
  • 25
  • 169
  • 233
208
votes
5 answers

What is state-of-the-art for text rendering in OpenGL as of version 4.1?

There are already a number of questions about text rendering in OpenGL, such as: How to do OpenGL live text-rendering for a GUI? But mostly what is discussed is rendering textured quads using the fixed-function pipeline. Surely shaders must make…
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
159
votes
5 answers

What is the correct file extension for GLSL shaders?

I'm learning glsl shading and I've come across different file formats. I've seen people giving their vertex and fragment shaders .vert and .frag extensions. But I've also seen .vsh and .fsh extensions, and even both shaders together in a single…
Samssonart
  • 3,443
  • 3
  • 31
  • 41
117
votes
5 answers

What's the origin of this GLSL rand() one-liner?

I've seen this pseudo-random number generator for use in shaders referred to here and there around the web: float rand(vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } It's variously called "canonical", or "a…
Grumdrig
  • 16,588
  • 14
  • 58
  • 69
109
votes
2 answers

Do conditional statements slow down shaders?

I want to know if "if-statements" inside shaders (vertex / fragment / pixel...) are really slowing down the shader performance. For example: Is it better to use this: vec3 output; output = input*enable + input2*(1-enable); instead of using…
Thomas
  • 2,093
  • 3
  • 21
  • 40
96
votes
2 answers

How does the fragment shader know what variable to use for the color of a pixel?

I see a lot of different fragment shaders, #version 130 out vec4 flatColor; void main(void) { flatColor = vec4(0.0,1.0,0.0,0.5); } And they all use a different variable for the "out color" (in this case flatColor). So how does OpenGL know…
mpen
  • 272,448
  • 266
  • 850
  • 1,236
84
votes
2 answers

Creating a GLSL Arrays of Uniforms?

I would like to leave OpenGL's lights and make my own. I would like my shaders to allow for a variable number of lights. Can we declare an array of uniforms in GLSL shaders? If so, how would we set the values of those uniforms?
Miles
  • 1,858
  • 1
  • 21
  • 34
84
votes
4 answers

Passing a list of values to fragment shader

I want to send a list of values into a fragment shader. It is a possibly large (couple of thousand items long) list of single precision floats. The fragment shader needs random access to this list and I want to refresh the values from the CPU on…
Ville Krumlinde
  • 7,021
  • 1
  • 33
  • 41
71
votes
5 answers

WebGL/GLSL - How does a ShaderToy work?

I've been knocking around Shadertoy - https://www.shadertoy.com/ - recently, in an effort to learn more about OpenGL and GLSL in particular. From what I understand so far, the OpenGL user first has to prepare all the geometry to be used and…
Charlie
  • 4,197
  • 5
  • 42
  • 59
71
votes
1 answer

Explanation of dFdx

I am trying to understand the dFdx() and dFdy() functions in GLSL. I understand the following: The derivative is the rate of change The partial derivative of a function with two parameters is when you differentiate the function while keeping one of…
bwroga
  • 5,379
  • 2
  • 23
  • 25
68
votes
11 answers

How to Practically Ship GLSL Shaders with your C++ Software

During OpenGL initialization, the program is supposed to do something like: Getting source code could be as simple as putting it in a string like: (Example…
Korchkidu
  • 4,908
  • 8
  • 49
  • 69
68
votes
1 answer

How do you access the individual elements of a glsl mat4?

Is it possible to access the individual elements of a glsl mat4 type matrix? How?
bobobobo
  • 64,917
  • 62
  • 258
  • 363
63
votes
1 answer

In OpenGL ES 2.0 / GLSL, where do you need precision specifiers?

Does the variable that you're stuffing values into dictate what precision you're working with, to the right of the equals sign? For example, is there any difference, of meaning, to the precision specifier here: gl_FragColor = lowp vec4(1); Here's…
user652038
63
votes
5 answers

Why transform normals with the transpose of the inverse of the modelview matrix?

I am working on some shaders, and I need to transform normals. I read in few tutorials the way you transform normals is you multiply them with the transpose of the inverse of the modelview matrix. But I can't find explanation of why is that so, and…
user1796942
  • 3,228
  • 5
  • 29
  • 38
1
2 3
99 100