Build a 2×4 in POV-Ray

If you are just getting started with POV-Ray, this simple tutorial will show you how to raytrace a wooden 2 x 4 stud. Along the way we will explore aspect ratios of the rendered output as well as looping to create multiple instances of 2 x 4s.

Earn with Bitconnect!Earn with Bitconnect!

Myths of the 2 x 4

Raise your hand if you knew that a 2 x 4 (the wooden studs that house walls are commonly built with) were actually 1.5 inches by 3.5 inches? Anyone familiar with house construction will of course know this, but the average computer geek might be amazed by this fact. You would likely be met with odd expressions if you went to the local lumber yard and asked for some 1.5 by 3.5 studs!

A common 2 x 4 length is 8 feet. A 2 x 4 stud however is usually cut down to 92-5/8″ (or 92.625 inches) in length. This allows for a double top plate and single bottom plate during wall construction. We we will be creating a 2 x 4 stud which has the following dimensions :

1.5 inches x 3.5 inches x 92.625 inches

Creating a 2×4 in POV-Ray couldn’t be simpler as we are basically asking it to build a textured box. We will require a simple scene for demonstrable purposes as well as a solution for the texture of the wood.

Aspect Ratios and Output Dimensions

The 16:9 aspect ratio commonly found on widescreen displays today will be our target aspect ratio. While we are using a 16:9 aspect ratio in this article, you can of course use any aspect ratio you want. It was only chosen because of the popularity of the 16:9 aspect ratio today. 16:9 simply means that the screen is 1.78 (which is 16 divided by 9) times wider than it is tall.

The camera can be configured to use a 16:9 aspect ratio by specifying right x*16/9 in your pov source file. You could also use right x*1.78 to achieve the same result, but the former has POV-Ray doing the math for us. You may notice that some scripts hard-code the output resolution directly into the camera’s right specification. For example : right x*1920/1080. In this example we arrive once again at 1.78 which is our desired 16:9 aspect ratio. As you can see there are many ways to specify our target aspect ratio.

An example of a 16:9 screen is the standard 1080p high definition format. A screen in this format contains 1,920 pixels across and 1,080 pixels in height. That’s over 2 million pixels. Raytracing a complex scene at that resolution can take a very long time. In most cases we do not need to work in such a high resolution while we are designing our scenes. By reducing the output resolution we can substantially decrease the rendering time.

Below are some examples of output resolutions which use a 16:9 aspect ratio. By selecting a lower resolution with fewer pixels, we can expect shorter rendering times. For example a 480 x 270 image will require 6.25% of the time to render a 1920 x 1080 image.

Width Height Pixels Render Time
1920 1080 2,073,600 100%
1280 720 921,600 44.44%
1024 576 589,824 28.44%
800 450 360,000 17.36%
640 360 230,400 11.11%
480 270 129,600 6.25%
320 180 57,600 2.78%
240 135 32,400 1.56%
If you know the width (in pixels) of the output and the aspect ratio that you desire, it is easy to determine the height (in pixels) of the output needed to obtain the desired aspect ratio :
Height = Width / Aspect Ratio

Setting up a basic scene and rendering a 2 x 4

Start a new file in your favorite text editor and save it with a pov extension (example : studs.pov). Enter the code below which defines a very simple scene with a pair of lights, a camera and you guessed it : a 2 x 4 stud!

#include "colors.inc"
#include "textures.inc"
#include "woods.inc"

camera {
	location <10,10,-30>
	look_at <4,4,0>
	angle 35
	right x*16/9
}

background {
	rgb <0.4,0.8,1>
}

light_source {
	<50,50,-100>
	color rgb <.7,.6,.6>
}

light_source {
	<-50,50,-100>
	color rgb <.6,.7,.6>
}

light_source {
	<50,50,-50>
	color rgb <.6,.6,.7>
}

box {
	<0,0,0>, <1.5,3.5,92.625> 
	texture {
		T_Wood7
	}
}

The dimensions of the 2 x 4 (box) are described in units that directly match the number of inches. This was done for the sake of simplicity. You can of course use any scaling factor you like. Render the scene using a 16:9 aspect ratio resolution like so :

povray studs.pov +W480 +H270 +A0.0 +J

Selecting your Wood

The official POV-Ray texture library has a nice selection of procedural wood textures. This tutorial will demonstrate just a few of these, including :

  • Bleached oak (white) : T_Wood3
  • Yellow pine (ragged grain) : T_Wood7
  • Soft pine (light yellow, smooth grain) : T_Wood10
  • A light tan wood – heavily grained (variable coloration) : T_Wood13
  • A light tan wood – heavily grained (variable coloration) : T_Wood31

By adding a few more 2 x 4s to the scene which use the various wood textures above, we can see what appears to be wood from different tree species. From left to right the textures are T_Wood3, T_Wood7, T_Wood10, T_Wood13 and T_Wood31.

Textures support a scale parameter which allows you to increase the scale of the texture to match the size of your object. It is also possible to rotate a texture to have it match the correct orientation of your object.

A good example of this is with wooden textures where the grain of the wood is usually running in the same direction as the longest dimension of the board. However, there is nothing stopping you from having the wood grain slightly offset or even perpendicular to create what is known as cross-cut wood.

The 2 x 4s above all use the same wood texture (T_Wood7). The first three are examples of different scaling values for the textures, and the last two demonstrate rotation of the texture.

box {
	<0,0,0>, <1.5,3.5,92.625> 
	texture {
		T_Wood7
		rotate 10
		scale 2
	}
}

The code above demonstrates how to use these parameters in a texture. It also shows that they can be used simultaneously. When combined, scale and rotate can change the look of the wood grain significantly. Below is a board rendered with both rotation and scale modifications applied to it’s texture.

Loops in POV-Ray

When you require multiple instances of the same object it can often be convenient to use loops to automate this process. As an example we will now create a wall section built from a number of of 2 x 4 studs. We will use a loop to place several 2 x 4 studs 16 inches apart (another house construction standard) and then add top and bottom plates to complete the wall section. The camera is repositioned for a better overhead view.

Earn with Bitconnect!Earn with Bitconnect!

A Union in POV-Ray is a collection of objects. In our example below we use a union to contain all of the components of the wall section and to later treat them as a single object. The union consists of regular wall studs, along with an 8 foot long bottom plate and two similarly sized top plates. This is a standard 8 foot long by 8 foot high wall section.

By declaring the studwall union (see source below) we are able to easily create entire wall sections without having to describe their individual components over and over again. It is possible to build the scene below without using a union. If however you plan on using more than a single wall section, defining it as a union will allow you to conveniently re-use much of your code.

#include "colors.inc"
#include "textures.inc"
#include "woods.inc"

camera {
	location <0,300,0>
	look_at <0,0,0>
	angle 35
	right x*16/9
	translate z*(92.625/2)
	translate x*48
}

background {
	rgb <0.85,0.95,1>
}

light_source {
	<50,150,-100>
	color rgb <.7,.6,.6>
}

light_source {
	<-50,150,-100>
	color rgb <.6,.7,.6>
}

light_source {
	<50,150,0>
	color rgb <.6,.6,.7>
}

declare studwall = union {

	// studs
	#declare BoardX = 0;
	#while (BoardX < 6)
		box { <0,0,0>, <1.5,3.5,92.625>
			texture {T_Wood10}
			translate x*(BoardX*16)
		}
		#declare BoardX = BoardX + 1;
	#end

	// last stud is inset
	box { <0,0,0>, <1.5,3.5,92.625>
		texture {T_Wood10}
		translate x*((BoardX*16)-1.5)
	}

	// top plate
	box { <0,0,0>, <1.5,3.5,96>
		texture {T_Wood7}
		rotate y*90
		translate z*(92.625)
	}

	// second top plate
	box { <0,0,0>, <1.5,3.5,96>
		texture {T_Wood31}
		rotate y*90
		translate z*(92.625+1.5)
	}

	// bottom plate
	box { <0,0,0>, <1.5,3.5,96>
		texture {T_Wood7}
		rotate y*90
	}
}

object {
	studwall
}

A while loop is used to define all of the studs except the last one which is inset to allow for a nailing edge to an adjoining wall section. BoardX is initialized with a value of 0 before the while loop is entered. With each pass of the loop it is incremented by one until it no longer meets the requirements of the while loop : BoardX < 6. This means that the while loop will have 6 passes, and during each pass we are creating one 2 x 4. The BoardX value is also used to move (or translate) each 2 x 4 along the X axis (16 inches apart). Using the while loop saves us from having to individually describe each stud. POV-Ray's while loop (as it is used above) is functionally similar to for/next loops found in other programming languages. Render the code above using POV-Ray to a 16:9 image and you will get the result below.

The entire wall section is defined as an object entitled studwall. We are now free to create as many wall sections as we desire without having to redefine the individual components they consist of.

#declare WallX = 0;
#while (WallX < 5)
	object {
		studwall
		translate x*(96*WallX)
		rotate z*-55
	}
#declare WallX = WallX + 1;
#end

It is possible to use a while loop to create multiple wall sections. The code above creates 5 wall sections end-to-end which results in a wall that is 40 feet in length.

Because we are using procedural textures rather than bitmap textures, the quality of the texture does not reduce when we zoom in closely to our objects. POV-Ray is able to use both bitmap based textures (image maps) as well as procedural textures. You can think of a procedural texture as one whose components are described in a scalable manner much like a postscript or svg file defines shapes.

Conclusion

Hopefully you now understand the basics of creating 2 x 4s or basically any kind of lumber in POV-Ray. You could expand on this further by assembling the frame for a house, a cabin or some other structure using these techniques. That of course is beyond the scope of this article!

Earn with Bitconnect!Earn with Bitconnect!

Comments

  1. Minta Bazin says:

    As a Newbie, I am permanently searching online for articles that can benefit me. Thank you

  2. Martin Digman says:

    Absolutely composed content, thank you for information.

Speak Your Mind

*

Read previous post:
Create a 3D Logotype Header with POV-Ray

Follow along as we build a 3D header for a website with help from POV-Ray and one of the many...

Close