2014-03-29 12:03:47 +00:00
|
|
|
/*
|
|
|
|
* Adapted from code Copyright 2009-2010 NVIDIA Corporation
|
|
|
|
* Modifications Copyright 2011, Blender Foundation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2014-03-29 12:03:48 +00:00
|
|
|
/* Motion Triangle Primitive
|
|
|
|
*
|
|
|
|
* These are stored as regular triangles, plus extra positions and normals at
|
|
|
|
* times other than the frame center. Computing the triangle vertex positions
|
|
|
|
* or normals at a given ray time is a matter of interpolation of the two steps
|
|
|
|
* between which the ray time lies.
|
|
|
|
*
|
|
|
|
* The extra positions and normals are stored as ATTR_STD_MOTION_VERTEX_POSITION
|
|
|
|
* and ATTR_STD_MOTION_VERTEX_NORMAL mesh attributes.
|
|
|
|
*/
|
|
|
|
|
2014-03-29 12:03:47 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2014-03-29 12:03:48 +00:00
|
|
|
/* Time interpolation of vertex positions and normals */
|
|
|
|
|
2014-03-29 12:03:47 +00:00
|
|
|
ccl_device_inline int find_attribute_motion(KernelGlobals *kg, int object, uint id, AttributeElement *elem)
|
|
|
|
{
|
2014-03-29 12:03:48 +00:00
|
|
|
/* todo: find a better (faster) solution for this, maybe store offset per object */
|
2014-03-29 12:03:47 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
ccl_device_inline void motion_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)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ccl_device_inline void motion_triangle_normals_for_step(KernelGlobals *kg, float3 tri_vindex, int offset, int numverts, int numsteps, int step, float3 normals[3])
|
|
|
|
{
|
|
|
|
if(step == numsteps) {
|
|
|
|
/* center step: regular vertex location */
|
|
|
|
normals[0] = float4_to_float3(kernel_tex_fetch(__tri_vnormal, __float_as_int(tri_vindex.x)));
|
|
|
|
normals[1] = float4_to_float3(kernel_tex_fetch(__tri_vnormal, __float_as_int(tri_vindex.y)));
|
|
|
|
normals[2] = float4_to_float3(kernel_tex_fetch(__tri_vnormal, __float_as_int(tri_vindex.z)));
|
|
|
|
}
|
|
|
|
else {
|
2014-03-29 12:03:48 +00:00
|
|
|
/* center step not stored in this array */
|
2014-03-29 12:03:47 +00:00
|
|
|
if(step > numsteps)
|
|
|
|
step--;
|
|
|
|
|
|
|
|
offset += step*numverts;
|
|
|
|
|
|
|
|
normals[0] = float4_to_float3(kernel_tex_fetch(__attributes_float3, offset + __float_as_int(tri_vindex.x)));
|
|
|
|
normals[1] = float4_to_float3(kernel_tex_fetch(__attributes_float3, offset + __float_as_int(tri_vindex.y)));
|
|
|
|
normals[2] = float4_to_float3(kernel_tex_fetch(__attributes_float3, offset + __float_as_int(tri_vindex.z)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ccl_device_inline void motion_triangle_vertices(KernelGlobals *kg, int object, int prim, float time, float3 verts[3])
|
|
|
|
{
|
|
|
|
/* get motion info */
|
|
|
|
int numsteps, numverts;
|
|
|
|
object_motion_info(kg, object, &numsteps, &numverts, NULL);
|
|
|
|
|
|
|
|
/* figure out which steps we need to fetch and their interpolation factor */
|
|
|
|
int maxstep = numsteps*2;
|
|
|
|
int step = min((int)(time*maxstep), maxstep-1);
|
|
|
|
float t = time*maxstep - step;
|
|
|
|
|
|
|
|
/* find attribute */
|
|
|
|
AttributeElement elem;
|
|
|
|
int offset = find_attribute_motion(kg, object, ATTR_STD_MOTION_VERTEX_POSITION, &elem);
|
|
|
|
kernel_assert(offset != ATTR_STD_NOT_FOUND);
|
|
|
|
|
|
|
|
/* fetch vertex coordinates */
|
|
|
|
float3 next_verts[3];
|
|
|
|
float3 tri_vindex = float4_to_float3(kernel_tex_fetch(__tri_vindex, prim));
|
|
|
|
|
|
|
|
motion_triangle_verts_for_step(kg, tri_vindex, offset, numverts, numsteps, step, verts);
|
|
|
|
motion_triangle_verts_for_step(kg, tri_vindex, offset, numverts, numsteps, step+1, 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];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
* a closer distance. */
|
|
|
|
|
|
|
|
ccl_device_inline float3 motion_triangle_refine(KernelGlobals *kg, ShaderData *sd, const Intersection *isect, const Ray *ray, float3 verts[3])
|
|
|
|
{
|
|
|
|
float3 P = ray->P;
|
|
|
|
float3 D = ray->D;
|
|
|
|
float t = isect->t;
|
|
|
|
|
|
|
|
#ifdef __INTERSECTION_REFINE__
|
2014-03-29 12:03:47 +00:00
|
|
|
if(isect->object != OBJECT_NONE) {
|
2015-02-10 14:07:55 +00:00
|
|
|
if(UNLIKELY(t == 0.0f)) {
|
|
|
|
return P;
|
|
|
|
}
|
2016-02-12 17:33:43 +00:00
|
|
|
# ifdef __OBJECT_MOTION__
|
2015-05-14 13:46:26 +00:00
|
|
|
Transform tfm = ccl_fetch(sd, ob_itfm);
|
2016-02-12 17:33:43 +00:00
|
|
|
# else
|
2014-03-29 12:03:47 +00:00
|
|
|
Transform tfm = object_fetch_transform(kg, isect->object, OBJECT_INVERSE_TRANSFORM);
|
2016-02-12 17:33:43 +00:00
|
|
|
# endif
|
2014-03-29 12:03:47 +00:00
|
|
|
|
|
|
|
P = transform_point(&tfm, P);
|
|
|
|
D = transform_direction(&tfm, D*t);
|
|
|
|
D = normalize_len(D, &t);
|
|
|
|
}
|
|
|
|
|
|
|
|
P = P + D*t;
|
|
|
|
|
|
|
|
/* compute refined intersection distance */
|
|
|
|
const float3 e1 = verts[0] - verts[2];
|
|
|
|
const float3 e2 = verts[1] - verts[2];
|
|
|
|
const float3 s1 = cross(D, e2);
|
|
|
|
|
|
|
|
const float invdivisor = 1.0f/dot(s1, e1);
|
|
|
|
const float3 d = P - verts[2];
|
|
|
|
const float3 s2 = cross(d, e1);
|
|
|
|
float rt = dot(e2, s2)*invdivisor;
|
|
|
|
|
|
|
|
/* compute refined position */
|
|
|
|
P = P + D*rt;
|
|
|
|
|
2014-03-29 12:03:47 +00:00
|
|
|
if(isect->object != OBJECT_NONE) {
|
2016-02-12 17:33:43 +00:00
|
|
|
# ifdef __OBJECT_MOTION__
|
2015-05-14 13:46:26 +00:00
|
|
|
Transform tfm = ccl_fetch(sd, ob_tfm);
|
2016-02-12 17:33:43 +00:00
|
|
|
# else
|
2014-03-29 12:03:47 +00:00
|
|
|
Transform tfm = object_fetch_transform(kg, isect->object, OBJECT_TRANSFORM);
|
2016-02-12 17:33:43 +00:00
|
|
|
# endif
|
2014-03-29 12:03:47 +00:00
|
|
|
|
|
|
|
P = transform_point(&tfm, P);
|
|
|
|
}
|
|
|
|
|
|
|
|
return P;
|
|
|
|
#else
|
|
|
|
return P + D*t;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-03-29 12:03:48 +00:00
|
|
|
/* Same as above, except that isect->t is assumed to be in object space for instancing */
|
|
|
|
|
|
|
|
#ifdef __SUBSURFACE__
|
2016-02-15 18:11:02 +00:00
|
|
|
# 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])
|
2014-03-29 12:03:47 +00:00
|
|
|
{
|
|
|
|
float3 P = ray->P;
|
|
|
|
float3 D = ray->D;
|
|
|
|
float t = isect->t;
|
|
|
|
|
2016-02-12 17:33:43 +00:00
|
|
|
# ifdef __INTERSECTION_REFINE__
|
2014-03-29 12:03:47 +00:00
|
|
|
if(isect->object != OBJECT_NONE) {
|
2016-02-12 17:33:43 +00:00
|
|
|
# ifdef __OBJECT_MOTION__
|
2015-05-14 13:46:26 +00:00
|
|
|
Transform tfm = ccl_fetch(sd, ob_itfm);
|
2016-02-12 17:33:43 +00:00
|
|
|
# else
|
2014-03-29 12:03:47 +00:00
|
|
|
Transform tfm = object_fetch_transform(kg, isect->object, OBJECT_INVERSE_TRANSFORM);
|
2016-02-12 17:33:43 +00:00
|
|
|
# endif
|
2014-03-29 12:03:47 +00:00
|
|
|
|
|
|
|
P = transform_point(&tfm, P);
|
|
|
|
D = transform_direction(&tfm, D);
|
|
|
|
D = normalize(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
P = P + D*t;
|
|
|
|
|
|
|
|
/* compute refined intersection distance */
|
|
|
|
const float3 e1 = verts[0] - verts[2];
|
|
|
|
const float3 e2 = verts[1] - verts[2];
|
|
|
|
const float3 s1 = cross(D, e2);
|
|
|
|
|
|
|
|
const float invdivisor = 1.0f/dot(s1, e1);
|
|
|
|
const float3 d = P - verts[2];
|
|
|
|
const float3 s2 = cross(d, e1);
|
|
|
|
float rt = dot(e2, s2)*invdivisor;
|
|
|
|
|
|
|
|
P = P + D*rt;
|
|
|
|
|
2014-03-29 12:03:47 +00:00
|
|
|
if(isect->object != OBJECT_NONE) {
|
2016-02-12 17:33:43 +00:00
|
|
|
# ifdef __OBJECT_MOTION__
|
2015-05-14 13:46:26 +00:00
|
|
|
Transform tfm = ccl_fetch(sd, ob_tfm);
|
2016-02-12 17:33:43 +00:00
|
|
|
# else
|
2014-03-29 12:03:47 +00:00
|
|
|
Transform tfm = object_fetch_transform(kg, isect->object, OBJECT_TRANSFORM);
|
2016-02-12 17:33:43 +00:00
|
|
|
# endif
|
2014-03-29 12:03:47 +00:00
|
|
|
|
|
|
|
P = transform_point(&tfm, P);
|
|
|
|
}
|
|
|
|
|
|
|
|
return P;
|
2016-02-12 17:33:43 +00:00
|
|
|
# else
|
2014-03-29 12:03:47 +00:00
|
|
|
return P + D*t;
|
2016-02-12 17:33:43 +00:00
|
|
|
# endif
|
2014-03-29 12:03:47 +00:00
|
|
|
}
|
2014-03-29 12:03:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Setup of motion triangle specific parts of ShaderData, moved into this one
|
|
|
|
* function to more easily share computation of interpolated positions and
|
|
|
|
* normals */
|
2014-03-29 12:03:47 +00:00
|
|
|
|
|
|
|
/* return 3 triangle vertex normals */
|
|
|
|
ccl_device_noinline void motion_triangle_shader_setup(KernelGlobals *kg, ShaderData *sd, const Intersection *isect, const Ray *ray, bool subsurface)
|
|
|
|
{
|
|
|
|
/* get shader */
|
Cycles: OpenCL kernel split
This commit contains all the work related on the AMD megakernel split work
which was mainly done by Varun Sundar, George Kyriazis and Lenny Wang, plus
some help from Sergey Sharybin, Martijn Berger, Thomas Dinges and likely
someone else which we're forgetting to mention.
Currently only AMD cards are enabled for the new split kernel, but it is
possible to force split opencl kernel to be used by setting the following
environment variable: CYCLES_OPENCL_SPLIT_KERNEL_TEST=1.
Not all the features are supported yet, and that being said no motion blur,
camera blur, SSS and volumetrics for now. Also transparent shadows are
disabled on AMD device because of some compiler bug.
This kernel is also only implements regular path tracing and supporting
branched one will take a bit. Branched path tracing is exposed to the
interface still, which is a bit misleading and will be hidden there soon.
More feature will be enabled once they're ported to the split kernel and
tested.
Neither regular CPU nor CUDA has any difference, they're generating the
same exact code, which means no regressions/improvements there.
Based on the research paper:
https://research.nvidia.com/sites/default/files/publications/laine2013hpg_paper.pdf
Here's the documentation:
https://docs.google.com/document/d/1LuXW-CV-sVJkQaEGZlMJ86jZ8FmoPfecaMdR-oiWbUY/edit
Design discussion of the patch:
https://developer.blender.org/T44197
Differential Revision: https://developer.blender.org/D1200
2015-05-09 14:34:30 +00:00
|
|
|
ccl_fetch(sd, shader) = kernel_tex_fetch(__tri_shader, ccl_fetch(sd, prim));
|
2014-03-29 12:03:47 +00:00
|
|
|
|
|
|
|
/* get motion info */
|
|
|
|
int numsteps, numverts;
|
Cycles: OpenCL kernel split
This commit contains all the work related on the AMD megakernel split work
which was mainly done by Varun Sundar, George Kyriazis and Lenny Wang, plus
some help from Sergey Sharybin, Martijn Berger, Thomas Dinges and likely
someone else which we're forgetting to mention.
Currently only AMD cards are enabled for the new split kernel, but it is
possible to force split opencl kernel to be used by setting the following
environment variable: CYCLES_OPENCL_SPLIT_KERNEL_TEST=1.
Not all the features are supported yet, and that being said no motion blur,
camera blur, SSS and volumetrics for now. Also transparent shadows are
disabled on AMD device because of some compiler bug.
This kernel is also only implements regular path tracing and supporting
branched one will take a bit. Branched path tracing is exposed to the
interface still, which is a bit misleading and will be hidden there soon.
More feature will be enabled once they're ported to the split kernel and
tested.
Neither regular CPU nor CUDA has any difference, they're generating the
same exact code, which means no regressions/improvements there.
Based on the research paper:
https://research.nvidia.com/sites/default/files/publications/laine2013hpg_paper.pdf
Here's the documentation:
https://docs.google.com/document/d/1LuXW-CV-sVJkQaEGZlMJ86jZ8FmoPfecaMdR-oiWbUY/edit
Design discussion of the patch:
https://developer.blender.org/T44197
Differential Revision: https://developer.blender.org/D1200
2015-05-09 14:34:30 +00:00
|
|
|
object_motion_info(kg, ccl_fetch(sd, object), &numsteps, &numverts, NULL);
|
2014-03-29 12:03:47 +00:00
|
|
|
|
|
|
|
/* figure out which steps we need to fetch and their interpolation factor */
|
|
|
|
int maxstep = numsteps*2;
|
Cycles: OpenCL kernel split
This commit contains all the work related on the AMD megakernel split work
which was mainly done by Varun Sundar, George Kyriazis and Lenny Wang, plus
some help from Sergey Sharybin, Martijn Berger, Thomas Dinges and likely
someone else which we're forgetting to mention.
Currently only AMD cards are enabled for the new split kernel, but it is
possible to force split opencl kernel to be used by setting the following
environment variable: CYCLES_OPENCL_SPLIT_KERNEL_TEST=1.
Not all the features are supported yet, and that being said no motion blur,
camera blur, SSS and volumetrics for now. Also transparent shadows are
disabled on AMD device because of some compiler bug.
This kernel is also only implements regular path tracing and supporting
branched one will take a bit. Branched path tracing is exposed to the
interface still, which is a bit misleading and will be hidden there soon.
More feature will be enabled once they're ported to the split kernel and
tested.
Neither regular CPU nor CUDA has any difference, they're generating the
same exact code, which means no regressions/improvements there.
Based on the research paper:
https://research.nvidia.com/sites/default/files/publications/laine2013hpg_paper.pdf
Here's the documentation:
https://docs.google.com/document/d/1LuXW-CV-sVJkQaEGZlMJ86jZ8FmoPfecaMdR-oiWbUY/edit
Design discussion of the patch:
https://developer.blender.org/T44197
Differential Revision: https://developer.blender.org/D1200
2015-05-09 14:34:30 +00:00
|
|
|
int step = min((int)(ccl_fetch(sd, time)*maxstep), maxstep-1);
|
|
|
|
float t = ccl_fetch(sd, time)*maxstep - step;
|
2014-03-29 12:03:47 +00:00
|
|
|
|
|
|
|
/* find attribute */
|
|
|
|
AttributeElement elem;
|
Cycles: OpenCL kernel split
This commit contains all the work related on the AMD megakernel split work
which was mainly done by Varun Sundar, George Kyriazis and Lenny Wang, plus
some help from Sergey Sharybin, Martijn Berger, Thomas Dinges and likely
someone else which we're forgetting to mention.
Currently only AMD cards are enabled for the new split kernel, but it is
possible to force split opencl kernel to be used by setting the following
environment variable: CYCLES_OPENCL_SPLIT_KERNEL_TEST=1.
Not all the features are supported yet, and that being said no motion blur,
camera blur, SSS and volumetrics for now. Also transparent shadows are
disabled on AMD device because of some compiler bug.
This kernel is also only implements regular path tracing and supporting
branched one will take a bit. Branched path tracing is exposed to the
interface still, which is a bit misleading and will be hidden there soon.
More feature will be enabled once they're ported to the split kernel and
tested.
Neither regular CPU nor CUDA has any difference, they're generating the
same exact code, which means no regressions/improvements there.
Based on the research paper:
https://research.nvidia.com/sites/default/files/publications/laine2013hpg_paper.pdf
Here's the documentation:
https://docs.google.com/document/d/1LuXW-CV-sVJkQaEGZlMJ86jZ8FmoPfecaMdR-oiWbUY/edit
Design discussion of the patch:
https://developer.blender.org/T44197
Differential Revision: https://developer.blender.org/D1200
2015-05-09 14:34:30 +00:00
|
|
|
int offset = find_attribute_motion(kg, ccl_fetch(sd, object), ATTR_STD_MOTION_VERTEX_POSITION, &elem);
|
2014-03-29 12:03:47 +00:00
|
|
|
kernel_assert(offset != ATTR_STD_NOT_FOUND);
|
|
|
|
|
|
|
|
/* fetch vertex coordinates */
|
|
|
|
float3 verts[3], next_verts[3];
|
Cycles: OpenCL kernel split
This commit contains all the work related on the AMD megakernel split work
which was mainly done by Varun Sundar, George Kyriazis and Lenny Wang, plus
some help from Sergey Sharybin, Martijn Berger, Thomas Dinges and likely
someone else which we're forgetting to mention.
Currently only AMD cards are enabled for the new split kernel, but it is
possible to force split opencl kernel to be used by setting the following
environment variable: CYCLES_OPENCL_SPLIT_KERNEL_TEST=1.
Not all the features are supported yet, and that being said no motion blur,
camera blur, SSS and volumetrics for now. Also transparent shadows are
disabled on AMD device because of some compiler bug.
This kernel is also only implements regular path tracing and supporting
branched one will take a bit. Branched path tracing is exposed to the
interface still, which is a bit misleading and will be hidden there soon.
More feature will be enabled once they're ported to the split kernel and
tested.
Neither regular CPU nor CUDA has any difference, they're generating the
same exact code, which means no regressions/improvements there.
Based on the research paper:
https://research.nvidia.com/sites/default/files/publications/laine2013hpg_paper.pdf
Here's the documentation:
https://docs.google.com/document/d/1LuXW-CV-sVJkQaEGZlMJ86jZ8FmoPfecaMdR-oiWbUY/edit
Design discussion of the patch:
https://developer.blender.org/T44197
Differential Revision: https://developer.blender.org/D1200
2015-05-09 14:34:30 +00:00
|
|
|
float3 tri_vindex = float4_to_float3(kernel_tex_fetch(__tri_vindex, ccl_fetch(sd, prim)));
|
2014-03-29 12:03:47 +00:00
|
|
|
|
|
|
|
motion_triangle_verts_for_step(kg, tri_vindex, offset, numverts, numsteps, step, verts);
|
|
|
|
motion_triangle_verts_for_step(kg, tri_vindex, offset, numverts, numsteps, step+1, 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];
|
|
|
|
|
|
|
|
/* compute refined position */
|
2014-03-29 12:03:48 +00:00
|
|
|
#ifdef __SUBSURFACE__
|
2014-03-29 12:03:47 +00:00
|
|
|
if(!subsurface)
|
2014-03-29 12:03:48 +00:00
|
|
|
#endif
|
Cycles: OpenCL kernel split
This commit contains all the work related on the AMD megakernel split work
which was mainly done by Varun Sundar, George Kyriazis and Lenny Wang, plus
some help from Sergey Sharybin, Martijn Berger, Thomas Dinges and likely
someone else which we're forgetting to mention.
Currently only AMD cards are enabled for the new split kernel, but it is
possible to force split opencl kernel to be used by setting the following
environment variable: CYCLES_OPENCL_SPLIT_KERNEL_TEST=1.
Not all the features are supported yet, and that being said no motion blur,
camera blur, SSS and volumetrics for now. Also transparent shadows are
disabled on AMD device because of some compiler bug.
This kernel is also only implements regular path tracing and supporting
branched one will take a bit. Branched path tracing is exposed to the
interface still, which is a bit misleading and will be hidden there soon.
More feature will be enabled once they're ported to the split kernel and
tested.
Neither regular CPU nor CUDA has any difference, they're generating the
same exact code, which means no regressions/improvements there.
Based on the research paper:
https://research.nvidia.com/sites/default/files/publications/laine2013hpg_paper.pdf
Here's the documentation:
https://docs.google.com/document/d/1LuXW-CV-sVJkQaEGZlMJ86jZ8FmoPfecaMdR-oiWbUY/edit
Design discussion of the patch:
https://developer.blender.org/T44197
Differential Revision: https://developer.blender.org/D1200
2015-05-09 14:34:30 +00:00
|
|
|
ccl_fetch(sd, P) = motion_triangle_refine(kg, sd, isect, ray, verts);
|
2014-03-29 12:03:48 +00:00
|
|
|
#ifdef __SUBSURFACE__
|
2014-03-29 12:03:47 +00:00
|
|
|
else
|
Cycles: OpenCL kernel split
This commit contains all the work related on the AMD megakernel split work
which was mainly done by Varun Sundar, George Kyriazis and Lenny Wang, plus
some help from Sergey Sharybin, Martijn Berger, Thomas Dinges and likely
someone else which we're forgetting to mention.
Currently only AMD cards are enabled for the new split kernel, but it is
possible to force split opencl kernel to be used by setting the following
environment variable: CYCLES_OPENCL_SPLIT_KERNEL_TEST=1.
Not all the features are supported yet, and that being said no motion blur,
camera blur, SSS and volumetrics for now. Also transparent shadows are
disabled on AMD device because of some compiler bug.
This kernel is also only implements regular path tracing and supporting
branched one will take a bit. Branched path tracing is exposed to the
interface still, which is a bit misleading and will be hidden there soon.
More feature will be enabled once they're ported to the split kernel and
tested.
Neither regular CPU nor CUDA has any difference, they're generating the
same exact code, which means no regressions/improvements there.
Based on the research paper:
https://research.nvidia.com/sites/default/files/publications/laine2013hpg_paper.pdf
Here's the documentation:
https://docs.google.com/document/d/1LuXW-CV-sVJkQaEGZlMJ86jZ8FmoPfecaMdR-oiWbUY/edit
Design discussion of the patch:
https://developer.blender.org/T44197
Differential Revision: https://developer.blender.org/D1200
2015-05-09 14:34:30 +00:00
|
|
|
ccl_fetch(sd, P) = motion_triangle_refine_subsurface(kg, sd, isect, ray, verts);
|
2014-03-29 12:03:48 +00:00
|
|
|
#endif
|
2014-03-29 12:03:47 +00:00
|
|
|
|
|
|
|
/* compute face normal */
|
2014-08-13 10:19:12 +00:00
|
|
|
float3 Ng;
|
Cycles: OpenCL kernel split
This commit contains all the work related on the AMD megakernel split work
which was mainly done by Varun Sundar, George Kyriazis and Lenny Wang, plus
some help from Sergey Sharybin, Martijn Berger, Thomas Dinges and likely
someone else which we're forgetting to mention.
Currently only AMD cards are enabled for the new split kernel, but it is
possible to force split opencl kernel to be used by setting the following
environment variable: CYCLES_OPENCL_SPLIT_KERNEL_TEST=1.
Not all the features are supported yet, and that being said no motion blur,
camera blur, SSS and volumetrics for now. Also transparent shadows are
disabled on AMD device because of some compiler bug.
This kernel is also only implements regular path tracing and supporting
branched one will take a bit. Branched path tracing is exposed to the
interface still, which is a bit misleading and will be hidden there soon.
More feature will be enabled once they're ported to the split kernel and
tested.
Neither regular CPU nor CUDA has any difference, they're generating the
same exact code, which means no regressions/improvements there.
Based on the research paper:
https://research.nvidia.com/sites/default/files/publications/laine2013hpg_paper.pdf
Here's the documentation:
https://docs.google.com/document/d/1LuXW-CV-sVJkQaEGZlMJ86jZ8FmoPfecaMdR-oiWbUY/edit
Design discussion of the patch:
https://developer.blender.org/T44197
Differential Revision: https://developer.blender.org/D1200
2015-05-09 14:34:30 +00:00
|
|
|
if(ccl_fetch(sd, flag) & SD_NEGATIVE_SCALE_APPLIED)
|
2014-08-13 10:19:12 +00:00
|
|
|
Ng = normalize(cross(verts[2] - verts[0], verts[1] - verts[0]));
|
|
|
|
else
|
|
|
|
Ng = normalize(cross(verts[1] - verts[0], verts[2] - verts[0]));
|
2014-03-29 12:03:47 +00:00
|
|
|
|
Cycles: OpenCL kernel split
This commit contains all the work related on the AMD megakernel split work
which was mainly done by Varun Sundar, George Kyriazis and Lenny Wang, plus
some help from Sergey Sharybin, Martijn Berger, Thomas Dinges and likely
someone else which we're forgetting to mention.
Currently only AMD cards are enabled for the new split kernel, but it is
possible to force split opencl kernel to be used by setting the following
environment variable: CYCLES_OPENCL_SPLIT_KERNEL_TEST=1.
Not all the features are supported yet, and that being said no motion blur,
camera blur, SSS and volumetrics for now. Also transparent shadows are
disabled on AMD device because of some compiler bug.
This kernel is also only implements regular path tracing and supporting
branched one will take a bit. Branched path tracing is exposed to the
interface still, which is a bit misleading and will be hidden there soon.
More feature will be enabled once they're ported to the split kernel and
tested.
Neither regular CPU nor CUDA has any difference, they're generating the
same exact code, which means no regressions/improvements there.
Based on the research paper:
https://research.nvidia.com/sites/default/files/publications/laine2013hpg_paper.pdf
Here's the documentation:
https://docs.google.com/document/d/1LuXW-CV-sVJkQaEGZlMJ86jZ8FmoPfecaMdR-oiWbUY/edit
Design discussion of the patch:
https://developer.blender.org/T44197
Differential Revision: https://developer.blender.org/D1200
2015-05-09 14:34:30 +00:00
|
|
|
ccl_fetch(sd, Ng) = Ng;
|
|
|
|
ccl_fetch(sd, N) = Ng;
|
2014-03-29 12:03:47 +00:00
|
|
|
|
|
|
|
/* compute derivatives of P w.r.t. uv */
|
|
|
|
#ifdef __DPDU__
|
Cycles: OpenCL kernel split
This commit contains all the work related on the AMD megakernel split work
which was mainly done by Varun Sundar, George Kyriazis and Lenny Wang, plus
some help from Sergey Sharybin, Martijn Berger, Thomas Dinges and likely
someone else which we're forgetting to mention.
Currently only AMD cards are enabled for the new split kernel, but it is
possible to force split opencl kernel to be used by setting the following
environment variable: CYCLES_OPENCL_SPLIT_KERNEL_TEST=1.
Not all the features are supported yet, and that being said no motion blur,
camera blur, SSS and volumetrics for now. Also transparent shadows are
disabled on AMD device because of some compiler bug.
This kernel is also only implements regular path tracing and supporting
branched one will take a bit. Branched path tracing is exposed to the
interface still, which is a bit misleading and will be hidden there soon.
More feature will be enabled once they're ported to the split kernel and
tested.
Neither regular CPU nor CUDA has any difference, they're generating the
same exact code, which means no regressions/improvements there.
Based on the research paper:
https://research.nvidia.com/sites/default/files/publications/laine2013hpg_paper.pdf
Here's the documentation:
https://docs.google.com/document/d/1LuXW-CV-sVJkQaEGZlMJ86jZ8FmoPfecaMdR-oiWbUY/edit
Design discussion of the patch:
https://developer.blender.org/T44197
Differential Revision: https://developer.blender.org/D1200
2015-05-09 14:34:30 +00:00
|
|
|
ccl_fetch(sd, dPdu) = (verts[0] - verts[2]);
|
|
|
|
ccl_fetch(sd, dPdv) = (verts[1] - verts[2]);
|
2014-03-29 12:03:47 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* compute smooth normal */
|
Cycles: OpenCL kernel split
This commit contains all the work related on the AMD megakernel split work
which was mainly done by Varun Sundar, George Kyriazis and Lenny Wang, plus
some help from Sergey Sharybin, Martijn Berger, Thomas Dinges and likely
someone else which we're forgetting to mention.
Currently only AMD cards are enabled for the new split kernel, but it is
possible to force split opencl kernel to be used by setting the following
environment variable: CYCLES_OPENCL_SPLIT_KERNEL_TEST=1.
Not all the features are supported yet, and that being said no motion blur,
camera blur, SSS and volumetrics for now. Also transparent shadows are
disabled on AMD device because of some compiler bug.
This kernel is also only implements regular path tracing and supporting
branched one will take a bit. Branched path tracing is exposed to the
interface still, which is a bit misleading and will be hidden there soon.
More feature will be enabled once they're ported to the split kernel and
tested.
Neither regular CPU nor CUDA has any difference, they're generating the
same exact code, which means no regressions/improvements there.
Based on the research paper:
https://research.nvidia.com/sites/default/files/publications/laine2013hpg_paper.pdf
Here's the documentation:
https://docs.google.com/document/d/1LuXW-CV-sVJkQaEGZlMJ86jZ8FmoPfecaMdR-oiWbUY/edit
Design discussion of the patch:
https://developer.blender.org/T44197
Differential Revision: https://developer.blender.org/D1200
2015-05-09 14:34:30 +00:00
|
|
|
if(ccl_fetch(sd, shader) & SHADER_SMOOTH_NORMAL) {
|
2014-03-29 12:03:47 +00:00
|
|
|
/* find attribute */
|
|
|
|
AttributeElement elem;
|
Cycles: OpenCL kernel split
This commit contains all the work related on the AMD megakernel split work
which was mainly done by Varun Sundar, George Kyriazis and Lenny Wang, plus
some help from Sergey Sharybin, Martijn Berger, Thomas Dinges and likely
someone else which we're forgetting to mention.
Currently only AMD cards are enabled for the new split kernel, but it is
possible to force split opencl kernel to be used by setting the following
environment variable: CYCLES_OPENCL_SPLIT_KERNEL_TEST=1.
Not all the features are supported yet, and that being said no motion blur,
camera blur, SSS and volumetrics for now. Also transparent shadows are
disabled on AMD device because of some compiler bug.
This kernel is also only implements regular path tracing and supporting
branched one will take a bit. Branched path tracing is exposed to the
interface still, which is a bit misleading and will be hidden there soon.
More feature will be enabled once they're ported to the split kernel and
tested.
Neither regular CPU nor CUDA has any difference, they're generating the
same exact code, which means no regressions/improvements there.
Based on the research paper:
https://research.nvidia.com/sites/default/files/publications/laine2013hpg_paper.pdf
Here's the documentation:
https://docs.google.com/document/d/1LuXW-CV-sVJkQaEGZlMJ86jZ8FmoPfecaMdR-oiWbUY/edit
Design discussion of the patch:
https://developer.blender.org/T44197
Differential Revision: https://developer.blender.org/D1200
2015-05-09 14:34:30 +00:00
|
|
|
int offset = find_attribute_motion(kg, ccl_fetch(sd, object), ATTR_STD_MOTION_VERTEX_NORMAL, &elem);
|
2014-03-29 12:03:47 +00:00
|
|
|
kernel_assert(offset != ATTR_STD_NOT_FOUND);
|
|
|
|
|
|
|
|
/* fetch vertex coordinates */
|
|
|
|
float3 normals[3], next_normals[3];
|
|
|
|
motion_triangle_normals_for_step(kg, tri_vindex, offset, numverts, numsteps, step, normals);
|
|
|
|
motion_triangle_normals_for_step(kg, tri_vindex, offset, numverts, numsteps, step+1, next_normals);
|
|
|
|
|
|
|
|
/* interpolate between steps */
|
|
|
|
normals[0] = (1.0f - t)*normals[0] + t*next_normals[0];
|
|
|
|
normals[1] = (1.0f - t)*normals[1] + t*next_normals[1];
|
|
|
|
normals[2] = (1.0f - t)*normals[2] + t*next_normals[2];
|
|
|
|
|
|
|
|
/* interpolate between vertices */
|
Cycles: OpenCL kernel split
This commit contains all the work related on the AMD megakernel split work
which was mainly done by Varun Sundar, George Kyriazis and Lenny Wang, plus
some help from Sergey Sharybin, Martijn Berger, Thomas Dinges and likely
someone else which we're forgetting to mention.
Currently only AMD cards are enabled for the new split kernel, but it is
possible to force split opencl kernel to be used by setting the following
environment variable: CYCLES_OPENCL_SPLIT_KERNEL_TEST=1.
Not all the features are supported yet, and that being said no motion blur,
camera blur, SSS and volumetrics for now. Also transparent shadows are
disabled on AMD device because of some compiler bug.
This kernel is also only implements regular path tracing and supporting
branched one will take a bit. Branched path tracing is exposed to the
interface still, which is a bit misleading and will be hidden there soon.
More feature will be enabled once they're ported to the split kernel and
tested.
Neither regular CPU nor CUDA has any difference, they're generating the
same exact code, which means no regressions/improvements there.
Based on the research paper:
https://research.nvidia.com/sites/default/files/publications/laine2013hpg_paper.pdf
Here's the documentation:
https://docs.google.com/document/d/1LuXW-CV-sVJkQaEGZlMJ86jZ8FmoPfecaMdR-oiWbUY/edit
Design discussion of the patch:
https://developer.blender.org/T44197
Differential Revision: https://developer.blender.org/D1200
2015-05-09 14:34:30 +00:00
|
|
|
float u = ccl_fetch(sd, u);
|
|
|
|
float v = ccl_fetch(sd, v);
|
2014-03-29 12:03:47 +00:00
|
|
|
float w = 1.0f - u - v;
|
Cycles: OpenCL kernel split
This commit contains all the work related on the AMD megakernel split work
which was mainly done by Varun Sundar, George Kyriazis and Lenny Wang, plus
some help from Sergey Sharybin, Martijn Berger, Thomas Dinges and likely
someone else which we're forgetting to mention.
Currently only AMD cards are enabled for the new split kernel, but it is
possible to force split opencl kernel to be used by setting the following
environment variable: CYCLES_OPENCL_SPLIT_KERNEL_TEST=1.
Not all the features are supported yet, and that being said no motion blur,
camera blur, SSS and volumetrics for now. Also transparent shadows are
disabled on AMD device because of some compiler bug.
This kernel is also only implements regular path tracing and supporting
branched one will take a bit. Branched path tracing is exposed to the
interface still, which is a bit misleading and will be hidden there soon.
More feature will be enabled once they're ported to the split kernel and
tested.
Neither regular CPU nor CUDA has any difference, they're generating the
same exact code, which means no regressions/improvements there.
Based on the research paper:
https://research.nvidia.com/sites/default/files/publications/laine2013hpg_paper.pdf
Here's the documentation:
https://docs.google.com/document/d/1LuXW-CV-sVJkQaEGZlMJ86jZ8FmoPfecaMdR-oiWbUY/edit
Design discussion of the patch:
https://developer.blender.org/T44197
Differential Revision: https://developer.blender.org/D1200
2015-05-09 14:34:30 +00:00
|
|
|
ccl_fetch(sd, N) = (u*normals[0] + v*normals[1] + w*normals[2]);
|
2014-03-29 12:03:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-29 12:03:48 +00:00
|
|
|
/* Ray intersection. We simply compute the vertex positions at the given ray
|
|
|
|
* time and do a ray intersection with the resulting triangle */
|
2014-03-29 12:03:47 +00:00
|
|
|
|
|
|
|
ccl_device_inline bool motion_triangle_intersect(KernelGlobals *kg, Intersection *isect,
|
2014-04-03 18:08:53 +00:00
|
|
|
float3 P, float3 dir, float time, uint visibility, int object, int triAddr)
|
2014-03-29 12:03:47 +00:00
|
|
|
{
|
|
|
|
/* primitive index for vertex location lookup */
|
|
|
|
int prim = kernel_tex_fetch(__prim_index, triAddr);
|
2014-03-29 12:03:47 +00:00
|
|
|
int fobject = (object == OBJECT_NONE)? kernel_tex_fetch(__prim_object, triAddr): object;
|
2014-03-29 12:03:47 +00:00
|
|
|
|
|
|
|
/* get vertex locations for intersection */
|
|
|
|
float3 verts[3];
|
|
|
|
motion_triangle_vertices(kg, fobject, prim, time, verts);
|
|
|
|
|
|
|
|
/* ray-triangle intersection, unoptimized */
|
|
|
|
float t, u, v;
|
|
|
|
|
2014-04-03 18:08:53 +00:00
|
|
|
if(ray_triangle_intersect_uv(P, dir, isect->t, verts[2], verts[0], verts[1], &u, &v, &t)) {
|
2014-05-23 14:10:07 +00:00
|
|
|
#ifdef __VISIBILITY_FLAG__
|
|
|
|
/* visibility flag test. we do it here under the assumption
|
|
|
|
* that most triangles are culled by node flags */
|
|
|
|
if(kernel_tex_fetch(__prim_visibility, triAddr) & visibility)
|
|
|
|
#endif
|
|
|
|
{
|
2014-10-11 09:16:31 +00:00
|
|
|
isect->t = t;
|
|
|
|
isect->u = u;
|
|
|
|
isect->v = v;
|
2014-05-23 14:10:07 +00:00
|
|
|
isect->prim = triAddr;
|
|
|
|
isect->object = object;
|
|
|
|
isect->type = PRIMITIVE_MOTION_TRIANGLE;
|
2014-03-29 12:03:47 +00:00
|
|
|
|
2014-05-23 14:10:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-03-29 12:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Special ray intersection routines for subsurface scattering. 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. */
|
|
|
|
|
2014-03-29 12:03:48 +00:00
|
|
|
#ifdef __SUBSURFACE__
|
2015-11-22 10:00:29 +00:00
|
|
|
ccl_device_inline void motion_triangle_intersect_subsurface(
|
|
|
|
KernelGlobals *kg,
|
|
|
|
SubsurfaceIntersection *ss_isect,
|
|
|
|
float3 P,
|
|
|
|
float3 dir,
|
|
|
|
float time,
|
|
|
|
int object,
|
|
|
|
int triAddr,
|
|
|
|
float tmax,
|
|
|
|
uint *lcg_state,
|
|
|
|
int max_hits)
|
2014-03-29 12:03:47 +00:00
|
|
|
{
|
|
|
|
/* primitive index for vertex location lookup */
|
|
|
|
int prim = kernel_tex_fetch(__prim_index, triAddr);
|
2014-03-29 12:03:47 +00:00
|
|
|
int fobject = (object == OBJECT_NONE)? kernel_tex_fetch(__prim_object, triAddr): object;
|
2014-03-29 12:03:47 +00:00
|
|
|
|
|
|
|
/* get vertex locations for intersection */
|
|
|
|
float3 verts[3];
|
|
|
|
motion_triangle_vertices(kg, fobject, prim, time, verts);
|
|
|
|
|
|
|
|
/* ray-triangle intersection, unoptimized */
|
|
|
|
float t, u, v;
|
|
|
|
|
2014-04-03 18:08:53 +00:00
|
|
|
if(ray_triangle_intersect_uv(P, dir, tmax, verts[2], verts[0], verts[1], &u, &v, &t)) {
|
2015-11-22 10:00:29 +00:00
|
|
|
ss_isect->num_hits++;
|
2014-03-29 12:03:47 +00:00
|
|
|
|
|
|
|
int hit;
|
|
|
|
|
2015-11-22 10:00:29 +00:00
|
|
|
if(ss_isect->num_hits <= max_hits) {
|
|
|
|
hit = ss_isect->num_hits - 1;
|
2014-03-29 12:03:47 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* reservoir sampling: if we are at the maximum number of
|
|
|
|
* hits, randomly replace element or skip it */
|
2015-11-22 10:00:29 +00:00
|
|
|
hit = lcg_step_uint(lcg_state) % ss_isect->num_hits;
|
2014-03-29 12:03:47 +00:00
|
|
|
|
|
|
|
if(hit >= max_hits)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* record intersection */
|
2015-11-22 10:00:29 +00:00
|
|
|
Intersection *isect = &ss_isect->hits[hit];
|
2014-10-11 09:16:31 +00:00
|
|
|
isect->t = t;
|
|
|
|
isect->u = u;
|
|
|
|
isect->v = v;
|
2014-03-29 12:03:47 +00:00
|
|
|
isect->prim = triAddr;
|
|
|
|
isect->object = object;
|
|
|
|
isect->type = PRIMITIVE_MOTION_TRIANGLE;
|
2015-11-22 10:00:29 +00:00
|
|
|
|
|
|
|
/* Record geometric normal. */
|
|
|
|
ss_isect->Ng[hit] = normalize(cross(verts[1] - verts[0],
|
|
|
|
verts[2] - verts[0]));
|
2014-03-29 12:03:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|