Refactor: Move display pass to Cycles viewport parameters

Allows to centralize storage and modification checks in a single place,
avoiding duplication in the synchronization code.

Ideally we would somehow be able to more granularly modify Cycles side
objects. Leaving this for a future decision, because it might be better
to implement it as a graph on the sync side.
This commit is contained in:
2021-05-27 11:31:03 +02:00
parent 7b5f4c8837
commit 2414a5787d
3 changed files with 38 additions and 35 deletions

View File

@@ -230,12 +230,7 @@ void BlenderSync::sync_recalc(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d
has_updates_ = true;
}
if (!has_updates_) {
Film *film = scene->film;
const PassType new_display_pass = new_viewport_parameters.get_render_pass(b_v3d);
has_updates_ |= film->get_display_pass() != new_display_pass;
}
has_updates_ |= viewport_parameters.modified(new_viewport_parameters);
}
}

View File

@@ -25,7 +25,8 @@ BlenderViewportParameters::BlenderViewportParameters()
use_scene_lights(true),
studiolight_rotate_z(0.0f),
studiolight_intensity(1.0f),
studiolight_background_alpha(1.0f)
studiolight_background_alpha(1.0f),
display_pass(PASS_COMBINED)
{
}
@@ -37,13 +38,11 @@ BlenderViewportParameters::BlenderViewportParameters(BL::SpaceView3D &b_v3d)
}
BL::View3DShading shading = b_v3d.shading();
PointerRNA cshading = RNA_pointer_get(&shading.ptr, "cycles");
/* We only copy the parameters if we are in look dev mode. otherwise
/* We only copy the shading parameters if we are in look dev mode. otherwise
* defaults are being used. These defaults mimic normal render settings */
if (shading.type() != BL::View3DShading::type_RENDERED) {
return;
}
if (shading.type() == BL::View3DShading::type_RENDERED) {
use_scene_world = shading.use_scene_world_render();
use_scene_lights = shading.use_scene_lights_render();
@@ -55,6 +54,10 @@ BlenderViewportParameters::BlenderViewportParameters(BL::SpaceView3D &b_v3d)
}
}
/* Film. */
display_pass = (PassType)get_enum(cshading, "render_pass", -1, -1);
}
bool BlenderViewportParameters::shader_modified(const BlenderViewportParameters &other) const
{
return use_scene_world != other.use_scene_world || use_scene_lights != other.use_scene_lights ||
@@ -64,26 +67,26 @@ bool BlenderViewportParameters::shader_modified(const BlenderViewportParameters
studiolight_path != other.studiolight_path;
}
bool BlenderViewportParameters::film_modified(const BlenderViewportParameters &other) const
{
return display_pass != other.display_pass;
}
bool BlenderViewportParameters::modified(const BlenderViewportParameters &other) const
{
return shader_modified(other) || film_modified(other);
}
bool BlenderViewportParameters::use_custom_shader() const
{
return !(use_scene_world && use_scene_lights);
}
PassType BlenderViewportParameters::get_render_pass(BL::SpaceView3D &b_v3d)
{
PassType display_pass = PASS_NONE;
if (b_v3d) {
BL::View3DShading b_view3dshading = b_v3d.shading();
PointerRNA cshading = RNA_pointer_get(&b_view3dshading.ptr, "cycles");
display_pass = (PassType)get_enum(cshading, "render_pass", -1, -1);
}
return display_pass;
}
PassType update_viewport_display_passes(BL::SpaceView3D &b_v3d, vector<Pass> &passes)
{
if (b_v3d) {
PassType display_pass = BlenderViewportParameters::get_render_pass(b_v3d);
const BlenderViewportParameters viewport_parameters(b_v3d);
const PassType display_pass = viewport_parameters.display_pass;
passes.clear();
Pass::add(display_pass, passes);

View File

@@ -37,19 +37,24 @@ class BlenderViewportParameters {
float studiolight_background_alpha;
ustring studiolight_path;
/* Film. */
PassType display_pass;
BlenderViewportParameters();
explicit BlenderViewportParameters(BL::SpaceView3D &b_v3d);
/* Check whether any of shading related settings are different from the given parameters. */
bool shader_modified(const BlenderViewportParameters &other) const;
/* Check whether any of film related settings are different from the given parameters. */
bool film_modified(const BlenderViewportParameters &other) const;
/* Check whether any of settings are different from the given parameters. */
bool modified(const BlenderViewportParameters &other) const;
/* Returns truth when a custom shader defined by the viewport is to be used instead of the
* regular background shader or scene light. */
bool use_custom_shader() const;
/* Retrieve the render pass type that needs to be displayed on the given `SpaceView3D`
* When the `b_v3d` parameter is not given `PASS_NONE` will be returned. */
static PassType get_render_pass(BL::SpaceView3D &b_v3d);
};
PassType update_viewport_display_passes(BL::SpaceView3D &b_v3d, vector<Pass> &passes);