Skip to content

Instantly share code, notes, and snippets.

View 0beqz's full-sized avatar

0beqz 0beqz

View GitHub Profile
@alaingalvan
alaingalvan / screenspacebentconesao.glsl
Last active December 27, 2023 20:53
GPU Pro 3 sample of bent cones screen space ambient occlusion.
void main()
{
vec3 positionX = backproject(depthTexture(pixelCoordinateI), inverseViewProjectionMatrix);
vec3 normalX = normalTexture(pixelCoordinateI);
// get ONB to transform samples
mat3 orthoNormalBasis = computeONB(normalX);
// select samples for pixel out of pattern
int patternOffset = getPatternOffset(pixelCoordinateI);
float ao = 0.0;
@dmnsgn
dmnsgn / WebGL-WebGPU-frameworks-libraries.md
Last active May 28, 2024 17:41
A collection of WebGL and WebGPU frameworks and libraries

A non-exhaustive list of WebGL and WebGPU frameworks and libraries. It is mostly for learning purposes as some of the libraries listed are wip/outdated/not maintained anymore.

Engines and libraries ⚙️

Name Stars Last Commit Description
three.js ![GitHub

Real depth in OpenGL / GLSL

http://olivers.posterous.com/linear-depth-in-glsl-for-real

So, many places will give you clues how to get linear depth from the OpenGL depth buffer, or visualise it, or other things. This, however, is what I believe to be the definitive answer:

This link http://www.songho.ca/opengl/gl_projectionmatrix.html gives a good run-down of the projection matrix, and the link between eye-space Z (z_e below) and normalised device coordinates (NDC) Z (z_n below). From there, we have

A   = -(zFar + zNear) / (zFar - zNear);

B = -2zFarzNear / (zFar - zNear);