Lighting in Octane: HDRI
Lighting in 3D in is a tricky, yet incredibly important thing. The purpose of this series is to go over all the various types of lights from a high level, explain when and how to use them, and a bit about how to optimize them. The focus of this writeup is HDRI lighting.What is HDRI lighting?
HDRI lighting (also known as Image-based lighting) is a quick, easy way to introduce natural looking lighting and reflections in your scene. The concept here is that we take a Sky object, wrap a big image around the inside of it, and then use it to emit light, create reflections in the metallic and specular materials in the scene, and also serve as an overall background if needed. The HDRI sky can be used alone, or mixed in with other light sources.
HDRI stands for High Dynamic Range Image. The most common file format for one of these is an .HDR file. Files in this format contain light exposure data that flat files like PNG and JPEG do not have. You can put a PNG or JPEG or anything else in an Octane Sky, but it won't work well for lighting the objects a scene (see above). The JPG version is useful for compositing, though, which we'll get to later.
HDRIs are almost always in a 2:1 aspect ratio, and are bizarrely distorted when viewed flat. When they wrap around the sky sphere, the distortion goes away and they look fine.
Often you'll be presented with the option of getting different resolutions for the HDRI. Lower resolution files will load faster and take less time to render. Higher resolution ones will render sharper, but that's really only apparent in the background, and not so much in reflections. If you are only using it for lighting and reflections and plan to replace or obscure the background, a lower resolution version will help with render speed and will be nicer on the GPU's VRAM.
HDRI Workflow
First, we need an HDRI. There are free cc0 ones onhdrihaven.com(and a few other places), paid ones are available from various sources on the web. Make sure you get an .HDR file (or sometimes .EXR, but those are much larger and less efficient for this). Start with a 2K version. If it's too blurry, go up to a 4K. 16K isn't often needed unless the final output is large and the image is being used as a background.
Now we need an Octane Sky with an Environment tag to put the HDRI in.
First, under the Objects menu in the Live Viewer, select an HDRI Environment. This will make an Octane Sky object with an Octane Environment tag. Next, click the tag, and it should show up with a Texture field that's populated with an ImageTexture node.
This is the important part - the HDRI goes INSIDE the Image Texture Node. To do this, click the button that says ImageTexture - NOT the dropdown button to the left of it, and NOT the three dots to the right of it (those two things will replace the ImageTexture node which we don't want). Once in the ImageTexture node settings, now we can hit the three dots to the right of the field that says File and find the downloaded HDRI.
Recent versions of Octane have a Node Editor button at the bottom of the options in the Environment Tag that launches the Node Editor. This allows us to do some advanced processing on the image, or replace it out with whatever we want. For now, if we click this, we can see the basic structure. On the right is the Environment tag, and on the left is the ImageTexture node that's piped into it. The HDRI is loaded into the ImageTexture node rather than replacing it.
Go ahead and close the node editor for now.
Environment Tag Options
Here are some options you can adjust in the Environment tag itself.
Power is what is used to change the intensity of any light - this is useful if the HDRI is too dark or bright, or if it's being used in combination with other light sources.
Rot.X and Rot.Y: These rotate the HDRI. RotX shifts the image horizontally and RotY shifts it vertically. You can also just rotate the sky object. These values go from -1 to 0 to 1, so a clockwise 90 degree turn would be 0.25, a counterclockwise 180 degree turn would be -0.5, etc. Best to just grab the slider and move it until you like the lighting and placement of the image.
Medium Tab: Another cool thing you can do here is add volumetric fog to the whole scene. Go to the Medium tab of the Environment tag. Just hit the Add Fog button and it will set you up with a Scattering Medium node. You can then adjust settings like density and other things that are out of the scope of this document to get a general fog going in the scene.
AO Environment Texture: Changes the color of the Ambient Occlusion only if Direct Lighting with Ambient Occlusion is being used. It does nothing in Pathtracing or PMC modes.
Imp. Samp.: Helps reduce noise generated by HDRI lighting - leave it on.
Image Texture Options
The ImageTexture Node (what the .HDR file goes into) has its own options that complement the ones in the Environment Tag. Here are the relevant ones for HDRI lighting:Power: This node has its own field for Power which adds to the Power of the Environment tag. It's a good idea to just choose one place to edit the power and stick with it.
Gamma: Leave it at 1 for a properly made .HDR file. If a JPG or something else is being used, it will have to go to 2.2 to get it bright enough. Gamma has to do with Linear Workflow, which is a pretty complex topic for another writeup.
This ImageTexture node is the same one used when making materials, so it has the same options.
A UV Transform node can be added which controls the some of the properties of the HDRI. In the default setup, only X and Y Scale values (S.X, S.Y) and the Z rotation value (R.Z) do anything. This isn't super useful for a realistic scene, but in an abstract one, these can produce some really weird and cool results..
There's also the option to add a UV Projection node - if is changed to Cubic or Perspective, it will distort the image in fun ways.
The image can be color corrected, distorted, inverted, or modified in other ways with various nodes. The Octane Gradient in particular is very useful here. It can be used to recolor the image, or desaturated by using a black to white gradient.
Important caveat: As soon as any new nodes are added to this network, the RotX and RotY controls in the Environment tag won't work anymore. The rotation values for the Sky object itself in the Coords tab will also no longer work. In order to rotate the HDRI now, A UV Transform node must be hooked up to the ImageTexture node, and then the T.X and T.Y controls are now used to rotate the HDRI (NOT the R.X and R.Y)
Compositing
Now that the basics are covered, let's talk about the background. Until now we've been using the HDRI for lighting, reflections, and the background image, but through a few workflows here, we can pick and choose which of these we want to use.
The first image above is the basic setup we already covered. It's just an HDRI image in an ImageTexture node in an Environment Tag on an Octane Sky. The rest of these are a little trickier.
Alpha Background Setup
The first thing we might want to do is wipe out the background altogether and end up with an image (or sequence) that can placed over anything in post. For this, in the Octane settings, Alpha Channel needs to be enabled. The Keep Environment option should generally be left on, but in some cases where the environment bleeds through semitransparent pixels and it doesn't look good, that can be turned off.
Then in C4D's render settings, it's a good idea to choose a format that supports an alpha channel, like PNG, PSD, EXR or TIFF. If something like JPG is chosen, Octane will automatically create a separate file for each frame that's just the alpha mask that will need to be composited in post.
When Render to Picture Viewer is chosen, it will still show the background (and have a thin white line around the objects), but when viewed it in a post application (Photoshop, After Effects, etc), it will have a transparent background. Also note that Alpha affects ALL environments, so if there's a second environment being used as a Visible environment, that will also be matted out in the final render.
Background Replacement Setup
We can also completely replace the background with either another image, or something else like a solid color or a gradient. To do this, we'll need a second Octane Sky, which we can get by duplicating the one we have or getting a new one from the Objects Menu.The important thing here is to tell Octane which environment we want to be used for lighting and reflections (Primary environment, default), and which one we want to see as a background image (Visible environment). For the second sky, in the Environment Tag options, pick Visible environment from the Type dropdown.
If we were after a different image for our visible background, we could just go into the ImageTexture node and swap the HDRI with something else. In this case, a JPEG or PNG or something similar would do better than a .HDR image because we don't need all the extra exposure data. JPEGs are smaller and will be less resource intensive.
If we wanted a solid color like in the example, we just need to click the green circle icon under the word "Main" in the Environment Tag for our Visible environment. That replaces the ImageTexture node with an RGB Spectrum node. This is the same thing as choosing "Texture Environment" from the Objects menu in the Live Viewer. If we were to look at it in the Node Editor, it would now have an RGB Spectrum node piped into the Environment tag instead of an ImageTexture node.
Now we can click the white box in the RGB Spectrum section and change it to whatever color we want. We can also swap the RGB Spectrum out with a gradient by clicking the little dropdown carat to the left of where it says "RGB Spectrum", and selecting either a C4D Gradient, or in plugins>c4doctane>Gradient you can find an Octane Gradient.
The regular C4D one is fine for a quick background, but the Octane one is more useful if you're going to be doing anything more complicated with the node network. The gradient is tricky because it's covering the whole sky, so try dragging the gradient knots close together first, and then moving them both to the left or right until it looks right.
Shadow Catcher Setup
HDRI lights cast shadows from the brightest points in the texture. Until now we haven't seen that because we just have one object floating in space with a background image behind it. If we were to throw in a plane that our object could sit on so we can get shadows, that would show a shadow, but the plane itself would also show over the top of the HDRI, breaking the illusion. This is where the Shadow Catcher material comes into play. It will hide the geometry of the plane (or whatever it's applied to) and only show the shadows.We need to add a plane under our object and size it up to accommodate the shadows of all the objects in the scene. Next, we have to make an Octane Material (any type will do, but I always prefer Universal Materials for everything), and apply it to the plane. It doesn't matter what's turned on or off in the all the channels in this case, so just leave it at default.
Now the important part: We need to go to the Common section of the material and enable Shadow catcher. Now the material will only show shadows, and it will look like the object is sitting on the ground in the HDRI.
This trick works best with HDRIs with relatively smooth, flat ground textures like pavement. The shadow will be flat because it's being cast on a plane, so there won't be any interaction with, say, a tall grassy material or big cobblestones. If the ground plane is uneven, we could spend some time trying to mimic the contours by using a displacer deformer on the plane, or just rough up the edges of the shadow in post if we're in a hurry.
Mix Sky Texture Setup
Let's say we don't like the shadow quality that the HDRI produces, or we picked an abstract HDRI that we only want to use for reflections, but would prefer the the shadows and lighting come from another light source. We can achieve this by using an Octane Daylight Rig in conjunction with an HDRI Octane Sky.First, we need to make sure we have an Octane Sky with the Octane Environment tag on it and an HDRI loaded into the ImageTexture tag like we've done in all the previous setups. Having a plane with a shadow catcher material on it is useful as well to see the shadows.
Next, we can drop in an Octane DayLight rig in by going to the Live Viewer, and under Objects>Lights, choose Octane DayLight. This makes a C4D Infinite Light with a C4D Sun tag, and also an Octane DayLight tag on it. We can ignore the Sun tag and the Infinite Light settings. What we want to focus on is the Octane DayLight tag.
Here's the important part: In the DayLight's tag options, we need to enable Mix sky texture. This uses the HDRI from the Octane Sky as the background and reflections, but now lets us use the Infinite Light for lighting and shadows.
We can change the position of the light (and therefore shadows) by simply rotating the Infinite Light around. Rotating the light on the P axis (red handle) makes the sun rise and set (and colors it accordingly). Rotating it on the H axis changes the position of the sun in the sky. B doesn't do anything. If we want to be physically accurate about it, we'll need to match the position of the sun's light source with the one in the HDRI.
There are plenty of other options in the DayLight tag that we're going to go into in a different writeup, but the important ones here are the Power which makes it brighter or darker, and the Sun size, which makes the shadows sharper or more diffuse.
One interesting trick is that if we use this Mix sky texture method, we can turn the sun's power to zero, and then use other Octane Lights to light the scene and control the shadows while still keeping the reflections and background from the HDRI. This is essentially using the DayLight rig as an override so we can separate out the lights from the reflections, since there's no option to do this in the area lights themselves.
Everything (and then some) Setup
Should we get a little crazy? Let's get a little crazy.
This setup has:
- An Octane Sky with an HDRI in the ImageTexture node. That ImageTexture node has a Transform node hooked up to it that has the scale set to 0.25 so that the sky is repeated four times for some more variety in the reflections.
- A Plane object placed on the ground plane of the scene and given a shadow catcher material so the shadows will be visible.
- A second Octane Sky that is set to Visible Environment so it shows as the background, but still keeps the reflections and lighting from the HDRI. This second sky has the default ImageTexture node replaced with an Octane Gradient node with the Flame 6 preset (standard C4D gradient preset that's purple and blue). That Gradient was set to Radial (which creates a Sine Wave node to achieve this), and then the whole thing was given a Transform node to position it and a Texture Projection node which was set to Perspective to give it more fun distortion. Sounds complex, but Octane does most of this for us if you just hit a bunch of buttons in the Octane Gradient settings.- An Octane DayLight rig was then added just to override the lighting from the HDRI. The Mix sky texture checkbox was activated and the sun's power was brought to zero.
- Finally, a targeted Octane Area Light was added to give the scene its final lighting and shadows.
This particular result probably won't gain a whole lot of likes on Instagram, but it shows off how versatile all these objects are when used together.