Blender V4.5
services_shared.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5/* Shared functions between OSL on CPU and GPU. */
6
7#pragma once
8
11
13
14/* TODO: deduplicate function `set_attribute_float3()` in CPU and GPU. */
15
17 ccl_private const ShaderData *sd,
18 float3 f[3])
19{
20 if (!(sd->type & PRIMITIVE_TRIANGLE) || !(sd->shader & SHADER_SMOOTH_NORMAL)) {
21 /* TODO: implement for curve. */
22 return false;
23 }
24
25 const bool backfacing = (sd->flag & SD_BACKFACING);
26
27 /* Fallback when the smooth normal is zero. */
28 float3 Ng = backfacing ? -sd->Ng : sd->Ng;
30
31 if (sd->type == PRIMITIVE_TRIANGLE) {
32 f[0] = triangle_smooth_normal(kg, Ng, sd->prim, sd->u, sd->v, sd->du, sd->dv, f[1], f[2]);
33 }
34 else {
37 kg, Ng, sd->object, sd->prim, sd->time, sd->u, sd->v, sd->du, sd->dv, f[1], f[2]);
38 }
39
40 if (sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED) {
41 /* Transform to local space. */
45 }
46
47 if (backfacing) {
48 f[0] = -f[0];
49 f[1] = -f[1];
50 f[2] = -f[2];
51 }
52
53 f[1] -= f[0];
54 f[2] -= f[0];
55
56 return true;
57}
58
#define ccl_device
#define ccl_private
const ThreadKernelGlobalsCPU * KernelGlobals
#define CCL_NAMESPACE_END
ccl_device_inline float3 triangle_smooth_normal(KernelGlobals kg, const float3 Ng, const int prim, const float u, float v)
#define assert(assertion)
ccl_device_inline void object_inverse_normal_transform(KernelGlobals kg, const ccl_private ShaderData *sd, ccl_private float3 *N)
@ SD_BACKFACING
@ PRIMITIVE_MOTION_TRIANGLE
@ PRIMITIVE_TRIANGLE
@ SHADER_SMOOTH_NORMAL
@ SD_OBJECT_TRANSFORM_APPLIED
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 bool attribute_bump_map_normal(KernelGlobals kg, ccl_private const ShaderData *sd, float3 f[3])