2022-02-11 13:53:21 +01:00
|
|
|
/* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
* Copyright 2011-2022 Blender Foundation */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device float4 svm_image_texture(KernelGlobals kg, int id, float x, float y, uint flags)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
if (id == -1) {
|
|
|
|
|
return make_float4(
|
|
|
|
|
TEX_IMAGE_MISSING_R, TEX_IMAGE_MISSING_G, TEX_IMAGE_MISSING_B, TEX_IMAGE_MISSING_A);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-22 23:38:42 +02:00
|
|
|
float4 r = kernel_tex_image_interp(kg, id, x, y);
|
2017-05-03 11:22:27 +02:00
|
|
|
const float alpha = r.w;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-19 02:46:24 +02:00
|
|
|
if ((flags & NODE_IMAGE_ALPHA_UNASSOCIATE) && alpha != 1.0f && alpha != 0.0f) {
|
2017-05-03 11:22:27 +02:00
|
|
|
r /= alpha;
|
2014-02-10 17:19:26 +04:00
|
|
|
r.w = alpha;
|
2014-01-13 18:21:34 +04:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-19 02:46:24 +02:00
|
|
|
if (flags & NODE_IMAGE_COMPRESS_AS_SRGB) {
|
2018-06-14 17:48:19 +02:00
|
|
|
r = color_srgb_to_linear_v4(r);
|
2014-01-13 18:21:34 +04:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 16:23:34 +11:00
|
|
|
/* Remap coordinate from 0..1 box to -1..-1 */
|
2015-01-22 00:37:09 +05:00
|
|
|
ccl_device_inline float3 texco_remap_square(float3 co)
|
|
|
|
|
{
|
|
|
|
|
return (co - make_float3(0.5f, 0.5f, 0.5f)) * 2.0f;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_noinline int svm_node_tex_image(
|
|
|
|
|
KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, uint4 node, int offset)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-05-19 02:46:24 +02:00
|
|
|
uint co_offset, out_offset, alpha_offset, flags;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar4(node.z, &co_offset, &out_offset, &alpha_offset, &flags);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
float3 co = stack_load_float3(stack, co_offset);
|
2015-02-19 12:52:48 +05:00
|
|
|
float2 tex_co;
|
2015-01-21 22:44:30 +05:00
|
|
|
if (node.w == NODE_IMAGE_PROJ_SPHERE) {
|
2015-01-22 00:37:09 +05:00
|
|
|
co = texco_remap_square(co);
|
2015-02-19 12:52:48 +05:00
|
|
|
tex_co = map_to_sphere(co);
|
2015-01-21 22:44:30 +05:00
|
|
|
}
|
2015-01-22 00:37:09 +05:00
|
|
|
else if (node.w == NODE_IMAGE_PROJ_TUBE) {
|
|
|
|
|
co = texco_remap_square(co);
|
2015-02-19 12:52:48 +05:00
|
|
|
tex_co = map_to_tube(co);
|
2015-01-22 00:37:09 +05:00
|
|
|
}
|
2015-02-19 12:52:48 +05:00
|
|
|
else {
|
|
|
|
|
tex_co = make_float2(co.x, co.y);
|
|
|
|
|
}
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
|
|
|
|
|
/* TODO(lukas): Consider moving tile information out of the SVM node.
|
|
|
|
|
* TextureInfo seems a reasonable candidate. */
|
|
|
|
|
int id = -1;
|
|
|
|
|
int num_nodes = (int)node.y;
|
|
|
|
|
if (num_nodes > 0) {
|
|
|
|
|
/* Remember the offset of the node following the tile nodes. */
|
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
|
|
|
int next_offset = offset + num_nodes;
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
|
|
|
|
|
/* Find the tile that the UV lies in. */
|
|
|
|
|
int tx = (int)tex_co.x;
|
|
|
|
|
int ty = (int)tex_co.y;
|
|
|
|
|
|
|
|
|
|
/* Check that we're within a legitimate tile. */
|
|
|
|
|
if (tx >= 0 && ty >= 0 && tx < 10) {
|
|
|
|
|
int tile = 1001 + 10 * ty + tx;
|
|
|
|
|
|
|
|
|
|
/* Find the index of the tile. */
|
|
|
|
|
for (int i = 0; i < num_nodes; i++) {
|
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 tile_node = read_node(kg, &offset);
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
if (tile_node.x == tile) {
|
|
|
|
|
id = tile_node.y;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (tile_node.z == tile) {
|
|
|
|
|
id = tile_node.w;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If we found the tile, offset the UVs to be relative to it. */
|
|
|
|
|
if (id != -1) {
|
|
|
|
|
tex_co.x -= tx;
|
|
|
|
|
tex_co.y -= ty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Skip over the remaining nodes. */
|
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
|
|
|
offset = next_offset;
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
id = -num_nodes;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-19 02:46:24 +02:00
|
|
|
float4 f = svm_image_texture(kg, id, tex_co.x, tex_co.y, flags);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
if (stack_valid(out_offset))
|
|
|
|
|
stack_store_float3(stack, out_offset, make_float3(f.x, f.y, f.z));
|
|
|
|
|
if (stack_valid(alpha_offset))
|
|
|
|
|
stack_store_float(stack, alpha_offset, f.w);
|
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
|
|
|
}
|
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_noinline void svm_node_tex_image_box(KernelGlobals kg,
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_private ShaderData *sd,
|
|
|
|
|
ccl_private float *stack,
|
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 node)
|
2012-09-04 13:29:07 +00:00
|
|
|
{
|
|
|
|
|
/* get object space normal */
|
2017-02-16 06:24:13 -05:00
|
|
|
float3 N = sd->N;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-02-16 06:24:13 -05:00
|
|
|
N = sd->N;
|
2016-11-03 03:08:14 +01:00
|
|
|
object_inverse_normal_transform(kg, sd, &N);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* project from direction vector to barycentric coordinates in triangles */
|
2017-09-05 18:11:13 +02:00
|
|
|
float3 signed_N = N;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
N.x = fabsf(N.x);
|
|
|
|
|
N.y = fabsf(N.y);
|
|
|
|
|
N.z = fabsf(N.z);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
N /= (N.x + N.y + N.z);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* basic idea is to think of this as a triangle, each corner representing
|
|
|
|
|
* one of the 3 faces of the cube. in the corners we have single textures,
|
|
|
|
|
* in between we blend between two textures, and in the middle we a blend
|
|
|
|
|
* between three textures.
|
|
|
|
|
*
|
2021-10-12 17:52:35 +11:00
|
|
|
* The `Nxyz` values are the barycentric coordinates in an equilateral
|
2012-10-20 15:09:36 +00:00
|
|
|
* triangle, which in case of blending, in the middle has a smaller
|
2012-09-04 13:29:07 +00:00
|
|
|
* equilateral triangle where 3 textures blend. this divides things into
|
2021-10-12 17:52:35 +11:00
|
|
|
* 7 zones, with an if() test for each zone. */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
float3 weight = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
|
float blend = __int_as_float(node.w);
|
|
|
|
|
float limit = 0.5f * (1.0f + blend);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* first test for corners with single texture */
|
|
|
|
|
if (N.x > limit * (N.x + N.y) && N.x > limit * (N.x + N.z)) {
|
|
|
|
|
weight.x = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
else if (N.y > limit * (N.x + N.y) && N.y > limit * (N.y + N.z)) {
|
|
|
|
|
weight.y = 1.0f;
|
2011-05-20 12:26:01 +00:00
|
|
|
}
|
2012-09-04 13:29:07 +00:00
|
|
|
else if (N.z > limit * (N.x + N.z) && N.z > limit * (N.y + N.z)) {
|
|
|
|
|
weight.z = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
else if (blend > 0.0f) {
|
|
|
|
|
/* in case of blending, test for mixes between two textures */
|
|
|
|
|
if (N.z < (1.0f - limit) * (N.y + N.x)) {
|
|
|
|
|
weight.x = N.x / (N.x + N.y);
|
2021-10-27 13:28:13 +02:00
|
|
|
weight.x = saturatef((weight.x - 0.5f * (1.0f - blend)) / blend);
|
2012-09-04 13:29:07 +00:00
|
|
|
weight.y = 1.0f - weight.x;
|
|
|
|
|
}
|
|
|
|
|
else if (N.x < (1.0f - limit) * (N.y + N.z)) {
|
|
|
|
|
weight.y = N.y / (N.y + N.z);
|
2021-10-27 13:28:13 +02:00
|
|
|
weight.y = saturatef((weight.y - 0.5f * (1.0f - blend)) / blend);
|
2012-09-04 13:29:07 +00:00
|
|
|
weight.z = 1.0f - weight.y;
|
|
|
|
|
}
|
|
|
|
|
else if (N.y < (1.0f - limit) * (N.x + N.z)) {
|
|
|
|
|
weight.x = N.x / (N.x + N.z);
|
2021-10-27 13:28:13 +02:00
|
|
|
weight.x = saturatef((weight.x - 0.5f * (1.0f - blend)) / blend);
|
2012-09-04 13:29:07 +00:00
|
|
|
weight.z = 1.0f - weight.x;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* last case, we have a mix between three */
|
|
|
|
|
weight.x = ((2.0f - limit) * N.x + (limit - 1.0f)) / (2.0f * limit - 1.0f);
|
|
|
|
|
weight.y = ((2.0f - limit) * N.y + (limit - 1.0f)) / (2.0f * limit - 1.0f);
|
|
|
|
|
weight.z = ((2.0f - limit) * N.z + (limit - 1.0f)) / (2.0f * limit - 1.0f);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-07 15:48:39 +02:00
|
|
|
else {
|
2021-06-26 21:35:18 +10:00
|
|
|
/* Desperate mode, no valid choice anyway, fallback to one side. */
|
2014-10-07 15:48:39 +02:00
|
|
|
weight.x = 1.0f;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* now fetch textures */
|
2019-05-19 02:46:24 +02:00
|
|
|
uint co_offset, out_offset, alpha_offset, flags;
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar4(node.z, &co_offset, &out_offset, &alpha_offset, &flags);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
float3 co = stack_load_float3(stack, co_offset);
|
|
|
|
|
uint id = node.y;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-23 15:53:10 +01:00
|
|
|
float4 f = zero_float4();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-09-05 18:11:13 +02:00
|
|
|
/* Map so that no textures are flipped, rotation is somewhat arbitrary. */
|
|
|
|
|
if (weight.x > 0.0f) {
|
|
|
|
|
float2 uv = make_float2((signed_N.x < 0.0f) ? 1.0f - co.y : co.y, co.z);
|
2019-05-19 02:46:24 +02:00
|
|
|
f += weight.x * svm_image_texture(kg, id, uv.x, uv.y, flags);
|
2017-09-05 18:11:13 +02:00
|
|
|
}
|
|
|
|
|
if (weight.y > 0.0f) {
|
|
|
|
|
float2 uv = make_float2((signed_N.y > 0.0f) ? 1.0f - co.x : co.x, co.z);
|
2019-05-19 02:46:24 +02:00
|
|
|
f += weight.y * svm_image_texture(kg, id, uv.x, uv.y, flags);
|
2017-09-05 18:11:13 +02:00
|
|
|
}
|
|
|
|
|
if (weight.z > 0.0f) {
|
|
|
|
|
float2 uv = make_float2((signed_N.z > 0.0f) ? 1.0f - co.y : co.y, co.x);
|
2019-05-19 02:46:24 +02:00
|
|
|
f += weight.z * svm_image_texture(kg, id, uv.x, uv.y, flags);
|
2017-09-05 18:11:13 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-09-16 13:14:02 +00:00
|
|
|
if (stack_valid(out_offset))
|
2012-09-04 13:29:07 +00:00
|
|
|
stack_store_float3(stack, out_offset, make_float3(f.x, f.y, f.z));
|
2011-09-16 13:14:02 +00:00
|
|
|
if (stack_valid(alpha_offset))
|
|
|
|
|
stack_store_float(stack, alpha_offset, f.w);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_noinline void svm_node_tex_environment(KernelGlobals kg,
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_private ShaderData *sd,
|
|
|
|
|
ccl_private float *stack,
|
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 node)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2011-05-13 14:32:08 +00:00
|
|
|
uint id = node.y;
|
2019-05-19 02:46:24 +02:00
|
|
|
uint co_offset, out_offset, alpha_offset, flags;
|
2012-03-08 19:52:58 +00:00
|
|
|
uint projection = node.w;
|
2011-05-13 14:32:08 +00:00
|
|
|
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar4(node.z, &co_offset, &out_offset, &alpha_offset, &flags);
|
2011-05-13 14:32:08 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
float3 co = stack_load_float3(stack, co_offset);
|
2012-03-08 19:52:58 +00:00
|
|
|
float2 uv;
|
|
|
|
|
|
2017-05-07 14:40:58 +02:00
|
|
|
co = safe_normalize(co);
|
|
|
|
|
|
2012-03-08 19:52:58 +00:00
|
|
|
if (projection == 0)
|
|
|
|
|
uv = direction_to_equirectangular(co);
|
|
|
|
|
else
|
|
|
|
|
uv = direction_to_mirrorball(co);
|
|
|
|
|
|
2019-05-19 02:46:24 +02:00
|
|
|
float4 f = svm_image_texture(kg, id, uv.x, uv.y, flags);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-09-16 13:14:02 +00:00
|
|
|
if (stack_valid(out_offset))
|
2012-09-04 13:29:07 +00:00
|
|
|
stack_store_float3(stack, out_offset, make_float3(f.x, f.y, f.z));
|
2011-09-16 13:14:02 +00:00
|
|
|
if (stack_valid(alpha_offset))
|
|
|
|
|
stack_store_float(stack, alpha_offset, f.w);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|