[Contents | Tutorials ]

### Lesson 6: Lighting and Texturing

As discussed earlier, each vertex on a drawn model primitive has a normal vector and texture anchor point (texcoord) compoents.

### Lighting

The normal vector is used to specify the surface normal at that vertex, note that the normal vector need not be the actual surface normal. The normal vector may point outward (convex) or inward (concave) relative to the actual surface to emphisize shading. This trick is used to create cheap but convincing objects such as the "four quad cylender" (shown on right).

The normal vector is displayed on the 2D views as a line originating from the selected vertex and towards a certain direction. Note that the length of the normal vector is adjusted so that it can fit on the screen and not its actual length. In most cases you will want the normal vector to be of unit length (unless your end use requires otherwise). To quickly make a normal vector of unit length, just select it on the values list and press Button3 and pick Unitlize Normal. You cannot modify the normal vector on the 2D views, only from the values list.

The color and material settings also play a role in lighting, the Color primitives specify the surface pigment and material properties for any primitives that come after it and untill another Color primitive. This program renders lighting according to OpenGL's lighting rules, so values that you specify may differ in results when you use this model on a third party program.

The last but not least aspect of lighting depends on the light itself. The V3D format does not store light positions (officially) but most programs will place third party lighting commands into the V3D file. Thus treating the V3D format as a `scene' suitable for things like raytracing or just an easy preview.

To set the position of a light, move the cursor on the 2D views to the desired location and then click on the Light Button (located on the Primitives Tool Ribbon). A menu will appear, pick Move To Cursor and the light will be moved to the position of the cursor. While you are there, make sure the light is enabled by clicking on Enabled. To modify other light properties, click on Properties... and you will see the dialog on the right.

From the Light Properties dialog, you can set virtually any and all availble OpenGL-like properties of lighting. Most of the values here are identical to those of the OpenGL specification, with a few exceptions such as the direction of the light (when omnidirectional is unchecked).

You get up to 8 lights to play with, to set a different light, just click on the light number combo box on the Light Properties dialog. Or you can select a light by entering the light number next to the Light Button (located on the Primitives Tool Ribbon).

### Texturing

Note: If don't have any sample texture files loaded, scroll down to the texture loading section and read that first!

Texturing requires that one Texture Select primitive be placed in order prior to the visual primitives that are to have texturing. Any Color primitves may have affect on the selected texture by tinting it.

Subsequent primitives that occure in order after a Texture Select and before a Texture Off primitive will be textured with that texture. Each visual primitive has vertices with texcoords, these values specify the coefficient * texture_dimension to determine the anchor point on the actual texture. Only two dimensional textures are supported and as such only the texcoord values for S and T have affect.

The S compoent of the texcoord specify the left to right coefficient value relative to the texture in the range of [0.0 to 1.0]. The T compoent of the texcoord specify the top to bottom coefficient value relative to the texture in the range of [0.0 to 1.0]. The bounds for both S and T may be exceeded to allow the texture to "repeat" but only if the end implementation allows it. For example if S and T were 0.0, 0.0 then this specifies that the vertex is anchored at the upper left corner of the texture. If S and T were 1.0, 0.75 then this specifies that S is on the right edge while T is 1/4 from the bottom.

There is also another way to specify texcoords without actually specifying texcoords for each vertex (which can get tedious) by using the Texture Orient * primitives. For example if the Texture Orient YZ primitive follows a Texture Select primitive, then subsequent primitives that come after the Texture Orient YZ will have their texcoords automatically set to the texture values on the Texture Orient YZ primitive. A Texture Off primitive turns off the effects of both the Texture Select and Texture Orient * primitives.

Texture Orient * primitives are very useful, be sure to take the time to throughly experiment with them. They can be used to easilly orient texture for what seems to be hard to orient surfaces like the side of an aircraft as shown on the right. All the visual primitives that you see on the left side of the aircraft have their texcoord values set by just one Texture Orient YZ primitive.

### Making Textures

You'll probably want to create textures of your own, by that you need to know about the `.tex` format that Vertex uses. To make a long story short, the `.tex` format is a descendent of the Targa RGB 24-bit or RGBA 32-bit `.tga` formats. Any paint program that saves to either of the above Targa formats would be able to produce valid `.tex` images by simply renaming the `.tex` extension to `.tga`.

The size of the texture is also important, it needs to be square in geometry and the dimension length must be a value of 2^n ( ie 16, 256, 1024, so on and anything in between). The minimum dimension value is 2 pixels.

If you want some of your texture pixels to be transparent (transparent pixels) but you are using a regular paint program to create your `.tex` textures from targa files, then you can use the special color pure black (24-bit hex triplet `0x000000`). V3D standards specifies this color as being transparent when converted to internal texture formats. The internal texture format will have this pixel's alpha value set to `0.0`.

### Loading Textures

To load a new texture into your model file, go to Surface->Textures... and you will see the Texture Browser. It lists all the textures that are to be loaded for the current model. You can add and remove textures from the Texture Browser. Each texture has the following information:

- Referance Name (so that Texture Select primitives can match it).
- File Name (actual image file to the texture).
- Texture Priority (likliness of texture to be put in special Texture Memory)

If the File Name is a relative path then the Texture Base directory specified in the model's header (see Edit->Header...) on the Vertex editor's menu bar) will be prefixed.

The Texture Priority is used for GL and similar implementations where the likliness of the texture to be resident in special texture memory needs to be specified. Values from 0.0 to 1.0 are valid, where 1.0 is the most likly to be in this special texture memory. In order words, the higher the value is to 1.0, the more important this texture is.

Next Lesson: Multiple Models

######

Back to the top

Vertex is Copyright © 2000-2001 WolfPack Entertainment