[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59399] branches/soc-2013-cycles_mblur/ intern/cycles: This week, I was trying to figure out a way to pack a moving triangle
Gavin Howard
gavin.d.howard at gmail.com
Fri Aug 23 08:35:14 CEST 2013
Revision: 59399
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59399
Author: gdh
Date: 2013-08-23 06:35:14 +0000 (Fri, 23 Aug 2013)
Log Message:
-----------
This week, I was trying to figure out a way to pack a moving triangle
into the kernel. I wasn't doing so well, so Brecht took time out of his
day to write something up (this commit). I am quite embarrassed right
now. Thanks, Brecht!
However, this commit breaks the CUDA build, at least on my machine. I
don't know why, but since deformation motion blur is only supported on
the CPU anyway, it shouldn't really matter.
There is still one issue. This commit changes the BVH::pack_triangle()
function a lot. To me, it appears that the changes only pack in the
number of steps and number of verts. It appears to delete the code that
used to pack triangles into the kernel. I will need to look into it more
and figure out what is going on.
I will also be going over the changes in this commit to figure out
exactly what Brecht did.
Modified Paths:
--------------
branches/soc-2013-cycles_mblur/intern/cycles/bvh/bvh.cpp
branches/soc-2013-cycles_mblur/intern/cycles/kernel/kernel_bvh.h
branches/soc-2013-cycles_mblur/intern/cycles/kernel/kernel_bvh_traversal.h
branches/soc-2013-cycles_mblur/intern/cycles/kernel/kernel_primitive.h
branches/soc-2013-cycles_mblur/intern/cycles/kernel/kernel_types.h
branches/soc-2013-cycles_mblur/intern/cycles/kernel/osl/osl_services.cpp
branches/soc-2013-cycles_mblur/intern/cycles/render/mesh.cpp
branches/soc-2013-cycles_mblur/intern/cycles/render/scene.cpp
branches/soc-2013-cycles_mblur/intern/cycles/util/util_math.h
Modified: branches/soc-2013-cycles_mblur/intern/cycles/bvh/bvh.cpp
===================================================================
--- branches/soc-2013-cycles_mblur/intern/cycles/bvh/bvh.cpp 2013-08-23 05:32:43 UTC (rev 59398)
+++ branches/soc-2013-cycles_mblur/intern/cycles/bvh/bvh.cpp 2013-08-23 06:35:14 UTC (rev 59399)
@@ -238,38 +238,23 @@
void BVH::pack_triangle(int idx, float4 woop[3])
{
- /* create Woop triangle */
int tob = pack.prim_object[idx];
const Mesh *mesh = objects[tob]->mesh;
- int tidx = pack.prim_index[idx];
- const int *vidx = mesh->triangles[tidx].v;
- const float3* vpos = &mesh->verts[0];
- float3 v0 = vpos[vidx[0]];
- float3 v1 = vpos[vidx[1]];
- float3 v2 = vpos[vidx[2]];
- float3 r0 = v0 - v2;
- float3 r1 = v1 - v2;
- float3 r2 = cross(r0, r1);
+ if(mesh->attributes.find(ATTR_STD_DMOTION)) {
+ /* quick hack to pack motion blur info into woop data structure */
+ int totalsteps = mesh->mblur_steps;
+ int numsteps = (totalsteps - 1)/2;
+ int numverts = mesh->verts.size();
- if(is_zero(r0) || is_zero(r1) || is_zero(r2)) {
- /* degenerate */
- woop[0] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+ woop[0] = make_float4(__int_as_float(numsteps), __int_as_float(numverts), 0.0f, 0.0f);
woop[1] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
woop[2] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
}
else {
- Transform t = make_transform(
- r0.x, r1.x, r2.x, v2.x,
- r0.y, r1.y, r2.y, v2.y,
- r0.z, r1.z, r2.z, v2.z,
- 0.0f, 0.0f, 0.0f, 1.0f);
-
- t = transform_inverse(t);
-
- woop[0] = make_float4(t.z.x, t.z.y, t.z.z, -t.z.w);
- woop[1] = make_float4(t.x.x, t.x.y, t.x.z, t.x.w);
- woop[2] = make_float4(t.y.x, t.y.y, t.y.z, t.y.w);
+ woop[0] = make_float4(__int_as_float(0), 0.0f, 0.0f, 0.0f);
+ woop[1] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+ woop[2] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
}
}
Modified: branches/soc-2013-cycles_mblur/intern/cycles/kernel/kernel_bvh.h
===================================================================
--- branches/soc-2013-cycles_mblur/intern/cycles/kernel/kernel_bvh.h 2013-08-23 05:32:43 UTC (rev 59398)
+++ branches/soc-2013-cycles_mblur/intern/cycles/kernel/kernel_bvh.h 2013-08-23 06:35:14 UTC (rev 59399)
@@ -112,6 +112,96 @@
}
#endif
+__device_inline void bvh_triangle_verts_for_step(KernelGlobals *kg, float3 tri_vindex, int offset, int numverts, int numsteps, int step, float3 verts[3])
+{
+ if(step == numsteps) {
+ /* center step: regular vertex location */
+ verts[0] = float4_to_float3(kernel_tex_fetch(__tri_verts, __float_as_int(tri_vindex.x)));
+ verts[1] = float4_to_float3(kernel_tex_fetch(__tri_verts, __float_as_int(tri_vindex.y)));
+ verts[2] = float4_to_float3(kernel_tex_fetch(__tri_verts, __float_as_int(tri_vindex.z)));
+ }
+ else {
+ /* center step not store in this array */
+ if(step > numsteps)
+ step--;
+
+ offset += step*numverts;
+
+ verts[0] = float4_to_float3(kernel_tex_fetch(__attributes_float3, offset + __float_as_int(tri_vindex.x)));
+ verts[1] = float4_to_float3(kernel_tex_fetch(__attributes_float3, offset + __float_as_int(tri_vindex.y)));
+ verts[2] = float4_to_float3(kernel_tex_fetch(__attributes_float3, offset + __float_as_int(tri_vindex.z)));
+ }
+}
+
+__device_inline bool bvh_triangle_intersect(KernelGlobals *kg, Intersection *isect,
+ float3 P, float3 idir, float time, uint visibility, int object, int triAddr)
+{
+ /* primitive index for vertex location lookup */
+ int prim = kernel_tex_fetch(__prim_index, triAddr);
+
+ /* triangle indexes */
+ float3 tri_vindex = float4_to_float3(kernel_tex_fetch(__tri_vindex, prim));
+
+ /* motion blur related triangle data */
+ float4 woop0 = kernel_tex_fetch(__tri_woop, triAddr*TRI_NODE_SIZE+0);
+ int numsteps = __float_as_int(woop0.x);
+ float3 verts[3];
+
+ /* test if we have motion blur */
+ if(time != -1.0f && numsteps) {
+ /* get motion steps attribute info, we could find some way to store the
+ * offset in woop0 as well to optimize this */
+ AttributeElement elem;
+ int fobject = (object == ~0)? kernel_tex_fetch(__prim_object, triAddr): object;
+ int offset = find_attribute_hack(kg, fobject, ATTR_STD_DMOTION, &elem);
+
+ /* the attribute should always be there */
+ kernel_assert(offset != ATTR_STD_NOT_FOUND);
+
+ /* get number of verts in mesh and total motion blur steps */
+ int numverts = __float_as_int(woop0.y);
+ int totalsteps = numsteps*2 + 1;
+
+ /* figure out which steps we need to fetch and their interpolation factor */
+ int step = min((int)(time*totalsteps), totalsteps - 1);
+ int next_step = min(step + 1, totalsteps - 1);
+ float t = time*totalsteps - step;
+
+ /* fetch vertex coordinates */
+ float3 next_verts[3];
+ bvh_triangle_verts_for_step(kg, tri_vindex, offset, numverts, numsteps, step, verts);
+ bvh_triangle_verts_for_step(kg, tri_vindex, offset, numverts, numsteps, next_step, next_verts);
+
+ /* interpolate between steps */
+ verts[0] = (1.0f - t)*verts[0] + t*next_verts[0];
+ verts[1] = (1.0f - t)*verts[1] + t*next_verts[1];
+ verts[2] = (1.0f - t)*verts[2] + t*next_verts[2];
+ }
+ else {
+ /* no motion blur, just get triangle coordinates */
+ verts[0] = float4_to_float3(kernel_tex_fetch(__tri_verts, __float_as_int(tri_vindex.x)));
+ verts[1] = float4_to_float3(kernel_tex_fetch(__tri_verts, __float_as_int(tri_vindex.y)));
+ verts[2] = float4_to_float3(kernel_tex_fetch(__tri_verts, __float_as_int(tri_vindex.z)));
+ }
+
+ /* ray-triangle intersection, unoptimized */
+ float3 D = make_float3(1.0f/idir.x, 1.0f/idir.y, 1.0f/idir.z);
+ float t, u, v;
+
+ if(ray_triangle_intersect_uv(P, D, isect->t, verts[2], verts[0], verts[1], &u, &v, &t)) {
+ isect->prim = triAddr;
+ isect->object = object;
+ isect->u = u;
+ isect->v = v;
+ isect->t = t;
+
+ return true;
+ }
+
+ return false;
+}
+
+#if 0
/* Sven Woop's algorithm */
__device_inline bool bvh_triangle_intersect(KernelGlobals *kg, Intersection *isect,
float3 P, float3 idir, uint visibility, int object, int triAddr)
@@ -159,6 +249,7 @@
return false;
}
+#endif
#ifdef __HAIR__
__device_inline void curvebounds(float *lower, float *upper, float *extremta, float *extrema, float *extremtb, float *extremb, float p0, float p1, float p2, float p3)
Modified: branches/soc-2013-cycles_mblur/intern/cycles/kernel/kernel_bvh_traversal.h
===================================================================
--- branches/soc-2013-cycles_mblur/intern/cycles/kernel/kernel_bvh_traversal.h 2013-08-23 05:32:43 UTC (rev 59398)
+++ branches/soc-2013-cycles_mblur/intern/cycles/kernel/kernel_bvh_traversal.h 2013-08-23 06:35:14 UTC (rev 59399)
@@ -252,7 +252,7 @@
}
else
#endif
- hit = bvh_triangle_intersect(kg, isect, P, idir, visibility, object, primAddr);
+ hit = bvh_triangle_intersect(kg, isect, P, idir, ray->time, visibility, object, primAddr);
/* shadow ray early termination */
#if defined(__KERNEL_SSE2__) && !FEATURE(BVH_HAIR_MINIMUM_WIDTH)
Modified: branches/soc-2013-cycles_mblur/intern/cycles/kernel/kernel_primitive.h
===================================================================
--- branches/soc-2013-cycles_mblur/intern/cycles/kernel/kernel_primitive.h 2013-08-23 05:32:43 UTC (rev 59398)
+++ branches/soc-2013-cycles_mblur/intern/cycles/kernel/kernel_primitive.h 2013-08-23 06:35:14 UTC (rev 59399)
@@ -52,6 +52,23 @@
}
}
+__device_inline int find_attribute_hack(KernelGlobals *kg, int object, uint id, AttributeElement *elem)
+{
+ /* for SVM, find attribute by unique id */
+ uint attr_offset = object*kernel_data.bvh.attributes_map_stride;
+ uint4 attr_map = kernel_tex_fetch(__attributes_map, attr_offset);
+
+ while(attr_map.x != id) {
+ attr_offset += ATTR_PRIM_TYPES;
+ attr_map = kernel_tex_fetch(__attributes_map, attr_offset);
+ }
+
+ *elem = (AttributeElement)attr_map.y;
+
+ /* return result */
+ return (attr_map.y == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : (int)attr_map.z;
+}
+
__device float primitive_attribute_float(KernelGlobals *kg, const ShaderData *sd, AttributeElement elem, int offset, float *dx, float *dy)
{
#ifdef __HAIR__
Modified: branches/soc-2013-cycles_mblur/intern/cycles/kernel/kernel_types.h
===================================================================
--- branches/soc-2013-cycles_mblur/intern/cycles/kernel/kernel_types.h 2013-08-23 05:32:43 UTC (rev 59398)
+++ branches/soc-2013-cycles_mblur/intern/cycles/kernel/kernel_types.h 2013-08-23 06:35:14 UTC (rev 59399)
@@ -122,7 +122,7 @@
#define __VISIBILITY_FLAG__
#define __RAY_DIFFERENTIALS__
#define __CAMERA_CLIPPING__
-#define __INTERSECTION_REFINE__
+//#define __INTERSECTION_REFINE__
#define __CLAMP_SAMPLE__
#ifdef __KERNEL_SHADING__
Modified: branches/soc-2013-cycles_mblur/intern/cycles/kernel/osl/osl_services.cpp
===================================================================
--- branches/soc-2013-cycles_mblur/intern/cycles/kernel/osl/osl_services.cpp 2013-08-23 05:32:43 UTC (rev 59398)
+++ branches/soc-2013-cycles_mblur/intern/cycles/kernel/osl/osl_services.cpp 2013-08-23 06:35:14 UTC (rev 59399)
@@ -35,10 +35,10 @@
#include "kernel_differential.h"
#include "kernel_object.h"
#include "kernel_random.h"
-#include "kernel_bvh.h"
#include "kernel_triangle.h"
#include "kernel_curve.h"
#include "kernel_primitive.h"
+#include "kernel_bvh.h"
#include "kernel_projection.h"
#include "kernel_accumulate.h"
#include "kernel_camera.h"
Modified: branches/soc-2013-cycles_mblur/intern/cycles/render/mesh.cpp
===================================================================
--- branches/soc-2013-cycles_mblur/intern/cycles/render/mesh.cpp 2013-08-23 05:32:43 UTC (rev 59398)
+++ branches/soc-2013-cycles_mblur/intern/cycles/render/mesh.cpp 2013-08-23 06:35:14 UTC (rev 59399)
@@ -676,6 +676,8 @@
* a correction for that in here */
if(element == ATTR_ELEMENT_VERTEX)
offset -= mesh->vert_offset;
+ else if(element == ATTR_ELEMENT_VERTEX_STEPS)
+ offset -= mesh->vert_offset;
else if(element == ATTR_ELEMENT_FACE)
offset -= mesh->tri_offset;
else if(element == ATTR_ELEMENT_CORNER)
Modified: branches/soc-2013-cycles_mblur/intern/cycles/render/scene.cpp
===================================================================
--- branches/soc-2013-cycles_mblur/intern/cycles/render/scene.cpp 2013-08-23 05:32:43 UTC (rev 59398)
+++ branches/soc-2013-cycles_mblur/intern/cycles/render/scene.cpp 2013-08-23 06:35:14 UTC (rev 59399)
@@ -221,7 +221,9 @@
if(std == ATTR_STD_UV)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list