UDN
Search public documentation:

PhysicalMaterialMask
日本語訳
中国翻译
한국어

Interested in the Unreal Engine?
Visit the Unreal Technology site.

Looking for jobs and company info?
Check out the Epic games site.

Questions about support via UDN?
Contact the UDN Staff

UE3 Home > Physics > Physical Material Masks

Physical Material Masks


Overview


A physical material mask provides the ability to use two physical materials on different parts of a graphical material. A physical material mask can be used to create unique effects on a static mesh without the need for multiple elements and materials. A simple example is a window mesh that has a material which is partly wood (for a window frame) and partly glass (for a window). You can set up a physical material mask to play a glass breaking sound when the glass part of the material is hit, and a wood cracking sound when the wood part of the material is hit.

Using Physical Material Masks


Physical material masks consist of four properties on Materials or Material Instances.

  • Phys Material Mask - This is a one bit texture that serves as a mask. The physical material used depends on a the color (black or white) of a hit pixel during a collision.
  • Phys Material Mask UVChannel - This is the UV channel that should be used for the masked texture. This UV channel should contain the texture coordinates used to map the mask texture to a specific static mesh.
  • Black Physical Material - The physical material to use when the black portion of the mask texture is hit during a collision.
  • White Physical Material - The physical material to use when the white portion of the mask texture is hit during a collision.

One bit monochrome textures


A one bit monochrome texture is a texture where each pixel is represented by one bit. If the bit is 0, the pixel is black and if the bit is 1 the pixel is white. When a collision with a static mesh occurs, the physical material mask system uses this texture to decide which physical material to use.

Importing one bit textures

There are two ways to import a one bit texture.
  • You can use an imaging program such as Adobe Photoshop which supports saving one bit bmp formatted textures. You can then import the bmp file like normal into the editor and it will automatically detect it as a one bit texture.
  • You can import a 32 bit texture with your physical material mask in the alpha channel. When the texture import dialog appears, under the compression settings category select TC_OneBitMonochrome. You can also chose this compression setting later in the texture viewer.

OneBitCompressionSettings.png

Using OneBitMonochrome compression will remove the RGB channels of your texture and convert the alpha channel to a one bit texture. Using this method can be useful if you want to create your one bit texture in the alpha channel using the RGB channels of your material's diffuse texture as a guide. ALERT! Note: Alpha channels are 8 bit which means their values range from 0-255. Since a 1 bit texture ranges from 0-1, values less than 128 will be 0 and values greater than or equal to 128 will be 1 when compressed.

Example setup


This is an example setup using the following window mesh.

Window.png

The first thing I did before importing the mesh, is to create a set of UV coordinates for the mask texture. This workflow is exactly the same as creating UVs for any mesh you import. You don't have to do this if the default set of texture coordinates in UV channel 0 are acceptable. These are the UV coordinates I have created which are in UV channel 1 of the mesh:

UVs.PNG

Then I used an image editing program such as Photoshop to create my one bit texture which I then imported to the editor.

TextureMask.PNG

The black areas represent the windows and the white areas represent the frame. Also note the red circle. The format for this texture is A1 which must be the format of the mask texture for physical material masking to work.

This is what the mask would look like if it were mapped on the window mesh:

ALERT! Note: A1 formatted textures cannot be used for normal rendering.

WindowMasked.png

As you can see the black areas properly match up to the windows and the white areas match up to the window frame.

Now all thats left to do is to set up the mask on the material which is a simple manner of setting a few properties on the material.

ALERT! Note: For this step I used a material instance constant, parented to the actual material of the mesh because I did not want to modify the actual material.

MaskProperties.PNG

After this we are ready to go provided we have a valid white and black physical material. See this link for learning more about physical materials.

How it works


When a line check hits a static mesh, Unreal finds the triangle that was hit and the graphical material on that triangle. If the material has valid physical material mask settings, a texture lookup is done into a one bit texture to find what pixel was hit. If the pixel is black the line check returns the black physical material. If the pixel is white, the line check returns the white physical material. Your game must have proper code setup to use physical materials returned from line checks in order to see results from physical material masks.

Notes:


  • When using physical material masks on material instances, you can override only portions of the physical material mask on the instance. The non-overridden parts will be found by looking at the material instances parent.
  • A1 formatted textures do not use GPU memory, only system memory. They are never mipmapped and are never streamed.