REALISTIC LIGHTING WITH LDRI IMAGES (FAKING HDRI)

INTRODUCTION

One of the biggest inventions in the last few years in realistic lighting solutions is the appearance of HDRI images and lighting the scenes with them. In my first tutorial on mentalray thematic, I have described the way how to use hdri images to light up the scene. As you already learned in that tutorial, the scene setup for the hdri lighting is not the problem. You just need to put the sphere and map the hdri image on it. If you have the collection of hdri images in on your comp, and these images are just the ones that you need, then you don't have anything to worry about. The problem comes in the situations where you need to create your own hdri image. Why is this a problem? Because if you want to create the hdri image, you will need to take bunch of images of the same scene with different exposures. When you do that, the program, like HDRIShop, calculates the final color in the image and creates hdri image. And what if you have made a lot of panorama pictures that you want to use as your light maps, or you don't want to bother with process of creating HDRI images? Well, there are some tricks when using ldri images, that we will explore in this tutorial, which will help us to get the lighting similar to the lighting with hdri images

As you probably know In HDRI image, some parts of image can be brighter than 255 level used in ldri images. These brighter areas are the main source of light emission from the hdri image. This can not be achieved with ldri images, because ldri can't emit the light more than 255 level of brightness..

For this tutorial you will need Maya with mentalray for scene setup and rendering, HDRI Shop with few hdri images to measure the light level and Photoshop to create the bitmaps for color scaling.

In our first step we will examine one HDRI images with HDRIShop. This will help us to measure how much is the light (sun) brighter than the rest of the HDRI image. In the second part we will go through process of creating color scale maps, and in the last part of the tuto we will see how to setup the shader for our faked hdri lighting.

MEASURING LIGHT SCALE VALUE IN HDRI SHOP

So, let's go and measure lighting level of our HDRI image (see the next image). I will use one hdri image from www.cgtechniques.com named salettl.hdr. Start the HDRIShop. Import in HDRIShop your hdri image. As you can see, the big part of the image is white. These are the parts where light brightness goes above the 255 levels. To find out how much brighter these areas are you must go to the View > Exposure > Costum. The exposure menu will pop up, with slider bar in it. Move slowly this slider in the left direction to the point where sun starts to lose it's white color and becomes gray. In the informations below the slider is the box where the Scale information is shown. This information is important since it shows how much we must multiply the white color in ldri image to get the brightness like in the hdri image. Now with your calculator divide number 1 with that value (mine is 0.15). The result should be somewhere around 6.6. Remember this value since this is the value with which we will multiply the parts of LDRI image where sun is.

 

Measuring the brightness of the Sun

 

CREATING SCALE MAPS IN PHOTOSHOP

Now that the light brightness mesauring is finished we must create the scale maps in photoshop. What are scale maps? They are grayscale image maps that are used to scale the original ldri image. At this moment we will learn how to create them, and later we will create the shading network in maya using these maps, and then you will see how does scale map work. To create the scale maps you need to have the ldri image with which you want to light up your scene. If you have some panorama images, that would be ideal image for that job, but now, to make things a little bit simple, we will use one of the images that my friend has taken at the sea... download it by clicking on the image or the link. Since we don't use the image of the sun at day, we would have to use different sun scale value from that one which you calculated above.

DOWNLOAD THE IMAGE FILE

The image that we will use for lighting the scene

 

As you can see from this picture, the main source of light energy in the scene comes from the sun. In the picture the sun has the color brightness somewhere around 255 which is the maximum value that LDRI image can store, but in real world it is much much brighter than this. If this would be the hdri image, then the brightness of the sun would have much higher values. If we examine the picture a little bit more and think about the similar situations in real world, we would get to conclusion that next stronger energy emitter in the image is the sky and the last one would be the mountains and the sea. That means that we must create three different scale maps, one for each one of the elements that we mentioned above.

Now that we've analyzed the picture, we can get busy and create the scale maps. Of course, this has to be done in Photoshop, so start it and load the picture from above.

First thing we will do is that we will create the scale map for the sun. Create new layer and name it Sun scale. Now pick the Elliptical Marquee Tool from the toolbar and mark the part of the image where the sun is. Check if the new layer is selected, and if it isn't select it.

Selecting the sun

 

Now go to the Edit > Fill. In the Contens > Use select White and click OK. This will create the circle filled with white color. Now we must fill the remaining section with black color. To do this go to the Select > Inverse and then again to the Edit > Fill, but now select the Black color. At the moment the image should look like this:

Created scale map for the sun

 

This can be our scale map for the sun, but we will make one more step to make things more realistic. What we want to do is to add a little glow around the bright sun spot. To do this duplicate the SunScale layer. The photoshop will name it SunScale copy and it will probably be placed above the SunScale layer. Now select this copy and go to the Filter > Blur > Gaussian Blur. Set Radius to 10 and click OK. This will blur up the image very strong. Our original layer (SunScale) is not visible at this moment, and it should be mixed with its blurred copy to get the right effect, so select the SunScale copy layer and change the Blending mode from Normal to Lighten. As you would see, the glow appears around sun. Since we would like to make it a little bit more brighter, we will go to the Image > Adjustments > Levels. When menu pops up, set the middle input box of Input Levels option to 1.3 and click OK. The image should look like this:

To make things more realistic, we added the glow around sun

 

Next scale map image would be the sky. So turn of the SunScale layer for the sun, and from the toolbox select the Lasso Tool. Select the sky area, like I did in picture below:

Selecting the sky in the image

 

Now create new layer and name it SkyScale. Fill it with white color as you did it before ... go to the Edit > Fill, in the Contens > Use select White and click OK. This will fill up the sky with white color. To fill the rest of the area with black color you have to go to the Select > Inverse to make inverse selection, and the again go to the Edit > Fill menu, select the Black color and click OK. The image should look like this:

Created scale map for the sky

 

To make image a little bit smoother we will apply a little blur filter. Go to the Filter > Blur > Blur More. This will smooth up image a little bit. Now we will do the same glow trick as we did for the sun. Duplicate the layer, then on this duplicated layer apply the Gaussian Blur filter with Radius of 10, and change it's blending mode to Lighten. The image should look like this:

A little glow effect for the skyscale map

 

We don't need the last scale map for the mountains and sea since it is of constant color, which means that we can do it easily in Maya.

Last thing we have to do here is to save these maps. First, turn off the SkyScale layers and turn on SunScale layers. When you do this go to the File > Save As and save the scale map for the sun. Then turn on the SkyScale layers and save this map also.

So let's go to maya and see what we can do with these scale maps ... double click on my, and probably yours favorite software ;)

CREATING SHADING NETWORK IN MAYA

Welcome to the beautifull empty (at the start) world of Maya. ;) What we must do is to fill up the scene with something like object. Since we want to make things as simple as we can, we will use some primitive nurbs objects from maya, and lately you can try to build and shade more complex scenes. Just download the scene that I created, the link is below. In the ZIP file are two images sunscale, and skyscale that we created in the section above, so if you don't have it you can use this ones.

DOWNLOAD THE SCENE (for maya 4.5)

Scene that we will use as our example

 

Open the scene with maya. You will probably see few primitive objects in the scene. There is also half of the sphere around the scene that will be used to light up the objects. This sphere doesn't have any material applied to it, but this is the step we have to do. If you examine the scene a little bit more, you'll see that there are few blinn shaders that are attached to the objects (spheres, cones, torus ) in the scene. These materials have some reflectivity so that it can reflect the scene around it. I have also set the mentalray final gather options ... you can see it in Render View> Options > RenderGlobals (MentalRay) > mentalrayOptions1 > Final Gather. If you have passed through my first tutorial, you'll probably know what these parameters are used for, if you didn't it would be wise to go and read it. ;) Ok now that I have explained a few things about this scene setup, let's go to work...

I hope you know a little bit about hypershade and how to use it. I'll go step by step and explain the process of building this type of shading network but you need some experience, so if you don't have an idea of what hypershade is read the manuals that comes with maya and come back to my tuto. ;)

Open the hypershade window Windows > Rendering Editors > Hypershade, or you could open the hypershade window in one of your viewports Panels > Panel > Hypershade. Now that you have opened the hshade, select the half of the sphere around scene and in hypershade windows select Graph > Graph Materials on Selected Objects. When you do this in the Work Area of the hypershade window the shading network will apear as in next picture:

The hypershade window which we will use to build our shading network

 

This means that initial lambert1 shader is attached to the sphere. Since we don't want this, we will create new surface shader to serve our big half-sphere. So what surface shader should we use? This time we will choose the Surface Shader since we don't need the lambert or blinn shaders because the material of our half sphere doesn't need to react with the light. Yes, I have used the Lambert shader in my first global illumination tutorial, but I have learned a few other things since then. ;) But, before you create Surface Shader, increase the space for Work Area, go to the Tabs > Show Bottom Tabs Only, and also clear the Work Area by clicking on Graph > Clear Graph. We will leave the tab on the left where nodes are since we have to use them very often.

Ok, for our first step, with your middle mouse button from the bar on left pull the Surface Shader in your Work Area. Now we have to attach this shader to our sphere so select the sphere and the right click (and hold) on the surfaceShader (hypershade Work Area) and select Assign Material To Selection. This will attach our shader to the sphere. You can check if it is attached to the sphere by clicking on the sphere and then in Hypershade select Graph > Graph Materials on Selected Objects. If the surfaceShader material appears in the Work Area of hypershade, then you have done it correctly.

Let's explain a little bit how does surface shader with half-sphere affect the scene. By default surface shader produces the black color of the surface on which it is attached to. If you render the scene at this moment you'll get the black picture. But, you can easily change this by changing output color of the surface shader. To do this double click on the surface shader icon in the work area of the hypershade, or click one time on it and press Ctrl+A. This will bring the new window on your screen named Attribute Editor: Surface Shader. Now in the Surface Shader Attributes move the slider of the Out Color to the right, somewhere in to the middle. Chose MentalRay as default renderer and render the scene. After the renderer has done its job the shaded scene appears in the render view. It should look like this:

Shading with simple gray color of the sphere

 

Yes, we created illumination of the scene but it is sooo boooring. ;) So let's go and attach the image of the sun to surface shader color Out Color. First, from the nodes menu on the left with your middle mouse button click and drop the File node (small red rectangle) in to the working area . The file node appears in the work area (marked with the big red rectangle)

Creating the image node which we will attach to the surfaceShader

 

After you have done this you must connect the file node to the surface shader. To do this press and hold CTRL and with your middle mouse button click - hold on the file node and drop it to the surface Shader node. If you did it right, the green line should appear between these two nodes, and if you point your mouse over the green line it should say what attribute of the file node is connected to the surface Shader, just like in this picture:

OutColor of file node is attached to the OutColor of the surfaceShader node

 

As you can see green line connects the output color from the file node to the out color of the surface Shader. Since the file node doesn't have any file attached to it, it produces black color. To change this double click on the file node. The attribute editor of the file will pop up. Let's just rename it to get more organization in our shading network... on the top of the attribute editor where the "file:" is, type the name "LDRI Image". Now in the File Attributes section at in the Image Name attribute press on the little folder icon and select our image. The shading network in the work area of the hypershade should look like this:

Pointing the LDRI_Image node to the image file that we will use for lighting.

 

Now do one quick test render. Wow, that looks much much better than before. But, there is one small problem, the image is not mapped correctly on to the sphere. To correct this, select the surface Shader node in the work area and click on the Graph > Input Connections. The new node will appear in the work area which is connected to the LDRI_Image node, and is named something like place2DTexture, just like in picture:

Expanding the connections to the LDRI_Image note so that we can see the place2DTexture node to correct the mapping direction.

 

Double click on the place2DTexture to bring up it's Attribute Editor. After it opens, change the Rotate Frame parameter to the 90. This will rotate the mapped image for 90 degrees and it should correct the problem. We will do one test render to see if it is corrected now.

Lighting with simple LDRI image

 

Mmmm... very nice. Now, this is what you get when you try to illuminate the scene with ldri image. If you would have done it with HDRI image the sun and sky would probably be much more brighter than they are now. This is where our scale maps come in place. With them we will increase the brightness of these areas and try to get more realistic results. Let's go back to hypershade...

First, we will attach the SunScale image to the LDRI_Image node. To do this double click on to the LDRI image node to open the Attribute Editor. In the Attrib. editor at the Color Balance section click on to the small box on the right side of the Color Offset attribute:

Connecting the SunScale to the ColorOffset attribute of LDRI_Image

After the click, new window will pop up, named Create Render Node. In that window, open the Texture section. Then, turn off the "With New Texture Placement" Option and in 2D Textures click on to the File. At this moment, the new file node is created and it is connected to the Color Offset option of the LDRI_Image node. To see the whole shading network in the work area of the hypershade select the surface Shader node and click Graph > Input Connections. The shading network should look like this:

The shading network with SkyScale node

 

Since new file node doesn't have any place2Dtexture node connected to it, it would be mapped with the default parameters of placement, and we don't want this to happen since it will not be correctly rotated, just like the LDRI_Image node was before. And, since we have the correct place2Dtexture node with the right rotation values, we will connect it to the fresh created file node. Remember that place2DTexture node can be attached to as many nodes as you want, but they must be from the 2D Texture section. Press and hold CTRL and with your middle mouse button drag from place2DTexture and drop to the File node. This will create the connection to the file, like in picture:

Connecting place2dtexture to our new file node

 

The file node is empty, and that means that we must point it to the image file. Double click on the file node to open attribute editor. First, rename this node to something like Sun_Scale, then click on the small folder icon on the right side of the Image Name attribute and select the sunscale.tga image. We did it, the first scale map is attached to image. ;) If you do a test render at this moment the rendered image should be similar to the one without scale map, but there is one little difference, the sun looks much brighter than in original picture. ;)

Without scale map
With Sunscale map attached to original image

 

Let's explain things a little bit more. The Color Offset can be used to increase the color values of the original image. This means that if the pixel x in the original image has the color of RGB 0.2 0.2 0.2, and if we increase the Color Offset value to 0.5 0.5 0.5, then the brightness of the pixel x will be offset to the color value of 0.7 0.7 0.7. So, if we connect the image (sunscale) to the Color Offset of the original image, where the sunscale image is black it will not offset the color in original image, but in the areas where the sunscale image is white it will offset the color of the original image by 1. I hope you understand what I'm talking about? :)

At the end, we will also connect the last scale map, named skyscale.tga, to our shading network. To do this, in work area of hypershade view double click on the SunScale node. When attribute editor opens, in the Color Balance section click on the little Box on the right side of Color Offset slider. In Create Render Node window at the Texture > 2D Textures section click on File. This will create the new file node ... and the attribute editor for the node will be automatically opened when you do this. Rename this node to Sky_Scale and in the File Attributes section > Image Name click on the folder icon on the right side of this attribute. Select the skyscale.tga image and click ok. The shading network should look like this:

Connecting the SkyScale node to the SunScale

 

As you probably know, we must connect the place2DTexture node to the Sky_Scale node to get the correct mapping. So, with CTRL pressed, drag with middle mouse button the place2dTexture node and drop it to Sky_Scale node.

The final shading network for illumination

 

Now our shader has been build up correctly. How does this shading network works? Well, as you see the Sky_Scale image node is connected to the SunScale Color Offset attribute and the Sun_Scale is connected to the LDRI_Image Color Offset attribute. This means that where the Sky_Scale image is white it does the offset to the Sun_Scale image, and where the Sky_Scale image is black it doesn't. After the Sun_Scale image has been offseted, the Sun_Scale node does the same thing to the LDRI_Image image. So with this kind of setup, where the Sky Scale and Sun_Scale is black it doesn't scale the LDRI_Image. Where the Sky_Scale is white and Sun_Scale is black it does the offset to original image of 1. This means that if the pixel color of the original image has the color of RGB 0.7 0.3 0.1, with the offset it will have 1.7 1.3 1.1. And, where the Sky_Scale and Sun_scale is white it does the offset of 2 to the original image. With this trick we're simulating the effect that HDRI image has ... and that means that we are increasing the brightness of the image to values higher than 255 levels. ;) Enough of this, let's see what will we get if we do a test render:

Scaled LDRI image, but to bright.

 

Very nice, but in my opinion the sky is too bright. We can easily control the brightness of the sun, sky and the other parts of the image. How? Well, let's try this for the sky. Double click on the Sky_Scale image node to open the attribute editor. In the Color Balance section, move the Color Gain slider to the middle (GrayColor). This will decrease the sky brightness level. Ok, now remember the first part of tutorial where we calculated the sun scale value? ;) Yes, we will use it here ... double click on the Sun_Scale node to open attribute editor. Then in the Color Balance section click on the color Box on the left side of the Color Gain slider. The color chooser will pop up. In the Sliders section where it says V set the value to somewhere around 5. This will scale up the part of the original image where the sun is. That means, that areas where the white color in sunscale.tga image is, that part in the original image will be scaled by 5 (+ the scaling value of the skyscale). Let's do one test render.

Decreasing the skyscale value and increasing the sunscale value.

 

There it is... but, it is not over yet. ;) You can also decrease the brightness of the original image by going in to the attribute editor of the LDRI_Image node and in the Color Balance section move the Color Gain slider to the middle of the line. And here it is, the final image:

Final image with correct values of scale maps

 

I hope you have understand what I was talking about in this tutorial. The technique I showed you goes one step ahead compared to HDRI images, because you can have brightness control of every part in the LDR image. Remember that in the HDR images you can only change the exposition value. Ok, maybe my technique is not as real as the illumination with HDRI images, but it is not too far away from that. I just want to point out that this was a simple example, so be free to experiment with scale maps. For example you can try to use the scale map with gradient for the sky ... that will for sure give the interesting effect.

Well, happy rendering and faking. ;) I hope this tutorial helped a little bit...

Bye bye till next time... ;)


Toni Bratincevic - toni@interstation3d.com - http://www.interstation3d.com