Blender V5.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#include "kernel/geom/object.h"
14#include "kernel/svm/util.h"
16#include "util/math_base.h"
17
19
20/* Wireframe Node */
21
23 ccl_private ShaderData *sd,
24 const differential3 dP,
25 const float size,
26 const int pixel_size,
28{
29#if defined(__HAIR__) || defined(__POINTCLOUD__)
30 if (sd->prim != PRIM_NONE && sd->type & PRIMITIVE_TRIANGLE)
31#else
32 if (sd->prim != PRIM_NONE)
33#endif
34 {
35 float3 Co[3];
36 float pixelwidth = 1.0f;
37
38 /* Triangles */
39 const int np = 3;
40
41 if (sd->type & PRIMITIVE_MOTION) {
42 motion_triangle_vertices(kg, sd->object, sd->prim, sd->time, Co);
43 }
44 else {
45 triangle_vertices(kg, sd->object, sd->prim, Co);
46 }
47
48 if (!(sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED)) {
49 object_position_transform(kg, sd, &Co[0]);
50 object_position_transform(kg, sd, &Co[1]);
51 object_position_transform(kg, sd, &Co[2]);
52 }
53
54 if (pixel_size) {
55 // Project the derivatives of P to the viewing plane defined
56 // by I so we have a measure of how big is a pixel at this point
57 const float pixelwidth_x = len(dP.dx - dot(dP.dx, sd->wi) * sd->wi);
58 const float pixelwidth_y = len(dP.dy - dot(dP.dy, sd->wi) * sd->wi);
59 // Take the average of both axis' length
60 pixelwidth = (pixelwidth_x + pixelwidth_y) * 0.5f;
61 }
62
63 // Use half the width as the neighbor face will render the
64 // other half. And take the square for fast comparison
65 pixelwidth *= 0.5f * size;
66 pixelwidth *= pixelwidth;
67 for (int i = 0; i < np; i++) {
68 const int i2 = i ? i - 1 : np - 1;
69 const float3 dir = *P - Co[i];
70 const float3 edge = Co[i] - Co[i2];
71 const float3 crs = cross(edge, dir);
72 // At this point dot(crs, crs) / dot(edge, edge) is
73 // the square of area / length(edge) == square of the
74 // distance to the edge.
75 if (dot(crs, crs) < (dot(edge, edge) * pixelwidth)) {
76 return 1.0f;
77 }
78 }
79 }
80 return 0.0f;
81}
82
84 ccl_private ShaderData *sd,
85 ccl_private float *stack,
87{
88 /* Input Data */
89 const float size = stack_load(stack, node.in_size);
90 const int pixel_size = (int)node.use_pixel_size;
91
92 /* Calculate wireframe */
93 const differential3 dP = differential_from_compact(sd->Ng, sd->dP);
94
95 float3 P = sd->P;
96 if (node.bump_offset == NODE_BUMP_OFFSET_DX) {
97 P += dP.dx * node.bump_filter_width;
98 }
99 else if (node.bump_offset == NODE_BUMP_OFFSET_DY) {
100 P += dP.dy * node.bump_filter_width;
101 }
102
103 const float f = wireframe(kg, sd, dP, size, pixel_size, &P);
104
105 if (stack_valid(node.out_fac_offset)) {
106 stack_store_float(stack, node.out_fac_offset, f);
107 }
108}
109
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
ccl_device_inline void stack_store_float(ccl_private float *stack, const uint a, const float f)
ccl_device_inline bool stack_valid(const uint a)
ccl_device_inline T stack_load(const ccl_private float *stack, const uint a)
#define ccl_restrict
#define PRIM_NONE
#define ccl_private
#define ccl_device_inline
#define ccl_global
#define ccl_device_noinline
#define CCL_NAMESPACE_END
ccl_device_forceinline differential3 differential_from_compact(const float3 D, const float dD)
ccl_device_inline void triangle_vertices(KernelGlobals kg, const int object, const int prim, float3 P[3])
float dot(VecOp< float, D >, VecOp< float, D >) RET
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
ccl_device_inline void object_position_transform(KernelGlobals kg, const ccl_private ShaderData *sd, ccl_private T *P)
@ NODE_BUMP_OFFSET_DY
@ NODE_BUMP_OFFSET_DX
@ PRIMITIVE_MOTION
@ PRIMITIVE_TRIANGLE
@ SD_OBJECT_TRANSFORM_APPLIED
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
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_NAMESPACE_BEGIN ccl_device_inline float wireframe(KernelGlobals kg, ccl_private ShaderData *sd, const differential3 dP, const float size, const int pixel_size, ccl_private float3 *P)
Definition wireframe.h:22
ccl_device_noinline void svm_node_wireframe(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, const ccl_global SVMNodeWireframe &ccl_restrict node)
Definition wireframe.h:83