Blender V5.0
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
18#include "kernel/globals.h"
19#include "kernel/types.h"
20
23
25
26/* Setup of motion triangle specific parts of ShaderData, moved into this one
27 * function to more easily share computation of interpolated positions and
28 * normals */
29
30/* return 3 triangle vertex normals */
32{
33 /* Get shader. */
34 sd->shader = kernel_data_fetch(tri_shader, sd->prim);
35
36 /* Compute motion info. */
37 int numsteps;
38 int step;
39 float t;
40 uint3 tri_vindex;
42 kg, sd->object, sd->time, sd->prim, &tri_vindex, &numsteps, &step, &t);
43
44 float3 verts[3];
45 const int numverts = kernel_data_fetch(objects, sd->object).numverts;
46 motion_triangle_vertices(kg, sd->object, tri_vindex, numsteps, numverts, step, t, verts);
47
48 /* Compute refined position. */
49 sd->P = motion_triangle_point_from_uv(kg, sd, sd->u, sd->v, verts);
50 /* Compute face normal. */
51 float3 Ng;
52 if (object_negative_scale_applied(sd->object_flag)) {
53 Ng = normalize(cross(verts[2] - verts[0], verts[1] - verts[0]));
54 }
55 else {
56 Ng = normalize(cross(verts[1] - verts[0], verts[2] - verts[0]));
57 }
58 sd->Ng = Ng;
59 sd->N = Ng;
60 /* Compute derivatives of P w.r.t. uv. */
61#ifdef __DPDU__
62 sd->dPdu = (verts[1] - verts[0]);
63 sd->dPdv = (verts[2] - verts[0]);
64#endif
65 /* Compute smooth normal. */
66 if (sd->shader & SHADER_SMOOTH_NORMAL) {
68 kg, Ng, sd->object, tri_vindex, numsteps, step, t, sd->u, sd->v);
69 }
70}
71
#define kernel_data_fetch(name, index)
#define ccl_private
const ThreadKernelGlobalsCPU * KernelGlobals
#define ccl_device_noinline
#define CCL_NAMESPACE_END
static float verts[][3]
VecBase< float, D > normalize(VecOp< float, D >) RET
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
ccl_device_inline bool object_negative_scale_applied(const int object_flag)
@ SHADER_SMOOTH_NORMAL
ccl_device_inline void motion_triangle_vertices(KernelGlobals kg, const int object, const uint3 tri_vindex, const int numsteps, const int numverts, const int step, const float t, float3 verts[3])
ccl_device_inline void motion_triangle_compute_info(KernelGlobals kg, const int object, const float time, const int prim, ccl_private uint3 *tri_vindex, ccl_private int *numsteps, ccl_private int *step, ccl_private float *t)
ccl_device_inline float3 motion_triangle_smooth_normal(KernelGlobals kg, const float3 Ng, const int object, const uint3 tri_vindex, const int numsteps, const int step, const float t, const float u, const float v)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 motion_triangle_point_from_uv(KernelGlobals kg, ccl_private ShaderData *sd, const float u, const float v, const float3 verts[3])
CCL_NAMESPACE_BEGIN ccl_device_noinline void motion_triangle_shader_setup(KernelGlobals kg, ccl_private ShaderData *sd)