RVMAT – ArmA: Armed Assault

From Bohemia Interactive Community
Revision as of 22:13, 11 April 2023 by Lou Montana (talk | contribs) (Text replacement - "pedia\.org\/([^w])" to "pedia.org/wiki/$1")
Jump to navigation Jump to search

Material theory

Lighting

Lighting and shading is what makes 3D scenes appealing. In realtime render we still have to simplify so Artist must understand how shading works in engine to be able to prepare the most realistic looking surfaces.

ArmA engine counts lighting as T * (D.o + A) + S.o

T = texture color

D = diffuse lighting (color, intensity and direction. Engine has just one light source of directional light - sun or moon.) D is calculated as max(L.N,0)*sunLightColor - where L is light direction, N is surface direction (normal)

A = ambient lighting (color and intensity. It is always present at same intensity all over the scene and its value is done by overcast setting)

S = specular (setting of material glossiness and specularity)

o = direction of light (1= pixel is lit, 0= pixel is in shadow)

Simple materials count lighting per vertex by interpolating light direction between face edges (normals). It is similar to well known Gouraud shading model. More complex materials use per pixel normal orientation.

Values for shading calculations are combined from textures, effect bitmaps, engine light settings (config) and material settings (*.rvmat).

Shadows

Shadows are calculated in ArmA engine two types, depending on values in Video options and each model setting.

Stencil buffer shadows are sharp and they are added after the whole scene has been drawn. Engine just subtracts diffuse light value on places where stencil shadow volume appears. This results in fact that speculars are still present in shadows. Also when ambient and diffuse settings of the material are not equal (and ForceDiffuse!=0) result color is not correct.

Shadow buffer makes one soft shadow map calculated on GCard for whole scene from the viewport. This affects the precision of the shadow.


Glossiness

Material specularity is defined by a curve (Bidirectional reflectance function) that says how much light is reflected under all angles. In ArmA engine we use SPECULAR POWER or IRRADIANCE TABLE values in *rvmat files.

Sections

Textures and materials are linked to each face separately so artist can have various materials on surface mapped with a single texture.

Every time when GCard is instructed to draw with new parameters, we call it scene section. It is usually when appears new object (*.p3d), texture or material. This workload between GPU and CPU slows down rendering often more than hundreds of new triangles.


RVMAT files

Those files are a sort of config.

Basic surface setting

Ambient[]={0.9,0.9,0.9,1};

multiplies color values (color texture R,G,B,A) of the surface that is not lit by main directional light.

Diffuse[]={0.9,0.9,0.9,1};

multiplies color values of the surface that is lit by main directional light.

ForcedDiffuse[]={0,0,0,0};

these values help to simulate so called Translucency. Part of the diffuse lighting that is reflected on surface in shadow. It works similar to ambient but with different component of lighting. Unfortunately some shaders don't work well with forcedDiffuse.

Ambient[]={1,1,1,1};
Diffuse[]={0.5,0.5,0.5,1};
ForcedDiffuse[]={0.5,0.5,0.5,0} 

This combination makes same result as old vertex property Half Lighted (surface is lit the same from all sides, it appears flat)

For foliage surfaces there are special shaders that use also forcedDiffuse Alpha value setting for calculating how much light goes through (1= all).

emmisive[]={0,0,0,0};

Also called Luminescence. Values give amount of light that surface shines by itself. Use it for light sources. It will appeal shining but will not light anything around it.

specular[]={0.3,0.3,0.3,0};

Used for making so called hotspot (in max it is Specular level+specular color). It is part of the light that is reflected from surface. Specular is calculated per vertex or per pixel depending on specific shader.

specularPower=40;

Also called Glossiness. Defines how sharp the hotspot will be. Some shaders use IRRADIANCE TABLE instead of this value.

MaterialSettings.jpg


All above mentioned settings can be calculated in some shaders per pixel using effect bitmaps.

All components are together used in calculation of surface shading:

pixel RGB on screen = 
((RVMAT ambient * RGB texture * Environment ambient) 
+ (RVMAT diffuse * RGB texture * Environment diffuse * light direction) 
+ (RVMAT forced diffuse * RGB texture * Environment diffuse) 
+ RVMAT emissive material * RGB texture 
+ (RVMAT specular * Environment diffuse * light direction)

Color values are usually in the range 0-1, but it can be more. ArmA engine calculates light in high dynamic range, with values exceeding 0-255 RGB depth. Final RGB in monitor is calculated for each frame depending on eye/optics Aperture (shutter) settings setAperture/setApertureNew.

Realistic surfaces do not reflect 100% of incoming light. The more light is reflected the less diffuse it has. Sum of diffuse, forced diffuse and reflected light should not exceed 1 BUT this is not true on ArmA realtime materials that do render just sunlight hotspot and miss environmental light - those would look too dark.

Diffuse for many usual surfaces is between 40%-80%. If you aim for maximum realistic surface settings, study photo reference. RVMAT settings allow you to put as much color range as possible in texture and then modify it to realistic values with maximum dynamic range.

Realistic surfaces usually reflect directional and scattered light the same way - Diffuse and Ambient are equal. ArmA engine has environment settings with values for diffuse and ambient (scene contrast) based on real world light recording. It is not wise to compensate contrast in material settings.

Lower diffuse values are used for spongy materials (some light is transferred to forceDiffuse). Lower ambient values can be used on surfaces where global ambient should be reduced, such as Interiors. It is usually made using Ambient Light maps.


Specular color

Usually we set RGB values color neutral. But sometimes it is effective to tint color in rvmat. Most obvious it is in specular settings of some glossy metal surfaces.

If I want a specific color, I count:

X= B/(Sp*Db)

B.. desired color of hotspot

Sp.. actual Specular setting of material

Db.. color of environment light (Ambient and Diffuse change during day and overcast) O2 environment editor shows actual colors used in buldozer preview.

X ..number that I use to multiply Specular to get desired color.

Render flags

Special shading properties that are used instead of old VERTEX LIGHTING PROPERTY settings.

renderFlags[] = {flag,flag};
  • NoZWrite

Face is not counted in Z-buffer. Used for alpha transparent surfaces laid over another face to fix shadow artefacts. (for example squad logo)

  • NoColorWrite

Disables calculation in color channels. Face is calculated just in alpha and Z-buffer.

  • NoAlphaWrite

Disables calculation in alpha channels. Used for transparent glass that has 2 pass material.

  • AddBlend

Allows adding alpha transparent surface color to the background. Used for fire particles.

  • LandShadow

For terrain.

  • AlphaTest32

Defines threshold where pixel becomes transparent at drop off to discrete alpha. The bigger value, the more pixels are used (Alphatest64, Alphatest128)

  • surfaceInfo="data\wood.bisurf";

Link to surface physics settings file.

  • mainLight
  • fogMode=FogAlpha

Setting for behaviour in fog. Used for roads - surface disappears by modifying also the alpha channel.

Always in Shadow can be achieved with setting RVMAT diffuse[]={0,0,0,0} + reasonable specular reduction.

Shader specific setting

Selecting shader.

PixelShaderID=".....";
VertexShaderID=".....";

Each shader uses specific "Stages"

class StageX

Each stage defines parameters for shader calculation, usually as links to effect bitmaps.

  • texture= (name and path to effect bitmap texture)
  • Filter="Anisotropic";

Default is Anisotropic, but in some situations you can use Point, Linear, Trilinear.

  • uvSource="tex";

can be: none, tex, tex1 (second UV set)

  • class uvTransform

Offset, deformation or repeating of texture in given UV set.

List of shaders

Pixel shaders:

AlphaNoShadow Shadow alpha (no shadow) write
AlphaShadow Shadow alpha write
Detail Detail texturing
DetailMacroAS
Grass Special shader to allow volumetric shadows to be cast on grass clutter
Interpolation
Normal Diffuse color modulate, alpha replicate
NormalDXTA Diffuse color modulate, alpha replicate, DXT alpha correction
NormalMap Normal map shader
NormalMapDetailMacroASSpecularDIMap
NormalMapDetailMacroASSpecularMap
NormalMapDetailSpecularDIMap
NormalMapDetailSpecularMap Similar to NormalMapDiffuse
NormalMapDiffuse
NormalMapDiffuseMacroAS
NormalMapGrass Normal map shader - through lighting
NormalMapMacroAS
NormalMapMacroASSpecularDIMap
NormalMapMacroASSpecularMap
NormalMapSpecularDIMap Same as NormalMapSpecularMap, but uses _SMDI texture
NormalMapSpecularMap
NormalMapSpecularThrough Normal map shader - through lighting
NormalMapThrough Normal map shader - through lighting
Refract Refraction textures
SpriteRefract Refraction in particle effects
Terrain
Water Sea water
WaterSimple Small water
White
WhiteAlpha

Vertex shaders:

Basic No extra info
BasicAlpha Basic with per-vertex alpha
BasicAS Ambient shadow
NormalMap Normal map
NormalMapAlpha Normal map with per-vertex alpha
NormalMapAS
NormalMapDiffuse Normal map + detail map
NormalMapDiffuseAlpha Normal map + detail map + per-vertex alpha
NormalMapDiffuseAS
NormalMapSpecularThrough Normal map - tree shader
NormalMapSpecularThroughNoFade Normal map with specular - tree shader - without face fading
NormalMapThrough Normal map - tree shader
NormalMapThroughNoFade Normal map - tree shader - without face fading
Point Anti-aliased points
ShadowVolume Shadow volumes
Sprite Particle effects
Super Used for glass
Terrain One pass terrain, no alpha mask - based on VSNormalMapDiffuse
TerrainAlpha terrain with alpha mask - based on VSNormalMapDiffuseAlpha
Water Per-vertex water animation
WaterSimple Per-vertex water animation (without foam)

Every specific type of material uses fixed combination of vertex and pixel shader with fixed stage numbers and type of texture. Use Material Templates in O2PE Material editor or check *.rvmat files in BI models.

Surface physical properties

RVMAT files are also used in geometry LODs for defining physical properties (the idea behind this is to be able to use one set of physical material definitions on many different surfaces that may still have different visual representation). It is done via a link to *.bisurf file.

surfaceInfo="data\wood.bisurf";

Content of a *.bisurf definition:

rough=0.1;
dust=0.1;
bulletPenetrability=150; 
// distance in mm that a bullet with speed 1000 m/s go until it stops. Slowdown is calculated linear. 
soundEnviron=Empty;
isWater=false;
thickness=10 // not implemented in ArmA
density=2500 // kg/m3, but it has actually no real value to ArmA engine too

See Also

Material_templates - Arma2 rvmat information for common surface types.

Bullet_penetrability - Arma2 information on how penetration works.