2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 01:50:24 +00:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2019-09-04 15:54:32 +00:00
|
|
|
/* The following offset functions generate random offsets to be added to texture
|
|
|
|
* coordinates to act as a seed since the noise functions don't have seed values.
|
|
|
|
* A seed value is needed for generating distortion textures and color outputs.
|
|
|
|
* The offset's components are in the range [100, 200], not too high to cause
|
2021-05-21 12:19:46 +00:00
|
|
|
* bad precision and not too small to be noticeable. We use float seed because
|
2019-09-04 15:54:32 +00:00
|
|
|
* OSL only support float hashes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ccl_device_inline float random_float_offset(float seed)
|
|
|
|
{
|
|
|
|
return 100.0f + hash_float_to_float(seed) * 100.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
ccl_device_inline float2 random_float2_offset(float seed)
|
|
|
|
{
|
|
|
|
return make_float2(100.0f + hash_float2_to_float(make_float2(seed, 0.0f)) * 100.0f,
|
|
|
|
100.0f + hash_float2_to_float(make_float2(seed, 1.0f)) * 100.0f);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-09-04 15:54:32 +00:00
|
|
|
ccl_device_inline float3 random_float3_offset(float seed)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-09-04 15:54:32 +00:00
|
|
|
return make_float3(100.0f + hash_float2_to_float(make_float2(seed, 0.0f)) * 100.0f,
|
|
|
|
100.0f + hash_float2_to_float(make_float2(seed, 1.0f)) * 100.0f,
|
|
|
|
100.0f + hash_float2_to_float(make_float2(seed, 2.0f)) * 100.0f);
|
|
|
|
}
|
2011-11-06 21:05:58 +00:00
|
|
|
|
2019-09-04 15:54:32 +00:00
|
|
|
ccl_device_inline float4 random_float4_offset(float seed)
|
|
|
|
{
|
|
|
|
return make_float4(100.0f + hash_float2_to_float(make_float2(seed, 0.0f)) * 100.0f,
|
|
|
|
100.0f + hash_float2_to_float(make_float2(seed, 1.0f)) * 100.0f,
|
|
|
|
100.0f + hash_float2_to_float(make_float2(seed, 2.0f)) * 100.0f,
|
|
|
|
100.0f + hash_float2_to_float(make_float2(seed, 3.0f)) * 100.0f);
|
|
|
|
}
|
2011-11-06 21:05:58 +00:00
|
|
|
|
2020-03-26 13:43:53 +00:00
|
|
|
ccl_device void noise_texture_1d(float co,
|
|
|
|
float detail,
|
|
|
|
float roughness,
|
|
|
|
float distortion,
|
|
|
|
bool color_is_needed,
|
|
|
|
float *value,
|
|
|
|
float3 *color)
|
2019-09-04 15:54:32 +00:00
|
|
|
{
|
|
|
|
float p = co;
|
|
|
|
if (distortion != 0.0f) {
|
2019-12-05 21:07:43 +00:00
|
|
|
p += snoise_1d(p + random_float_offset(0.0f)) * distortion;
|
2019-09-04 15:54:32 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 13:43:53 +00:00
|
|
|
*value = fractal_noise_1d(p, detail, roughness);
|
2019-09-04 15:54:32 +00:00
|
|
|
if (color_is_needed) {
|
|
|
|
*color = make_float3(*value,
|
2020-03-26 13:43:53 +00:00
|
|
|
fractal_noise_1d(p + random_float_offset(1.0f), detail, roughness),
|
|
|
|
fractal_noise_1d(p + random_float_offset(2.0f), detail, roughness));
|
2019-09-04 15:54:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 13:43:53 +00:00
|
|
|
ccl_device void noise_texture_2d(float2 co,
|
|
|
|
float detail,
|
|
|
|
float roughness,
|
|
|
|
float distortion,
|
|
|
|
bool color_is_needed,
|
|
|
|
float *value,
|
|
|
|
float3 *color)
|
2019-09-04 15:54:32 +00:00
|
|
|
{
|
|
|
|
float2 p = co;
|
|
|
|
if (distortion != 0.0f) {
|
2019-12-05 21:07:43 +00:00
|
|
|
p += make_float2(snoise_2d(p + random_float2_offset(0.0f)) * distortion,
|
|
|
|
snoise_2d(p + random_float2_offset(1.0f)) * distortion);
|
2019-09-04 15:54:32 +00:00
|
|
|
}
|
2011-11-06 21:05:58 +00:00
|
|
|
|
2020-03-26 13:43:53 +00:00
|
|
|
*value = fractal_noise_2d(p, detail, roughness);
|
2019-09-04 15:54:32 +00:00
|
|
|
if (color_is_needed) {
|
|
|
|
*color = make_float3(*value,
|
2020-03-26 13:43:53 +00:00
|
|
|
fractal_noise_2d(p + random_float2_offset(2.0f), detail, roughness),
|
|
|
|
fractal_noise_2d(p + random_float2_offset(3.0f), detail, roughness));
|
2019-09-04 15:54:32 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2020-03-26 13:43:53 +00:00
|
|
|
ccl_device void noise_texture_3d(float3 co,
|
|
|
|
float detail,
|
|
|
|
float roughness,
|
|
|
|
float distortion,
|
|
|
|
bool color_is_needed,
|
|
|
|
float *value,
|
|
|
|
float3 *color)
|
2019-09-04 15:54:32 +00:00
|
|
|
{
|
|
|
|
float3 p = co;
|
2017-02-21 12:24:33 +00:00
|
|
|
if (distortion != 0.0f) {
|
2019-12-05 21:07:43 +00:00
|
|
|
p += make_float3(snoise_3d(p + random_float3_offset(0.0f)) * distortion,
|
|
|
|
snoise_3d(p + random_float3_offset(1.0f)) * distortion,
|
|
|
|
snoise_3d(p + random_float3_offset(2.0f)) * distortion);
|
2019-09-04 15:54:32 +00:00
|
|
|
}
|
2017-02-21 12:24:33 +00:00
|
|
|
|
2020-03-26 13:43:53 +00:00
|
|
|
*value = fractal_noise_3d(p, detail, roughness);
|
2019-09-04 15:54:32 +00:00
|
|
|
if (color_is_needed) {
|
|
|
|
*color = make_float3(*value,
|
2020-03-26 13:43:53 +00:00
|
|
|
fractal_noise_3d(p + random_float3_offset(3.0f), detail, roughness),
|
|
|
|
fractal_noise_3d(p + random_float3_offset(4.0f), detail, roughness));
|
2019-09-04 15:54:32 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-06 21:05:58 +00:00
|
|
|
|
2020-03-26 13:43:53 +00:00
|
|
|
ccl_device void noise_texture_4d(float4 co,
|
|
|
|
float detail,
|
|
|
|
float roughness,
|
|
|
|
float distortion,
|
|
|
|
bool color_is_needed,
|
|
|
|
float *value,
|
|
|
|
float3 *color)
|
2019-09-04 15:54:32 +00:00
|
|
|
{
|
|
|
|
float4 p = co;
|
|
|
|
if (distortion != 0.0f) {
|
2019-12-05 21:07:43 +00:00
|
|
|
p += make_float4(snoise_4d(p + random_float4_offset(0.0f)) * distortion,
|
|
|
|
snoise_4d(p + random_float4_offset(1.0f)) * distortion,
|
|
|
|
snoise_4d(p + random_float4_offset(2.0f)) * distortion,
|
|
|
|
snoise_4d(p + random_float4_offset(3.0f)) * distortion);
|
2017-02-21 12:24:33 +00:00
|
|
|
}
|
2011-11-06 21:05:58 +00:00
|
|
|
|
2020-03-26 13:43:53 +00:00
|
|
|
*value = fractal_noise_4d(p, detail, roughness);
|
2019-09-04 15:54:32 +00:00
|
|
|
if (color_is_needed) {
|
|
|
|
*color = make_float3(*value,
|
2020-03-26 13:43:53 +00:00
|
|
|
fractal_noise_4d(p + random_float4_offset(4.0f), detail, roughness),
|
|
|
|
fractal_noise_4d(p + random_float4_offset(5.0f), detail, roughness));
|
2019-09-04 15:54:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
ccl_device_noinline int svm_node_tex_noise(const KernelGlobals *kg,
|
|
|
|
ShaderData *sd,
|
|
|
|
float *stack,
|
|
|
|
uint dimensions,
|
|
|
|
uint offsets1,
|
|
|
|
uint offsets2,
|
|
|
|
int offset)
|
2019-09-04 15:54:32 +00:00
|
|
|
{
|
2020-03-26 13:43:53 +00:00
|
|
|
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;
|
2019-09-04 15:54:32 +00:00
|
|
|
|
|
|
|
svm_unpack_node_uchar4(
|
|
|
|
offsets1, &vector_stack_offset, &w_stack_offset, &scale_stack_offset, &detail_stack_offset);
|
2020-03-26 13:43:53 +00:00
|
|
|
svm_unpack_node_uchar4(offsets2,
|
|
|
|
&roughness_stack_offset,
|
|
|
|
&distortion_stack_offset,
|
|
|
|
&value_stack_offset,
|
|
|
|
&color_stack_offset);
|
2019-09-04 15:54:32 +00:00
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
uint4 defaults1 = read_node(kg, &offset);
|
|
|
|
uint4 defaults2 = read_node(kg, &offset);
|
2019-09-04 15:54:32 +00:00
|
|
|
|
|
|
|
float3 vector = stack_load_float3(stack, vector_stack_offset);
|
2020-03-26 13:43:53 +00:00
|
|
|
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);
|
2019-09-04 15:54:32 +00:00
|
|
|
|
|
|
|
vector *= scale;
|
|
|
|
w *= scale;
|
|
|
|
|
|
|
|
float value;
|
|
|
|
float3 color;
|
|
|
|
switch (dimensions) {
|
|
|
|
case 1:
|
2020-03-26 13:43:53 +00:00
|
|
|
noise_texture_1d(
|
|
|
|
w, detail, roughness, distortion, stack_valid(color_stack_offset), &value, &color);
|
2019-09-04 15:54:32 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
noise_texture_2d(make_float2(vector.x, vector.y),
|
|
|
|
detail,
|
2020-03-26 13:43:53 +00:00
|
|
|
roughness,
|
2019-09-04 15:54:32 +00:00
|
|
|
distortion,
|
|
|
|
stack_valid(color_stack_offset),
|
|
|
|
&value,
|
|
|
|
&color);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
noise_texture_3d(
|
2020-03-26 13:43:53 +00:00
|
|
|
vector, detail, roughness, distortion, stack_valid(color_stack_offset), &value, &color);
|
2019-09-04 15:54:32 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
noise_texture_4d(make_float4(vector.x, vector.y, vector.z, w),
|
|
|
|
detail,
|
2020-03-26 13:43:53 +00:00
|
|
|
roughness,
|
2019-09-04 15:54:32 +00:00
|
|
|
distortion,
|
|
|
|
stack_valid(color_stack_offset),
|
|
|
|
&value,
|
|
|
|
&color);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
kernel_assert(0);
|
|
|
|
}
|
2011-11-06 21:05:58 +00:00
|
|
|
|
2019-09-04 15:54:32 +00:00
|
|
|
if (stack_valid(value_stack_offset)) {
|
|
|
|
stack_store_float(stack, value_stack_offset, value);
|
2017-02-21 12:24:33 +00:00
|
|
|
}
|
2019-09-04 15:54:32 +00:00
|
|
|
if (stack_valid(color_stack_offset)) {
|
|
|
|
stack_store_float3(stack, color_stack_offset, color);
|
2017-02-21 12:24:33 +00:00
|
|
|
}
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
return offset;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|