Cycles: Experiment with getting rid of ray_offset() function
Needs ReviewPublic

Authored by Sergey Sharybin (sergey) on Apr 1 2015, 7:10 PM.



Major issue with current ray_offset(0 was that it might have pushed
ray far too away in some axis, causing it to go into surface leading
to shading artifacts.

The idea of this change is to simply skip doing preliminary ray push
and check distance to triangle during intersection. This is relatively
cheap operation because there was already a check for sign of the

This change solves such issues as reported in T43835.

Another thing we can do with intersection-time distance check is to
scale minimal distance to intersection by the magnitude of determinant.
Such an additional trick might cause some speed losses, this is to
be investigated still. This partially solves T43865 (it solves the
huge floor plane case, but cornell box scene is still having some

There's no changes in the hair intersection code yet, so it might
give artifacts for until it's properly implemented.

Diff Detail

rB Blender
Build Status
Buildable 874
Build 874: arc lint + arc unit
Sergey Sharybin (sergey) retitled this revision from to Cycles: Experiment with getting rid of ray_offset() function.Apr 1 2015, 7:10 PM
Sergey Sharybin (sergey) updated this object.

Solved darkening in the cornell box scene

Campbell Barton (campbellbarton) added inline comments.
1107–1112 ↗(On Diff #3878)

this looks like its not working with big endian.

Made needed modifications to curve intersection code

Still having some shading artifacts which are most easy to notice with hair BSDF closures.

Forgot some pieces of code in previous update

Updated against latest master

Just updating against latest master with some minor changes

Fixed missing proper ray_tnear in some places of curve intersections.

Unfortunately, there's still some darkening including very simple
scenes, would need to have a closer look to nail down exact circumstances.

Still think doing something like this is kind of beneficial to avoid

Update against latest master

Updated against latest master

Also did some research on shading artifacts.

Seems they only happens on Hair BSDF and the reason for those
artifacts seems to be caused by those BSDFs reflecting rays
by a shallow angle which was not causing self-shadowing in the
past because ray was offsetting, but now it hits internal side
of the surface.

This part needs to be investigated still.

@Brecht Van Lommel (brecht), maybe you can have some extra look here? :)

Update against latest master.

I've also investigated the darkening of hair BSDFs. This is caused by the model
reflecting rays into the medium (aka, act as a transmission instead of
reflection). Here is a simple file


What happens prior to this fix is:

  • Ray hits the sphere.
  • Hair Reflection BSDF gives a direction which points into the sphere.
  • Surface bounce pushes intersection point a bit outside of the sphere, so the new ray hits sphere again in almost the same spot.
  • This time hair BSDF gives proper reflection vector and ray hits the light.

What happens with this patch is:

  • Ray hits the sphere.
  • Hair Reflection BSDF gives a direction which points into the sphere.
  • Since we don't push point outside of a sphere again, the ray transmits into the geometry, which produces darkening.

The file contains script which visualizes light path in before and after this
change (you need to uncomment master and comment branch points in the script,
and run it for each of configurations).

Now, where is the root of the issue? :) It doesn't sound correct that hair BSDF
can give such a direction, and it's only like a co-incident that reflection was
properly happening with an extra bounce. But, is it a problem in the model
itself? Or is it a legitimate situation that for certain incoming rays and
tangent hair strand will not give any of reflection? Or maybe we can just add
some abs() somewhere, but then what is the ground truth render result here?
And why the used model / paper is not even mentioned?..