~harrison-rt/+junk/jaguar_company

« back to all changes in this revision

Viewing changes to trunk/jaguar_company.oxp/Shaders/jaguar_company_base.fragment

  • Committer: Richard Harrison
  • Date: 2013-01-19 22:41:59 UTC
  • Revision ID: harrison.rt@gmail.com-20130119224159-v97r97cskj8opitt
Tags: 1.7
* Simplified the intercept AI.
* Heavily commented the scripts and AIs.
* Stray comma in pirate-victim-roles.plist removed.
* Used Obj2DatTexNorm.py on the models and preserved the material names.
* Modified the shipdata to use the material names.
* Relaxed distance code to cope with battalion sized groups. (64 ships tested)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* jaguar_company_base.fragment for the Jaguar Company Base.
2
 
**
3
 
** Copyright (C) 2012 Tricky
4
 
**
5
 
** This work is licensed under the Creative Commons
6
 
** Attribution-Noncommercial-Share Alike 3.0 Unported License.
7
 
**
8
 
** To view a copy of this license, visit
9
 
** http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter
10
 
** to Creative Commons, 171 Second Street, Suite 300, San Francisco,
11
 
** California, 94105, USA.
12
 
**
13
 
** Pixel/Fragment shader for the Jaguar Company Base.
14
 
*/
 
2
 *
 
3
 * Copyright (C) 2012 Tricky
 
4
 *
 
5
 * This work is licensed under the Creative Commons
 
6
 * Attribution-Noncommercial-Share Alike 3.0 Unported License.
 
7
 *
 
8
 * To view a copy of this license, visit
 
9
 * http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter
 
10
 * to Creative Commons, 171 Second Street, Suite 300, San Francisco,
 
11
 * California, 94105, USA.
 
12
 *
 
13
 * Pixel/Fragment shader for the Jaguar Company Base.
 
14
 */
15
15
 
16
16
#define MAX_LIGHTS 8
17
17
#define NUM_LIGHTS 2
23
23
#endif
24
24
 
25
25
varying vec2        vTexCoord;
26
 
varying vec3        vEyeVector;   // These are all in tangent space
 
26
varying vec3        vEyeVector; /* These are all in tangent space. */
27
27
varying vec3        vLightVectors[MAX_LIGHTS]; 
28
28
 
29
 
uniform sampler2D   uColorMap;
30
 
uniform sampler2D   uNormalMap;
 
29
uniform sampler2D   uDiffuseTexture;
 
30
uniform sampler2D   uNormalTexture;
31
31
 
32
32
const float         Kgamma = 0.4;
33
33
const float         KspecExponent = 5.0;
34
34
 
35
 
void Light(in vec3 lightVector, in vec3 normal, in vec3 lightColor, in vec3 eyeVector,
 
35
void Light(in vec3 lightVector, in vec3 normalMaterial, in vec3 lightColor, in vec3 eyeVector,
36
36
           in float KspecExponent, inout vec3 totalDiffuse, inout vec3 totalSpecular)
37
37
{
38
38
    lightVector = normalize(lightVector);
39
 
    vec3 reflection = normalize(-reflect(lightVector, normal));
 
39
    vec3 reflection = normalize(-reflect(lightVector, normalMaterial));
40
40
 
41
 
    totalDiffuse += gl_FrontMaterial.diffuse.rgb * lightColor * max(dot(normal, lightVector), 0.0);
 
41
    totalDiffuse += gl_FrontMaterial.diffuse.rgb * lightColor * max(dot(normalMaterial, lightVector), 0.0);
42
42
    totalSpecular += lightColor * pow(max(dot(reflection, eyeVector), 0.0), KspecExponent);
43
43
}
44
44
 
45
 
#define LIGHT(idx, vector) Light(vector, normal, gl_LightSource[idx].diffuse.rgb, eyeVector, KspecExponent, diffuse, specular)
 
45
#define LIGHT(idx, vector) Light(vector, normalMaterial, gl_LightSource[idx].diffuse.rgb, eyeVector, KspecExponent, diffuse, specular)
46
46
 
47
47
void main()
48
48
{
49
49
    vec3 eyeVector = normalize(vEyeVector);
50
50
    vec3 diffuse = vec3(0.0), specular = vec3(0.0);
51
 
    vec3 colorMap = texture2D(uColorMap, vTexCoord).rgb;
52
 
    vec3 normal = normalize(texture2D(uNormalMap, vTexCoord).rgb - 0.5);
 
51
    vec3 diffuseMaterial = texture2D(uDiffuseTexture, vTexCoord).rgb;
 
52
    vec3 normalMaterial = normalize(texture2D(uNormalTexture, vTexCoord).rgb - 0.5);
53
53
 
54
 
    /* Lights */
 
54
    /* Lights. */
55
55
#ifdef OO_LIGHT_0_FIX
56
56
    int i = 0;
57
57
#else
62
62
        LIGHT(i, vLightVectors[i]);
63
63
    }
64
64
 
65
 
    /* Texture */
 
65
    /* Texture. */
66
66
    diffuse += gl_FrontMaterial.ambient.rgb * gl_LightModel.ambient.rgb;
67
 
    vec3 color = diffuse * colorMap;
68
 
    color += colorMap * specular;
 
67
    vec3 color = diffuseMaterial * diffuse;
 
68
    color += diffuseMaterial * specular;
69
69
    color *= Kgamma;
70
70
 
71
 
    /* Return final result */
 
71
    /* Return final result. */
72
72
    gl_FragColor = vec4(color, 1.0);
73
73
}