Commit Graph

376 Commits

Author SHA1 Message Date
Weizhen Huang
f9a75d1e40 Fix #122976: Cycles light linking broken for volumes with light tree
Light linking was never working correctly in volume segment with light
tree, because `sd->object` was not assigned, thus
`light_link_receiver_nee(kg, sd)` always returned `OBJECT_NONE`, causing
the light tree sample to fail. This problem was revealed by fdc2962beb
since now the same light is used for volume segment and volume.

Also ensure we don't sample position on the light if sampling from
volume segment is failed, by setting `emitter_id` to `EMITTER_NONE` in
such cases.

Pull Request: https://projects.blender.org/blender/blender/pulls/122999
2024-06-10 16:11:12 +02:00
Michael Jones
99f5433445 Cycles: Dormant fixes for adaptive feature compilation
This PR fixes the (currently unused) scene-based selective feature compilation macros. These feature based macros haven't been used for a few years, and enabling them currently results in compilation errors.

The only functional change in this PR is in geom/primitive.h where undef-ing `__HAIR__` had exposed an inconsistency in how pointcloud attributes were being fetched. Using the more general `primitive_surface_attribute_float4` (instead of `curve_attribute_float4`) fixed a compilation error that occurred when rendering pointcloud unit test scenes with adaptive compilation enabled.

Pull Request: https://projects.blender.org/blender/blender/pulls/121216
2024-04-30 12:56:22 +02:00
Weizhen Huang
a6330cad7f Refactor: wrap block of codes into a function 2024-04-17 18:49:00 +02:00
Weizhen Huang
418acfe8bb Cleanup: remove unused function parameters
This is not a complete list of all the unused parameters in kernel, but
those I touch often, so I am more confident that it's safe to delete them.
2024-04-17 18:49:00 +02:00
Brecht Van Lommel
898187cfab Fix #118466: Cycles renders black on Metal + AMD
Global built-ins appear to not work on AMD cards.

Also add a tweak to avoid a performance regression, similar
to what was done before. Disable adaptive subdivision kernel
code if not used.

Pull Request: https://projects.blender.org/blender/blender/pulls/119175
2024-03-08 16:41:27 +01:00
Brecht Van Lommel
8087dd9e96 Cleanup: Cycles: use one fewer object struct member for motion data 2024-01-24 20:17:13 +01:00
Brecht Van Lommel
ac70bc3611 Fix: temporarily disable Cycles patch map assert to avoid failing test
After recent 4.1 libraries update update for macOS ARM.
2024-01-04 04:06:19 +01:00
Brecht Van Lommel
d377ef2543 Clang Format: bump to version 17
Along with the 4.1 libraries upgrade, we are bumping the clang-format
version from 8-12 to 17. This affects quite a few files.

If not already the case, you may consider pointing your IDE to the
clang-format binary bundled with the Blender precompiled libraries.
2024-01-03 13:38:14 +01:00
Campbell Barton
2721b937fb Cleanup: use braces in headers 2023-09-24 14:52:38 +10:00
Campbell Barton
785bd13b9a Cleanup: spelling in comments 2023-07-05 14:09:33 +10:00
Campbell Barton
c12994612b License headers: use SPDX-FileCopyrightText in intern/cycles 2023-06-14 16:53:23 +10:00
Weizhen Huang
84863dae89 Fix light texture invisible when looking at a light
`sd->type` was set to `PRIMITIVE_TRIANGLE` when it should be
`PRIMITIVE_LAMP`.

Function #lights_intersect_impl sets `isect->prim` to `lamp`, which is
passed to function #shader_setup_from_sample. There `prim != PRIM_NONE`
is evaluated to `true`, thus setting `sd->type` to `PRIMITIVE_TRIANGLE`
erroneously. This fix checks `lamp != LAMP_NONE` first, as in all other
usages of #shader_setup_from_sample `LAMP_NONE` is passed as the value
of `lamp`.

Pull Request: https://projects.blender.org/blender/blender/pulls/108769
2023-06-08 18:05:30 +02:00
Weizhen Huang
2ab020cc3c Cycles: enable normal transformation of lights in Vector Transform node
This is added so that some texture pipeline with point light and spot
light could work as before. Some people use the Normal socket from
Texture Coordinate node for texturing light, however the Normal there is
actually the incoming light direction and should be corrected. Using the
Parametric socket from Geometry node + normal transform from world to
object with Vector Transform node delivers the same result as using the
Normal socket from Texture Coordinate node.

Currently for lights only normal transformation works, because only
there we fetch light transform properly. This is a confusing behaviour,
but testing if it's a lamp in all relevant functions could have bad
impact on the performance. A more proper solution would be to change
lights to real objects, which is planned for the future.

![Geometry_Vector_Transform](attachments/fe38895e-85b3-4e7a-873f-12068237f790)

Pull Request: https://projects.blender.org/blender/blender/pulls/108666
2023-06-06 19:07:43 +02:00
Campbell Barton
12d91d4e60 Cleanup: spelling in comments 2023-05-27 15:24:52 +10:00
Campbell Barton
6859bb6e67 Cleanup: format (with BraceWrapping::AfterControlStatement "MultiLine") 2023-05-02 09:37:49 +10:00
Weizhen Huang
390a63b264 Refactor: de-duplicate motion triangle vertices and normals computation
Barycentric coordinate convention was changed at some point, which is
reflected in `motion_triangle_shader.h` (1c2c468abc) but not in
`motion_triangle.h`, this is also fixed by sharing functions between the
two header files.

Pull Request: https://projects.blender.org/blender/blender/pulls/106629
2023-04-06 17:28:41 +02:00
Weizhen Huang
792da15d53 Fix #106394: motion triangles could have unnormalized normals 2023-04-06 13:48:45 +02:00
Campbell Barton
f240a16037 Cleanup: format 2023-02-27 21:34:53 +11:00
William Leeson
6c03339e48 Cycles: reduce mesh memory usage by unflattening
To improve mesh upload speeds and reduce the size of the scene data which allows larger scenes to be rendered.

The meshes in Cycles are currently stored as flattened meshes, where each triangle is stored as a set of 3 vertices. Unflattening writes out the vertices in a list according to the index buffer. This uses a lot of memory and for current hardware does not provide a noticeable benefit. This change unflattens the mesh by directly using the meshes vertex and index buffers directly and skips the unflattening. This change allows for larger scenes and also a reduction in the sizes of the meshes. Further it results in a decrease the amount of time it takes to upload the data to a GPU. This is especially important for when multiple GPUs are used in a single machine.

Pull Request #105173
2023-02-27 10:39:19 +01:00
Lukas Stockner
ce25e3e581 Cycles: Cleanup: Add general-purpose conversion between sin and cos 2023-01-24 17:59:29 +01:00
Weizhen Huang
543bf28fb1 Refactor: renamed I -> wi, omega_in -> wo in Cycles
wi is the viewing direction, and wo is the illumination direction. Under this notation, BSDF sampling always samples from wi and outputs wo, which is consistent with most of the papers and mitsuba. This order is reversed compared with PBRT, although PBRT also traces from the camera.
2023-01-17 18:07:13 +01:00
Lukas Stockner
c41601becd Fix T89037: Cycles: Backfacing node can be wrong for lights with negative scale
When rendering in the viewport (or probably on instanced objects, but I didn't
test that), emissive objects whose scale is negative give the wrong value on the
"backfacing" input when multiple sampling is enabled.

The underlying problem was a corner case in how normal transformation is handled,
which is generally a bit messy.

From what I can tell, the pattern appears to be:
- If you first transform vertices to world space and then compute the normal from
  them (as triangle light samping, MNEE and light tree do), you need to flip
  whenever the transform has negative scale regardless of whether the transform
  has been applied
- If you compute the normal in object space and then transform it to world space
  (as the regular shader_setup_from_ray path does), you only need to flip if the
  transform was already applied and was negative
- If you get the normal from a local intersection result (as bevel and SSS do),
  you only need to flip if the transform was already applied and was negative
- If you get the normal from vertex normals, you don't need to do anything since
  the host-side code does the flip for you (arguably it'd be more consistent to
  do this in the kernel as well, but meh, not worth the potential slowdown)

So, this patch fixes the logic in the triangle emission code.

Also, turns out that the MNEE code had the same problem and was also having
problems in the viewport on negative-scale objects, this is also fixed now.

Differential Revision: https://developer.blender.org/D16952
2023-01-10 02:55:23 +01:00
Patrick Mours
a45c36efae Cycles: Make OSL implementation independent from SVM
Cleans up the file structure to be more similar to that of the SVM
and also makes it possible to build kernels with OSL support, but
without having to include SVM support.

This patch was split from D15902.

Differential Revision: https://developer.blender.org/D15949
2022-09-13 10:59:28 +02:00
Patrick Mours
ef7c9e793e Cycles: Remove separate OSL attribute map and instead always use SVM attribute map
The SVM attribute map is always generated and uses a simple
linear search to lookup by an opaque ID, so can reuse that for OSL
as well and simply use the attribute name hash as ID instead of
generating a unique value separately. This works for both object
and geometry attributes since the SVM attribute map already
stores both. Simplifies code somewhat and reduces memory
usage slightly.

This patch was split from D15902.

Differential Revision: https://developer.blender.org/D15918
2022-09-09 15:35:44 +02:00
Brecht Van Lommel
e949d6da5b Cycles: simplify handling of ray differentials
* Store compact ray differentials in ShaderData and compute full differentials
  on demand. This reduces register pressure on the GPU.
* Remove BSDF differential code that was effectively doing nothing as the
  differential orientation was discarded when making it compact.

This gives a 1-5% speedup with RTX A6000 + OptiX in our benchmarks, with the
bigger speedups in simpler scenes.

Renders appear to be identical except for the Both displacement option that
does both displacement and bump.

Differential Revision: https://developer.blender.org/D15677
2022-08-15 13:48:02 +02:00
Brecht Van Lommel
1c2c468abc Fix T100134: Cycles faceted triangle normals with motion blur
After recent changes to change barycentric coordinate convention.
2022-08-04 19:08:45 +02:00
Brecht Van Lommel
38af5b0501 Cycles: switch Cycles triangle barycentric convention to match Embree/OptiX
Simplifies intersection code a little and slightly improves precision regarding
self intersection.

The parametric texture coordinate in shader nodes is still the same as before
for compatibility.
2022-07-27 21:03:33 +02:00
Brecht Van Lommel
69f2732a13 Cleanup: remove unnecessary bvh_instance_motion_pop 2022-07-27 21:02:21 +02:00
Brecht Van Lommel
484ad31653 Cycles: simplify handling of ray distance in GPU rendering
All our intersections functions now work with unnormalized ray direction,
which means we no longer need to transform ray distance between world and
object space, they can all remain in world space.

There doesn't seem to be any real performance difference one way or the
other, but it does simplify the code.
2022-07-25 13:27:40 +02:00
Brecht Van Lommel
023eb2ea7c Cycles: more closely match some math and intersection operations in Embree
This helps with debugging, and gives a slightly closer match between CPU
and CUDA/HIP/Metal renders when it comes to ray tracing precision.
2022-07-25 13:27:40 +02:00
Brecht Van Lommel
5152c7c152 Cycles: refactor rays to have start and end distance, fix precision issues
For transparency, volume and light intersection rays, adjust these distances
rather than the ray start position. This way we increment the start distance
by the smallest possible float increment to avoid self intersections, and be
sure it works as the distance compared to be will be exactly the same as
before, due to the ray start position and direction remaining the same.

Fix T98764, T96537, hair ray tracing precision issues.

Differential Revision: https://developer.blender.org/D15455
2022-07-15 18:46:24 +02:00
Xavier Hallade
633c2f07da Cyles: switch primitive.h inline hints to forceinline
This change helps decrease Intel GPU binaries compile time by 5-10
minutes without impacting other backends.

Reviewed By: sergey, brecht

Differential Revision: http://developer.blender.org/D15273
2022-06-23 18:36:48 +02:00
Andrii Symkin
c2a2f3553a Cycles: unify math functions names
This patch unifies the names of math functions for different data types and uses
overloading instead. The goal is to make it possible to swap out all the float3
variables containing RGB data with something else, with as few as possible
changes to the code. It's a requirement for future spectral rendering patches.

Differential Revision: https://developer.blender.org/D15276
2022-06-23 15:02:53 +02:00
Brecht Van Lommel
ff1883307f Cleanup: renaming and consistency for kernel data
* Rename "texture" to "data array". This has not used textures for a long time,
  there are just global memory arrays now. (On old CUDA GPUs there was a cache
  for textures but not global memory, so we used to put all data in textures.)
* For CUDA and HIP, put globals in KernelParams struct like other devices.
* Drop __ prefix for data array names, no possibility for naming conflict now that
  these are in a struct.
2022-06-20 12:30:48 +02:00
Brecht Van Lommel
24246d9870 Cleanup: replace uint4 by AttributeMap struct 2022-06-17 14:08:14 +02:00
Lukas Stockner
ad35453cd1 Cycles: Add support for light groups
Light groups are a type of pass that only contains lighting from a subset of light sources.
They are created in the View layer, and light sources (lamps, objects with emissive materials
and/or the environment) can be assigned to a group.

Currently, each light group ends up generating its own version of the Combined pass.
In the future, additional types of passes (e.g. shadowcatcher) might be getting their own
per-lightgroup versions.

The lightgroup creation and assignment is not Cycles-specific, so Eevee or external render
engines could make use of it in the future.

Note that Lightgroups are identified by their name - therefore, the name of the Lightgroup
in the View Layer and the name that's set in an object's settings must match for it to be
included.
Currently, changing a Lightgroup's name does not update objects - this is planned for the
future, along with other features such as denoising for light groups and viewing them in
preview renders.

Original patch by Alex Fuller (@mistaed), with some polishing by Lukas Stockner (@lukasstockner97).

Differential Revision: https://developer.blender.org/D12871
2022-04-02 06:14:27 +02:00
Ethan-Hall
f5066d43ae Cleanup: use make_float4(f) zero_float4() to simplify code
Differential Revision: https://developer.blender.org/D14426
2022-03-23 20:06:12 +01:00
Ethan-Hall
5b4ab89663 Shader Nodes: add Alpha output to Object Info node
An alpha component can be specified for an object's color. This adds an alpha
socket to the object info shader node allowing for the alpha component of the
object's color to be accessed in the shader editor.

Differential Revision: https://developer.blender.org/D14141
2022-03-07 17:35:48 +01:00
Kévin Dietrich
bdf4e1596d Merge remote-tracking branch 'origin/blender-v3.1-release' 2022-02-25 21:36:09 +01:00
Brecht Van Lommel
4896e72a4d Fix T95977: Point Info node radius wrong under rotation 2022-02-25 20:51:22 +01:00
Campbell Barton
14dd207b75 License headers: use SPDX for remaining files in Cycles 2022-02-15 17:52:38 +11:00
Brecht Van Lommel
9cfc7967dd Cycles: use SPDX license headers
* Replace license text in headers with SPDX identifiers.
* Remove specific license info from outdated readme.txt, instead leave details
  to the source files.
* Add list of SPDX license identifiers used, and corresponding license texts.
* Update copyright dates while we're at it.

Ref D14069, T95597
2022-02-11 17:47:34 +01:00
Brecht Van Lommel
5fabbedb04 Fix Cycles assert in light sampling
There is no object transform on lights.
2022-01-31 20:45:12 +01:00
Brecht Van Lommel
82ad1631e4 Fix Cycles assert in light sampling
There is no object transform on lights.
2022-01-28 17:32:18 +01:00
William Leeson
a9bb460766 Cycles: compute triangle location from barycentric instead of re-intersecting
This is a bit more efficient than what we did before.

Ref D12954
2022-01-26 17:51:05 +01:00
Brecht Van Lommel
c813a1b358 Cycles: add Point Info node
With (center) position, radius and random value outputs.

Eevee does not yet support rendering point clouds, but an untested
implementation of this node was added for when it does.

Ref T92573
2022-01-25 17:14:20 +01:00
Brecht Van Lommel
0928fe8710 Fix T94651: Cycles error with pointcloud vector attribute 2022-01-24 15:58:32 +01:00
Brecht Van Lommel
4d10a46e63 Cleanup: refactor BVH2 in preparation of self intersection skip
Move some logic out of triangle intersection functions and into BVH
traversal, so we can share logic between primitives.

Ref D12954
2022-01-17 17:35:23 +01:00
Olivier Maury
34d553671d Fix wrong shadow terminator geometry offset with deformation motion blur
Differential Revision: https://developer.blender.org/D13759
2022-01-07 17:20:04 +01:00
Brecht Van Lommel
edb3ab0617 Fix T94251: Cycles wrong pointcloud normal for instanced objects
Refactor code a bit also so we need to do fewer matrix transforms for shader
data setup of points and curves.
2021-12-20 14:14:43 +01:00