if you prefer, you can just specify a RGB colour in your shader to use when colouring the specular effect, this will give the same specular colour accross the entire model and you won't need to provide a new texture map.
Code: Select all
// Information from Oolite.
uniform sampler2D tex0; // Difuse and Specular Intensity map
uniform sampler2D tex1; // Effects & Light Illumination Map
const float specExponent = 5.0;
uniform float time;
uniform float eng_pow;
uniform float gun_heat;
// Information from vertex shader.
varying vec3 v_normal; // Surface normal
varying vec3 v_pos; // Vertex/fragment position in eye space
// cyanGlow effect
vec4 cyanGlow(float level)
{
vec4 result;
result.rgb = vec3(0.3, 0.6, 0.7) * level * 2.0;
result.a = 1.0;
return result;
}
// redGlow effect
vec4 redGlow(float level)
{
vec4 result;
result.rgb = vec3(1.9, 0.5, 0.2) * level * 2.0;
result.a = 1.0;
return result;
}
// WeaponGlow effect
vec4 WeaponGlow(float level)
{
vec4 result;
result.rgb = vec3(1.9, 0.5, 0.20) * level;
result.a = 1.0;
return result;
}
#ifdef OO_REDUCED_COMPLEXITY
#define Pulse(v, ts) ((v) * 0.95)
#else
// Irregular flickering function.
float Pulse(float value, float timeScale)
{
float t = time * timeScale;
float s0 = t;
s0 -= floor(s0);
float sum = abs( s0 - 0.5);
float s1 = t * 0.7 - 0.05;
s1 -= floor(s1);
sum += abs(s1 - 0.5) - 0.25;
float s2 = t * 1.3 - 0.3;
s2 -= floor(s2);
sum += abs(s2 - 0.5) - 0.25;
float s3 = t * 5.09 - 0.6;
s3 -= floor(s3);
sum += abs(s3 - 0.5) - 0.25;
return (sum * 0.1 + 0.9) * value;
}
#endif
// Calculate the contribution of a single light. Ought to be a function, but OS X's GLSlang implementation isn't sufficiently clever.
#define LIGHT(idx) \
{ \
vec3 lightVector = normalize(gl_LightSource[idx].position.xyz); \
vec3 reflection = normalize(-reflect(lightVector, v_normal)); \
diffuse += gl_FrontMaterial.diffuse * gl_LightSource[idx].diffuse * max(dot(v_normal, lightVector), 0.0); \
specular += gl_LightSource[idx].diffuse * pow(max(dot(reflection, eyeVector), 0.0), specExponent); \
}
void main(void)
{
vec4 diffuse = vec4(0.0), specular = vec4(0.0, 0.0, 0.0, 1.0);
vec3 eyeVector = normalize(-v_pos);
vec4 lightColor = vec4(0.8, 0.5, 0.2, 1.0); // Sets the RGB and Alpha values for the light, in this case a nice golden orange colour
// Load texture data
vec2 texCoord = gl_TexCoord[0].st;
vec4 diffuseMap = texture2D(tex0, texCoord);
vec4 effectsMap = texture2D(tex1, texCoord);
float specIntensity = 15.0 * diffuseMap.a * diffuseMap.a;
/* Light 0 is the "showroom" light, used in the demo screen and shipyard.
Light 0 is currently disabled, light 1 is the sun.
*/
#ifdef OO_LIGHT_0_FIX
LIGHT(0);
#endif
LIGHT(1);
diffuse += gl_FrontMaterial.ambient * gl_LightModel.ambient;
diffuse += effectsMap.a; // adds illumination to diffuse to give glowing lights effect
specular = mix(specular * lightColor, specular * diffuse, 0.0); // Adds the Specular Effect
vec4 color = diffuse * diffuseMap + specular * specIntensity;
color += cyanGlow(effectsMap.r * Pulse(min(eng_pow, 1.0), 1.0)); // adds cyan exhaust glow
color += redGlow(effectsMap.b * Pulse(min(eng_pow, 1.0), 1.0)); // adds red 'engine heat' glow
color += WeaponGlow(effectsMap.g * gun_heat);
gl_FragColor = vec4(color.rgb, 1.0);
}
the important lines are these two:
vec4 lightColor = vec4(0.8, 0.5, 0.2, 1.0); // Sets the RGB and Alpha values for the light, in this case a nice golden orange colour
specular = mix(specular * lightColor, specular * diffuse, 0.0); // Adds the Specular Effect
this example is a bit out of date now, Ahruman has added the ability to send vec4's to the shader using uniforms in the shipdata.plist. In this example the specular colour is hard-coded in the shader using this line:
vec4 lightColor = vec4(0.8, 0.5, 0.2, 1.0); // Sets the RGB and Alpha values for the light, in this case a nice golden orange colour
we could now specify the lightColor vec4 in the ships 'shipdata.plist' eg:
Code: Select all
uniforms =
{
SpecularRGB = { type = vector; value = "0.5 0.7 1.0";}
};
so different variations of your ship could have different specular colours without having to write a different fragment shader for each one.