Blender V4.3
wireframe.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009-2010 Sony Pictures Imageworks Inc., et al. All Rights Reserved.
2 * SPDX-FileCopyrightText: 2011-2022 Blender Foundation
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 * Adapted code from Open Shading Language. */
7
8#pragma once
9
11
12/* Wireframe Node */
13
16 const differential3 dP,
17 float size,
18 int pixel_size,
20{
21#if defined(__HAIR__) || defined(__POINTCLOUD__)
22 if (sd->prim != PRIM_NONE && sd->type & PRIMITIVE_TRIANGLE)
23#else
24 if (sd->prim != PRIM_NONE)
25#endif
26 {
27 float3 Co[3];
28 float pixelwidth = 1.0f;
29
30 /* Triangles */
31 int np = 3;
32
33 if (sd->type & PRIMITIVE_MOTION) {
34 motion_triangle_vertices(kg, sd->object, sd->prim, sd->time, Co);
35 }
36 else {
37 triangle_vertices(kg, sd->prim, Co);
38 }
39
40 if (!(sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED)) {
41 object_position_transform(kg, sd, &Co[0]);
42 object_position_transform(kg, sd, &Co[1]);
43 object_position_transform(kg, sd, &Co[2]);
44 }
45
46 if (pixel_size) {
47 // Project the derivatives of P to the viewing plane defined
48 // by I so we have a measure of how big is a pixel at this point
49 float pixelwidth_x = len(dP.dx - dot(dP.dx, sd->wi) * sd->wi);
50 float pixelwidth_y = len(dP.dy - dot(dP.dy, sd->wi) * sd->wi);
51 // Take the average of both axis' length
52 pixelwidth = (pixelwidth_x + pixelwidth_y) * 0.5f;
53 }
54
55 // Use half the width as the neighbor face will render the
56 // other half. And take the square for fast comparison
57 pixelwidth *= 0.5f * size;
58 pixelwidth *= pixelwidth;
59 for (int i = 0; i < np; i++) {
60 int i2 = i ? i - 1 : np - 1;
61 float3 dir = *P - Co[i];
62 float3 edge = Co[i] - Co[i2];
63 float3 crs = cross(edge, dir);
64 // At this point dot(crs, crs) / dot(edge, edge) is
65 // the square of area / length(edge) == square of the
66 // distance to the edge.
67 if (dot(crs, crs) < (dot(edge, edge) * pixelwidth)) {
68 return 1.0f;
69 }
70 }
71 }
72 return 0.0f;
73}
74
77 ccl_private float *stack,
78 uint4 node)
79{
80 uint in_size = node.y;
81 uint out_fac = node.z;
82 uint use_pixel_size, bump_offset;
83 svm_unpack_node_uchar2(node.w, &use_pixel_size, &bump_offset);
84
85 /* Input Data */
86 float size = stack_load_float(stack, in_size);
87 int pixel_size = (int)use_pixel_size;
88
89 /* Calculate wireframe */
90 const differential3 dP = differential_from_compact(sd->Ng, sd->dP);
91 float f = wireframe(kg, sd, dP, size, pixel_size, &sd->P);
92
93 /* TODO(sergey): Think of faster way to calculate derivatives. */
94 if (bump_offset == NODE_BUMP_OFFSET_DX) {
95 float3 Px = sd->P - dP.dx;
96 f += (f - wireframe(kg, sd, dP, size, pixel_size, &Px)) / len(dP.dx);
97 }
98 else if (bump_offset == NODE_BUMP_OFFSET_DY) {
99 float3 Py = sd->P - dP.dy;
100 f += (f - wireframe(kg, sd, dP, size, pixel_size, &Py)) / len(dP.dy);
101 }
102
103 if (stack_valid(out_fac))
104 stack_store_float(stack, out_fac, f);
105}
106
unsigned int uint
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
additional_info("compositor_sum_squared_difference_float_shared") .push_constant(Type output_img float dot(value.rgb, luminance_coefficients)") .define("LOAD(value)"
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define ccl_private
#define ccl_device_inline
#define ccl_device_noinline
#define CCL_NAMESPACE_END
ccl_device_forceinline differential3 differential_from_compact(const float3 D, const float dD)
int len
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
ccl_device_inline void triangle_vertices(KernelGlobals kg, int prim, float3 P[3])
ccl_device_inline void object_position_transform(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float3 *P)
ccl_device_forceinline void svm_unpack_node_uchar2(uint i, ccl_private uint *x, ccl_private uint *y)
ccl_device_inline void stack_store_float(ccl_private float *stack, uint a, float f)
ccl_device_inline float stack_load_float(ccl_private float *stack, uint a)
ccl_device_inline bool stack_valid(uint a)
@ NODE_BUMP_OFFSET_DY
@ NODE_BUMP_OFFSET_DX
@ PRIMITIVE_MOTION
@ PRIMITIVE_TRIANGLE
#define PRIM_NONE
ShaderData
@ SD_OBJECT_TRANSFORM_APPLIED
ccl_device_inline float cross(const float2 a, const float2 b)
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_noinline void svm_node_wireframe(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, uint4 node)
Definition wireframe.h:75
CCL_NAMESPACE_BEGIN ccl_device_inline float wireframe(KernelGlobals kg, ccl_private ShaderData *sd, const differential3 dP, float size, int pixel_size, ccl_private float3 *P)
Definition wireframe.h:14