Blender  V2.93
geom_motion_triangle_shader.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /* Motion Triangle Primitive
18  *
19  * These are stored as regular triangles, plus extra positions and normals at
20  * times other than the frame center. Computing the triangle vertex positions
21  * or normals at a given ray time is a matter of interpolation of the two steps
22  * between which the ray time lies.
23  *
24  * The extra positions and normals are stored as ATTR_STD_MOTION_VERTEX_POSITION
25  * and ATTR_STD_MOTION_VERTEX_NORMAL mesh attributes.
26  */
27 
29 
30 /* Setup of motion triangle specific parts of ShaderData, moved into this one
31  * function to more easily share computation of interpolated positions and
32  * normals */
33 
34 /* return 3 triangle vertex normals */
36  KernelGlobals *kg, ShaderData *sd, const Intersection *isect, const Ray *ray, bool is_local)
37 {
38  /* Get shader. */
39  sd->shader = kernel_tex_fetch(__tri_shader, sd->prim);
40  /* Get motion info. */
41  /* TODO(sergey): This logic is really similar to motion_triangle_vertices(),
42  * can we de-duplicate something here?
43  */
44  int numsteps, numverts;
45  object_motion_info(kg, sd->object, &numsteps, &numverts, NULL);
46  /* Figure out which steps we need to fetch and their interpolation factor. */
47  int maxstep = numsteps * 2;
48  int step = min((int)(sd->time * maxstep), maxstep - 1);
49  float t = sd->time * maxstep - step;
50  /* Find attribute. */
51  AttributeElement elem;
52  int offset = find_attribute_motion(kg, sd->object, ATTR_STD_MOTION_VERTEX_POSITION, &elem);
54  /* Fetch vertex coordinates. */
55  float3 verts[3], next_verts[3];
56  uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim);
57  motion_triangle_verts_for_step(kg, tri_vindex, offset, numverts, numsteps, step, verts);
58  motion_triangle_verts_for_step(kg, tri_vindex, offset, numverts, numsteps, step + 1, next_verts);
59  /* Interpolate between steps. */
60  verts[0] = (1.0f - t) * verts[0] + t * next_verts[0];
61  verts[1] = (1.0f - t) * verts[1] + t * next_verts[1];
62  verts[2] = (1.0f - t) * verts[2] + t * next_verts[2];
63  /* Compute refined position. */
64 #ifdef __BVH_LOCAL__
65  if (is_local) {
66  sd->P = motion_triangle_refine_local(kg, sd, isect, ray, verts);
67  }
68  else
69 #endif /* __BVH_LOCAL__*/
70  {
71  sd->P = motion_triangle_refine(kg, sd, isect, ray, verts);
72  }
73  /* Compute face normal. */
74  float3 Ng;
75  if (sd->object_flag & SD_OBJECT_NEGATIVE_SCALE_APPLIED) {
76  Ng = normalize(cross(verts[2] - verts[0], verts[1] - verts[0]));
77  }
78  else {
79  Ng = normalize(cross(verts[1] - verts[0], verts[2] - verts[0]));
80  }
81  sd->Ng = Ng;
82  sd->N = Ng;
83  /* Compute derivatives of P w.r.t. uv. */
84 #ifdef __DPDU__
85  sd->dPdu = (verts[0] - verts[2]);
86  sd->dPdv = (verts[1] - verts[2]);
87 #endif
88  /* Compute smooth normal. */
89  if (sd->shader & SHADER_SMOOTH_NORMAL) {
90  /* Find attribute. */
91  AttributeElement elem;
92  int offset = find_attribute_motion(kg, sd->object, ATTR_STD_MOTION_VERTEX_NORMAL, &elem);
94  /* Fetch vertex coordinates. */
95  float3 normals[3], next_normals[3];
96  motion_triangle_normals_for_step(kg, tri_vindex, offset, numverts, numsteps, step, normals);
98  kg, tri_vindex, offset, numverts, numsteps, step + 1, next_normals);
99  /* Interpolate between steps. */
100  normals[0] = (1.0f - t) * normals[0] + t * next_normals[0];
101  normals[1] = (1.0f - t) * normals[1] + t * next_normals[1];
102  normals[2] = (1.0f - t) * normals[2] + t * next_normals[2];
103  /* Interpolate between vertices. */
104  float u = sd->u;
105  float v = sd->v;
106  float w = 1.0f - u - v;
107  sd->N = (u * normals[0] + v * normals[1] + w * normals[2]);
108  }
109 }
110 
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
static float verts[][3]
static float normals[][3]
CCL_NAMESPACE_BEGIN ccl_device_inline int find_attribute_motion(KernelGlobals *kg, int object, uint id, AttributeElement *elem)
ccl_device_inline void motion_triangle_normals_for_step(KernelGlobals *kg, uint4 tri_vindex, int offset, int numverts, int numsteps, int step, float3 normals[3])
ccl_device_inline void motion_triangle_verts_for_step(KernelGlobals *kg, uint4 tri_vindex, int offset, int numverts, int numsteps, int step, float3 verts[3])
CCL_NAMESPACE_BEGIN ccl_device_inline float3 motion_triangle_refine(KernelGlobals *kg, ShaderData *sd, const Intersection *isect, const Ray *ray, float3 verts[3])
CCL_NAMESPACE_BEGIN ccl_device_noinline void motion_triangle_shader_setup(KernelGlobals *kg, ShaderData *sd, const Intersection *isect, const Ray *ray, bool is_local)
ccl_device_inline void object_motion_info(KernelGlobals *kg, int object, int *numsteps, int *numverts, int *numkeys)
Definition: geom_object.h:293
#define kernel_assert(cond)
#define kernel_tex_fetch(tex, index)
#define ccl_device_noinline
#define CCL_NAMESPACE_END
@ ATTR_STD_MOTION_VERTEX_NORMAL
Definition: kernel_types.h:757
@ ATTR_STD_NOT_FOUND
Definition: kernel_types.h:773
@ ATTR_STD_MOTION_VERTEX_POSITION
Definition: kernel_types.h:756
ShaderData
@ SHADER_SMOOTH_NORMAL
Definition: kernel_types.h:581
@ SD_OBJECT_NEGATIVE_SCALE_APPLIED
Definition: kernel_types.h:910
AttributeElement
Definition: kernel_types.h:729
#define min(a, b)
Definition: sort.c:51
__forceinline avxf cross(const avxf &a, const avxf &b)
Definition: util_avxf.h:119
ccl_device_inline float2 normalize(const float2 &a)