Getting the true z value from the depth buffer

From http://web.archive.org/web/20130416194336/http://olivers.posterous.com/linear-depth-in-glsl-for-real // == Post-process frag shader =========================================== uniform sampler2D depthBuffTex; uniform float zNear; uniform float zFar; varying vec2 vTexCoord; void main(void) { float z_b = texture2D(depthBuffTex, vTexCoord).x; float z_n = 2.0 * z_b – 1.0; float z_e = 2.0 * zNear * zFar / (zFar + zNear – z_n * (zFar – zNear)); } … Read more

Passing a list of values to fragment shader

There are currently 4 ways to do this: standard 1D textures, buffer textures, uniform buffers, and shader storage buffers. 1D Textures With this method, you use glTex(Sub)Image1D to fill a 1D texture with your data. Since your data is just an array of floats, your image format should be GL_R32F. You then access it in … Read more

Matrix inverse accuracy

for starters see Understanding 4×4 homogenous transform matrices Improving accuracy for cumulative matrices (Normalization) To avoid degeneration of transform matrix select one axis as main. I usually chose Z as it is usually view or forward direction in my apps. Then exploit cross product to recompute/normalize the rest of axises (which should be perpendicular to … Read more

What is the proper way to modify OpenGL vertex buffer?

The size of any OpenGL buffer object is set when you call glBufferData. That is, OpenGL will allocate the amount of memory you specify in the second argument of glBufferData (which isn’t listed in the OP). In fact, if you call, for example glBufferData( GL_ARRAY_BUFFER, bufferSize, NULL, GL_DYNAMIC_DRAW ); OpenGL will create a buffer of … Read more

What does “immediate mode” mean in OpenGL?

One example of “immediate mode” is using glBegin and glEnd with glVertex in between them. Another example of “immediate mode” is to use glDrawArrays with a client vertex array (i.e. not a vertex buffer object). You will usually never want to use immediate mode (except maybe for your first “hello world” program) because it is … Read more

What are the Attribute locations for fixed function pipeline in OpenGL 4.0++ core profile?

Outside of NVIDIA drivers, this does not work (reliably). Compliant drivers will only alias glVertexPointer (…) to attribute slot 0. NV in their infinite wisdom devised a standard non-standard scheme many years ago where they aliased all of the fixed-function pointers to certain attribute locations, but I do not know if new NV drivers support … Read more