Skip to content

Commit 322b78f

Browse files
author
Steven Garcia
committed
Improve skylight generator a bit.
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.
1 parent 420d90e commit 322b78f

File tree

2 files changed

+159
-12
lines changed

2 files changed

+159
-12
lines changed

io_scene_halo/misc/__init__.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,21 @@ class Scale_ModelPropertiesGroup(PropertyGroup):
145145
)
146146

147147
class SkyPropertiesGroup(PropertyGroup):
148+
sun_yaw: FloatProperty(
149+
name="Sun Yaw",
150+
description="Set the yaw for the sun.",
151+
default=0.0,
152+
min=0.0,
153+
max=360.0
154+
)
155+
156+
sun_pitch: FloatProperty(
157+
name="Sun Pitch",
158+
description="Set the pitch for the sun.",
159+
default=0.0,
160+
min=0.0,
161+
max=360.0
162+
)
148163
zenith_color: FloatVectorProperty(
149164
name = "Zenith Color",
150165
description = "Set the color around the bottom rim of the hemisphere",
@@ -254,6 +269,12 @@ def draw(self, context):
254269
box.label(text="Generate Skylights:")
255270
col = box.column(align=True)
256271
row = col.row()
272+
row.label(text='Sun Yaw:')
273+
row.prop(scene_halo_sky, "sun_yaw", text='')
274+
row = col.row()
275+
row.label(text='Sun Pitch:')
276+
row.prop(scene_halo_sky, "sun_pitch", text='')
277+
row = col.row()
257278
row.label(text='Zenith Color:')
258279
row.prop(scene_halo_sky, "zenith_color", text='')
259280
row = col.row()
@@ -363,7 +384,7 @@ def execute(self, context):
363384
from io_scene_halo.misc import generate_hemisphere
364385
scene = context.scene
365386
scene_halo_sky = scene.halo_sky
366-
return global_functions.run_code("generate_hemisphere.generate_hemisphere(scene_halo_sky.zenith_color, scene_halo_sky.horizon_color, scene_halo_sky.strength)")
387+
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)")
367388

368389
class ExportLightmap(Operator, ExportHelper):
369390
"""Write a LUV file"""

io_scene_halo/misc/generate_hemisphere.py

Lines changed: 137 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,160 @@
2828

2929
from math import degrees, radians
3030

31+
columm_rot = 14.65
32+
column_elements = 26
33+
row_rot = 12.5
34+
row_elements = 8
35+
3136
def interpolate_color(color_a, color_b, steps):
3237
color_list = []
3338
rdelta, gdelta, bdelta = (color_b[0]-color_a[0])/steps, (color_b[1]-color_a[1])/steps, (color_b[2]-color_a[2])/steps
34-
r1 = color_a[0]
35-
g1 = color_a[1]
36-
b1 = color_a[2]
39+
r1, g1, b1 = color_a[0], color_a[1], color_a[2]
3740
color_list.append(color_a)
3841
for step in range(steps):
3942
r1 += rdelta
4043
g1 += gdelta
4144
b1 += bdelta
4245
color_list.append((r1, g1, b1))
46+
4347
color_list.append(color_b)
48+
4449
return color_list
4550

46-
def generate_hemisphere(zenith_color, horizon_color, strength):
51+
def get_center_point(rotation, is_x_axis):
52+
light_spacing = row_rot
53+
if is_x_axis:
54+
light_spacing = columm_rot
55+
56+
sun_id = round(rotation / light_spacing)
57+
58+
return sun_id
59+
60+
def get_percentages(rotation, is_x_axis, color_loops):
61+
62+
light_spacing = row_rot
63+
max_elements = row_elements
64+
if is_x_axis:
65+
light_spacing = columm_rot
66+
max_elements = column_elements
67+
68+
percentage_list = []
69+
postitive_space_list = []
70+
negative_space_list = []
71+
sun_id = round(rotation / light_spacing)
72+
postive_space = max_elements - sun_id + 1
73+
74+
if color_loops:
75+
halved_elements = round(max_elements / 2)
76+
for idx in range(halved_elements):
77+
percentage = 1 / halved_elements
78+
if idx > 0:
79+
percentage = percentage * (idx + 1)
80+
81+
if idx == halved_elements - 1:
82+
percentage = 1.0
83+
84+
negative_space_list.append(percentage)
85+
postitive_space_list.append(percentage)
86+
87+
postitive_space_list.reverse()
88+
89+
starting_point_list = []
90+
if sun_id > halved_elements:
91+
92+
starting_point_list_reversed = []
93+
for idx in range(sun_id - halved_elements):
94+
starting_point_list_reversed.append(negative_space_list[idx])
95+
96+
starting_point_list_reversed.reverse()
97+
starting_point_list = starting_point_list_reversed
98+
99+
for idx in range(sun_id - halved_elements):
100+
starting_point_list.append(negative_space_list[idx])
101+
102+
middle_point_list_reversed = []
103+
for idx in range(max_elements - sun_id):
104+
middle_point_list_reversed.append(postitive_space_list[idx])
105+
106+
middle_point_list_reversed.reverse()
107+
starting_point_list = starting_point_list + middle_point_list_reversed
108+
109+
for idx in range(max_elements - sun_id):
110+
starting_point_list.append(postitive_space_list[idx])
111+
112+
else:
113+
for idx in range(sun_id):
114+
starting_point_list.append(negative_space_list[(idx + 1 ) * -1])
115+
116+
starting_point_list.reverse()
117+
118+
for idx in range(halved_elements):
119+
starting_point_list.append(postitive_space_list[idx])
120+
121+
for idx in range(max_elements - (halved_elements + sun_id)):
122+
starting_point_list.append(negative_space_list[idx])
123+
124+
percentage_list = starting_point_list
125+
126+
else:
127+
for idx in range(sun_id):
128+
percentage = 1 / sun_id
129+
if idx > 0:
130+
percentage = percentage * (idx + 1)
131+
132+
if idx == sun_id - 1:
133+
percentage = 1.0
134+
135+
negative_space_list.append(percentage)
136+
137+
for idx in range(postive_space):
138+
percentage = 1 / postive_space
139+
if idx > 0:
140+
percentage = percentage * (idx + 1)
141+
142+
if not percentage == 1.0:
143+
postitive_space_list.append(percentage)
144+
145+
postitive_space_list.reverse()
146+
percentage_list = negative_space_list + postitive_space_list
147+
148+
return percentage_list
149+
150+
def darken_color(color, light_x_idx, light_y_idx, percentage_list_y, percentage_list_x):
151+
percentage_y = percentage_list_y[light_y_idx]
152+
percentage_x = percentage_list_x[light_x_idx]
153+
color_r, color_g, color_b = (color[0], color[1], color[2])
154+
color_r_y, color_g_y, color_b_y = (color_r * percentage_y), (color_g * percentage_y), (color_b * percentage_y)
155+
color_r_xy, color_g_xy, color_b_xy = ((color_r_y * percentage_x), (color_g_y * percentage_x), (color_b_y * percentage_x))
156+
return (color_r_xy, color_g_xy, color_b_xy)
157+
158+
def generate_hemisphere(zenith_color, horizon_color, strength, sun_yaw, sun_pitch):
159+
percentage_list_y = get_percentages(sun_yaw, False, False)
160+
percentage_list_x = get_percentages(sun_pitch, True, True)
161+
162+
sun_row_id = get_center_point(sun_yaw, False)
163+
sun_column_id = get_center_point(sun_pitch, True)
164+
47165
color_list = interpolate_color(zenith_color, horizon_color, 6)
48-
object_list = []
49-
for light_row in range(26):
50-
for light in range(8):
51-
rot_tuple = (radians(90 + (12.5 * light)), 0, radians(18 * light_row))
52-
name = 'skylight_%s' % (light + (8 * light_row))
166+
167+
for light_column in range(column_elements):
168+
for light_row in range(row_elements):
169+
rot_tuple = (radians(90 + (row_rot * light_row)), 0, radians(columm_rot * light_column))
170+
name = 'skylight_%s' % (light_row + (8 * light_column))
171+
53172
light_data = bpy.data.lights.new(name, "SUN")
54173
object_mesh = bpy.data.objects.new(name, light_data)
55174
bpy.context.collection.objects.link(object_mesh)
56-
object_mesh.data.color = color_list[light]
57-
object_mesh.data.energy = strength
175+
58176
object_mesh.rotation_euler = rot_tuple
177+
if light_column == sun_column_id and light_row == sun_row_id:
178+
print("%s is the sun point. Beat the shit out of him!!!" % name)
179+
object_mesh.data.energy = 0.000047
180+
object_mesh.data.color = (1.0, 1.0, 1.0)
181+
182+
else:
183+
object_mesh.data.energy = strength
184+
object_mesh.data.color = darken_color(color_list[light_row], light_column, light_row, percentage_list_y, percentage_list_x)
59185

60186
return {'FINISHED'}
61187

0 commit comments

Comments
 (0)