How are we doing? Please help us improve Stack Overflow. Take our short survey

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.

Filter by
Sorted by
Tagged with
229 votes
13 answers
175k views

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 ?
220 votes
14 answers
231k views

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 ...
  • 69k
208 votes
5 answers
79k views

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

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 ...
  • 273k
152 votes
5 answers
84k views

What is the correct file extension for GLSL shaders? [closed]

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,...
  • 3,363
114 votes
5 answers
40k views

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); } ...
  • 16.2k
104 votes
2 answers
64k views

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*...
  • 2,003
94 votes
2 answers
38k views

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&...
  • 262k
82 votes
4 answers
44k views

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 ...
81 votes
2 answers
76k views

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 ...
  • 1,830
70 votes
1 answer
26k views

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 ...
  • 5,299
68 votes
5 answers
31k views

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 ...
  • 4,082
66 votes
1 answer
63k views

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?
  • 63k
65 votes
11 answers
41k views

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

During OpenGL initialization, the program is supposed to do something like: <Get Shader Source Code> <Create Shader> <Attach Source Code To Shader> <Compile Shader> Getting ...
  • 4,768
60 votes
5 answers
40k views

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. ...
  • 3,048
60 votes
4 answers
20k views

Proper way to delete GLSL shader?

My code approaches GLSL shader management in the way, that it creates each shader and the associated program and deletes each shader and program. I recently read http://www.opengl.org/wiki/GLSL_Object ...
  • 5,820
60 votes
1 answer
64k views

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 ...
  • 11.2k
60 votes
1 answer
2k views

Interior Mapping shader self shadowing

I'm tinkering with Joost van Dongen's Interior mapping shader and I'm trying to implement self-shadowing. Still I couldn't quite figure out what coordinates shadow casting light vectors need to be in. ...
56 votes
2 answers
22k views

How can I do these image processing tasks using OpenGL ES 2.0 shaders?

How can I perform the following image processing tasks using OpenGL ES 2.0 shaders? Colorspace transform ( RGB/YUV/HSL/Lab ) Swirling of the image Converting to a sketch Converting to an oil ...
  • 118k
55 votes
4 answers
28k views

In OpenGL is there a way to get a list of all uniforms & attribs used by a shader program?

I'd like to get a list of all the uniforms & attribs used by a shader program object. glGetAttribLocation() & glGetUniformLocation() can be used to map a string to a location, but what I ...
  • 7,345
53 votes
2 answers
22k views

Should I calculate matrices on the GPU or on the CPU?

Should I prefer to calculate matrices on the CPU or GPU? Let's say I have the following matrices P * V * M , should I calculate them on the CPU so that I can send the final matrix to the GPU (GLSL) ...
  • 14.9k
52 votes
3 answers
9k views

Why would it be beneficial to have a separate projection matrix, yet combine model and view matrix?

When you are learning 3D programming, you are taught that it's easiest think in terms of 3 transformation matrices: The Model Matrix. This matrix is individual to every single model and it rotates ...
  • 120k
52 votes
3 answers
28k views

What can cause glDrawArrays to generate a GL_INVALID_OPERATION error?

I've been attempting to write a two-pass GPU implementation of the Marching Cubes algorithm, similar to the one detailed in the first chapter of GPU Gems 3, using OpenGL and GLSL. However, the call to ...
49 votes
2 answers
25k views

Why does my OpenGL Phong shader behave like a flat shader?

I've been learning OpenGL for the past couple of weeks and I've run into some trouble implementing a Phong shader. It appears to do no interpolation between vertexes despite my use of the smooth ...
  • 1,107
49 votes
4 answers
53k views

How to calculate Tangent and Binormal?

Talking about bump mapping, specular highlight and these kind of things in OpenGL Shading Language (GLSL) I have: An array of vertices (e.g. {0.2,0.5,0.1, 0.2,0.4,0.5, ...}) An array of normals (e.g....
46 votes
1 answer
13k views

Should I ever use a `vec3` inside of a uniform buffer or shader storage buffer object?

The vec3 type is a very nice type. It only takes up 3 floats, and I have data that only needs 3 floats. And I want to use one in a structure in a UBO and/or SSBO: layout(std140) uniform UBO { vec4 ...
46 votes
6 answers
31k views

Tools for GLSL editing [closed]

I'm looking for some kind of tool to work with GLSL. I want to experiment with shaders in the WebGL application, so what I'm looking for is something like RenderMonkey. As far as I know - RenderMonkey ...
  • 4,839
42 votes
2 answers
48k views

How to get a "Glow" shader effect in OpenGL ES 2.0?

I'm writing a 3D app for iOS. I'm new to OpenGL ES 2.0, so I'm still getting myself around writing basic shaders. I really need to implement a "Glow" effect on some of my models, based on the ...
  • 456
41 votes
6 answers
60k views

How to do ray tracing in modern OpenGL?

So I'm at a point that I should begin lighting my flatly colored models. The test application is a test case for the implementation of only latest methods so I realized that ideally it should be ...
  • 3,514
41 votes
4 answers
34k views

printf in GLSL?

In C, I can debug code like: fprintf(stderr, "blah: %f", some_var); in GLSL ... is there anyway for me to just dump out a value in a Vertex or Fragment shader? I don't care if it's slow; I just want ...
  • 39.6k
41 votes
4 answers
11k views

How can I improve the performance of my custom OpenGL ES 2.0 depth texture generation?

I have an open source iOS application that uses custom OpenGL ES 2.0 shaders to display 3-D representations of molecular structures. It does this by using procedurally generated sphere and cylinder ...
  • 170k
41 votes
3 answers
9k views

GLSL multiple shaderprogram VS uniforms switches

I'm working on a shader manager architecture and I have several questions for more advanced people. My current choice oppose two designs which are: 1. Per material shader program => Create one shader ...
  • 934
38 votes
1 answer
27k views

Passing a variable to an OpenGL GLSL shader

I'm writing an iPhone app which uses GLSL shaders to perform transformations on textures, but one point that I'm having a little hard time with is passing variables to my GLSL shader. I've read that ...
38 votes
2 answers
42k views

How can I pass multiple textures to a single shader?

I am using freeglut, GLEW and DevIL to render a textured teapot using a vertex and fragment shader. This is all working fine in OpenGL 2.0 and GLSL 1.2 on Ubuntu 14.04. Now, I want to apply a bump ...
  • 14.3k
38 votes
3 answers
42k views

What does it mean to normalize a value?

I'm currently studying lighting in OpenGL, which utilizes a function in GLSL called normalize. According to OpenGL docs, it says that it "calculates the normalized product of two vectors". However, ...
38 votes
3 answers
30k views

Vertex shader attribute mapping in GLSL

I'm coding a small rendering engine with GLSL shaders: Each Mesh (well, submesh) has a number of vertex streams (eg. position,normal,texture,tangent,etc) into one big VBO and a MaterialID. Each ...
  • 27.7k
37 votes
13 answers
32k views

WebGL - is there an alternative to embedding shaders in HTML?

The popular way of using GLSL shaders in WebGL seems to be to embed them in the main html file. The vertex and fragments shaders are embedded in tags like: <script id="shader-fs" type="x-shader/x-...
  • 5,107
37 votes
4 answers
17k views

Adding GLSL syntax highlighting to Eclipse [closed]

Is there an Eclipse plugin that adds support for GLSL files? I found something old on Google, but I couldn't get it to work.
36 votes
7 answers
43k views

How do I get the current color of a fragment?

I'm trying to wrap my head around shaders in GLSL, and I've found some useful resources and tutorials, but I keep running into a wall for something that ought to be fundamental and trivial: how does ...
36 votes
3 answers
5k views

Organizing GLSL shaders in OpenGL engine

Which is better ? To have one shader program with a lot of uniforms specifying lights to use, or mappings to do (e.g. I need one mesh to be parallax mapped, and another one parallax/specular mapped)....
36 votes
1 answer
58k views

What does sampler2D store?

I've read a texture example in OpenGL 2.1. The fragment shader looks like this: #version 120 uniform sampler2D texture; varying vec2 texcoord; void main(void) { gl_FragColor = texture2D(texture,...
35 votes
1 answer
22k views

Point Sprites for particle system

Are point sprites the best choice to build a particle system? Are point sprites present in the newer versions of OpenGL and drivers of the latest graphics cards? Or should I do it using vbo and glsl?
34 votes
3 answers
7k views

Why does GL divide `gl_Position` by W for you rather than letting you do it yourself?

Note: I understand the basic math. I understand that the typical perspective function in various math libraries produces a matrix that converts z values from -zNear to -zFar back into -1 to +1 but ...
  • 95.2k
34 votes
1 answer
14k views

What does the term "genType" mean in OpenGL/GLSL?

In GLSL documentation, the term genType is used often as the type of parameters. For example, the function dot is documented as follows: float dot(genType x, genType y); double dot(...
33 votes
2 answers
42k views

From RGB to HSV in OpenGL GLSL

I need to pass from RGB color space to HSV .. I searched in internet and found two different implementations, but those give me different results: A: precision mediump float; vec3 rgb2hsv(float r, ...
  • 779
33 votes
3 answers
29k views

How to Using the #include in glsl support ARB_shading_language_include

I wan't to use the #include macro to include shader files in glsl, and I heard there is a ARB_shading_language_include extension support the #include macro. Is there anyone can give me a code snippet ...
  • 1,918
32 votes
2 answers
11k views

Differences between GLSL and GLSL ES 2

Two questions really... Is GLSL ES 2 a totally separate language, or a special version of GLSL? What are the differences between them, in terms of "standard library" functions, syntax and ...
  • 58.6k
31 votes
3 answers
36k views

What is the precision of highp floats in GLSL ES 2.0 (for iPhone/iPod touch/iPad)?

I have a shader that ideally needs 28 bits of mantissa, though I can use less and degrade performance. How can I determine what the precision of 'highp' is in OpenGL ES? It's probably an FP24, with ...
  • 2,186
30 votes
1 answer
53k views

texture vs texture2D in GLSL

When sampling a 2D texture in GLSL (a uniform sampler2D), the texture function is used and the dimension is inferred from the sampler (2D in this case). This is the modern way of sampling a texture in ...
  • 3,303
30 votes
1 answer
15k views

Uniform versus attributes in GLSL ES

I have some parameters being passed from CPU to GPU that are constant for all fragments but which change on every frame (I'm using GLSL ES 1.1). Should I use uniforms or attributes for such values? ...
  • 5,534
29 votes
6 answers
44k views

What's the best way to draw a fullscreen quad in OpenGL 3.2?

I'm doing ray casting in the fragment shader. I can think of a couple ways to draw a fullscreen quad for this purpose. Either draw a quad in clip space with the projection matrix set to the identity ...
  • 4,221

1
2 3 4 5
155