Blender  V3.3
motion_triangle_shader.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 /* Motion Triangle Primitive
5  *
6  * These are stored as regular triangles, plus extra positions and normals at
7  * times other than the frame center. Computing the triangle vertex positions
8  * or normals at a given ray time is a matter of interpolation of the two steps
9  * between which the ray time lies.
10  *
11  * The extra positions and normals are stored as ATTR_STD_MOTION_VERTEX_POSITION
12  * and ATTR_STD_MOTION_VERTEX_NORMAL mesh attributes.
13  */
14 
15 #pragma once
16 
18 
19 /* Setup of motion triangle specific parts of ShaderData, moved into this one
20  * function to more easily share computation of interpolated positions and
21  * normals */
22 
23 /* return 3 triangle vertex normals */
26  const float3 P,
27  const float3 D,
28  const float ray_t,
29  const int isect_object,
30  const int isect_prim,
31  bool is_local)
32 {
33  /* Get shader. */
34  sd->shader = kernel_data_fetch(tri_shader, sd->prim);
35  /* Get motion info. */
36  /* TODO(sergey): This logic is really similar to motion_triangle_vertices(),
37  * can we de-duplicate something here?
38  */
39  int numsteps, numverts;
40  object_motion_info(kg, sd->object, &numsteps, &numverts, NULL);
41  /* Figure out which steps we need to fetch and their interpolation factor. */
42  int maxstep = numsteps * 2;
43  int step = min((int)(sd->time * maxstep), maxstep - 1);
44  float t = sd->time * maxstep - step;
45  /* Find attribute. */
48  /* Fetch vertex coordinates. */
49  float3 verts[3], next_verts[3];
50  uint4 tri_vindex = kernel_data_fetch(tri_vindex, sd->prim);
51  motion_triangle_verts_for_step(kg, tri_vindex, offset, numverts, numsteps, step, verts);
52  motion_triangle_verts_for_step(kg, tri_vindex, offset, numverts, numsteps, step + 1, next_verts);
53  /* Interpolate between steps. */
54  verts[0] = (1.0f - t) * verts[0] + t * next_verts[0];
55  verts[1] = (1.0f - t) * verts[1] + t * next_verts[1];
56  verts[2] = (1.0f - t) * verts[2] + t * next_verts[2];
57  /* Compute refined position. */
58  sd->P = motion_triangle_point_from_uv(kg, sd, isect_object, isect_prim, sd->u, sd->v, verts);
59  /* Compute face normal. */
60  float3 Ng;
61  if (sd->object_flag & SD_OBJECT_NEGATIVE_SCALE_APPLIED) {
62  Ng = normalize(cross(verts[2] - verts[0], verts[1] - verts[0]));
63  }
64  else {
65  Ng = normalize(cross(verts[1] - verts[0], verts[2] - verts[0]));
66  }
67  sd->Ng = Ng;
68  sd->N = Ng;
69  /* Compute derivatives of P w.r.t. uv. */
70 #ifdef __DPDU__
71  sd->dPdu = (verts[1] - verts[0]);
72  sd->dPdv = (verts[2] - verts[0]);
73 #endif
74  /* Compute smooth normal. */
75  if (sd->shader & SHADER_SMOOTH_NORMAL) {
76  /* Find attribute. */
79  /* Fetch vertex coordinates. */
80  float3 normals[3], next_normals[3];
81  motion_triangle_normals_for_step(kg, tri_vindex, offset, numverts, numsteps, step, normals);
83  kg, tri_vindex, offset, numverts, numsteps, step + 1, next_normals);
84  /* Interpolate between steps. */
85  normals[0] = (1.0f - t) * normals[0] + t * next_normals[0];
86  normals[1] = (1.0f - t) * normals[1] + t * next_normals[1];
87  normals[2] = (1.0f - t) * normals[2] + t * next_normals[2];
88  /* Interpolate between vertices. */
89  float u = sd->u;
90  float v = sd->v;
91  float w = 1.0f - u - v;
92  sd->N = safe_normalize(w * normals[0] + u * normals[1] + v * normals[2]);
93  }
94 }
95 
_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
#define kernel_assert(cond)
Definition: cpu/compat.h:34
#define ccl_private
Definition: cuda/compat.h:48
#define ccl_device_noinline
Definition: cuda/compat.h:40
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
ccl_device_inline int intersection_find_attribute(KernelGlobals kg, const int object, const uint id)
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define kernel_data_fetch(name, index)
static float verts[][3]
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
ccl_device_inline void object_motion_info(KernelGlobals kg, int object, ccl_private int *numsteps, ccl_private int *numverts, ccl_private int *numkeys)
@ ATTR_STD_MOTION_VERTEX_NORMAL
Definition: kernel/types.h:625
@ ATTR_STD_NOT_FOUND
Definition: kernel/types.h:647
@ ATTR_STD_MOTION_VERTEX_POSITION
Definition: kernel/types.h:624
ShaderData
Definition: kernel/types.h:925
@ SHADER_SMOOTH_NORMAL
Definition: kernel/types.h:435
@ SD_OBJECT_NEGATIVE_SCALE_APPLIED
Definition: kernel/types.h:810
ccl_device_inline float2 safe_normalize(const float2 &a)
Definition: math_float2.h:201
static float P(float k)
Definition: math_interp.c:25
CCL_NAMESPACE_BEGIN 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_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_NAMESPACE_BEGIN ccl_device_inline float3 motion_triangle_point_from_uv(KernelGlobals kg, ccl_private ShaderData *sd, const int isect_object, const int isect_prim, const float u, const float v, float3 verts[3])
CCL_NAMESPACE_BEGIN ccl_device_noinline void motion_triangle_shader_setup(KernelGlobals kg, ccl_private ShaderData *sd, const float3 P, const float3 D, const float ray_t, const int isect_object, const int isect_prim, bool is_local)
vec_base< T, 3 > cross(const vec_base< T, 3 > &a, const vec_base< T, 3 > &b)
vec_base< T, Size > normalize(const vec_base< T, Size > &v)
MutableSpan< float3 > normals
#define min(a, b)
Definition: sort.c:35
BLI_INLINE float D(const float *data, const int res[3], int x, int y, int z)
Definition: voxel.c:13