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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartosz Moniewski <monio>2020-03-26 16:43:53 +0300
committerBrecht Van Lommel <brecht@blender.org>2020-04-09 22:48:03 +0300
commit054950def946ed7638c2d9c18ef850cbba94d9d7 (patch)
tree6c38c89f8c04be9259a4246b5b0cd5e842951052 /intern/cycles/kernel/svm
parentf3433fcd3bf87c9405fb05c96fde036eb658e8aa (diff)
Shading: add Roughness input to Noise and Wave texture nodes
Currently in fractal_noise functions, each subsequent octave doubles the frequency and reduces the amplitude by half. This patch introduces Roughness input to Noise and Wave nodes. This multiplier determines how quickly the amplitudes of the subsequent octaves decrease. Value of 0.5 will be the default, generating identical noise we had before. Values above 0.5 will increase influence of each octave resulting in more "rough" noise, most interesting pattern changes happen there. Values below 0.5 will result in more "smooth" noise. Differential Revision: https://developer.blender.org/D7065
Diffstat (limited to 'intern/cycles/kernel/svm')
-rw-r--r--intern/cycles/kernel/svm/svm_fractal_noise.h52
-rw-r--r--intern/cycles/kernel/svm/svm_noisetex.h91
-rw-r--r--intern/cycles/kernel/svm/svm_wave.h32
3 files changed, 107 insertions, 68 deletions
diff --git a/intern/cycles/kernel/svm/svm_fractal_noise.h b/intern/cycles/kernel/svm/svm_fractal_noise.h
index 5b2e4a28fce..57fa8c690ac 100644
--- a/intern/cycles/kernel/svm/svm_fractal_noise.h
+++ b/intern/cycles/kernel/svm/svm_fractal_noise.h
@@ -17,114 +17,118 @@
CCL_NAMESPACE_BEGIN
/* The fractal_noise_[1-4] functions are all exactly the same except for the input type. */
-ccl_device_noinline float fractal_noise_1d(float p, float octaves)
+ccl_device_noinline float fractal_noise_1d(float p, float octaves, float roughness)
{
float fscale = 1.0f;
float amp = 1.0f;
+ float maxamp = 0.0f;
float sum = 0.0f;
octaves = clamp(octaves, 0.0f, 16.0f);
int n = float_to_int(octaves);
for (int i = 0; i <= n; i++) {
float t = noise_1d(fscale * p);
sum += t * amp;
- amp *= 0.5f;
+ maxamp += amp;
+ amp *= clamp(roughness, 0.0f, 1.0f);
fscale *= 2.0f;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
float t = noise_1d(fscale * p);
float sum2 = sum + t * amp;
- sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
- sum2 *= ((float)(1 << (n + 1)) / (float)((1 << (n + 2)) - 1));
+ sum /= maxamp;
+ sum2 /= maxamp + amp;
return (1.0f - rmd) * sum + rmd * sum2;
}
else {
- sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
- return sum;
+ return sum / maxamp;
}
}
/* The fractal_noise_[1-4] functions are all exactly the same except for the input type. */
-ccl_device_noinline float fractal_noise_2d(float2 p, float octaves)
+ccl_device_noinline float fractal_noise_2d(float2 p, float octaves, float roughness)
{
float fscale = 1.0f;
float amp = 1.0f;
+ float maxamp = 0.0f;
float sum = 0.0f;
octaves = clamp(octaves, 0.0f, 16.0f);
int n = float_to_int(octaves);
for (int i = 0; i <= n; i++) {
float t = noise_2d(fscale * p);
sum += t * amp;
- amp *= 0.5f;
+ maxamp += amp;
+ amp *= clamp(roughness, 0.0f, 1.0f);
fscale *= 2.0f;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
float t = noise_2d(fscale * p);
float sum2 = sum + t * amp;
- sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
- sum2 *= ((float)(1 << (n + 1)) / (float)((1 << (n + 2)) - 1));
+ sum /= maxamp;
+ sum2 /= maxamp + amp;
return (1.0f - rmd) * sum + rmd * sum2;
}
else {
- sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
- return sum;
+ return sum / maxamp;
}
}
/* The fractal_noise_[1-4] functions are all exactly the same except for the input type. */
-ccl_device_noinline float fractal_noise_3d(float3 p, float octaves)
+ccl_device_noinline float fractal_noise_3d(float3 p, float octaves, float roughness)
{
float fscale = 1.0f;
float amp = 1.0f;
+ float maxamp = 0.0f;
float sum = 0.0f;
octaves = clamp(octaves, 0.0f, 16.0f);
int n = float_to_int(octaves);
for (int i = 0; i <= n; i++) {
float t = noise_3d(fscale * p);
sum += t * amp;
- amp *= 0.5f;
+ maxamp += amp;
+ amp *= clamp(roughness, 0.0f, 1.0f);
fscale *= 2.0f;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
float t = noise_3d(fscale * p);
float sum2 = sum + t * amp;
- sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
- sum2 *= ((float)(1 << (n + 1)) / (float)((1 << (n + 2)) - 1));
+ sum /= maxamp;
+ sum2 /= maxamp + amp;
return (1.0f - rmd) * sum + rmd * sum2;
}
else {
- sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
- return sum;
+ return sum / maxamp;
}
}
/* The fractal_noise_[1-4] functions are all exactly the same except for the input type. */
-ccl_device_noinline float fractal_noise_4d(float4 p, float octaves)
+ccl_device_noinline float fractal_noise_4d(float4 p, float octaves, float roughness)
{
float fscale = 1.0f;
float amp = 1.0f;
+ float maxamp = 0.0f;
float sum = 0.0f;
octaves = clamp(octaves, 0.0f, 16.0f);
int n = float_to_int(octaves);
for (int i = 0; i <= n; i++) {
float t = noise_4d(fscale * p);
sum += t * amp;
- amp *= 0.5f;
+ maxamp += amp;
+ amp *= clamp(roughness, 0.0f, 1.0f);
fscale *= 2.0f;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
float t = noise_4d(fscale * p);
float sum2 = sum + t * amp;
- sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
- sum2 *= ((float)(1 << (n + 1)) / (float)((1 << (n + 2)) - 1));
+ sum /= maxamp;
+ sum2 /= maxamp + amp;
return (1.0f - rmd) * sum + rmd * sum2;
}
else {
- sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
- return sum;
+ return sum / maxamp;
}
}
diff --git a/intern/cycles/kernel/svm/svm_noisetex.h b/intern/cycles/kernel/svm/svm_noisetex.h
index 12884c6cb25..920dd7d9d02 100644
--- a/intern/cycles/kernel/svm/svm_noisetex.h
+++ b/intern/cycles/kernel/svm/svm_noisetex.h
@@ -50,24 +50,34 @@ ccl_device_inline float4 random_float4_offset(float seed)
100.0f + hash_float2_to_float(make_float2(seed, 3.0f)) * 100.0f);
}
-ccl_device void noise_texture_1d(
- float co, float detail, float distortion, bool color_is_needed, float *value, float3 *color)
+ccl_device void noise_texture_1d(float co,
+ float detail,
+ float roughness,
+ float distortion,
+ bool color_is_needed,
+ float *value,
+ float3 *color)
{
float p = co;
if (distortion != 0.0f) {
p += snoise_1d(p + random_float_offset(0.0f)) * distortion;
}
- *value = fractal_noise_1d(p, detail);
+ *value = fractal_noise_1d(p, detail, roughness);
if (color_is_needed) {
*color = make_float3(*value,
- fractal_noise_1d(p + random_float_offset(1.0f), detail),
- fractal_noise_1d(p + random_float_offset(2.0f), detail));
+ fractal_noise_1d(p + random_float_offset(1.0f), detail, roughness),
+ fractal_noise_1d(p + random_float_offset(2.0f), detail, roughness));
}
}
-ccl_device void noise_texture_2d(
- float2 co, float detail, float distortion, bool color_is_needed, float *value, float3 *color)
+ccl_device void noise_texture_2d(float2 co,
+ float detail,
+ float roughness,
+ float distortion,
+ bool color_is_needed,
+ float *value,
+ float3 *color)
{
float2 p = co;
if (distortion != 0.0f) {
@@ -75,16 +85,21 @@ ccl_device void noise_texture_2d(
snoise_2d(p + random_float2_offset(1.0f)) * distortion);
}
- *value = fractal_noise_2d(p, detail);
+ *value = fractal_noise_2d(p, detail, roughness);
if (color_is_needed) {
*color = make_float3(*value,
- fractal_noise_2d(p + random_float2_offset(2.0f), detail),
- fractal_noise_2d(p + random_float2_offset(3.0f), detail));
+ fractal_noise_2d(p + random_float2_offset(2.0f), detail, roughness),
+ fractal_noise_2d(p + random_float2_offset(3.0f), detail, roughness));
}
}
-ccl_device void noise_texture_3d(
- float3 co, float detail, float distortion, bool color_is_needed, float *value, float3 *color)
+ccl_device void noise_texture_3d(float3 co,
+ float detail,
+ float roughness,
+ float distortion,
+ bool color_is_needed,
+ float *value,
+ float3 *color)
{
float3 p = co;
if (distortion != 0.0f) {
@@ -93,16 +108,21 @@ ccl_device void noise_texture_3d(
snoise_3d(p + random_float3_offset(2.0f)) * distortion);
}
- *value = fractal_noise_3d(p, detail);
+ *value = fractal_noise_3d(p, detail, roughness);
if (color_is_needed) {
*color = make_float3(*value,
- fractal_noise_3d(p + random_float3_offset(3.0f), detail),
- fractal_noise_3d(p + random_float3_offset(4.0f), detail));
+ fractal_noise_3d(p + random_float3_offset(3.0f), detail, roughness),
+ fractal_noise_3d(p + random_float3_offset(4.0f), detail, roughness));
}
}
-ccl_device void noise_texture_4d(
- float4 co, float detail, float distortion, bool color_is_needed, float *value, float3 *color)
+ccl_device void noise_texture_4d(float4 co,
+ float detail,
+ float roughness,
+ float distortion,
+ bool color_is_needed,
+ float *value,
+ float3 *color)
{
float4 p = co;
if (distortion != 0.0f) {
@@ -112,11 +132,11 @@ ccl_device void noise_texture_4d(
snoise_4d(p + random_float4_offset(3.0f)) * distortion);
}
- *value = fractal_noise_4d(p, detail);
+ *value = fractal_noise_4d(p, detail, roughness);
if (color_is_needed) {
*color = make_float3(*value,
- fractal_noise_4d(p + random_float4_offset(4.0f), detail),
- fractal_noise_4d(p + random_float4_offset(5.0f), detail));
+ fractal_noise_4d(p + random_float4_offset(4.0f), detail, roughness),
+ fractal_noise_4d(p + random_float4_offset(5.0f), detail, roughness));
}
}
@@ -128,21 +148,27 @@ ccl_device void svm_node_tex_noise(KernelGlobals *kg,
uint offsets2,
int *offset)
{
- uint vector_stack_offset, w_stack_offset, scale_stack_offset, detail_stack_offset;
- uint distortion_stack_offset, value_stack_offset, color_stack_offset;
+ uint vector_stack_offset, w_stack_offset, scale_stack_offset;
+ uint detail_stack_offset, roughness_stack_offset, distortion_stack_offset;
+ uint value_stack_offset, color_stack_offset;
svm_unpack_node_uchar4(
offsets1, &vector_stack_offset, &w_stack_offset, &scale_stack_offset, &detail_stack_offset);
- svm_unpack_node_uchar3(
- offsets2, &distortion_stack_offset, &value_stack_offset, &color_stack_offset);
+ svm_unpack_node_uchar4(offsets2,
+ &roughness_stack_offset,
+ &distortion_stack_offset,
+ &value_stack_offset,
+ &color_stack_offset);
- uint4 defaults = read_node(kg, offset);
+ uint4 defaults1 = read_node(kg, offset);
+ uint4 defaults2 = read_node(kg, offset);
float3 vector = stack_load_float3(stack, vector_stack_offset);
- float w = stack_load_float_default(stack, w_stack_offset, defaults.x);
- float scale = stack_load_float_default(stack, scale_stack_offset, defaults.y);
- float detail = stack_load_float_default(stack, detail_stack_offset, defaults.z);
- float distortion = stack_load_float_default(stack, distortion_stack_offset, defaults.w);
+ float w = stack_load_float_default(stack, w_stack_offset, defaults1.x);
+ float scale = stack_load_float_default(stack, scale_stack_offset, defaults1.y);
+ float detail = stack_load_float_default(stack, detail_stack_offset, defaults1.z);
+ float roughness = stack_load_float_default(stack, roughness_stack_offset, defaults1.w);
+ float distortion = stack_load_float_default(stack, distortion_stack_offset, defaults2.x);
vector *= scale;
w *= scale;
@@ -151,11 +177,13 @@ ccl_device void svm_node_tex_noise(KernelGlobals *kg,
float3 color;
switch (dimensions) {
case 1:
- noise_texture_1d(w, detail, distortion, stack_valid(color_stack_offset), &value, &color);
+ noise_texture_1d(
+ w, detail, roughness, distortion, stack_valid(color_stack_offset), &value, &color);
break;
case 2:
noise_texture_2d(make_float2(vector.x, vector.y),
detail,
+ roughness,
distortion,
stack_valid(color_stack_offset),
&value,
@@ -163,11 +191,12 @@ ccl_device void svm_node_tex_noise(KernelGlobals *kg,
break;
case 3:
noise_texture_3d(
- vector, detail, distortion, stack_valid(color_stack_offset), &value, &color);
+ vector, detail, roughness, distortion, stack_valid(color_stack_offset), &value, &color);
break;
case 4:
noise_texture_4d(make_float4(vector.x, vector.y, vector.z, w),
detail,
+ roughness,
distortion,
stack_valid(color_stack_offset),
&value,
diff --git a/intern/cycles/kernel/svm/svm_wave.h b/intern/cycles/kernel/svm/svm_wave.h
index 64102535f7d..c4763475b47 100644
--- a/intern/cycles/kernel/svm/svm_wave.h
+++ b/intern/cycles/kernel/svm/svm_wave.h
@@ -23,9 +23,10 @@ ccl_device_noinline_cpu float svm_wave(NodeWaveType type,
NodeWaveRingsDirection rings_dir,
NodeWaveProfile profile,
float3 p,
- float detail,
float distortion,
+ float detail,
float dscale,
+ float droughness,
float phase)
{
/* Prevent precision issues on unit coordinates. */
@@ -66,7 +67,7 @@ ccl_device_noinline_cpu float svm_wave(NodeWaveType type,
n += phase;
if (distortion != 0.0f)
- n += distortion * (fractal_noise_3d(p * dscale, detail) * 2.0f - 1.0f);
+ n += distortion * (fractal_noise_3d(p * dscale, detail, droughness) * 2.0f - 1.0f);
if (profile == NODE_WAVE_PROFILE_SIN) {
return 0.5f + 0.5f * sinf(n - M_PI_2_F);
@@ -84,35 +85,40 @@ ccl_device_noinline_cpu float svm_wave(NodeWaveType type,
ccl_device void svm_node_tex_wave(
KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset)
{
- uint4 defaults1 = read_node(kg, offset);
- uint4 defaults2 = read_node(kg, offset);
+ uint4 node2 = read_node(kg, offset);
+ uint4 node3 = read_node(kg, offset);
/* RNA properties */
uint type_offset, bands_dir_offset, rings_dir_offset, profile_offset;
/* Inputs, Outputs */
- uint co_offset, scale_offset, distortion_offset, detail_offset, dscale_offset, phase_offset;
+ uint co_offset, scale_offset, distortion_offset, detail_offset, dscale_offset, droughness_offset,
+ phase_offset;
uint color_offset, fac_offset;
svm_unpack_node_uchar4(
node.y, &type_offset, &bands_dir_offset, &rings_dir_offset, &profile_offset);
- svm_unpack_node_uchar4(node.z, &co_offset, &scale_offset, &distortion_offset, &detail_offset);
- svm_unpack_node_uchar4(node.w, &dscale_offset, &phase_offset, &color_offset, &fac_offset);
+ svm_unpack_node_uchar3(node.z, &co_offset, &scale_offset, &distortion_offset);
+ svm_unpack_node_uchar4(
+ node.w, &detail_offset, &dscale_offset, &droughness_offset, &phase_offset);
+ svm_unpack_node_uchar2(node2.x, &color_offset, &fac_offset);
float3 co = stack_load_float3(stack, co_offset);
- float scale = stack_load_float_default(stack, scale_offset, defaults1.x);
- float detail = stack_load_float_default(stack, detail_offset, defaults1.y);
- float distortion = stack_load_float_default(stack, distortion_offset, defaults1.z);
- float dscale = stack_load_float_default(stack, dscale_offset, defaults1.w);
- float phase = stack_load_float_default(stack, phase_offset, defaults2.x);
+ float scale = stack_load_float_default(stack, scale_offset, node2.y);
+ float distortion = stack_load_float_default(stack, distortion_offset, node2.z);
+ float detail = stack_load_float_default(stack, detail_offset, node2.w);
+ float dscale = stack_load_float_default(stack, dscale_offset, node3.x);
+ float droughness = stack_load_float_default(stack, droughness_offset, node3.y);
+ float phase = stack_load_float_default(stack, phase_offset, node3.z);
float f = svm_wave((NodeWaveType)type_offset,
(NodeWaveBandsDirection)bands_dir_offset,
(NodeWaveRingsDirection)rings_dir_offset,
(NodeWaveProfile)profile_offset,
co * scale,
- detail,
distortion,
+ detail,
dscale,
+ droughness,
phase);
if (stack_valid(fac_offset))