43 Commits

Author SHA1 Message Date
Brecht Van Lommel
19e845b91e Fix: Cycles blackbody renders wrong with OSL and ACEScg
OSL only supports a fixed number of color space, so detect a few common
ones and set those. This makes functions like blackbody work correctly.

Pull Request: https://projects.blender.org/blender/blender/pulls/145755
2025-09-05 11:11:32 +02:00
Alaska
736559f320 Fix #139718: Always treat OSL cameras as inside a volume
Cycles automatically tries to decide if the camera ray should be a
surface or a volume + surface camera ray by checking to see if the
scene contains a volumetric material, and if it does, is it near
where the camera rays are expected to spawn. This step is done
during scene intialization.

With the OSL camera, it is impratical to predict where the
camera rays will spawn during scene intialization, which makes it
impratical to predict if the OSL camera ray will spawn near a
volumetric object. So this commit marks all OSL cameras as
"inside a volume", leading to the spawning of volume + surface camera
rays for OSL cameras while the scene contains a volumetric material.

This leads to increased render times ranging between 1% - 5% in scenes
that use a OSL camera, has a volumetric object in it, and the
volumetric object is far away from the camera. Every other scene should
see no performance impact.

Testing was done on a AMD Ryzen 9 5950X and a NVIDIA GeForce RTX 4090.

Pull Request: https://projects.blender.org/blender/blender/pulls/142036
2025-07-16 16:25:38 +02:00
Brecht Van Lommel
40339e3edd Merge branch 'blender-v4.5-release' 2025-07-14 17:39:16 +02:00
Brecht Van Lommel
c5df70a7d4 Fix #141779: Adaptive subdivision + custom OSL camera crash
This is not an actual solution, it falls back to a perspective camera instead
of crashing. Note full_rastertocamera exists specifically for computing raster
size for adaptive subdivision, and changing it should not affect anything else.

Pull Request: https://projects.blender.org/blender/blender/pulls/141905
2025-07-14 17:36:29 +02:00
Brecht Van Lommel
73fe848e07 Fix: Cycles log levels conflict with macros on some platforms
In particular DEBUG, but prefix all of them to be sure.

Pull Request: https://projects.blender.org/blender/blender/pulls/141749
2025-07-10 19:44:14 +02:00
Brecht Van Lommel
fb4e3c8167 Refactor: Cycles: Remove distinction between severity and verbosity
Only use LOG() and LOG_IS_ON() macros, no more VLOG_.

Pull Request: https://projects.blender.org/blender/blender/pulls/140244
2025-07-09 20:59:24 +02:00
Campbell Barton
07121d44ae Cleanup: use braces (follow own style guide) 2025-06-11 09:05:26 +00:00
Lukas Stockner
507267393e Cleanup: Cycles: Restructure camera viewplane calculation
This started with investigating a render issue that appears to be caused by
GCC 15. From what I can tell, it was caused by
`*viewplane = (*viewplane) * bcam->zoom;`.

I'm not entirely sure what the root cause is (potentially pointer aliasing?),
but the restructured code works fine now.

Pull Request: https://projects.blender.org/blender/blender/pulls/139416
2025-05-26 22:24:20 +02:00
Lukas Stockner
bf412ed9dd Cycles: Support for custom OSL cameras
This allows users to implement arbitrary camera models using OSL by writing
shaders that take an image position as input and compute ray origin and
direction.

The obvious applications for this are e.g. panorama modes, lens distortion
models and realistic lens simulation, but the possibilities are endless.

Currently, this is only supported on devices with OSL support, so CPU and
OptiX. However, it is independent from the shading model used, so custom
cameras can be used without getting the performance hit of OSL shading.

A few samples are provided as Text Editor templates.

One notable current limitation (in addition to the limited device support)
is that inverse mapping is not supported, so Window texture coordinates and
the Vector pass will not work with custom cameras.

Pull Request: https://projects.blender.org/blender/blender/pulls/129495
2025-04-25 19:27:30 +02:00
Brecht Van Lommel
86b67a20d6 Refactor: Cycles: Move scene update earlier in render iteration update
This will be needed to determine if there are volumes in the scene, before
allocation passes to aid volume sampling.

The kernels are now also loaded in the middle of scene update, at a place
where kernel features are known but before the kernels are needed for
displacement and background light evaluation..

Updating the camera to final resolution for progressive refinement still
happens later.

Pull Request: https://projects.blender.org/blender/blender/pulls/137228
2025-04-11 14:28:22 +02:00
Brecht Van Lommel
c4db213127 Refactor: Cycles: Use full resolution for viewplane bounds check
Results should be unchanged, but it's confusing if these use the progressive
refinement resolution instead of the full resolution.

Pull Request: https://projects.blender.org/blender/blender/pulls/137228
2025-04-11 14:28:22 +02:00
Brecht Van Lommel
48398b223b Cleanup: Fix various divisions by zero reported by ASAN
Pull Request: https://projects.blender.org/blender/blender/pulls/135326
2025-03-06 22:34:23 +01:00
Brecht Van Lommel
57ff24cb99 Refactor: Cycles: Add const keyword to more function parameters
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:24 +01:00
Brecht Van Lommel
dd51c8660b Refactor: Cycles: Add const keyword where possible, using clang-tidy
Check was misc-const-correctness, combined with readability-isolate-declaration
as suggested by the docs.

Temporarily clang-format "QualifierAlignment: Left" was used to get consistency
with the prevailing order of keywords.

Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:20 +01:00
Brecht Van Lommel
689633d802 Refactor: Cycles: Avoid unsafe memcpy and memcmp
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:15 +01:00
Brecht Van Lommel
60bec183cb Refactor: Cycles: Replace foreach() by range based for loops
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:05 +01:00
Brecht Van Lommel
d0c2e68e5f Refactor: Cycles: Automated clang-tidy fixups in Cycles
* Use .empty() and .data()
* Use nullptr instead of 0
* No else after return
* Simple class member initialization
* Add override for virtual methods
* Include C++ instead of C headers
* Remove some unused includes
* Use default constructors
* Always use braces
* Consistent names in definition and declaration
* Change typedef to using

Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:22:55 +01:00
Brecht Van Lommel
5c46063607 Refactor: Cycles: Make kernel headers work by themselves
Shuffle around some code and add more includes so that individual
header files compile without errors.

Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:22:50 +01:00
Brecht Van Lommel
4e777476b5 Refactor: Cycles: Replace std::bind by lambdas
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:22:35 +01:00
Thomas Dinges
1be75e86aa Cleanup: replace floatX_to_floatY() with make_floatY()
Now that function overloads are usable on all GPUs, replace the former explicit functions.

Pull Request: https://projects.blender.org/blender/blender/pulls/132067
2024-12-19 09:41:55 +01:00
Mark Stead
dfc58d282b Fix #69731: Cycles: Vector Pass ignores animated FOV
This PR fixes the motion vector values when using animation of the (perspective)
camera focal length (and therefore changing the fov).

Pull Request: https://projects.blender.org/blender/blender/pulls/127442
2024-10-15 11:42:11 +02:00
Campbell Barton
d497452a73 Cleanup: typo, spaces in comments, comment blocks & use double quotes 2024-08-29 17:16:44 +10:00
softyoda
5e9096829c Cycles: Add Central Cylindrical Panoramic camera model
This type of projection is often used e.g. in exhibitions that leverage big
curved screens.

Effectively, the frame is mapped onto a cylinder, with the x axis becoming the
longitude and y axis becoming the height.

Users can configure the min/max longitude, the min/max height and the radius of
the cylinder.

Co-authored-by: Lukas Stockner <lukas.stockner@freenet.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/123046
2024-07-29 15:03:57 +02:00
Alaska
10737d719e Cleanup: Correct Cycles code comment
The code comment references a variable that was removed during the
review process of !123341

Pull Request: https://projects.blender.org/blender/blender/pulls/123409
2024-06-19 10:42:13 +02:00
Alaska
56bb8b2b3c Fix #123324: Improve Cycles camera bounding box size calculation
Cycles runs a check to see if the camera is possibly inside a
volumetric object by seeing if the bounding box of the camera
and volumetric object intersect.

If the calculation is wrong (Cycles says the camera is outside the
volume when it's inside it), then the volume will not render properly.

This commit resolves most of these issues by making the camera
bounding box larger than before, taking into consideration
features like:

1. The impact DOF could have on the camera ray start position and how
that should impact the bounding box size.
2. Taking into consideration near clipping, which was missed from the
orthographic camera due to a oversight in a previous commit
(08cc73a9bb).

Pull Request: https://projects.blender.org/blender/blender/pulls/123341
2024-06-18 17:35:16 +02:00
Alaska
274da96722 Render: Clamp minimum DOF focus distance
Clamp DOF focus distance to a minimum of 1e-5.
This is to primarily stop focus distances of 0 being used
which would lead to issues in future code changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/123310
2024-06-17 17:42:38 +02:00
Campbell Barton
5b9740c913 Cleanup: use braces for sources in intern/
Omitted intern/itasc as some of these sources are from KDL:
https://www.orocos.org/kdl.html
2023-09-17 09:05:40 +10:00
Campbell Barton
c12994612b License headers: use SPDX-FileCopyrightText in intern/cycles 2023-06-14 16:53:23 +10:00
Weizhen Huang
41e49d7ece Refactor: group multiple floats to float2 or float3
Multiple random numbers were passed around separately, making some
argument lists unnecessarily long.
No functional changes expected.

Pull Request: https://projects.blender.org/blender/blender/pulls/108236
2023-05-24 18:56:58 +02:00
Brecht Van Lommel
36e5157693 Cleanup: remove redundant lerp function, mix already does the same 2023-05-12 21:00:52 +02:00
Sergey Sharybin
d32d787f5f Clang-Format: Allow empty functions to be single-line
For example

```
OIIOOutputDriver::~OIIOOutputDriver()
{
}
```

becomes

```
OIIOOutputDriver::~OIIOOutputDriver() {}
```

Saves quite some vertical space, which is especially handy for
constructors.

Pull Request: https://projects.blender.org/blender/blender/pulls/105594
2023-03-29 16:50:54 +02:00
Lukas Stockner
95696d09bc Fix T88849: Motion blur in cycles leaves bright edge on trailing end of blur
The code that computes and inverts the shutter CDF had some issues that caused
the result to be asymmetric, this tweaks it to be more robust and produce
symmetric outputs for symmetric inputs.
2023-01-09 03:08:36 +01:00
Damian Trebilco
f9113b7eb6 Cycles: add Equiangular Cubemap Face camera projection
This can be used for example for VR video formats that use this projection
instead of perspective projection for cubemap faces.

Differential Revision: https://developer.blender.org/D13525
2022-10-28 16:24:03 +02:00
Brecht Van Lommel
b865339833 Cleanup: remove some unnecessary kernel feature defines
That are either unused or aren't useful for testing anymore without a
megakernel.
2022-09-02 17:13:28 +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
2c1bffa286 Cleanup: add verbose logging category names instead of numbers
And use them more consistently than before.
2022-06-17 14:08:14 +02:00
Kévin Dietrich
2890c11cd7 Cycles: add support for volume motion blur
This adds support for rendering motion blur for volumes, using their
velocity field. This works for fluid simulations and imported VDB
volumes. For the latter, the name of the velocity field can be set per
volume object, with automatic detection of velocity fields that are
split into 3 scalar grids.

A new parameter is also added to scale velocity for more artistic control.

Like for Alembic and USD caches, a parameter to set the unit of time in
which the velocity vectors are expressed is also added. For Blender gas
simulations, the velocity unit should always be in seconds, so this is
only exposed for volume objects which may come from external OpenVDB
files.

These parameters are available under the `Render` panels for the fluid
domain and the volume object data properties respectively.

Credits: kernel advection code from Tangent Animation's Blackbird based
on earlier work by Geraldine Chua

Differential Revision: https://developer.blender.org/D14629
2022-04-19 17:07:53 +02: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
Aaron Carlisle
b71e29b3da Cleanup: clang-format 2021-12-07 23:12:13 -05:00
Håkan Ardö
24e0165463 Cycles: add Fisheye Lens Polynomial camera model
This allows real world cameras to be modeled by specifying the coordinates of a
4th degree polynomial that relates a pixels distance (in mm) from the optical
center on the sensor to the angle (in radians) of the world ray that is
projected onto that pixel.

This is available as part of the panoramic lens type, however it can also be
used to model lens distortions in projective cameras for example.

Differential Revision: https://developer.blender.org/D12691
2021-12-07 20:05:57 +01:00
Brecht Van Lommel
049510f425 Fix T92491: Cycles panoramic camera inside volume fails with near clipping 2021-10-28 21:43:08 +02:00
Brecht Van Lommel
fd25e883e2 Cycles: remove prefix from source code file names
Remove prefix of filenames that is the same as the folder name. This used
to help when #includes were using individual files, but now they are always
relative to the cycles root directory and so the prefixes are redundant.

For patches and branches, git merge and rebase should be able to detect the
renames and move over code to the right file.
2021-10-26 15:37:04 +02:00
Brecht Van Lommel
d7d40745fa Cycles: changes to source code folders structure
* Split render/ into scene/ and session/. The scene/ folder now contains the
  scene and its nodes. The session/ folder contains the render session and
  associated data structures like drivers and render buffers.
* Move top level kernel headers into new folders kernel/camera/, kernel/film/,
  kernel/light/, kernel/sample/, kernel/util/
* Move integrator related kernel headers into kernel/integrator/
* Move OSL shaders from kernel/shaders/ to kernel/osl/shaders/

For patches and branches, git merge and rebase should be able to detect the
renames and move over code to the right file.
2021-10-26 15:36:39 +02:00