RVMAT – ArmA: Armed Assault

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "[[Image:" to "[[File:")
m (Some wiki formatting)
 
Line 33: Line 33:


==== Sections ====
==== Sections ====
Textures and materials are linked to each face separately so artist can have various materials on surface mapped with a single texture.  
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.
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.
Line 39: Line 39:


== RVMAT files ==
== RVMAT files ==
Those files are a sort of config.  
Those files are a sort of config.


=== Basic surface setting ===
=== Basic surface setting ===
Line 45: Line 45:
  Ambient[]={0.9,0.9,0.9,1};
  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.  
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};
  Diffuse[]={0.9,0.9,0.9,1};
Line 52: Line 52:


  ForcedDiffuse[]={0,0,0,0};
  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.  
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};
  Ambient[]={1,1,1,1};
  Diffuse[]={0.5,0.5,0.5,1};
  Diffuse[]={0.5,0.5,0.5,1};
  ForcedDiffuse[]={0.5,0.5,0.5,0}  
  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)
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).  
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};
  emmisive[]={0,0,0,0};
Line 77: Line 77:
'''All components are together used in calculation of surface shading:'''
'''All components are together used in calculation of surface shading:'''


  '''pixel RGB on screen ='''  
  '''pixel RGB on screen ='''
  ((RVMAT ambient * RGB texture * Environment ambient)  
  ((RVMAT ambient * RGB texture * Environment ambient)
  + (RVMAT diffuse * RGB texture * Environment diffuse * light direction)  
  + (RVMAT diffuse * RGB texture * Environment diffuse * light direction)
  + (RVMAT forced diffuse * RGB texture * Environment diffuse)  
  + (RVMAT forced diffuse * RGB texture * Environment diffuse)
  + RVMAT emissive material * RGB texture  
  + RVMAT emissive material * RGB texture
  + (RVMAT specular * Environment diffuse * light direction)
  + (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]].
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.  
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.
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.  
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.
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.
Line 96: Line 96:


==== Specular color ====
==== 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.
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:
If I want a specific color, I count:
Line 117: Line 116:
  renderFlags[] = {flag,flag};
  renderFlags[] = {flag,flag};


* '''NoZWrite'''  
* '''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)
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'''  
* '''NoColorWrite'''
Disables calculation in color channels. Face is calculated just in alpha and Z-buffer.
Disables calculation in color channels. Face is calculated just in alpha and Z-buffer.


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


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


* '''LandShadow'''
* '''LandShadow'''
Line 136: Line 135:


* surfaceInfo="data\wood.bisurf";
* surfaceInfo="data\wood.bisurf";
Link to surface physics settings file.  
Link to surface physics settings file.


* '''mainLight'''  
* '''mainLight'''


* '''fogMode=FogAlpha'''
* '''fogMode=FogAlpha'''
Setting for behaviour in fog. Used for roads - surface disappears by modifying also the alpha channel.  
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.
'''Always in Shadow''' can be achieved with setting RVMAT diffuse[]={0,0,0,0} + reasonable specular reduction.
Line 168: Line 167:
* class uvTransform
* class uvTransform
Offset, deformation or repeating of texture in given UV set.
Offset, deformation or repeating of texture in given UV set.


== List of shaders ==
== List of shaders ==
Line 174: Line 174:


{| class="wikitable"
{| class="wikitable"
|+
! Name
|-
! Description
| AlphaNoShadow || Shadow alpha (no shadow) write
| AlphaNoShadow || Shadow alpha (no shadow) write
|-
|-
Line 182: Line 182:
| Detail || Detail texturing
| Detail || Detail texturing
|-
|-
| DetailMacroAS ||  
| DetailMacroAS ||
|-
|-
| Grass || Special shader to allow volumetric shadows to be cast on grass clutter
| Grass || Special shader to allow volumetric shadows to be cast on grass clutter
|-
|-
| Interpolation ||  
| Interpolation ||
|-
|-
| Normal || Diffuse color modulate, alpha replicate
| Normal || Diffuse color modulate, alpha replicate
Line 194: Line 194:
| NormalMap || Normal map shader
| NormalMap || Normal map shader
|-
|-
| NormalMapDetailMacroASSpecularDIMap ||  
| NormalMapDetailMacroASSpecularDIMap ||
|-
|-
| NormalMapDetailMacroASSpecularMap ||  
| NormalMapDetailMacroASSpecularMap ||
|-
|-
| NormalMapDetailSpecularDIMap ||  
| NormalMapDetailSpecularDIMap ||
|-
|-
| NormalMapDetailSpecularMap || Similar to NormalMapDiffuse  
| NormalMapDetailSpecularMap || Similar to NormalMapDiffuse
|-
|-
| NormalMapDiffuse ||  
| NormalMapDiffuse ||
|-
|-
| NormalMapDiffuseMacroAS ||  
| NormalMapDiffuseMacroAS ||
|-
|-
| NormalMapGrass || Normal map shader - through lighting
| NormalMapGrass || Normal map shader - through lighting
|-
|-
| NormalMapMacroAS ||  
| NormalMapMacroAS ||
|-
|-
| NormalMapMacroASSpecularDIMap ||  
| NormalMapMacroASSpecularDIMap ||
|-
|-
| NormalMapMacroASSpecularMap ||  
| NormalMapMacroASSpecularMap ||
|-
|-
| NormalMapSpecularDIMap || Same as NormalMapSpecularMap, but uses _SMDI texture
| NormalMapSpecularDIMap || Same as NormalMapSpecularMap, but uses _SMDI texture
|-
|-
| NormalMapSpecularMap ||  
| NormalMapSpecularMap ||
|-
|-
| NormalMapSpecularThrough || Normal map shader - through lighting
| NormalMapSpecularThrough || Normal map shader - through lighting
Line 226: Line 226:
| SpriteRefract || Refraction in particle effects
| SpriteRefract || Refraction in particle effects
|-
|-
| Terrain ||  
| Terrain ||
|-
|-
| Water || Sea water
| Water || Sea water
Line 232: Line 232:
| WaterSimple || Small water
| WaterSimple || Small water
|-
|-
| White ||  
| White ||
|-
|-
| WhiteAlpha ||  
| WhiteAlpha ||
|}
|}


Line 240: Line 240:


{| class="wikitable"
{| class="wikitable"
|+
! Name
|-
! Description
| Basic || No extra info
| Basic || No extra info
|-
|-
Line 252: Line 252:
| NormalMapAlpha || Normal map with per-vertex alpha
| NormalMapAlpha || Normal map with per-vertex alpha
|-
|-
| NormalMapAS ||  
| NormalMapAS ||
|-
|-
| NormalMapDiffuse || Normal map + detail map
| NormalMapDiffuse || Normal map + detail map
Line 258: Line 258:
| NormalMapDiffuseAlpha || Normal map + detail map + per-vertex alpha
| NormalMapDiffuseAlpha || Normal map + detail map + per-vertex alpha
|-
|-
| NormalMapDiffuseAS ||  
| NormalMapDiffuseAS ||
|-
|-
| NormalMapSpecularThrough || Normal map - tree shader
| NormalMapSpecularThrough || Normal map - tree shader
Line 286: Line 286:


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.
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 ==
== 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.  
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";
  '''surfaceInfo='''"data\wood.bisurf";


Content of a '''*.bisurf''' definition:
Content of a '''*.bisurf''' definition:
 
  '''rough='''0.1;
  '''rough='''0.1;
  '''dust='''0.1;
  '''dust='''0.1;
  '''bulletPenetrability='''150; ''
  '''bulletPenetrability='''150; ''
  // distance in mm that a bullet with speed 1000 m/s go until it stops. Slowdown is calculated linear.  
  // distance in mm that a bullet with speed 1000 m/s go until it stops. Slowdown is calculated linear.
  '''soundEnviron='''Empty;
  '''soundEnviron='''Empty;
  '''isWater='''false;
  '''isWater='''false;
Line 305: Line 306:


== See Also ==
== See Also ==
[[Material_templates]] - Arma2 rvmat information for common surface types.


[[Bullet_penetrability]] - Arma2 information on how penetration works.
* [[Material Templates]] - {{arma2}} rvmat information for common surface types
* [[Bullet_penetrability]] - {{arma2}} information on how penetration works
 


{{GameCategory|arma1|Addon Editing}}
{{GameCategory|arma1|Addon Editing}}

Latest revision as of 22:10, 8 August 2024

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:

Name Description 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:

Name Description 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