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
67 votes
6 answers
47k 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 ...
user avatar
  • 2,580
37 votes
4 answers
19k 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 ...
user avatar
  • 2,580
24 votes
2 answers
30k 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: ...
user avatar
  • 343
22 votes
1 answer
3k 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 ...
user avatar
  • 323
14 votes
1 answer
1k 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 ...
user avatar
  • 363
13 votes
1 answer
2k 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-...
user avatar
  • 233
13 votes
1 answer
5k 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 ...
user avatar
  • 1,169
12 votes
1 answer
4k 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 ...
user avatar
  • 1,200
11 votes
1 answer
8k 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. ...
user avatar
  • 1,200
9 votes
1 answer
3k 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 ...
user avatar
  • 581
9 votes
1 answer
974 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, ...
user avatar
  • 161
9 votes
2 answers
6k 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 ...
user avatar
9 votes
1 answer
849 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. ...
user avatar
  • 121
8 votes
3 answers
11k views

Dynamic Array in GLSL

Is it possible to have a dynamic array in a GLSL shader? For instance, what if I have something like this in my GLSL Shader: ...
user avatar
  • 399
8 votes
1 answer
11k views

How to use GLSL texelFetch?

I have read the OpenGl documentation of texelFetch, which is: gvec4 texelFetch(gsampler2D sampler, ivec2 P, int lod). I know the first argument "sampler" is just a texture. But I am very confused ...
user avatar
  • 405
8 votes
1 answer
1k 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 ...
user avatar
8 votes
2 answers
1k 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 '...
user avatar
  • 103
8 votes
1 answer
782 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?
user avatar
  • 1,156
7 votes
1 answer
1k 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 ...
user avatar
  • 377
7 votes
2 answers
1k 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 ...
user avatar
  • 1,169
6 votes
3 answers
6k 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 ...
user avatar
  • 909
6 votes
1 answer
5k 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. ...
user avatar
  • 523
6 votes
2 answers
659 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 ...
user avatar
  • 5,882
6 votes
1 answer
733 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 ...
user avatar
  • 161
6 votes
1 answer
2k 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 ...
user avatar
6 votes
1 answer
2k 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 ...
user avatar
6 votes
1 answer
230 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 ...
user avatar
  • 1,169
5 votes
2 answers
534 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 ...
user avatar
  • 204
5 votes
2 answers
182 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 ...
user avatar
5 votes
2 answers
266 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 ...
user avatar
  • 1,169
5 votes
1 answer
486 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 ...
user avatar
  • 2,037
5 votes
1 answer
77 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 ...
user avatar
  • 151
5 votes
1 answer
2k 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. ...
user avatar
  • 165
5 votes
1 answer
377 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 ...
user avatar
  • 153
5 votes
1 answer
2k 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. ...
user avatar
  • 581
5 votes
1 answer
605 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 ...
user avatar
  • 2,037
5 votes
1 answer
109 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 ...
user avatar
5 votes
1 answer
577 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 ...
user avatar
  • 7,341
5 votes
1 answer
2k views

Manually fetching 8 neighboring texels from 3D texture greatly decreases performance

I'm implementing manual interpolation between texels in a 3D texture to be able to discard some of them when needed. Compared to hardware interpolation, this process takes a lot of time. If I simply ...
user avatar
4 votes
2 answers
219 views

Strange behaviour in vertex shader with divisions

This is the vertex shader code: ...
user avatar
  • 617
4 votes
1 answer
587 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 ...
user avatar
  • 1,457
4 votes
1 answer
1k views

GLSL shapes signed distance field implementation explanation?

I'm trying to understand all primitives In this article.After hard work I just learn Sphere and Cube , I wrote description here. I could draw 2D shapes but I have trouble understanding 3D below codes:...
user avatar
4 votes
1 answer
239 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 ...
user avatar
  • 1,365
4 votes
1 answer
324 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 ...
user avatar
  • 171
4 votes
1 answer
413 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 ...
user avatar
4 votes
1 answer
1k 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 ...
user avatar
  • 280
4 votes
2 answers
1k views

Transforming fragment-to-camera to tangent space for parallax occlusion mapping

I'm trying to implement POM using this tutorial. As stated, I need to transform fragment-to-camera to tangent space and then pass it to a function. tangent space is computed using Assimp. Well I ...
user avatar
  • 2,037
4 votes
1 answer
1k 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?
user avatar
  • 171
4 votes
1 answer
745 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 (...
user avatar
  • 2,037
4 votes
1 answer
377 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 ...
user avatar
  • 243

1
2 3 4 5