2022-02-11 13:53:21 +01:00
|
|
|
/* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
* Copyright 2011-2022 Blender Foundation */
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
|
|
/* Brick */
|
|
|
|
|
|
2019-08-21 12:03:32 +02:00
|
|
|
ccl_device_inline float brick_noise(uint n) /* fast integer noise */
|
2012-09-04 13:29:07 +00:00
|
|
|
{
|
2017-11-21 00:38:02 -05:00
|
|
|
uint nn;
|
2015-09-18 17:28:40 +05:00
|
|
|
n = (n + 1013) & 0x7fffffff;
|
2012-09-04 13:29:07 +00:00
|
|
|
n = (n >> 13) ^ n;
|
|
|
|
|
nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
|
|
|
|
|
return 0.5f * ((float)nn / 1073741824.0f);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-22 17:36:54 +02:00
|
|
|
ccl_device_noinline_cpu float2 svm_brick(float3 p,
|
|
|
|
|
float mortar_size,
|
|
|
|
|
float mortar_smooth,
|
|
|
|
|
float bias,
|
|
|
|
|
float brick_width,
|
|
|
|
|
float row_height,
|
|
|
|
|
float offset_amount,
|
|
|
|
|
int offset_frequency,
|
|
|
|
|
float squash_amount,
|
|
|
|
|
int squash_frequency)
|
2014-01-13 20:40:13 +01:00
|
|
|
{
|
2012-09-04 13:29:07 +00:00
|
|
|
int bricknum, rownum;
|
|
|
|
|
float offset = 0.0f;
|
|
|
|
|
float x, y;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-06-07 16:06:17 +00:00
|
|
|
rownum = floor_to_int(p.y / row_height);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
if (offset_frequency && squash_frequency) {
|
2013-06-26 23:08:18 +00:00
|
|
|
brick_width *= (rownum % squash_frequency) ? 1.0f : squash_amount; /* squash */
|
|
|
|
|
offset = (rownum % offset_frequency) ? 0.0f : (brick_width * offset_amount); /* offset */
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-06-07 16:06:17 +00:00
|
|
|
bricknum = floor_to_int((p.x + offset) / brick_width);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
x = (p.x + offset) - brick_width * bricknum;
|
|
|
|
|
y = p.y - row_height * rownum;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-27 13:28:13 +02:00
|
|
|
float tint = saturatef((brick_noise((rownum << 16) + (bricknum & 0xFFFF)) + bias));
|
2016-10-30 01:33:10 +02:00
|
|
|
float min_dist = min(min(x, y), min(brick_width - x, row_height - y));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-10-30 01:33:10 +02:00
|
|
|
float mortar;
|
|
|
|
|
if (min_dist >= mortar_size) {
|
|
|
|
|
mortar = 0.0f;
|
|
|
|
|
}
|
|
|
|
|
else if (mortar_smooth == 0.0f) {
|
|
|
|
|
mortar = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
min_dist = 1.0f - min_dist / mortar_size;
|
|
|
|
|
mortar = (min_dist < mortar_smooth) ? smoothstepf(min_dist / mortar_smooth) : 1.0f;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-10-30 01:33:10 +02:00
|
|
|
return make_float2(tint, mortar);
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_noinline int svm_node_tex_brick(
|
|
|
|
|
KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, uint4 node, int offset)
|
2018-07-06 10:17:58 +02: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 17:59:20 +02:00
|
|
|
uint4 node2 = read_node(kg, &offset);
|
|
|
|
|
uint4 node3 = read_node(kg, &offset);
|
|
|
|
|
uint4 node4 = read_node(kg, &offset);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* Input and Output Sockets */
|
|
|
|
|
uint co_offset, color1_offset, color2_offset, mortar_offset, scale_offset;
|
|
|
|
|
uint mortar_size_offset, bias_offset, brick_width_offset, row_height_offset;
|
2016-10-30 01:33:10 +02:00
|
|
|
uint color_offset, fac_offset, mortar_smooth_offset;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* RNA properties */
|
|
|
|
|
uint offset_frequency, squash_frequency;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar4(node.y, &co_offset, &color1_offset, &color2_offset, &mortar_offset);
|
|
|
|
|
svm_unpack_node_uchar4(
|
2012-09-04 13:29:07 +00:00
|
|
|
node.z, &scale_offset, &mortar_size_offset, &bias_offset, &brick_width_offset);
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar4(
|
2016-10-30 01:33:10 +02:00
|
|
|
node.w, &row_height_offset, &color_offset, &fac_offset, &mortar_smooth_offset);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar2(node2.x, &offset_frequency, &squash_frequency);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
float3 co = stack_load_float3(stack, co_offset);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
float3 color1 = stack_load_float3(stack, color1_offset);
|
|
|
|
|
float3 color2 = stack_load_float3(stack, color2_offset);
|
|
|
|
|
float3 mortar = stack_load_float3(stack, mortar_offset);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
float scale = stack_load_float_default(stack, scale_offset, node2.y);
|
|
|
|
|
float mortar_size = stack_load_float_default(stack, mortar_size_offset, node2.z);
|
2016-10-30 01:33:10 +02:00
|
|
|
float mortar_smooth = stack_load_float_default(stack, mortar_smooth_offset, node4.x);
|
2012-09-04 13:29:07 +00:00
|
|
|
float bias = stack_load_float_default(stack, bias_offset, node2.w);
|
|
|
|
|
float brick_width = stack_load_float_default(stack, brick_width_offset, node3.x);
|
|
|
|
|
float row_height = stack_load_float_default(stack, row_height_offset, node3.y);
|
|
|
|
|
float offset_amount = __int_as_float(node3.z);
|
|
|
|
|
float squash_amount = __int_as_float(node3.w);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-10-30 01:33:10 +02:00
|
|
|
float2 f2 = svm_brick(co * scale,
|
|
|
|
|
mortar_size,
|
|
|
|
|
mortar_smooth,
|
|
|
|
|
bias,
|
|
|
|
|
brick_width,
|
|
|
|
|
row_height,
|
2012-11-30 07:27:17 +00:00
|
|
|
offset_amount,
|
|
|
|
|
offset_frequency,
|
|
|
|
|
squash_amount,
|
|
|
|
|
squash_frequency);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-30 07:27:17 +00:00
|
|
|
float tint = f2.x;
|
|
|
|
|
float f = f2.y;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
if (f != 1.0f) {
|
|
|
|
|
float facm = 1.0f - tint;
|
2015-02-23 16:49:17 +01:00
|
|
|
color1 = facm * color1 + tint * color2;
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
if (stack_valid(color_offset))
|
2016-10-30 16:25:35 +01:00
|
|
|
stack_store_float3(stack, color_offset, color1 * (1.0f - f) + mortar * f);
|
2012-09-04 13:29:07 +00:00
|
|
|
if (stack_valid(fac_offset))
|
|
|
|
|
stack_store_float(stack, fac_offset, f);
|
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 17:59:20 +02:00
|
|
|
return offset;
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|