Model rendering with Milkshape and POV-Ray 3.5

Copyright (C)2003 Neil Jedrzejewski
(Email)

Rendering your model with POV-Ray

Assuming your model is built and your materials and textures are all assigned, you can now export your model as a POV-Ray include file for inclusion in your rendering scene.

Creating the include file

The include file is a simple text document that can be edited in POV-Ray or any other text editor. The plug-in will export ALL of your object groups from Milkshape, even hidden ones so delete any objects you dont want to be exported first. Then simply go to the File -> Export menu and select "POV-Ray 3.5 Include File...", select a filename and the export is done

Using non BMP textures

***UPDATED IN VERSION 1.1***

Version 1.1 now recognises the bitmap format of the textures assigned to your models and will set the type flag accordingly in the include file.

The plug-in assumes BMP format for any texture it doesnt recognise and sets it as such in the include file. POV-Ray supports GIF, TGA, PPM, PGM, PNG, JPG or TIFF as well as BMP format so if your texture is one of these its type flag will be set by the plug-in.

If you should need to change texture format, open up your include file and at the top, you will find the material definition list. It will look something like this:

// Begin Textures Definitions

// Material: "Material04"
#declare uvtexture_0 = texture{
    uv_mapping pigment{
        image_map{
            sys ".\lilies.jpg"
            map_type 0
            interpolate 2
            transmit all 0.000000
        }
    }
    finish{
        ambient rgb <0.200000 0.200000 0.200000>
        specular 0.000000
        roughness 0.000000
    }
}

Its the line marked in red that we're interested in. As you can see the filename is a JPG but the file format type is marked as "sys" which is a system format. In the case of Windows, this would mean a BMP file. To use other file formats, we need to replace the word "sys" with the right keyword for the file type we're using. The keywords are:

In our above example, we are using a JPEG file so we need to alter the code as follows:

// Begin Textures Definitions

// Material: "Material04"
#declare uvtexture_0 = texture{
    uv_mapping pigment{
        image_map{
            jpeg ".\lilies.jpg"
            map_type 0
            interpolate 2
            transmit all 0.000000
        }
    }
    finish{
        ambient rgb <0.200000 0.200000 0.200000>
        specular 0.000000
        roughness 0.000000
    }
}

You sould repeat the above steps for all the materials in your model that use non-BMP format textures.

Using the sample scene

OK, so we have our exported include file ready with all the texture maps set to the correct format. Now we need to render it!

Included with the plug-in is a sample POV-Ray scene. This gives a fairly generic rendering environment you can tweak to produce pictures of your models.

First of all, I recommend making a working folder for your renders so that you can keep everything together. Into this working folder copy your generated include file, from the "samples" folder the "sample_scene.pov" file and any texture files that your model needs.

Now we're ready to render so start-up POV-Ray 3.5. If this is the first time you've used POV-Ray you'll see that it opens a LOT of files by default. This is indicated by the tabs along the top. We're not going to need all these files so use the close button on the toolbar and close all of them except the "Messages" tab. It should look something like this:

Now, open the "sample_scene.pov" file and your include file in POV-Ray and then click on the "sample_scene.pov" tab so that it is back in focus. It should look like this:

Next stage is to tell the scene to include our exported include file. If you scroll down sample_scene in the editor window you should see the following code:

/* included our model */
#include "model.inc"          // file name of exported include file

What we're interested in is the red part. You need to change this to the filename of your exported include file. If you copied it to the same folder as "sample_scene.pov" you just need to add the filename, but if you saved it somewhere else you will need include the full path to it or POV-Ray won't be able to find it. For example:

/* included our model */
#include "c:\my models\model.inc"          // file name of exported include file

OK, now assuming you've set the file name of your include file your ready to do a test render! First of all select your output resolution from the drop down on the top left. I usually use "640x480, AA 0.3" which gives a good sized render with anti-aliasing.

Ok, that done, make sure that "sample_scene.pov" is the currently selected tab and press the green "Run" icon on the toobar and your render should start!

ARRRGGGH!!!! Its all gone wrong!

If your render didnt start its likely you got an error. The "Messages" tab will give you more details but here are the most common.

POV-Ray stopped, high-lighting the #include "model.inc" line.

POV-Ray can't find your model include file. Either copy it to the same folder as the "sample_scene.pov" file and just use the filename, or make sure you specify the full path to it.

POV-Ray stopped, high-lighting a line with a texure filename in my include file.

When the plug-in exports the materials, it includes any path info stored with the texture filename in Milkshape. Basically POV-Ray is saying it cant find your texture file. You will either need to edit the line to include the full path to your texture file or copy it to the same folder as your "sample_scene.pov" file and use just the filename in the include file.

POV-Ray rendered, but the output window is all black.

Chances are you didnt have the "sample_scene.pov" file active as the selected tab and instead you've tried to render the include file. Make sure that "sample_scene.pov" is selected and run the render again. The other possibility is your model is so large your actually inside it and its just dark.

Moving, rotating and scaling your model

OK, assuming all went well you should now have at least a very basic render of your model on screen. However theres a good chance you need to move it around a bit to get the desired effect. By making some small edits to the "sample_scene.pov" file, we can sort our model out.

Moving the model

By default, the model is placed at 0, 0, 0 within the scene. Assuming your model was orientated correctly in Milkshape and didnt fall below the ground plane, you should be able to see it all. However, if your rendering something like a posed Half-Life model, its possible part of it is below ground.

We can therefore move the model around in our scene by editing the following piece of code in our "sample_scene.pov" file.

object {
    milkshape_model
    translate <0,0,0>
    //rotate <-90,180,0>
    scale <-1,1,1>
}

The line is red is the one we want. This moves or "translates" the object in the X, Y and Z planes. For example, if we were rendering a posed Day of Defeat model, they have a tendancy to be below the ground. So we need to move them up vertically (Y plane). We can do this by changing the line to:

object {
    milkshape_model
    translate <0,17,0>
    //rotate <-90,180,0>
    scale <-1,1,1>
}

which moves our model up 17 units. You can move it left and right by changing the first number and forwards backwards by changing the third. Negative numbers make the model move in the opposite direction.

Rotating the model

If your model is rotated the wrong way you can spin it back into the right orientation by editing the following line of code:

object {
    milkshape_model
    translate <0,0,0>
    rotate <0,0,0>
    scale <-1,1,1>
}

Again, the red line is the part we want. The numbers represent rotation along the X, Y and Z planes and and are in degrees. In our case, we need to rotate our model 90 degrees along the X plane so we change the line to:

object {
    milkshape_model
    translate <0,0,0>
    rotate <90,0,0>
    scale <-1,1,1>
}

Mirroring/Flipping the model

Exporting from Milkshape often makes the models flipped along the X plane (Left/Right reversed). The "sample_scene.pov" file takes this into account and automatically adjusts it. However, if your model is flipped in another plane, you can fix it by editing the following line of code:

object {
    milkshape_model
    translate <0,0,0>
    rotate <0,0,0>
    scale <-1,1,1>
}

The numbers represent the X, Y and Z planes and are flipped by setting that planes value to -1 to reverse it and 1 to leave it as is. In the above example, we are telling it to flip only the X plane, making it swap left and right on our model.

Scaling the model

If your model is too big, you can either move the view point back away from it, or choose to scale the model down or up as needed. Doing this is done by editing the same line of code as for mirroring, but keeping any values set as negative. For example, the following scales our model down 50% but retains the mirroring in the X plane.:

object {
    milkshape_model
    translate <0,0,0>
    rotate <0,0,0>
    scale <-0.5,0.5,0.5>
}

Moving the viewpoint

Now that you've got your model in position and facing the right way, you probably want to render a picture of it from a much more interesting viewpoint. To do this we alter the location of our viewpoint and what point we are looking at. Control of this is done with the following two lines of code:

/* Our Camera. */
camera {
    location <0.0, 80, 150.0>
    look_at <0.0, 0.0, 0.0>

}

The "look_at" value, dictates the X, Y & Z point in our scene that out "camera" is looking at. In this case, we are looking at the point right in the middle of the scene, in the example picture at the floor right between the models feet.

The "location" value dictates the camera's X, Y & Z position in space and in this case is directly in front of the model, 150 units back and up 80.

Now lets say I want to look at the model at chest height but a little closer and to the right. First of all I would move the view point of the camera up by changing the "look_at" value:

/* Our Camera. */
camera {
    location <0.0, 80, 150.0>
    look_at <0.0, 30.0, 0.0>
}

This brings our focal point up off the floor 30 units to about where the waist is. Next step is to move the camera into a better position by changing the "location" values:

/* Our Camera. */
camera {
    location <-30, 80, 80>
    look_at <0.0, 30.0, 0.0>
}

Now in this case I've moved the camera to the right 30 units (X = -30), left it at 80 units above ground (Y = 80) and moved it closer so its now only 80 units away from the center (Z = 80). Now our render looks like this:

Obviously you dont have to show the whole model, if you like you can alter the viewpoint and camera location to do close ups...

Changing the lighting and brightness

By default, the "sample_scene.pov" file renderes your module using radiosity lighting. This gives you models nice natural light and soft shadows as seen in renderers like Brazil. However, the sample scene includes an extra light source you can turn on. Using this light gives a much more projected light source and gives you longer sharper shadows. The extra light is controlled by the following lines of code:

// set this to true if you want and extra light
// set it to false to just use ambient lighting
#declare use_light = false;

/* extra light if so desired */
#if (use_light)
    light_source {
        <0, 80, 30>*1000
        color rgb <1.0, 1.0, 1.0>
    }
#end

The first value we're interested in is the "use_light" value. We need to change "false" to be "true" to turn the light on. Doing so alters your renders thus:

As you can see the model is now lit from a more directed light rather than the sky light and has longer, sharper shadows. The next to values we are interested in are the lights position and its colour.

Like other values in the scene file, the lights position is set via 3 numbers defining its X, Y & Z position. In our case, this is "<0, 80, 30>*1000". The "*1000" multiplies the values by 1000, basically moving our light source way back. I dont recommend changing this value, just edit the actual X, Y and Z co-ordinates of the light itself.

As an example, lets move the light behind the models and to the left a little by changing the values as follows:

// set this to true if you want and extra light
// set it to false to just use ambient lighting
#declare use_light = true;

/* extra light if so desired */
#if (use_light)
    light_source {
        <30, 80, -30>*1000
        color rgb <1.0, 1.0, 1.0>
    }
#end

Now as you can see the light is behind the model and to the left, casting a long shadow in front and to the right of it.

The next option we can change is the colour of the cast light. By default, this is white, but you may want to tint it to give a more natural looking effect. The following line controls the colour:

// set this to true if you want and extra light
// set it to false to just use ambient lighting
#declare use_light = true;

/* extra light if so desired */
#if (use_light)
    light_source {
        <30, 80, -30>*1000
        color rgb <1.0, 1.0, 1.0>
    }
#end

Now there is a point to note here. In POV-Ray the red, green and blue components are specified as decimals between 0 and 1. If you have a RGB colour such as "255, 192, 171" you will have to convert those values to the correct decimal format. To do this use the formula 1/255 * X where X is the number you need to convert. In our case our example "255, 192, 172" becomes "1, 0.75, 0.67".

So, using and extreme example and making our light a dark blue colour our code would look like:

// set this to true if you want and extra light
// set it to false to just use ambient lighting
#declare use_light = true;

/* extra light if so desired */
#if (use_light)
    light_source {
        <0, 80, 30>*1000
        color rgb <0.0, 0.0, 0.5>
    }
#end

And the render of our model would look like:

There is another line of code we can change to adjust the brightness of our render by tweaking the gamma of the output. This is not a "brighter or darker" control as such but can compensate to some degree for very dark renders. The line of code that controls this looks like:

// adjust the gamma here if render is too light/dark
// 1.0 = lighter
// 2.0 = darker
assumed_gamma 1.5

As the comments state, setting this value nearer to 1.0 or 2.0 lightens or darkens the image respectively. Note however that you should use very small increments and the changes in output can be quite large.

Adjusting render quality

By default, the sample scene is set to use fast radiosity rendering. This should be good enough for basic setting up and testing of your render but you probably want to render it with a decent level of quality as your final output. The quality of the render is set at the top of the "sample_scene.pov" file in the following code:

radiosity {

    // uncomment one of the lines below depending on
    // what level of render quality you want.

    //Rad_Settings(Radiosity_Default, off, off)
    //Rad_Settings(Radiosity_Debug, off, off)
    Rad_Settings(Radiosity_Fast, off, off)
    //Rad_Settings(Radiosity_Normal, off, off)
    //Rad_Settings(Radiosity_2Bounce, off, off)
    //Rad_Settings(Radiosity_Final, off, off)
    //Rad_Settings(Radiosity_OutdoorLQ, off, off)
    //Rad_Settings(Radiosity_OutdoorHQ, off, off)
    //Rad_Settings(Radiosity_OutdoorLight, off, off)
    //Rad_Settings(Radiosity_IndoorLQ, off, off)
    //Rad_Settings(Radiosity_IndoorHQ, off, off)
}

To change the quality of the final render, uncomment ONE of the "Rad_Settings" lines by removing the leading double forward-slashes and commenting the one you dont want out by adding them. For example, if we want to use the Outdoor High Quality setting, our code would look like:

radiosity {

    // uncomment one of the lines below depending on
    // what level of render quality you want.

    //Rad_Settings(Radiosity_Default, off, off)
    //Rad_Settings(Radiosity_Debug, off, off)
    //Rad_Settings(Radiosity_Fast, off, off)
    //Rad_Settings(Radiosity_Normal, off, off)
    //Rad_Settings(Radiosity_2Bounce, off, off)
    //Rad_Settings(Radiosity_Final, off, off)
    //Rad_Settings(Radiosity_OutdoorLQ, off, off)
    Rad_Settings(Radiosity_OutdoorHQ, off, off)
    //Rad_Settings(Radiosity_OutdoorLight, off, off)
    //Rad_Settings(Radiosity_IndoorLQ, off, off)
    //Rad_Settings(Radiosity_IndoorHQ, off, off)
}

The various radiosity settings effect how POV-Ray calculates light bounces, shadows, etc. and can result in some VERY long rendering times so be patient.

Saving your final render to disk

By default, POV-Ray saves your render as a BMP file with the same location and filename as your scene. In this example, our rendered image will be called "sample_scene.bmp".

>>Index   >>More tips and tricks