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>2017-10-30 22:25:08 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2017-11-08 00:35:12 +0300
commitf79f38673145c716f9a693084b0bc4c4873e66c1 (patch)
tree42fe530c4e218f23b5989b123d5d3641a77ee68c /intern/cycles/kernel/geom
parentd0af56fe3b6490445ba3e501b0fb98cfec622aa3 (diff)
Code refactor: rename subsurface to local traversal, for reuse.
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_motion_triangle_shader.h18
-rw-r--r--intern/cycles/kernel/geom/geom_triangle_intersect.h43
3 files changed, 65 insertions, 50 deletions
diff --git a/intern/cycles/kernel/geom/geom_motion_triangle_intersect.h b/intern/cycles/kernel/geom/geom_motion_triangle_intersect.h
index f74995becf5..4a19f2ba031 100644
--- a/intern/cycles/kernel/geom/geom_motion_triangle_intersect.h
+++ b/intern/cycles/kernel/geom/geom_motion_triangle_intersect.h
@@ -97,17 +97,17 @@ ccl_device_inline float3 motion_triangle_refine(KernelGlobals *kg,
* for instancing.
*/
-#ifdef __SUBSURFACE__
+#ifdef __BVH_LOCAL__
# if defined(__KERNEL_CUDA__) && (defined(i386) || defined(_M_IX86))
ccl_device_noinline
# else
ccl_device_inline
# endif
-float3 motion_triangle_refine_subsurface(KernelGlobals *kg,
- ShaderData *sd,
- const Intersection *isect,
- const Ray *ray,
- float3 verts[3])
+float3 motion_triangle_refine_local(KernelGlobals *kg,
+ ShaderData *sd,
+ const Intersection *isect,
+ const Ray *ray,
+ float3 verts[3])
{
float3 P = ray->P;
float3 D = ray->D;
@@ -159,7 +159,7 @@ float3 motion_triangle_refine_subsurface(KernelGlobals *kg,
return P + D*t;
# endif /* __INTERSECTION_REFINE__ */
}
-#endif /* __SUBSURFACE__ */
+#endif /* __BVH_LOCAL__ */
/* Ray intersection. We simply compute the vertex positions at the given ray
@@ -215,31 +215,37 @@ ccl_device_inline bool motion_triangle_intersect(
return false;
}
-/* Special ray intersection routines for subsurface scattering. In that case we
+/* Special ray intersection routines for local intersections. In that case we
* only want to intersect with primitives in the same object, and if case of
* multiple hits we pick a single random primitive as the intersection point.
*/
-#ifdef __SUBSURFACE__
-ccl_device_inline void motion_triangle_intersect_subsurface(
+#ifdef __BVH_LOCAL__
+ccl_device_inline void motion_triangle_intersect_local(
KernelGlobals *kg,
- SubsurfaceIntersection *ss_isect,
+ LocalIntersection *local_isect,
float3 P,
float3 dir,
float time,
int object,
+ int local_object,
int prim_addr,
float tmax,
uint *lcg_state,
int max_hits)
{
+ /* Only intersect with matching object, for instanced objects we
+ * already know we are only intersecting the right object. */
+ if(object == OBJECT_NONE) {
+ if(kernel_tex_fetch(__prim_object, prim_addr) != local_object) {
+ return;
+ }
+ }
+
/* Primitive index for vertex location lookup. */
int prim = kernel_tex_fetch(__prim_index, prim_addr);
- int fobject = (object == OBJECT_NONE)
- ? kernel_tex_fetch(__prim_object, prim_addr)
- : object;
/* Get vertex locations for intersection. */
float3 verts[3];
- motion_triangle_vertices(kg, fobject, prim, time, verts);
+ motion_triangle_vertices(kg, local_object, prim, time, verts);
/* Ray-triangle intersection, unoptimized. */
float t, u, v;
if(ray_triangle_intersect(P,
@@ -252,27 +258,27 @@ ccl_device_inline void motion_triangle_intersect_subsurface(
#endif
&u, &v, &t))
{
- for(int i = min(max_hits, ss_isect->num_hits) - 1; i >= 0; --i) {
- if(ss_isect->hits[i].t == t) {
+ for(int i = min(max_hits, local_isect->num_hits) - 1; i >= 0; --i) {
+ if(local_isect->hits[i].t == t) {
return;
}
}
- ss_isect->num_hits++;
+ local_isect->num_hits++;
int hit;
- if(ss_isect->num_hits <= max_hits) {
- hit = ss_isect->num_hits - 1;
+ 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) % ss_isect->num_hits;
+ hit = lcg_step_uint(lcg_state) % local_isect->num_hits;
if(hit >= max_hits)
return;
}
/* Record intersection. */
- Intersection *isect = &ss_isect->hits[hit];
+ Intersection *isect = &local_isect->hits[hit];
isect->t = t;
isect->u = u;
isect->v = v;
@@ -280,10 +286,10 @@ ccl_device_inline void motion_triangle_intersect_subsurface(
isect->object = object;
isect->type = PRIMITIVE_MOTION_TRIANGLE;
/* Record geometric normal. */
- ss_isect->Ng[hit] = normalize(cross(verts[1] - verts[0],
+ local_isect->Ng[hit] = normalize(cross(verts[1] - verts[0],
verts[2] - verts[0]));
}
}
-#endif /* __SUBSURFACE__ */
+#endif /* __BVH_LOCAL__ */
CCL_NAMESPACE_END
diff --git a/intern/cycles/kernel/geom/geom_motion_triangle_shader.h b/intern/cycles/kernel/geom/geom_motion_triangle_shader.h
index cb456056e20..4789137d5b0 100644
--- a/intern/cycles/kernel/geom/geom_motion_triangle_shader.h
+++ b/intern/cycles/kernel/geom/geom_motion_triangle_shader.h
@@ -36,7 +36,7 @@ ccl_device_noinline void motion_triangle_shader_setup(KernelGlobals *kg,
ShaderData *sd, const
Intersection *isect,
const Ray *ray,
- bool subsurface)
+ bool is_local)
{
/* Get shader. */
sd->shader = kernel_tex_fetch(__tri_shader, sd->prim);
@@ -66,16 +66,16 @@ ccl_device_noinline void motion_triangle_shader_setup(KernelGlobals *kg,
verts[1] = (1.0f - t)*verts[1] + t*next_verts[1];
verts[2] = (1.0f - t)*verts[2] + t*next_verts[2];
/* Compute refined position. */
-#ifdef __SUBSURFACE__
- if(subsurface) {
- sd->P = motion_triangle_refine_subsurface(kg,
- sd,
- isect,
- ray,
- verts);
+#ifdef __BVH_LOCAL__
+ if(is_local) {
+ sd->P = motion_triangle_refine_local(kg,
+ sd,
+ isect,
+ ray,
+ verts);
}
else
-#endif /* __SUBSURFACE__*/
+#endif /* __BVH_LOCAL__*/
{
sd->P = motion_triangle_refine(kg, sd, isect, ray, verts);
}
diff --git a/intern/cycles/kernel/geom/geom_triangle_intersect.h b/intern/cycles/kernel/geom/geom_triangle_intersect.h
index 804e74d7e37..7daa378f81e 100644
--- a/intern/cycles/kernel/geom/geom_triangle_intersect.h
+++ b/intern/cycles/kernel/geom/geom_triangle_intersect.h
@@ -70,23 +70,32 @@ ccl_device_inline bool triangle_intersect(KernelGlobals *kg,
return false;
}
-/* Special ray intersection routines for subsurface scattering. In that case we
+/* Special ray intersection routines for local intersection. In that case we
* only want to intersect with primitives in the same object, and if case of
* multiple hits we pick a single random primitive as the intersection point.
*/
-#ifdef __SUBSURFACE__
-ccl_device_inline void triangle_intersect_subsurface(
+#ifdef __BVH_LOCAL__
+ccl_device_inline void triangle_intersect_local(
KernelGlobals *kg,
- SubsurfaceIntersection *ss_isect,
+ LocalIntersection *local_isect,
float3 P,
float3 dir,
int object,
+ int local_object,
int prim_addr,
float tmax,
uint *lcg_state,
int max_hits)
{
+ /* Only intersect with matching object, for instanced objects we
+ * already know we are only intersecting the right object. */
+ if(object == OBJECT_NONE) {
+ if(kernel_tex_fetch(__prim_object, prim_addr) != local_object) {
+ return;
+ }
+ }
+
const uint tri_vindex = kernel_tex_fetch(__prim_tri_index, prim_addr);
#if defined(__KERNEL_SSE2__) && defined(__KERNEL_SSE__)
const ssef *ssef_verts = (ssef*)&kg->__prim_tri_verts.data[tri_vindex];
@@ -109,29 +118,29 @@ ccl_device_inline void triangle_intersect_subsurface(
return;
}
- for(int i = min(max_hits, ss_isect->num_hits) - 1; i >= 0; --i) {
- if(ss_isect->hits[i].t == t) {
+ for(int i = min(max_hits, local_isect->num_hits) - 1; i >= 0; --i) {
+ if(local_isect->hits[i].t == t) {
return;
}
}
- ss_isect->num_hits++;
+ local_isect->num_hits++;
int hit;
- if(ss_isect->num_hits <= max_hits) {
- hit = ss_isect->num_hits - 1;
+ 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) % ss_isect->num_hits;
+ hit = lcg_step_uint(lcg_state) % local_isect->num_hits;
if(hit >= max_hits)
return;
}
/* record intersection */
- Intersection *isect = &ss_isect->hits[hit];
+ Intersection *isect = &local_isect->hits[hit];
isect->prim = prim_addr;
isect->object = object;
isect->type = PRIMITIVE_TRIANGLE;
@@ -145,9 +154,9 @@ ccl_device_inline void triangle_intersect_subsurface(
tri_b = float4_to_float3(kernel_tex_fetch(__prim_tri_verts, tri_vindex+1)),
tri_c = float4_to_float3(kernel_tex_fetch(__prim_tri_verts, tri_vindex+2));
#endif
- ss_isect->Ng[hit] = normalize(cross(tri_b - tri_a, tri_c - tri_a));
+ local_isect->Ng[hit] = normalize(cross(tri_b - tri_a, tri_c - tri_a));
}
-#endif /* __SUBSURFACE__ */
+#endif /* __BVH_LOCAL__ */
/* Refine triangle intersection to more precise hit point. For rays that travel
* far the precision is often not so good, this reintersects the primitive from
@@ -226,10 +235,10 @@ ccl_device_inline float3 triangle_refine(KernelGlobals *kg,
/* Same as above, except that isect->t is assumed to be in object space for
* instancing.
*/
-ccl_device_inline float3 triangle_refine_subsurface(KernelGlobals *kg,
- ShaderData *sd,
- const Intersection *isect,
- const Ray *ray)
+ccl_device_inline float3 triangle_refine_local(KernelGlobals *kg,
+ ShaderData *sd,
+ const Intersection *isect,
+ const Ray *ray)
{
float3 P = ray->P;
float3 D = ray->D;