Skip to content
Ben Heasly edited this page Oct 17, 2016 · 10 revisions

The Dice recipe wraps a bitmap texture around modeled dice that are roughly cube-shaped. Since the dice are modeled with smooth edges and indented "pips", the texture wrapping requires a custom UV map.

Above, PBRT rendered the scene.

Above, Mitsuba rendered the scene.

Description

The parent scene contains 4 dice in mid-roll, tumbling over a flat plane. Two white lights illuminate the dice, one from above and one from near the camera. The camera sits near the plane.

The dice are manipulated to use a matte material with diffuse reflectance taken from an image file, based on a UV "layout" template that Blender created. The template contains grid lines that correspond to UV coordinates. The template was "colored in" for this scene with blue-filled grid squares and red "pips".

The flat plane is manipulated to use a brown-looking multi-spectral refelctance.

Here is the customized texture image:

Rendering

Use the script script rtbMakeDice.m to produce the images above.

Transformations Variant

DiceTransformations is a variant of the Dice recipe. It produces a family of four renderer-native scene files and renderings, using a variety of spatial transformations on one of the dice. These demonstrate interactions between spatial transformations that you might want to apply to an object with spatial transformations exported from the modeled, and one way to handle with the interactions.

Use the script rtbMakeDiceTransformations.m to produce the family of scene files and renderings.

Modeling the Die (Blender)

The Dice scene began with a model of a 6-sided die. This video tutorial, "How to Create a Dice Cube using Blender", was pretty easy to follow. The video refers to Blender version 2.5, but it agrees well with version 2.63.

The tutorial shows how to create a cube-shaped die with rounded edges that look good in Blender. These rely on a Blender feature called "Subsurf modifier". In order to export the rounded edges, you must apply the modifier to the die's mesh data. You can do this by clicking on the "Apply" button in the Subsurf dialog, as discussed in this Blender forum.

At this point the modeled die will have the correct shape, but it will have boring coloring.

Adding a Texture (Blender)

You can add fancy coloring by wrapping a texture around the die model. Texture wrapping requires you to define "UV" texture coordinates for each point on the surface of the die. These coordinates range from 0 to 1, and indicate to horizontal and vertical locations in an image file.

This video tutorial, "Image UV Mapping Texture Tutorial For Beginners", shows how to wrap a texture around a cube.

The tutorial uses Blender's "UV/Image Editor" view. Sometimes this view is obscured by a rendering preview, which is confusing! As discussed on this Blender Artists forum, you can close the offending preview by clicking on an "X" next to the phrase "Render Result" at the bottom of the UV/Image Editor view.

The tutorial will result in a "UV layout" image that you can edit. It might look different from the UV layout in the UV mapping tutorial. The idea is that the image will contain familiar landmarks from your 3D model that you can refer to when editing the texture image.

Nonlinear Workflow (Blender)

The modeling tutorial above produces a die with rounded edges. However, the subsequent UV mapping tutorial expects a cube with sharp edges. You might find it easier to mix the tutorials together as follows:

  • Follow the modeling tutorial for 10 minutes to produce a die with sharp edges.
  • Skip to the UV mapping tutorial to produce a UV layout image.
  • Rejoin the modeling tutorial at the 10 minute mark, to round off the edges of the die.

This would result in a UV layout image like this one:

Although it came from the rough-edged die, it will still work with the rounded die. Just make sure that "Subdivied UVs" is checked in the Subsurf dialog (It should be checked by default).

The renderings above used a similar UV layout image, with red circles and blue squares drawn in.

Collada Export (Blender)

You can copy and modify the die to produce a fun parent scene. In this parent scene, the die is copied, translated, and rotated four times, to evoke tumbling dice. This parent scene also contains a floor, a sun light, and a point light. When you have a parent scene you like, you can export a Collada file for use with RenderToolbox:

File -> Export -> COLLADA (.dae)

Rendering with a Texture (RenderToolbox)

RenderToolbox defines a generic mappings syntax for assigning texture images to materials.

The first step is to define a new texture based on an image file. OpenEXR images should work for both PBRT and Mitsuba. The next step is to assign the texture to a target material, in this case the material of the dice. All the hard work of wrapping the image around the dice is handled by the renderers, based on the UV coordinates created in Blener.

This excerpt from the mappings file, DiceMappings.json, demonstrates the RenderToolbox generic syntax for working with textures:

	{
		"name": "diceTexture",
		"broadType": "spectrumTextures",
		"specificType": "bitmap",
		"operation": "create",
		"properties": {
			"name": "filename",
			"valueType": "string",
			"value": "DiceUVColored.exr"
		}
	},
	{
		"name": "Textured",
		"broadType": "materials",
		"specificType": "anisoward",
		"operation": "update",
		"properties": [
            {
                "name": "diffuseReflectance",
                "valueType": "texture",
                "value": "diceTexture"
            },

The last step is to render the image with rtbMakeDice.m.