Sub topic 8
Rotating the HDRI and setting its strength
This chapter assumes you can build the basic HDRI World shader (Texture Coordinate, Environment Texture, Background, World Output) from the previous chapter. It also assumes you can switch the viewport to Rendered shading to judge the result. Two controls decide how the HDRI lights your scene: a rotation that sets where the light comes from, and a strength that sets how much of it there is.
What each control changes
An HDRI stores light as a sphere of directions. Each pixel records how much light arrives from one direction.
- Rotation changes which direction each pixel is read from. It moves the bright areas, such as the sun or a window, around the scene. This changes shadow direction, which side of the subject is lit, and which reflections appear.
- Strength multiplies every pixel by the same number. It changes brightness only. The direction and contrast of the lighting stay the same.
Keep the two jobs separate. If the lighting looks wrong in shape, rotate. If it looks right in shape but too bright or dark, change strength.
Rotating with the Mapping node
The Environment Texture node has no rotation field of its own. Rotation comes from a Mapping node placed between Texture Coordinate and the texture's Vector input.
In the Mapping node:
- Leave Type as Point.
- Change only Rotation Z for normal work. This spins the HDRI around the vertical axis, like turning a globe on its stand.
- Leave Location and Scale alone. The environment is treated as infinitely far away, so Location has almost no visible effect. A Scale other than 1 stretches or repeats the image.
- Rotate X or Y only to fix an HDRI whose horizon is tilted. Doing this on purpose tilts the "sky" and makes the floor lighting look wrong.
The rotation turns the lookup direction, not the image. A positive angle therefore makes the picture appear to turn the opposite way from what you might expect. Do not memorize the sign. Switch the viewport to Rendered shading, drag the Z value, and watch where the shadows go.
Matching shadows to a visible sun
Many outdoor HDRIs contain a sun as a very bright spot. Rotate until the shadow under your subject falls where you want it. If you also use a Sun lamp, rotate the HDRI until its sun sits in the same direction as the lamp. Otherwise the scene has two shadows pointing different ways. The "Combining an HDRI with lamps" chapter covers that case. Here the rule is that the HDRI's rotation is the control you adjust, because the lamp is easier to leave where it is.
Rotation in degrees and radians
The Blender interface shows degrees. The Python API stores radians. Passing 90 to default_value[2] rotates by 90 radians, which is about 5157 degrees and looks like a random angle. Always convert with math.radians().
Setting strength on the Background node
The Strength value on the Background node is a plain multiplier.
- At 1.0 the scene receives the HDRI pixel values as stored.
- Each doubling adds one photographic stop of brightness. Each halving removes one.
| Strength | Change in stops | Typical use |
|---|---|---|
| 0.25 | -2 | Dim ambient fill under strong lamps |
| 0.5 | -1 | Soften an overly bright HDRI |
| 1.0 | 0 | Starting point |
| 2.0 | +1 | Boost a dull indoor HDRI |
| 4.0 | +2 | Bright HDRI for a dim scene |
Values above 1 are normal. HDRIs are high dynamic range, and the numbers inside them can be far larger than 1.0. A sun pixel can be thousands of times brighter than the sky.
Strength is not exposure
Strength changes how much light the scene receives, so it changes shading, shadows and reflections. Exposure, under Render Properties > Color Management, is applied to the finished image after rendering. If you use both to compensate for each other, the result is confusing. A practical order is:
- Set HDRI strength so the subject is lit plausibly.
- Set lamp power relative to that.
- Use exposure last, for the final look.
The camera sees the HDRI too
The Background node lights the scene and also paints the backdrop the camera sees. Raising strength to light a dark subject can therefore blow out the visible sky. There are two fixes:
- Turn on Film > Transparent to remove the backdrop from the final image. The HDRI still lights the scene.
- Mix two Background nodes with a Mix Shader, using the Is Camera Ray output of a Light Path node as the factor. This gives the camera one strength and the lighting another.
Setting both with Python
This script finds the existing Mapping and Background nodes in the World and sets rotation and strength. It assumes the setup from the previous chapter.
import bpy
import math
def set_hdri(rotation_z_deg, strength):
world = bpy.context.scene.world
if world is None or not world.use_nodes:
raise RuntimeError("The scene needs a World with use_nodes enabled")
nodes = world.node_tree.nodes
mapping = next((n for n in nodes if n.bl_idname == 'ShaderNodeMapping'), None)
background = next((n for n in nodes if n.bl_idname == 'ShaderNodeBackground'), None)
if mapping is None or background is None:
raise RuntimeError("Build the HDRI node setup first")
mapping.inputs['Rotation'].default_value[2] = math.radians(rotation_z_deg)
background.inputs['Strength'].default_value = strength
set_hdri(rotation_z_deg=135.0, strength=1.5)To turn the HDRI over time, for example to preview several sun positions, keyframe the Z component. The index=2 argument selects Z:
import bpy
import math
world = bpy.context.scene.world
mapping = next(n for n in world.node_tree.nodes if n.bl_idname == 'ShaderNodeMapping')
rotation = mapping.inputs['Rotation']
for frame, degrees in ((1, 0.0), (120, 180.0)):
rotation.default_value[2] = math.radians(degrees)
rotation.keyframe_insert(data_path="default_value", index=2, frame=frame)Blender interpolates between keyframes, so the sun appears to travel around the scene. This is a quick way to compare lighting directions in a single render sequence.
Common mistakes
- Rotating the wrong axis. If shadows do not move horizontally, or the horizon tilts, you changed X or Y. Reset them to 0 and use Z.
- Rotating the object instead of the HDRI. Rotating your subject changes how it faces the light, not where the light comes from. Both are valid, but only the Mapping node moves the reflections of the sky consistently with everything else.
- Radians versus degrees in scripts. An unexpected angle after running a script is almost always this.
- Missing Texture Coordinate or Mapping link. If rotation has no effect, check that the Mapping output actually connects to the Environment Texture's Vector input.
- Using strength to fix an off-center sun. A dim side means the sun is behind the subject. Rotate rather than brighten.
- Over-high strength with a visible backdrop. The sky clips to white. Lower strength, enable Film Transparent, or use the Is Camera Ray split.
Exercise
A scene lit by an HDRI looks correct in shape, but the subject is one stop too dark and the sun's shadow falls toward the camera when you want it to fall to the right. What do you change on the Mapping node and on the Background node, and why those two controls?
Show answer
Rotate the HDRI with Rotation Z on the Mapping node until the shadow falls to the right, because rotation changes the light direction. Then raise Strength on the Background node from 1.0 to 2.0, because each doubling adds one stop. Do the rotation first, since moving the sun can change how bright the subject looks.
Exercise
A script sets mapping.inputs['Rotation'].default_value[2] = 90 to turn the HDRI a quarter turn, but the lighting looks arbitrary. What is wrong, and what is the corrected line?
Show answer
The API stores rotation in radians, so 90 means 90 radians (about 5157 degrees). The corrected line is mapping.inputs['Rotation'].default_value[2] = math.radians(90.0), with import math at the top.