The NL2Mat Editor allows the creation of special material files that replace and extend the material definitions used inside a 3D model file. The following list shows an incomplete number of features that are possible:
The material settings control the vertex and pixel pipeline of rendered polygons. There are different units responsible for creating and modifying vertex and pixel data to produce the final pixels on screen:
- Dynamic vertex deformation effects (Sprite effects, plant waving etc.)
- Dynamic texture coordinates (Texture scrolling)
- Apply wave functions to diffuse color, or alpha channel, or texture coordinates (e.g. for pulsating glow effects)
- Special lighting effects (Bump mapping, specular masking)
- Control aspects of the material from a script
- Customize the way color and alpha and texture inputs produce the final pixels being rendered (e.g. interpolate between multiple textures)
- Customize blending operations
- Add foot step sounds
- Control the shadow casting and receiving
- Control the collision detection with the player
- Use as occluder polygons (to optimize framerates)
These units are linked together. The Deform Vertices unit, the color units, the TCGEN unit, and the TCMOD unit are vertex based. They produce the vertex attributes that are further used for the pixel based shader core unit, lighting, and reflection units.
The TCMOD unit directly works on the data from the TCGEN unit. Some units like the Deform Vertices unit and the TCMOD units can have multiple stages, that are linked together. The output of an upper stage is forwarded to the input of a lower stage. Lots of interesting effects are possible.
- Deform Vertices Unit - The Deform vertices unit can dynamically modify the vertices and normals from the 3D model file (e.g. plant waving effect or sprite effect). Multiple stages can be specified that are linked together.
- Color Unit - The color unit generates rgba values for each pixel (e.g. lighting color). Those values can be used inside the shader core unit to combine with texture pixels to create the final pixels being rendered.
- Texture Units - Up to 4 texture units can be used to fetch texture images.
- TCGEN Unit - The Texture Coordinate GENneration unit is part of each texture unit and is resposible for generating texture coordinates for texture. (e.g. produce texture coordinates for cube reflection mapping)
- TCMOD Unit - The Texture Coordinate MODification unit is part of each texture unit and is resposible for further modifying the generated texture coordinates from the texture coordinate generation unit (e.g. for texture scrolling). Multiple TCMOD stages can be used that are linked together.
- Shader Core Unit - The shader core unit is responsible for combining the results of the color unit and fetched texture pixels from the texture units. (e.g. multiply two textures and add a third one)
- Lighting Unit - The lighting unit is an internal unit responsible for lighting the surfaces. It is controlled using the color unit and shader core unit.
- Reflection Unit - The reflection unit can be optionally used to create a reflection effect that will be applied to the material.
- Alpha Test Unit - This unit can be used to reject pixels using the final alpha value. The final alpha value as generated from the shader core will produce values from 0..1. Using Alpha Testing, pixels with alpha < 0.5 will be rejected.
- Blend Unit - This unit can be used to blend the pixels from the material with existing pixels inside the frame buffer. (for transparency effects)
Select a file path and file name for a new NL2MAT file.
Open an existing NL2MAT file.
Save the current setting to the NL2MAT selected by New... or Open....
Save the current setting to another NL2MAT file and will use this file path from now on for upcoming Save commands.
Close the currently opened NL2MAT file.
- Path [not an input] - This text box displays the directory path to the .nl2mat file.
- Description - Add a description for the .nl2mat file (will be displayed inside the File Browser).
- Preview - Select image file for preview (will be displayed inside the File Browser).
- Footstep Sounds - Select four sound files to specify the sound effect being played when the player walks over polygons using this material in walk mode.
Deform Vertices Tab
Here you can add, remove or configure Deform Vertices stages. The Deform Vertices Unit is responsible for processing and modifying the original 3D vertex data from the 3D model file to achieve a vertex based dynamic movement effect. If no Deform Vertices stages are specified, the original vertex data will be processed without changes and the geometry will appear static.
Multiple Deform Vertices stages can be specified. Multiple stages will be executed in order. The first stage receives the original vertex data as input. The second stage will receive the output of the first stage as input and so on. The last stage's output will be used for further rendering operations inside the material pipeline. Not that some Deform Vertices modes, such as the Autosprite mode, do not allow multiple stages.
Note that all Deform Vertices modes are visible effects only. They do not affect the collision detection used for other parts of the 3D engine. It is meant for effects only. For realistic movements of scene objects, the scripting engine should be used instead.
- Rotate - This mode rotates the 3D model around an axis. Frequency and Phase control the speed and timing.
- Move - This mode moves the 3D model using a wave function. DX, DY, DZ control the direction vector of the movement the wave function will be applied to.
- Wave - This mode will create a water or flag like wave effect. It works best on a mesh grid. Div controls the size of the
wave (Waves per meter). For larger grid distances, smaller Div values should be used.
- Autosprite - Always orient the polygons towards the viewer. The polygons of the 3D object needs to organized as quads (two triangles sharing two vertices). No other DV stages are possible when autosprite is used.
- Autosprite 2 - Simililar to Autosprite, but will only rotate the quad around its longest axis. Usefull for cable or beam effects.
- Plant - Applies a plant wave effect to the geometry depending on the coordinates of the vertex. The wave effect is stronger, the higher the Y coordinate of the vertex.
At Y = 0, the wave effect is zero. The DX and DZ parameters control the amplitude of the wave depending on the X and Z coordinates of the vertices at Y = 1. The scene object must NOT be pretransformed using the World Entity option.
Here you can override the basic material properties of the 3D model file's material.
RGB Color Tab
You can select the lighting type or type of RGB color generation here. Lighting mode will use the basic material settings to generate brightness and colors. Others color modes will generate color values to be used inside the shader core unit to further process and create the final pixels.
- Const - This mode simply produces the specified color. This mode works great if you want to create an object with a fixed color or brightness that should not be influenced by lighting.
- Simple Lighting - This mode is a simple lighting mode that will not use any specular lighting or directional shading. It is ideal for sprites and imposters.
- Lighting - This is the standard lighting mode.
- Bump Lighting - This is an advanced lighting mode using a bump map. To use you need to specify a bump map in one of the texture units and configure the texture unit as a bump map texture unit (see texture units).
- Vertex - This mode simply takes the colors from the 3D model file (only supported by LWO files right now, the 3DS format does not support vertex color maps)
- Wave - Generate color using a dynamic wave function. The type of wave function and it is parameters can
be configured using the Setup button. This can be used to create pulsating brightness effects.
- Entity - Use the color from the entity property as part of any scene object. The entity property can be changed from within scripts attached to scene objects.
Alpha Color Tab
You can select how the initial alpha component of the color should generated here.
- Const - This mode simply produces the specified intensity.
- Vertex - This mode simply takes the alpha intensity from the 3D model file (only supported by LWO files right now, the 3DS format does not support vertex color maps)
- Wave - Generate alpha using a dynamic wave function. The type of wave function and it is parameters can
be configured using the Setup button. This can be used together with alpha blending to create pulsating effects.
- From Depth - This mode computes the alpha value using the depth of the vertex to the viewer. Two parameters can scale and bias the depth. Works good together with alpha blending to fade objects depending on distance to the viewer.
- Entity - Use the alpha from the entity color property as part of any scene object. The entity property can be changed from within scripts attached to scene objects.
You can setup up to 4 textures here. Read the Texture Unit Setup documentation for more information.
Here you specify how the textures and color are combined using the Shader Core Language. Default mode will simply modulate all used textures and the color from the color units (Modulate = Multiply).
Here you can add a faked reflection effect. Replace Alpha with Reflection Strength can be used to create a Fresnel effect. When enabled, it will overwrite the alpha value of the pixel using a value computed based on the Fresnel effect (Viewer angle to the surface) and two parameters. The alpha value then can used with alpha blending to create transparency based on the fresnel effect.
By using a custom Cube-Map, you can bypass the internal global reflection map and use a custom reflection map instead. This can be used to create local reflections.
Alpha and Blend Tab
This will apply a fading effect to the alpha channel, based on the distance to the underlaying pixels in the frame buffer. Can be used with Autosprites and Alpha Blending to smoothly fade objects near the lines of intersection with other objects (e.g. soft smoke effects).
When enabled, the pixels will not be rendered when the alpha channel's value is less than 0.5. Can be used for simple yes/no transparency.
When enabled, the pixels will be blended with the existing pixels from the frame buffer. The Src Factor and Dst Factor control how the incomming (Src) pixels of the material will be blended with the existing (Dst) pixels of the frame buffer.
Typical blending operations:
- Src Factor: 'SrcAlpha'; Dst Factor: '1 - SrcAlpha': Blend with existing pixels using alpha channel of material as transparency control
- Src Factor: '1'; Dst Factor: '1': Add material pixels to existing pixels
- Src Factor: 'DstColor'; Dst Factor: '0': Filter (Darkening) existing pixels using material color
Here you can configure advanced properties
- No Render - Render in Editor only (can be used for helper objects)
- Non Solid - Do not perform collision detection with player in walk or fly view. Usefull for plants and grasses.
- No Fog - Do not add fog effect
- No Shadow Receive - Do not receive shadows from other objects
- No Shadow Cast - Do not cast shadows to other objects
- Top Editor View Only - Render in Top view of the editor only. Usefull for billboards or helper objects.
- Alpha Test for picking - Use the alpha value of the first texture to more precisly detect if the object is under the mouse cursor when selecting objects. If not enabled, only whole polygons will be tested.
- No Depth-Write - Do not write the depth value to the Z-Buffer. Only use it if you exactly know what and why you require this.
- Polygon Offset - Will apply a small negative offset to the depth. This will pull the polygons slightly towards the viewer. It can be used to reduce Z-fighting with other polygons that have similar depth. (e.g. for pictures on walls)
- Occluder - Use the polygon using this material as occluder polygons. The Occlussion Culling System can be used to optimize frame rates. Use with great care. When not designed properly, the overhead introduced might outperform the benefit easily.
Polygons that use materials with the Occluder option enabled will give the engine a hint where possible occlusion occurs. The engine tries to prevent objects from being drawn that are behind occluder polygons. Less objects to draw can improve the frame rates. This is called Occlusion Culling. Note that Occlusion Culling comes with a high extra overhead. If not used with great care, the overhead might be higher than the benefit. The following text will provide information about the internal process and possible pitfalls.
The polygons marked as occluders are only double sided when the original mesh material was marked as double sided, otherwise occluder faces are single sided. There is no separate double sided option. Single sided occluder faces will only occlude other objects from one side.
Quad and Triangle Primitives
The occluder mesh can be made up of any shape of triangle mesh. Internally, the engine tries to detect quads (two triangles that share 2 vertices and together form a convex polygon with 4 corners) which are quite common for walls and such. For best performance, it is recommended to use quads. The bigger the quads, the better. At least lots of small triangles should be avoided. If the occluding mesh is highly detailed, it might make sense to create an invisible and simplified mesh for the occluders only.
Holes in the Geometry
Whenever the occluder mesh is made up of multiple polygons, great care should be taken to make sure there are no required holes between polygons. Even the smallest hole of one pixel on the screen can result in not working occlusion detection. For best performance the occluder mesh should therefore use as many shared vertices as possible without any holes at the borders of adjacent triangles. A typical problem found in poorly designed meshes are the so called T-junctions. T-junctions should be avoided at all costs because they can make the occlusion culling completely useless.
For best performance, the occluder meshes should be as large as possible, and the distance to the objects that should be culled should be as large as possible. The larger the occluders and the larger the distance to the other objects, the more likely it is that the other objects are completely behind the occluders. Only when the other objects are completely behind all the occluders, they can be skipped from rendering.
The culling works on a per object basis. One object is either a terrain tile, a short piece of track, one support beam, one car, one tree or one scene object element (sub object). The smaller these objects are, the more likely it is that one such object lies behind occluders. The object gets culled when the bounding box of the object is behind the occluders. The bounding box can be much larger than the object itself. Occlusion culling makes only sense when the bounding boxes of objects are as tight as possible. For scene objects it might make sense to split up large objects into smaller localized elements (sub objects).
GPU vs. CPU
The Occlusion Culling system runs on the CPU in separated threads. For single core CPUs, the OC might not be of any benefit at all. For systems having a slow GPU and a modern CPU with multiple cores (such as modern laptops), the OC can be a great benefit. When designing occluders, it is recommended to try out different scenarios (slow or fast GPU/CPU combinations).
DDS files in NL2MAT materials
DDS files can be used for textures. They might make sense when you want to supply special color formats or mipmaps, or when you want to use cube maps stored inside a single DDS file.
Not all possible formats are supported, only the most common:
DXT1 (Compressed to 4Bit per pixel)
DXT3 (Compressed to 8Bit per pixel)
DXT5 (Compressed to 8Bit per pixel)
ARGB 8:8:8:8 (32Bit per pixel)
RGB 8:8:8 (24Bit per pixel)
RGB 8:8:8 (32Bit per pixel)
ARGB 4:4:4:4 (16Bit per pixel)
RGB 5:6:5 (16Bit per pixel)
RGB 5:5:5 (16Bit per pixel)
ARGB 1:5:5:5 (16Bit per pixel)
Guide for choosing the best DXT format
Image has no alpha information: Choose DXT1
DXT1 has best quality and smallest size for images without alpha
Image has 1bit alpha information: Choose DXT1 or DXT3
DXT1 saves 1Bit alpha information, DXT3 saves alpha information with
4Bits per pixel.
DXT1 has a smaller file size than DXT3 but pixels near transparent
pixels tend to blur to black. This is caused by texture filtering and
the fact that the color channels of transparent pixels in DXT1 are
Image has alpha information with different shades: Choose DXT3 or DXT5
Both formats have the same file size and the color channels are
identical. Both formats only differ in the way they handle alpha
information. DXT3 saves the alpha information using 4Bits for each
pixel (16 shades), while DXT5 compresses and interpolates the alpha information
based on two 8Bit gray levels. Therefore DXT5 might be able to
reproduce an alpha channel with 256 gray levels, a much higher resolution
compared to the 16 gray levels of DXT3, but because of the compression,
some artefacts in the alpha channel might be introduced, similar to the
artefacts in the color channels of a DXT compressed image.