diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-10-05 21:28:51 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-10-05 21:29:12 +0300 |
commit | 6306d747b770685f38f95bc57f8681335ddfa506 (patch) | |
tree | 71a54752a9400149535d7a3a95652fe9e1a86c0c /source/blender/draw/engines | |
parent | 74ff0aeea0180dfd89b98f15dacf0dd0c8fa8dfd (diff) |
DRW: Split ViewProjectionMatrix in order to increase precision
This also removes the need to compute the persmat and saves some memory
from the `ViewInfos` struct. This is needed to allow multiview support.
Initial testing found no major performance regression during vertex
heavy workload.
Test file: {F13610017}
Results:
| Platform | Master | Split Matrix|
| Linux + Mesa + AMD W6600 | 48 fps | 47 fps |
| Macbook Pro M1 | 50 fps | 51 fps |
| Linux + NVidia 1080Ti | 51 fps | 52 fps |
| Linux + Radeon Vega 64 | 25.6 fps | 26.7 fps |
Increased precision when far from origin:
{F13610024}
{F13610025}
Reviewed By: jbakker
Differential Revision: https://developer.blender.org/D16125
Diffstat (limited to 'source/blender/draw/engines')
20 files changed, 28 insertions, 25 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_vert.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_vert.glsl index c9af2753baa..1c32a5975be 100644 --- a/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_vert.glsl @@ -39,6 +39,6 @@ void main() vec3 screen_pos = screen_vecs[0] * quadCoord.x + screen_vecs[1] * quadCoord.y; ws_location += screen_pos * sphere_size; - gl_Position = ViewProjectionMatrix * vec4(ws_location, 1.0); + gl_Position = ProjectionMatrix * (ViewMatrix * vec4(ws_location, 1.0)); gl_Position.z += 0.0001; /* Small bias to let the icon draw without zfighting */ } diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl index 6fefe1319bd..c296d901880 100644 --- a/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl @@ -42,6 +42,6 @@ void main() vec3 screen_pos = screen_vecs[0] * quadCoord.x + screen_vecs[1] * quadCoord.y; ws_cell_location += screen_pos * sphere_size; - gl_Position = ViewProjectionMatrix * vec4(ws_cell_location, 1.0); + gl_Position = ProjectionMatrix * (ViewMatrix * vec4(ws_cell_location, 1.0)); gl_Position.z += 0.0001; /* Small bias to let the icon draw without zfighting */ } diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl index e1035af37be..6c1a95bba49 100644 --- a/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl @@ -203,7 +203,7 @@ vec3 probe_evaluate_planar(int id, PlanarData pd, vec3 P, vec3 N, vec3 V, float vec3 ref_pos = point_on_plane + proj_ref; /* Reproject to find texture coords. */ - vec4 refco = ViewProjectionMatrix * vec4(ref_pos, 1.0); + vec4 refco = ProjectionMatrix * (ViewMatrix * vec4(ref_pos, 1.0)); refco.xy /= refco.w; /* TODO: If we support non-ssr planar reflection, we should blur them with gaussian diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl index 0a53abcb04a..fff3209bb8a 100644 --- a/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl @@ -10,7 +10,7 @@ out vec4 FragColor; void main() { - vec4 refco = ViewProjectionMatrix * vec4(worldPosition, 1.0); + vec4 refco = ProjectionMatrix * (ViewMatrix * vec4(worldPosition, 1.0)); refco.xy /= refco.w; FragColor = vec4( textureLod(probePlanars, vec3(refco.xy * vec2(-0.5, 0.5) + 0.5, float(probeIdx)), 0.0).rgb, diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_vert.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_vert.glsl index 6759c060259..9c79fd4c939 100644 --- a/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_vert.glsl @@ -12,6 +12,6 @@ flat out int probeIdx; void main() { worldPosition = (probe_mat * vec4(-pos.x, pos.y, 0.0, 1.0)).xyz; - gl_Position = ViewProjectionMatrix * vec4(worldPosition, 1.0); + gl_Position = ProjectionMatrix * (ViewMatrix * vec4(worldPosition, 1.0)); probeIdx = probe_id; } diff --git a/source/blender/draw/engines/eevee/shaders/object_motion_vert.glsl b/source/blender/draw/engines/eevee/shaders/object_motion_vert.glsl index ef96bcbaedb..9dab04006a8 100644 --- a/source/blender/draw/engines/eevee/shaders/object_motion_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/object_motion_vert.glsl @@ -52,8 +52,8 @@ void main() /* Use jittered projmatrix to be able to match exact sample depth (depth equal test). * Note that currModelMatrix needs to also be equal to ModelMatrix for the samples to match. */ #ifndef HAIR - gl_Position = ViewProjectionMatrix * vec4(currWorldPos, 1.0); + gl_Position = ProjectionMatrix * (ViewMatrix * vec4(currWorldPos, 1.0)); #else - gl_Position = ViewProjectionMatrix * vec4(wpos, 1.0); + gl_Position = ProjectionMatrix * (ViewMatrix * vec4(wpos, 1.0)); #endif } diff --git a/source/blender/draw/engines/eevee/shaders/surface_lib.glsl b/source/blender/draw/engines/eevee/shaders/surface_lib.glsl index 69762027643..ac7519195c0 100644 --- a/source/blender/draw/engines/eevee/shaders/surface_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/surface_lib.glsl @@ -181,7 +181,7 @@ vec3 coordinate_screen(vec3 P) window.xy = window.xy * CameraTexCoFactors.xy + CameraTexCoFactors.zw; #else /* MESH */ - window.xy = project_point(ViewProjectionMatrix, P).xy * 0.5 + 0.5; + window.xy = project_point(ProjectionMatrix, transform_point(ViewMatrix, P)).xy * 0.5 + 0.5; window.xy = window.xy * CameraTexCoFactors.xy + CameraTexCoFactors.zw; #endif return window; diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl index 9ed21fc0bf5..eebcf56de28 100644 --- a/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl @@ -52,7 +52,7 @@ vec3 coordinate_camera(vec3 P) vec3 coordinate_screen(vec3 P) { vec3 window = vec3(0.0); - window.xy = project_point(ViewProjectionMatrix, P).xy * 0.5 + 0.5; + window.xy = project_point(ProjectionMatrix, transform_point(ViewMatrix, P)).xy * 0.5 + 0.5; window.xy = window.xy * CameraTexCoFactors.xy + CameraTexCoFactors.zw; return window; } diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl index 777e48fde34..07b817d1713 100644 --- a/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl @@ -117,7 +117,7 @@ vec3 light_volume_light_vector(LightData ld, vec3 P) vec3 participating_media_extinction(vec3 wpos, sampler3D volume_extinction) { /* Waiting for proper volume shadowmaps and out of frustum shadow map. */ - vec3 ndc = project_point(ViewProjectionMatrix, wpos); + vec3 ndc = project_point(ProjectionMatrix, transform_point(ViewMatrix, wpos)); vec3 volume_co = ndc_to_volume(ndc * 0.5 + 0.5); /* Let the texture be clamped to edge. This reduce visual glitches. */ @@ -147,12 +147,15 @@ vec3 light_volume_shadow(LightData ld, vec3 ray_wpos, vec4 l_vector, sampler3D v if (ld.l_type == SUN) { /* For sun light we scan the whole frustum. So we need to get the correct endpoints. */ - vec3 ndcP = project_point(ViewProjectionMatrix, ray_wpos); - vec3 ndcL = project_point(ViewProjectionMatrix, ray_wpos + l_vector.xyz) - ndcP; + vec3 ndcP = project_point(ProjectionMatrix, transform_point(ViewMatrix, ray_wpos)); + vec3 ndcL = project_point(ProjectionMatrix, + transform_point(ViewMatrix, ray_wpos + l_vector.xyz)) - + ndcP; vec3 frustum_isect = ndcP + ndcL * line_unit_box_intersect_dist_safe(ndcP, ndcL); - L = project_point(ViewProjectionMatrixInverse, frustum_isect) - ray_wpos; + vec4 L_hom = ViewMatrixInverse * (ProjectionMatrixInverse * vec4(frustum_isect, 1.0)); + L = (L_hom.xyz / L_hom.w) - ray_wpos; L /= volShadowSteps; dd = length(L); } diff --git a/source/blender/draw/engines/eevee/shaders/world_vert.glsl b/source/blender/draw/engines/eevee/shaders/world_vert.glsl index 29892a7ffb4..837dca4ad08 100644 --- a/source/blender/draw/engines/eevee/shaders/world_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/world_vert.glsl @@ -17,7 +17,7 @@ void main() gl_Position = vec4(pos, 1.0, 1.0); viewPosition = project_point(ProjectionMatrixInverse, vec3(pos, 0.0)); - worldPosition = project_point(ViewProjectionMatrixInverse, vec3(pos, 0.0)); + worldPosition = transform_point(ViewMatrixInverse, viewPosition); /* Not usable. */ viewNormal = vec3(0.0); worldNormal = vec3(0.0); diff --git a/source/blender/draw/engines/eevee_next/shaders/eevee_nodetree_lib.glsl b/source/blender/draw/engines/eevee_next/shaders/eevee_nodetree_lib.glsl index dd047709afd..9422cb726b7 100644 --- a/source/blender/draw/engines/eevee_next/shaders/eevee_nodetree_lib.glsl +++ b/source/blender/draw/engines/eevee_next/shaders/eevee_nodetree_lib.glsl @@ -344,7 +344,7 @@ vec3 coordinate_screen(vec3 P) } else { /* TODO(fclem): Actual camera transform. */ - window.xy = project_point(ViewProjectionMatrix, P).xy * 0.5 + 0.5; + window.xy = project_point(ProjectionMatrix, transform_point(ViewMatrix, P)).xy * 0.5 + 0.5; window.xy = window.xy * CameraTexCoFactors.xy + CameraTexCoFactors.zw; } return window; diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_depth_merge_vert.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_depth_merge_vert.glsl index 2fca8b69183..07e14fd7bef 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_depth_merge_vert.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_depth_merge_vert.glsl @@ -5,5 +5,5 @@ void main() int v = gl_VertexID % 3; float x = -1.0 + float((v & 1) << 2); float y = -1.0 + float((v & 2) << 1); - gl_Position = drw_view.persmat * (model_matrix * vec4(x, y, 0.0, 1.0)); + gl_Position = drw_view.winmat * (drw_view.viewmat * (model_matrix * vec4(x, y, 0.0, 1.0))); } diff --git a/source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_solid_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_solid_vert.glsl index 4d21ffd96b5..17aed643224 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_solid_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_solid_vert.glsl @@ -38,5 +38,5 @@ void main() view_clipping_distances(sp); vec4 pos_4d = vec4(sp, 1.0); - gl_Position = drw_view.persmat * pos_4d; + gl_Position = drw_view.winmat * (drw_view.viewmat * pos_4d); } diff --git a/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_solid_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_solid_vert.glsl index 68f7e75673f..2b5605c85d3 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_solid_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_solid_vert.glsl @@ -25,7 +25,7 @@ void main() finalColor.a = 1.0; vec4 world_pos = model_mat * vec4(pos, 1.0); - gl_Position = drw_view.persmat * world_pos; + gl_Position = drw_view.winmat * (drw_view.viewmat * world_pos); view_clipping_distances(world_pos.xyz); } diff --git a/source/blender/draw/engines/overlay/shaders/overlay_edit_mesh_skin_root_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_edit_mesh_skin_root_vert.glsl index 76a944c6987..caca123a0c2 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_edit_mesh_skin_root_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_edit_mesh_skin_root_vert.glsl @@ -9,7 +9,7 @@ void main() vec3 up = normalize(imat * screenVecs[1].xyz); vec3 screen_pos = (right * pos.x + up * pos.z) * size; vec4 pos_4d = ModelMatrix * vec4(local_pos + screen_pos, 1.0); - gl_Position = drw_view.persmat * pos_4d; + gl_Position = drw_view.winmat * (drw_view.viewmat * pos_4d); /* Manual stipple: one segment out of 2 is transparent. */ finalColor = ((gl_VertexID & 1) == 0) ? colorSkinRoot : vec4(0.0); diff --git a/source/blender/draw/engines/overlay/shaders/overlay_grid_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_grid_vert.glsl index b43b1eb4a52..6a027f94f49 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_grid_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_grid_vert.glsl @@ -39,5 +39,5 @@ void main() local_pos.z = clamp(local_pos.z, -1.0, 0.0); } - gl_Position = drw_view.persmat * vec4(real_pos, 1.0); + gl_Position = drw_view.winmat * (drw_view.viewmat * vec4(real_pos, 1.0)); } diff --git a/source/blender/draw/engines/overlay/shaders/overlay_motion_path_line_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_motion_path_line_vert.glsl index e6281f75b8f..50c24de0838 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_motion_path_line_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_motion_path_line_vert.glsl @@ -18,7 +18,7 @@ vec2 proj(vec4 pos) void main() { - gl_Position = drw_view.persmat * vec4(pos, 1.0); + gl_Position = drw_view.winmat * (drw_view.viewmat * vec4(pos, 1.0)); interp.ss_pos = proj(gl_Position); diff --git a/source/blender/draw/engines/overlay/shaders/overlay_motion_path_line_vert_no_geom.glsl b/source/blender/draw/engines/overlay/shaders/overlay_motion_path_line_vert_no_geom.glsl index 89878a63c4b..c83e7f095a7 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_motion_path_line_vert_no_geom.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_motion_path_line_vert_no_geom.glsl @@ -108,8 +108,8 @@ void main() vec3 in_pos0 = vertex_fetch_attribute(base_vertex_id, pos, vec3); vec3 in_pos1 = vertex_fetch_attribute(base_vertex_id + 1, pos, vec3); - vec4 out_pos0 = ViewProjectionMatrix * vec4(in_pos0, 1.0); - vec4 out_pos1 = ViewProjectionMatrix * vec4(in_pos1, 1.0); + vec4 out_pos0 = ProjectionMatrix * (ViewMatrix * vec4(in_pos0, 1.0)); + vec4 out_pos1 = ProjectionMatrix * (ViewMatrix * vec4(in_pos1, 1.0)); /* Final calculations required for Geometry Shader alternative. * We need to calculate values for each vertex position to correctly determine the final output diff --git a/source/blender/draw/engines/overlay/shaders/overlay_motion_path_point_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_motion_path_point_vert.glsl index 70892954cd8..7305d00c052 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_motion_path_point_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_motion_path_point_vert.glsl @@ -9,7 +9,7 @@ void main() { - gl_Position = drw_view.persmat * vec4(pos, 1.0); + gl_Position = drw_view.winmat * (drw_view.viewmat * vec4(pos, 1.0)); gl_PointSize = float(pointSize + 2); int frame = gl_VertexID + cacheStart; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_gpencil_frag.glsl b/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_gpencil_frag.glsl index 92be9ec3bcb..a575d42231e 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_gpencil_frag.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_gpencil_frag.glsl @@ -25,7 +25,7 @@ void main() bool is_persp = drw_view.winmat[3][3] == 0.0; vec2 uvs = vec2(gl_FragCoord.xy) * drw_view.viewport_size_inverse; vec3 pos_ndc = vec3(uvs, gl_FragCoord.z) * 2.0 - 1.0; - vec4 pos_world = drw_view.persinv * vec4(pos_ndc, 1.0); + vec4 pos_world = drw_view.viewinv * (drw_view.wininv * vec4(pos_ndc, 1.0)); vec3 pos = pos_world.xyz / pos_world.w; vec3 ray_ori = pos; |