Blender V5.3
overlay_line_packing.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
8
9namespace overlay {
10
16float4 pack_line_data(float2 frag_co, float2 edge_start, float2 edge_pos)
17{
18 float2 edge = edge_start - edge_pos;
19 float len = length(edge);
20 if (len > 0.0f) {
21 edge /= len;
22
23 /* Get perpendicular in direction of upper hemicircle. */
24 float2 perp = float2(-edge.y, edge.x);
25 if (perp.y < 0.0) {
26 perp = -perp;
27 }
28
29 /* Get distance along perpendicular by projection of edge. */
30 float sin_theta = perp.x;
31 float dist = dot(perp, frag_co - edge_start);
32
33 /* Pack dist to [0.1, ..., 0.9], leaving 0.1 boundary for clear or blocked pixels. */
34 return float4(sin_theta * 0.5f + 0.5f, dist * 0.4f + 0.5f, 0.0f, 1.0f);
35 }
36 /* Default line if the origin is perfectly aligned with a pixel. */
37 return float4(0.0f, 0.5f, 0.0f, 1.0f);
38}
39
45{
46 return float4(0.0f, 1.0f, 0.0f, 1.0f);
47}
48
52void unpack_line_data(float2 data, float2 &perp, float &dist)
53{
54 /* Unpack distance to edge, remove 0.1 boundary around value. */
55 dist = (data.y - 0.5f) * 2.5f;
56
57 /* Recover perpendicular vector from packed sin_theta. */
58 float sin_theta = (data.x - 0.5f) * 2.0f;
61}
62
63} // namespace overlay
ccl_device_inline float cos_theta(const float3 w)
ccl_device_inline float sin_theta(const float3 w)
VecBase< float, D > normalize(VecOp< float, D >) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
float length(VecOp< float, D >) RET
float cos_from_sin(float s)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
float4 pack_line_data(float2 frag_co, float2 edge_start, float2 edge_pos)
void unpack_line_data(float2 data, float2 &perp, float &dist)
float4 pack_line_data_no_aa()
float x
float y