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.

The OpenGL shading language is a high-level language that can be used to write shader programs that can execute on a GPU.

262 questions
40
votes
4 answers

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 vertex shaders need (or any other stage). Of…
Martin Ender
  • 2,730
  • 4
  • 23
  • 45
6
votes
3 answers

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 layout (binding = 0, r32f ) coherent uniform writeonly image3D volumeTexture; I have only used samplers in the past and have never seen image3D before. I…
BRabbit27
  • 969
  • 1
  • 10
  • 21
4
votes
1 answer

Operator associativity and 4x4 matrices - performance question

During vertex processing with 4x4 matrices, we might stack multiple transformations like projection, model-world, world-camera, etc. by doing something like this: $$v_{final} = T_N \cdot ... \cdot T_1 \cdot T_0 \cdot v$$ Now from the GLSL specs…
wychmaster
  • 1,251
  • 2
  • 9
  • 27
4
votes
1 answer

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?
user9778
  • 191
  • 3
  • 7
3
votes
2 answers

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 returns a 0 or a 1 based on the variables actualY…
J.Doe
  • 1,445
  • 12
  • 23
3
votes
1 answer

GLSL function parameters

In GLSL: Common Mistakes it states: Functions parameters must be declared with the in, out, or inout qualifiers. but I have never declared function parameters with in, out, or inout qualifiers and I have never run into any problems. Could this be…
Archmede
  • 481
  • 2
  • 7
  • 21
3
votes
2 answers

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 (at least) once for each pixel. In a vertex shader…
user3168961
  • 133
  • 3
2
votes
1 answer

Difference between isnan and comparison to self

In GLSL, what is the difference between isnan(x) and !(x == x)?
Tomas
  • 41
  • 3
2
votes
2 answers

Why does GLSL smoothstep return 0 when all parameters are literal floats?

I was working through https://thebookofshaders.com/05/ when I came across some unintuitive behaviour of smoothstep. I wanted to understand it better so I replaced the following line of code: return smoothstep(0.02, 0.0, abs(st.y - st.x)); With all…
AJP
  • 83
  • 7
2
votes
1 answer

How to work around the pointer limitations of GLSL?

(I am new to Computer Graphics in general) I am learning how to ray trace from a book called ''Peter Shirley - Ray Tracing in One Weekend''. In the book, the code is written in C++. I have intermediate-advanced level understanding of good ol' C, but…
sigsegv
  • 121
  • 1
  • 2
1
vote
1 answer

Detecting edges on really small float-value differences

I'm working on a game that has a big proc. generated map (10000km by 20000km). The map generation is based on multi-octave perlin noise. ... vec2 step = vec2(1.3, 1.7); float n = 0.0; n += color(uv.xy, t); n += 0.5 * color(uv.xy * 2.0 - step, t); n…
wcobalt
  • 111
  • 3
1
vote
1 answer

GLSL Uniform Layout Spec says member array stride alignment is rounded up to vec4?

in GLSL spec section 7.6.2.2 about Standard Uniform Block Layout, rule (4) says: If the member is an array of scalars or vectors, the base alignment and array stride are set to match the base alignment of a single array element, according to rules…
wip
  • 1,851
  • 1
  • 13
  • 26
1
vote
2 answers

GLSL get min/max index of vec3

I have written a function in GLSL that returns the min index (index 0 is the x component, 1 is the y component, and 2 is the z component) of a vec3 variable. uint getMinIndex(vec3 vector) { float minValue = min(min(vector.x, vector.y),…
Thomas
  • 1,245
  • 1
  • 4
  • 16
1
vote
1 answer

Convert image to CIE Lab using GLSL to change hue/chroma

It is possible to convert an image or other output to CIE Lab color model using GLSL? Does it require compute shaders or can be done using only vertex shaders?
vaunnaut
  • 11
  • 2
0
votes
2 answers

What's the type of iChannel[0-3] in Shadertoy?

I'd like to have a helper function in the Common tab that does something fancy with texture input and returns the result. I'd like the function in question to be able to use any iChannel, like: vec3 do_something_fancy( in channelType channel, in…
1
2