Skip to content

Commit

Permalink
Merge branch 'hdri' into testing
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderRitter02 committed Jul 4, 2022
2 parents 1ba28a6 + 64bf91c commit 0c398d4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
14 changes: 4 additions & 10 deletions HDRI/hdri.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,9 @@ def set_background_brightness(new_strength : float) -> None:

# set if the background light should affect the objects
# the parameter "is_affecting" decides it
# Adapted from https://blender.stackexchange.com/questions/154928/use-hdri-without-lighting-the-scene/171096#171096
def background_brightness_affects_objects(is_affecting : bool) -> None:
world = bpy.data.worlds["World"]
if is_affecting:
world.cycles_visibility.diffuse = True
world.cycles_visibility.glossy = True
world.cycles_visibility.transmission = True
world.cycles_visibility.scatter = True
else:
world.cycles_visibility.diffuse = False
world.cycles_visibility.glossy = False
world.cycles_visibility.transmission = False
world.cycles_visibility.scatter = False
world.cycles_visibility.diffuse = is_affecting
world.cycles_visibility.transmission = is_affecting
world.cycles_visibility.scatter = is_affecting
10 changes: 10 additions & 0 deletions Lightning/light_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import math
from Lightning.light_class import *
from utils import *
from HDRI.hdri import background_brightness_affects_objects
#from camera_animation_module import *

# delete all lights
Expand All @@ -11,6 +12,15 @@ def delete_all_lights() -> None:
if ob.type == 'LIGHT':
ob.select_set(True)
bpy.ops.object.delete()

def lights_enabled(is_light: bool) -> None:
if is_light:
print("Enabling lights, disabling background lighting")
background_brightness_affects_objects(False)
else:
delete_all_lights()
print("Deleting all lights, enabling background lighting")
background_brightness_affects_objects(True)

# delete the lights in "lights"-array (the elements are objects)
def delete_lights(lights: list[Light]) -> None:
Expand Down
13 changes: 6 additions & 7 deletions gui/gui_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from gui.properties import VERSION_PATCH, VERSION_MAJOR, VERSION_MINOR, UPDATE_URL
from camera_animation import camera_animation_module as cammod

from Lightning.light_functions import day_light, night_light, delete_lights, lantern_light, day_night_cycle, delete_all_lights, delete_light_animation
from Lightning.light_functions import day_light, night_light, delete_lights, lantern_light, day_night_cycle, delete_all_lights, delete_light_animation, lights_enabled
from Lightning.light_class import Light
from HDRI.hdri import set_background_brightness, background_brightness_affects_objects
from materials.materials import *
Expand Down Expand Up @@ -694,8 +694,7 @@ def get_background_strength(self) -> None:

# lights will be deleted
def lights_off(self) -> None:
delete_all_lights()
self.is_day_night.set(False)
lights_enabled(False)
self.control.re_render()

# set daytime value to "value"
Expand Down Expand Up @@ -725,14 +724,14 @@ def fit_brightness_to_lights(self) -> None:
return
case _:
self.set_lantern()


# returns the brightness
def get_brightness(self) -> float:
return self.brightness

# some setting that should be made before creating new lights
def standard_light_settings(self, use_light_type: int) -> None:
lights_enabled(True)
self.use_light_type = use_light_type
self.is_day_night.set(False)
delete_lights(self.light_objects)
Expand All @@ -748,7 +747,7 @@ def set_night(self) -> None:
self.standard_light_settings(1)
self.light_objects = night_light(self.get_brightness(), self.get_daytime() * self.TIME_TO_ANGLE_CONSTANT, True, self.control.camera)
self.control.re_render()

# set lantern light
def set_lantern(self) -> None:
self.standard_light_settings(2)
Expand Down Expand Up @@ -776,7 +775,8 @@ def switch_day_night_circle(self):
# def set_frame(self, value):
# bpy.context.scene.frame_current = int(value)
# self.control.re_render()



class BackgroundControl(Frame):
def __init__(self, master, control):
Frame.__init__(self, master, borderwidth=2, relief="groove")
Expand Down Expand Up @@ -904,7 +904,6 @@ class PointCloudObjects(enum.Enum):
CUBE = "cube"
DISK = "disk"


class RightPanel(Frame):

def __init__(self, master, control):
Expand Down
4 changes: 2 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def set_preview_render(self,
self.scene.view_layers[0].cycles.use_denoising = False
self.scene.cycles.use_adaptive_sampling = True
self.scene.cycles.samples = num_samples
self.scene.render.use_persistent_data = True
self.scene.render.use_persistent_data = False
self.scene.cycles.max_bounces = 4
self.scene.cycles.tile_size = 4096
self.scene.cycles.time_limit = 0.3
Expand All @@ -155,7 +155,7 @@ def set_final_render(self,
self.scene.view_layers[0].cycles.use_denoising = True
self.scene.cycles.use_adaptive_sampling = True
self.scene.cycles.samples = num_samples
self.scene.render.use_persistent_data = True
self.scene.render.use_persistent_data = False
self.scene.cycles.max_bounces = 12
self.scene.cycles.tile_size = 2048
self.scene.cycles.use_fast_gi = False
Expand Down

0 comments on commit 0c398d4

Please sign in to comment.