RVMAT basics

From Bohemia Interactive Community
Jump to navigation Jump to search

Theory

Lighting

Lighting and shading are what make 3D scene appealing. In real-time render we still have to simplify so the Artist must understand how shading works in engine to be able prepare the best realistic looking surfaces.

Real Virtuality counts lighting as T * (D.o + A) + S.o:

  • T = texture color
  • D = diffuse lighting (color, intensity and direction. ARMA 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 appeared. This results in speculars still being present in shadows. Also when ambient and diffuse settings of the material are not equal (and ForceDiffuse!=0) then resulting color isn't 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 Real Virtuality we are able to use:

  • Specular Power
  • Irradiance Table
  • Fresnel 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.

Everytime when Graphics Card (GPU) is instructed to draw with new parameters, we call it scene section. It is usually when new object (*.p3d), texture or material appears. Sections are generated each time when there is need to change parameters for rendering on Graphical Card (GPU). This is always when loading information from CPU about independent OBJECT, TEXTURE, MATERIAL or bone limit is exceeded on the card. Overhead in instruction transfer between CPU and GPU then lowers rendering performance which could be used to render hundreds polygons or textures etc.

Texture (TGA) is assigned to individual faces. Material (RVMAT) is assigned to same faces separately thus it is possible use various materials on surface covered with one UV and CO map. Yet then are generated another sections. In STAGE 0 is possible change with RVMAT also difusse component texture. Sections may differ in individual LODs.

Procedural textures

Besides TGA/PAA textures, Real Virtuality can work with maps generated in real-time procedurally - see Procedural Textures.

Normal Map

The Normal maps used in Arma are Tangent-space maps with the X+ Y- orientation (same as in Unreal Engine and 3dsmax renderer default setting).


RVMAT files

Those files are a sort of config.

Basic Surface Setting

Ambient

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 the main directional light.

Diffuse

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

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

ForcedDiffuse

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

those 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 lighting component. Unfortunately some shaders do not 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 the same result as the old HalfLighted vertex property (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

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

Emmisivesic - also called Luminescence. Values give amount of light that surface shines by himself. Use it for light-sources. It will appeal shining but will not lit anything around.

Specular

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 poer vertex or per pixel depending od specific shader.

SpecularPower

specularPower = 40;

Also called Glossiness. Defines how sharp the hot-spot 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 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 od eye/optics Aperture (shutter) settings setAperture/setApertureNew.

Realistic surfaces do not reflect 100% of incoming light. The more light is reflected as specular the less diffuse it has. Sum of diffuse, forced diffuse and reflected light should not exceed 1 BUT this is not true on ArmA real-time materials that do render just sunlight hot-spot and miss environmental light.

Diffuse for many usual surfaces is between 40%-80%. If you aim for maximum realistic surface settings, study photoreference. RVMAT settings allow you to put as much color range as possible in texture and than 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. Real Virtuality has environment settings with values for diffuse and ambient (scene contrast) based on real world light recording. Color Calibration. It is not wise to compensate contrast in material settings.

Lower diffuse values are used for spongy materials (some light is transfered 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 hot-spot

Sp.. actual Specular setting of hot-spotmaterial

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.

RenderFlags

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

renderFlags[] = { flag1, flag2 };
Flag Name Description
NoZWrite Face is not count in Z-buffer. Used for alpha-transparent surfaces laid over another faces to fix shadow artifacts. (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
Alphatest64
Alphatest128

Defines threshold where pixel becomes transparent at drop off to discrete alpha. The bigger value, the more pixels are used
Road
NoTiWrite
NoReceiveShadow
NoLODBlend
Dummy0

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

Light Mode

Setting of various kinds of light calculation:

mainLight = "Sun";

Possible values are:

  • None
  • Sun
  • Sky
  • Horizon
  • Stars
  • SunObject
  • SunHaloObject
  • MoonObject
  • MoonHaloObject

Fog Mode

Setting of various kinds of fog calculation:

fogMode = "Alpha";

Possible values are:

  • none - no fog
  • fog - fog used by usual opaque objects; the more the object is covered by fog, the closer its color is to fog color
  • alpha - fog used by objects with alpha; the more the object is covered by fog, the more transparent it is
  • fogAlpha - combination of both above approaches; used for roads (alpha-out could be quicker than fogging); can be used to fade away objects when object is not just normally fogging
  • fogSky - fog for sky objects (moon, stars)

Shader-Specific Setting

Selecting shader.

PixelShaderID = "xxx";
VertexShaderID = "xxx";

Each shader uses specific "Stages".

class StageX

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

  • texture = (name and path to effect bitmap texture)

Must obey texture naming conventions Texture Naming Conventions otherwise there will be no proper automatic conversion made from TGA to PAA.

  • Filter = "Anizotropic";

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

  • uvSource = "tex";

can be: none, tex, tex1 (second UV set), pos, norm, worlPos, worldNorm, texShoreAnim, texCollimator, texCollimatorInv

  • class uvTransform

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

Material Types

Inside O2 Material editor exist examples for most of shaders - see Oxygen 2 - Manual - MAT plugin.

Shaders

Pixel Shaders

Vertex Shaders

You can find More about material settings in Material Templates.

Physical Properties

Materials are also used in geometries for definition of physical properties.

Parameters for engine are saves into material tables *.bisurf and reference to them from material looks like:

surfaceInfo = "data\wood.bisurf";

Such .bisurf file with physical properties looks like:

density = 2500;				// density of homogeneous object in kg/m³ - see https://en.wikipedia.org/wiki/List_of_elements_by_density
thickness = 10;				// non-homogeneous component casing thickness in mm, implemented since Arma 2: Operation Arrowhead
rough = 0.1;
dust = 0.1;
bulletPenetrability = 150;	// distance in mm bullet (with speed 1000m/s) travels before it fully stops, simulation for calculation simplification calculate linear braking
							// (ergo on third of distance is bullet decelerated to two thirds of original speed)
soundEnviron = Empty;
isWater = false;

See more about penetration in Bullet penetrability.

When components in Your model got materials with references to physical properties then use script which sets weight.