Code: Select all
// Information from Oolite.
uniform sampler2D uColorMap; // Diffuse and Specular Intensity map
uniform sampler2D uFXMap; // Effects & Light Illumination Map
uniform sampler2D uNormalMap; // Normal Map
const float SpecExponent = 4.0;
uniform vec3 SpecularRGB
uniform float time;
uniform float eng_pow;
uniform float hull_heat;
Code: Select all
varying vec2 vTexCoord;
varying vec3 vEyeVector; // These are all in tangent space
varying vec3 vLight0Vector;
varying vec3 vLight1Vector;
Code: Select all
// 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;
}
// EngineGlow effect
vec4 EngineGlow(float level)
{
vec4 result;
result.rgb = vec3(1.9, 0.5, 0.20) * level;
result.a = 1.0;
return result;
}
Code: Select all
void Light(in vec3 lightVector, in vec3 normal, in vec4 lightColor, in vec3 eyeVector,
in float specExponent, inout vec4 totalDiffuse, inout vec4 totalSpecular)
{
lightVector = normalize(lightVector);
vec3 reflection = normalize(-reflect(lightVector, normal));
totalDiffuse += gl_FrontMaterial.diffuse * lightColor * max(dot(normal, lightVector), 0.0);
totalSpecular += lightColor * pow(max(dot(reflection, eyeVector), 0.0), specExponent);
}
Code: Select all
#define LIGHT(idx, vector) Light(vector, normal, gl_LightSource[idx].diffuse, eyeVector, SpecExponent, diffuse, specular)
Now should be ready for the main function - starts out initializing what is going to end up as holding the final color/lighting stuff that gets applied, and loads the textures. There's an exrta bit for normal maps which I'm not used to.
Code: Select all
void main()
{
vec4 diffuse = vec4(0.0), specular = vec4(0);
vec3 eyeVector = normalize(vEyeVector);
vec2 texCoord = vTexCoord; // what's this?
// Load texture data
vec4 colorMap = texture2D(uColorMap, texCoord);
vec4 fxMap = texture2D(uFXMap, texCoord);
vec3 normal = normalize( texture2D(uNormalMap, texCoord).xyz - 0.5);
normal = normalize(normal);
float specIntensity = 15.0 * colorMap.a * colorMap.a;
Note that the griff boa sets specular intensity to a constant - but I want to use the alpha channel in the texture for this ... which will be fun when I get around to playing with it.
From here I need to add in the effects, and the specular:
Code: Select all
#ifdef OO_LIGHT_0_FIX
LIGHT(0, normalize(vLight0Vector));
#endif
LIGHT(1, normalize(vLight1Vector)); // change the 0 to 1 when exporting back to oolite
diffuse += gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
diffuse += fxMap.a; // use fxmap alpha channel as an illumination map
vec4 color = diffuse * colorMap;
color += redGlow(effectsMap.b * Pulse(min(eng_pow, 1.0), 1.0)); // adds red 'engine heat' glow
color += EngineGlow(effectsMap.r * eng_pow); // adds orange/red exhaust-vent glow
// calculate the specular, color it using a weighted sum of diffuse map and imported color
color += 3.0 * ((0.7*SpecularRGB)+(0.3*colorMap)) * specular * specIntensity;
color.a = 1.0;
gl_FragColor = color;
}
Now - apart from syntax errors - which I never see before hitting "send" - I'm sure I've missed something out...