Blender V4.3
motion_triangle_shader.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5/* Motion Triangle Primitive
6 *
7 * These are stored as regular triangles, plus extra positions and normals at
8 * times other than the frame center. Computing the triangle vertex positions
9 * or normals at a given ray time is a matter of interpolation of the two steps
10 * between which the ray time lies.
11 *
12 * The extra positions and normals are stored as ATTR_STD_MOTION_VERTEX_POSITION
13 * and ATTR_STD_MOTION_VERTEX_NORMAL mesh attributes.
14 */
15
16#pragma once
17
19
20/* Setup of motion triangle specific parts of ShaderData, moved into this one
21 * function to more easily share computation of interpolated positions and
22 * normals */
23
24/* return 3 triangle vertex normals */
26{
27 /* Get shader. */
28 sd->shader = kernel_data_fetch(tri_shader, sd->prim);
29
30 /* Compute motion info. */
31 int numsteps, step;
32 float t;
33 uint3 tri_vindex;
35 kg, sd->object, sd->time, sd->prim, &tri_vindex, &numsteps, &step, &t);
36
37 float3 verts[3];
38 const int numverts = kernel_data_fetch(objects, sd->object).numverts;
39 motion_triangle_vertices(kg, sd->object, tri_vindex, numsteps, numverts, step, t, verts);
40
41 /* Compute refined position. */
42 sd->P = motion_triangle_point_from_uv(kg, sd, sd->u, sd->v, verts);
43 /* Compute face normal. */
44 float3 Ng;
45 if (object_negative_scale_applied(sd->object_flag)) {
46 Ng = normalize(cross(verts[2] - verts[0], verts[1] - verts[0]));
47 }
48 else {
49 Ng = normalize(cross(verts[1] - verts[0], verts[2] - verts[0]));
50 }
51 sd->Ng = Ng;
52 sd->N = Ng;
53 /* Compute derivatives of P w.r.t. uv. */
54#ifdef __DPDU__
55 sd->dPdu = (verts[1] - verts[0]);
56 sd->dPdv = (verts[2] - verts[0]);
57#endif
58 /* Compute smooth normal. */
59 if (sd->shader & SHADER_SMOOTH_NORMAL) {
61 kg, Ng, sd->object, tri_vindex, numsteps, step, t, sd->u, sd->v);
62 }
63}
64
SIMD_FORCE_INLINE btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
Definition btVector3.h:303
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define kernel_data_fetch(name, index)
#define ccl_private
#define ccl_device_noinline
#define CCL_NAMESPACE_END
static float verts[][3]
ccl_device_inline bool object_negative_scale_applied(const int object_flag)
ShaderData
@ SHADER_SMOOTH_NORMAL
ccl_device_inline float cross(const float2 a, const float2 b)
ccl_device_inline float3 motion_triangle_smooth_normal(KernelGlobals kg, float3 Ng, int object, uint3 tri_vindex, int numsteps, int step, float t, float u, float v)
ccl_device_inline void motion_triangle_vertices(KernelGlobals kg, int object, uint3 tri_vindex, int numsteps, int numverts, int step, float t, float3 verts[3])
ccl_device_inline void motion_triangle_compute_info(KernelGlobals kg, int object, float time, int prim, ccl_private uint3 *tri_vindex, ccl_private int *numsteps, ccl_private int *step, ccl_private float *t)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 motion_triangle_point_from_uv(KernelGlobals kg, ccl_private ShaderData *sd, 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)