racer home

Glowing brake discs

 

Home Effect fun with brake discs heating up, using Cg shaders.


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

INTRODUCTION

This document describes how to add glowing brakediscs to your car in Racer (possible since v0.6.2, 8-8-08). It uses a Cg fragment shader so your graphics card must support this (most modern cards do).

THE IDEA

Racer keeps track of the temperature of the brake disc in each wheel. Braking increases heat stored in the disc, and letting go of the brakes, plus car & spin velocity make it cooler again. The variables in car.ini involved are:

The temperature is passed to the rendering system as the variable 'heat', which can be used in your Cg fragment shader. This 'heat' parameter is normalized to a value between 0 and 1, where heat=currentTemp/brakeMaxTemp.

Note that currently (v0.8.3) the brake temperature is NOT used in the physics engine, and so has no influence on driving behavior yet.

THE STEPS

Take the following steps to get glowing brake discs:

NOTES

Note that this simple example skips lighting that you normally have when using the fixed OpenGL pipeline. However, if you start out with dark brake discs it might be fine as it is (they're always hidden behind the wheel anyway).

DISC_HEAT.CG FILE

Here is the disc_heat.cg shader file:

struct FragIn
{
       float2 tc0 : TEXCOORD0;
};       
struct FragOut
{
         float4 col : COLOR;
};
FragOut main
(
         FragIn fin,
         uniform sampler2D tex0 : TEXUNIT0,
         uniform float heat
)
{
  FragOut fout;
  float4 red=float4(1.0,0.25,0.1,1); 
  float4 cColor=tex2D(tex0,fin.tc0);

  cColor=(1-heat)*cColor+heat*3.0*red;
 fout.col=cColor;
 return fout;
} 

 


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

(last updated November 13, 2012 )