Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2022-10-06 19:25:29 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-10-07 13:43:09 +0300
commit8f96d0f73285a3f80a711588555650c696e2b726 (patch)
tree9882257ab334878e8c6ba2974a2ae86d7605ec11 /source/blender/draw/intern/shaders
parent03a7f1d7b1103e693a5a3ee95ed5f4bc46b1ca54 (diff)
DRW: Remove view vectors
This is part of the effor to simplify the View struct in order to implement multiview rendering. The viewvecs can easilly be replace by projection matrix operation. Even if slightly more complex, there is no performance impact.
Diffstat (limited to 'source/blender/draw/intern/shaders')
-rw-r--r--source/blender/draw/intern/shaders/common_view_lib.glsl44
1 files changed, 20 insertions, 24 deletions
diff --git a/source/blender/draw/intern/shaders/common_view_lib.glsl b/source/blender/draw/intern/shaders/common_view_lib.glsl
index 2382337e782..a09bccc4f2e 100644
--- a/source/blender/draw/intern/shaders/common_view_lib.glsl
+++ b/source/blender/draw/intern/shaders/common_view_lib.glsl
@@ -17,10 +17,6 @@ layout(std140) uniform viewBlock
mat4 ProjectionMatrixInverse;
vec4 clipPlanes[6];
-
- /* View frustum corners [NDC(-1.0, -1.0, -1.0) & NDC(1.0, 1.0, 1.0)].
- * Fourth components are near and far values. */
- vec4 ViewVecs[2];
};
#endif /* USE_GPU_SHADER_CREATE_INFO */
@@ -34,9 +30,6 @@ layout(std140) uniform viewBlock
#define IS_DEBUG_MOUSE_FRAGMENT (ivec2(gl_FragCoord) == drw_view.mouse_pixel)
#define IS_FIRST_INVOCATION (gl_GlobalInvocationID == uvec3(0))
-#define ViewNear (ViewVecs[0].w)
-#define ViewFar (ViewVecs[1].w)
-
#define cameraForward ViewMatrixInverse[2].xyz
#define cameraPos ViewMatrixInverse[3].xyz
vec3 cameraVec(vec3 P)
@@ -310,24 +303,26 @@ float buffer_depth(bool is_persp, float z, float zf, float zn)
float get_view_z_from_depth(float depth)
{
+ float d = 2.0 * depth - 1.0;
if (ProjectionMatrix[3][3] == 0.0) {
- float d = 2.0 * depth - 1.0;
- return -ProjectionMatrix[3][2] / (d + ProjectionMatrix[2][2]);
+ d = -ProjectionMatrix[3][2] / (d + ProjectionMatrix[2][2]);
}
else {
- return ViewVecs[0].z + depth * ViewVecs[1].z;
+ d = (d - ProjectionMatrix[3][2]) / ProjectionMatrix[2][2];
}
+ return d;
}
float get_depth_from_view_z(float z)
{
+ float d;
if (ProjectionMatrix[3][3] == 0.0) {
- float d = (-ProjectionMatrix[3][2] / z) - ProjectionMatrix[2][2];
- return d * 0.5 + 0.5;
+ d = (-ProjectionMatrix[3][2] / z) - ProjectionMatrix[2][2];
}
else {
- return (z - ViewVecs[0].z) / ViewVecs[1].z;
+ d = ProjectionMatrix[2][2] * z + ProjectionMatrix[3][2];
}
+ return d * 0.5 + 0.5;
}
vec2 get_uvs_from_view(vec3 view)
@@ -338,12 +333,9 @@ vec2 get_uvs_from_view(vec3 view)
vec3 get_view_space_from_depth(vec2 uvcoords, float depth)
{
- if (ProjectionMatrix[3][3] == 0.0) {
- return vec3(ViewVecs[0].xy + uvcoords * ViewVecs[1].xy, 1.0) * get_view_z_from_depth(depth);
- }
- else {
- return ViewVecs[0].xyz + vec3(uvcoords, depth) * ViewVecs[1].xyz;
- }
+ vec3 ndc = vec3(uvcoords, depth) * 2.0 - 1.0;
+ vec4 p = ProjectionMatrixInverse * vec4(ndc, 1.0);
+ return p.xyz / p.w;
}
vec3 get_world_space_from_depth(vec2 uvcoords, float depth)
@@ -351,14 +343,18 @@ vec3 get_world_space_from_depth(vec2 uvcoords, float depth)
return (ViewMatrixInverse * vec4(get_view_space_from_depth(uvcoords, depth), 1.0)).xyz;
}
-vec3 get_view_vector_from_screen_uv(vec2 uv)
+vec3 get_view_vector_from_screen_uv(vec2 uvcoords)
{
if (ProjectionMatrix[3][3] == 0.0) {
- return normalize(vec3(ViewVecs[0].xy + uv * ViewVecs[1].xy, 1.0));
- }
- else {
- return vec3(0.0, 0.0, 1.0);
+ vec2 ndc = vec2(uvcoords * 2.0 - 1.0);
+ /* This is the manual inversion of the ProjectionMatrix. */
+ vec3 vV = vec3((-ndc - ProjectionMatrix[2].xy) /
+ vec2(ProjectionMatrix[0][0], ProjectionMatrix[1][1]),
+ -ProjectionMatrix[2][2] - ProjectionMatrix[3][2]);
+ return normalize(vV);
}
+ /* Orthographic case. */
+ return vec3(0.0, 0.0, 1.0);
}
#endif /* COMMON_VIEW_LIB_GLSL */