Final: Auto three point lighting set up
Final: Auto 3 point lighting set up
The idea:
This final assignment was pretty free form. I had a couple ideas that I wanted to explore, but I ended up wanting to make an automatic three point lighting set up. When showing off a model one of the most common lighting set ups is a three point one. I thought this would be something that could be useful in quickly setting up some lighting that could be customized.
The process:
I ended up using chatgpt as a tool for this assignment. It offered interesting starting places.
Notes:
I first tried to use the position of the camera to auto update the locations of the lights, i wanted them to rotate around the subject with the camera. I was thinking of using expressions with mel or using condition nodes, however I ended up not going down that route and the lights would be set up around the subject once and could be set up again by running the script again.
I used the xform function to get the position of the subject, I used chatgpt to get a couple iterations that used xform to position the lights around the subject.
I found out about extract world bounding box. This command figures out an exact-fit bounding box for the specified objects (or selected objects if none are specified) This bounding box is always in world space.
I started using this in my iterations with chat gpt. It produced some interesting results and got me much closer to what I was looking for. But I had trouble understanding how it was working.
I did not allow myself enough time to full get this script working, this ended up being more challenging to figure out than I was expecting.
import maya.cmds as cmds
# Create Arnold area lights pointing at the subject
def create_area_light(name, intensity, color, position, target):
light = cmds.shadingNode('aiAreaLight', asLight=True)
cmds.setAttr(light + '.intensity', intensity)
cmds.setAttr(light + '.color', color[0], color[1], color[2], type='double3')
cmds.setAttr(light + '.translateX', position[0])
cmds.setAttr(light + '.translateY', position[1])
cmds.setAttr(light + '.translateZ', position[2])
cmds.setAttr(light + '.rotateX', -90) # Rotate the light to point downward
cmds.setAttr(light + '.rotateY', 0)
cmds.setAttr(light + '.rotateZ', 0)
# Aim the light at the target (subject)
aim_constraint = cmds.aimConstraint(target, light, aimVector=(0, -1, 0), upVector=(0, 0, 1))
cmds.setAttr(aim_constraint[0] + '.offsetX', 0) # Adjust the offset if needed
cmds.rename(light, name)
return light
# Create a locator for the subject and position it in the scene
subject_locator = cmds.spaceLocator(name="subject_locator")[0]
cmds.setAttr(subject_locator + '.translateX', 0)
cmds.setAttr(subject_locator + '.translateY', 0)
cmds.setAttr(subject_locator + '.translateZ', 0)
# Create key, fill, and rim lights above the ground plane aiming at the subject
key_light = create_area_light("key_light", 2.0, [1.0, 1.0, 1.0], [0, 10, 0], subject_locator)
fill_light = create_area_light("fill_light", 1.0, [0.5, 0.5, 0.5], [0, 10, 5], subject_locator)
rim_light = create_area_light("rim_light", 1.5, [1.0, 0.0, 0.0], [5, 10, 0], subject_locator)
# Create a ground plane
ground_plane = cmds.polyPlane(width=20, height=20)[0]
cmds.setAttr(ground_plane + '.translateY', -1)
# Create a camera and aim it at the subject
camera = cmds.camera(name="camera")[0]
cmds.setAttr(camera + '.translateY', 5)
cmds.setAttr(camera + '.translateZ', 15)
cmds.aimConstraint(subject_locator, camera, aimVector=(0, 0, -1), upVector=(0, 1, 0))
# Group the lights, camera, and subject locator for organization
light_group = cmds.group([key_light, fill_light, rim_light], name="light_group")
camera_group = cmds.group([camera, subject_locator], name="camera_group")
# Set the render resolution
cmds.setAttr("defaultResolution.width", 1920)
cmds.setAttr("defaultResolution.height", 1080)
# Set Arnold as the render engine
cmds.setAttr("defaultRenderGlobals.currentRenderer", "arnold", type="string")
# Assign a simple shader to the ground plane (you can replace this with your own materials)
shader = cmds.shadingNode('lambert', asShader=True)
shading_group = cmds.sets(renderable=True, noSurfaceShader=True, empty=False)
cmds.select(ground_plane)
cmds.hyperShade(assign=shader)
# Set up the render settings
cmds.setAttr("defaultArnoldRenderOptions.AASamples", 4)
cmds.setAttr("defaultArnoldRenderOptions.GIDiffuseSamples", 3)
cmds.setAttr("defaultArnoldRenderOptions.GISpecularSamples", 2)
cmds.setAttr("defaultArnoldRenderOptions.GITransmissionSamples", 2)
cmds.setAttr("defaultArnoldRenderOptions.GIVolumeSamples", 2)
# Set up the render camera
cmds.setAttr("defaultRenderGlobals.imageFormat", 7) # JPEG format
cmds.setAttr("defaultRenderGlobals.outFormatControl", 0) # Use render settings
cmds.setAttr("defaultRenderGlobals.animation", 0) # Single frame render
cmds.setAttr(camera + ".renderable", 1) # Make the camera renderable
print("Three-point lighting setup with Arnold area lights created.")
This script makes the three lights and is supposed to be closer to the ground plane and aimed towards the locator. The locator is meant to be where the subject is.
This script also sets the camera up to be renderable. It makes a ground plane and sets up a simple shader.
The camera is aim constrained to the subject locator.
There are many issues with this code that if I had managed my time better I would have tried to fix. The lights are broken an aim away from the subject locator instead of towards and they are too high up above the subject.
Comments
Post a Comment