1
1
/* jaguar_company_base.fragment for the Jaguar Company Base.
3
** Copyright (C) 2012 Tricky
5
** This work is licensed under the Creative Commons
6
** Attribution-Noncommercial-Share Alike 3.0 Unported License.
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.
13
** Pixel/Fragment shader for the Jaguar Company Base.
3
* Copyright (C) 2012 Tricky
5
* This work is licensed under the Creative Commons
6
* Attribution-Noncommercial-Share Alike 3.0 Unported License.
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.
13
* Pixel/Fragment shader for the Jaguar Company Base.
16
16
#define MAX_LIGHTS 8
17
17
#define NUM_LIGHTS 2
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];
29
uniform sampler2D uColorMap;
30
uniform sampler2D uNormalMap;
29
uniform sampler2D uDiffuseTexture;
30
uniform sampler2D uNormalTexture;
32
32
const float Kgamma = 0.4;
33
33
const float KspecExponent = 5.0;
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)
38
38
lightVector = normalize(lightVector);
39
vec3 reflection = normalize(-reflect(lightVector, normal));
39
vec3 reflection = normalize(-reflect(lightVector, normalMaterial));
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);
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)
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);
55
55
#ifdef OO_LIGHT_0_FIX
62
62
LIGHT(i, vLightVectors[i]);
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;
71
/* Return final result */
71
/* Return final result. */
72
72
gl_FragColor = vec4(color, 1.0);