Blender(cycles) fails to render correct values in some pixels. Fails to hit correct triangle. Why? And how to avoid this problem? #54768

Closed
opened 2018-04-23 11:39:52 +02:00 by sasha · 10 comments

I do some rendering in blender(cycles). I render with the help of cycles nodes .exr images, where in each pixel instead of rgba-channels I store xyzObjectIndex-channels. Everything works fine up to several pixels.

Capture1.PNG

For example, on the image above you can see visualization of the object ids. Each pixel has information onto which object it looks now. You can see that blender failed to recognize building in one blue pixel, blender suggested that this part of the building is the sky and has rendered sky there.

As I can see this happens for degenerate triangles, triangles which are almost in parallel to the ray, which is shoot from pixel. It means that blender(cycles) raytracing algorithm fails to detect correct triangle when shooting ray.

Material setup:

wp.PNG

cap.PNG

This nodes help me to render .exr image, where instead of RGB I have XYZ - 3D position of the surface seen by pixel and instead of alpha - Object Index. Rendered image is correct up to a few pixels.

Geometry of the mesh: As far as I know my mesh consists from triangles.

Rendering machine: I use SVM.

Samples: one ray.

How to avoid this problem?

Here is test scene for testing:
testscene.blend

P.S.: Also noticed that function ray_triangle_intersect() in file "\cycles\util\util_math_intersect.h" returns sometimes wrong barycentric coordinates (u + v > 1, which is wrong), hence it renders incorrect 3D position for current pixel. Wrong barycentric coordinates are there due to fact that in line 182 (const float inv_den = 1.0f / den;) happens division by zero.

I do some rendering in blender(cycles). I render with the help of cycles nodes .exr images, where in each pixel instead of rgba-channels I store xyzObjectIndex-channels. Everything works fine up to several pixels. ![Capture1.PNG](https://archive.blender.org/developer/F2954439/Capture1.PNG) For example, on the image above you can see visualization of the object ids. Each pixel has information onto which object it looks now. You can see that blender failed to recognize building in one blue pixel, blender suggested that this part of the building is the sky and has rendered sky there. As I can see this happens for degenerate triangles, triangles which are almost in parallel to the ray, which is shoot from pixel. It means that blender(cycles) raytracing algorithm fails to detect correct triangle when shooting ray. Material setup: ![wp.PNG](https://archive.blender.org/developer/F2954456/wp.PNG) ![cap.PNG](https://archive.blender.org/developer/F2954457/cap.PNG) This nodes help me to render .exr image, where instead of RGB I have XYZ - 3D position of the surface seen by pixel and instead of alpha - Object Index. Rendered image is correct up to a few pixels. Geometry of the mesh: As far as I know my mesh consists from triangles. Rendering machine: I use SVM. Samples: one ray. How to avoid this problem? Here is test scene for testing: [testscene.blend](https://archive.blender.org/developer/F3056321/testscene.blend) P.S.: Also noticed that function ray_triangle_intersect() in file "\cycles\util\util_math_intersect.h" returns sometimes wrong barycentric coordinates (u + v > 1, which is wrong), hence it renders incorrect 3D position for current pixel. Wrong barycentric coordinates are there due to fact that in line 182 (const float inv_den = 1.0f / den;) happens division by zero.
Author

Added subscriber: @shurup4ik

Added subscriber: @shurup4ik
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Thanx for investigating.
Could you please attach a .blend as well so someone can reproduce with your geometry?

Thanx for investigating. Could you please attach a .blend as well so someone can reproduce with your geometry?
Author

In #54768#496256, @lichtwerk wrote:
Thanx for investigating.
Could you please attach a .blend as well so someone can reproduce with your geometry?

I have attached a test scene.

> In #54768#496256, @lichtwerk wrote: > Thanx for investigating. > Could you please attach a .blend as well so someone can reproduce with your geometry? I have attached a test scene.
Member

Not really sure this is the solution to all issues in question (havent checked any code and your first example pic seems unrelated to the example scene?)

BUT: in the provided scene, there is a gap between faces (right where you get black pixels).
If I close this gap (by slightly moving one edge up in Z and merge vertices), those black pixels are gone...

#54768.png

Not sure this is a bug?
If this is unrelated, please provide another example (without gaps in the geometry, where this issue also shows...)

Marking as incomplete for the time being...

Not really sure this is the solution to all issues in question (havent checked any code and your first example pic seems unrelated to the example scene?) BUT: in the provided scene, there is a gap between faces (right where you get black pixels). If I close this gap (by slightly moving one edge up in Z and merge vertices), those black pixels are gone... ![#54768.png](https://archive.blender.org/developer/F3057786/T54768.png) Not sure this is a bug? If this is unrelated, please provide another example (without gaps in the geometry, where this issue also shows...) Marking as incomplete for the time being...
Author

Dear @lichtwerk , thanks for your answer. Yes, you are right in some places I have gaps in the mesh, that's why positions were wrong. But in most cases 3D positions are almost correct, I get deviations from correct positions in ~cm or ~mm range. After careful debugging, I have noticed, this happens due to place in file "blender/intern/cycles/kernel/geom/geom_triangle_intersect.h", line 221:

if(det != 0.0f) {
/* If determinant is zero it means ray lies in the plane of
* the triangle. It is possible in theory due to watertight
* nature of triangle intersection. For such cases we simply
* don't refine intersection hoping it'll go all fine.
/
float rt = dot(edge2, qvec) / det;
P = P + D
rt;
}

Mainly, I am interested in sentence:

For such cases we simply don't refine intersection hoping it'll go all fine.

In my case it doesnt go fine. And I am getting wrong(almost correct) 3D positions with wrong barycentric coordinates.

Noticed that function ray_triangle_intersect() in file "\cycles\util\util_math_intersect.h" returns sometimes wrong barycentric coordinates (u + v > 1, which is wrong), hence it renders incorrect 3D position for current pixel. Wrong barycentric coordinates are there due to fact that in line 182 (const float inv_den = 1.0f / den;) happens division by very small number.

Question:
• It is clear that in function ray_triangle_intersect() you are getting sometimes not really correct values, due to division on very small number, that's why you use function triangle_refine() to shoot ray second time to refine position. But it is not clear why it is not refined completely? Division on very small numbers still is not handled properly.
• How one can get correct barycentric coordinates?

Dear @lichtwerk , thanks for your answer. Yes, you are right in some places I have gaps in the mesh, that's why positions were wrong. But in most cases 3D positions are almost correct, I get deviations from correct positions in ~cm or ~mm range. After careful debugging, I have noticed, this happens due to place in file "blender/intern/cycles/kernel/geom/geom_triangle_intersect.h", line 221: > if(det != 0.0f) { > /* If determinant is zero it means ray lies in the plane of > * the triangle. It is possible in theory due to watertight > * nature of triangle intersection. For such cases we simply > * don't refine intersection hoping it'll go all fine. > */ > float rt = dot(edge2, qvec) / det; > P = P + D*rt; > } Mainly, I am interested in sentence: > For such cases we simply don't refine intersection **hoping** it'll go all fine. In my case it doesnt go fine. And I am getting wrong(almost correct) 3D positions with wrong barycentric coordinates. Noticed that function ray_triangle_intersect() in file "\cycles\util\util_math_intersect.h" returns sometimes wrong barycentric coordinates (u + v > 1, which is wrong), hence it renders incorrect 3D position for current pixel. Wrong barycentric coordinates are there due to fact that in line 182 (const float inv_den = 1.0f / den;) happens division by very small number. Question: • It is clear that in function ray_triangle_intersect() you are getting sometimes not really correct values, due to division on very small number, that's why you use function triangle_refine() to shoot ray second time to refine position. But it is not clear why it is not refined completely? Division on very small numbers still is not handled properly. • How one can get correct barycentric coordinates?
Brecht Van Lommel was assigned by Philipp Oeser 2018-05-02 15:23:17 +02:00
Member

Added subscribers: @Sergey, @brecht

Added subscribers: @Sergey, @brecht
Member

Thanx for investigating. In that case, I'll pass this on to @brecht or @Sergey for judgement.

Thanx for investigating. In that case, I'll pass this on to @brecht or @Sergey for judgement.

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'

We don't guarantee exact accurate ray-triangle intersections, mainly for performance reasons. It's always interesting to investigate how to get more accurate without affecting performance too much, but that's outside the scope of the bug tracker, more like continuous things we can improve in Cycles.

We don't guarantee exact accurate ray-triangle intersections, mainly for performance reasons. It's always interesting to investigate how to get more accurate without affecting performance too much, but that's outside the scope of the bug tracker, more like continuous things we can improve in Cycles.
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
Interest: X11
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
3 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#54768
No description provided.