Node: Gabor Noise Texture #110802

Open
Charlie Jolly wants to merge 68 commits from CharlieJolly/blender:gabor into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
4 changed files with 33 additions and 24 deletions
Showing only changes of commit ec8bf9ba73 - Show all commits

View File

@ -25,6 +25,8 @@
# define M_EPI 0.0432139182637722
#endif
#define GABOR_SEED 1259
struct GaborParams {
float base_frequency;
float bandwidth;
@ -53,7 +55,7 @@ int impulses_per_cell(int seed, vector3 cell, float impulses)
int n = int(impulses);
float rmd = impulses - floor(impulses);
if (rmd > 0.0) {
float t = hash_vector4_to_float(vector4(cell[0], cell[1], cell[2], float(seed - 1259)));
float t = hash_vector4_to_float(vector4(cell[0], cell[1], cell[2], float(seed - GABOR_SEED)));
if (t <= rmd) {
return n + 1;
}
@ -143,7 +145,7 @@ vector3 gabor_cell_3d(output GaborParams gp, point cell, point cell_position, in
vector3 rand_position = vector3(0.0);
rand_position = mix(
rand_position,
hash_vector4_to_color(vector4(cell[0], cell[1], cell[2], float(seed + i * 1259))),
hash_vector4_to_color(vector4(cell[0], cell[1], cell[2], float(seed + i * GABOR_SEED))),
gp.cell_randomness);
point kernel_position = (cell_position - rand_position);
@ -154,7 +156,7 @@ vector3 gabor_cell_3d(output GaborParams gp, point cell, point cell_position, in
vector3 omega;
float phi;
gabor_sample(gp, cell, seed + (num_impulses + i) * 1259, omega, phi);
gabor_sample(gp, cell, seed + (num_impulses + i) * GABOR_SEED, omega, phi);
sum += gabor_kernel(gp, omega, phi, kernel_position, dv);
}
}
@ -169,7 +171,7 @@ vector3 gabor_cell_2d(output GaborParams gp, point cell, point cell_position, in
vector3 rand_position = vector3(0.0);
rand_position = mix(
rand_position,
hash_vector4_to_color(vector4(cell[0], cell[1], cell[2], float(seed + i * 1259))),
hash_vector4_to_color(vector4(cell[0], cell[1], cell[2], float(seed + i * GABOR_SEED))),
gp.cell_randomness);
rand_position.z = 0.0;
@ -181,7 +183,7 @@ vector3 gabor_cell_2d(output GaborParams gp, point cell, point cell_position, in
vector3 omega;
float phi;
gabor_sample(gp, cell, seed + (num_impulses + i) * 1259, omega, phi);
gabor_sample(gp, cell, seed + (num_impulses + i) * GABOR_SEED, omega, phi);
sum += gabor_kernel(gp, omega, phi, kernel_position, dv);
}
}

View File

@ -19,6 +19,8 @@ CCL_NAMESPACE_BEGIN
# define M_EPI_F (0.0432139182637722f)
#endif
#define GABOR_SEED 1259
typedef struct GaborParams {
float base_frequency;
float bandwidth;
@ -47,7 +49,7 @@ ccl_device int impulses_per_cell(int seed, float3 cell, float impulses)
int n = int(impulses);
float rmd = impulses - floorf(impulses);
if (rmd > 0.0f) {
float t = hash_float4_to_float(make_float4(cell.x, cell.y, cell.z, float(seed - 1259)));
float t = hash_float4_to_float(make_float4(cell.x, cell.y, cell.z, float(seed - GABOR_SEED)));
return (t <= rmd) ? n + 1 : n;
}
return n;
@ -135,7 +137,7 @@ ccl_device float3 gabor_cell_3d(GaborParams gp, float3 cell, float3 cell_positio
float3 rand_position = zero_float3();
rand_position = mix(
rand_position,
hash_float4_to_float3(make_float4(cell.x, cell.y, cell.z, float(seed + i * 1259))),
hash_float4_to_float3(make_float4(cell.x, cell.y, cell.z, float(seed + i * GABOR_SEED))),
gp.cell_randomness);
float3 kernel_position = (cell_position - rand_position);
@ -146,7 +148,7 @@ ccl_device float3 gabor_cell_3d(GaborParams gp, float3 cell, float3 cell_positio
float3 omega;
float phi;
gabor_sample(gp, cell, seed + (num_impulses + i) * 1259, &omega, &phi);
gabor_sample(gp, cell, seed + (num_impulses + i) * GABOR_SEED, &omega, &phi);
sum += gabor_kernel(gp, omega, phi, kernel_position, dv);
}
}
@ -161,7 +163,7 @@ ccl_device float3 gabor_cell_2d(GaborParams gp, float3 cell, float3 cell_positio
float3 rand_position = zero_float3();
rand_position = mix(
rand_position,
hash_float4_to_float3(make_float4(cell.x, cell.y, cell.z, float(seed + i * 1259))),
hash_float4_to_float3(make_float4(cell.x, cell.y, cell.z, float(seed + i * GABOR_SEED))),
gp.cell_randomness);
rand_position.z = 0.0f;
@ -173,7 +175,7 @@ ccl_device float3 gabor_cell_2d(GaborParams gp, float3 cell, float3 cell_positio
float3 omega;
float phi;
gabor_sample(gp, cell, seed + (num_impulses + i) * 1259, &omega, &phi);
gabor_sample(gp, cell, seed + (num_impulses + i) * GABOR_SEED, &omega, &phi);
sum += gabor_kernel(gp, omega, phi, kernel_position, dv);
}
}

View File

@ -54,6 +54,8 @@
#define SHD_GABOR_MODE_PHASOR_CROSS 6
#define SHD_GABOR_MODE_PHASOR_SQUARE 7
#define GABOR_SEED 1259
struct GaborParams {
float base_frequency;
float bandwidth;
@ -85,7 +87,7 @@ int impulses_per_cell(int seed, vec3 cell, float impulses)
int n = int(impulses);
float rmd = impulses - floor(impulses);
if (rmd > 0.0) {
float t = hash_vec4_to_float(vec4(cell, float(seed - 1259)));
float t = hash_vec4_to_float(vec4(cell, float(seed - GABOR_SEED)));
CharlieJolly marked this conversation as resolved Outdated

Add a note specifying that for non phasor modes, the result is just a broadcast of a single value in a vec3.

Add a note specifying that for non phasor modes, the result is just a broadcast of a single value in a `vec3`.

Note added.

Note added.
return (t <= rmd) ? n + 1 : n;
}
return n;
@ -177,8 +179,9 @@ vec3 gabor_cell_3d(GaborParams gp, vec3 cell, vec3 cell_position, int seed)
vec3 sum = vec3(0.0);
for (int i = 0; i < num_impulses; ++i) {
vec3 rand_position = vec3(0.0);
rand_position = mix(
rand_position, hash_vec4_to_vec3(vec4(cell, float(seed + i * 1259))), gp.cell_randomness);
rand_position = mix(rand_position,
hash_vec4_to_vec3(vec4(cell, float(seed + i * GABOR_SEED))),
gp.cell_randomness);
CharlieJolly marked this conversation as resolved Outdated

Unnecessary separation between declaration and initialization, just do vec3 rand_position = mix(...).

Unnecessary separation between declaration and initialization, just do `vec3 rand_position = mix(...)`.
vec3 kernel_position = (cell_position - rand_position);
@ -188,7 +191,7 @@ vec3 gabor_cell_3d(GaborParams gp, vec3 cell, vec3 cell_position, int seed)
vec3 omega;
float phi;
gabor_sample(gp, cell, seed + (num_impulses + i) * 1259, omega, phi);
gabor_sample(gp, cell, seed + (num_impulses + i) * GABOR_SEED, omega, phi);
sum += gabor_kernel(gp, omega, phi, kernel_position, dv);
}
}
@ -203,8 +206,9 @@ vec3 gabor_cell_2d(GaborParams gp, vec3 cell, vec3 cell_position, int seed)
vec3 sum = vec3(0.0);
for (int i = 0; i < num_impulses; ++i) {
vec3 rand_position = vec3(0.0);
rand_position = mix(
rand_position, hash_vec4_to_vec3(vec4(cell, float(seed + i * 1259))), gp.cell_randomness);
rand_position = mix(rand_position,
hash_vec4_to_vec3(vec4(cell, float(seed + i * GABOR_SEED))),
gp.cell_randomness);
rand_position.z = 0.0;
vec3 kernel_position = (cell_position - rand_position);
@ -215,7 +219,7 @@ vec3 gabor_cell_2d(GaborParams gp, vec3 cell, vec3 cell_position, int seed)
vec3 omega;
float phi;
gabor_sample(gp, cell, seed + (num_impulses + i) * 1259, omega, phi);
gabor_sample(gp, cell, seed + (num_impulses + i) * GABOR_SEED, omega, phi);
sum += gabor_kernel(gp, omega, phi, kernel_position, dv);
}
}

View File

@ -190,6 +190,8 @@ static void node_update(bNodeTree *ntree, bNode *node)
# define M_EPI_F 0.0432139182637722f
#endif
#define GABOR_SEED 1259
typedef struct GaborParams {
float base_frequency;
float bandwidth;
@ -216,9 +218,9 @@ typedef struct FractalParams {
int impulses_per_cell(const int seed, const float3 cell, const float impulses)
{
const int n = int(impulses);
float rmd = impulses - math::floor(impulses);
const float rmd = impulses - math::floor(impulses);
if (rmd > 0.0f) {
const float t = noise::hash_float_to_float(float4(cell, float(seed - 1259)));
const float t = noise::hash_float_to_float(float4(cell, float(seed - GABOR_SEED)));
return (t <= rmd) ? n + 1 : n;
}
return n;
@ -275,7 +277,6 @@ static float3 gabor_kernel(const GaborParams gp,
const float h2 = math::sin(gp.base_frequency * math::dot(omega, position) + phi) +
math::sin(gp.base_frequency * math::dot(omega, positionyxz) + phi);
r = float3(h, h2, 0.0f) * 0.5f;
;
}
return r * g;
@ -312,7 +313,7 @@ static float3 gabor_cell_3d(GaborParams &gp, float3 cell, float3 cell_position,
float3 rand_position = float3(0.0f);
rand_position = math::interpolate(
rand_position,
noise::hash_float_to_float3(float4(cell, float(seed + i * 1259))),
noise::hash_float_to_float3(float4(cell, float(seed + i * GABOR_SEED))),
gp.cell_randomness);
const float3 kernel_position = (cell_position - rand_position);
@ -322,7 +323,7 @@ static float3 gabor_cell_3d(GaborParams &gp, float3 cell, float3 cell_position,
if (dv <= 1.0f) {
float3 omega;
float phi;
gabor_sample(gp, cell, seed + (num_impulses + i) * 1259, omega, phi);
gabor_sample(gp, cell, seed + (num_impulses + i) * GABOR_SEED, omega, phi);
sum += gabor_kernel(gp, omega, phi, kernel_position, dv);
}
}
@ -337,7 +338,7 @@ static float3 gabor_cell_2d(GaborParams &gp, float3 cell, float3 cell_position,
float3 rand_position = float3(0.0f);
rand_position = math::interpolate(
rand_position,
noise::hash_float_to_float3(float4(cell, float(seed + i * 1259))),
noise::hash_float_to_float3(float4(cell, float(seed + i * GABOR_SEED))),
gp.cell_randomness);
rand_position.z = 0.0f;
@ -348,7 +349,7 @@ static float3 gabor_cell_2d(GaborParams &gp, float3 cell, float3 cell_position,
if (dv <= 1.0f) {
float3 omega;
float phi;
gabor_sample(gp, cell, seed + (num_impulses + i) * 1259, omega, phi);
gabor_sample(gp, cell, seed + (num_impulses + i) * GABOR_SEED, omega, phi);
sum += gabor_kernel(gp, omega, phi, kernel_position, dv);
}
}