logarithmic depth
This commit is contained in:
parent
cdc4aea9d5
commit
b312d390da
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 = (1.0/z-1.0/n)/(1.0/n-1.0/f);
|
||||
float depth;
|
||||
// linear depth
|
||||
//depth = z/f;
|
||||
|
||||
pixel.x = z/f;
|
||||
// logarithmic depth
|
||||
depth = log(z*pow(E,n)/f)/n;
|
||||
|
||||
// pack normal into texture
|
||||
pixel.xyz = hit.normal*0.5+0.5;
|
||||
pixel.w = depth;
|
||||
|
||||
imageStore(g0_output, pixelCoords, pixel);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue