diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2021-10-14 12:27:30 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2021-10-14 12:49:34 +0300 |
commit | 42d79a6041a7e45efd9eee4613994bdb6090e028 (patch) | |
tree | 229fb792246769f85306ea28cee292cb5b3efbbb /source/blender/draw/engines | |
parent | 583939c54deadbb224f77412c09b58a86e66882c (diff) |
Fix T91398 Overlay: Camera BG jitter offset (regression)
This was caused by camera background being rendered in world space, causing
floating point imprecision issues when camera was far from origin.
Adding a uniform to change vertex shader to process everything in viewspace
to fix the problem.
Diffstat (limited to 'source/blender/draw/engines')
-rw-r--r-- | source/blender/draw/engines/overlay/overlay_image.c | 3 | ||||
-rw-r--r-- | source/blender/draw/engines/overlay/shaders/image_vert.glsl | 11 |
2 files changed, 11 insertions, 3 deletions
diff --git a/source/blender/draw/engines/overlay/overlay_image.c b/source/blender/draw/engines/overlay/overlay_image.c index ada07499d1c..2e9a9bc5c64 100644 --- a/source/blender/draw/engines/overlay/overlay_image.c +++ b/source/blender/draw/engines/overlay/overlay_image.c @@ -344,7 +344,6 @@ void OVERLAY_image_camera_cache_populate(OVERLAY_Data *vedata, Object *ob) if (tex) { image_camera_background_matrix_get(cam, bgpic, draw_ctx, aspect, mat); - mul_m4_m4m4(mat, modelmat, mat); const bool is_foreground = (bgpic->flag & CAM_BGIMG_FLAG_FOREGROUND) != 0; /* Alpha is clamped just below 1.0 to fix background images to interfere with foreground * images. Without this a background image with 1.0 will be rendered on top of a transparent @@ -361,6 +360,7 @@ void OVERLAY_image_camera_cache_populate(OVERLAY_Data *vedata, Object *ob) DRW_shgroup_uniform_texture(grp, "imgTexture", tex); DRW_shgroup_uniform_bool_copy(grp, "imgPremultiplied", use_alpha_premult); DRW_shgroup_uniform_bool_copy(grp, "imgAlphaBlend", true); + DRW_shgroup_uniform_bool_copy(grp, "isCameraBackground", true); DRW_shgroup_uniform_bool_copy(grp, "depthSet", true); DRW_shgroup_uniform_vec4_copy(grp, "color", color_premult_alpha); DRW_shgroup_call_obmat(grp, DRW_cache_quad_get(), mat); @@ -446,6 +446,7 @@ void OVERLAY_image_empty_cache_populate(OVERLAY_Data *vedata, Object *ob) DRW_shgroup_uniform_texture(grp, "imgTexture", tex); DRW_shgroup_uniform_bool_copy(grp, "imgPremultiplied", use_alpha_premult); DRW_shgroup_uniform_bool_copy(grp, "imgAlphaBlend", use_alpha_blend); + DRW_shgroup_uniform_bool_copy(grp, "isCameraBackground", false); DRW_shgroup_uniform_bool_copy(grp, "depthSet", depth_mode != OB_EMPTY_IMAGE_DEPTH_DEFAULT); DRW_shgroup_uniform_vec4_copy(grp, "color", ob->color); DRW_shgroup_call_obmat(grp, DRW_cache_quad_get(), mat); diff --git a/source/blender/draw/engines/overlay/shaders/image_vert.glsl b/source/blender/draw/engines/overlay/shaders/image_vert.glsl index 621e1d8068b..a44ea7081ba 100644 --- a/source/blender/draw/engines/overlay/shaders/image_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/image_vert.glsl @@ -1,5 +1,6 @@ uniform bool depthSet; +uniform bool isCameraBackground; in vec3 pos; @@ -7,8 +8,14 @@ out vec2 uvs; void main() { - vec3 world_pos = point_object_to_world(pos); - gl_Position = point_world_to_ndc(world_pos); + if (isCameraBackground) { + vec3 vP = (ModelMatrix * vec4(pos, 1.0)).xyz; + gl_Position = point_view_to_ndc(vP); + } + else { + vec3 world_pos = point_object_to_world(pos); + gl_Position = point_world_to_ndc(world_pos); + } if (depthSet) { /* Result in a position at 1.0 (far plane). Small epsilon to avoid precision issue. |