This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/gpu/shaders/gpu_shader_fx_lib.glsl
Antonis Ryakiotakis 590efaacb8 Potential fix for T43987, ambient occlusion different between offscreen
and on screen rendering.

Aaaaah, the beauty of driver implementations of OpenGL!

Turns out the problem here is that drivers calculate df/dy differently
in some cases (probably because OpenGL counts y reverse to how the
window system does, so drivers can get confused).

Fixed this for the ATI case based on info we have so far, there's also
the Intel case which will be handled separately (missing info on Intel's
renderer string etc).

Unfortunately we can't really fix this for the general case so we'll
have to haldle cases as they come in our tracker and by adding silly
string comparisons in our GPU initialization module <sigh>.
2015-03-30 14:14:52 +02:00

40 lines
1.1 KiB
GLSL

/* simple depth reconstruction, see http://www.derschmale.com/2014/01/26/reconstructing-positions-from-the-depth-buffer
* we change the factors from the article to fit the OpennGL model. */
#ifdef PERSP_MATRIX
/* perspective camera code */
vec3 get_view_space_from_depth(in vec2 uvcoords, in vec3 viewvec_origin, in vec3 viewvec_diff, in float depth)
{
float d = 2.0 * depth - 1.0;
float zview = -gl_ProjectionMatrix[3][2] / (d + gl_ProjectionMatrix[2][2]);
return zview * (viewvec_origin + vec3(uvcoords, 0.0) * viewvec_diff);
}
vec4 get_view_space_z_from_depth(in vec4 near, in vec4 range, in vec4 depth)
{
vec4 d = 2.0 * depth - vec4(1.0);
/* return positive value, so sign differs! */
return vec4(gl_ProjectionMatrix[3][2]) / (d + vec4(gl_ProjectionMatrix[2][2]));
}
#else
/* orthographic camera code */
vec3 get_view_space_from_depth(in vec2 uvcoords, in vec3 viewvec_origin, in vec3 viewvec_diff, in float depth)
{
vec3 offset = vec3(uvcoords, depth);
return vec3(viewvec_origin + offset * viewvec_diff);
}
vec4 get_view_space_z_from_depth(in vec4 near, in vec4 range, in vec4 depth)
{
return -(near + depth * range);
}
#endif