This patch allows the Voronoi node to operate in 1D, 2D, and 4D space. It also adds a Randomness input to control the randomness of the texture. Additionally, it adds three new modes of operation: - Smooth F1: A smooth version of F1 Voronoi with no discontinuities. - Distance To Edge: Returns the distance to the edges of the cells. - N-Sphere Radius: Returns the radius of the n-sphere inscribed in the cells. In other words, it is half the distance between the closest feature point and the feature point closest to it. And it removes the following three modes of operation: - F3. - F4. - Cracks. The Distance metric is now called Euclidean, and it computes the actual euclidean distance as opposed to the old method of computing the squared euclidean distance. This breaks backward compatibility in many ways, including the base case. Reviewers: brecht, JacquesLucke Differential Revision: https://developer.blender.org/D5743
82 lines
2.1 KiB
C
82 lines
2.1 KiB
C
#include "stdosl.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
|