Skip to content

Commit

Permalink
Improve skylight generator a bit.
Browse files Browse the repository at this point in the history
Weaken the color of the skylights further away from the sun point.

Mess with rotation value a bit so that sunlights don't overlap

Generate a single white skylight for our shadows.

Allow users to define the sun in their scene through yaw and pitch. Will need something to represent this somehow.
  • Loading branch information
Steven Garcia committed Sep 24, 2021
1 parent 420d90e commit 322b78f
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 12 deletions.
23 changes: 22 additions & 1 deletion io_scene_halo/misc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,21 @@ class Scale_ModelPropertiesGroup(PropertyGroup):
)

class SkyPropertiesGroup(PropertyGroup):
sun_yaw: FloatProperty(
name="Sun Yaw",
description="Set the yaw for the sun.",
default=0.0,
min=0.0,
max=360.0
)

sun_pitch: FloatProperty(
name="Sun Pitch",
description="Set the pitch for the sun.",
default=0.0,
min=0.0,
max=360.0
)
zenith_color: FloatVectorProperty(
name = "Zenith Color",
description = "Set the color around the bottom rim of the hemisphere",
Expand Down Expand Up @@ -254,6 +269,12 @@ def draw(self, context):
box.label(text="Generate Skylights:")
col = box.column(align=True)
row = col.row()
row.label(text='Sun Yaw:')
row.prop(scene_halo_sky, "sun_yaw", text='')
row = col.row()
row.label(text='Sun Pitch:')
row.prop(scene_halo_sky, "sun_pitch", text='')
row = col.row()
row.label(text='Zenith Color:')
row.prop(scene_halo_sky, "zenith_color", text='')
row = col.row()
Expand Down Expand Up @@ -363,7 +384,7 @@ def execute(self, context):
from io_scene_halo.misc import generate_hemisphere
scene = context.scene
scene_halo_sky = scene.halo_sky
return global_functions.run_code("generate_hemisphere.generate_hemisphere(scene_halo_sky.zenith_color, scene_halo_sky.horizon_color, scene_halo_sky.strength)")
return global_functions.run_code("generate_hemisphere.generate_hemisphere(scene_halo_sky.zenith_color, scene_halo_sky.horizon_color, scene_halo_sky.strength, scene_halo_sky.sun_yaw, scene_halo_sky.sun_pitch)")

class ExportLightmap(Operator, ExportHelper):
"""Write a LUV file"""
Expand Down
148 changes: 137 additions & 11 deletions io_scene_halo/misc/generate_hemisphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,160 @@

from math import degrees, radians

columm_rot = 14.65
column_elements = 26
row_rot = 12.5
row_elements = 8

def interpolate_color(color_a, color_b, steps):
color_list = []
rdelta, gdelta, bdelta = (color_b[0]-color_a[0])/steps, (color_b[1]-color_a[1])/steps, (color_b[2]-color_a[2])/steps
r1 = color_a[0]
g1 = color_a[1]
b1 = color_a[2]
r1, g1, b1 = color_a[0], color_a[1], color_a[2]
color_list.append(color_a)
for step in range(steps):
r1 += rdelta
g1 += gdelta
b1 += bdelta
color_list.append((r1, g1, b1))

color_list.append(color_b)

return color_list

def generate_hemisphere(zenith_color, horizon_color, strength):
def get_center_point(rotation, is_x_axis):
light_spacing = row_rot
if is_x_axis:
light_spacing = columm_rot

sun_id = round(rotation / light_spacing)

return sun_id

def get_percentages(rotation, is_x_axis, color_loops):

light_spacing = row_rot
max_elements = row_elements
if is_x_axis:
light_spacing = columm_rot
max_elements = column_elements

percentage_list = []
postitive_space_list = []
negative_space_list = []
sun_id = round(rotation / light_spacing)
postive_space = max_elements - sun_id + 1

if color_loops:
halved_elements = round(max_elements / 2)
for idx in range(halved_elements):
percentage = 1 / halved_elements
if idx > 0:
percentage = percentage * (idx + 1)

if idx == halved_elements - 1:
percentage = 1.0

negative_space_list.append(percentage)
postitive_space_list.append(percentage)

postitive_space_list.reverse()

starting_point_list = []
if sun_id > halved_elements:

starting_point_list_reversed = []
for idx in range(sun_id - halved_elements):
starting_point_list_reversed.append(negative_space_list[idx])

starting_point_list_reversed.reverse()
starting_point_list = starting_point_list_reversed

for idx in range(sun_id - halved_elements):
starting_point_list.append(negative_space_list[idx])

middle_point_list_reversed = []
for idx in range(max_elements - sun_id):
middle_point_list_reversed.append(postitive_space_list[idx])

middle_point_list_reversed.reverse()
starting_point_list = starting_point_list + middle_point_list_reversed

for idx in range(max_elements - sun_id):
starting_point_list.append(postitive_space_list[idx])

else:
for idx in range(sun_id):
starting_point_list.append(negative_space_list[(idx + 1 ) * -1])

starting_point_list.reverse()

for idx in range(halved_elements):
starting_point_list.append(postitive_space_list[idx])

for idx in range(max_elements - (halved_elements + sun_id)):
starting_point_list.append(negative_space_list[idx])

percentage_list = starting_point_list

else:
for idx in range(sun_id):
percentage = 1 / sun_id
if idx > 0:
percentage = percentage * (idx + 1)

if idx == sun_id - 1:
percentage = 1.0

negative_space_list.append(percentage)

for idx in range(postive_space):
percentage = 1 / postive_space
if idx > 0:
percentage = percentage * (idx + 1)

if not percentage == 1.0:
postitive_space_list.append(percentage)

postitive_space_list.reverse()
percentage_list = negative_space_list + postitive_space_list

return percentage_list

def darken_color(color, light_x_idx, light_y_idx, percentage_list_y, percentage_list_x):
percentage_y = percentage_list_y[light_y_idx]
percentage_x = percentage_list_x[light_x_idx]
color_r, color_g, color_b = (color[0], color[1], color[2])
color_r_y, color_g_y, color_b_y = (color_r * percentage_y), (color_g * percentage_y), (color_b * percentage_y)
color_r_xy, color_g_xy, color_b_xy = ((color_r_y * percentage_x), (color_g_y * percentage_x), (color_b_y * percentage_x))
return (color_r_xy, color_g_xy, color_b_xy)

def generate_hemisphere(zenith_color, horizon_color, strength, sun_yaw, sun_pitch):
percentage_list_y = get_percentages(sun_yaw, False, False)
percentage_list_x = get_percentages(sun_pitch, True, True)

sun_row_id = get_center_point(sun_yaw, False)
sun_column_id = get_center_point(sun_pitch, True)

color_list = interpolate_color(zenith_color, horizon_color, 6)
object_list = []
for light_row in range(26):
for light in range(8):
rot_tuple = (radians(90 + (12.5 * light)), 0, radians(18 * light_row))
name = 'skylight_%s' % (light + (8 * light_row))

for light_column in range(column_elements):
for light_row in range(row_elements):
rot_tuple = (radians(90 + (row_rot * light_row)), 0, radians(columm_rot * light_column))
name = 'skylight_%s' % (light_row + (8 * light_column))

light_data = bpy.data.lights.new(name, "SUN")
object_mesh = bpy.data.objects.new(name, light_data)
bpy.context.collection.objects.link(object_mesh)
object_mesh.data.color = color_list[light]
object_mesh.data.energy = strength

object_mesh.rotation_euler = rot_tuple
if light_column == sun_column_id and light_row == sun_row_id:
print("%s is the sun point. Beat the shit out of him!!!" % name)
object_mesh.data.energy = 0.000047
object_mesh.data.color = (1.0, 1.0, 1.0)

else:
object_mesh.data.energy = strength
object_mesh.data.color = darken_color(color_list[light_row], light_column, light_row, percentage_list_y, percentage_list_x)

return {'FINISHED'}

Expand Down

0 comments on commit 322b78f

Please sign in to comment.