commit 6c7c77879c1ac71fb1f9caccdfd2e4e535082ea8
parent 36e65c04e19ddd59120cae8eb1c727d423531e32
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 6 Apr 2017 16:48:50 +0200
Fix some rendering issue with perturbated normals
Diffstat:
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/ssol_draw_draft.c b/src/ssol_draw_draft.c
@@ -59,6 +59,7 @@ Li
size_t isshape;
double o[3], wi[3];
double N[3]={0};
+ double cos_Ns_wi;
/* Retrieve the hit shaded shape */
inst = *htable_instance_find(&scn->instances_rt, &hit.prim.inst_id);
@@ -76,6 +77,7 @@ Li
d3_set_f3(o, org);
d3_set_f3(wi, dir);
+ d3_normalize(wi, wi);
if(d3_dot(N, wi) < 0) {
mtl = sshape->mtl_front;
} else {
@@ -87,7 +89,8 @@ Li
material_shade_normal(mtl, &frag, 1/*TODO wavelength*/, frag.Ns);
ASSERT(d3_is_normalized(frag.Ns));
- d3_splat(val, fabs(d3_dot(frag.Ns, wi)));
+ cos_Ns_wi = d3_dot(frag.Ns, d3_minus(wi, wi));
+ d3_splat(val, MMAX(cos_Ns_wi, 0));
}
}
diff --git a/src/ssol_draw_pt.c b/src/ssol_draw_pt.c
@@ -108,13 +108,12 @@ sun_lighting
d3_minus(wi, sun->direction);
/* The point look backward the sun */
- if(d3_dot(wi, N) < 0) return 0.0;
+ cos_wi_N = d3_dot(wi, N);
+ if(cos_wi_N < 0 || eq_eps(cos_wi_N, 0, 1.e-6)) return 0.0;
R = ssf_bsdf_eval(bsdf, wo, N, wi);
if(R <= 0) return 0.0;
- cos_wi_N = d3_dot(wi, N);
-
f3_set_d3(ray_dir, wi);
S3D(scene_view_trace_ray(view, ray_org, ray_dir, ray_range, ray_data, &hit));
if(S3D_HIT_NONE(&hit)) return R * cos_wi_N;