## avoid rejection sampling

Practical and theoretical implementation discussion.
koiava
Posts: 49
Joined: Thu Apr 24, 2014 8:18 am
Location: Tbilisi, Georgia
Contact:

### avoid rejection sampling

Hi guys, I have problem about rejection sampling.
I have surface with perturbed normals(smooth shaded or perturbed with normal map) and I want to evaluate BRDF to get reflected ray.
There is a probability that angle between reflected ray direction and face normal may be greater then π/2.
In this case I'm using rejection sampling to avoid this problem.
I'm generating brdf proportional reflected rays until reflected ray isn't directed as desired. It works correctly but dramatically decreases performance.
Colibri Renderer

sriravic
Posts: 20
Joined: Fri Jun 22, 2012 6:48 pm

### Re: avoid rejection sampling

You can use cosine weighted sampling (pdf proportional to the cos(theta) term) which is where I feel its more important to sample since you're using a normal map to perturb the normals.

koiava
Posts: 49
Joined: Thu Apr 24, 2014 8:18 am
Location: Tbilisi, Georgia
Contact:

### Re: avoid rejection sampling

this is a figure illustrating this problem. If surface is highly specular then probability that reflected ray will fall under the surface is high.
Actually, this is a reason of "shadow terminator" problem... (When Angle between light direction and perturbed surface normal is less then π/2, And angle between light direction and face normal is greater then π/2). One solution for this is to do always flat shading and subdivide surface to make correct smooth shading. Is there any different solutions for this?
Colibri Renderer

Posts: 206
Joined: Fri Dec 02, 2011 8:00 am

### Re: avoid rejection sampling

koiava wrote: Actually, this is a reason of "shadow terminator" problem... (When Angle between light direction and perturbed surface normal is less then π/2, And angle between light direction and face normal is greater then π/2).
Another solution is to use only the geometry normal (i.e. face normal in your figure) for this kind of check and not the shading normal (i.e. perturbed normal). You are going to have less problems: energy conservation, no rays reflected inside the sphere, etc. However there will be still some noticeable shading artifact on the transition between the dark side and the illuminated side.

koiava
Posts: 49
Joined: Thu Apr 24, 2014 8:18 am
Location: Tbilisi, Georgia
Contact:

### Re: avoid rejection sampling

Energy Conservation is another problem here. When I evaluate BRDF, if it always gives me a ray from hemisphere(directed to perturbed normal) minus solid angle(which fall under surface), then a corresponding pdf isn't normalized anymore and correct normalization isn't easy task for complicated BRDFs.
Colibri Renderer

koiava
Posts: 49
Joined: Thu Apr 24, 2014 8:18 am
Location: Tbilisi, Georgia
Contact:

### Re: avoid rejection sampling

according to SolidAngle documentation, Arnold has shadow_terminator_fix option, but this solution doesn't work in some cases.
It works great for convex meshes, but may produce artifacts in concave areas of high curvature. A proper solution in this situation to reduce the shadow terminator artifact is to increase the number of subdivision iterations in the mesh
.
I think that for unbiased physical bases production renderers proper solution is to avoid normal perturbing, replace fake smooth shading with subdivision surfaces, and normal mapping with displacement.
Colibri Renderer

bod
Posts: 1
Joined: Fri Sep 26, 2014 9:53 pm

### Re: avoid rejection sampling

The LEADR paper proposes an non-centred BRDF that only relies on the geometric normal, the offset usually comes from the bump normal, but perhaps the shading normal could also be part of the offset.

http://hal.inria.fr/hal-00858220/en

Sampling theory comes here: http://hal.inria.fr/hal-00996995/en