34
votes
Accepted
How can I debug GLSL shaders?
As far as I know there are no tools that allows you to steps through code in a shader (also, in that case you would have to be able to select just a pixel/vertex you want to "debug", the ...
32
votes
Accepted
GLSL. Can someone explain why gl_FragCoord.xy / screenSize is performed and for what reason?
First, gl_FragCoord.xy are screen space coordinates of current pixel based on viewport size. So if viewport size is width=5, <...
24
votes
Accepted
Why does my Perlin Noise look "blocky"?
The interpolation looks fine. The main problem here is that the hash function you're using isn't very good. If I look at just one octave, and visualize the hash result by outputting ...
23
votes
Accepted
Sharing code between multiple GLSL shaders
There's a bunch of a approaches, but none is perfect.
It's possible to share code by using glAttachShader to combine shaders, but this doesn't make it possible to ...
16
votes
Accepted
Dynamic Array in GLSL
I don't think uniform arrays can be dynamically sized. In your case you should define the array as the maximum number of lights you will process and then use a uniform to control the number of ...
16
votes
Accepted
How to use GLSL texelFetch?
OK, I have figured out this problem.
For the texture coordinates, there are two kind of texture coordinates. One is normalized texture coordinates, which is in the range [0, 1]. The other is texel ...
15
votes
Accepted
When to disable perspective correct interpolation ( noperspective )
Use cases are only limited by your imagination! noperspective means that the attribute is interpolated across the triangle as though the triangle was completely ...
13
votes
Accepted
Double precision in shader
The problem is, glVertexAttribPointer(0, 4, GL_DOUBLE... doesn't do what you think it does.
Using actual double-precision vertex attributes and performing double ...
12
votes
Accepted
Why is accessing textures much slower when calculating the texture coordinate in the fragment shader?
What you're talking about is commonly called "dependent texture reads" in the mobile development community. It's an implementation detail of certain hardware, and therefore it really depends on the ...
12
votes
Accepted
Do I need to rebind uniforms or attributes when changing shader programs?
You don't need to rebind the attributes, so long as you ensure that their location stays the same in both shaders. (Usually using the layout(location = X) syntax in ...
11
votes
Sharing code between multiple GLSL shaders
I generally just use the fact that glShaderSource(...) accepts an array of strings as it's input.
I use a json-based shader definition file, which specifies how a shader (or a program to be more ...
11
votes
How can I debug GLSL shaders?
There is also GLSL-Debugger. It is a debugger used to be known as "GLSL Devil".
The Debugger itself is super handy not only for GLSL code, but for OpenGL itself as well. You have the ability to jump ...
11
votes
Accepted
Shadow Mapping artefacts
This issue looks like standard shadow map acne artifacts. Additionally your's lighting equation is incomplete or wrong. Light shouldn't influence faces with normals facing away from it. This also ...
11
votes
Confused with PBR implementations
DFG pops up in the family of microfacet based BRDFs. It is simply the product of three terms:
D : The microfacet distribution.
F : The fresnel coefficient.
G : The geometric attenuation between ...
10
votes
Accepted
Getting rid of branching to check if a variable is within a range in GLSL
This could be done that way:
First condition is float val = 1.0-step(shouldY, ActualY);
Then, the condition: ...
9
votes
How can I debug GLSL shaders?
There are several offerings by GPU vendors like AMD's CodeXL or NVIDIA's nSight/Linux GFX Debugger which allow stepping through shaders but are tied to the respective vendor's hardware.
Let me note ...
9
votes
Accepted
OpenGL specular shading - Gradient banding issues
This is a common problem with very subtle gradients. The problem is that the image is displayed with 8 bits per component and this is not quite enough precision to make a gradient that is smooth to ...
8
votes
Accepted
What are Jittering and Dithering
Jittering and dithering are both techniques of adding noise to reduce visible artefacts (such as banding) in an image. They solve different kinds of artefacts so they are used in different situations. ...
7
votes
What factors affect which shader language to learn?
The shader language is bound to the APIs/engines that support it (glsl to openGL & WebGL and hlsl to D3D). There are tools to translate from one to the other but they aren't perfect.
This means ...
7
votes
Flat shading for non-planar polygons
Without knowing the internals of Blender, I would say it uses shared normals for the quads, splitting the normals only on edges between the quads, not between the triangles. So your idea of uploading ...
7
votes
Accepted
WebGL Omnidirectional Shadow Mapping Issue
SOLUTION
After a couple of days I realized that I was computing my projection matrix using a FOV angle in degrees and It should be in radians. I made the conversion and now everything works great. ...
7
votes
Accepted
Why does substracting -1 in shader fail for a float data type?
Without seeing the error message I can't be sure but I think it's failing on the 1 being int instead of a float.
float inv_coord = v_coord - 1.0;
There is a ...
7
votes
Is there a objective reason for matrix naming conventions?
I think the naming order is intuitive because it is in reading order (left to right), e.g., worldViewProjection means that your point/direction is first multiplied by the world matrix, then the view ...
7
votes
Accepted
Why do we multiply vertex from left side in vertex shader with matrices?
There is no 100% consensus on what order matrix multiplication should model things, worse the industry is split along this. Some sources use row major and some sources use column major matrices. Great ...
7
votes
Accepted
Is a branched discard to be avoided
You can use a stencil instead, This allows the gpu to do an early out test before the fragment shader even starts.
You only have to build the stencil once (possibly with a discard in a simple shader) ...
6
votes
Accepted
Loop performance in a shader
Shader compilers are extremely aggressive about unrolling since early HW often didn't have flow control and the cost on more recent HW can vary. If you have a benchmark you are actively testing ...
6
votes
Accepted
How to convert a thread ID into Screen Space Coord in an OpenGL Compute Shader?
The problem is actually in your fragment shader:
color_out = texture(source_image, gl_FragCoord.xy);
The texture() function accepts normalized coordinates which ...
6
votes
Creating an "ink spread" effect with a glsl fragment shader
If you want to implement this with GLSL, the general concept that could be applied is multi-pass rendering. In a first render pass, draw some ink on the screen and write the result in a frame buffer ...
6
votes
I dont understand how a GPU computes and branches, could you please help me fix this shader preformance
Rather than trying to speed up your shader by fiddling with the code, can I suggest you make use of the GPU's inherent ability to rapidly fill polygons? This will allow it to eliminate the vast bulk ...
6
votes
What is the difference between a Sampler and an Image variables in GLSL?
Image and Samplers differ in many ways. Unlike Samplers, images can only be addressed with an integer coordinate that ranges from (0,0) to (x,y), where x and y are the width and height of the image. ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
glsl × 210opengl × 118
shader × 59
texture × 18
c++ × 14
hlsl × 14
fragment-shader × 14
webgl × 12
raytracing × 10
rendering × 10
lighting × 10
vulkan × 9
mathematics × 8
compute-shader × 8
uv-mapping × 8
transformations × 5
pbr × 5
performance × 5
raymarching × 5
signed-distance-field × 5
shading × 4
real-time × 4
2d × 4
shadow × 4
shadow-mapping × 4