logarithmic depth

This commit is contained in:
ktyl 2021-08-13 13:43:54 +01:00
parent cdc4aea9d5
commit b312d390da
4 changed files with 19 additions and 10 deletions

View File

@ -1,4 +1,5 @@
const float INF = 17.0;
const float INF = 100.0;
const float PI = 3.14159;
const float E = 2.71828;
const int SAMPLES = 1;
const int BOUNCES = 4;

View File

@ -61,9 +61,11 @@ void main()
pixel.xyz /= SAMPLES;
vec4 d = imageLoad(_g0, ivec2(gl_GlobalInvocationID.xy));
float depth = d.x;
float depth = d.w;
vec3 normal = d.xyz*2.0-1.0; // unpack normal packaged into texture
pixel.xyz = mix(pixel.xyz, vec3(0), depth);
//pixel.xyz = mix(pixel.xyz, normal, 1.0-depth);
pixel.xyz = mix(pixel.xyz, vec3(1.0), depth);
//pixel.a = 1.0;

View File

@ -33,16 +33,22 @@ void main()
Ray ray = createCameraRay(uv);
RayHit hit = trace(ray);
//pixel.xyz = hit.normal;
// TODO: non-linear depth
float n = 1;
// n roughly correlates to steepness of log curve
// TODO: what does this mean in mathematical terms??
float n = 3;
float f = INF;
float z = hit.distance;
float depth;
// linear depth
//depth = z/f;
float depth = (1.0/z-1.0/n)/(1.0/n-1.0/f);
// logarithmic depth
depth = log(z*pow(E,n)/f)/n;
pixel.x = z/f;
// pack normal into texture
pixel.xyz = hit.normal*0.5+0.5;
pixel.w = depth;
imageStore(g0_output, pixelCoords, pixel);
}

View File

@ -8,7 +8,7 @@ void updateCameraUniforms(GLuint shaderProgram, float aspect)
// wobble up dir
vec3 cdir, cright, cup;
vec3 up = {0.1*sin(t),1.0,0.2*cos(t)};
vec3 up = {0.1*sin(t),1.0,0.05*cos(0.5*t)};
glm_vec3_normalize(up);
// camera and target pos