Skip to content

Commit

Permalink
sun and sky now use a separate gain property with default 0.00002 to …
Browse files Browse the repository at this point in the history
…prevent overexposion with default tonemapper settings
  • Loading branch information
Theverat committed Feb 19, 2020
1 parent c98247b commit 3f923f6
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 11 deletions.
21 changes: 15 additions & 6 deletions export/light.py
Expand Up @@ -489,21 +489,18 @@ def _convert_luxcore_world(exporter, scene, world, is_viewport_render):
definitions["ground.color"] = list(world.luxcore.ground_color)
definitions["groundalbedo"] = list(world.luxcore.groundalbedo)

gain = apply_exposure(gain, world.luxcore.exposure)
if world.luxcore.sun and world.luxcore.sun.data:
# Use sun turbidity and direction so the user does not have to keep two values in sync
definitions["turbidity"] = world.luxcore.sun.data.luxcore.turbidity
definitions["dir"] = _calc_sun_dir(world.luxcore.sun.matrix_world)
if world.luxcore.use_sun_gain_for_sky:
sun = world.luxcore.sun.data
gain, importance, lightgroup_id = _convert_common_props(exporter, scene, sun)
gain = apply_exposure(gain, sun.luxcore.exposure)
gain, _, _ = _convert_common_props(exporter, scene, sun)
definitions["gain"] = apply_exposure(gain, sun.luxcore.exposure)
else:
# Use world turbidity
definitions["turbidity"] = world.luxcore.turbidity

definitions["gain"] = gain

elif light_type == "infinite":
if world.luxcore.image:
transformation = Matrix.Rotation(world.luxcore.rotation, 4, "Z")
Expand Down Expand Up @@ -536,7 +533,19 @@ def _calc_sun_dir(transform):


def _convert_common_props(exporter, scene, light_or_world):
gain = [light_or_world.luxcore.gain] * 3
if isinstance(light_or_world, bpy.types.Light):
if light_or_world.type == "SUN" and light_or_world.luxcore.light_type == "sun":
raw_gain = light_or_world.luxcore.sun_sky_gain
else:
raw_gain = light_or_world.luxcore.gain
else:
# It's a bpy.types.World
if light_or_world.luxcore.light == "sky2":
raw_gain = light_or_world.luxcore.sun_sky_gain
else:
raw_gain = light_or_world.luxcore.gain

gain = [raw_gain] * 3
importance = light_or_world.luxcore.importance
lightgroup_id = scene.luxcore.lightgroups.get_id_by_name(light_or_world.luxcore.lightgroup)
exporter.lightgroup_cache.add(lightgroup_id)
Expand Down
4 changes: 3 additions & 1 deletion operators/general.py
Expand Up @@ -195,7 +195,9 @@ def poll(cls, context):
return context.scene.world and context.object

def execute(self, context):
context.scene.world.luxcore.sun = context.object
world = context.scene.world
world.luxcore.sun = context.object
world.update_tag()
return {"FINISHED"}


Expand Down
13 changes: 13 additions & 0 deletions properties/light.py
Expand Up @@ -73,6 +73,16 @@
RELSIZE_DESC = "1.0 is the apparent size of the sun when observed from earth (at mean distance of 149,600,000 km)"
THETA_DESC = "Half angle in degrees. Larger values make the light source appear larger and the shadows softer"
NORMALIZE_DISTANT_DESC = "Make the brightness received at surfaces independent from the size of this light"
SUN_SKY_GAIN_DESC = (
"Brightness multiplier. Set to 1 for physically correct sun/sky brightness, "
"if you also use physically based tonemapper and light settings"
)

PHYSICALLY_BASED_INTENSITY_DESC = (
"If enabled, the true sun/sky brigthness is used, which is useful if you also work with physical light units "
"and tonemapper settings in the rest of the scene. If disabled, the sun/sky gain is multiplied with 0.00002 "
"to prevent overexposed outdoor renders when using the default tonemapper settings"
)


class LuxCoreLightProps(bpy.types.PropertyGroup):
Expand Down Expand Up @@ -118,8 +128,11 @@ def update_is_laser(self, context):
# TODO: check min/max, add descriptions

# sun, sky2
sun_sky_gain: FloatProperty(name="Gain", default=0.00002, min=0, precision=6, description=SUN_SKY_GAIN_DESC)
turbidity: FloatProperty(name="Turbidity", default=2.2, min=0, max=30,
description=TURBIDITY_DESC)
use_physically_based_intensity: BoolProperty(name="Use Physically Based Intensity", default=False,
description=PHYSICALLY_BASED_INTENSITY_DESC)

# sun
relsize: FloatProperty(name="Relative Size", default=1, min=1,
Expand Down
3 changes: 2 additions & 1 deletion properties/world.py
@@ -1,5 +1,4 @@
import bpy
import math
from bpy.props import (
PointerProperty, EnumProperty, FloatProperty,
FloatVectorProperty, IntProperty, BoolProperty,
Expand All @@ -10,6 +9,7 @@
GAMMA_DESCRIPTION, SAMPLEUPPERHEMISPHEREONLY_DESCRIPTION,
LIGHTGROUP_DESC, TURBIDITY_DESC, VIS_INDIRECT_DIFFUSE_DESC,
VIS_INDIRECT_GLOSSY_DESC, VIS_INDIRECT_SPECULAR_DESC,
SUN_SKY_GAIN_DESC,
)
from .image_user import LuxCoreImageUser
from .config import ENVLIGHT_CACHE_DESC
Expand Down Expand Up @@ -67,6 +67,7 @@ def poll_sun(self, obj):
sun: PointerProperty(name="Sun", type=bpy.types.Object,
poll=poll_sun, # The poll method filters the objects in the scene
description=SUN_DESC)
sun_sky_gain: FloatProperty(name="Gain", default=0.00002, min=0, precision=6, description=SUN_SKY_GAIN_DESC)
# 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)
Expand Down
5 changes: 4 additions & 1 deletion ui/light.py
Expand Up @@ -112,7 +112,10 @@ def draw_luxcore_settings(self, context):
layout.prop(light.luxcore, "normalizebycolor")
else:
col = layout.column(align=True)
col.prop(light.luxcore, "gain")
if light.type == "SUN" and light.luxcore.light_type == "sun":
col.prop(light.luxcore, "sun_sky_gain")
else:
col.prop(light.luxcore, "gain")
col.prop(light.luxcore, "exposure", slider=True)

col = layout.column(align=True)
Expand Down
11 changes: 9 additions & 2 deletions ui/world.py
Expand Up @@ -55,10 +55,17 @@ def draw_luxcore_settings(self, context):

col = layout.column(align=True)
if is_sky and has_sun and world.luxcore.use_sun_gain_for_sky:
col.prop(world.luxcore.sun.data.luxcore, "gain")
sun = world.luxcore.sun.data
if sun.type == "SUN" and sun.luxcore.light_type == "sun":
col.prop(sun.luxcore, "sun_sky_gain")
else:
col.prop(sun.luxcore, "gain")
col.prop(world.luxcore.sun.data.luxcore, "exposure", slider=True)
else:
col.prop(world.luxcore, "gain")
if is_sky:
col.prop(world.luxcore, "sun_sky_gain")
else:
col.prop(world.luxcore, "gain")
col.prop(world.luxcore, "exposure", slider=True)

if is_sky and has_sun:
Expand Down

0 comments on commit 3f923f6

Please sign in to comment.