I have tried null state->pri
[img]http://www.puppet.cgtalk.ru/change_normal.jpg[/img]
My code looks like:
Code:
miVector *bump_normal;
if(sp->use_normal) //Change normal(bump)
{
bump_normal = mi_eval_vector(¶s->input_normal);
mi_vector_normalize(bump_normal);
state->dot_nd = mi_vector_dot(bump_normal, &state->dir);
state->normal = *bump_normal;
}
void* pri = state->pri;
state->pri = NULL;
if (m == 1)
mi_inclusive_lightlist(&n_l, &light, state);
else if (m == 2)
mi_exclusive_lightlist(&n_l, &light, state);
for (n=0; n < n_l; n++, light++)
{
sum.r = sum.g = sum.b = 0;
samples = 0;
while (mi_sample_light(&light_col.l_color_shd, &dir, &dot_nl, state, *light, &samples))
{
...
}
if (samples)
{
...
}
state->pri = pri;
}
As I understand nulling state->pri disable mr optimization that don't call light if face away from light.
But result is strange (see right image)
Now I use another code that I talking before
Code:
miVector orig_normal;
miVector *bump_normal;
if(sp->use_normal) //Change normal(bump)
{
orig_normal = state->normal;
bump_normal = mi_eval_vector(¶s->input_normal);
mi_vector_normalize(bump_normal);
state->dot_nd = mi_vector_dot(bump_normal, &state->dir);
state->normal = *bump_normal;
}
state->normal = orig_normal;
if (m == 1)
mi_inclusive_lightlist(&n_l, &light, state);
else if (m == 2)
mi_exclusive_lightlist(&n_l, &light, state);
for (n=0; n < n_l; n++, light++)
{
sum.r = sum.g = sum.b = 0;
samples = 0;
while (mi_sample_light(&light_col.l_color_shd, &dir, &dot_nl, state, *light, &samples))
{
state->normal = *bump_normal;
...
state->normal = orig_normal;
}
if (samples)
{
...
}
}
state->normal = *bump_normal;
And it works fine except one case, if occlusion shader used as light shader.
As I understand mi_sample_light always return 0 before switch to next light source. I don't know how to track it and what should I get from it.
Ofcourse it return 0 on back side of sphere (if I don't null state->pri).
Anyway thanks for your help.