[Bf-cycles] Question about Oren-Nayar diffuse model
Brecht Van Lommel
brechtvanlommel at pandora.be
Mon Oct 17 09:49:33 CEST 2011
This looks like a correct optimization to me, can't see any mistakes
in it. I'd say those references are wrong :).
Brecht.
On Mon, Oct 17, 2011 at 9:16 AM, Yasuhiro Fujii
<y-fujii at mimosa-pudica.net> wrote:
> 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
> _______________________________________________
> Bf-cycles mailing list
> Bf-cycles at blender.org
> http://lists.blender.org/mailman/listinfo/bf-cycles
>
More information about the Bf-cycles
mailing list