Differences between GLSL and GLSL ES 2

Is GLSL ES 2 a totally separate language, or a special version of GLSL? Every version of GLSL is ultimately a “totally separate language;” some aren’t even backwards compatible with previous versions. However, the ES variation of GLSL is even moreso. Think of it as a fork of desktop GLSL. A fork of GLSL from … Read more

What’s the logic for determining a min/max vector in GLSL?

Quoting from the first source that I could find (PDF), at the top of §8.3 Common Functions, page 132: These all operate component-wise. The description is per component. Nearly all the functions that operator on vectors but really only make sense for a scalar operate component-wise. (This includes abs, sign, floor, trunc, round, roundEven, ceil, … Read more

printf in GLSL?

Unfortunately it’s not possible directly. One possible solution though, that I end up using a lot (but I’m sure it’s pretty common among GLSL developers) is to “print” values as colors, in place of your intended final result. Of course this has many limitations; for one, you have to make sure that your value maps … Read more

In OpenGL ES 2.0 / GLSL, where do you need precision specifiers?

You don’t need precision specifiers on constants/literals since those get compile time evaluated to whatever they are being assigned to. In vertex shaders, the following precisions are declared by default: ( 4.5.3 Default Precision Qualifiers) precision highp float; precision highp int; precision lowp sampler2D; precision lowp samplerCube; And in fragment shaders you get: precision mediump … Read more

Explanation of dFdx

To understand how these instructions work, it helps to understand the basic execution architecture of GPUs and how fragment programs map to that architecture. GPUs run a bunch of threads in ‘lock-step’ over the same program, which each thread having its own set of registers. So it fetches an instruction, then executes that instruction N … Read more

What’s the origin of this GLSL rand() one-liner?

Very interesting question! I am trying to figure this out while typing the answer 🙂 First an easy way to play with it: http://www.wolframalpha.com/input/?i=plot%28+mod%28+sin%28x*12.9898+%2B+y*78.233%29+*+43758.5453%2C1%29x%3D0..2%2C+y%3D0..2%29 Then let’s think about what we are trying to do here: For two input coordinates x,y we return a “random number”. Now this is not a random number though. It’s the … Read more

tech