Skip to content

Commit

Permalink
refactors lighting out of main render function (#730)
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesfrye authored May 3, 2024
1 parent 8ff22cc commit 03c44cb
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions 06_gpu_and_ml/blender/blender_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,30 +107,8 @@ def render(angle: int = 0) -> bytes:
add_prism(ctx, (-2.07, -1, 0), 45, angle, iridescent_material)
add_prism(ctx, (2.07, 1, 0), -45, angle, iridescent_material)

# set up the lighting
# warm key light
bpy.ops.object.light_add(type="POINT", location=(5, 5, 5))
key_light = bpy.context.object
key_light.data.energy = 100
key_light.data.color = (1, 0.8, 0.5) # warm

# tight, cool spotlight
bpy.ops.object.light_add(type="SPOT", radius=1, location=(4, 0, 6))
spot_light = bpy.context.object
spot_light.data.energy = 500
spot_light.data.spot_size = 0.5
spot_light.data.color = (0.8, 0.8, 1) # cool
spot_light.rotation_euler = (3.14 / 4, 0, -3.14 / 4)

# soft overall illumination
bpy.ops.object.light_add(type="AREA", radius=3, location=(-3, 3, 5))
area_light = bpy.context.object
area_light.data.energy = 50 # softer
area_light.data.size = 5 # larger
area_light.data.color = (1, 1, 1) # neutral
area_light.rotation_euler = (3.14 / 2, 0, 3.14)

# add camera
# add lighting and camera
add_lighting()
bpy.ops.object.camera_add(location=(7, -7, 5))
scene.camera = bpy.context.object
ctx.object.rotation_euler = (1.1, 0, 0.785)
Expand Down Expand Up @@ -335,3 +313,29 @@ def create_iridescent_material():
links.new(mix_shader_node.outputs["Shader"], output_node.inputs["Surface"])

return mat


def add_lighting():
import bpy

# warm key light
bpy.ops.object.light_add(type="POINT", location=(5, 5, 5))
key_light = bpy.context.object
key_light.data.energy = 100
key_light.data.color = (1, 0.8, 0.5) # warm

# tight, cool spotlight
bpy.ops.object.light_add(type="SPOT", radius=1, location=(4, 0, 6))
spot_light = bpy.context.object
spot_light.data.energy = 500
spot_light.data.spot_size = 0.5
spot_light.data.color = (0.8, 0.8, 1) # cool
spot_light.rotation_euler = (3.14 / 4, 0, -3.14 / 4)

# soft overall illumination
bpy.ops.object.light_add(type="AREA", radius=3, location=(-3, 3, 5))
area_light = bpy.context.object
area_light.data.energy = 50 # softer
area_light.data.size = 5 # larger
area_light.data.color = (1, 1, 1) # neutral
area_light.rotation_euler = (3.14 / 2, 0, 3.14)

0 comments on commit 03c44cb

Please sign in to comment.