Blender  V3.3
node_hash.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #include "stdcycles.h"
5 #include "vector2.h"
6 #include "vector4.h"
7 
8 #define vector3 point
9 
10 /* **** Hash a float or vector[234] into a float [0, 1] **** */
11 
12 float hash_float_to_float(float k)
13 {
14  return hashnoise(k);
15 }
16 
17 float hash_vector2_to_float(vector2 k)
18 {
19  return hashnoise(k.x, k.y);
20 }
21 
23 {
24  return hashnoise(k);
25 }
26 
27 float hash_vector4_to_float(vector4 k)
28 {
29  return hashnoise(vector3(k.x, k.y, k.z), k.w);
30 }
31 
32 /* **** Hash a vector[234] into a vector[234] [0, 1] **** */
33 
34 vector2 hash_vector2_to_vector2(vector2 k)
35 {
36  return vector2(hash_vector2_to_float(k), hash_vector3_to_float(vector3(k.x, k.y, 1.0)));
37 }
38 
40 {
42  hash_vector4_to_float(vector4(k[0], k[1], k[2], 1.0)),
43  hash_vector4_to_float(vector4(k[0], k[1], k[2], 2.0)));
44 }
45 
46 vector4 hash_vector4_to_vector4(vector4 k)
47 {
48  return vector4(hash_vector4_to_float(k),
49  hash_vector4_to_float(vector4(k.w, k.x, k.y, k.z)),
50  hash_vector4_to_float(vector4(k.z, k.w, k.x, k.y)),
51  hash_vector4_to_float(vector4(k.y, k.z, k.w, k.x)));
52 }
53 
54 /* **** Hash a float or a vec[234] into a color [0, 1] **** */
55 
57 {
58  return color(hash_float_to_float(k),
59  hash_vector2_to_float(vector2(k, 1.0)),
60  hash_vector2_to_float(vector2(k, 2.0)));
61 }
62 
64 {
65  return color(hash_vector2_to_float(k),
66  hash_vector3_to_float(vector3(k.x, k.y, 1.0)),
67  hash_vector3_to_float(vector3(k.x, k.y, 2.0)));
68 }
69 
71 {
72  return color(hash_vector3_to_float(k),
73  hash_vector4_to_float(vector4(k[0], k[1], k[2], 1.0)),
74  hash_vector4_to_float(vector4(k[0], k[1], k[2], 2.0)));
75 }
76 
78 {
79  return color(hash_vector4_to_float(k),
80  hash_vector4_to_float(vector4(k.z, k.x, k.w, k.y)),
81  hash_vector4_to_float(vector4(k.w, k.z, k.y, k.x)));
82 }
83 
84 #undef vector3
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a color
color hash_vector3_to_color(vector3 k)
Definition: node_hash.h:70
float hash_vector4_to_float(vector4 k)
Definition: node_hash.h:27
float hash_vector3_to_float(vector3 k)
Definition: node_hash.h:22
color hash_float_to_color(float k)
Definition: node_hash.h:56
color hash_vector4_to_color(vector4 k)
Definition: node_hash.h:77
float hash_vector2_to_float(vector2 k)
Definition: node_hash.h:17
color hash_vector2_to_color(vector2 k)
Definition: node_hash.h:63
#define vector3
Definition: node_hash.h:8
vector2 hash_vector2_to_vector2(vector2 k)
Definition: node_hash.h:34
vector4 hash_vector4_to_vector4(vector4 k)
Definition: node_hash.h:46
float hash_float_to_float(float k)
Definition: node_hash.h:12
vector3 hash_vector3_to_vector3(vector3 k)
Definition: node_hash.h:39