### Render 3D realistic images of EAGLE circuit boards

Did you ever wanted to see how some of your electronic projects would look before you actually build it? This post will show you how to create realistic images of your PCB designs that you can use in presentations, websites or only to get an idea of how it will look.

The process is the following: you design a PCB using CadSoft Autodesk EAGLE. Then, the Eagle3D script converts the EAGLE PCB file into a POV-Ray source. This is then rendered into something like below. POV-Ray is a very high quality and very configurable renderer. To make an idea of what ic can do with the right input, see the hall of fame of images rendered with it.

There is also a video version of this and some new improvements in: [Video] Render 3D images of EAGLE PCB projects.

This post will describe:
• How to install POV-Ray. Linux users may want to compile POV-Ray (at the time of writing this there were no Ubuntu packages, you can now install from repositories).
• How to use HDRI lighting to improve the quality of the rendered pictures.
• How to install MegaPOV, a modified version of POV-Ray 3.6. Again, Linux users may want to compile from source. This is described below.
In the above render you can see Hexapod Interface EAGLE example project. Rendered using HDR Beverly Hills courthouse (sun) by Keith Bruns (available from http://www.unparent.com/photos_probes.html) and background texture by M0tty (Own work) [CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0)], via Wikimedia Commons.

## Rendered vs. Real

 Some rendered PCBs vs. real homemade PCBs

## Required software:

1. Cadsoft Autodesk EAGLE - will be used for schematic capture and PCB design.
2. Eagle3D is the script that generates POV-Ray files from EAGLE PCBs.
3. POV-Ray or MegaPOV is used to render images.

## Installation/Compilation

### For the Linux/Ubuntu users:

Cadsoft Autodesk EAGLE is supplied both as 32 bit software and 64 bit software starting from version 7.3.0. It can be installed by running ./eagle*.run in a Terminal in the download directory.

Eagle3D doesn't need to be installed. Simply extract it to a folder of your choice (note that the subfolder povray is what Eagle3D_povray_folder refers to). There is a bug in e3d_special.inc file from povray folder. Go to line 3248 and replace disc {<9.45-2.5, H+0.05, 7.28-2> y,0.7,0.6.5 pigment{col}} with disc {<9.45-2.5, H+0.05, 7.28-2> y,0.7,0.65 pigment{col}} (remove that second point in 0.6.5 so it will be 0.65).

POV-Ray needs to be compiled. Ubuntu packages are now available in the Universe repository. You can install it with sudo apt-get install povray povray-examples povray-includes. Skip to the Linking section.

If you still want to compile it, then download the archive from GitHub and extract it to a folder. Open a Terminal and run the following commands:
cd povray-master
cd unix
sudo apt-get install build-essential libboost-dev zlib1g-dev libpng12-dev libjpeg8-dev libtiff5-dev libopenexr-dev autoconf automake libboost-thread-dev libxmu-dev libx11-dev libsdl1.2-dev libsvga1-dev
echo dummy > ./config/compile # do this ONLY if the following command errors
./prebuild.sh
cd ../
./configure COMPILED_BY="name <email>" LIBS="-lboost_system -lboost_thread" --with-x --disable-io-restrictions --with-svga
make
sudo make install

If you compiled POV-Ray (add the Library_Path at the end of the file that opens and save) or if you are using Windows:
gedit ~/.povray/3.7/povray.ini
Library_Path="Eagle3D_povray_folder"
If you installed from repository:
mkdir ~/.povray
mkdir ~/.povray/3.7
cp /etc/povray/3.7/povray.conf ~/.povray/3.7/povray.conf
cp /etc/povray/3.7/povray.ini ~/.povray/3.7/povray.ini
You must edit two text configuration files:
gedit ~/.povray/3.7/povray.ini
Here you will add at the end a line like below (replace Eagle3D_povray_folder accordingly):
Library_Path="Eagle3D_povray_folder"
And the other file is povray.conf:
gedit ~/.povray/3.7/povray.conf
Here look in the category [File I/O Security] where you will uncomment none and comment restricted to look like:
[File I/O Security]
none       ; all read and write operations on files are allowed.
;restricted  ; uses _only_ "read" and "read+write" directories for file I/O.
Save and close the files.

### For the Windows users:

You don't have to compile POV-Ray. It is simple to install. At the installation wizard don't forget to check Download Editor DLL and follow the instructions. The configuration file povray.ini may be in Program Files, POV-Ray subfolder or in user documents folder. And you don't have to worry about where it is, because you can open POV-Ray, go to Tools menu and choose Edit master POVRAY.INI. In this file you must add the Library_Path to Eagle3D files.

## First render

Open a PCB in EAGLE and go to File - Run ULP. Browse to Eagle3D directory - ulp and select 3d50.ulp. Choose a language, accept license then select a folder where POV-Ray generated files will be placed. Go to POVRay tab and modify settings as (if using Windows adjust paths):

Click Create POV-File and Exit. Select logos and sockets for ICs, LEDs color, crystals height etc. When you see the POV-Ray File successfully written dialog, you should have an image already generated. Look in the folder you selected when first launched 3d50.ulp. If there is no image, open a Terminal in this folder and run the bash script. Look for any errors.

This is the result:

 Hexapod Interface EAGLE example project rendered with POV-Ray
If this looks good, you should know that there are many improvements that can be made.

## HDRI and radiosity in POV-Ray

Starting with version 3.7, POV-Ray supports HDRI lighting. Following Friedrich A. Lohmüller How to create Realistic Skies with POV-Ray, POV-Wiki Radiosity without conventional lighting tutorial and Jaime Vives Piqueres Experiments with Eagle3D the following code should be added in the .pov file before the line #include "e3d_tools.inc".
#declare hdrprobe = "sun.hdr"
#declare table = "wood_painting_texture.jpg"
global_settings {
pretrace_start 0.05
pretrace_end 0.005
count 150
nearest_count 10
error_bound 0.5
recursion_limit 1
low_error_factor 0.5
gray_threshold 0.5
minimum_reuse 0.005
maximum_reuse 0.2
brightness 1
}
}
// default finish for all textures:
#default{texture{finish{emission 0 diffuse 1 }}}
// hdr environment
sky_sphere{
pigment{
image_map{ hdr hdrprobe
gamma 1
map_type 1 interpolate 2}
}
rotate <0,90,0>
}
// wood table
plane{y,-3
texture{
pigment{image_map{jpeg table}}
normal{bump_map{jpeg table}}
finish{reflection{0,.1}}
translate -.5 rotate <90,90,0> scale <10,10,5>*30
}
}
Replace the table and hdrprobe declarations with your own filenames. You'll need two files:
• a HDR light probe. See the Resources section.
• a texture. You can use Creative Commons Search to find those on the web. I used a file By M0tty (Own work) [CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0)], via Wikimedia Commons. Replace texture.jpg with the name of that texture.
Put these files in Eagle3D - povray subdirectory (the above Eagle3D_povray_folder).

The result is the first image in this post. To get that, some textures were also modified. The PCB (defined in e3d_tools.inc as col_brd) got a bit of reflection (as seen on ignorancia.org) and a lower diffuse (0.4) than the default. Also the Gold and Silver textures defined in e3d_tex.inc were added an emission of 0.1 (when using radiosity, these textures emit light).

Don't forget to change the version declaration from 3.5 to 3.7 (at the beggining of the .pov file). And of course, remove all four light_source definitions.

### Automating things

There are 3 steps you need to do every time:
1. Change file version to 3.7
2. Paste the above contents in the file
3. Remove light definitions
To make things easier, first of all save the above code into a file e3d_hdr.inc. Put this file into the Eagle3D_povray_folder. Now, the 3d50.ulp must be edited. Go to Eagle3D - ulp folder and open that file in any text editor. Now edit the usrinc string and change  "#version 3.5;\n\n" to  "#version 3.7;\n\n" (it is on line 35). Edit also the incfiles string and add on line 64 "#include \"e3d_hdr.inc\"\n". All that's left now is to remove light definitions. There is no need to remove them as the Activate checkbox can be unchecked by default.

The value is stored in lgtx_inf[10], where x ranges from 1 to 4. They can be found on lines 556 - 559. Change the value to 0 like this: lgt1_inf[10] = 0; for all four lights.

If you change often the texture and the HDR, you can remove those definitions (the first two lines with #declare) from e3d_hdr.inc and put them in 3d50.ulp to be added in the main .pov file.

## MegaPOV

If you want to follow Jaime Vives Piqueres Experiments with Eagle3D tutorial, you'll need MegaPOV. This is a custom build of POV-Ray 3.6 (which did not have HDRI support) and as POV-Ray 3.6 is not a multithreaded application.

There are Linux binaries on its website, but to be able to run that install script, you need to have POV-Ray 3.6 installed on your system, which may conflict with 3.7 on a Linux OS. There is no problem on Windows machines, as 3.6 and 3.7 install in different locations.

If you compile MegaPOV and use the include folder from POV-Ray 3.6 there is no need for a full POV-Ray 3.6 installation. Here is how to compile MegaPOV.

After you downloaded the archive and you extracted it to a folder, go to that folder and:
cd megapov-1.2.1
sudo apt-get install build-essential libx11-dev libxmu-dev libsvga1-dev
./configure COMPILED_BY="name <email>" --with-x --disable-io-restrictions --with-svga --disable-lib-checks
make
sudo make install
MegaPOV is based on POV-Ray 3.6 and it lacks some of its files. You'll have to download a v3.6 archive and add the required file to MegaPOV. Extract the include folder to a location you want (the location is mentioned below as include_folder_from_povray). Now, link that and Eagle3D to MegaPOV. Run:
gedit ~/.megapov/1.2.1/povray.ini
Library_Path="Eagle3D_povray_folder"
Library_Path="include_folder_from_povray"
On Windows, you'll have to install first an old version of POV-Ray (recommended v3.6 with exe installer, not msi - see this). You can have both POV-Ray 3.6 and 3.7 installed at the same time.