Questions tagged [glsl]

GLSL is the OpenGL shading language. Use this tag for questions which are specifically about shaders written in this language. For generic shader questions use [shader] instead.

Filter by
Sorted by
Tagged with
38
votes
6answers
23k views

How can I debug GLSL shaders?

When writing non-trivial shaders (just as when writing any other piece of non-trivial code), people make mistakes.[citation needed] However, I can't just debug it like any other code - you can't just ...
29
votes
4answers
10k views

Sharing code between multiple GLSL shaders

I often find myself copy-pasting code between several shaders. This includes both certain computations or data shared between all shaders in a single pipeline, and common computations which all of my ...
21
votes
1answer
2k views

Why does my Perlin Noise look “blocky”?

I tried to implement Perlin Noise by myself using just the theory (following flafla2.github.io/2014/08/09/perlinnoise.html). Unfortunately I was unable to achieve the look of the "original" Perlin ...
12
votes
1answer
565 views

Confused with PBR implementations

I'm discovering the wonderful world of math and I'm hitting a huge wall with PBR and naming so I have a few questions: As far as I understand BRDF describe how a material react to light (incoming ...
11
votes
1answer
979 views

When to disable perspective correct interpolation ( noperspective )

In GLSL, perspective correct interpolation of vertex attributes is the default setting - one can disable it for specific vertex attributes by using the noperspective qualifier. Other than in post-...
11
votes
1answer
2k views

Do I need to rebind uniforms or attributes when changing shader programs?

Rendering the scene usually involves more than one shader program which, in my case, all use the same attributes and share at least some of the uniforms. To have them working properly, I currently ...
11
votes
1answer
3k views

Loop performance in a shader

I am wondering what's the best way to integrate a dynamic loop function in a shader? First, it seems that dynamic arrays are not possible. So, is it better to create a maximum size array and only ...
10
votes
1answer
5k views

Why is accessing textures much slower when calculating the texture coordinate in the fragment shader?

When using textures in GLSL, it is best to calculate the final texture coordinates in the vertex shader and hand them over to the fragment shader using varyings. ...
9
votes
1answer
718 views

WebGL Omnidirectional Shadow Mapping Issue

First of all, I want to say that I've read a lot of post about shadow mapping using depth maps and cubemaps and I understand how they work and also, I have working experience with them using OpenGL, ...
9
votes
1answer
615 views

Trying to implement Microfacet BRDF but my result images are wrong

I am trying to implement microfacet BRDF model. I am reading Sebastien Lagarde's slides. I implemented formulas to my code but i think result image is wrong. Yellow is base color of material. ...
8
votes
1answer
824 views

Shadow Mapping artefacts

I've been playing around with shadow mapping in OpenGL using depth textures. The depth texture is fine and I can map it onto the scene but I have some strange artefacts on the back of the object: My ...
8
votes
2answers
644 views

What is a good approach for handling uniforms in modern OpenGL?

I'm creating a renderer using modern OpenGL (3.1 and up) and now I'm trying to create an efficient but flexible way of handling uniforms. I've been reading up on uniform buffer objects and on what a '...
8
votes
1answer
491 views

Shader uniform performance

I'd like to know if there's any performance impact based on how I struct my shader uniforms. For instance, is passing 4 floats worse than passing a single vec4?
7
votes
1answer
9k views

GLSL. Can someone explain why gl_FragCoord.xy / screenSize is performed and for what reason?

I'm new to shaders and know that you can color pixels with gl_FragColor but sometimes there is this thing: ...
7
votes
1answer
2k views

OpenGL specular shading - Gradient banding issues

I use Phong shading as my lighting model. Nevertheless, the specular shading produces gradients in the light cone: Hopefully you can see the gradient starting from the lower left corner expanding ...
7
votes
2answers
807 views

Eye Parallax Refraction

I am trying to implement the Parallax Refraction effect explained by Jorge Jimenez on this presentation: http://www.iryoku.com/downloads/Next-Generation-Character-Rendering-v6.pptx and I am facing ...
6
votes
1answer
3k views

Double precision in shader

for better accuracy, instead of GLfloat, I bound double data and tried to use the data in shader as follow: (I just tested to draw single triangle.) cpp. ...
6
votes
2answers
269 views

Is there a objective reason for matrix naming conventions?

I'm probably going to screw this up but.... In all the graphics libraries I've seen various matrices are often called something along the lines of ...
6
votes
2answers
307 views

What factors affect which shader language to learn?

I don't know any shader languages. I've heard of GLSL and HLSL, and I'm interested in learning one or both. Are there significant differences between them that would make one or other better in ...
6
votes
1answer
550 views

Flat shading for non-planar polygons

I'm trying to figure out how to properly implement flat shading for meshes containing non-planar polygons (using OpenGL/GLSL). The aim is to obtain something similar to the result Blender gives (all ...
6
votes
1answer
475 views

Ray tracing - partial derivatives for texture lookup

I'm doing some ray tracing on GPU using a fragment shader... How can I calculate texture coordinates partial derivatives with respect to screen coordinates so I could perform filtered texture lookup ...
6
votes
2answers
2k views

How can I convert signed distance field to a mesh?

I can easily make models by Modeling with Distance Functions but I need make mesh from It so I decide to use voxelizing and make triangles for my signed distance field torus like this video.but I ...
5
votes
3answers
2k views

What is the difference between a Sampler and an Image variables in GLSL?

Reading through some code about voxelization I found the following line in the fragment shader ...
5
votes
2answers
173 views

What is the correct way to put different textures on different parts of an object?

I tried passing a variable from the vertex shader to tell the fragment shader whether or not I wanted part of an object textured. That way I could write another shader for the other parts of the ...
5
votes
2answers
243 views

Special directional light type

I am currently trying to implement a specific directional light type. This light type has been used in the game INSIDE and is called orthogonal spotlight (aka local directional light). I assume that ...
5
votes
1answer
213 views

I dont understand how a GPU computes and branches, could you please help me fix this shader preformance

I have been working on how the GPU does parellel processing, and branching. However I am not yet to the point where I know how to make this shader more efficent. Essentially I dont know enough about ...
5
votes
1answer
181 views

Tesselation sine distortion?

I am experimenting on a simple wave tessellation shader. I ported it from a working vertex shader. When my frequency is higher than 1, I get strange "saw-tooth" artifacting at peaks of the wave. Here ...
5
votes
1answer
359 views

Binary scene voxelization using imageStore - problem

This problem has been haunting me for some time but I was busy with other things. I can't finish my GI technique (specifically occlusion step) without solving it. I made a binary scene voxelization ...
5
votes
1answer
765 views

Creating an “ink spread” effect with a glsl fragment shader

I have dealt with glsl before, but I still have problems with my understanding of how to achieve certain kinds of effects with per-pixel processing. What I am looking to do is use a fragment shader to ...
5
votes
1answer
68 views

Why cant I use `#include` after upgrading my driver

After updating my graphics driver and trying to run this example from John Chapman's blog I got this error ...
5
votes
1answer
216 views

How to prevent moire artifacts in this light casting algorithm?

I am writing a 2D light casting algorithm with OpenGL compute shaders. The algorithm is simple: For each light source shoot out light rays from it, the ray begins at the light coordinates, it ends at ...
5
votes
1answer
708 views

What happens to float values written to UNSIGNED_BYTE texture?

This is more a theoretical question. I'm wondering what happens when I write float values into an empty RGBA texture of type gl.UNSIGNED_BYTE in WebGL 1.0. ...
5
votes
1answer
256 views

Can't get output from a GLSL code

I'm trying to learn GLSL, I'm following this tutorial. I've done everything according to the tutorials but I can't get any output from my code. As you see I'm checking for both compile errors and ...
5
votes
1answer
699 views

GLSL - Merge two textures

I would like to display arbitrary 3d meshes with black edges (black outline, black ridges, etc.). Thereby I have created two different textures: One color texture and one anti-aliased edge texture. ...
5
votes
1answer
318 views

mapping 3d texture on view frustum (or part of it)

I'm implementing volumetric fog in my OpenGL renderer. First I inject color into 3D texture using compute shader, atomic operations and shadow map visibility check. The information I use to compute ...
5
votes
1answer
204 views

Shadow map projection issue

I am using Unity but this question might not be proper to this engine. I have projected the shadow map onto this sphere but there are grazing shadows. Is it possible to avoid it or to correct it as I ...
5
votes
1answer
93 views

gamma transform in webGLSL: when already done or yet to be done?

Color spaces issues are such a pain, especially when you create color data at the middle of the chain, and a pile of libs and apps separate this to the display... Here I only worry about gamma ...
5
votes
1answer
444 views

Methods for grid traversal in a glsl pixel shader?

I'm working on a shadertoy "snake" game, using the new multi pass rendering abilities to save game state between frames. I'm using raytracing to render the board (an AABB), and am planning on using ...
4
votes
2answers
1k views

Getting rid of branching to check if a variable is within a range in GLSL

I have this GLSL function that I am trying to optimize because it is going to be ran on many pixels of an older devices GPU. There is no room for branching inefficiency. Essentially this function ...
4
votes
2answers
186 views

Strange behaviour in vertex shader with divisions

This is the vertex shader code: ...
4
votes
1answer
2k views

What are Jittering and Dithering

I've heard a lot about jittering and dithering but I would like to know more about those techniques, especially when used to avoid visible sampling in a fragment shader. What are the differences ...
4
votes
1answer
519 views

Is a branched discard to be avoided

When a simulating a camera, I may run into the situation that a black elliptic border is needed (rather than a rectangular image). In this case I have the option to discard the fragment in the ...
4
votes
2answers
389 views

OpenGL vertex color

Why do I need to specify the same name for color input in fragment shader and output color from vertex shader? ...
4
votes
1answer
224 views

Texture coordinates are not updating according to the vertex divisor specified

I want to draw a string of text with a single draw call (Instancing). I am reading a bitmap for each character texture. I want to pass the texture coordinates for each vertex of a quad (a single ...
4
votes
1answer
1k views

How to convert a thread ID into Screen Space Coord in an OpenGL Compute Shader?

I've written an implementation of the sphere tracing algorithm in OpenGL 4+. As an experiment/toy project, I'm re-implementing it using the OpenGL 4.3 compute shader, but I'm having trouble with the ...
4
votes
1answer
400 views

How to align Ray Marching on top of traditional 3D rasterization?

I'm trying to apply raymarching on top of 3D rasterization, ordering what 3D object gets displayed based on the depth of a rasterization pass and the raymarch depth. After getting the transform ...
4
votes
2answers
472 views

OpenGL: Purpose of transform matrix in Vertex shader where transform*vertex

I'm trying to understand OpenGL by using Processing OpenGL ES. If I have an example Cube to render. I've read that a vertex shader will be run once for each Vertex. The fragment shader will be run (...
4
votes
1answer
177 views

How does GLSL code get “loaded” and “compiled”?

I just wanted to find out for sure how GLSL code gets loaded and compiled. Does the g++ compiler do it?
4
votes
1answer
1k views

Unable to pass custom Matrix4 to GLSL as a uniform

I am fairly new to graphics programming and I am trying to pass a custom Matrix4 (non-glm) to my vertex shader by using a uniform. ...
4
votes
1answer
498 views

Exponential shadow maps sampling with PCF for sampler2DShadow instead of sampler2D

I am trying to make use of free hardware PCF sampling with sampler2DShadow and extend it to more samples. So far I am sampling shadow map (...