1
uniform sampler2D uColorMap;
2
uniform sampler2D uNormalMap;
5
varying vec2 vTexCoord;
6
varying vec3 vEyeVector; // These are all in tangent space
7
varying vec3 vLight0Vector;
8
varying vec3 vLight1Vector;
10
const float KspecExponent = 5.0;
12
// Uniforms from Oolite
14
uniform float hull_heat_level;
15
uniform float laser_heat_level;
17
// Irregular flickering function
18
#ifdef OO_REDUCED_COMPLEXITY
19
#define Pulse(v, ts) ((v) * 0.95)
20
#define Blink_on_off(value) (1.0)
23
float Pulse(float value, float timeScale)
25
float t = uTime * timeScale;
29
float sum = abs( s0 - 0.5);
31
float s1 = t * 0.7 - 0.05;
33
sum += abs(s1 - 0.5) - 0.25;
35
float s2 = t * 1.3 - 0.3;
37
sum += abs(s2 - 0.5) - 0.25;
39
float s3 = t * 5.09 - 0.6;
41
sum += abs(s3 - 0.5) - 0.25;
43
return (sum * 0.1 + 0.9) * value;
47
// Hull Temperate heat glow effect
48
vec3 TemperatureGlow(float level)
50
vec3 result = vec3(0);
53
result.g = level * level * level;
54
result.b = max(level - 0.7, 0.0) * 2.0;
58
// Heated weapon glow effect
59
vec3 WeaponGlow(float level)
62
result.rgb = vec3(1.38, 0.35, 0.20) * level;
68
void Light(in vec3 lightVector, in vec3 normal, in vec3 lightColor, in vec3 eyeVector,
69
in float KspecExponent, inout vec3 totalDiffuse, inout vec3 totalSpecular)
71
lightVector = normalize(lightVector);
72
vec3 reflection = normalize(-reflect(lightVector, normal));
74
totalDiffuse += gl_FrontMaterial.diffuse.rgb * lightColor * max(dot(normal, lightVector), 0.0);
75
totalSpecular += lightColor * pow(max(dot(reflection, eyeVector), 0.0), KspecExponent);
79
#define LIGHT(idx, vector) Light(vector, normal, gl_LightSource[idx].diffuse.rgb, eyeVector, KspecExponent, diffuse, specular)
84
vec3 eyeVector = normalize(vEyeVector);
85
vec3 normal = normalize(texture2D(uNormalMap, vTexCoord).rgb - 0.5);
86
vec3 colorMap = texture2D(uColorMap, vTexCoord).rgb;
87
float gunglowMap = texture2D(uNormalMap, vTexCoord).a;
88
vec3 diffuse = vec3(0.0), specular = vec3(0);
90
float specIntensity = texture2D(uColorMap, vTexCoord).a;
93
LIGHT(0, normalize(vLight0Vector));
95
LIGHT(1, normalize(vLight1Vector)); // change the 0 to 1 when exporting back to oolite
96
diffuse += gl_FrontMaterial.ambient.rgb * gl_LightModel.ambient.rgb;
98
vec3 color = diffuse * colorMap;
99
color += colorMap * specular * 6.0 * specIntensity;
102
// these next glow effects are only available in full shader mode
103
#ifndef OO_REDUCED_COMPLEXITY
106
//Add in the laser firing gun barrel flash effect
107
color += WeaponGlow(gunglowMap * Pulse(min(laser_heat_level, 1.0), 1.0));
109
// Add the all over hull temperature glow. Full Shader mode only
110
float hullHeat = max(hull_heat_level - 0.5, 0.0) * 2.0;
111
hullHeat = Pulse(hullHeat * hullHeat, 0.1);
112
color += TemperatureGlow(hullHeat);
115
gl_FragColor = vec4(color.rgb, 1.0);