Cycles - Bump Mapping - Bump Mapping has weird line based of Camera clipping #49750

Closed
opened 2016-10-17 05:30:47 +02:00 by Carlo Andreacchio · 17 comments

System Information
Windows 7 x64 GTX 580

Blender Version
Broken: 2a6ec00

Short description of error
Bump mapping has weird line based off camera clipping

Exact steps for others to reproduce the error

  1. Open attached blend file
  2. Shift z
  3. notice weird black line through the plane
  4. change cameras clip start to 1.9km
  5. notice how the line moves

It also doesn't matter if you are using a noise or an image texture.

Present in CPU mode, GPU mode, Supported, Experimental, Path Tracing and Branched-Path Tracing, Dynamic and Static BVH

bug.blend

**System Information** Windows 7 x64 GTX 580 **Blender Version** Broken: 2a6ec00 **Short description of error** Bump mapping has weird line based off camera clipping **Exact steps for others to reproduce the error** 1. Open attached blend file 2. Shift z 3. notice weird black line through the plane 4. change cameras clip start to 1.9km 5. notice how the line moves It also doesn't matter if you are using a noise or an image texture. Present in CPU mode, GPU mode, Supported, Experimental, Path Tracing and Branched-Path Tracing, Dynamic and Static BVH [bug.blend](https://archive.blender.org/developer/F379660/bug.blend)

Changed status to: 'Open'

Changed status to: 'Open'

Added subscriber: @candreacchio

Added subscriber: @candreacchio

Added subscribers: @dfelinto, @Sergey

Added subscribers: @dfelinto, @Sergey
Dalai Felinto was assigned by Sergey Sharybin 2016-10-17 11:55:12 +02:00

Can confirm the issue.

Caused by de7a8af. Doing something liek this solves the problem:

P416: Patch for #49750

diff --git a/intern/cycles/kernel/kernel_camera.h b/intern/cycles/kernel/kernel_camera.h
index ed9726e..d4ed649 100644
--- a/intern/cycles/kernel/kernel_camera.h
+++ b/intern/cycles/kernel/kernel_camera.h
@@ -123,14 +123,12 @@ ccl_device void camera_sample_perspective(KernelGlobals *kg, float raster_x, flo
 	tD = tD_diff + float4_to_float3(kernel_data.cam.dx);
 	Pcamera = spherical_stereo_position(kg, tD, tP);
 	ray->dD.dx = spherical_stereo_direction(kg, tD, tP, Pcamera) - Ddiff;
-	ray->dP.dx = Pcamera - Pdiff;
 
 	tP = transform_perspective(&rastertocamera,
 	                           make_float3(raster_x, raster_y + 1.0f, 0.0f));
 	tD = tD_diff + float4_to_float3(kernel_data.cam.dy);
 	Pcamera = spherical_stereo_position(kg, tD, tP);
 	ray->dD.dy = spherical_stereo_direction(kg, tD, tP, Pcamera) - Ddiff;
-	/* dP.dy is zero, since the omnidirectional panorama only shift the eyes horizontally */
 #endif
 
 #ifdef __CAMERA_CLIPPING__

@dfelinto, same issue happens with spherical stereo, so not sure we need to calculate dP here at all?

Can confirm the issue. Caused by de7a8af. Doing something liek this solves the problem: [P416: Patch for #49750](https://archive.blender.org/developer/P416.txt) ``` diff --git a/intern/cycles/kernel/kernel_camera.h b/intern/cycles/kernel/kernel_camera.h index ed9726e..d4ed649 100644 --- a/intern/cycles/kernel/kernel_camera.h +++ b/intern/cycles/kernel/kernel_camera.h @@ -123,14 +123,12 @@ ccl_device void camera_sample_perspective(KernelGlobals *kg, float raster_x, flo tD = tD_diff + float4_to_float3(kernel_data.cam.dx); Pcamera = spherical_stereo_position(kg, tD, tP); ray->dD.dx = spherical_stereo_direction(kg, tD, tP, Pcamera) - Ddiff; - ray->dP.dx = Pcamera - Pdiff; tP = transform_perspective(&rastertocamera, make_float3(raster_x, raster_y + 1.0f, 0.0f)); tD = tD_diff + float4_to_float3(kernel_data.cam.dy); Pcamera = spherical_stereo_position(kg, tD, tP); ray->dD.dy = spherical_stereo_direction(kg, tD, tP, Pcamera) - Ddiff; - /* dP.dy is zero, since the omnidirectional panorama only shift the eyes horizontally */ #endif #ifdef __CAMERA_CLIPPING__ ``` @dfelinto, same issue happens with spherical stereo, so not sure we need to calculate dP here at all?

Will this bug be fixed for 2.78a?

Will this bug be fixed for 2.78a?

@candreacchio, undefined yet. Might not be enough time to check on all usecases to verify the fix.

@candreacchio, undefined yet. Might not be enough time to check on all usecases to verify the fix.

Added subscribers: @sebastian_k, @brecht

Added subscribers: @sebastian_k, @brecht

@Sergey honestly, a lot of this differential changes were from @brecht since I still don't fully understand them.

By the way, I think, even with your change we would also need the following (which on its own doesn't solve this reported issue):

P419: Masterwork From Distant Lands

diff --git a/intern/cycles/kernel/kernel_camera.h b/intern/cycles/kernel/kernel_camera.h
index ed9726e..1a524d3 100644
--- a/intern/cycles/kernel/kernel_camera.h
+++ b/intern/cycles/kernel/kernel_camera.h
@@ -113,23 +113,24 @@ ccl_device void camera_sample_perspective(KernelGlobals *kg, float raster_x, flo
 #ifdef __RAY_DIFFERENTIALS__
 	/* ray differential */
 	ray->dP = differential3_zero();
+	float3 tPcamera = Pcamera;
 
-	float3 tD_diff = transform_direction(&cameratoworld, Pcamera);
-	float3 Pdiff = spherical_stereo_position(kg, tD_diff, Pcamera);
-	float3 Ddiff = spherical_stereo_direction(kg, tD_diff, Pcamera, Pdiff);
+	float3 tD_diff = transform_direction(&cameratoworld, tPcamera);
+	float3 Pdiff = spherical_stereo_position(kg, tD_diff, tPcamera);
+	float3 Ddiff = spherical_stereo_direction(kg, tD_diff, tPcamera, Pdiff);
 
 	tP = transform_perspective(&rastertocamera,
 	                           make_float3(raster_x + 1.0f, raster_y, 0.0f));
 	tD = tD_diff + float4_to_float3(kernel_data.cam.dx);
-	Pcamera = spherical_stereo_position(kg, tD, tP);
-	ray->dD.dx = spherical_stereo_direction(kg, tD, tP, Pcamera) - Ddiff;
-	ray->dP.dx = Pcamera - Pdiff;
+	tPcamera = spherical_stereo_position(kg, tD, tP);
+	ray->dD.dx = spherical_stereo_direction(kg, tD, tP, tPcamera) - Ddiff;
+	ray->dP.dx = tPcamera - Pdiff;
 
 	tP = transform_perspective(&rastertocamera,
 	                           make_float3(raster_x, raster_y + 1.0f, 0.0f));
 	tD = tD_diff + float4_to_float3(kernel_data.cam.dy);
-	Pcamera = spherical_stereo_position(kg, tD, tP);
-	ray->dD.dy = spherical_stereo_direction(kg, tD, tP, Pcamera) - Ddiff;
+	tPcamera = spherical_stereo_position(kg, tD, tP);
+	ray->dD.dy = spherical_stereo_direction(kg, tD, tP, tPcamera) - Ddiff;
 	/* dP.dy is zero, since the omnidirectional panorama only shift the eyes horizontally */
 #endif
 

@sebastian_k do you have the time to test Sergey's patch? You were the one reporting bump map + spherical stereo bugs in the first place.

@Sergey honestly, a lot of this differential changes were from @brecht since I still don't fully understand them. By the way, I think, even with your change we would also need the following (which on its own doesn't solve this reported issue): [P419: Masterwork From Distant Lands](https://archive.blender.org/developer/P419.txt) ``` diff --git a/intern/cycles/kernel/kernel_camera.h b/intern/cycles/kernel/kernel_camera.h index ed9726e..1a524d3 100644 --- a/intern/cycles/kernel/kernel_camera.h +++ b/intern/cycles/kernel/kernel_camera.h @@ -113,23 +113,24 @@ ccl_device void camera_sample_perspective(KernelGlobals *kg, float raster_x, flo #ifdef __RAY_DIFFERENTIALS__ /* ray differential */ ray->dP = differential3_zero(); + float3 tPcamera = Pcamera; - float3 tD_diff = transform_direction(&cameratoworld, Pcamera); - float3 Pdiff = spherical_stereo_position(kg, tD_diff, Pcamera); - float3 Ddiff = spherical_stereo_direction(kg, tD_diff, Pcamera, Pdiff); + float3 tD_diff = transform_direction(&cameratoworld, tPcamera); + float3 Pdiff = spherical_stereo_position(kg, tD_diff, tPcamera); + float3 Ddiff = spherical_stereo_direction(kg, tD_diff, tPcamera, Pdiff); tP = transform_perspective(&rastertocamera, make_float3(raster_x + 1.0f, raster_y, 0.0f)); tD = tD_diff + float4_to_float3(kernel_data.cam.dx); - Pcamera = spherical_stereo_position(kg, tD, tP); - ray->dD.dx = spherical_stereo_direction(kg, tD, tP, Pcamera) - Ddiff; - ray->dP.dx = Pcamera - Pdiff; + tPcamera = spherical_stereo_position(kg, tD, tP); + ray->dD.dx = spherical_stereo_direction(kg, tD, tP, tPcamera) - Ddiff; + ray->dP.dx = tPcamera - Pdiff; tP = transform_perspective(&rastertocamera, make_float3(raster_x, raster_y + 1.0f, 0.0f)); tD = tD_diff + float4_to_float3(kernel_data.cam.dy); - Pcamera = spherical_stereo_position(kg, tD, tP); - ray->dD.dy = spherical_stereo_direction(kg, tD, tP, Pcamera) - Ddiff; + tPcamera = spherical_stereo_position(kg, tD, tP); + ray->dD.dy = spherical_stereo_direction(kg, tD, tP, tPcamera) - Ddiff; /* dP.dy is zero, since the omnidirectional panorama only shift the eyes horizontally */ #endif ``` @sebastian_k do you have the time to test Sergey's patch? You were the one reporting bump map + spherical stereo bugs in the first place.

We should be using the near clipping distance to propagate the differentials to the modified ray origin, which should keep the resulting differentials on the mesh surface the same regardless of the near clipping.

diff --git a/intern/cycles/kernel/kernel_camera.h b/intern/cycles/kernel/kernel_camera.h
index ed9726e..bd71cdb 100644
--- a/intern/cycles/kernel/kernel_camera.h
+++ b/intern/cycles/kernel/kernel_camera.h
@@ -138,6 +138,8 @@ ccl_device void camera_sample_perspective(KernelGlobals *kg, float raster_x, flo
        float3 Pclip = normalize(Pcamera);
        float z_inv = 1.0f / Pclip.z;
        ray->P += kernel_data.cam.nearclip*ray->D * z_inv;
+       ray->dP.dx += kernel_data.cam.nearclip * ray->dD.dx * z_inv;
+       ray->dP.dy += kernel_data.cam.nearclip * ray->dD.dy * z_inv;
        ray->t = kernel_data.cam.cliplength * z_inv;
 #else
        ray->t = FLT_MAX;
@@ -298,6 +300,8 @@ ccl_device_inline void camera_sample_panorama(KernelGlobals *kg,
 #ifdef __CAMERA_CLIPPING__
        /* clipping */
        ray->P += kernel_data.cam.nearclip*ray->D;
+       ray->dP.dx += kernel_data.cam.nearclip * ray->dD.dx;
+       ray->dP.dy += kernel_data.cam.nearclip * ray->dD.dy;
        ray->t = kernel_data.cam.cliplength;
 #else
        ray->t = FLT_MAX;

@dfelinto's fix also seems a step in the right direction since the differential computation should not affect the Pcamera used for clipping.

Spherical stereo can change the ray origin between pixels, so if that's correct then dP should be non-zero. I don't really understand this though, does there exist a diagram that explains the spherical stereo camera model?

Spherical stereo seems to be computed in world space, and there is a fixed (0,0,1) up vector, is that intentional? I would expect the up axis to rotate along with the camera, and the poles for pole merging to change with camera rotation as well.

The differential computation is definitely missing a camera space to world space transformation somewhere. The resulting ray differentials should be in world space and they are not currently.

We should be using the near clipping distance to propagate the differentials to the modified ray origin, which should keep the resulting differentials on the mesh surface the same regardless of the near clipping. ``` diff --git a/intern/cycles/kernel/kernel_camera.h b/intern/cycles/kernel/kernel_camera.h index ed9726e..bd71cdb 100644 --- a/intern/cycles/kernel/kernel_camera.h +++ b/intern/cycles/kernel/kernel_camera.h @@ -138,6 +138,8 @@ ccl_device void camera_sample_perspective(KernelGlobals *kg, float raster_x, flo float3 Pclip = normalize(Pcamera); float z_inv = 1.0f / Pclip.z; ray->P += kernel_data.cam.nearclip*ray->D * z_inv; + ray->dP.dx += kernel_data.cam.nearclip * ray->dD.dx * z_inv; + ray->dP.dy += kernel_data.cam.nearclip * ray->dD.dy * z_inv; ray->t = kernel_data.cam.cliplength * z_inv; #else ray->t = FLT_MAX; @@ -298,6 +300,8 @@ ccl_device_inline void camera_sample_panorama(KernelGlobals *kg, #ifdef __CAMERA_CLIPPING__ /* clipping */ ray->P += kernel_data.cam.nearclip*ray->D; + ray->dP.dx += kernel_data.cam.nearclip * ray->dD.dx; + ray->dP.dy += kernel_data.cam.nearclip * ray->dD.dy; ray->t = kernel_data.cam.cliplength; #else ray->t = FLT_MAX; ``` @dfelinto's fix also seems a step in the right direction since the differential computation should not affect the `Pcamera` used for clipping. Spherical stereo can change the ray origin between pixels, so if that's correct then `dP` should be non-zero. I don't really understand this though, does there exist a diagram that explains the spherical stereo camera model? Spherical stereo seems to be computed in world space, and there is a fixed (0,0,1) up vector, is that intentional? I would expect the up axis to rotate along with the camera, and the poles for pole merging to change with camera rotation as well. The differential computation is definitely missing a camera space to world space transformation somewhere. The resulting ray differentials should be in world space and they are not currently.

does there exist a diagram that explains the spherical stereo camera model?

Here: https:*code.blender.org/2015/03/1451/ or more specifically: http:*paulbourke.net/papers/vsmm2006/vsmm2006.pdf

Spherical stereo seems to be computed in world space, and there is a fixed (0,0,1) up vector, is that intentional?

For perspective cameras, yes. That's to permit the user to render cubemaps with spherical stereo (the camera local UP wouldn't work in this case).

> does there exist a diagram that explains the spherical stereo camera model? Here: https:*code.blender.org/2015/03/1451/ or more specifically: http:*paulbourke.net/papers/vsmm2006/vsmm2006.pdf > Spherical stereo seems to be computed in world space, and there is a fixed (0,0,1) up vector, is that intentional? For perspective cameras, yes. That's to permit the user to render cubemaps with spherical stereo (the camera local UP wouldn't work in this case).

Thanks for the links.

In #49750#400456, @dfelinto wrote:
For perspective cameras, yes. That's to permit the user to render cubemaps with spherical stereo (the camera local UP wouldn't work in this case).

Ok, so then this assumption is wrong, since the offset is not necessarily horizontal in image space.

/* dP.dy is zero, since the omnidirectional panorama only shift the eyes horizontally */
Thanks for the links. > In #49750#400456, @dfelinto wrote: > For perspective cameras, yes. That's to permit the user to render cubemaps with spherical stereo (the camera local UP wouldn't work in this case). Ok, so then this assumption is wrong, since the offset is not necessarily horizontal in image space. ``` /* dP.dy is zero, since the omnidirectional panorama only shift the eyes horizontally */ ```

This issue was referenced by blender/cycles@96e68d7c0c

This issue was referenced by blender/cycles@96e68d7c0c3bd5523cc977c790d05855f88493ce

This issue was referenced by 9d0ac94d52

This issue was referenced by 9d0ac94d52268ff34ce645035d4315d6018d02b9

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

Fix committed. I rewrote the entire thing since it was difficult to understand, hopefully more clear now what it is going on.

Fix committed. I rewrote the entire thing since it was difficult to understand, hopefully more clear now what it is going on.

I saw the meeting notes today and noticed that this fix was not part of the revisions for 2.78a

I would like to propose that it to be included, as it is a bug that now has been fixed.

Thanks to everyone to getting to the source of the issue!

I saw the meeting notes today and noticed that this fix was not part of the revisions for 2.78a I would like to propose that it to be included, as it is a bug that now has been fixed. Thanks to everyone to getting to the source of the issue!

If you have a closer look then you'll see that the list is only covering revisions from 7c53260 to 417847c and can not be covering this bugfix. This list will be revisited tomorrow before we do final AHOY and surely such a regression fix will be included there.

If you have a closer look then you'll see that the list is only covering revisions from 7c53260 to 417847c and can not be covering this bugfix. This list will be revisited tomorrow before we do final AHOY and surely such a regression fix will be included there.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#49750
No description provided.