[Bf-cycles] Question about Oren-Nayar diffuse model

Yasuhiro Fujii y-fujii at mimosa-pudica.net
Mon Oct 17 09:16:17 CEST 2011


Hi all,
I am trying to implement Oren-Nayar reflectance model for the cycles renderer.
I have some question about the implementation of O-N model (Sorry for not
cycles specific question).

I optimized the calculation of O-N model like this:

original (from gpu_shader_material.glsl, modified for an explanation):
  nl = max(dot(N, L), 0.0f);
  nv = max(dot(N, E), 0.0f);
  cos_nl = acos(nl);
  cos_nv = acos(nv);
  a = max(nl, nv);
  b = min(nl, nv);
  b *= 0.95f;
  sin_a = sin(a);
  tan_b = tan(b);
  // use sin_a, tan_b

optimized:
  nl = max(dot(N, L), 0.0f);
  nv = max(dot(N, E), 0.0f);
  cos_a = min(nl, nv);
  cos_b = max(nl, nv);
  cos_b += FLT_MIN;
  // FLT_MIN <= cos_b <= 1.0f because 1.0f + FLT_MIN == 1.0f
  sin_a = sqrtf(1.0f - cos_a * cos_a);
  tan_b = sqrtf(1.0f - cos_b * cos_b) / cos_b;
  // use sin_a, tan_b

But some references say "O-N model is expensive because the calculation of
trigonometric function is unavoidable".  I doubt this optimization has
something wrong though it seems to be worked on my implementation.

Are there any suggestions?

-- y.fujii


More information about the Bf-cycles mailing list