Welcome to mirror list, hosted at ThFree Co, Russian Federation.

node_hash.h « shaders « kernel « cycles « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b42e42ff910b61e946cf5c8b02835624a25a3420 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "stdcycles.h"
#include "vector2.h"
#include "vector4.h"

#define vector3 point

/* **** Hash a float or vector[234] into a float [0, 1] **** */

float hash_float_to_float(float k)
{
  return hashnoise(k);
}

float hash_vector2_to_float(vector2 k)
{
  return hashnoise(k.x, k.y);
}

float hash_vector3_to_float(vector3 k)
{
  return hashnoise(k);
}

float hash_vector4_to_float(vector4 k)
{
  return hashnoise(vector3(k.x, k.y, k.z), k.w);
}

/* **** Hash a vector[234] into a vector[234] [0, 1] **** */

vector2 hash_vector2_to_vector2(vector2 k)
{
  return vector2(hash_vector2_to_float(k), hash_vector3_to_float(vector3(k.x, k.y, 1.0)));
}

vector3 hash_vector3_to_vector3(vector3 k)
{
  return vector3(hash_vector3_to_float(k),
                 hash_vector4_to_float(vector4(k[0], k[1], k[2], 1.0)),
                 hash_vector4_to_float(vector4(k[0], k[1], k[2], 2.0)));
}

vector4 hash_vector4_to_vector4(vector4 k)
{
  return vector4(hash_vector4_to_float(k),
                 hash_vector4_to_float(vector4(k.w, k.x, k.y, k.z)),
                 hash_vector4_to_float(vector4(k.z, k.w, k.x, k.y)),
                 hash_vector4_to_float(vector4(k.y, k.z, k.w, k.x)));
}

/* **** Hash a float or a vec[234] into a color [0, 1] **** */

color hash_float_to_color(float k)
{
  return color(hash_float_to_float(k),
               hash_vector2_to_float(vector2(k, 1.0)),
               hash_vector2_to_float(vector2(k, 2.0)));
}

color hash_vector2_to_color(vector2 k)
{
  return color(hash_vector2_to_float(k),
               hash_vector3_to_float(vector3(k.x, k.y, 1.0)),
               hash_vector3_to_float(vector3(k.x, k.y, 2.0)));
}

color hash_vector3_to_color(vector3 k)
{
  return color(hash_vector3_to_float(k),
               hash_vector4_to_float(vector4(k[0], k[1], k[2], 1.0)),
               hash_vector4_to_float(vector4(k[0], k[1], k[2], 2.0)));
}

color hash_vector4_to_color(vector4 k)
{
  return color(hash_vector4_to_float(k),
               hash_vector4_to_float(vector4(k.z, k.x, k.w, k.y)),
               hash_vector4_to_float(vector4(k.w, k.z, k.y, k.x)));
}

#undef vector3