Skip to content

Commit

Permalink
preparation for switching to Blender 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwlouse committed May 16, 2022
1 parent d10a74d commit ea9556f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
8 changes: 6 additions & 2 deletions challenges/complex_brdf/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,14 @@ def add_material(name, obj, **properties):
color = (rand_color[0], rand_color[1], rand_color[2], 1)

if FLAGS.rubber:
add_material('Rubber', object, Color=color)
add_material('Rubber', object, Color=color)
if bpy.app.version > (3, 0, 0):
object.visible_shadow = False
else:
object.cycles_visibility.shadow = False

else:
add_material('MyMetal', object, Color=color)
add_material('MyMetal', object, Color=color)

# --- Saving state; WARNING: uses a lot of disk space
# logging.info("Saving 'scene.blend' file...")
Expand Down
5 changes: 4 additions & 1 deletion challenges/multiview_matting/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ def add_hdri_dome(scene, background_hdri=None):
blender_renderer = [v for v in scene.views if isinstance(v, Blender)]
if blender_renderer:
dome_blender = dome.linked_objects[blender_renderer[0]]
dome_blender.cycles_visibility.shadow = False
if bpy.app.version > (3, 0, 0):
dome_blender.visible_shadow = False
else:
dome_blender.cycles_visibility.shadow = False
if background_hdri is not None:
dome_mat = dome_blender.data.materials[0]
texture_node = dome_mat.node_tree.nodes["Image Texture"]
Expand Down
6 changes: 5 additions & 1 deletion examples/shapenet.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import logging
import numpy as np
import bpy

import kubric as kb
from kubric.renderer import Blender
Expand Down Expand Up @@ -33,7 +34,10 @@
# Make the floor transparent except for catching shadows
# Together with background_transparency=True (above) this results in
# the background being transparent except for the object shadows.
floor.linked_objects[renderer].cycles.is_shadow_catcher = True
if bpy.app.version > (3, 0, 0):
floor.linked_objects[renderer].is_shadow_catcher = True
else:
floor.linked_objects[renderer].cycles.is_shadow_catcher = True

# --- Keyframe the camera
scene.camera = kb.PerspectiveCamera()
Expand Down
4 changes: 3 additions & 1 deletion kubric/renderer/blender.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ def use_denoising(self) -> bool:
@use_denoising.setter
def use_denoising(self, value: bool):
self.blender_scene.cycles.use_denoising = value
self.blender_scene.cycles.denoiser = "NLM"
if bpy.app.version < (3, 0, 0):
# NLM is removed since Blender 3. TODO: check if denoising still works
self.blender_scene.cycles.denoiser = "NLM"

@property
def samples_per_pixel(self) -> int:
Expand Down
27 changes: 19 additions & 8 deletions kubric/renderer/blender_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,33 @@ def add_coordinate_material():
return mat


def activate_render_passes(normal: bool = True,
optical_flow: bool = True,
segmentation: bool = True,
uv: bool = True):
def activate_render_passes(
normal: bool = True,
optical_flow: bool = True,
segmentation: bool = True,
uv: bool = True,
depth: bool = True
):

# We use two separate view layers
# 1) the default view layer renders the image and uses many samples per pixel
# 2) the aux view layer uses only 1 sample per pixel to avoid anti-aliasing

# TODO(klausg): commented no-op line below, delete?
# default_view_layer = bpy.context.scene.view_layers[0]
# Starting in Blender 3.0 the depth-pass must be activated separately
if depth:
default_view_layer = bpy.context.scene.view_layers[0]
default_view_layer.use_pass_z = True

aux_view_layer = bpy.context.scene.view_layers.new("AuxOutputs")
aux_view_layer.samples = 1 # only use 1 ray per pixel to disable anti-aliasing
aux_view_layer.use_pass_z = False # no need for a separate z-pass
aux_view_layer.material_override = add_coordinate_material()
object_coords_aov = aux_view_layer.aovs.add()
if hasattr(aux_view_layer, 'aovs'):
object_coords_aov = aux_view_layer.aovs.add()
else:
# seems that some versions of blender use this form instead
object_coords_aov = aux_view_layer.cycles.aovs.add()

object_coords_aov.name = "ObjectCoordinates"
aux_view_layer.cycles.use_denoising = False

Expand Down Expand Up @@ -401,7 +412,7 @@ def bpy_mesh_object_to_trimesh(obj):

return tmesh


# NLM is removed since Blender 3. TODO: check if denoising works
def center_mesh_around_center_of_mass(obj):
tmesh = bpy_mesh_object_to_trimesh(obj)

Expand Down

0 comments on commit ea9556f

Please sign in to comment.