Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2018-01-21 16:04:22 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2018-02-09 21:58:33 +0300
commit0df9b2c71517a98760a5e577f434d9d86e4e1910 (patch)
treeeee5839a1e6408af8c0e1766f37e68a8aadfbfb2 /intern/cycles/kernel/geom
parent3ab5ef7b4f34f110e4861096428b83b4f9b5efe9 (diff)
Cycles: random walk subsurface scattering.
It is basically brute force volume scattering within the mesh, but part of the SSS code for faster performance. The main difference with actual volume scattering is that we assume the boundaries are diffuse and that all lighting is coming through this boundary from outside the volume. This gives much more accurate results for thin features and low density. Some challenges remain however: * Significantly more noisy than BSSRDF. Adding Dwivedi sampling may help here, but it's unclear still how much it helps in real world cases. * Due to this being a volumetric method, geometry like eyes or mouth can darken the skin on the outside. We may be able to reduce this effect, or users can compensate for it by reducing the scattering radius in such areas. * Sharp corners are quite bright. This matches actual volume rendering and results in some other renderers, but maybe not so much real world objects. Differential Revision: https://developer.blender.org/D3054
Diffstat (limited to 'intern/cycles/kernel/geom')
-rw-r--r--intern/cycles/kernel/geom/geom_motion_triangle_intersect.h54
-rw-r--r--intern/cycles/kernel/geom/geom_triangle_intersect.h40
2 files changed, 62 insertions, 32 deletions
diff --git a/intern/cycles/kernel/geom/geom_motion_triangle_intersect.h b/intern/cycles/kernel/geom/geom_motion_triangle_intersect.h
index 4a19f2ba031..542843edc84 100644
--- a/intern/cycles/kernel/geom/geom_motion_triangle_intersect.h
+++ b/intern/cycles/kernel/geom/geom_motion_triangle_intersect.h
@@ -248,23 +248,30 @@ ccl_device_inline void motion_triangle_intersect_local(
motion_triangle_vertices(kg, local_object, prim, time, verts);
/* Ray-triangle intersection, unoptimized. */
float t, u, v;
- if(ray_triangle_intersect(P,
- dir,
- tmax,
+ if(!ray_triangle_intersect(P,
+ dir,
+ tmax,
#if defined(__KERNEL_SSE2__) && defined(__KERNEL_SSE__)
- (ssef*)verts,
+ (ssef*)verts,
#else
- verts[0], verts[1], verts[2],
+ verts[0], verts[1], verts[2],
#endif
- &u, &v, &t))
+ &u, &v, &t))
{
+ return;
+ }
+
+ int hit;
+ if(lcg_state) {
+ /* Record up to max_hits intersections. */
for(int i = min(max_hits, local_isect->num_hits) - 1; i >= 0; --i) {
if(local_isect->hits[i].t == t) {
return;
}
}
+
local_isect->num_hits++;
- int hit;
+
if(local_isect->num_hits <= max_hits) {
hit = local_isect->num_hits - 1;
}
@@ -277,18 +284,29 @@ ccl_device_inline void motion_triangle_intersect_local(
if(hit >= max_hits)
return;
}
- /* Record intersection. */
- Intersection *isect = &local_isect->hits[hit];
- isect->t = t;
- isect->u = u;
- isect->v = v;
- isect->prim = prim_addr;
- isect->object = object;
- isect->type = PRIMITIVE_MOTION_TRIANGLE;
- /* Record geometric normal. */
- local_isect->Ng[hit] = normalize(cross(verts[1] - verts[0],
- verts[2] - verts[0]));
}
+ else {
+ /* Record closest intersection only. */
+ if(local_isect->num_hits && t > local_isect->hits[0].t) {
+ return;
+ }
+
+ hit = 0;
+ local_isect->num_hits = 1;
+ }
+
+ /* Record intersection. */
+ Intersection *isect = &local_isect->hits[hit];
+ isect->t = t;
+ isect->u = u;
+ isect->v = v;
+ isect->prim = prim_addr;
+ isect->object = object;
+ isect->type = PRIMITIVE_MOTION_TRIANGLE;
+
+ /* Record geometric normal. */
+ local_isect->Ng[hit] = normalize(cross(verts[1] - verts[0],
+ verts[2] - verts[0]));
}
#endif /* __BVH_LOCAL__ */
diff --git a/intern/cycles/kernel/geom/geom_triangle_intersect.h b/intern/cycles/kernel/geom/geom_triangle_intersect.h
index 7daa378f81e..a3b23115ae4 100644
--- a/intern/cycles/kernel/geom/geom_triangle_intersect.h
+++ b/intern/cycles/kernel/geom/geom_triangle_intersect.h
@@ -118,28 +118,40 @@ ccl_device_inline void triangle_intersect_local(
return;
}
- for(int i = min(max_hits, local_isect->num_hits) - 1; i >= 0; --i) {
- if(local_isect->hits[i].t == t) {
- return;
+ int hit;
+ if(lcg_state) {
+ /* Record up to max_hits intersections. */
+ for(int i = min(max_hits, local_isect->num_hits) - 1; i >= 0; --i) {
+ if(local_isect->hits[i].t == t) {
+ return;
+ }
}
- }
- local_isect->num_hits++;
- int hit;
+ local_isect->num_hits++;
+
+ if(local_isect->num_hits <= max_hits) {
+ hit = local_isect->num_hits - 1;
+ }
+ else {
+ /* reservoir sampling: if we are at the maximum number of
+ * hits, randomly replace element or skip it */
+ hit = lcg_step_uint(lcg_state) % local_isect->num_hits;
- if(local_isect->num_hits <= max_hits) {
- hit = local_isect->num_hits - 1;
+ if(hit >= max_hits)
+ return;
+ }
}
else {
- /* reservoir sampling: if we are at the maximum number of
- * hits, randomly replace element or skip it */
- hit = lcg_step_uint(lcg_state) % local_isect->num_hits;
-
- if(hit >= max_hits)
+ /* Record closest intersection only. */
+ if(local_isect->num_hits && t > local_isect->hits[0].t) {
return;
+ }
+
+ hit = 0;
+ local_isect->num_hits = 1;
}
- /* record intersection */
+ /* Record intersection. */
Intersection *isect = &local_isect->hits[hit];
isect->prim = prim_addr;
isect->object = object;