ZModeler2 Lesson#1: Textures and Materials.

Textures.

This chapter will use lots of quotes from Ryan Travisol's "ZModeler Guide", but no quotation marks or signs will be placed where quoted text appears indeed.

Textures are image files, like any pictures you can see on web sites, or wallpaper on your desktop. They are special because they contain the graphical details of a model. They are essentially pictures of the object from different angles, with little details all arranged on one canvas. Many people call texturing "skinning" because it adds a "skin" that stretches overtop to your mesh, giving it detail, color, and shading. There is no need to model a castle out of bricks - you can apply texture with bricks over a quite simple mesh. Texture are mostly used to add details to a simplified mesh. Photos are a great resource for details, because itís nearly impossible to hand-draw a perfect taillight, for example. Therefore, even those who use hand-drawn textures resort to photos for textures of emblems, lights, and other details.

Most of the time, textures are not just untouched photos of whatever it is that you're modeling. Instead, they are distorted, retouched, airbrushed, stretched, groups of pictures in one image. Evenmore, professionaly-made texture give the use for the most the space on the canvas, and fits as many parts of the car on one image as possible, all at the highest possible resolution. This issue of details resolution is another key concept when working with textures.

A practice that takes time and experience to develop is knowing just how much resolution is needed to properly display the desired amount of detail. Therefore, you don't want to include a huge texture of a certain emblem on the car, but relegate the side texture to a tiny portion of the image. The fact of the matter is, if you zoom in close enough, almost any texture is going to look blurry and pixelated. This effect can be minimized, though, by a process of selection. You can take the portions of the model that are very large (and thus subject to a larger zoom factor) and make them have larger textures, and those parts which are small and less visible will have smaller textures. This is a balancing act which you will learn from experience.

Overall resolution of your texture is important as well. You have to work within the limits of whatever application you choose to make of your model. For example, those of you who still work with Need For Speed High Stakes are limited to a single texture with a size of 256x256 pixels. Other games might not restrict with texture size limits, but hardware might. For example, my nVidia GeForce4 MX has a 1024x1024 texture limit and my Radeon 9800 has 2048x2048 limits. However, these limits should not be pushed - you should keep your texture sharp, clean, and stunning on as low resolution as possible. Waste of space on texture is what you should eliminate from your previouse experience.

Hardware Limitations.

I've said about hardware limitaion of maximum texture size, but it's not the only. Another and, probably, the most inconvenient limitation is a so-called power of 2 which means that both width and height of texture must be some power of 2: (64 is 2^6; 256 is 2^8; 512 is 2^9 and so on). This forces you to keep texture of a limited edge-size (64, 128, 256 and 512 are the most commonly used sizes).

Second, a so called square textures only hardware limitation is a quite common case. This means that only square textures can be used. For example, you might have a side photo of a car and you can make a 256x128 pixels texture out of this photo. Caused by this limitation, some hardware will convert it to 256x256 texture with no visual changes in game, but with twice more memory used. So, I strongly recommend to use square textures initially. Image below shows my Radeon 9800 hardware texture compatibilities. I've highlighted with red color a "power of two" limitation and with green color absence of "square textures only":

Materials.

Geometry can not be rendered as is - certain properties have to be defined. This set of properties, settings and textures is material. To display solid meshes on screen you have to specify color at least (different dark and bright levels of this color on the mesh will be computed by Direct3D, but color itself is set by you). So, color is the basic property of material. You have used to create meshes and see them in 3D already - that's beacuse these meshes used an internal Default Material (which is grey). Then texture(s) can be applied over this color in some manner: they can set generic color (default texture apply), add some light (light maps), add some darkness (shadow maps), add roughness (bump maps), emulate light reflection (specular maps) and so on. Whilst (or before) applying textures, transparency and it's behaviour can be defined. All these properties and settings in once is single material which can be used to render geometry.

Shaders or materials?

Applying set of properties and textures to geometry while rendering is called shading and it's done by shader, which is, internally, a piece of code loaded to your hardware graphic processing unit (or emulated in software). Modern game engines are shader-oriented, which means they have an explicit set of shaders (code fragments) to shade geometry in game. Previouse to shaders, materials were used instead of them. ZModeler resides on materials for both historical reasons and for simplicity. It's obviouse, that there could be way too many different shaders in all varity of games, so using old-facion materials is quite suitable solution. Final meshes are rendered by game engine with all it's featuring shaders, so you don't should be disappointed with absence of shaders in ZModeler.

So, ZModeler uses materials - To edit them, press Materials Editor button in main toolbar:

Materials Editor

Once clicked materials editor button ('E' is hotkey), Materials Editor dialog box will pop up. There are three general areas in this dialog box: they are (i) Material preview control with buttons under it; (ii) Materials tree/list box on the right of it; (iii) Material properties rollup area.

Materials tree/list box shows the list of available materials. Currently, only one material is available ("Default Material") and it is selected in the list. Material preview control shows a grey sphere. It is "currently selected" material ("Default Material" in our case) shaded over sample sphere. This control uses build-in sphere and box primitives to show preview of material. Sphere is used by default, but you can switch between sphere and box by pressing a white box button in a row of buttons under sample. This control has also a build-in white light; it's direction and viewer position can't be changed.
Take a look at the row of buttons under preview control: . They are (from left to right):

  • New Material
  • Copy Selected Material
  • Delete Selected Material
  • Swicth preview shape between box and sphere
  • Run animation (not available yet)
  • Toggle pattern background on/off Now press Copy Selected Material button and toggle pattern background on. Then, in materials list on the right click on a label with "New Material" (this is a material that was created by coping "Default Material") and rename it to "Test Material" by clicking on the label again. We shall now modify this material properties.

    Take a look at roll-ups area in materials editor. It contains several rollup pages which can be expanded or collapsed by clicking on according wide label-button. Click on "Basic Parameters" button (if it's not pushed already) to expand material basic parameters. Basic parameters are a set of material colors. By default, "Simple color mode" is toggled on which allows to edit single (diffuse) color of material. This is, in general, enough for most of cases when color need to be changed, since "diffuse" is the actual color of material. If you want to change any other color, disable "simple color mode", pick a color you want to change and drag sliders. You can click on a color square and a color dialog box will pop up. On the image below, I've set "Emissive" color to dark red. Emissive is the "internal shine" color of material - notice how sample material has changed.

    Well, I think there should be nothing confusing about basic material parameters.

    Alpha parameters

    There is much more confusing in "Alpha parameters" indeed. So, let me explain what is "alpha".

    Besides Red, Green and Blue (RGB) values, color can contain an Alpha value (RGBA) which is widely used in computer graphics. Alpha value (like red, green and blue) ranges from 0 to 255 and specifies by default an opacity level (0 - fully transparent, 255 - fully opacity (non-transparent)).

    Alpha can be set on per-material basis (each pixel shaded with such a material will have a pre-defined alpha value), or on textures level (each pixel of texture has it's own alpha value). These define "source" of alpha, but not how it's affected shading of certain material.

    Alpha Blend

    Expand "Alpha Parameters" rollup. Pay attention currently to Alpha Blend area only. First of all, make sure it's enabled (checkmark). Then scroll "opacity" slider to 150-170 and pay attention how material sample changes (I hope you still have background pattern toggled On in preview control). This is the most commonly used way of setting transparency. But to understand what exactly has happened, and why material sample became transparent exactly this way, I'll explain what alpha blending is.

    Alpha blending is an actual blending of pixel color/alpha, which is currently set in rendered image (destination pixel) with according pixel color/alpha which is been currently rendered and about to overwrite underlying pixel in rendered image.

    I think a good example here will be a case of the outdoor landscape, observed through a tinted glass. First, landscape polygons as usual are rendered. Then, a glass-polygon should be rendered over this "almost-ready" image. Glass polygons will not completely overwrite rendered landscape pixels, instead it will blend glass tint color with the color of landscape pixels. Image on the right is an example: it has a green landscape with gray road on it, and a red-tint glass in a frame. When rendering this image, landscape was rendered first and then galss was. So, how this red-tint appeared? Take a look at alpha settings of my "Red-tint Glass" material:

    Opacity was set to 83, but it's not all what is worth noticing. Pay attention to Source: "Source Alpha" and Destination: "Inv. Source Alpha". These are the settings which responsible for alpha blending in "general alpha-blend formula":

      P = S*[Material Pixel Color] + D*[Current pixel color]
      where:
      P - result pixel color
      S - Source blend selected
      D - Destination blend selected
    

    With "Source Blend" set to "Source Alpha" (material alpha, 83/255 = 0.33) and "Destination Blend" set to "Inverted Source Alpha" (1.0 - 0.33 = 0.67), this formula can be readed as: Pixel = 0.33*(red color) + 0.67*(color of landscape pixels), and, as a result pixels under tinted glass will have 67% of their previouse color and 33% of material's red color. If you set slider to 255, "source alpha" will be 1.0 (100%) and "inverted source alpha" will be 0.0 (0%), so red tint will completly replace landscape pixel colors with it's red color.

    Why have I written all this stuff here? Just because you really need to understand how exacly alpha blending is performed and why there are different Source and Destination settings. You can change combinations of Source and Destination settings to see what can be achieved.

    The Presets area is solely for storing Source/Destination combinations you use most recently.

    You can type name of current preset and hit Add button to store preset. By picking a preset name in drop-list, according setttings will be applied. Del button will, as you guess, delete currently selected preset. Presets are stored in profile and available after next time you start zmodeler.

    Alpha Test

    Alpha test is a way different, than alpha blending. Alpha test is performed on per-pixel level and determines whether certain pixel of material will be drawen or not. Condition for the pixel to be drawn is:
    Material's pixel Alpha should be (function) than a (reference value)
    Where function is "less", "equal", "greather or equal" etc, and reference value is a value in range 0 .. 255.
    On the image below, Function is set to be "greather or equal" and Reference value is set to 56. An interactive gradient paints a range of alpha values that will be transparent.

    In most of cases, alpha testing is used with texture-based alpha. Otherwise - all material pixels have the same alpha value and there is no need to perform per-pixel test on them (either all will be drawen, or all will not - this can be determined before rendering).

    The benefit of alpha-testing against alpha-blending is in the way it's used. Alpha test does not provide a range of transparency levels - pixels are either fully visible, or fully transparent (and not rendered at all). This can be used to draw, for example, a fence or something similar. In case of alpha-belding, fully transparent pixels are actually rendered (they do not affect the image because of transparency), but they involve computation time and, the most worse thing - they update depth buffer (z-buffer) of rendered image which can result in incorrect rendering of polygons behind transparent polygons.

    In any case, sorting objects in ZModeler, sorting polygons inside an object allows you to force transparent objects be rendered after the rest of scene - and avoid most of problems with transparent materials.

    Material Extensions

    Material extensions are an additional non-commonly used settings applied to material. They are in Extensions rollup. Expand it: there is a list of available extensions and an area for settings dialog for currently selected extension. On the right image "Specular Highlight" extension is selected and settings dialog for this extension is shown.

    To enable certain extension, you need to checkmark according line in a list of extensions.

    Another currently available extension is "No ZBuffer Write". When enabled, this extension forces material not to update z-buffer depth value. Rarely used indeed.

    Texture Layers

    Finally, the most important concept. Textures are applied to meshes only with materials via texture layers of according material. Each material can have upto eight texture layers, but this limit is rarely achieved and in most cases your hardware will add even more limit: four or even two texture layers can be used at a time. So, to apply certain texture to the mesh, there must be material and this texture must be set as it's texture layer (with some required properties). Expand Texture Layers rollup. Image on the right shows only four of eight rows for texture layers. Each row contains the following set of controls:

  • 1 - Enables according texture layer (If you want to temporary get rid of certain texture on material, but don't want to loose this texture and it's settings - simply disable according layer)
  • 2 - Layer's texture. By pressing this button you can load certain texture onto this layer. When texture loaded, filename displayed on the button.
  • 3 - Texture apply mode. There are lots of variouse settings for texture application mode. You can change here the way texture applied: generic texture, environment texture, lightmap, etc. Besides this, texture smoothing (filtering), wrapping and other rarely-used settings are availabe in a dialog box which will pop-up once you click on "Edit..." button.
  • 4 - Layer priority. You can sort certain layers by changing their order - you don't need to sort rows with all their settings. Available priority settings (from highest to lowest) are: First, Earlier, Default, Later, Last. Thus, for example, if you want first texture layer (first row) be appliead after all other texture layers, simply change it's priority to "Later".
  • 5 - Layer Delete, Copy and Paste button. Delete button will, obviousely, delete layer; Copy and paste can be used to copy texture with it's settings (a whole row) inside material or among other materials. As an example, you can set up default environment reflections texture on one material, copy this layer and paste it over other reflective materials.

    Before going further, create a shapy Torus in the scene (preferable, in top view). It's in geometry drop-list in toolbar. First you define it's base radius and then you set it's cross-section radius. In any case, options box will pop-up when done creating where the following options can be set (see an image on the right). What's worth been changed here is Cross-circles and Parallel-circles to 24. I've also set Base-radius to 0.8 and Cross-radius to 0.35. Quad-based is preferable. Image below is the torus in perspective view.

    We have created this torus with the only purpose - when adjusting material you can spin perspective view and look how material affects this torus, but in general, this step was optional. Now return to Materials Editor - we shall now edit Default Material since it's assigned to the torus by default.

    Select "Default Material" materials list and expand "Texture Layers" box. We shall now create a shiny textured material like on the image below:

    In a first texture layer row click on texture button (the one with "..." on it). It will open Textures Browser. Locate "earth.png" image in Files folder of this tutorial; load "chrome1.png" texture into textures browser too. Then make sure "earth.png" is selected in textures browser and press OK button to close it. "earth.png" texture will be placed on first texture layer. Now, load "chrome1.png" onto second texture layer. You will have something like on the image below:

    Click on "Edit..." button in second texture layer (next to "chrome1.png" texture). A layer properties dialog will pop up. Make sure to switch it to Simple Mode in top. Image on the right shows default texture properties - they are assigned when texture is loaded. These are the most recently used settings:

  • Apply texture as: Mix with previouse - mix current texture with previouse layer (or with material color in case of first layer)
  • Use UV Mapping: Manual UV #1 - use first (and usually the only) UV-channel which is explicity mapped by modeler.
  • Smooth Textures - set "linear" texture filtering.
  • Wrap UV Mapping - wraps (or tiles) UV Mapping if it exceeds texture boundary.

    First of all, change Apply texture as to "High-level environment map". Chrome texture will shine over sample sphere. Then change Use UV Mapping to "Auto Sphere Environment". Click OK, close materials editor and spin torus in perspective view. You will see some reflections on it - this is our chrome1.png texture, applied as "enviroment map":