Creating a 3D Ebook with POV-Ray

With the recent news that digital books have surpassed physical books in terms of sales, people are turning towards their computers, tablets, phones and dedicated ebook readers to consume digital books more than ever before. While ebooks have been around for quite some time, they have generally never looked so good or been as popular as they are today.

Earn with Bitconnect!Earn with Bitconnect!

Although Johannes Gutenberg’s work on the printing press began in approximately 1436, we have had books for even longer. It should come as no surprise that ebooks often mimic real books in their marketed appearance. People are simply comfortable with books and have been for a long time. Future generations may view real books as novelty items from the past. In the meantime ebooks are commonly displayed as traditional books with covers and paper pages even if the actual ebook contains no such things.

This tutorial will demonstrate how to create a virtual ebook image using Pov-ray, the freeware multi-platform ray tracing program. These techniques can help you get started towards creating a traditional looking book image for your next ebook project.

Alternate methods to create ebook images

Before we begin the tutorial I wanted to point out that there are countless ways to create ebooks images. This article demonstrates how to build such an image using free tools. You may not have the technical desire, time or energy to build a cover for your ebook in this manner.

In that case there are numerous commercial software solutions that can help you. Here are just a few examples in no particular order.

Another popular way to create pseudo 3D ebook covers is to use 2D templates that you apply your cover images to. Various photoshop actions are available to do just that such as 3D Cover Actions. While they may not be true 3D (you cannot rotate objects or change the viewing angle for example) some pleasing results can be achieved nonetheless.

Perhaps you are familiar with using graphical user interface based 3D design applications such as Blender, Lightwave or 3D Studio Max? They are terrific at creating 3D ebook images but do require a large investment in time to become comfortable with.

Finally you can always pay someone to create a 3D ebook image for you. One of the least expensive ways to accomplish this (though results may vary depending on who you hire) is to use a service like fiverr.com.

With that out of the way, let’s begin building our 3D ebook using Pov-ray.

The front cover, back cover and spine texture maps

We will require three regular 2D images for our ebook :

  • The front cover
  • The back cover
  • The spine of the ebook

These images will be texture mapped onto the 3D primitives that we will be creating to represent the ebook. The size of the front and back covers are identical. The spine (end) of the ebook shares the same height as the front and back covers, but can be any width. The width of the spine indicates how thick our ebook is.

For the purposes of this article I have chosen to use the dimensions of an A5 standard paper size which is 210 mm in height and 148 mm in width. While I could easily create an image that is 148 pixels by 210 pixels, it would be better to use something larger in order to provide enough detail for our rendering process. So I will quadruple these and use a cover image which is 592 pixels wide and 840 pixels tall. This maintains the same aspect ratio as the A5 standard we are targeting.

592 x 840 is still a fairly small texture size. You may prefer to scale this up further (1,184 x 1,680 for example) if your renderings are required to be large or if you intend to zoom in to your objects closely.

Like the front and back covers, the spine will also be 840 pixels in height. Again, it’s width will determine the thickness of our ebook. We will select a thickness of 20 mm for our ebook. This we need to scale by four to match the scaling factor we used for our cover images. The result is a spine image with the pixel dimensions of 80 pixels by 840 pixels.

Our spine image will be wrapped around a squashed cylinder (see below) with only half of the cylinder being visible. We need to wrap our image all the way around the circumference of the cylinder as that is how cylindrical image mapping works. Therefore our spine image will need to be twice the intended size or 160 pixels in width. The portion of the image that will be exposed as the spine of the book will be an 80 x 840 pixel strip centered within this 160 x 840 pixel image.

We have now defined the sizes for our ebook front cover, back cover and spine images. Of course you could easily change the aspect ratio and scaling factors to match your own project requirements and create books of any dimension.

  • frontcover.png : 592 x 840
  • backcover.png : 592 x 840
  • spine.png : 160 x 840 (see above for imaging area)

Below you will find a downloadable ZIP archive containing template versions of the above images that you can use if you want to follow along. Of course it would be best if you added your own graphics to these which resemble the ebook that you would like to create. The green regions on the spine image template are wrapped around to the invisible portion of the spine cylinder.

A simple scene

We will be creating a very simple scene with a pair of lights and a white background. This article will not be going into depth regarding the scene but will instead be concentrating on the book.

Earn with Bitconnect!Earn with Bitconnect!

Create a new project directory on your computer for your 3d ebook project and place the front cover, back cover and spine images within it. Using your favorite text editor, create a new text file in this same directory entitled 3debook.pov and enter the following code into it :

#declare coverwidth = 592;
#declare coverheight = 840;
#declare spinewidth = 80;
#declare coveraspectratio = coverwidth / coverheight;
#declare coverthickness = 0.005;

// simple scene
background { color rgb<1,1,1> }

camera { location <-0.25,0.5,-1> look_at  <0.2,0.5,0> }

light_source { <2,3,-1> color rgb<1,1,1> }     

light_source { <-2,1,-2> color rgb<1,1,1> }    

// front cover
box { <0,0,0> <1,1,coverthickness>  
	pigment { 
		image_map {
			png "front.png"
			map_type 0
			interpolate 2
		}
	}
	scale <coveraspectratio,1,1>
}

To keep things simple and straight forward we will use a scale where 1 unit in Pov-ray is equal to 1,000 texture pixels. The dimensions of our book within Pov-ray become 0.592 units wide by 0.840 units high, and the spine is 0.080 units in width.

The Front Cover

As you can see we are using a box primitive to represent the cover of the ebook. The front.png image file is texture mapped to the box. Rendering the scene results in the image below.

Notice that the scaling happens after the pigment is defined. This will scale both the pigment and the box together and effectively allows us to keep the height of our book at exactly 1 unit. For more information about applying and scaling planar textures check out Image Maps Explained from the POVRAY Cyclopedia of Solutions.

Pov-ray supports a variety of texture mapping types. The map_type 0 tells Pov-ray that we wish to use Planar texture mapping. This is Pov-ray’s default texturing mapping type. Specifying it as we did is optional but I wanted to point out that there are other mapping types supported by Pov-ray.

Interpolating the pixels on the surface of the box will create a much smoother texture mapped result. Pov-ray supports bilinear interpolation (interpolate 2) and normalized distance interpolation (interpolate 4). We are using bilinear interpolation which is a little slower than normalized distance interpolation but produces high quality results.

The Back Cover

The back cover is created in much the same way as the front cover. The only difference is that we rotate the back.png image texture (when it is used as a pigment) 180 degrees. This is accomplished by using rotate <0,180,0> within the pigment definition (see below). We then simply push it back to where the thickness of the book would have it rest.

box { <0,0,0> <1,1,coverthickness>  
	pigment { 
		image_map {
			png "back.png"
			map_type 0
			interpolate 2
		}
		rotate <0,180,0>
	}
	scale <coveraspectratio,1,1>
	translate <0,0,bookthickness-coverthickness>
}

The Spine

There are several different ways to create the end binding or spine of a book. There are spiral bindings and flat spines for example. In this tutorial we will be creating a simple curved spine.

Starting with a cylinder the same height and thickness of the book, we wrap the spine.png texture around the entire circumference of the cylinder using cylindrical image mapping. Next we squash the cylinder by scaling it along one axis and then we move it into position.

The image above visualizes this process. From left to right we have a plain cylinder, then a cylinder with cylindrical image mapping using our spine texture, and finally a squashed version of the texture mapped cylinder.

Constructive Solid Geometry (CSG) is a technique that Pov-ray uses to add or subtract overlapping regions of solid objects to either create new shapes or effect existing ones. Unions combine objects together, Differences subtracts the space of one object from another and intersections keep only the overlapping portions of objects. We will be using a CSG Difference operation (also known as a boolean difference) to slice away half of the spine.

The transparent red regions in the image above define the boundaries of the CSG difference box we use to slice away the portion of the book’s spine that we do not require. Note that the cylinders above have not been squashed yet. This was just to help make the effect of the CSG difference more clear.

If the size the csg difference box were to match the exact dimensions of the object(s) that we wish to cut away we could experience noisy results in the rendering. This is known as the coincident surfaces problem and is solved by ensuring the CSG object is slightly larger.

The paper pages

Rather than create all of the individual pages of our book, which is an alternative approach by the way, we will create a simple white box that represents all of the pages. We will then be applying a texture to the box that will give it the appearance of individual pages. For this purpose a colormap is used, to provide the grey lines between our pages.

Refer to the image below of three distinct reams of paper. They are all exactly the same and even use the same color map. The only difference between them is the scale of the color map.

For more information about color maps, please refer to Friedrich A. Lohmüller’s Stripe Patterns.

To give the appearance of more or fewer pages in our book we only need to scale the colormap accordingly. We must also ensure the colormap is rotated to orient the virtual pages so that they are perpendicular to the book’s spine (or parallel with the book’s two covers).

The pages of the book can be inset from the outer dimensions of the front and back covers as is common in many hard-cover books. The inset is easily adjusted in the script to whatever you require. You can also remove the inset altogether by specifying a zero value for it.

Bringing it all together

The code below includes all of the items we described above brought together to form our complete 3D ebook. The #declare statements at the beginning of the code support arbitrary values for the dimensions of the book components. This makes it easier for you to create custom sized books.

#declare coverwidth = 592;
#declare coverheight = 840;
#declare spinewidth = 80;
#declare coveraspectratio = coverwidth / coverheight;
#declare bookthickness = (spinewidth/coverwidth)/2;
#declare coverthickness = 0.005;
#declare paperinset = 0.005;

#declare paperpigment = pigment {
	gradient <0,1,0>
	color_map {
		[0.0 color rgb<0.9,0.9,0.9>]
		[0.5 color rgb<0.9,0.9,0.9>]
		[0.5 color rgb<1,1,1>]
		[1.0 color rgb<1,1,1>]
	}
	scale <0.002,0.002,0.002>
	rotate <90,0,0>
}

#declare bookfinish = finish {
	diffuse 0.9
	reflection {0.25}
	specular 0.75
	roughness 0.05
}

background { color rgb<1,1,1> }

camera { location <-0.25,1.25,-0.75> look_at  <0.2,0.65,0> }

light_source { <2,3,-1>	color rgb<1,1,1> }     

light_source { <-2,1,-2> color rgb<1,1,1> }    

// front cover
box { <0,0,0> <1,1,coverthickness>  
	pigment {
		image_map {
			png "front.png"
			map_type 0
			interpolate 2
		}
	}
	scale <coveraspectratio,1,1>
	finish { bookfinish }
}

// back cover
box {
	<0,0,0> <1,1,coverthickness>  
	pigment { 
		image_map {
			png "back.png"
			map_type 0
			interpolate 2
		}
		rotate <0,180,0>
	}
	scale <coveraspectratio,1,1>
	finish { bookfinish }
	translate <0,0,bookthickness-coverthickness>
}

// spine
difference {
	cylinder { <0,0,0>,<0,1,0>,(bookthickness/2)
		pigment {
			image_map {
				png "spine.png"
				map_type 2
				interpolate 2
			}
		}
		scale <0.5,1,1>
		translate <0,0,(bookthickness/2)>
		finish { bookfinish }
	}
	box { <0,-0.001,0> <1,1.001,bookthickness>
		pigment { color rgb <1,1,1> }
		scale <coveraspectratio,1,1>
		translate <0,0,0>
	}
}

// dimensions of pages
#declare paper = object {
	box {
		<0,0,0> <1,1,bookthickness-(coverthickness*2)>
		scale <coveraspectratio,1,1>
		translate <0,0,coverthickness>
	}
}

// pages box with inset
box { min_extent(paper) max_extent(paper)-((paperinset*2)*y)-(paperinset*x)
	translate <0,paperinset,0>
	pigment {paperpigment}
	finish {ambient 0.5}
}

The final rendering our ebook is crisp and clean. You may wish to render against a transparent background which would allow the ebook to easily be used on a variety of background colors and patterns. Perhaps you would prefer to put the ebook into a scene that contained soft shadows or other niceties? That however is beyond the scope of this particular article.

Building your ebook in this way allows you to change the rendering angle to whatever you need simply by adjusting the camera and the lights as required and re-rendering. This provides for a lot more flexibility than a mere 2D image.

Another benefit of using 3D is that you can zoom up close to your objects without loosing detail. Well, with the exception of the bitmap texture that is. If you intend to zoom closely to your objects or render them in a high resolution, it is important that you use textures of significant enough detail.

Conclusion

This article has demonstrated a basic approach for crafting a high quality book in 3D using POV-Ray. The code above can be used as is with the image templates provided to create your own similar 3D ebook. Or you can customize the size of the book or enhance the environment it is rendered within. I leave that part up to you.

Earn with Bitconnect!Earn with Bitconnect!

Comments

  1. Sharee Stromquist says:

    I wanted to send you that very little note so as to say thanks a lot over again with your stunning pointers you’ve provided in this article. It’s simply remarkably generous of people like you in giving extensively just what a number of us would have offered for sale for an e book to generate some bucks on their own, and in particular given that you could have done it in the event you wanted. Those good ideas also served to be a easy way to realize that some people have a similar desire just as my very own to understand a little more around this issue. I’m certain there are many more fun sessions ahead for many who read your blog post.

  2. Karissa Ilg says:

    I like this website very much, Its a very nice spot to read and obtain information.

  3. Toya Otterbine says:

    I’ve recently started a web site, the information you offer on this website has helped me greatly. Thanks for all of your time & work.

Trackbacks

  1. […] the original here: Creating a 3D Ebook with Pov-ray | Computing Voyage This entry was posted in Cylinder Scales and tagged 160-pixels, around-the, circumference, […]

Speak Your Mind

*

Read previous post:
A Simple CSS Grid for your WordPress Theme

A Cascading Style Sheet (CSS) Grid is a structure that helps designers lay out columns of content on their web...

Close