Blender V5.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 are stored as additional motion steps in ATTR_STD_POSITION.
13 * Normals in ATTR_STD_VERTEX_NORMAL or ATTR_STD_CORNER_NORMAL.
14 */
15
16#pragma once
17
18#include "kernel/globals.h"
19#include "kernel/types.h"
20
24
26
27/* Setup of motion triangle specific parts of ShaderData, moved into this one
28 * function to more easily share computation of interpolated positions and
29 * normals */
30
31/* return 3 triangle vertex normals */
33{
34 /* Get shader. */
35 sd->shader = kernel_data_fetch(tri_shader, sd->prim);
36
37 /* Compute motion info. */
38 int numsteps;
39 int step;
40 float t;
41 uint3 tri_vindex;
43 kg, sd->object, sd->time, sd->prim, &tri_vindex, &numsteps, &step, &t);
44
45 float3 verts[3];
46 const int numverts = kernel_data_fetch(objects, sd->object).numverts;
47 motion_triangle_vertices(kg, sd->object, tri_vindex, numsteps, numverts, step, t, verts);
48
49 /* Compute refined position. */
50 sd->P = triangle_point_from_uv_and_verts(kg, sd, sd->u, sd->v, verts);
51 /* Compute face normal. */
52 float3 Ng;
53 if (object_negative_scale_applied(sd->object_flag)) {
54 Ng = normalize(cross(verts[2] - verts[0], verts[1] - verts[0]));
55 }
56 else {
57 Ng = normalize(cross(verts[1] - verts[0], verts[2] - verts[0]));
58 }
59 sd->Ng = Ng;
60 sd->N = Ng;
61 /* Compute derivatives of P w.r.t. uv. */
62#ifdef __DPDU__
63 sd->dPdu = (verts[1] - verts[0]);
64 sd->dPdv = (verts[2] - verts[0]);
65#endif
66 /* Compute smooth normal. */
67 if (sd->shader & SHADER_SMOOTH_NORMAL) {
69 kg, Ng, sd->object, sd->prim, tri_vindex, numsteps, step, t, sd->u, sd->v);
70 }
71}
72
#define kernel_data_fetch(name, index)
#define ccl_private
#define ccl_device_noinline
#define CCL_NAMESPACE_END
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 uint 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 float3 motion_triangle_smooth_normal(KernelGlobals kg, const float3 Ng, const int object, const int prim, const uint3 tri_vindex, const int numsteps, const int step, const float t, const float u, const float v)
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_NAMESPACE_BEGIN ccl_device_noinline void motion_triangle_shader_setup(KernelGlobals kg, ccl_private ShaderData *sd)
ccl_device_inline float3 triangle_point_from_uv_and_verts(KernelGlobals kg, ccl_private ShaderData *sd, const float u, const float v, const float3 verts[3])