| 1 |
uniform float y0; |
|---|
| 2 |
uniform bool lightingEnabled; |
|---|
| 3 |
|
|---|
| 4 |
vec4 warp(in vec4 source) |
|---|
| 5 |
{ |
|---|
| 6 |
float divisor = source.y + y0; |
|---|
| 7 |
return vec4(source.x * (1.0 + y0 ), source.y * y0 + 1.0, (source.z * y0 + 1.0)*0.01, source.w * divisor); |
|---|
| 8 |
} |
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
vec3 fnormal(void) |
|---|
| 12 |
{ |
|---|
| 13 |
//Compute the normal |
|---|
| 14 |
vec3 normal = gl_NormalMatrix * gl_Normal; |
|---|
| 15 |
normal = normalize(normal); |
|---|
| 16 |
return normal; |
|---|
| 17 |
} |
|---|
| 18 |
|
|---|
| 19 |
void directionalLight(in int i, |
|---|
| 20 |
in vec3 normal, |
|---|
| 21 |
inout vec4 ambient, |
|---|
| 22 |
inout vec4 diffuse, |
|---|
| 23 |
inout vec4 specular) |
|---|
| 24 |
{ |
|---|
| 25 |
float nDotVP; // normal . light direction |
|---|
| 26 |
float nDotHV; // normal . light half vector |
|---|
| 27 |
float pf; // power factor |
|---|
| 28 |
|
|---|
| 29 |
nDotVP = max(0.0, dot(normal, normalize(vec3 (gl_LightSource[i].position)))); |
|---|
| 30 |
nDotHV = max(0.0, dot(normal, vec3 (gl_LightSource[i].halfVector))); |
|---|
| 31 |
|
|---|
| 32 |
if (nDotVP == 0.0) |
|---|
| 33 |
{ |
|---|
| 34 |
pf = 0.0; |
|---|
| 35 |
} |
|---|
| 36 |
else |
|---|
| 37 |
{ |
|---|
| 38 |
pf = pow(nDotHV, gl_FrontMaterial.shininess); |
|---|
| 39 |
|
|---|
| 40 |
} |
|---|
| 41 |
ambient += gl_LightSource[i].ambient; |
|---|
| 42 |
diffuse += gl_LightSource[i].diffuse * nDotVP; |
|---|
| 43 |
specular += gl_LightSource[i].specular * pf; |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
void main() |
|---|
| 47 |
{ |
|---|
| 48 |
gl_Position = warp(ftransform()); |
|---|
| 49 |
|
|---|
| 50 |
if (lightingEnabled) |
|---|
| 51 |
{ |
|---|
| 52 |
vec4 ambient = vec4(0.0); |
|---|
| 53 |
vec4 diffuse = vec4(0.0); |
|---|
| 54 |
vec4 specular = vec4(0.0); |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
vec3 normal = fnormal(); |
|---|
| 58 |
|
|---|
| 59 |
directionalLight(0, normal, ambient, diffuse, specular); |
|---|
| 60 |
|
|---|
| 61 |
vec4 color = gl_FrontLightModelProduct.sceneColor + |
|---|
| 62 |
ambient * gl_FrontMaterial.ambient + |
|---|
| 63 |
diffuse * gl_FrontMaterial.diffuse + |
|---|
| 64 |
specular * gl_FrontMaterial.specular; |
|---|
| 65 |
|
|---|
| 66 |
gl_FrontColor = color; |
|---|
| 67 |
|
|---|
| 68 |
} |
|---|
| 69 |
else |
|---|
| 70 |
{ |
|---|
| 71 |
gl_FrontColor = gl_Color; |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
} |
|---|