Material Script

From Celestial Impact Wiki

Jump to: navigation, search

Material script is used to define what surfaces in the game should look like. A material file has two sections, this first is the global and then we have up to four stages. The global section control stuff like if the surface should cast shadows, position deform (vertex position) and some other stuff. You can have between 1 and 4 stages per material. The stages specify exactly what should be rendered, most materials only have one stage. If you define more then one stage each stage will be drawn on top of the stage before. This makes it’s totally useless to have opaque stages except for the first stage. Now let’s look at some random material script

cullBack

{

   specular 1.0
   shininess 255
   
   colorMaps game/swat/swat_color.tga
   bumpMaps game/swat/swat_bump.tga
   essrMaps game/swat/swat_essr.tga

}

First we have the global section, here it says cullBack. This means that back facing surfaces of this material should not be drawn. This is the default value so we really don't need to specify it.

Then we have our first and only stage. Here we specify to factor values specular and shininess. Then comes the most important part of the material, here we specify 3 textures that should be used. First a color map that’s specify the color for the material. Then a bump map that specify normals for the material. The we have the essr map, ESSR stands for Emissive, Specular, Shininess and Reflection.

Contents

Deforms

There are a number of different deforms a material can do. Position, color, alpha and emissive. Most of them share very similar syntax: deform <func> <base> <amp> <freq> <phase>

deform = <base> + <amp> * <func>( (time, xyz, st) * <freq> + <phase> )

Deform can use time, xyz or st (texcoords) as the changing variable. Time can be set from the game code. You can pile deforms on each other, One of the most useful example of this is when you want texture rotation around a arbitrary position, then use MOVE to offset the texture and then MOVE again to return to normal position

Deform Functions

<func> in all deforms use the same functions

  • SIN

The sine function

  • TRIANGLE

/\ Like a triangle

  • SQUARE

_|^|_ Like a square

  • SAWTOOTH

/| A 45 degree line up and a straight line down

  • INVERSESAWTOOTH

|\ A straight line up and a 45 degree line down

  • ID

f(x) = x

Global Params

  • noShadows (flag)

This material will not receive shadows (makes it faster to draw)

  • noCastShadows (flag)

Material will not cast shadows on other materials

  • onlyColorMap (flag)

Used for all HUDs, muzzleflashes etc.

  • onlyAmbient (flag)

No lights will be drawn to this material

  • cullBack (flag) This is default

Don't draw back facing surfaces (default)

  • cullNone (flag)

Draw both back and front facing surfaces

  • isSky (flag)

This material is a sky material

  • isGeo (flag)

Should be removed...

  • isMirror (flag)

This surface should be used as a mirror (don't work right now)

  • depthSort (enum)

All surfaces will be sorted before they get drawn. This defines the sort order for this material

  • depthHack (flag)

Will hack the depth values so that will draw infront of other surfaces

FIRST

MTV

OPAQUE_HUD

OPAQUE_WEAPON

OPAQUE (default for opaque surfaces

OPAQUE_DECAL

OPAQUE_WORLD

OPAQUE_SPACE

OPAQUE_SKY (default for sky surfaces)

TRANSPARENT_FIRST

TRANSPARENT_DECAL

TRANSPARENT_DECAL0

TRANSPARENT_DECAL1

TRANSPARENT_DECAL2

TRANSPARENT_DECAL3

TRANSPARENT_DECAL4

TRANSPARENT

TRANSPARENT0

TRANSPARENT1

TRANSPARENT2 (default for transparent surfaces)

TRANSPARENT3

TRANSPARENT4

TRANSPARENT_MUZZLE

TRANSPARENT_MUZZLE0

TRANSPARENT_MUZZLE1

TRANSPARENT_MUZZLE2

TRANSPARENT_MUZZLE3

TRANSPARENT_MUZZLE4

TRANSPARENT_WEAPON

TRANSPARENT_WEAPON0

TRANSPARENT_WEAPON1

TRANSPARENT_WEAPON2

TRANSPARENT_WEAPON3

TRANSPARENT_WEAPON4

TRANSPARENT_HUD

TRANSPARENT_HUD0

TRANSPARENT_HUD1

TRANSPARENT_HUD2

TRANSPARENT_HUD3

TRANSPARENT_HUD4

LAST

  • positionDeform

Perform deformation on the vertex position for this material. There are 3 different ways to deform them

positionDeform WAVE <func> <base> <amp> <freq> <spread> <phase> This will make a wave like motion of the vertexes. Spread is how spread the waves should be

positionDeform BULGE <func> <base> <amp> <freq> <sSpread> <tSpread> <phase> Same as above but uses texcoords for deform. Good for making pipes look like there is a flow inside them

positionDeform MOVE <func> <vectorX> <vectorY> <vectorZ> <base> <amp> <freq> <spread> <phase> Defines a vector that material should move in.

Stage Params

  • wrapClamp (flag)

Texture will be clamped at 0.0 and 1.0

  • wrapRepeat (flag)

Texture repeats 1.5 issame as 0.5. This is good when creating texcoord deforms

  • globalTime (flag)

Material stage will always use global time instead of entity time

  • blend (enum)

This stage should be blended.

ADD Just adds the new color value with old (good for sparks)

SCALE Adds a source color scaled with source alpha with destination color value

NONE Just black

MODULATE Multiples source and destination colors

FILTER Same as MODULATE

ALPHA Alpha blend (This is most common)

  • refraction (variable)

Default is 0 if more this stage will use the selected bump map to do refraction of the background

  • maskColor (flag)

Write no colors

  • maskAlpha (flag)

Write no alpha values

  • maskDepth (flag)

Write no depth values

  • emissive (variable) default value: 0.0

Emissive factor (glow)

  • ambient (variable) default value: 1.0

Ambient factor, light thats come from everywhere

  • skyAmbient (variable) default value: 1.0

skyAmbient factor, light that comes from sky

  • diffuse (variable) default value: 1.0

Diffuse factor, light that comes from lights

  • specular (variable) default value: 1.0

Specular factor, light that gets reflected from the light to your eye

  • shininess (variable) default value: 255.0

Shininiess factor, how broad the specular highlight should be

  • reflection (variable) default value: 0.0

Reflection factor light that comes from reflection map

  • renderTexture (flag)

Should only be used by Programmers

  • colorMaps

Specify one or more color maps. You can use more then one for texture animation like explosions

  • bumpMaps

Normal maps

  • essrMaps

ESSR maps, ESSR stands for Emissive, Specular, Shininess and Reflection. Each channel in the image controls its factor value on a per pixel level

  • refMaps

Reflection maps _px.tga _nx.tga _py.tga _ny.tga _pz.tga _nz.tga will be the 6 extension for the relection map

  • texcoordGen

Controls how texture coords should be generated

texcoordGen BASE texcoords from model file (defualt)

texcoordGen NORMAL normal is used to produce texcoords

texcoordGen PROJECTION <sVectorX> <sVectorY> <sVectorZ> <tVectorX> <tVectorY> <tVectorZ> texcoords comes

texcoordGen ENVIRONMENT reflection vector is used to produce texcoords from 2D projection

  • colorGen

Controls how vertex colors should be generated

colorGen BASE (defualt) colorGen CONST <red> <green> <blue> A constant RGB value

  • alphaGen

Controls how vertex alphas should be generated

alphaGen BASE (defualt) alphaGen CONST <alpha> A constant alpha value

  • texcoordDeform

texcoordDeform SCALE <sScale> <tScale> Scale texture in S and T

texcoordDeform STRETCH <func> <base> <amp> <freq> <phase> Stretch the texture with center as (0.5 0.5)

texcoordDeform SCROLL <sSpeed> <tSpeed> Make texture scroll

texcoordDeform SCROLL_S <func> <base> <amp> <freq> <phase>

texcoordDeform SCROLL_T <func> <base> <amp> <freq> <phase>

Make texture scroll in S or in T direction

texcoordDeform MOVE <sOffset> <tOffset> Just put a fixed offset to the texture coords can be used to make texture rotation rotate around correct point

texcoordDeform ROTATE <speed> Makes texture rotate

texcoordDeform STATIC_ROTATE <angle> Makes a static texture rotation in degrees

texcoordDeform TURBULENCE <base> <amp> <freq> <spread> <phase> Make texture swim around

  • colorDeform

colorDeform WAVE <func> <base> <amp> <freq> <spread> <phase> Like position deform but but for vertex colors

colorDeform BULGE <func> <base> <amp> <freq> <sSpread> <tSpread> <phase> Like position deform but but for vertex colors

colorDeform PULSE <func> <base> <amp> <freq> <phase> Make the entire material pulse

colorDeform LINEAR colorDeform ONE_MINUS_LINEAR Just scale color with time (usefull for make explosions and particel effect fade with time)

  • alphaDeform

Exactly the some as above but effects the alpha value for vertexes

  • emissiveDeform

emissiveDeform PULSE <func> <base> <amp> <freq> <phase>

emissiveDeform LINEAR

emissiveDeform ONE_MINUS_LINEAR

Personal tools