Skip to content

Commit

Permalink
add option to sync sun and sky gain
Browse files Browse the repository at this point in the history
  • Loading branch information
Theverat committed Mar 18, 2018
1 parent 792fdf3 commit 48fa82f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
4 changes: 4 additions & 0 deletions export/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ def convert_world(world, scene):
if world.luxcore.sun:
definitions["dir"] = _calc_sun_dir(world.luxcore.sun)

if world.luxcore.use_sun_gain_for_sky:
gain = [x * world.luxcore.sun.data.luxcore.gain for x in world.luxcore.rgb_gain]
definitions["gain"] = gain

if world.luxcore.sun and world.luxcore.sun.data:
# Use sun turbidity so the user does not have to keep two values in sync
definitions["turbidity"] = world.luxcore.sun.data.luxcore.turbidity
Expand Down
2 changes: 1 addition & 1 deletion properties/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def update_is_laser(self, context):
##############################################
# BlendLuxCore specific properties needed to translate LuxCore light concepts to Blender
sun_types = [
("sun", "Sun", "Sun", 0),
("sun", "Sun", "Physically correct sun that emits parallel light rays and changes color with elevation", 0),
("distant", "Distant", "Distant star without atmosphere simulation (emits parallel light)", 1),
]
sun_type = EnumProperty(name="Sun Type", items=sun_types, default="sun")
Expand Down
7 changes: 7 additions & 0 deletions properties/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
VISIBILITYMAP_ENABLE_DESC,
)

USE_SUN_GAIN_FOR_SKY_DESC = (
"Use the gain setting of the attached sun "
"(so you adjust both sun and sky gain at the same time)"
)

def init():
bpy.types.World.luxcore = PointerProperty(type=LuxCoreWorldProps)
Expand All @@ -33,6 +37,9 @@ class LuxCoreWorldProps(bpy.types.PropertyGroup):

# sky2 settings
sun = PointerProperty(name="Sun", type=bpy.types.Object, description="Used to specify the sun direction")
# Only shown in UI when light is sky2 and a sun is attached
use_sun_gain_for_sky = BoolProperty(name="Use Sun Gain", default=True,
description=USE_SUN_GAIN_FOR_SKY_DESC)
turbidity = FloatProperty(name="Turbidity", default=2.2, min=0, max=30)
groundalbedo = FloatVectorProperty(name="Ground Albedo", default=(0.5, 0.5, 0.5), min=0, max=1, subtype="COLOR")
ground_enable = BoolProperty(name="Use Ground Color", default=False)
Expand Down
27 changes: 21 additions & 6 deletions ui/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ def draw(self, context):
layout.prop(world.luxcore, "light", expand=True)

if world.luxcore.light != "none":
# TODO: id (light group)
split = layout.split(percentage=0.33)
split.prop(world.luxcore, "rgb_gain", text="")
split.prop(world.luxcore, "gain")
# TODO: id (light group)

is_sky = world.luxcore.light == "sky2"
has_sun = world.luxcore.sun and world.luxcore.sun.type == "LAMP"

if is_sky and has_sun and world.luxcore.use_sun_gain_for_sky:
split.prop(world.luxcore.sun.data.luxcore, "gain")
else:
split.prop(world.luxcore, "gain")

if is_sky and has_sun:
split.prop(world.luxcore, "use_sun_gain_for_sky")

layout.label("Default Volume (used on materials without attached volume):")
utils_ui.template_node_tree(layout, world.luxcore, "volume", ICON_VOLUME,
Expand Down Expand Up @@ -54,10 +64,15 @@ def draw(self, context):
world = context.world

layout.prop(world.luxcore, "sun")
sun_obj = world.luxcore.sun
if sun_obj and sun_obj.data and sun_obj.data.type == "SUN":
layout.label("Using turbidity of sun light:", icon="INFO")
layout.prop(sun_obj.data.luxcore, "turbidity")
sun = world.luxcore.sun
if sun:
is_really_a_sun = sun.type == "LAMP" and sun.data and sun.data.type == "SUN"

if is_really_a_sun:
layout.label("Using turbidity of sun light:", icon="INFO")
layout.prop(sun.data.luxcore, "turbidity")
else:
layout.label("Not a sun lamp", icon="ERROR")
else:
layout.prop(world.luxcore, "turbidity")

Expand Down

0 comments on commit 48fa82f

Please sign in to comment.