~harrison-rt/+junk/jaguar_company

« back to all changes in this revision

Viewing changes to tags/1.6/jaguar_company_1.6.oxp/Shaders/jaguar_company_griff_cobra_mk3_frontgun.fragment

  • Committer: Richard Harrison
  • Date: 2013-01-19 22:39:57 UTC
  • Revision ID: harrison.rt@gmail.com-20130119223957-lcuzmbsrx6o2bk8o
Tags: 1.6.2
* Bug fix for the ship script.
* Bug fix to the waypoint AI. Never exited the stock AI.
* Cascade Weapon detection actually works for pre v1.77
* Took the opportunity to clean up some files and re-do the textures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
uniform sampler2D    uColorMap;
 
2
uniform sampler2D    uNormalMap;
 
3
 
 
4
 
 
5
varying vec2         vTexCoord;
 
6
varying vec3         vEyeVector;   // These are all in tangent space
 
7
varying vec3         vLight0Vector;
 
8
varying vec3         vLight1Vector;
 
9
 
 
10
const float KspecExponent = 5.0;
 
11
 
 
12
// Uniforms from Oolite
 
13
   uniform float  uTime;
 
14
   uniform float  hull_heat_level;
 
15
   uniform float  laser_heat_level;
 
16
 
 
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)
 
21
   #else
 
22
 
 
23
     float Pulse(float value, float timeScale)
 
24
     {
 
25
        float t = uTime * timeScale;   
 
26
 
 
27
        float s0 = t;
 
28
        s0 -= floor(s0);
 
29
        float sum = abs( s0 - 0.5);
 
30
   
 
31
        float s1 = t * 0.7 - 0.05;
 
32
        s1 -= floor(s1);
 
33
        sum += abs(s1 - 0.5) - 0.25;
 
34
   
 
35
        float s2 = t * 1.3 - 0.3;
 
36
        s2 -= floor(s2);
 
37
        sum += abs(s2 - 0.5) - 0.25;
 
38
   
 
39
        float s3 = t * 5.09 - 0.6;
 
40
        s3 -= floor(s3);
 
41
        sum += abs(s3 - 0.5) - 0.25;
 
42
 
 
43
        return (sum * 0.1 + 0.9) * value;
 
44
 
 
45
      }
 
46
 
 
47
// Hull Temperate heat glow effect
 
48
     vec3 TemperatureGlow(float level) 
 
49
     { 
 
50
        vec3 result = vec3(0); 
 
51
    
 
52
        result.r = level; 
 
53
        result.g = level * level * level; 
 
54
        result.b = max(level - 0.7, 0.0) * 2.0; 
 
55
        return result;    
 
56
     } 
 
57
  
 
58
// Heated weapon glow effect
 
59
   vec3 WeaponGlow(float level)
 
60
   {
 
61
      vec3 result;
 
62
      result.rgb = vec3(1.38, 0.35, 0.20) * level;    
 
63
      return result;
 
64
   }   
 
65
   
 
66
#endif
 
67
 
 
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)
 
70
{
 
71
   lightVector = normalize(lightVector);
 
72
   vec3 reflection = normalize(-reflect(lightVector, normal));
 
73
   
 
74
   totalDiffuse += gl_FrontMaterial.diffuse.rgb * lightColor * max(dot(normal, lightVector), 0.0);
 
75
   totalSpecular += lightColor * pow(max(dot(reflection, eyeVector), 0.0), KspecExponent);
 
76
}
 
77
 
 
78
 
 
79
#define LIGHT(idx, vector) Light(vector, normal, gl_LightSource[idx].diffuse.rgb, eyeVector, KspecExponent, diffuse, specular)
 
80
 
 
81
 
 
82
void main()
 
83
{
 
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);
 
89
 
 
90
float specIntensity = texture2D(uColorMap, vTexCoord).a;
 
91
 
 
92
#ifdef OO_LIGHT_0_FIX
 
93
   LIGHT(0, normalize(vLight0Vector));
 
94
#endif
 
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;
 
97
   
 
98
 vec3 color = diffuse * colorMap;
 
99
      color += colorMap * specular * 6.0 * specIntensity;  
 
100
   
 
101
  
 
102
// these next glow effects are only available in full shader mode   
 
103
   #ifndef OO_REDUCED_COMPLEXITY 
 
104
 
 
105
 
 
106
//Add in the laser firing gun barrel flash effect    
 
107
   color += WeaponGlow(gunglowMap  * Pulse(min(laser_heat_level, 1.0), 1.0));
 
108
 
 
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); 
 
113
#endif   
 
114
    
 
115
   gl_FragColor = vec4(color.rgb, 1.0);
 
116
}