2023-06-14 16:52:36 +10:00
|
|
|
# SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
#
|
2022-02-11 13:53:21 +01:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2023-06-14 16:52:36 +10:00
|
|
|
|
2021-02-21 21:21:18 +11:00
|
|
|
from __future__ import annotations
|
2011-11-15 02:58:01 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
bl_info = {
|
|
|
|
|
"name": "Cycles Render Engine",
|
|
|
|
|
"author": "",
|
2017-04-25 16:18:24 +02:00
|
|
|
"blender": (2, 80, 0),
|
2019-06-02 13:23:04 +02:00
|
|
|
"description": "Cycles renderer integration",
|
2011-04-27 11:58:34 +00:00
|
|
|
"warning": "",
|
2020-03-05 11:40:05 +11:00
|
|
|
"doc_url": "https://docs.blender.org/manual/en/latest/render/cycles/",
|
2011-04-27 11:58:34 +00:00
|
|
|
"tracker_url": "",
|
2011-11-13 10:05:07 +00:00
|
|
|
"support": 'OFFICIAL',
|
2011-04-27 11:58:34 +00:00
|
|
|
"category": "Render"}
|
|
|
|
|
|
2017-01-22 12:42:14 +01:00
|
|
|
# Support 'reload' case.
|
|
|
|
|
if "bpy" in locals():
|
|
|
|
|
import importlib
|
|
|
|
|
if "engine" in locals():
|
|
|
|
|
importlib.reload(engine)
|
|
|
|
|
if "version_update" in locals():
|
|
|
|
|
importlib.reload(version_update)
|
|
|
|
|
if "ui" in locals():
|
|
|
|
|
importlib.reload(ui)
|
2019-02-06 12:57:10 +01:00
|
|
|
if "operators" in locals():
|
|
|
|
|
importlib.reload(operators)
|
2017-01-22 12:42:14 +01:00
|
|
|
if "properties" in locals():
|
|
|
|
|
importlib.reload(properties)
|
|
|
|
|
if "presets" in locals():
|
|
|
|
|
importlib.reload(presets)
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
import bpy
|
|
|
|
|
|
2015-05-17 17:17:31 +10:00
|
|
|
from . import (
|
2018-07-12 11:03:13 +02:00
|
|
|
engine,
|
|
|
|
|
version_update,
|
|
|
|
|
)
|
2013-01-15 23:17:45 +00:00
|
|
|
|
2014-09-17 18:36:17 +10:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
class CyclesRender(bpy.types.RenderEngine):
|
2011-08-28 13:55:59 +00:00
|
|
|
bl_idname = 'CYCLES'
|
2018-04-22 10:21:40 +02:00
|
|
|
bl_label = "Cycles"
|
2019-06-06 14:36:40 +02:00
|
|
|
bl_use_eevee_viewport = True
|
2013-01-28 17:37:51 +00:00
|
|
|
bl_use_preview = True
|
2013-06-10 13:53:38 +00:00
|
|
|
bl_use_exclude_layers = True
|
Multi-View: Cycles - Spherical Stereo support (VR Panoramas)
This is a new option for panorama cameras to render
stereo that can be used in virtual reality devices
The option is available under the camera panel when Multi-View is enabled (Views option in the Render Layers panel)
Known limitations:
------------------
* Parallel convergence is not supported (you need to set a convergence distance really high to simulate this effect).
* Pivot was not supposed to affect the render but it does, this has to be looked at, but for now set it to CENTER
* Derivatives in perspective camera need to be pre-computed or we shuld get rid of kcam->dx/dy (Sergey words, I don't fully grasp the implication shere)
* This works in perspective mode and in panorama mode. However, for fully benefit from this effect in perspective mode you need to render a cube map. (there is an addon for this, developed separately, perhaps we could include it in master).
* We have no support for "neck distance" at the moment. This is supposed to help with objects at short distances.
* We have no support to rotate the "Up Axis" of the stereo plane. Meaning, we hardcode 0,0,1 as UP, and create the stereo pair related to that. (although we could take the camera local UP when rendering panoramas, this wouldn't work for perspective cameras.
* We have no support for interocular distance attenuation based on the proximity of the poles (which helps to reduce the pole rotation effect/artifact).
THIS NEEDS DOCS - both in 2.78 release log and the Blender manual.
Meanwhile you can read about it here: http://code.blender.org/2015/03/1451
This patch specifically dates from March 2015, as you can see in the code.blender.org post. Many thanks to all the reviewers, testers and minor sponsors who helped me maintain spherical-stereo for 1 year.
All that said, have fun with this. This feature was what got me started with Multi-View development (at the time what I was looking for was Fulldome stereo support, but the implementation is the same). In order to make this into Blender I had to make it aiming at a less-specic user-case Thus Multi-View started. (this was December 2012, during Siggraph Asia and a chat I had with Paul Bourke during the conference). I don't have the original patch anymore, but you can find a re-based version of it from March 2013, right before I start with the Multi-View project https://developer.blender.org/P332
Reviewers: sergey, dingto
Subscribers: #cycles
Differential Revision: https://developer.blender.org/D1223
2016-03-10 09:28:29 -03:00
|
|
|
bl_use_spherical_stereo = True
|
2021-02-01 18:24:15 +01:00
|
|
|
bl_use_custom_freestyle = True
|
2021-08-19 14:34:01 +02:00
|
|
|
bl_use_alembic_procedural = True
|
2011-04-27 11:58:34 +00:00
|
|
|
|
RNA: Make the `PointerRNA` struct non-trivial.
For now, PointerRNA is made non-trivial by giving explicit default
values to its members.
Besides of BPY python binding code, the change is relatively trivial.
The main change (besides the creation/deletion part) is the replacement
of `memset` by zero-initialized assignment (using `{}`).
makesrna required changes are quite small too.
The big piece of this PR is the refactor of the BPY RNA code.
It essentially brings back allocation and deletion of the BPy_StructRNA,
BPy_Pointer etc. python objects into 'cannonical process', using `__new__`,
and `__init__` callbacks (and there matching CAPI functions).
Existing code was doing very low-level manipulations to create these
data, which is not really easy to understand, and AFAICT incompatible
with handling C++ data that needs to be constructed and destructed.
Unfortunately, similar change in destruction code (using `__del__` and
matching `tp_finalize` CAPI callback) is not possible, because of technical
low-level implementation details in CPython (see [1] for details).
`std::optional` pointer management is used to encapsulate PointerRNA
data. This allows to keep control on _when_ actual RNA creation is done,
and to have a safe destruction in `tp_dealloc` callbacks.
Note that a critical change in Blender's Python API will be that classes
inherinting from `bpy_struct` etc. will now have to properly call the
base class `__new__` and/or `__init__`if they define them.
Implements #122431.
[1] https://discuss.python.org/t/cpython-usage-of-tp-finalize-in-c-defined-static-types-with-no-custom-tp-dealloc/64100
2024-10-30 15:08:37 +01:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super().__init__(*args, **kwargs)
|
2011-08-28 13:55:59 +00:00
|
|
|
self.session = None
|
2011-11-15 02:58:01 +00:00
|
|
|
|
2011-08-28 13:55:59 +00:00
|
|
|
def __del__(self):
|
|
|
|
|
engine.free(self)
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-08-28 13:55:59 +00:00
|
|
|
# final render
|
2018-05-23 12:13:21 +02:00
|
|
|
def update(self, data, depsgraph):
|
2015-02-21 19:17:09 +05:00
|
|
|
if not self.session:
|
|
|
|
|
if self.is_preview:
|
2014-01-13 23:29:35 +01:00
|
|
|
cscene = bpy.context.scene.cycles
|
2022-11-09 14:25:32 +01:00
|
|
|
use_osl = cscene.shading_system
|
2013-01-28 17:37:51 +00:00
|
|
|
|
2018-05-23 12:13:21 +02:00
|
|
|
engine.create(self, data, preview_osl=use_osl)
|
2013-01-28 17:37:51 +00:00
|
|
|
else:
|
2018-05-23 12:13:21 +02:00
|
|
|
engine.create(self, data)
|
|
|
|
|
|
|
|
|
|
engine.reset(self, data, depsgraph)
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2018-05-30 14:32:47 +02:00
|
|
|
def render(self, depsgraph):
|
2018-02-26 16:46:48 +01:00
|
|
|
engine.render(self, depsgraph)
|
2011-05-17 14:26:45 +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 17:59:20 +02:00
|
|
|
def render_frame_finish(self):
|
|
|
|
|
engine.render_frame_finish(self)
|
|
|
|
|
|
|
|
|
|
def draw(self, context, depsgraph):
|
|
|
|
|
engine.draw(self, depsgraph, context.space_data)
|
|
|
|
|
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
def bake(self, depsgraph, obj, pass_type, pass_filter, width, height):
|
|
|
|
|
engine.bake(self, depsgraph, obj, pass_type, pass_filter, width, height)
|
2014-01-02 19:05:07 -02:00
|
|
|
|
2011-08-28 13:55:59 +00:00
|
|
|
# viewport render
|
2019-05-16 17:19:05 +02:00
|
|
|
def view_update(self, context, depsgraph):
|
2011-08-28 13:55:59 +00:00
|
|
|
if not self.session:
|
2022-03-21 10:58:37 +01:00
|
|
|
# When starting a new render session in viewport (by switching
|
|
|
|
|
# viewport to Rendered shading) unpause the render. The way to think
|
|
|
|
|
# of it is: artist requests render, so we start to render.
|
|
|
|
|
# Do it for both original and evaluated scene so that Cycles
|
|
|
|
|
# immediately reacts to un-paused render.
|
|
|
|
|
cscene = context.scene.cycles
|
|
|
|
|
cscene_eval = depsgraph.scene_eval.cycles
|
|
|
|
|
if cscene.preview_pause or cscene_eval.preview_pause:
|
|
|
|
|
cscene.preview_pause = False
|
|
|
|
|
cscene_eval.preview_pause = False
|
|
|
|
|
|
2018-05-23 12:13:21 +02:00
|
|
|
engine.create(self, context.blend_data,
|
2013-01-15 23:17:45 +00:00
|
|
|
context.region, context.space_data, context.region_data)
|
2018-05-23 12:13:21 +02:00
|
|
|
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
engine.reset(self, context.blend_data, depsgraph)
|
|
|
|
|
engine.sync(self, depsgraph, context.blend_data)
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-05-16 17:19:05 +02:00
|
|
|
def view_draw(self, context, depsgraph):
|
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
|
|
|
engine.view_draw(self, depsgraph, context.region, context.space_data, context.region_data)
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
def update_script_node(self, node):
|
|
|
|
|
if engine.with_osl():
|
|
|
|
|
from . import osl
|
|
|
|
|
osl.update_script_node(node, self.report)
|
|
|
|
|
else:
|
2023-04-17 11:40:14 +02:00
|
|
|
self.report({'ERROR'}, "OSL support disabled in this build")
|
2012-11-03 14:32:35 +00:00
|
|
|
|
Render API/Cycles: Identify Render Passes by their name instead of a type flag
Previously, every RenderPass would have a bitfield that specified its type. That limits the number of passes to 32, which was reached a while ago.
However, most of the code already supported arbitrary RenderPasses since they were also used to store Multilayer EXR images.
Therefore, this commit completely removes the passflag from RenderPass and changes all code to use the unique pass name for identification.
Since Blender Internal relies on hardcoded passes and to preserve compatibility, 32 pass names are reserved for the old hardcoded passes.
To support these arbitrary passes, the Render Result compositor node now adds dynamic sockets. For compatibility, the old hardcoded sockets are always stored and just hidden when the corresponding pass isn't available.
To use these changes, the Render Engine API now includes a function that allows render engines to add arbitrary passes to the render result. To be able to add options for these passes, addons can now add their own properties to SceneRenderLayers.
To keep the compositor input node updated, render engine plugins have to implement a callback that registers all the passes that will be generated.
From a user perspective, nothing should change with this commit.
Differential Revision: https://developer.blender.org/D2443
Differential Revision: https://developer.blender.org/D2444
2017-05-03 00:21:18 +02:00
|
|
|
def update_render_passes(self, scene, srl):
|
|
|
|
|
engine.register_passes(self, scene, srl)
|
|
|
|
|
|
2011-11-15 02:58:01 +00:00
|
|
|
|
2016-02-07 03:40:41 +05:00
|
|
|
def engine_exit():
|
|
|
|
|
engine.exit()
|
|
|
|
|
|
|
|
|
|
|
2017-03-20 12:16:51 +11:00
|
|
|
classes = (
|
|
|
|
|
CyclesRender,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
def register():
|
2017-03-20 12:16:51 +11:00
|
|
|
from bpy.utils import register_class
|
2012-12-13 08:45:55 +00:00
|
|
|
from . import ui
|
2019-02-06 12:57:10 +01:00
|
|
|
from . import operators
|
2012-12-13 08:45:55 +00:00
|
|
|
from . import properties
|
|
|
|
|
from . import presets
|
2016-02-07 03:40:41 +05:00
|
|
|
import atexit
|
|
|
|
|
|
2016-02-16 13:00:44 +01:00
|
|
|
# Make sure we only registered the callback once.
|
2016-02-16 12:47:12 +01:00
|
|
|
atexit.unregister(engine_exit)
|
2016-02-07 03:40:41 +05:00
|
|
|
atexit.register(engine_exit)
|
2012-12-13 08:45:55 +00:00
|
|
|
|
2013-01-14 17:30:33 +00:00
|
|
|
engine.init()
|
|
|
|
|
|
2011-08-28 13:55:59 +00:00
|
|
|
properties.register()
|
|
|
|
|
ui.register()
|
2019-02-06 12:57:10 +01:00
|
|
|
operators.register()
|
2011-08-29 17:55:14 +00:00
|
|
|
presets.register()
|
2017-03-20 12:16:51 +11:00
|
|
|
|
|
|
|
|
for cls in classes:
|
|
|
|
|
register_class(cls)
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-08-28 18:58:21 +06:00
|
|
|
bpy.app.handlers.version_update.append(version_update.do_versions)
|
|
|
|
|
|
2011-11-15 02:58:01 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
def unregister():
|
2017-03-20 12:16:51 +11:00
|
|
|
from bpy.utils import unregister_class
|
2012-12-13 08:45:55 +00:00
|
|
|
from . import ui
|
2019-02-06 12:57:10 +01:00
|
|
|
from . import operators
|
2012-12-13 08:45:55 +00:00
|
|
|
from . import properties
|
|
|
|
|
from . import presets
|
|
|
|
|
|
2014-08-28 18:58:21 +06:00
|
|
|
bpy.app.handlers.version_update.remove(version_update.do_versions)
|
|
|
|
|
|
2011-08-28 13:55:59 +00:00
|
|
|
ui.unregister()
|
2019-02-06 12:57:10 +01:00
|
|
|
operators.unregister()
|
2011-08-28 13:55:59 +00:00
|
|
|
properties.unregister()
|
2011-08-29 17:55:14 +00:00
|
|
|
presets.unregister()
|
2017-03-20 12:16:51 +11:00
|
|
|
|
|
|
|
|
for cls in classes:
|
|
|
|
|
unregister_class(cls)
|