racer home

Developing cars & tracks for Racer

 

Home Defining physical materials in Racer shaders.


Dolphinity Organiser - free planning, project management and organizing software for all your action lists

Introduction

Materials in Racer are physical descriptions that are connected to Racer's shaders. Racer uses the Newton physics engine, which supports detecting collisions between material pairs. (all available starting from v0.8.9)

<under construction>

Materials

Newton’s material structure allows you to define physical properties for interactions between specific materials. This can be useful for using custom friction values, collision sounds and generating particles (such as sparks) for example.
We define materials  and material interaction in data\physics\materials.ini.

First thing we need to define in materials.ini is which materials are going to be used, this looks like this:

materials
{
  stone
  metal
  grass
  plastic
  ; The 'default' material is always present, so no need to create it explicitly
}

There is always a material “default” defined by default for objects without a custom material, so there is no need to define it in here.
Next up is defining material interactions, also known as material-pairs. Racer will always define material-pairs, even when the material-pair is not defined in materials.ini.

Example:
pair_stone&metal
{

  elasticity=0.4
  static_friction=0.9
  kinetic_friction=0.5
  softness=0.1

  sound
  {
    impact
    {
      file=data/physics/audio/metal_stone_imp.wav
      factor=0.2f
      speedthreshold=1.0f
    }
 
    scratch
    {
      file=data/physics/audio/metal__stone_scr.wav
      factor=0.00003f
      forcethreshold=100.0
      anglethreshold=0.8
      smoothness=0.90
    }
  }
}

First, we need to identify which material-pair we are going to define.

pair_stone&metal

We are going to define the material pair consisting of the two materials “stone” and “metal”. The order of the materials does not matter, so the above is the same as writing:

pair_metal&stone

You can also define a material interaction with two identical materials.

pair_stone&stone

You can also define material interactions for the default material.

pair_default&stone
pair_default&default

Next up are the physical interation properties, which speak for themselves:

; elasticity on collision
elasticity=0.4
; static friction on collision
static_friction=0.9
; kinetic friction on collision
kinetic_friction=0.5
; softness on collision
softness=0.1

 

 

Sound

Sound is the next step. Materials colliding can generate 2 types of sound: impacts and scratching.

sound
{
  impact
  {
    file=data/physics/audio/light_imp_4.wav
    factor=0.2f
    speedthreshold=1.0f
  }
  scratch
  {
    file=data/physics/audio/Metal_Scrape.wav
    factor=0.00003f
    forcethreshold=100.0
    anglethreshold=0.8
    smoothness=0.90
  }
}

Scratch sounds can be persistent, they can last as long as the objects interact.
Impact sounds are triggered by a speed threshold, if a certain contact speed is reached, the impact sound is triggered. Scratch sounds are triggered when reaching a certain force threshold, forces are generated when a collision is persistent.
Let’s go over the possible settings for impact sounds:
; location of the sound file
file=data/physics/audio/light_imp_4.wav
; the volume of the impact sound is determined by the speed of the impact.
; additionally you can define a volume factor, if the volume needs tweaking
factor=0.2f
; do not trigger impact sounds if the impact-speed is below this threshold
speedthreshold=1.0f

scratch sound settings:

; location of the sound file
file=data/physics/audio/Metal_Scrape.wav
; the volume of the scratch sound is determined by the force of the
; collision.
; additionally you can define a volume factor, if the volume needs tweaking
factor=0.00003f
; do not trigger scratch sounds if the force is below this threshold
forcethreshold=100.0
; at which angle trigger the scratch sound?
; 0.0 is the lowest possible. In this example, scratch sounds are triggered
; if the relative angle between the collision objects is between 0.8 and -0.8
anglethreshold=0.8

; Scratch sounds are persistent, and can change volume during the
; interaction. When volume changes are too “sharp”, change this value for
; smoother sound transitions (1.0 being the smoothest).
smoothness=0.90

Shader additions

Now that all materials, and material-pairs are defined, now we need to define materials for the shaders that should be affected. We define the physical materials in .shd files (car.shd or track.shd).

For example:

shader_billboard~vf_standard
{
  material=plastic
  ; …
}

We just add a “material” property in the object’s shader definition. You must use the material names that are defined in materials.ini (see above).

 

 


Dolphinity Organiser - free planning, project management and organizing software for all your action lists

(last updated November 13, 2012 )